diff options
Diffstat (limited to 'src/mir_app/src/imgconv.cpp')
-rw-r--r-- | src/mir_app/src/imgconv.cpp | 95 |
1 files changed, 6 insertions, 89 deletions
diff --git a/src/mir_app/src/imgconv.cpp b/src/mir_app/src/imgconv.cpp index bf1486b226..8be46a92ef 100644 --- a/src/mir_app/src/imgconv.cpp +++ b/src/mir_app/src/imgconv.cpp @@ -26,93 +26,17 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. typedef DWORD ARGB;
-void InitBitmapInfo(BITMAPINFO &bmi, const SIZE &size)
+HBITMAP ConvertIconToBitmap(HIMAGELIST hIml, int iconId)
{
- memset(&bmi, 0, sizeof(BITMAPINFO));
+ BITMAPINFO bmi = {};
bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmi.bmiHeader.biPlanes = 1;
bmi.bmiHeader.biCompression = BI_RGB;
bmi.bmiHeader.biBitCount = 32;
-
- bmi.bmiHeader.biWidth = size.cx;
- bmi.bmiHeader.biHeight = size.cy;
-}
-
-void ConvertToPARGB32(HDC hdc, ARGB *pargb, HBITMAP hbmp, SIZE& sizImage, int cxRow)
-{
- BITMAPINFO bmi;
- InitBitmapInfo(bmi, sizImage);
-
- void *pvBits = malloc(sizImage.cx * 4 * sizImage.cy);
- if (GetDIBits(hdc, hbmp, 0, bmi.bmiHeader.biHeight, pvBits, &bmi, DIB_RGB_COLORS) == bmi.bmiHeader.biHeight) {
- ULONG cxDelta = cxRow - bmi.bmiHeader.biWidth;
- ARGB *pargbMask = (ARGB *)pvBits;
-
- for (ULONG y = bmi.bmiHeader.biHeight + 1; --y;) {
- for (ULONG x = bmi.bmiHeader.biWidth + 1; --x;) {
- if (*pargbMask++) {
- // transparent pixel
- *pargb++=0;
- }
- else {
- // opaque pixel
- *pargb++ |= 0xFF000000;
- }
- }
-
- pargb += cxDelta;
- }
- }
- free(pvBits);
-}
-
-bool HasAlpha(ARGB *pargb, SIZE& sizImage, int cxRow)
-{
- ULONG cxDelta = cxRow - sizImage.cx;
- for (ULONG y = sizImage.cy; y--;) {
- for (ULONG x = sizImage.cx; x--;) {
- if (*pargb++ & 0xFF000000)
- return true;
- }
- pargb += cxDelta;
- }
-
- return false;
-}
-
-void ConvertBufferToPARGB32(HANDLE hPaintBuffer, HDC hdc, HICON hIcon, SIZE& sizIcon)
-{
- RGBQUAD *prgbQuad;
- int cxRow;
- HRESULT hr = getBufferedPaintBits(hPaintBuffer, &prgbQuad, &cxRow);
- if (SUCCEEDED(hr)) {
- ARGB *pargb = (ARGB *)prgbQuad;
- if (!HasAlpha(pargb, sizIcon, cxRow)) {
- ICONINFO info;
- if (GetIconInfo(hIcon, &info)) {
- if (info.hbmMask)
- ConvertToPARGB32(hdc, pargb, info.hbmMask, sizIcon, cxRow);
-
- DeleteObject(info.hbmColor);
- DeleteObject(info.hbmMask);
- }
- }
- }
-}
-
-HBITMAP ConvertIconToBitmap(HICON hicon, HIMAGELIST hIml, int iconId)
-{
- SIZE sizIcon;
- sizIcon.cx = g_iIconSX;
- sizIcon.cy = g_iIconSY;
-
- RECT rcIcon = { 0, 0, sizIcon.cx, sizIcon.cy };
+ bmi.bmiHeader.biWidth = g_iIconSX;
+ bmi.bmiHeader.biHeight = g_iIconSY;
HDC hdc = CreateCompatibleDC(NULL);
-
- BITMAPINFO bmi;
- InitBitmapInfo(bmi, sizIcon);
-
HBITMAP hbmp = CreateDIBSection(hdc, &bmi, DIB_RGB_COLORS, NULL, NULL, 0);
HBITMAP hbmpOld = (HBITMAP)SelectObject(hdc, hbmp);
@@ -123,17 +47,10 @@ HBITMAP ConvertIconToBitmap(HICON hicon, HIMAGELIST hIml, int iconId) paintParams.pBlendFunction = &bfAlpha;
HDC hdcBuffer;
+ RECT rcIcon = { 0, 0, g_iIconSX, g_iIconSY };
HANDLE hPaintBuffer = beginBufferedPaint(hdc, &rcIcon, BPBF_DIB, &paintParams, &hdcBuffer);
if (hPaintBuffer) {
- if (hIml)
- ImageList_Draw(hIml, iconId, hdc, 0, 0, ILD_TRANSPARENT);
- else
- DrawIconEx(hdcBuffer, 0, 0, hicon, sizIcon.cx, sizIcon.cy, 0, NULL, DI_NORMAL);
-
- // If icon did not have an alpha channel we need to convert buffer to PARGB
- ConvertBufferToPARGB32(hPaintBuffer, hdc, hicon, sizIcon);
-
- // This will write the buffer contents to the destination bitmap
+ ImageList_Draw(hIml, iconId, hdc, 0, 0, ILD_TRANSPARENT);
endBufferedPaint(hPaintBuffer, TRUE);
}
|