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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
98 char* row = (char*)bm->getPixels(); | 98 char* row = (char*)bm->getPixels(); |
99 for (int y = 0; y < bm->height(); ++y) { | 99 for (int y = 0; y < bm->height(); ++y) { |
100 proc(row, bm->width()); | 100 proc(row, bm->width()); |
101 row += bm->rowBytes(); | 101 row += bm->rowBytes(); |
102 } | 102 } |
103 bm->setAlphaType(kOpaque_SkAlphaType); | 103 bm->setAlphaType(kOpaque_SkAlphaType); |
104 } | 104 } |
105 | 105 |
106 #define BITMAP_INFO (kCGBitmapByteOrder32Big | kCGImageAlphaPremultipliedLast) | 106 #define BITMAP_INFO (kCGBitmapByteOrder32Big | kCGImageAlphaPremultipliedLast) |
107 | 107 |
108 #ifndef SK_BUILD_FOR_IOS | |
108 static bool icc_profile_is_sRGB(const void* data, size_t length) { | 109 static bool icc_profile_is_sRGB(const void* data, size_t length) { |
mtklein
2014/11/11 15:08:51
Seems like a good candidate to inline into colorsp
reed1
2014/11/11 15:19:05
Done.
| |
109 // found by inspection -- need a cleaner way to sniff a profile | 110 // found by inspection -- need a cleaner way to sniff a profile |
110 const size_t ICC_PROFILE_OFFSET_TO_SRGB_TAG = 52; | 111 const size_t ICC_PROFILE_OFFSET_TO_SRGB_TAG = 52; |
111 | 112 |
112 if (length >= ICC_PROFILE_OFFSET_TO_SRGB_TAG + 4) { | 113 if (length >= ICC_PROFILE_OFFSET_TO_SRGB_TAG + 4) { |
113 return !memcmp((const char*)data + ICC_PROFILE_OFFSET_TO_SRGB_TAG, "sRGB ", 4); | 114 return !memcmp((const char*)data + ICC_PROFILE_OFFSET_TO_SRGB_TAG, "sRGB ", 4); |
114 } | 115 } |
115 return false; | 116 return false; |
116 } | 117 } |
118 #endif | |
119 | |
120 class AutoCFDataRelease { | |
121 CFDataRef fDR; | |
122 public: | |
123 AutoCFDataRelease(CFDataRef dr) : fDR(dr) {} | |
124 ~AutoCFDataRelease() { if (fDR) { CFRelease(fDR); } } | |
125 | |
126 operator CFDataRef () { return fDR; } | |
127 CFDataRef get() { return fDR; } | |
mtklein
2014/11/11 15:08:52
get() is dead?
reed1
2014/11/11 15:19:05
Done.
| |
128 }; | |
129 | |
130 static bool colorspace_is_sRGB(CGColorSpaceRef cs) { | |
131 #ifdef SK_BUILD_FOR_IOS | |
132 return true; // iOS seems to define itself to always return sRGB...I thin k | |
mtklein
2014/11/11 15:08:52
I think -> reed thinks?
reed1
2014/11/11 15:19:05
Done.
| |
133 #else | |
134 AutoCFDataRelease data(CGColorSpaceCopyICCProfile(cs)); | |
135 if (data && icc_profile_is_sRGB(CFDataGetBytePtr(data), CFDataGetLength(data ))) { | |
136 return true; | |
137 } | |
138 return false; | |
139 #endif | |
140 } | |
117 | 141 |
118 SkImageDecoder::Result SkImageDecoder_CG::onDecode(SkStream* stream, SkBitmap* b m, Mode mode) { | 142 SkImageDecoder::Result SkImageDecoder_CG::onDecode(SkStream* stream, SkBitmap* b m, Mode mode) { |
119 CGImageSourceRef imageSrc = SkStreamToCGImageSource(stream); | 143 CGImageSourceRef imageSrc = SkStreamToCGImageSource(stream); |
120 | 144 |
121 if (NULL == imageSrc) { | 145 if (NULL == imageSrc) { |
122 return kFailure; | 146 return kFailure; |
123 } | 147 } |
124 SkAutoTCallVProc<const void, CFRelease> arsrc(imageSrc); | 148 SkAutoTCallVProc<const void, CFRelease> arsrc(imageSrc); |
125 | 149 |
126 CGImageRef image = CGImageSourceCreateImageAtIndex(imageSrc, 0, NULL); | 150 CGImageRef image = CGImageSourceCreateImageAtIndex(imageSrc, 0, NULL); |
127 if (NULL == image) { | 151 if (NULL == image) { |
128 return kFailure; | 152 return kFailure; |
129 } | 153 } |
130 SkAutoTCallVProc<CGImage, CGImageRelease> arimage(image); | 154 SkAutoTCallVProc<CGImage, CGImageRelease> arimage(image); |
131 | 155 |
132 const int width = SkToInt(CGImageGetWidth(image)); | 156 const int width = SkToInt(CGImageGetWidth(image)); |
133 const int height = SkToInt(CGImageGetHeight(image)); | 157 const int height = SkToInt(CGImageGetHeight(image)); |
134 SkColorProfileType cpType = kLinear_SkColorProfileType; | 158 SkColorProfileType cpType = kLinear_SkColorProfileType; |
135 | 159 |
136 CGColorSpaceRef cs = CGImageGetColorSpace(image); | 160 CGColorSpaceRef cs = CGImageGetColorSpace(image); |
137 if (cs) { | 161 if (cs) { |
138 CGColorSpaceModel m = CGColorSpaceGetModel(cs); | 162 CGColorSpaceModel m = CGColorSpaceGetModel(cs); |
139 if (kCGColorSpaceModelRGB == m) { | 163 if (kCGColorSpaceModelRGB == m && colorspace_is_sRGB(cs)) { |
140 CFDataRef data = CGColorSpaceCopyICCProfile(cs); | 164 cpType = kSRGB_SkColorProfileType; |
141 if (data && icc_profile_is_sRGB(CFDataGetBytePtr(data), CFDataGetLen gth(data))) { | |
142 cpType = kSRGB_SkColorProfileType; | |
143 CFRelease(data); | |
144 } | |
145 } | 165 } |
146 } | 166 } |
147 | 167 |
148 bm->setInfo(SkImageInfo::MakeN32Premul(width, height, cpType)); | 168 bm->setInfo(SkImageInfo::MakeN32Premul(width, height, cpType)); |
149 if (SkImageDecoder::kDecodeBounds_Mode == mode) { | 169 if (SkImageDecoder::kDecodeBounds_Mode == mode) { |
150 return kSuccess; | 170 return kSuccess; |
151 } | 171 } |
152 | 172 |
153 if (!this->allocPixelRef(bm, NULL)) { | 173 if (!this->allocPixelRef(bm, NULL)) { |
154 return kFailure; | 174 return kFailure; |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
371 | 391 |
372 SkAutoTCallVProc<const void, CFRelease> arsrc(imageSrc); | 392 SkAutoTCallVProc<const void, CFRelease> arsrc(imageSrc); |
373 const CFStringRef name = CGImageSourceGetType(imageSrc); | 393 const CFStringRef name = CGImageSourceGetType(imageSrc); |
374 if (NULL == name) { | 394 if (NULL == name) { |
375 return SkImageDecoder::kUnknown_Format; | 395 return SkImageDecoder::kUnknown_Format; |
376 } | 396 } |
377 return UTType_to_Format(name); | 397 return UTType_to_Format(name); |
378 } | 398 } |
379 | 399 |
380 static SkImageDecoder_FormatReg gFormatReg(get_format_cg); | 400 static SkImageDecoder_FormatReg gFormatReg(get_format_cg); |
OLD | NEW |