Tell CG ImageEncoder that a bitmap is opaque if it is.
Review URL: https://codereview.appspot.com/6819110
git-svn-id: http://skia.googlecode.com/svn/trunk@6378 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/utils/mac/SkCreateCGImageRef.cpp b/src/utils/mac/SkCreateCGImageRef.cpp
index df20ba9..abad8cb 100644
--- a/src/utils/mac/SkCreateCGImageRef.cpp
+++ b/src/utils/mac/SkCreateCGImageRef.cpp
@@ -36,31 +36,51 @@
*bitsPerComponent = 8;
#if defined(SK_CPU_LENDIAN) && HAS_ARGB_SHIFTS(24, 0, 8, 16) \
|| defined(SK_CPU_BENDIAN) && HAS_ARGB_SHIFTS(0, 24, 16, 8)
- *info = kCGBitmapByteOrder32Big | kCGImageAlphaPremultipliedLast;
+ *info = kCGBitmapByteOrder32Big;
+ if (bm.isOpaque()) {
+ *info |= kCGImageAlphaNoneSkipLast;
+ } else {
+ *info |= kCGImageAlphaPremultipliedLast;
+ }
#elif defined(SK_CPU_LENDIAN) && HAS_ARGB_SHIFTS(24, 16, 8, 0) \
|| defined(SK_CPU_BENDIAN) && HAS_ARGB_SHIFTS(24, 16, 8, 0)
// Matches the CGBitmapInfo that Apple recommends for best
// performance, used by google chrome.
- *info = kCGBitmapByteOrder32Little | kCGImageAlphaPremultipliedFirst;
+ *info = kCGBitmapByteOrder32Little;
+ if (bm.isOpaque()) {
+ *info |= kCGImageAlphaNoneSkipFirst;
+ } else {
+ *info |= kCGImageAlphaPremultipliedFirst;
+ }
#else
// ...add more formats as required...
#warning Cannot convert SkBitmap to CGImageRef with these shiftmasks. \
This will probably not work.
// Legacy behavior. Perhaps turn this into an error at some
// point.
- *info = kCGBitmapByteOrder32Big | kCGImageAlphaPremultipliedLast;
+ *info = kCGBitmapByteOrder32Big;
+ if (bm.isOpaque()) {
+ *info |= kCGImageAlphaNoneSkipLast;
+ } else {
+ *info |= kCGImageAlphaPremultipliedLast;
+ }
#endif
break;
#if 0
case SkBitmap::kRGB_565_Config:
// doesn't see quite right. Are they thinking 1555?
*bitsPerComponent = 5;
- *info = kCGBitmapByteOrder16Little;
+ *info = kCGBitmapByteOrder16Little | kCGImageAlphaNone;
break;
#endif
case SkBitmap::kARGB_4444_Config:
*bitsPerComponent = 4;
- *info = kCGBitmapByteOrder16Little | kCGImageAlphaPremultipliedLast;
+ *info = kCGBitmapByteOrder16Little;
+ if (bm.isOpaque()) {
+ *info |= kCGImageAlphaNoneSkipLast;
+ } else {
+ *info |= kCGImageAlphaPremultipliedLast;
+ }
break;
default:
return false;