Prefer F16 in SkAndroidCodec for high precision images
authorMatt Sarett <msarett@google.com>
Wed, 14 Dec 2016 15:23:41 +0000 (10:23 -0500)
committerSkia Commit-Bot <skia-commit-bot@chromium.org>
Wed, 14 Dec 2016 15:59:15 +0000 (15:59 +0000)
Adapted from:
https://googleplex-android-review.git.corp.google.com/#/c/1707531/

TBR=djsollen@google.com
BUG=skia:

Change-Id: I21b99e8452e728aed70e8913677c253c1ae9f751
Reviewed-on: https://skia-review.googlesource.com/6023
Commit-Queue: Matt Sarett <msarett@google.com>
Reviewed-by: Leon Scroggins <scroggo@google.com>
include/codec/SkAndroidCodec.h
src/codec/SkAndroidCodec.cpp

index ecf0a08..e30a2aa 100644 (file)
@@ -56,9 +56,13 @@ public:
     /**
      *  @param requestedColorType Color type requested by the client
      *
-     *  If it is possible to decode to requestedColorType, this returns
-     *  requestedColorType.  Otherwise, this returns whichever color type
-     *  is suggested by the codec as the best match for the encoded data.
+     *  |requestedColorType| may be overriden.  We will default to kF16
+     *  for high precision images and kIndex8 for GIF and WBMP.
+     *
+     *  In the general case, if it is possible to decode to
+     *  |requestedColorType|, this returns |requestedColorType|.
+     *  Otherwise, this returns a color type that is an appropriate
+     *  match for the the encoded data.
      */
     SkColorType computeOutputColorType(SkColorType requestedColorType);
 
index 5dddfe3..a3daeae 100644 (file)
@@ -70,10 +70,13 @@ SkColorType SkAndroidCodec::computeOutputColorType(SkColorType requestedColorTyp
     }
 
     SkColorType suggestedColorType = this->getInfo().colorType();
+    bool highPrecision = fCodec->getEncodedInfo().bitsPerComponent() > 8;
     switch (requestedColorType) {
         case kARGB_4444_SkColorType:
-        case kN32_SkColorType:
             return kN32_SkColorType;
+        case kN32_SkColorType:
+            // F16 is the Android default for high precision images.
+            return highPrecision ? kRGBA_F16_SkColorType : kN32_SkColorType;
         case kIndex_8_SkColorType:
             if (kIndex_8_SkColorType == suggestedColorType) {
                 return kIndex_8_SkColorType;
@@ -93,6 +96,8 @@ SkColorType SkAndroidCodec::computeOutputColorType(SkColorType requestedColorTyp
                 return kRGB_565_SkColorType;
             }
             break;
+        case kRGBA_F16_SkColorType:
+            return kRGBA_F16_SkColorType;
         default:
             break;
     }
@@ -103,8 +108,8 @@ SkColorType SkAndroidCodec::computeOutputColorType(SkColorType requestedColorTyp
         return kN32_SkColorType;
     }
 
-    // This may be kN32_SkColorType or kIndex_8_SkColorType.
-    return suggestedColorType;
+    // |suggestedColorType| may be kN32_SkColorType or kIndex_8_SkColorType.
+    return highPrecision ? kRGBA_F16_SkColorType : suggestedColorType;
 }
 
 SkAlphaType SkAndroidCodec::computeOutputAlphaType(bool requestedUnpremul) {