diff options
author | msarett <msarett@google.com> | 2016-08-22 08:48:40 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-08-22 08:48:40 -0700 |
commit | dcd5e65340f9ef239d769bf20bafd2fa819eab31 (patch) | |
tree | 5597db8cdd3183f6ea8e9acb090887a90ba0f174 /src/codec/SkCodecPriv.h | |
parent | c0c6e1c5d133c51cc75ed9d5770fdc5448d8c324 (diff) |
Support color xforms for kIndex8 pngs
This change started as: "Always use color xforms to
premultiply". We need to be in a linear space to
premultiply correctly.
It became clear that we also need to support kIndex8
color xforms in order to make this change.
BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2246143002
Review-Url: https://codereview.chromium.org/2246143002
Diffstat (limited to 'src/codec/SkCodecPriv.h')
-rw-r--r-- | src/codec/SkCodecPriv.h | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/src/codec/SkCodecPriv.h b/src/codec/SkCodecPriv.h index b768b23a8a..17494074b3 100644 --- a/src/codec/SkCodecPriv.h +++ b/src/codec/SkCodecPriv.h @@ -310,10 +310,25 @@ static inline PackColorProc choose_pack_color_proc(bool isPremul, SkColorType co } } +static inline bool needs_premul(const SkImageInfo& dstInfo, const SkImageInfo& srcInfo) { + return kPremul_SkAlphaType == dstInfo.alphaType() && + kUnpremul_SkAlphaType == srcInfo.alphaType(); +} + static inline bool needs_color_xform(const SkImageInfo& dstInfo, const SkImageInfo& srcInfo) { - return (kRGBA_F16_SkColorType == dstInfo.colorType()) || - (dstInfo.colorSpace() && !SkColorSpace::Equals(srcInfo.colorSpace(), - dstInfo.colorSpace())); + // Color xform is necessary in order to correctly perform premultiply in linear space. + bool needsPremul = needs_premul(dstInfo, srcInfo); + + // F16 is by definition a linear space, so we always must perform a color xform. + bool isF16 = kRGBA_F16_SkColorType == dstInfo.colorType(); + + // Need a color xform when dst space does not match the src. + bool srcDstNotEqual = !SkColorSpace::Equals(srcInfo.colorSpace(), dstInfo.colorSpace()); + + // We never perform a color xform in legacy mode. + bool isLegacy = nullptr == dstInfo.colorSpace(); + + return !isLegacy && (needsPremul || isF16 || srcDstNotEqual); } #endif // SkCodecPriv_DEFINED |