| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2008 The Android Open Source Project | 2 * Copyright 2008 The Android Open Source Project |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "SkCGUtils.h" | 8 #include "SkCGUtils.h" |
| 9 #include "SkColorPriv.h" | 9 #include "SkColorPriv.h" |
| 10 #include "SkImageDecoder.h" | 10 #include "SkImageDecoder.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 CGImageSourceRef imageSrc = CGImageSourceCreateWithDataProvider(data, 0); | 43 CGImageSourceRef imageSrc = CGImageSourceCreateWithDataProvider(data, 0); |
| 44 CGDataProviderRelease(data); | 44 CGDataProviderRelease(data); |
| 45 return imageSrc; | 45 return imageSrc; |
| 46 } | 46 } |
| 47 | 47 |
| 48 class SkImageDecoder_CG : public SkImageDecoder { | 48 class SkImageDecoder_CG : public SkImageDecoder { |
| 49 protected: | 49 protected: |
| 50 virtual bool onDecode(SkStream* stream, SkBitmap* bm, Mode); | 50 virtual bool onDecode(SkStream* stream, SkBitmap* bm, Mode); |
| 51 }; | 51 }; |
| 52 | 52 |
| 53 // Returns an unpremultiplied version of color. It will have the same ordering a
nd size as an | |
| 54 // SkPMColor, but the alpha will not be premultiplied. | |
| 55 static SkPMColor unpremultiply_pmcolor(SkPMColor color) { | |
| 56 U8CPU a = SkGetPackedA32(color); | |
| 57 const SkUnPreMultiply::Scale scale = SkUnPreMultiply::GetScale(a); | |
| 58 return SkPackARGB32NoCheck(a, | |
| 59 SkUnPreMultiply::ApplyScale(scale, SkGetPackedR32
(color)), | |
| 60 SkUnPreMultiply::ApplyScale(scale, SkGetPackedG32
(color)), | |
| 61 SkUnPreMultiply::ApplyScale(scale, SkGetPackedB32
(color))); | |
| 62 } | |
| 63 | |
| 64 #define BITMAP_INFO (kCGBitmapByteOrder32Big | kCGImageAlphaPremultipliedLast) | 53 #define BITMAP_INFO (kCGBitmapByteOrder32Big | kCGImageAlphaPremultipliedLast) |
| 65 | 54 |
| 66 bool SkImageDecoder_CG::onDecode(SkStream* stream, SkBitmap* bm, Mode mode) { | 55 bool SkImageDecoder_CG::onDecode(SkStream* stream, SkBitmap* bm, Mode mode) { |
| 67 CGImageSourceRef imageSrc = SkStreamToCGImageSource(stream); | 56 CGImageSourceRef imageSrc = SkStreamToCGImageSource(stream); |
| 68 | 57 |
| 69 if (NULL == imageSrc) { | 58 if (NULL == imageSrc) { |
| 70 return false; | 59 return false; |
| 71 } | 60 } |
| 72 SkAutoTCallVProc<const void, CFRelease> arsrc(imageSrc); | 61 SkAutoTCallVProc<const void, CFRelease> arsrc(imageSrc); |
| 73 | 62 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 if (SkBitmap::ComputeIsOpaque(*bm)) { | 100 if (SkBitmap::ComputeIsOpaque(*bm)) { |
| 112 bm->setAlphaType(kOpaque_SkAlphaType); | 101 bm->setAlphaType(kOpaque_SkAlphaType); |
| 113 } | 102 } |
| 114 } | 103 } |
| 115 if (!bm->isOpaque() && this->getRequireUnpremultipliedColors()) { | 104 if (!bm->isOpaque() && this->getRequireUnpremultipliedColors()) { |
| 116 // CGBitmapContext does not support unpremultiplied, so the image has be
en premultiplied. | 105 // CGBitmapContext does not support unpremultiplied, so the image has be
en premultiplied. |
| 117 // Convert to unpremultiplied. | 106 // Convert to unpremultiplied. |
| 118 for (int i = 0; i < width; ++i) { | 107 for (int i = 0; i < width; ++i) { |
| 119 for (int j = 0; j < height; ++j) { | 108 for (int j = 0; j < height; ++j) { |
| 120 uint32_t* addr = bm->getAddr32(i, j); | 109 uint32_t* addr = bm->getAddr32(i, j); |
| 121 *addr = unpremultiply_pmcolor(*addr); | 110 *addr = SkUnPreMultiply::UnPreMultiplyPreservingByteOrder(*addr)
; |
| 122 } | 111 } |
| 123 } | 112 } |
| 124 bm->setAlphaType(kUnpremul_SkAlphaType); | 113 bm->setAlphaType(kUnpremul_SkAlphaType); |
| 125 } | 114 } |
| 126 bm->unlockPixels(); | 115 bm->unlockPixels(); |
| 127 return true; | 116 return true; |
| 128 } | 117 } |
| 129 | 118 |
| 130 /////////////////////////////////////////////////////////////////////////////// | 119 /////////////////////////////////////////////////////////////////////////////// |
| 131 | 120 |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 | 286 |
| 298 SkAutoTCallVProc<const void, CFRelease> arsrc(imageSrc); | 287 SkAutoTCallVProc<const void, CFRelease> arsrc(imageSrc); |
| 299 const CFStringRef name = CGImageSourceGetType(imageSrc); | 288 const CFStringRef name = CGImageSourceGetType(imageSrc); |
| 300 if (NULL == name) { | 289 if (NULL == name) { |
| 301 return SkImageDecoder::kUnknown_Format; | 290 return SkImageDecoder::kUnknown_Format; |
| 302 } | 291 } |
| 303 return UTType_to_Format(name); | 292 return UTType_to_Format(name); |
| 304 } | 293 } |
| 305 | 294 |
| 306 static SkImageDecoder_FormatReg gFormatReg(get_format_cg); | 295 static SkImageDecoder_FormatReg gFormatReg(get_format_cg); |
| OLD | NEW |