From 8dcc84f7dc8523dd90501a4feb1f632808337c34 Mon Sep 17 00:00:00 2001 From: Matt Sarett Date: Wed, 14 Dec 2016 10:23:41 -0500 Subject: [PATCH] Prefer F16 in SkAndroidCodec for high precision images 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 Reviewed-by: Leon Scroggins --- include/codec/SkAndroidCodec.h | 10 +++++++--- src/codec/SkAndroidCodec.cpp | 11 ++++++++--- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/include/codec/SkAndroidCodec.h b/include/codec/SkAndroidCodec.h index ecf0a08c15..e30a2aa0b3 100644 --- a/include/codec/SkAndroidCodec.h +++ b/include/codec/SkAndroidCodec.h @@ -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); diff --git a/src/codec/SkAndroidCodec.cpp b/src/codec/SkAndroidCodec.cpp index 5dddfe355e..a3daeae72b 100644 --- a/src/codec/SkAndroidCodec.cpp +++ b/src/codec/SkAndroidCodec.cpp @@ -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) {