Set sRGB flag for PNGs with an sRGB chunk
authormsarett <msarett@google.com>
Thu, 4 Feb 2016 23:37:58 +0000 (15:37 -0800)
committerCommit bot <commit-bot@chromium.org>
Thu, 4 Feb 2016 23:37:58 +0000 (15:37 -0800)
BUG=skia:3471
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1667823004

Review URL: https://codereview.chromium.org/1667823004

src/codec/SkCodecPriv.h
src/codec/SkPngCodec.cpp

index fa7d146..235c4e2 100644 (file)
@@ -117,7 +117,12 @@ inline bool valid_alpha(SkAlphaType dstAlpha, SkAlphaType srcAlpha) {
  * - otherwise match the src color type
  */
 inline bool conversion_possible(const SkImageInfo& dst, const SkImageInfo& src) {
-    if (dst.profileType() != src.profileType()) {
+    // FIXME: skbug.com/4895
+    // Currently, we treat both kLinear and ksRGB encoded images as if they are kLinear.
+    // This makes sense while we do not have proper support for ksRGB.  This is also
+    // the reason why we always allow the client to request kLinear.
+    if (dst.profileType() != src.profileType() &&
+            kLinear_SkColorProfileType != dst.profileType()) {
         return false;
     }
 
index 232373c..656df7d 100644 (file)
@@ -328,10 +328,13 @@ static bool read_header(SkStream* stream, SkPngChunkReader* chunkReader,
         *numberPassesPtr = numberPasses;
     }
 
-    // FIXME: Also need to check for sRGB ( https://bug.skia.org/3471 ).
+    SkColorProfileType profileType = kLinear_SkColorProfileType;
+    if (png_get_valid(png_ptr, info_ptr, PNG_INFO_sRGB)) {
+        profileType = kSRGB_SkColorProfileType;
+    }
 
     if (imageInfo) {
-        *imageInfo = SkImageInfo::Make(origWidth, origHeight, colorType, alphaType);
+        *imageInfo = SkImageInfo::Make(origWidth, origHeight, colorType, alphaType, profileType);
     }
     autoClean.detach();
     if (png_ptrp) {