diff options
author | George Hazan <george.hazan@gmail.com> | 2013-09-26 07:57:19 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2013-09-26 07:57:19 +0000 |
commit | a2774c8af4d12c9952738b9cbab00bd0fc0e0128 (patch) | |
tree | 24a951b5880bcbc9dbeb8ba7a4e214474bb5e419 /plugins | |
parent | 0920e599aa9ad0e6137bb0a23699456df4e9966e (diff) |
crash on premultiplying of non-32-bit bitmaps
git-svn-id: http://svn.miranda-ng.org/main/trunk@6238 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/AdvaImg/src/main.cpp | 58 |
1 files changed, 25 insertions, 33 deletions
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;
|