Move reused code to the separate function

Checking whether alpha info flag contains one of
the constants representing image/bitmap with alpha
channel is done more than once in the code so this
check can be moved to a dedicated function.
This commit is contained in:
Artur Wieczorek
2019-10-01 00:12:32 +02:00
parent 01b769e975
commit d0311cec8d

View File

@@ -41,6 +41,11 @@ CGDataProviderRef wxMacCGDataProviderCreateWithMemoryBuffer( const wxMemoryBuffe
// If raw bitmap data needs to be accessed, then even the NSImage has to be
// rendered into a CGBitmapContextRef
static inline bool IsCGImageAlphaFlag(CGImageAlphaInfo alphaInfo)
{
return !(alphaInfo == kCGImageAlphaNone || alphaInfo == kCGImageAlphaNoneSkipFirst || alphaInfo == kCGImageAlphaNoneSkipLast);
}
class WXDLLEXPORT wxBitmapRefData: public wxGDIRefData
{
friend class WXDLLIMPEXP_FWD_CORE wxIcon;
@@ -238,14 +243,9 @@ bool wxBitmapRefData::Create(CGImageRef image, double scale)
size_t bytesPerRow = GetBestBytesPerRow(width * 4);
CGImageAlphaInfo alpha = CGImageGetAlphaInfo(image);
if (alpha == kCGImageAlphaNone || alpha == kCGImageAlphaNoneSkipFirst || alpha == kCGImageAlphaNoneSkipLast)
{
m_hBitmap = CGBitmapContextCreate(NULL, width, height, 8, bytesPerRow, wxMacGetGenericRGBColorSpace(), kCGImageAlphaNoneSkipFirst);
}
else
{
m_hBitmap = CGBitmapContextCreate(NULL, width, height, 8, bytesPerRow, wxMacGetGenericRGBColorSpace(), kCGImageAlphaPremultipliedFirst);
}
bool hasAlpha = IsCGImageAlphaFlag(alpha);
m_hBitmap = CGBitmapContextCreate(NULL, width, height, 8, bytesPerRow, wxMacGetGenericRGBColorSpace(),
hasAlpha ? kCGImageAlphaPremultipliedFirst : kCGImageAlphaNoneSkipFirst);
wxCHECK_MSG(m_hBitmap, false, wxT("Unable to create CGBitmapContext context"));
CGRect rect = CGRectMake(0, 0, width, height);
CGContextDrawImage(m_hBitmap, rect, image);
@@ -341,7 +341,7 @@ bool wxBitmapRefData::HasAlpha() const
if ( m_hBitmap )
{
CGImageAlphaInfo alpha = CGBitmapContextGetAlphaInfo(m_hBitmap);
return !(alpha == kCGImageAlphaNone || alpha == kCGImageAlphaNoneSkipFirst || alpha == kCGImageAlphaNoneSkipLast);
return IsCGImageAlphaFlag(alpha);
}
else
{