Index: src/ports/SkImageDecoder_CG.cpp |
diff --git a/src/ports/SkImageDecoder_CG.cpp b/src/ports/SkImageDecoder_CG.cpp |
index 8d8d0c8b17a32d31a8763b66d460378bf224b06c..87476abf5c423914d772211a4e68f06379f238ef 100644 |
--- a/src/ports/SkImageDecoder_CG.cpp |
+++ b/src/ports/SkImageDecoder_CG.cpp |
@@ -105,6 +105,7 @@ static void force_opaque(SkBitmap* bm) { |
#define BITMAP_INFO (kCGBitmapByteOrder32Big | kCGImageAlphaPremultipliedLast) |
+#ifndef SK_BUILD_FOR_IOS |
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.
|
// found by inspection -- need a cleaner way to sniff a profile |
const size_t ICC_PROFILE_OFFSET_TO_SRGB_TAG = 52; |
@@ -114,6 +115,29 @@ static bool icc_profile_is_sRGB(const void* data, size_t length) { |
} |
return false; |
} |
+#endif |
+ |
+class AutoCFDataRelease { |
+ CFDataRef fDR; |
+public: |
+ AutoCFDataRelease(CFDataRef dr) : fDR(dr) {} |
+ ~AutoCFDataRelease() { if (fDR) { CFRelease(fDR); } } |
+ |
+ operator CFDataRef () { return fDR; } |
+ CFDataRef get() { return fDR; } |
mtklein
2014/11/11 15:08:52
get() is dead?
reed1
2014/11/11 15:19:05
Done.
|
+}; |
+ |
+static bool colorspace_is_sRGB(CGColorSpaceRef cs) { |
+#ifdef SK_BUILD_FOR_IOS |
+ return true; // iOS seems to define itself to always return sRGB...I think |
mtklein
2014/11/11 15:08:52
I think -> reed thinks?
reed1
2014/11/11 15:19:05
Done.
|
+#else |
+ AutoCFDataRelease data(CGColorSpaceCopyICCProfile(cs)); |
+ if (data && icc_profile_is_sRGB(CFDataGetBytePtr(data), CFDataGetLength(data))) { |
+ return true; |
+ } |
+ return false; |
+#endif |
+} |
SkImageDecoder::Result SkImageDecoder_CG::onDecode(SkStream* stream, SkBitmap* bm, Mode mode) { |
CGImageSourceRef imageSrc = SkStreamToCGImageSource(stream); |
@@ -136,12 +160,8 @@ SkImageDecoder::Result SkImageDecoder_CG::onDecode(SkStream* stream, SkBitmap* b |
CGColorSpaceRef cs = CGImageGetColorSpace(image); |
if (cs) { |
CGColorSpaceModel m = CGColorSpaceGetModel(cs); |
- if (kCGColorSpaceModelRGB == m) { |
- CFDataRef data = CGColorSpaceCopyICCProfile(cs); |
- if (data && icc_profile_is_sRGB(CFDataGetBytePtr(data), CFDataGetLength(data))) { |
- cpType = kSRGB_SkColorProfileType; |
- CFRelease(data); |
- } |
+ if (kCGColorSpaceModelRGB == m && colorspace_is_sRGB(cs)) { |
+ cpType = kSRGB_SkColorProfileType; |
} |
} |