From c6e6a5f45e54006e861275a6d5c165830f403dcd Mon Sep 17 00:00:00 2001 From: Leon Scroggins III Date: Mon, 5 Jun 2017 15:53:38 -0400 Subject: Simplify SkCodecs' call to SkColorSpaceXform::apply Most SkCodec subclasses did the following to apply their SkColorSpaceXform: dstFormat = select_xform_format(dstInfo.colorType()); srcFormat = select_xform_format(); xformAlphaType = select_xform_alpha(dstInfo.alphaType(), this->getInfo().alphaType()); this->colorXform()->apply(dstFormat, dst, srcFormat, src, width, xformAlphaType); Consolidate the computation of these parameters into SkCodec and add a new method to SkCodec that calls apply() with those parameters. Add a SkColorSpaceXform::ColorFormat to SkCodec. This allows the new method SkCodec::applyColorXform to supply the ColorFormat. TBR=reed@google.com (No change to public API.) Change-Id: I8ea7ba4c0024be827a9f9359796c778744330f6e Reviewed-on: https://skia-review.googlesource.com/18523 Reviewed-by: Leon Scroggins Reviewed-by: Matt Sarett Commit-Queue: Leon Scroggins --- include/codec/SkCodec.h | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) (limited to 'include/codec') diff --git a/include/codec/SkCodec.h b/include/codec/SkCodec.h index d52433e3a3..d498007486 100644 --- a/include/codec/SkCodec.h +++ b/include/codec/SkCodec.h @@ -10,6 +10,7 @@ #include "../private/SkTemplates.h" #include "SkColor.h" +#include "SkColorSpaceXform.h" #include "SkEncodedImageFormat.h" #include "SkEncodedInfo.h" #include "SkImageInfo.h" @@ -415,10 +416,10 @@ public: * @return Enum representing success or reason for failure. */ Result startIncrementalDecode(const SkImageInfo& dstInfo, void* dst, size_t rowBytes, - const SkCodec::Options*, SkPMColor* ctable, int* ctableCount); + const Options*, SkPMColor* ctable, int* ctableCount); Result startIncrementalDecode(const SkImageInfo& dstInfo, void* dst, size_t rowBytes, - const SkCodec::Options* options) { + const Options* options) { return this->startIncrementalDecode(dstInfo, dst, rowBytes, options, nullptr, nullptr); } @@ -483,7 +484,7 @@ public: * decoding the palette. * @return Enum representing success or reason for failure. */ - Result startScanlineDecode(const SkImageInfo& dstInfo, const SkCodec::Options* options, + Result startScanlineDecode(const SkImageInfo& dstInfo, const Options* options, SkPMColor ctable[], int* ctableCount); /** @@ -678,12 +679,15 @@ public: } protected: + using XformFormat = SkColorSpaceXform::ColorFormat; + /** * Takes ownership of SkStream* */ SkCodec(int width, int height, const SkEncodedInfo&, + XformFormat srcFormat, SkStream*, sk_sp, Origin = kTopLeft_Origin); @@ -694,6 +698,7 @@ protected: */ SkCodec(const SkEncodedInfo&, const SkImageInfo&, + XformFormat srcFormat, SkStream*, Origin = kTopLeft_Origin); @@ -805,7 +810,7 @@ protected: const SkImageInfo& dstInfo() const { return fDstInfo; } - const SkCodec::Options& options() const { return fOptions; } + const Options& options() const { return fOptions; } /** * Returns the number of scanlines that have been decoded so far. @@ -819,7 +824,11 @@ protected: bool initializeColorXform(const SkImageInfo& dstInfo, SkTransferFunctionBehavior premulBehavior); + void applyColorXform(void* dst, const void* src, int count, SkAlphaType) const; + void applyColorXform(void* dst, const void* src, int count) const; + SkColorSpaceXform* colorXform() const { return fColorXform.get(); } + bool xformOnDecode() const { return fXformOnDecode; } virtual int onGetFrameCount() { return 1; @@ -838,13 +847,16 @@ protected: private: const SkEncodedInfo fEncodedInfo; const SkImageInfo fSrcInfo; + const XformFormat fSrcXformFormat; std::unique_ptr fStream; bool fNeedsRewind; const Origin fOrigin; SkImageInfo fDstInfo; - SkCodec::Options fOptions; + Options fOptions; + XformFormat fDstXformFormat; // Based on fDstInfo. std::unique_ptr fColorXform; + bool fXformOnDecode; // Only meaningful during scanline decodes. int fCurrScanline; @@ -868,13 +880,13 @@ private: } // Methods for scanline decoding. - virtual SkCodec::Result onStartScanlineDecode(const SkImageInfo& /*dstInfo*/, - const SkCodec::Options& /*options*/, SkPMColor* /*ctable*/, int* /*ctableCount*/) { + virtual Result onStartScanlineDecode(const SkImageInfo& /*dstInfo*/, + const Options& /*options*/, SkPMColor* /*ctable*/, int* /*ctableCount*/) { return kUnimplemented; } virtual Result onStartIncrementalDecode(const SkImageInfo& /*dstInfo*/, void*, size_t, - const SkCodec::Options&, SkPMColor*, int*) { + const Options&, SkPMColor*, int*) { return kUnimplemented; } -- cgit v1.2.3