| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 #include "SkCGUtils.h" | 8 #include "SkCGUtils.h" |
| 9 #include "SkBitmap.h" | 9 #include "SkBitmap.h" |
| 10 #include "SkColorPriv.h" | 10 #include "SkColorPriv.h" |
| 11 | 11 |
| 12 static void SkBitmap_ReleaseInfo(void* info, const void* pixelData, size_t size)
{ | 12 static void SkBitmap_ReleaseInfo(void* info, const void* pixelData, size_t size)
{ |
| 13 SkBitmap* bitmap = reinterpret_cast<SkBitmap*>(info); | 13 SkBitmap* bitmap = reinterpret_cast<SkBitmap*>(info); |
| 14 delete bitmap; | 14 delete bitmap; |
| 15 } | 15 } |
| 16 | 16 |
| 17 #define HAS_ARGB_SHIFTS(a, r, g, b) \ | |
| 18 (SK_A32_SHIFT == (a) && SK_R32_SHIFT == (r) \ | |
| 19 && SK_G32_SHIFT == (g) && SK_B32_SHIFT == (b)) | |
| 20 | |
| 21 static bool getBitmapInfo(const SkBitmap& bm, | 17 static bool getBitmapInfo(const SkBitmap& bm, |
| 22 size_t* bitsPerComponent, | 18 size_t* bitsPerComponent, |
| 23 CGBitmapInfo* info, | 19 CGBitmapInfo* info, |
| 24 bool* upscaleTo32) { | 20 bool* upscaleTo32) { |
| 25 if (upscaleTo32) { | 21 if (upscaleTo32) { |
| 26 *upscaleTo32 = false; | 22 *upscaleTo32 = false; |
| 27 } | 23 } |
| 28 | 24 |
| 29 switch (bm.config()) { | 25 switch (bm.config()) { |
| 30 case SkBitmap::kRGB_565_Config: | 26 case SkBitmap::kRGB_565_Config: |
| 31 if (upscaleTo32) { | 27 if (upscaleTo32) { |
| 32 *upscaleTo32 = true; | 28 *upscaleTo32 = true; |
| 33 } | 29 } |
| 34 // fall through | 30 // fall through |
| 35 case SkBitmap::kARGB_8888_Config: | 31 case SkBitmap::kARGB_8888_Config: |
| 36 *bitsPerComponent = 8; | 32 *bitsPerComponent = 8; |
| 37 #if defined(SK_CPU_LENDIAN) && HAS_ARGB_SHIFTS(24, 0, 8, 16) \ | 33 #if SK_PMCOLOR_BYTE_ORDER(R,G,B,A) |
| 38 || defined(SK_CPU_BENDIAN) && HAS_ARGB_SHIFTS(0, 24, 16, 8) | |
| 39 *info = kCGBitmapByteOrder32Big; | 34 *info = kCGBitmapByteOrder32Big; |
| 40 if (bm.isOpaque()) { | 35 if (bm.isOpaque()) { |
| 41 *info |= kCGImageAlphaNoneSkipLast; | 36 *info |= kCGImageAlphaNoneSkipLast; |
| 42 } else { | 37 } else { |
| 43 *info |= kCGImageAlphaPremultipliedLast; | 38 *info |= kCGImageAlphaPremultipliedLast; |
| 44 } | 39 } |
| 45 #elif defined(SK_CPU_LENDIAN) && HAS_ARGB_SHIFTS(24, 16, 8, 0) \ | 40 #elif SK_PMCOLOR_BYTE_ORDER(B,G,R,A) |
| 46 || defined(SK_CPU_BENDIAN) && HAS_ARGB_SHIFTS(24, 16, 8, 0) | |
| 47 // Matches the CGBitmapInfo that Apple recommends for best | 41 // Matches the CGBitmapInfo that Apple recommends for best |
| 48 // performance, used by google chrome. | 42 // performance, used by google chrome. |
| 49 *info = kCGBitmapByteOrder32Little; | 43 *info = kCGBitmapByteOrder32Little; |
| 50 if (bm.isOpaque()) { | 44 if (bm.isOpaque()) { |
| 51 *info |= kCGImageAlphaNoneSkipFirst; | 45 *info |= kCGImageAlphaNoneSkipFirst; |
| 52 } else { | 46 } else { |
| 53 *info |= kCGImageAlphaPremultipliedFirst; | 47 *info |= kCGImageAlphaPremultipliedFirst; |
| 54 } | 48 } |
| 55 #else | 49 #else |
| 56 // ...add more formats as required... | 50 // ...add more formats as required... |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 copy = new SkBitmap; | 95 copy = new SkBitmap; |
| 102 // here we make a ceep copy of the pixels, since CG won't take our | 96 // here we make a ceep copy of the pixels, since CG won't take our |
| 103 // 565 directly | 97 // 565 directly |
| 104 bm.copyTo(copy, SkBitmap::kARGB_8888_Config); | 98 bm.copyTo(copy, SkBitmap::kARGB_8888_Config); |
| 105 } else { | 99 } else { |
| 106 copy = new SkBitmap(bm); | 100 copy = new SkBitmap(bm); |
| 107 } | 101 } |
| 108 return copy; | 102 return copy; |
| 109 } | 103 } |
| 110 | 104 |
| 111 #undef HAS_ARGB_SHIFTS | |
| 112 | |
| 113 CGImageRef SkCreateCGImageRefWithColorspace(const SkBitmap& bm, | 105 CGImageRef SkCreateCGImageRefWithColorspace(const SkBitmap& bm, |
| 114 CGColorSpaceRef colorSpace) { | 106 CGColorSpaceRef colorSpace) { |
| 115 size_t bitsPerComponent SK_INIT_TO_AVOID_WARNING; | 107 size_t bitsPerComponent SK_INIT_TO_AVOID_WARNING; |
| 116 CGBitmapInfo info SK_INIT_TO_AVOID_WARNING; | 108 CGBitmapInfo info SK_INIT_TO_AVOID_WARNING; |
| 117 | 109 |
| 118 SkBitmap* bitmap = prepareForImageRef(bm, &bitsPerComponent, &info); | 110 SkBitmap* bitmap = prepareForImageRef(bm, &bitsPerComponent, &info); |
| 119 if (NULL == bitmap) { | 111 if (NULL == bitmap) { |
| 120 return NULL; | 112 return NULL; |
| 121 } | 113 } |
| 122 | 114 |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 CGColorSpaceRelease(cs); | 223 CGColorSpaceRelease(cs); |
| 232 | 224 |
| 233 if (ctx) { | 225 if (ctx) { |
| 234 CGContextDrawPDFPage(ctx, page); | 226 CGContextDrawPDFPage(ctx, page); |
| 235 CGContextRelease(ctx); | 227 CGContextRelease(ctx); |
| 236 } | 228 } |
| 237 | 229 |
| 238 output->swap(bitmap); | 230 output->swap(bitmap); |
| 239 return true; | 231 return true; |
| 240 } | 232 } |
| OLD | NEW |