diff options
author | René Schümann <white06tiger@gmail.com> | 2013-11-05 16:17:53 +0000 |
---|---|---|
committer | René Schümann <white06tiger@gmail.com> | 2013-11-05 16:17:53 +0000 |
commit | ebe0ab019e3c45fac0ff6067ff8808b060aff987 (patch) | |
tree | 55937f26f65900f28f9d15ac2d29b29b2b647382 /plugins/SendScreenshotPlus/src/Utils.cpp | |
parent | 36dffc5b63263b87e6cf63e74edd404b7ede7c42 (diff) |
// 3 out of 5
! fixed allocation of new char[] and freeing as Gdiplus::ImageCodecInfo struct
! fixed missing initialization (also reordered to comply declaration)
* allowed target window to be reused if "Open Again" is set.
git-svn-id: http://svn.miranda-ng.org/main/trunk@6788 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/SendScreenshotPlus/src/Utils.cpp')
-rw-r--r-- | plugins/SendScreenshotPlus/src/Utils.cpp | 154 |
1 files changed, 77 insertions, 77 deletions
diff --git a/plugins/SendScreenshotPlus/src/Utils.cpp b/plugins/SendScreenshotPlus/src/Utils.cpp index b56d953d79..ad2c00d4cf 100644 --- a/plugins/SendScreenshotPlus/src/Utils.cpp +++ b/plugins/SendScreenshotPlus/src/Utils.cpp @@ -157,81 +157,81 @@ FIBITMAP* CaptureScreen (HDC hDC,SIZE size,HWND hCapture){ }else{// bitblt screen DC to memory DC BitBlt(hMemDC,0,0,size.cx,size.cy,hScrDC,0,0,CAPTUREBLT|SRCCOPY); } - dib = FIP->FI_CreateDIBFromHBITMAP(hBitmap);
-
- //alpha channel from window is always wrong,
- //coz GDI do not draw all in alpha mode.
- //we have to create our own new alpha channel.
- bool bFixAlpha = true;
- bool bInvert = false;
-
- // Create monochrome (1 bit) B+W mask bitmap.
- HBITMAP hMask = CreateBitmap(size.cx,size.cy, 1, 1, NULL);
- HDC hMaskDC = CreateCompatibleDC(0);
- SelectBitmap(hMaskDC, hMask);
-
- //Create a SolidBrush object for non transparent area
- HBRUSH hBr = CreateSolidBrush(RGB(255,255,255));
-
- HRGN hrgn = NULL;
- int regionType;
- if(hCapture) {
- hrgn = CreateRectRgn(0,0,0,0);
- regionType = GetWindowRgn(hCapture, hrgn);
- if (regionType != ERROR) {
- // not layerd - fill the window region
- FillRgn(hMaskDC, hrgn, hBr);
- }
- else { //layerd window (WS_EX_LAYERED)
- BYTE bAlpha= 0;
- COLORREF crKey=0; //0x00bbggrr
- DWORD dwFlags=0;
- if(GetLayeredWindowAttributes(hCapture,&crKey,&bAlpha,&dwFlags)) {
- //per window transparency (like fading in a whole window).
- if((dwFlags & LWA_ALPHA) == LWA_ALPHA) {
- //Use bAlpha to determine the opacity of the layered window.
- bFixAlpha = false;
- }
- if((dwFlags & LWA_COLORKEY) == LWA_COLORKEY) {
- //Use crKey as the transparency color.
- SetBkColor(hMemDC, crKey);
- BitBlt(hMaskDC, 0, 0, size.cx, size.cy, hMemDC, 0, 0, SRCCOPY);
- bInvert = true;
- bFixAlpha = true;
- }
- }
- else {
- //per-pixel transparency (won't use the WM_PAINT )
- bFixAlpha = false;
- }
- }
- }
- else { //fill the desktop region
- hrgn = CreateRectRgn(0,0,size.cx,size.cy);
- FillRgn(hMaskDC, hrgn, hBr);
- }
-
- if(bFixAlpha) {
- FIBITMAP* dibMask = FIP->FI_CreateDIBFromHBITMAP(hMask);
- if(bInvert) FIP->FI_Invert(dibMask);
- FIBITMAP* dib8 = FIP->FI_ConvertTo8Bits(dibMask);
-
- //copy the dib8 alpha mask to dib32 main bitmap
- FIP->FI_SetChannel(dib,dib8,FICC_ALPHA);
- FIP->FI_Unload(dibMask);
- FIP->FI_Unload(dib8);
- }
-
- //clean up
- DeleteObject(hBr);
- if(hrgn) DeleteObject(hrgn);
- DeleteDC(hMaskDC);
- DeleteObject(hMask);
- SelectObject(hMemDC, hOld);
- DeleteDC(hMemDC);
- if(!hDC) ReleaseDC(NULL, hScrDC);
- DeleteObject(hBitmap);
-
+ dib = FIP->FI_CreateDIBFromHBITMAP(hBitmap); + + //alpha channel from window is always wrong, + //coz GDI do not draw all in alpha mode. + //we have to create our own new alpha channel. + bool bFixAlpha = true; + bool bInvert = false; + + // Create monochrome (1 bit) B+W mask bitmap. + HBITMAP hMask = CreateBitmap(size.cx,size.cy, 1, 1, NULL); + HDC hMaskDC = CreateCompatibleDC(0); + SelectBitmap(hMaskDC, hMask); + + //Create a SolidBrush object for non transparent area + HBRUSH hBr = CreateSolidBrush(RGB(255,255,255)); + + HRGN hrgn = NULL; + int regionType; + if(hCapture) { + hrgn = CreateRectRgn(0,0,0,0); + regionType = GetWindowRgn(hCapture, hrgn); + if (regionType != ERROR) { + // not layerd - fill the window region + FillRgn(hMaskDC, hrgn, hBr); + } + else { //layerd window (WS_EX_LAYERED) + BYTE bAlpha= 0; + COLORREF crKey=0; //0x00bbggrr + DWORD dwFlags=0; + if(GetLayeredWindowAttributes(hCapture,&crKey,&bAlpha,&dwFlags)) { + //per window transparency (like fading in a whole window). + if((dwFlags & LWA_ALPHA) == LWA_ALPHA) { + //Use bAlpha to determine the opacity of the layered window. + bFixAlpha = false; + } + if((dwFlags & LWA_COLORKEY) == LWA_COLORKEY) { + //Use crKey as the transparency color. + SetBkColor(hMemDC, crKey); + BitBlt(hMaskDC, 0, 0, size.cx, size.cy, hMemDC, 0, 0, SRCCOPY); + bInvert = true; + bFixAlpha = true; + } + } + else { + //per-pixel transparency (won't use the WM_PAINT ) + bFixAlpha = false; + } + } + } + else { //fill the desktop region + hrgn = CreateRectRgn(0,0,size.cx,size.cy); + FillRgn(hMaskDC, hrgn, hBr); + } + + if(bFixAlpha) { + FIBITMAP* dibMask = FIP->FI_CreateDIBFromHBITMAP(hMask); + if(bInvert) FIP->FI_Invert(dibMask); + FIBITMAP* dib8 = FIP->FI_ConvertTo8Bits(dibMask); + + //copy the dib8 alpha mask to dib32 main bitmap + FIP->FI_SetChannel(dib,dib8,FICC_ALPHA); + FIP->FI_Unload(dibMask); + FIP->FI_Unload(dib8); + } + + //clean up + DeleteObject(hBr); + if(hrgn) DeleteObject(hrgn); + DeleteDC(hMaskDC); + DeleteObject(hMask); + SelectObject(hMemDC, hOld); + DeleteDC(hMemDC); + if(!hDC) ReleaseDC(NULL, hScrDC); + DeleteObject(hBitmap); + #ifdef _DEBUG switch (FIP->FI_GetImageType(dib)){ case FIT_UNKNOWN: @@ -430,7 +430,7 @@ BOOL GetEncoderClsid(wchar_t *wchMimeType, CLSID& clsidEncoder) { BOOL bOk=FALSE; Gdiplus::GetImageEncodersSize(&uiNum,&uiSize); if(uiSize>0){ - Gdiplus::ImageCodecInfo* pImageCodecInfo=(Gdiplus::ImageCodecInfo *)new char[uiSize]; + Gdiplus::ImageCodecInfo* pImageCodecInfo=(Gdiplus::ImageCodecInfo*)mir_alloc(uiSize); if(pImageCodecInfo){ Gdiplus::GetImageEncoders(uiNum,uiSize,pImageCodecInfo); for( UINT i=0; i<uiNum; ++i){ @@ -439,8 +439,8 @@ BOOL GetEncoderClsid(wchar_t *wchMimeType, CLSID& clsidEncoder) { bOk=TRUE; } } + mir_free(pImageCodecInfo); } - delete pImageCodecInfo; } return bOk; } |