diff options
author | George Hazan <george.hazan@gmail.com> | 2014-07-08 15:49:18 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2014-07-08 15:49:18 +0000 |
commit | 62ab18a9fda2f19c08ae63a14c7a262ca62f0cce (patch) | |
tree | 821876224af8cb3e3f4b9b29ea3237212cde37e7 /plugins/SecureIM/src/images.cpp | |
parent | 19a5e6f0b9c3232933132dbaa9420aecef497336 (diff) |
code cleaning
git-svn-id: http://svn.miranda-ng.org/main/trunk@9732 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/SecureIM/src/images.cpp')
-rw-r--r-- | plugins/SecureIM/src/images.cpp | 151 |
1 files changed, 61 insertions, 90 deletions
diff --git a/plugins/SecureIM/src/images.cpp b/plugins/SecureIM/src/images.cpp index abecbb5ab8..c3a0fbdde3 100644 --- a/plugins/SecureIM/src/images.cpp +++ b/plugins/SecureIM/src/images.cpp @@ -1,38 +1,30 @@ #include "commonheaders.h"
-
void HalfBitmap32Alpha(HBITMAP hBitmap)
{
BITMAP bmp;
- DWORD dwLen;
- BYTE *p;
- int x, y;
-
GetObject(hBitmap, sizeof(bmp), &bmp);
-
if (bmp.bmBitsPixel != 32)
return;
- dwLen = bmp.bmWidth * bmp.bmHeight * (bmp.bmBitsPixel / 8);
- p = (BYTE *)malloc(dwLen);
+ DWORD dwLen = bmp.bmWidth * bmp.bmHeight * (bmp.bmBitsPixel / 8);
+ BYTE *p = (BYTE *)malloc(dwLen);
if (p == NULL)
return;
memset(p, 0, dwLen);
GetBitmapBits(hBitmap, dwLen, p);
- for (y = 0; y < bmp.bmHeight; ++y) {
- BYTE *px = p + bmp.bmWidth * 4 * y;
+ for (int y = 0; y < bmp.bmHeight; ++y) {
+ BYTE *px = p + bmp.bmWidth * 4 * y;
- for (x = 0; x < bmp.bmWidth; ++x)
- {
- px[3]>>=1;
+ for (int x = 0; x < bmp.bmWidth; ++x) {
+ px[3] >>= 1;
px += 4;
}
}
SetBitmapBits(hBitmap, dwLen, p);
-
free(p);
}
@@ -41,16 +33,12 @@ void HalfBitmap32Alpha(HBITMAP hBitmap) void MakeBmpTransparent(HBITMAP hBitmap)
{
BITMAP bmp;
- DWORD dwLen;
- BYTE *p;
-
GetObject(hBitmap, sizeof(bmp), &bmp);
-
if (bmp.bmBitsPixel != 32)
return;
- dwLen = bmp.bmWidth * bmp.bmHeight * (bmp.bmBitsPixel / 8);
- p = (BYTE *)malloc(dwLen);
+ DWORD dwLen = bmp.bmWidth * bmp.bmHeight * (bmp.bmBitsPixel / 8);
+ BYTE *p = (BYTE *)malloc(dwLen);
if (p == NULL)
return;
@@ -60,7 +48,6 @@ void MakeBmpTransparent(HBITMAP hBitmap) free(p);
}
-
// Correct alpha from bitmaps loaded without it (it cames with 0 and should be 255)
void CorrectBitmap32Alpha(HBITMAP hBitmap, BOOL force)
{
@@ -85,16 +72,13 @@ void CorrectBitmap32Alpha(HBITMAP hBitmap, BOOL force) fixIt = TRUE;
for (y = 0; fixIt && y < bmp.bmHeight; ++y) {
- BYTE *px = p + bmp.bmWidth * 4 * y;
+ BYTE *px = p + bmp.bmWidth * 4 * y;
- for (x = 0; fixIt && x < bmp.bmWidth; ++x)
- {
- if (px[3] != 0 && !force)
- {
+ for (x = 0; fixIt && x < bmp.bmWidth; ++x) {
+ if (px[3] != 0 && !force) {
fixIt = FALSE;
}
- else
- {
+ else {
if (px[0] != 0 || px[1] != 0 || px[2] != 0)
px[3] = 255;
}
@@ -112,7 +96,7 @@ void CorrectBitmap32Alpha(HBITMAP hBitmap, BOOL force) HBITMAP CopyBitmapTo32(HBITMAP hBitmap)
{
- BITMAPINFO RGB32BitsBITMAPINFO;
+ BITMAPINFO RGB32BitsBITMAPINFO;
BYTE * ptPixels;
HBITMAP hDirectBitmap;
@@ -135,23 +119,22 @@ HBITMAP CopyBitmapTo32(HBITMAP hBitmap) RGB32BitsBITMAPINFO.bmiHeader.biPlanes = 1;
RGB32BitsBITMAPINFO.bmiHeader.biBitCount = 32;
- hDirectBitmap = CreateDIBSection(NULL,
- (BITMAPINFO *)&RGB32BitsBITMAPINFO,
- DIB_RGB_COLORS,
- (void **)&ptPixels,
- NULL, 0);
+ hDirectBitmap = CreateDIBSection(NULL,
+ (BITMAPINFO *)&RGB32BitsBITMAPINFO,
+ DIB_RGB_COLORS,
+ (void **)&ptPixels,
+ NULL, 0);
// Copy data
- if (bmp.bmBitsPixel != 32)
- {
+ if (bmp.bmBitsPixel != 32) {
HDC hdcOrig, hdcDest;
HBITMAP oldOrig, oldDest;
-
+
hdcOrig = CreateCompatibleDC(NULL);
- oldOrig = (HBITMAP) SelectObject(hdcOrig, hBitmap);
+ oldOrig = (HBITMAP)SelectObject(hdcOrig, hBitmap);
hdcDest = CreateCompatibleDC(NULL);
- oldDest = (HBITMAP) SelectObject(hdcDest, hDirectBitmap);
+ oldDest = (HBITMAP)SelectObject(hdcDest, hDirectBitmap);
BitBlt(hdcDest, 0, 0, bmp.bmWidth, bmp.bmHeight, hdcOrig, 0, 0, SRCCOPY);
@@ -163,8 +146,7 @@ HBITMAP CopyBitmapTo32(HBITMAP hBitmap) // Set alpha
CorrectBitmap32Alpha(hDirectBitmap, FALSE);
}
- else
- {
+ else {
GetBitmapBits(hBitmap, dwLen, p);
SetBitmapBits(hDirectBitmap, dwLen, p);
}
@@ -177,29 +159,29 @@ HBITMAP CopyBitmapTo32(HBITMAP hBitmap) HBITMAP CreateBitmap32(int cx, int cy)
{
- BITMAPINFO RGB32BitsBITMAPINFO;
+ BITMAPINFO RGB32BitsBITMAPINFO;
UINT * ptPixels;
HBITMAP DirectBitmap;
- ZeroMemory(&RGB32BitsBITMAPINFO,sizeof(BITMAPINFO));
- RGB32BitsBITMAPINFO.bmiHeader.biSize=sizeof(BITMAPINFOHEADER);
- RGB32BitsBITMAPINFO.bmiHeader.biWidth=cx;//bm.bmWidth;
- RGB32BitsBITMAPINFO.bmiHeader.biHeight=cy;//bm.bmHeight;
- RGB32BitsBITMAPINFO.bmiHeader.biPlanes=1;
- RGB32BitsBITMAPINFO.bmiHeader.biBitCount=32;
-
- DirectBitmap = CreateDIBSection(NULL,
- (BITMAPINFO *)&RGB32BitsBITMAPINFO,
- DIB_RGB_COLORS,
- (void **)&ptPixels,
- NULL, 0);
+ ZeroMemory(&RGB32BitsBITMAPINFO, sizeof(BITMAPINFO));
+ RGB32BitsBITMAPINFO.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
+ RGB32BitsBITMAPINFO.bmiHeader.biWidth = cx;//bm.bmWidth;
+ RGB32BitsBITMAPINFO.bmiHeader.biHeight = cy;//bm.bmHeight;
+ RGB32BitsBITMAPINFO.bmiHeader.biPlanes = 1;
+ RGB32BitsBITMAPINFO.bmiHeader.biBitCount = 32;
+
+ DirectBitmap = CreateDIBSection(NULL,
+ (BITMAPINFO *)&RGB32BitsBITMAPINFO,
+ DIB_RGB_COLORS,
+ (void **)&ptPixels,
+ NULL, 0);
return DirectBitmap;
}
BOOL MakeBitmap32(HBITMAP *hBitmap)
{
- BITMAP bmp;
+ BITMAP bmp;
GetObject(*hBitmap, sizeof(bmp), &bmp);
@@ -208,12 +190,11 @@ BOOL MakeBitmap32(HBITMAP *hBitmap) HBITMAP hBmpTmp = CopyBitmapTo32(*hBitmap);
DeleteObject(*hBitmap);
*hBitmap = hBmpTmp;
- }
+ }
return TRUE;
}
-
#define GET_PIXEL(__P__, __X__, __Y__)(__P__ + width * 4 * (__Y__) + 4 * (__X__))
BOOL MakeGrayscale(HBITMAP *hBitmap)
@@ -221,62 +202,56 @@ BOOL MakeGrayscale(HBITMAP *hBitmap) BYTE *p = NULL;
BYTE *p1;
DWORD dwLen;
- int width, height, x, y;
- BITMAP bmp;
+ int width, height, x, y;
+ BITMAP bmp;
GetObject(*hBitmap, sizeof(bmp), &bmp);
- width = bmp.bmWidth;
+ width = bmp.bmWidth;
height = bmp.bmHeight;
dwLen = width * height * 4;
p = (BYTE *)malloc(dwLen);
- if (p == NULL)
- {
+ if (p == NULL) {
return FALSE;
}
- if (bmp.bmBitsPixel != 32)
- {
+ if (bmp.bmBitsPixel != 32) {
// Convert to 32 bpp
HBITMAP hBmpTmp = CopyBitmapTo32(*hBitmap);
DeleteObject(*hBitmap);
*hBitmap = hBmpTmp;
- }
+ }
GetBitmapBits(*hBitmap, dwLen, p);
// Make grayscale
- for (y = 0 ; y < height ; y++)
- {
- for (x = 0 ; x < width ; x++)
- {
+ for (y = 0; y < height; y++) {
+ for (x = 0; x < width; x++) {
p1 = GET_PIXEL(p, x, y);
p1[0] = p1[1] = p1[2] = (p1[0] + p1[1] + p1[2]) / 3;
}
}
- dwLen = SetBitmapBits(*hBitmap, dwLen, p);
- free(p);
+ dwLen = SetBitmapBits(*hBitmap, dwLen, p);
+ free(p);
return TRUE;
}
-
HICON MakeHalfAlphaIcon(HICON SourceIcon)
{
- ICONINFO TargetIconInfo;
- BITMAP TargetBitmapInfo;
- HICON TargetIcon, TempIcon;
+ HICON TempIcon = CopyIcon(SourceIcon);
- TempIcon = CopyIcon(SourceIcon);
+ ICONINFO TargetIconInfo;
if (!GetIconInfo(TempIcon, &TargetIconInfo))
return NULL;
+ BITMAP TargetBitmapInfo;
if (!GetObject(TargetIconInfo.hbmColor, sizeof(BITMAP), &TargetBitmapInfo))
return NULL;
MakeBitmap32(&TargetIconInfo.hbmColor);
HalfBitmap32Alpha(TargetIconInfo.hbmColor);
- TargetIcon = CreateIconIndirect(&TargetIconInfo);
+ HICON TargetIcon = CreateIconIndirect(&TargetIconInfo);
DestroyIcon(TempIcon);
DeleteObject(TargetIconInfo.hbmColor);
@@ -284,33 +259,32 @@ HICON MakeHalfAlphaIcon(HICON SourceIcon) return TargetIcon;
}
-
HICON MakeGrayscaleIcon(HICON SourceIcon)
{
+ HICON TempIcon = CopyIcon(SourceIcon);
+
ICONINFO TargetIconInfo;
BITMAP TargetBitmapInfo;
- HICON TargetIcon, TempIcon;
-
- TempIcon = CopyIcon(SourceIcon);
- if (! GetIconInfo(TempIcon, &TargetIconInfo) || GetObject(TargetIconInfo.hbmColor, sizeof(BITMAP), &TargetBitmapInfo) == 0) return NULL;
+ if (!GetIconInfo(TempIcon, &TargetIconInfo) || GetObject(TargetIconInfo.hbmColor, sizeof(BITMAP), &TargetBitmapInfo) == 0)
+ return NULL;
MakeGrayscale(&TargetIconInfo.hbmColor);
- TargetIcon = CreateIconIndirect(&TargetIconInfo);
+ HICON TargetIcon = CreateIconIndirect(&TargetIconInfo);
DestroyIcon(TempIcon);
return TargetIcon;
}
-HICON BindOverlayIcon(HICON SourceIcon,HICON OverlayIcon)
+HICON BindOverlayIcon(HICON SourceIcon, HICON OverlayIcon)
{
ICONINFO OverlayIconInfo, TargetIconInfo;
BITMAP OverlayBitmapInfo, TargetBitmapInfo;
HBITMAP OldOverlayBitmap, OldTargetBitmap;
HICON TargetIcon, TempIcon;
HDC OverlayDC, TargetDC;
- BLENDFUNCTION bf = {0,0,255,1};
+ BLENDFUNCTION bf = { 0, 0, 255, 1 };
TempIcon = CopyIcon(SourceIcon);
if (!GetIconInfo(TempIcon, &TargetIconInfo))
@@ -330,13 +304,13 @@ HICON BindOverlayIcon(HICON SourceIcon,HICON OverlayIcon) OldOverlayBitmap = (HBITMAP)SelectObject(OverlayDC, OverlayIconInfo.hbmColor);
AlphaBlend(TargetDC, 0, 0, TargetBitmapInfo.bmWidth, TargetBitmapInfo.bmHeight,
- OverlayDC, 0, 0, OverlayBitmapInfo.bmWidth, OverlayBitmapInfo.bmHeight, bf);
+ OverlayDC, 0, 0, OverlayBitmapInfo.bmWidth, OverlayBitmapInfo.bmHeight, bf);
SelectObject(TargetDC, TargetIconInfo.hbmMask);
SelectObject(OverlayDC, OverlayIconInfo.hbmMask);
BitBlt(TargetDC, 0, 0, TargetBitmapInfo.bmWidth, TargetBitmapInfo.bmHeight,
- OverlayDC, 0, 0, SRCCOPY);
+ OverlayDC, 0, 0, SRCCOPY);
TargetIcon = CreateIconIndirect(&TargetIconInfo);
DestroyIcon(TempIcon);
@@ -353,6 +327,3 @@ HICON BindOverlayIcon(HICON SourceIcon,HICON OverlayIcon) return TargetIcon;
}
-
-
-// EOF
|