From a2774c8af4d12c9952738b9cbab00bd0fc0e0128 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Thu, 26 Sep 2013 07:57:19 +0000 Subject: crash on premultiplying of non-32-bit bitmaps git-svn-id: http://svn.miranda-ng.org/main/trunk@6238 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/AdvaImg/src/main.cpp | 58 +++++++++++++++++++------------------------- 1 file changed, 25 insertions(+), 33 deletions(-) (limited to 'plugins/AdvaImg') diff --git a/plugins/AdvaImg/src/main.cpp b/plugins/AdvaImg/src/main.cpp index 542c3c0dee..83b092a59a 100644 --- a/plugins/AdvaImg/src/main.cpp +++ b/plugins/AdvaImg/src/main.cpp @@ -113,46 +113,38 @@ static void FI_CorrectBitmap32Alpha(HBITMAP hBitmap, BOOL force) */ static BOOL FreeImage_PreMultiply(HBITMAP hBitmap) { - BYTE *p = NULL; - DWORD dwLen; - int width, height, x, y; - BITMAP bmp; - BYTE alpha; BOOL transp = FALSE; + BITMAP bmp; GetObject(hBitmap, sizeof(bmp), &bmp); - width = bmp.bmWidth; - height = bmp.bmHeight; - dwLen = width * height * 4; - p = (BYTE *)malloc(dwLen); - if (p != NULL) - { - GetBitmapBits(hBitmap, dwLen, p); - - for (y = 0; y < height; ++y) - { - BYTE *px = p + width * 4 * y; - - for (x = 0; x < width; ++x) - { - alpha = px[3]; - - if (alpha < 255) - { - transp = TRUE; + if (bmp.bmBitsPixel == 32) { + int width = bmp.bmWidth; + int height = bmp.bmHeight; + int dwLen = width * height * 4; + BYTE *p = (BYTE *)malloc(dwLen); + if (p != NULL) { + GetBitmapBits(hBitmap, dwLen, p); + + for (int y = 0; y < height; ++y) { + BYTE *px = p + width * 4 * y; + for (int x = 0; x < width; ++x) { + BYTE alpha = px[3]; + if (alpha < 255) { + transp = TRUE; + + px[0] = px[0] * alpha/255; + px[1] = px[1] * alpha/255; + px[2] = px[2] * alpha/255; + } - px[0] = px[0] * alpha/255; - px[1] = px[1] * alpha/255; - px[2] = px[2] * alpha/255; + px += 4; } - - px += 4; } - } - if (transp) - dwLen = SetBitmapBits(hBitmap, dwLen, p); - free(p); + if (transp) + dwLen = SetBitmapBits(hBitmap, dwLen, p); + free(p); + } } return transp; -- cgit v1.2.3