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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 static bool icc_profile_is_sRGB(const void* data, size_t length) { 108 class AutoCFDataRelease {
109 // found by inspection -- need a cleaner way to sniff a profile 109 CFDataRef fDR;
110 const size_t ICC_PROFILE_OFFSET_TO_SRGB_TAG = 52; 110 public:
111 AutoCFDataRelease(CFDataRef dr) : fDR(dr) {}
112 ~AutoCFDataRelease() { if (fDR) { CFRelease(fDR); } }
111 113
112 if (length >= ICC_PROFILE_OFFSET_TO_SRGB_TAG + 4) { 114 operator CFDataRef () { return fDR; }
113 return !memcmp((const char*)data + ICC_PROFILE_OFFSET_TO_SRGB_TAG, "sRGB ", 4); 115 };
116
117 static bool colorspace_is_sRGB(CGColorSpaceRef cs) {
118 #ifdef SK_BUILD_FOR_IOS
119 return true; // iOS seems to define itself to always return sRGB <reed>
120 #else
121 AutoCFDataRelease data(CGColorSpaceCopyICCProfile(cs));
122 if (data) {
123 // found by inspection -- need a cleaner way to sniff a profile
124 const CFIndex ICC_PROFILE_OFFSET_TO_SRGB_TAG = 52;
125
126 if (CFDataGetLength(data) >= ICC_PROFILE_OFFSET_TO_SRGB_TAG + 4) {
127 return !memcmp(CFDataGetBytePtr(data) + ICC_PROFILE_OFFSET_TO_SRGB_T AG, "sRGB", 4);
128 }
114 } 129 }
115 return false; 130 return false;
131 #endif
116 } 132 }
117 133
118 SkImageDecoder::Result SkImageDecoder_CG::onDecode(SkStream* stream, SkBitmap* b m, Mode mode) { 134 SkImageDecoder::Result SkImageDecoder_CG::onDecode(SkStream* stream, SkBitmap* b m, Mode mode) {
119 CGImageSourceRef imageSrc = SkStreamToCGImageSource(stream); 135 CGImageSourceRef imageSrc = SkStreamToCGImageSource(stream);
120 136
121 if (NULL == imageSrc) { 137 if (NULL == imageSrc) {
122 return kFailure; 138 return kFailure;
123 } 139 }
124 SkAutoTCallVProc<const void, CFRelease> arsrc(imageSrc); 140 SkAutoTCallVProc<const void, CFRelease> arsrc(imageSrc);
125 141
126 CGImageRef image = CGImageSourceCreateImageAtIndex(imageSrc, 0, NULL); 142 CGImageRef image = CGImageSourceCreateImageAtIndex(imageSrc, 0, NULL);
127 if (NULL == image) { 143 if (NULL == image) {
128 return kFailure; 144 return kFailure;
129 } 145 }
130 SkAutoTCallVProc<CGImage, CGImageRelease> arimage(image); 146 SkAutoTCallVProc<CGImage, CGImageRelease> arimage(image);
131 147
132 const int width = SkToInt(CGImageGetWidth(image)); 148 const int width = SkToInt(CGImageGetWidth(image));
133 const int height = SkToInt(CGImageGetHeight(image)); 149 const int height = SkToInt(CGImageGetHeight(image));
134 SkColorProfileType cpType = kLinear_SkColorProfileType; 150 SkColorProfileType cpType = kLinear_SkColorProfileType;
135 151
136 CGColorSpaceRef cs = CGImageGetColorSpace(image); 152 CGColorSpaceRef cs = CGImageGetColorSpace(image);
137 if (cs) { 153 if (cs) {
138 CGColorSpaceModel m = CGColorSpaceGetModel(cs); 154 CGColorSpaceModel m = CGColorSpaceGetModel(cs);
139 if (kCGColorSpaceModelRGB == m) { 155 if (kCGColorSpaceModelRGB == m && colorspace_is_sRGB(cs)) {
140 CFDataRef data = CGColorSpaceCopyICCProfile(cs); 156 cpType = kSRGB_SkColorProfileType;
141 if (data && icc_profile_is_sRGB(CFDataGetBytePtr(data), CFDataGetLen gth(data))) {
142 cpType = kSRGB_SkColorProfileType;
143 CFRelease(data);
144 }
145 } 157 }
146 } 158 }
147 159
148 bm->setInfo(SkImageInfo::MakeN32Premul(width, height, cpType)); 160 bm->setInfo(SkImageInfo::MakeN32Premul(width, height, cpType));
149 if (SkImageDecoder::kDecodeBounds_Mode == mode) { 161 if (SkImageDecoder::kDecodeBounds_Mode == mode) {
150 return kSuccess; 162 return kSuccess;
151 } 163 }
152 164
153 if (!this->allocPixelRef(bm, NULL)) { 165 if (!this->allocPixelRef(bm, NULL)) {
154 return kFailure; 166 return kFailure;
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 383
372 SkAutoTCallVProc<const void, CFRelease> arsrc(imageSrc); 384 SkAutoTCallVProc<const void, CFRelease> arsrc(imageSrc);
373 const CFStringRef name = CGImageSourceGetType(imageSrc); 385 const CFStringRef name = CGImageSourceGetType(imageSrc);
374 if (NULL == name) { 386 if (NULL == name) {
375 return SkImageDecoder::kUnknown_Format; 387 return SkImageDecoder::kUnknown_Format;
376 } 388 }
377 return UTType_to_Format(name); 389 return UTType_to_Format(name);
378 } 390 }
379 391
380 static SkImageDecoder_FormatReg gFormatReg(get_format_cg); 392 static SkImageDecoder_FormatReg gFormatReg(get_format_cg);
OLDNEW
« 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