Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(815)

Unified Diff: src/ports/SkImageDecoder_CG.cpp

Issue 712363003: guard call to CGColorSpaceCopyICCProfile in case we're building for iOS (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/ports/SkImageDecoder_CG.cpp
diff --git a/src/ports/SkImageDecoder_CG.cpp b/src/ports/SkImageDecoder_CG.cpp
index 8d8d0c8b17a32d31a8763b66d460378bf224b06c..eb2b46a080f72455100d6b16162e78cff8c22004 100644
--- a/src/ports/SkImageDecoder_CG.cpp
+++ b/src/ports/SkImageDecoder_CG.cpp
@@ -105,14 +105,30 @@ static void force_opaque(SkBitmap* bm) {
#define BITMAP_INFO (kCGBitmapByteOrder32Big | kCGImageAlphaPremultipliedLast)
-static bool icc_profile_is_sRGB(const void* data, size_t length) {
- // found by inspection -- need a cleaner way to sniff a profile
- const size_t ICC_PROFILE_OFFSET_TO_SRGB_TAG = 52;
+class AutoCFDataRelease {
+ CFDataRef fDR;
+public:
+ AutoCFDataRelease(CFDataRef dr) : fDR(dr) {}
+ ~AutoCFDataRelease() { if (fDR) { CFRelease(fDR); } }
+
+ operator CFDataRef () { return fDR; }
+};
- if (length >= ICC_PROFILE_OFFSET_TO_SRGB_TAG + 4) {
- return !memcmp((const char*)data + ICC_PROFILE_OFFSET_TO_SRGB_TAG, "sRGB", 4);
+static bool colorspace_is_sRGB(CGColorSpaceRef cs) {
+#ifdef SK_BUILD_FOR_IOS
+ return true; // iOS seems to define itself to always return sRGB <reed>
+#else
+ AutoCFDataRelease data(CGColorSpaceCopyICCProfile(cs));
+ if (data) {
+ // found by inspection -- need a cleaner way to sniff a profile
+ const CFIndex ICC_PROFILE_OFFSET_TO_SRGB_TAG = 52;
+
+ if (CFDataGetLength(data) >= ICC_PROFILE_OFFSET_TO_SRGB_TAG + 4) {
+ return !memcmp(CFDataGetBytePtr(data) + ICC_PROFILE_OFFSET_TO_SRGB_TAG, "sRGB", 4);
+ }
}
return false;
+#endif
}
SkImageDecoder::Result SkImageDecoder_CG::onDecode(SkStream* stream, SkBitmap* bm, Mode mode) {
@@ -136,12 +152,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;
}
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698