aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/utils
diff options
context:
space:
mode:
authorGravatar scroggo@google.com <scroggo@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-11-12 16:18:43 +0000
committerGravatar scroggo@google.com <scroggo@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-11-12 16:18:43 +0000
commit426648ef313dff7030249f99dcd7bc8badcbe054 (patch)
tree5b90adcc4b1a83ca63851bdb2531671e03a9a503 /src/utils
parent2e0c79fb637c870780e7a041259e7bdc1443cd63 (diff)
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
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/mac/SkCreateCGImageRef.cpp30
1 files changed, 25 insertions, 5 deletions
diff --git a/src/utils/mac/SkCreateCGImageRef.cpp b/src/utils/mac/SkCreateCGImageRef.cpp
index df20ba930d..abad8cb440 100644
--- a/src/utils/mac/SkCreateCGImageRef.cpp
+++ b/src/utils/mac/SkCreateCGImageRef.cpp
@@ -36,31 +36,51 @@ static bool getBitmapInfo(const SkBitmap& bm,
*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;