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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 | 97 |
98 CGContextDrawImage(cg, CGRectMake(0, 0, width, height), image); | 98 CGContextDrawImage(cg, CGRectMake(0, 0, width, height), image); |
99 CGContextRelease(cg); | 99 CGContextRelease(cg); |
100 | 100 |
101 CGImageAlphaInfo info = CGImageGetAlphaInfo(image); | 101 CGImageAlphaInfo info = CGImageGetAlphaInfo(image); |
102 switch (info) { | 102 switch (info) { |
103 case kCGImageAlphaNone: | 103 case kCGImageAlphaNone: |
104 case kCGImageAlphaNoneSkipLast: | 104 case kCGImageAlphaNoneSkipLast: |
105 case kCGImageAlphaNoneSkipFirst: | 105 case kCGImageAlphaNoneSkipFirst: |
106 SkASSERT(SkBitmap::ComputeIsOpaque(*bm)); | 106 SkASSERT(SkBitmap::ComputeIsOpaque(*bm)); |
107 bm->setIsOpaque(true); | 107 bm->setAlphaType(kOpaque_SkAlphaType); |
108 break; | 108 break; |
109 default: | 109 default: |
110 // we don't know if we're opaque or not, so compute it. | 110 // we don't know if we're opaque or not, so compute it. |
111 bm->computeAndSetOpaquePredicate(); | 111 if (SkBitmap::ComputeIsOpaque(*bm)) { |
| 112 bm->setAlphaType(kOpaque_SkAlphaType); |
| 113 } |
112 } | 114 } |
113 if (!bm->isOpaque() && this->getRequireUnpremultipliedColors()) { | 115 if (!bm->isOpaque() && this->getRequireUnpremultipliedColors()) { |
114 // CGBitmapContext does not support unpremultiplied, so the image has be
en premultiplied. | 116 // CGBitmapContext does not support unpremultiplied, so the image has be
en premultiplied. |
115 // Convert to unpremultiplied. | 117 // Convert to unpremultiplied. |
116 for (int i = 0; i < width; ++i) { | 118 for (int i = 0; i < width; ++i) { |
117 for (int j = 0; j < height; ++j) { | 119 for (int j = 0; j < height; ++j) { |
118 uint32_t* addr = bm->getAddr32(i, j); | 120 uint32_t* addr = bm->getAddr32(i, j); |
119 *addr = unpremultiply_pmcolor(*addr); | 121 *addr = unpremultiply_pmcolor(*addr); |
120 } | 122 } |
121 } | 123 } |
| 124 bm->setAlphaType(kUnpremul_SkAlphaType); |
122 } | 125 } |
123 bm->unlockPixels(); | 126 bm->unlockPixels(); |
124 return true; | 127 return true; |
125 } | 128 } |
126 | 129 |
127 /////////////////////////////////////////////////////////////////////////////// | 130 /////////////////////////////////////////////////////////////////////////////// |
128 | 131 |
129 extern SkImageDecoder* image_decoder_from_stream(SkStreamRewindable*); | 132 extern SkImageDecoder* image_decoder_from_stream(SkStreamRewindable*); |
130 | 133 |
131 SkImageDecoder* SkImageDecoder::Factory(SkStreamRewindable* stream) { | 134 SkImageDecoder* SkImageDecoder::Factory(SkStreamRewindable* stream) { |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 | 297 |
295 SkAutoTCallVProc<const void, CFRelease> arsrc(imageSrc); | 298 SkAutoTCallVProc<const void, CFRelease> arsrc(imageSrc); |
296 const CFStringRef name = CGImageSourceGetType(imageSrc); | 299 const CFStringRef name = CGImageSourceGetType(imageSrc); |
297 if (NULL == name) { | 300 if (NULL == name) { |
298 return SkImageDecoder::kUnknown_Format; | 301 return SkImageDecoder::kUnknown_Format; |
299 } | 302 } |
300 return UTType_to_Format(name); | 303 return UTType_to_Format(name); |
301 } | 304 } |
302 | 305 |
303 static SkImageDecoder_FormatReg gFormatReg(get_format_cg); | 306 static SkImageDecoder_FormatReg gFormatReg(get_format_cg); |
OLD | NEW |