diff options
author | George Hazan <george.hazan@gmail.com> | 2015-06-02 15:55:48 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2015-06-02 15:55:48 +0000 |
commit | ab53b72bf7067feb9dede0fd76b5a3cbc13863b9 (patch) | |
tree | 677a18bc997d1cf118379b288a7c2dd2c160d9b1 /plugins/SplashScreen | |
parent | 1c229f90bfc6c8032bd2d20e297e97f321eb4db7 (diff) |
- old PNG conversion code (png2dib, dib2png) removed;
- m_png.h also removed;
- all calls of LoadImage replaced with CallService(MS_IMG_LOAD);
- four invalid CloseHandle() calls removed;
- massive code cleaning for Popup, HistoryStats & SplashScreen plugins
git-svn-id: http://svn.miranda-ng.org/main/trunk@13974 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/SplashScreen')
-rw-r--r-- | plugins/SplashScreen/src/bitmap_funcs.cpp | 141 | ||||
-rw-r--r-- | plugins/SplashScreen/src/bitmap_funcs.h | 4 | ||||
-rw-r--r-- | plugins/SplashScreen/src/headers.h | 7 | ||||
-rw-r--r-- | plugins/SplashScreen/src/main.cpp | 32 | ||||
-rw-r--r-- | plugins/SplashScreen/src/splash.cpp | 137 |
5 files changed, 74 insertions, 247 deletions
diff --git a/plugins/SplashScreen/src/bitmap_funcs.cpp b/plugins/SplashScreen/src/bitmap_funcs.cpp index 3e4f3d8e54..e75395e838 100644 --- a/plugins/SplashScreen/src/bitmap_funcs.cpp +++ b/plugins/SplashScreen/src/bitmap_funcs.cpp @@ -38,14 +38,14 @@ MyBitmap::MyBitmap(int w, int h) allocate(w, h);
}
-MyBitmap::MyBitmap(TCHAR *fn, TCHAR *fnAlpha)
+MyBitmap::MyBitmap(TCHAR *fn)
{
dcBmp = 0;
hBmp = 0;
bits = 0;
width = height = 0;
bitsSave = 0;
- loadFromFile(fn, fnAlpha);
+ loadFromFile(fn);
}
MyBitmap::~MyBitmap()
@@ -125,133 +125,40 @@ void MyBitmap::DrawText(TCHAR *str, int x, int y) this->saveAlpha(x - 2, y - 2, sz.cx + 2, sz.cy + 2);
::DrawText(this->getDC(), str, -1, &rc, DT_LEFT | DT_TOP | DT_SINGLELINE | DT_NOPREFIX);
this->restoreAlpha(x - 2, y - 2, sz.cx + 2, sz.cy + 2);
- //(x,y,sz.cx,sz.cy);
}
-bool MyBitmap::loadFromFile(TCHAR *fn, TCHAR *fnAlpha)
+bool MyBitmap::loadFromFile(TCHAR *fn)
{
if (bits) free();
- SIZE sz;
-
- TCHAR *ext;
- ext = &fn[mir_tstrlen(fn) - 4];
-
- if (!mir_tstrcmpi(ext, _T(".png"))) {
- HANDLE hFile, hMap = NULL;
- BYTE *ppMap = NULL;
- long cbFileSize = 0;
- BITMAPINFOHEADER *pDib = { 0 };
- BYTE *pDibBits = 0;
-
- if (!png2dibConvertor) {
- return false;
- }
-
- if ((hFile = CreateFile(fn, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL)) != INVALID_HANDLE_VALUE)
- if ((hMap = CreateFileMapping(hFile, NULL, PAGE_READONLY, 0, 0, NULL)) != NULL)
- if ((ppMap = (BYTE*)MapViewOfFile(hMap, FILE_MAP_READ, 0, 0, 0)) != NULL)
- cbFileSize = GetFileSize(hFile, NULL);
- if (cbFileSize != 0) {
- PNG2DIB param;
- param.pSource = ppMap;
- param.cbSourceSize = cbFileSize;
- param.pResult = &pDib;
-
- if (png2dibConvertor((char*)param.pSource, param.cbSourceSize, param.pResult))
- pDibBits = (BYTE*)(pDib + 1);
- else
- cbFileSize = 0;
+ HBITMAP hBmpLoaded = (HBITMAP)CallService(MS_IMG_LOAD, (WPARAM)fn, IMGL_TCHAR);
+ if (!hBmpLoaded) {
#ifdef _DEBUG
- logMessage(_T("Loading splash file"), _T("done"));
+ logMessage(_T("MyBitmap::loadFromFile"), _T("Bitmap load failed"));
#endif
- }
-
- if (ppMap) UnmapViewOfFile(ppMap);
- if (hMap) CloseHandle(hMap);
- if (hFile) CloseHandle(hFile);
-
- if (!cbFileSize) return false;
-
- BITMAPINFO *bi = (BITMAPINFO*)pDib;
- BYTE *pt = (BYTE*)bi;
- pt += bi->bmiHeader.biSize;
- HBITMAP hBitmap = NULL;
-
- if (bi->bmiHeader.biBitCount != 32) {
- allocate(abs(bi->bmiHeader.biWidth), abs(bi->bmiHeader.biHeight));
- HDC hdcTmp = CreateCompatibleDC(getDC());
- HBITMAP hBitmap = CreateDIBitmap(getDC(), pDib, CBM_INIT, pDibBits, bi, DIB_PAL_COLORS);
- SelectObject(hdcTmp, hBitmap);
- BitBlt(this->getDC(), 0, 0, abs(bi->bmiHeader.biWidth), abs(bi->bmiHeader.biHeight), hdcTmp, 0, 0, SRCCOPY);
- this->makeOpaque();
- DeleteDC(hdcTmp);
- DeleteObject(hBitmap);
-
- }
- else {
- BYTE *ptPixels = pt;
- hBitmap = CreateDIBSection(NULL, bi, DIB_RGB_COLORS, (void **)&ptPixels, NULL, 0);
- memcpy(ptPixels, pt, bi->bmiHeader.biSizeImage);
-
- allocate(abs(bi->bmiHeader.biWidth), abs(bi->bmiHeader.biHeight));
- //memcpy(bits, pt, bi->bmiHeader.biSizeImage);
-
- BYTE *p2 = (BYTE*)pt;
- for (int y = 0; y < bi->bmiHeader.biHeight; ++y) {
- BYTE *p1 = (BYTE*)bits + (bi->bmiHeader.biHeight - y - 1)*bi->bmiHeader.biWidth * 4;
- for (int x = 0; x < bi->bmiHeader.biWidth; ++x) {
- p1[0] = p2[0];
- p1[1] = p2[1];
- p1[2] = p2[2];
- p1[3] = p2[3];
- p1 += 4;
- p2 += 4;
- }
- }
-
- premultipleChannels();
- }
-
- GlobalFree(pDib);
- DeleteObject(hBitmap);
- return true;
+ return false;
}
- else {
- HBITMAP hBmpLoaded = (HBITMAP)LoadImage(NULL, fn, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
- if (!hBmpLoaded) {
-#ifdef _DEBUG
- logMessage(_T("MyBitmap::loadFromFile"), _T("Bitmap load failed"));
-#endif
- return false;
- }
- BITMAP bm; GetObject(hBmpLoaded, sizeof(bm), &bm);
- SetBitmapDimensionEx(hBmpLoaded, bm.bmWidth, bm.bmHeight, NULL);
+ BITMAP bm; GetObject(hBmpLoaded, sizeof(bm), &bm);
+ SetBitmapDimensionEx(hBmpLoaded, bm.bmWidth, bm.bmHeight, NULL);
- HDC dcTmp = CreateCompatibleDC(0);
- GetBitmapDimensionEx(hBmpLoaded, &sz);
- HBITMAP hBmpDcSave = (HBITMAP)SelectObject(dcTmp, hBmpLoaded);
+ SIZE sz;
+ HDC dcTmp = CreateCompatibleDC(0);
+ GetBitmapDimensionEx(hBmpLoaded, &sz);
+ HBITMAP hBmpDcSave = (HBITMAP)SelectObject(dcTmp, hBmpLoaded);
- allocate(sz.cx, sz.cy);
- BitBlt(dcBmp, 0, 0, width, height, dcTmp, 0, 0, SRCCOPY);
+ allocate(sz.cx, sz.cy);
+ BitBlt(dcBmp, 0, 0, width, height, dcTmp, 0, 0, SRCCOPY);
- DeleteObject(SelectObject(dcTmp, hBmpDcSave));
- DeleteDC(dcTmp);
+ DeleteObject(SelectObject(dcTmp, hBmpDcSave));
+ DeleteDC(dcTmp);
- MyBitmap alpha;
- if (fnAlpha && alpha.loadFromFile(fnAlpha) &&
- (alpha.getWidth() == width) &&
- (alpha.getHeight() == height)) {
- for (int i = 0; i < width*height; i++)
- bits[i] = (bits[i] & 0x00ffffff) | ((alpha.bits[i] & 0x000000ff) << 24);
- premultipleChannels();
- }
- else {
- makeOpaque();
- }
- return true;
- }
+ if (bm.bmBitsPixel == 32)
+ premultipleChannels();
+ else
+ makeOpaque();
+
+ return true;
}
void MyBitmap::allocate(int w, int h)
@@ -293,4 +200,4 @@ void MyBitmap::premultipleChannels() {
for (int i = 0; i < width*height; i++)
bits[i] = rgba(getr(bits[i])*geta(bits[i]) / 255, getg(bits[i])*geta(bits[i]) / 255, getb(bits[i])*geta(bits[i]) / 255, geta(bits[i]));
-}
\ No newline at end of file +}
diff --git a/plugins/SplashScreen/src/bitmap_funcs.h b/plugins/SplashScreen/src/bitmap_funcs.h index f91423dc52..35be6683db 100644 --- a/plugins/SplashScreen/src/bitmap_funcs.h +++ b/plugins/SplashScreen/src/bitmap_funcs.h @@ -26,10 +26,10 @@ private: public:
MyBitmap();
MyBitmap(int w, int h);
- MyBitmap(TCHAR *fn, TCHAR *fnAlpha = 0);
+ MyBitmap(TCHAR *fn);
~MyBitmap();
- bool loadFromFile(TCHAR *fn, TCHAR *fnAlpha = 0);
+ bool loadFromFile(TCHAR *fn);
int getWidth() { return width; }
int getHeight() { return height; }
diff --git a/plugins/SplashScreen/src/headers.h b/plugins/SplashScreen/src/headers.h index ffb47ae14c..0ec78e6cd6 100644 --- a/plugins/SplashScreen/src/headers.h +++ b/plugins/SplashScreen/src/headers.h @@ -32,7 +32,7 @@ #include <m_database.h>
#include <m_options.h>
#include <m_langpack.h>
-#include <m_png.h>
+#include <m_imgsrvc.h>
#include <m_splash.h>
@@ -72,13 +72,8 @@ extern TCHAR szSplashFile[MAX_PATH], szSoundFile[MAX_PATH], szPrefix[128]; extern TCHAR *szMirDir;
extern char szVersion[MAX_PATH];
extern BOOL bserviceinvoked, bmodulesloaded, png2dibavail;
-extern HANDLE hSplashThread;
extern HINSTANCE hInst;
-// png2dib interface
-typedef BOOL ( *pfnConvertPng2dib )( char*, size_t, BITMAPINFOHEADER** );
-extern pfnConvertPng2dib png2dibConvertor;
-
extern int OptInit(WPARAM wParam, LPARAM lParam);
extern BOOL ShowSplash(BOOL bpreview);
extern VOID ReadDbConfig();
diff --git a/plugins/SplashScreen/src/main.cpp b/plugins/SplashScreen/src/main.cpp index 6f1dbf8546..e08d070729 100644 --- a/plugins/SplashScreen/src/main.cpp +++ b/plugins/SplashScreen/src/main.cpp @@ -25,8 +25,6 @@ int hLangpack; static HMODULE hAdvaimg = NULL;
-pfnConvertPng2dib png2dibConvertor = NULL;
-
BOOL bstartup = true; // startup?
BOOL bserviceinvoked = false;
BOOL bmodulesloaded = false; // modules are loaded
@@ -41,7 +39,6 @@ TCHAR szLogFile[MAX_PATH]; #endif
SPLASHOPTS options;
HWND hwndSplash;
-HANDLE hSplashThread;
PLUGININFOEX pluginInfo = {
sizeof(PLUGININFOEX),
@@ -87,32 +84,6 @@ void SplashMain() if (bstartup & (options.active == 1))
{
- if (hAdvaimg == NULL)
- {
- hAdvaimg = LoadLibrary(szhAdvaimgPath);
- if (hAdvaimg == NULL)
- {
- png2dibavail = false;
- bstartup = false;
- }
- if (hAdvaimg)
- {
- png2dibConvertor = (pfnConvertPng2dib)GetProcAddress(hAdvaimg, "mempng2dib");
- if (png2dibConvertor == NULL)
- {
- FreeLibrary(hAdvaimg); hAdvaimg = NULL;
- MessageBox(NULL,
- TranslateT("Your advaimg.dll is either obsolete or damaged. Get latest from Miranda alpha builds."),
- TranslateT("Error"),
- MB_OK | MB_ICONSTOP);
- }
-#ifdef _DEBUG
- if (png2dibConvertor)
- logMessage(_T("Loading advaimg"), _T("done"));
-#endif
- }
- }
-
DBVARIANT dbv = { 0 };
if (!db_get_ts(NULL, MODNAME, "VersionPrefix", &dbv))
{
@@ -315,9 +286,6 @@ extern "C" int __declspec(dllexport) Load(void) extern "C" int __declspec(dllexport) Unload(void)
{
- if (hSplashThread)
- CloseHandle(hSplashThread);
-
UnregisterClass(_T(SPLASH_CLASS), hInst);
// Freeing loaded libraries
diff --git a/plugins/SplashScreen/src/splash.cpp b/plugins/SplashScreen/src/splash.cpp index 8a75544b5f..8f885a74e9 100644 --- a/plugins/SplashScreen/src/splash.cpp +++ b/plugins/SplashScreen/src/splash.cpp @@ -24,18 +24,15 @@ MyBitmap *SplashBmp, *tmpBmp; LRESULT CALLBACK SplashWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
- switch (message)
- {
+ switch (message) {
case WM_LOADED:
- {
#ifdef _DEBUG
logMessage(_T("WM_LOADED"), _T("called"));
#endif
- if (!options.showtime) SetTimer(hwnd, 7, 2000, 0);
-
+ if (!options.showtime)
+ SetTimer(hwnd, 7, 2000, 0);
break;
- }
case WM_LBUTTONDOWN:
PostMessage(hwnd, WM_CLOSE, 0, 0);
@@ -51,82 +48,65 @@ LRESULT CALLBACK SplashWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM logMessage(_T("ShowTime value"), b);
#endif
- if (options.showtime > 0) //TimeToShow enabled
- {
- if (wParam == 6)
- {
+ if (options.showtime > 0) { // TimeToShow enabled
+ if (wParam == 6) {
PostMessage(hwnd, WM_CLOSE, 0, 0);
#ifdef _DEBUG
logMessage(_T("Showtime timer"), _T("triggered"));
#endif
}
}
- else
- {
+ else {
PostMessage(hwnd, WM_CLOSE, 0, 0);
- if (wParam == 7)
- {
+ if (wParam == 7) {
#ifdef _DEBUG
logMessage(_T("On Modules Loaded timer"), _T("triggered"));
#endif
}
- if (wParam == 8)
- {
-#ifdef _DEBUG
- logMessage(_T("On Modules Loaded workaround"), _T("triggered"));
-#endif
- }
}
-
break;
case WM_RBUTTONDOWN:
- {
ShowWindow(hwndSplash, SW_HIDE);
DestroyWindow(hwndSplash);
bpreviewruns = false; // preview is stopped.
break;
- }
case WM_CLOSE:
- {
- RECT rc; GetWindowRect(hwndSplash, &rc);
- POINT ptDst = { rc.left, rc.top };
- POINT ptSrc = { 0, 0 };
- SIZE sz = { rc.right - rc.left, rc.bottom - rc.top };
-
- BLENDFUNCTION blend;
- blend.BlendOp = AC_SRC_OVER;
- blend.BlendFlags = 0;
- blend.SourceConstantAlpha = 255;
- blend.AlphaFormat = AC_SRC_ALPHA;
-
- // Fade Out
- if (options.fadeout)
{
- int i;
- for (i = 255; i >= 0; i -= options.fosteps)
- {
- blend.SourceConstantAlpha = i;
- UpdateLayeredWindow(hwndSplash, NULL, &ptDst, &sz, SplashBmp->getDC(), &ptSrc, 0xffffffff, &blend, LWA_ALPHA);
- Sleep(1);
+ RECT rc; GetWindowRect(hwndSplash, &rc);
+ POINT ptDst = { rc.left, rc.top };
+ POINT ptSrc = { 0, 0 };
+ SIZE sz = { rc.right - rc.left, rc.bottom - rc.top };
+
+ BLENDFUNCTION blend;
+ blend.BlendOp = AC_SRC_OVER;
+ blend.BlendFlags = 0;
+ blend.SourceConstantAlpha = 255;
+ blend.AlphaFormat = AC_SRC_ALPHA;
+
+ // Fade Out
+ if (options.fadeout) {
+ int i;
+ for (i = 255; i >= 0; i -= options.fosteps) {
+ blend.SourceConstantAlpha = i;
+ UpdateLayeredWindow(hwndSplash, NULL, &ptDst, &sz, SplashBmp->getDC(), &ptSrc, 0xffffffff, &blend, LWA_ALPHA);
+ Sleep(1);
+ }
}
}
if (bserviceinvoked) bserviceinvoked = false;
if (bpreviewruns) bpreviewruns = false;
DestroyWindow(hwndSplash);
- }
+ break;
case WM_MOUSEMOVE:
- {
if (bserviceinvoked)
PostMessage(hwnd, WM_CLOSE, 0, 0);
break;
- }
case WM_DESTROY:
- {
#ifdef _DEBUG
logMessage(_T("WM_DESTROY"), _T("called"));
#endif
@@ -135,7 +115,6 @@ LRESULT CALLBACK SplashWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM PostQuitMessage(0);
break;
}
- }
return DefWindowProc(hwnd, message, wParam, lParam);
}
@@ -145,8 +124,7 @@ void __cdecl SplashThread(void *arg) IGraphBuilder *pGraph = NULL;
IMediaControl *pControl = NULL;
- if (options.playsnd)
- {
+ if (options.playsnd) {
// Initialize the COM library.
CoInitialize(NULL);
@@ -218,22 +196,18 @@ void __cdecl SplashThread(void *arg) blend.SourceConstantAlpha = 0;
blend.AlphaFormat = AC_SRC_ALPHA;
- if (options.showversion)
- {
+ if (options.showversion) {
// locate text markers:
int i, x = -1, y = -1;
int splashWidth = SplashBmp->getWidth();
for (i = 0; i < splashWidth; ++i)
- if (SplashBmp->getRow(0)[i] & 0xFF000000)
- {
- if (x < 0)
- {
+ if (SplashBmp->getRow(0)[i] & 0xFF000000) {
+ if (x < 0) {
x = i - 1; // 1 pixel for marker line
splashWithMarkers = true;
}
- else
- {
+ else {
x = -1;
splashWithMarkers = false;
break;
@@ -241,15 +215,12 @@ void __cdecl SplashThread(void *arg) }
int splashHeight = SplashBmp->getHeight();
for (i = 0; splashWithMarkers && (i < splashHeight); ++i)
- if (SplashBmp->getRow(i)[0] & 0xFF000000)
- {
- if (y < 0)
- {
+ if (SplashBmp->getRow(i)[0] & 0xFF000000) {
+ if (y < 0) {
y = i - 1; // 1 pixel for marker line
splashWithMarkers = true;
}
- else
- {
+ else {
y = -1;
splashWithMarkers = false;
break;
@@ -264,8 +235,7 @@ void __cdecl SplashThread(void *arg) lf.lfHeight = 14;
mir_tstrcpy(lf.lfFaceName, _T("Verdana"));
SelectObject(SplashBmp->getDC(), CreateFontIndirect(&lf));
- if (!splashWithMarkers)
- {
+ if (!splashWithMarkers) {
SIZE v_sz = { 0, 0 };
GetTextExtentPoint32(SplashBmp->getDC(), verString, (int)mir_tstrlen(verString), &v_sz);
x = SplashBmp->getWidth() / 2 - (v_sz.cx / 2);
@@ -282,11 +252,9 @@ void __cdecl SplashThread(void *arg) ShowWindow(hwndSplash, SW_SHOWNORMAL);
- if (options.fadein)
- {
+ if (options.fadein) {
// Fade in
- for (int i = 0; i < 255; i += options.fisteps)
- {
+ for (int i = 0; i < 255; i += options.fisteps) {
blend.SourceConstantAlpha = i;
UpdateLayeredWindow(hwndSplash, NULL, &ptDst, &sz, SplashBmp->getDC(), &ptSrc, 0xffffffff, &blend, LWA_ALPHA);
Sleep(1);
@@ -295,20 +263,16 @@ void __cdecl SplashThread(void *arg) blend.SourceConstantAlpha = 255;
UpdateLayeredWindow(hwndSplash, NULL, &ptDst, &sz, SplashBmp->getDC(), &ptSrc, 0xffffffff, &blend, LWA_ALPHA);
- if (DWORD(arg) > 0)
- {
- if (SetTimer(hwndSplash, 6, DWORD(arg), 0))
- {
+ if (DWORD(arg) > 0) {
+ if (SetTimer(hwndSplash, 6, DWORD(arg), 0)) {
#ifdef _DEBUG
logMessage(_T("Timer TimeToShow"), _T("set"));
#endif
}
}
else
- if (bmodulesloaded)
- {
- if (SetTimer(hwndSplash, 8, 2000, 0))
- {
+ if (bmodulesloaded) {
+ if (SetTimer(hwndSplash, 8, 2000, 0)) {
#ifdef _DEBUG
logMessage(_T("Timer Modules loaded"), _T("set"));
#endif
@@ -323,8 +287,7 @@ void __cdecl SplashThread(void *arg) DispatchMessage(&msg);
}
- if (options.playsnd)
- {
+ if (options.playsnd) {
pControl->Release();
pGraph->Release();
CoUninitialize();
@@ -344,15 +307,14 @@ BOOL ShowSplash(BOOL bpreview) logMessage(_T("Loading splash file"), szSplashFile);
#endif
- if (!SplashBmp->loadFromFile(szSplashFile, NULL))
+ if (!SplashBmp->loadFromFile(szSplashFile))
return 0;
#ifdef _DEBUG
logMessage(_T("Thread"), _T("start"));
#endif
- if (bpreview)
- {
+ if (bpreview) {
ShowWindow(hwndSplash, SW_HIDE);
DestroyWindow(hwndSplash);
@@ -361,8 +323,7 @@ BOOL ShowSplash(BOOL bpreview) logMessage(_T("Preview"), _T("yes"));
#endif
}
- else
- {
+ else {
timeout = options.showtime;
#ifdef _DEBUG
TCHAR b[40];
@@ -371,14 +332,10 @@ BOOL ShowSplash(BOOL bpreview) #endif
}
- hSplashThread = mir_forkthread(SplashThread, (void*)timeout);
+ mir_forkthread(SplashThread, (void*)timeout);
#ifdef _DEBUG
logMessage(_T("Thread"), _T("end"));
#endif
-
- CloseHandle(hSplashThread);
- hSplashThread = NULL;
-
return 1;
}
\ No newline at end of file |