Fix creating CGImage from wxBitmap

For internal purposes wxBitmap with mask should be converted to CGImage
with alpha values only (with no mask). This is i.a. needed to assure
compatibility of wxGraphicsBitmap format with other ports where these
bitmaps are in pure ARGB format.
This commit is contained in:
Artur Wieczorek 2021-02-08 18:56:10 +01:00
parent d4e5adf5d6
commit e74cc53775

View File

@ -1,3 +1,7 @@
/////////////////////////////////////////////////////////////////////////////
// Name: src/osx/core/bitmap.cpp
// Purpose: wxBitmap
@ -672,13 +676,25 @@ CGImageRef wxBitmapRefData::CreateCGImage() const
if ( m_bitmapMask )
{
// First apply mask to image
CGImageRef imageMask = CGBitmapContextCreateImage(m_bitmapMask->GetHBITMAP());
CGImageRef imageBmp = image;
CGImageRef imageMasked = CGImageCreateWithMask(image, imageMask);
image = CGImageCreateWithMask(imageBmp, imageMask);
// Convert masked image to plain ARGB image without mask
int w = GetWidth();
int h = GetHeight();
CGContextRef hBmpAlpha = CGBitmapContextCreate(NULL, w, h, 8, GetBytesPerRow(), wxMacGetGenericRGBColorSpace(), kCGImageAlphaPremultipliedFirst);
CGRect r = CGRectMake(0, 0, w, h);
CGContextDrawImage(hBmpAlpha, r, imageMasked);
CGContextTranslateCTM(hBmpAlpha, 0, h);
CGContextScaleCTM(hBmpAlpha, GetScaleFactor(), -GetScaleFactor());
CGImageRelease(imageBmp);
CGImageRelease(imageMasked);
CGImageRelease(imageMask);
CGImageRelease(image);
image = CGBitmapContextCreateImage(hBmpAlpha);
CGContextRelease(hBmpAlpha);
}
}
else