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

Unified Diff: src/ports/SkImageDecoder_CG.cpp

Issue 676883003: flag imageinfo as srgb (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: fix copy/paste error in loop limits 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 | « src/core/SkImageInfo.cpp ('k') | tests/ImageIsOpaqueTest.cpp » ('j') | 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 73a95fc688e6a317a275e18e1f8d9c689f4a1b40..8d8d0c8b17a32d31a8763b66d460378bf224b06c 100644
--- a/src/ports/SkImageDecoder_CG.cpp
+++ b/src/ports/SkImageDecoder_CG.cpp
@@ -105,6 +105,16 @@ 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;
+
+ if (length >= ICC_PROFILE_OFFSET_TO_SRGB_TAG + 4) {
+ return !memcmp((const char*)data + ICC_PROFILE_OFFSET_TO_SRGB_TAG, "sRGB", 4);
+ }
+ return false;
+}
+
SkImageDecoder::Result SkImageDecoder_CG::onDecode(SkStream* stream, SkBitmap* bm, Mode mode) {
CGImageSourceRef imageSrc = SkStreamToCGImageSource(stream);
@@ -121,8 +131,21 @@ SkImageDecoder::Result SkImageDecoder_CG::onDecode(SkStream* stream, SkBitmap* b
const int width = SkToInt(CGImageGetWidth(image));
const int height = SkToInt(CGImageGetHeight(image));
+ SkColorProfileType cpType = kLinear_SkColorProfileType;
+
+ 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);
+ }
+ }
+ }
- bm->setInfo(SkImageInfo::MakeN32Premul(width, height));
+ bm->setInfo(SkImageInfo::MakeN32Premul(width, height, cpType));
if (SkImageDecoder::kDecodeBounds_Mode == mode) {
return kSuccess;
}
« no previous file with comments | « src/core/SkImageInfo.cpp ('k') | tests/ImageIsOpaqueTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698