diff options
author | Leon Scroggins III <scroggo@google.com> | 2017-06-05 15:53:38 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-06-05 20:14:57 +0000 |
commit | c6e6a5f45e54006e861275a6d5c165830f403dcd (patch) | |
tree | 3d4bc3a0c43d6c2986728a3dffdec43e8547f43f /src | |
parent | 348060fa820e1ee7a4fd246afe517a80a9ef311d (diff) |
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(<something that doesn't change>);
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 <scroggo@google.com>
Reviewed-by: Matt Sarett <msarett@google.com>
Commit-Queue: Leon Scroggins <scroggo@google.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/codec/SkBmpCodec.cpp | 14 | ||||
-rw-r--r-- | src/codec/SkBmpCodec.h | 2 | ||||
-rw-r--r-- | src/codec/SkBmpMaskCodec.cpp | 3 | ||||
-rw-r--r-- | src/codec/SkBmpRLECodec.cpp | 2 | ||||
-rw-r--r-- | src/codec/SkBmpStandardCodec.cpp | 23 | ||||
-rw-r--r-- | src/codec/SkBmpStandardCodec.h | 1 | ||||
-rw-r--r-- | src/codec/SkCodec.cpp | 52 | ||||
-rw-r--r-- | src/codec/SkCodecPriv.h | 24 | ||||
-rw-r--r-- | src/codec/SkGifCodec.cpp | 33 | ||||
-rw-r--r-- | src/codec/SkGifCodec.h | 1 | ||||
-rw-r--r-- | src/codec/SkIcoCodec.cpp | 5 | ||||
-rw-r--r-- | src/codec/SkJpegCodec.cpp | 7 | ||||
-rw-r--r-- | src/codec/SkPngCodec.cpp | 31 | ||||
-rw-r--r-- | src/codec/SkPngCodec.h | 2 | ||||
-rw-r--r-- | src/codec/SkRawCodec.cpp | 13 | ||||
-rw-r--r-- | src/codec/SkWbmpCodec.cpp | 4 | ||||
-rw-r--r-- | src/codec/SkWebpCodec.cpp | 10 |
17 files changed, 89 insertions, 138 deletions
diff --git a/src/codec/SkBmpCodec.cpp b/src/codec/SkBmpCodec.cpp index 0525d9530c..c21a863419 100644 --- a/src/codec/SkBmpCodec.cpp +++ b/src/codec/SkBmpCodec.cpp @@ -602,7 +602,7 @@ SkCodec* SkBmpCodec::NewFromStream(SkStream* stream, bool inIco) { SkBmpCodec::SkBmpCodec(int width, int height, const SkEncodedInfo& info, SkStream* stream, uint16_t bitsPerPixel, SkCodec::SkScanlineOrder rowOrder) - : INHERITED(width, height, info, stream, SkColorSpace::MakeSRGB()) + : INHERITED(width, height, info, kXformSrcColorFormat, stream, SkColorSpace::MakeSRGB()) , fBitsPerPixel(bitsPerPixel) , fRowOrder(rowOrder) , fSrcRowBytes(SkAlign4(compute_row_bytes(width, fBitsPerPixel))) @@ -653,15 +653,3 @@ bool SkBmpCodec::skipRows(int count) { bool SkBmpCodec::onSkipScanlines(int count) { return this->skipRows(count); } - -void SkBmpCodec::applyColorXform(const SkImageInfo& dstInfo, void* dst, void* src) const { - SkColorSpaceXform* xform = this->colorXform(); - if (xform) { - const SkColorSpaceXform::ColorFormat dstFormat = select_xform_format(dstInfo.colorType()); - const SkColorSpaceXform::ColorFormat srcFormat = select_xform_format(kXformSrcColorType); - const SkAlphaType alphaType = select_xform_alpha(dstInfo.alphaType(), - this->getInfo().alphaType()); - SkAssertResult(xform->apply(dstFormat, dst, srcFormat, src, dstInfo.width(), - alphaType)); - } -} diff --git a/src/codec/SkBmpCodec.h b/src/codec/SkBmpCodec.h index 75740f76ff..e956a9fc40 100644 --- a/src/codec/SkBmpCodec.h +++ b/src/codec/SkBmpCodec.h @@ -106,7 +106,6 @@ protected: const SkCodec::Options& options, SkPMColor inputColorPtr[], int* inputColorCount); - void applyColorXform(const SkImageInfo& dstInfo, void* dst, void* src) const; uint32_t* xformBuffer() const { return fXformBuffer.get(); } void resetXformBuffer(int count) { fXformBuffer.reset(new uint32_t[count]); } @@ -115,6 +114,7 @@ protected: * than RGBA. */ static const SkColorType kXformSrcColorType = kBGRA_8888_SkColorType; + static const auto kXformSrcColorFormat = SkColorSpaceXform::kBGRA_8888_ColorFormat; private: diff --git a/src/codec/SkBmpMaskCodec.cpp b/src/codec/SkBmpMaskCodec.cpp index c839983d43..1fc98a2909 100644 --- a/src/codec/SkBmpMaskCodec.cpp +++ b/src/codec/SkBmpMaskCodec.cpp @@ -94,9 +94,8 @@ int SkBmpMaskCodec::decodeRows(const SkImageInfo& dstInfo, void* dstRow = SkTAddOffset<void>(dst, row * dstRowBytes); if (this->colorXform()) { - SkImageInfo xformInfo = dstInfo.makeWH(fMaskSwizzler->swizzleWidth(), dstInfo.height()); fMaskSwizzler->swizzle(this->xformBuffer(), srcRow); - this->applyColorXform(xformInfo, dstRow, this->xformBuffer()); + this->applyColorXform(dstRow, this->xformBuffer(), fMaskSwizzler->swizzleWidth()); } else { fMaskSwizzler->swizzle(dstRow, srcRow); } diff --git a/src/codec/SkBmpRLECodec.cpp b/src/codec/SkBmpRLECodec.cpp index 1968616fa6..c6d788b800 100644 --- a/src/codec/SkBmpRLECodec.cpp +++ b/src/codec/SkBmpRLECodec.cpp @@ -331,7 +331,7 @@ int SkBmpRLECodec::decodeRows(const SkImageInfo& info, void* dst, size_t dstRowB int decodedHeight = this->decodeRLE(decodeInfo, decodeDst, decodeRowBytes); if (this->colorXform() && decodeDst) { for (int y = 0; y < decodedHeight; y++) { - this->applyColorXform(dstInfo, dst, decodeDst); + this->applyColorXform(dst, decodeDst, dstInfo.width()); decodeDst = SkTAddOffset<void>(decodeDst, decodeRowBytes); dst = SkTAddOffset<void>(dst, dstRowBytes); } diff --git a/src/codec/SkBmpStandardCodec.cpp b/src/codec/SkBmpStandardCodec.cpp index c223678769..959e75ba5b 100644 --- a/src/codec/SkBmpStandardCodec.cpp +++ b/src/codec/SkBmpStandardCodec.cpp @@ -28,7 +28,6 @@ SkBmpStandardCodec::SkBmpStandardCodec(int width, int height, const SkEncodedInf , fIsOpaque(isOpaque) , fInIco(inIco) , fAndMaskRowBytes(fInIco ? SkAlign4(compute_row_bytes(this->getInfo().width(), 1)) : 0) - , fXformOnDecode(false) {} /* @@ -123,13 +122,8 @@ SkCodec::Result SkBmpStandardCodec::onGetPixels(const SkImageInfo& dstInfo, colorTable[i] = SkPackARGB32NoCheck(0xFF, 0, 0, 0); } - if (this->colorXform() && !fXformOnDecode) { - SkColorSpaceXform::ColorFormat dstFormat = select_xform_format_ct(dstColorType); - SkColorSpaceXform::ColorFormat srcFormat = SkColorSpaceXform::kBGRA_8888_ColorFormat; - SkAlphaType xformAlphaType = select_xform_alpha(dstAlphaType, - this->getInfo().alphaType()); - SkAssertResult(this->colorXform()->apply(dstFormat, colorTable, srcFormat, colorTable, - maxColors, xformAlphaType)); + if (this->colorXform() && !this->xformOnDecode()) { + this->applyColorXform(colorTable, colorTable, maxColors); } // Set the color table @@ -198,12 +192,8 @@ void SkBmpStandardCodec::initializeSwizzler(const SkImageInfo& dstInfo, const Op SkCodec::Result SkBmpStandardCodec::onPrepareToDecode(const SkImageInfo& dstInfo, const SkCodec::Options& options, SkPMColor inputColorPtr[], int* inputColorCount) { - fXformOnDecode = false; - if (this->colorXform()) { - fXformOnDecode = apply_xform_on_decode(dstInfo.colorType(), this->getEncodedInfo().color()); - if (fXformOnDecode) { - this->resetXformBuffer(dstInfo.width()); - } + if (this->xformOnDecode()) { + this->resetXformBuffer(dstInfo.width()); } // Create the color table if necessary and prepare the stream for decode @@ -240,11 +230,10 @@ int SkBmpStandardCodec::decodeRows(const SkImageInfo& dstInfo, void* dst, size_t void* dstRow = SkTAddOffset<void>(dst, row * dstRowBytes); - if (fXformOnDecode) { + if (this->xformOnDecode()) { SkASSERT(this->colorXform()); - SkImageInfo xformInfo = dstInfo.makeWH(fSwizzler->swizzleWidth(), dstInfo.height()); fSwizzler->swizzle(this->xformBuffer(), this->srcBuffer()); - this->applyColorXform(xformInfo, dstRow, this->xformBuffer()); + this->applyColorXform(dstRow, this->xformBuffer(), fSwizzler->swizzleWidth()); } else { fSwizzler->swizzle(dstRow, this->srcBuffer()); } diff --git a/src/codec/SkBmpStandardCodec.h b/src/codec/SkBmpStandardCodec.h index 82937f385c..ec3d707ab8 100644 --- a/src/codec/SkBmpStandardCodec.h +++ b/src/codec/SkBmpStandardCodec.h @@ -95,7 +95,6 @@ private: const bool fIsOpaque; const bool fInIco; const size_t fAndMaskRowBytes; // only used for fInIco decodes - bool fXformOnDecode; typedef SkBmpBaseCodec INHERITED; }; diff --git a/src/codec/SkCodec.cpp b/src/codec/SkCodec.cpp index 688cfaa993..2cae6db1df 100644 --- a/src/codec/SkCodec.cpp +++ b/src/codec/SkCodec.cpp @@ -114,10 +114,12 @@ SkCodec* SkCodec::NewFromData(sk_sp<SkData> data, SkPngChunkReader* reader) { return NewFromStream(new SkMemoryStream(data), reader); } -SkCodec::SkCodec(int width, int height, const SkEncodedInfo& info, SkStream* stream, +SkCodec::SkCodec(int width, int height, const SkEncodedInfo& info, + XformFormat srcFormat, SkStream* stream, sk_sp<SkColorSpace> colorSpace, Origin origin) : fEncodedInfo(info) , fSrcInfo(info.makeImageInfo(width, height, std::move(colorSpace))) + , fSrcXformFormat(srcFormat) , fStream(stream) , fNeedsRewind(false) , fOrigin(origin) @@ -126,10 +128,11 @@ SkCodec::SkCodec(int width, int height, const SkEncodedInfo& info, SkStream* str , fCurrScanline(-1) {} -SkCodec::SkCodec(const SkEncodedInfo& info, const SkImageInfo& imageInfo, SkStream* stream, - Origin origin) +SkCodec::SkCodec(const SkEncodedInfo& info, const SkImageInfo& imageInfo, + XformFormat srcFormat, SkStream* stream, Origin origin) : fEncodedInfo(info) , fSrcInfo(imageInfo) + , fSrcXformFormat(srcFormat) , fStream(stream) , fNeedsRewind(false) , fOrigin(origin) @@ -474,9 +477,29 @@ void SkCodec::fillIncompleteImage(const SkImageInfo& info, void* dst, size_t row } } +static inline SkColorSpaceXform::ColorFormat select_xform_format_ct(SkColorType colorType) { + switch (colorType) { + case kRGBA_8888_SkColorType: + return SkColorSpaceXform::kRGBA_8888_ColorFormat; + case kBGRA_8888_SkColorType: + return SkColorSpaceXform::kBGRA_8888_ColorFormat; + case kRGB_565_SkColorType: + case kIndex_8_SkColorType: +#ifdef SK_PMCOLOR_IS_RGBA + return SkColorSpaceXform::kRGBA_8888_ColorFormat; +#else + return SkColorSpaceXform::kBGRA_8888_ColorFormat; +#endif + default: + SkASSERT(false); + return SkColorSpaceXform::kRGBA_8888_ColorFormat; + } +} + bool SkCodec::initializeColorXform(const SkImageInfo& dstInfo, SkTransferFunctionBehavior premulBehavior) { fColorXform = nullptr; + fXformOnDecode = false; bool needsColorCorrectPremul = needs_premul(dstInfo, fEncodedInfo) && SkTransferFunctionBehavior::kRespect == premulBehavior; if (needs_color_xform(dstInfo, fSrcInfo, needsColorCorrectPremul)) { @@ -485,13 +508,32 @@ bool SkCodec::initializeColorXform(const SkImageInfo& dstInfo, if (!fColorXform) { return false; } - } else { - fColorXform.reset(); + + // We will apply the color xform when reading the color table unless F16 is requested. + fXformOnDecode = SkEncodedInfo::kPalette_Color != fEncodedInfo.color() + || kRGBA_F16_SkColorType == dstInfo.colorType(); + if (fXformOnDecode) { + fDstXformFormat = select_xform_format(dstInfo.colorType()); + } else { + fDstXformFormat = select_xform_format_ct(dstInfo.colorType()); + } } return true; } +void SkCodec::applyColorXform(void* dst, const void* src, int count, SkAlphaType at) const { + SkASSERT(fColorXform); + SkAssertResult(fColorXform->apply(fDstXformFormat, dst, + fSrcXformFormat, src, + count, at)); +} + +void SkCodec::applyColorXform(void* dst, const void* src, int count) const { + auto alphaType = select_xform_alpha(fDstInfo.alphaType(), fSrcInfo.alphaType()); + this->applyColorXform(dst, src, count, alphaType); +} + std::vector<SkCodec::FrameInfo> SkCodec::getFrameInfo() { const int frameCount = this->getFrameCount(); SkASSERT(frameCount >= 0); diff --git a/src/codec/SkCodecPriv.h b/src/codec/SkCodecPriv.h index 5c8dc8747a..b69e48808e 100644 --- a/src/codec/SkCodecPriv.h +++ b/src/codec/SkCodecPriv.h @@ -323,11 +323,6 @@ static inline SkAlphaType select_xform_alpha(SkAlphaType dstAlphaType, SkAlphaTy return (kOpaque_SkAlphaType == srcAlphaType) ? kOpaque_SkAlphaType : dstAlphaType; } -static inline bool apply_xform_on_decode(SkColorType dstColorType, SkEncodedInfo::Color srcColor) { - // We will apply the color xform when reading the color table unless F16 is requested. - return SkEncodedInfo::kPalette_Color != srcColor || kRGBA_F16_SkColorType == dstColorType; -} - /* * Alpha Type Conversions * - kOpaque to kOpaque, kUnpremul, kPremul is valid @@ -365,23 +360,4 @@ static inline bool conversion_possible(const SkImageInfo& dst, const SkImageInfo } } -static inline SkColorSpaceXform::ColorFormat select_xform_format_ct(SkColorType colorType) { - switch (colorType) { - case kRGBA_8888_SkColorType: - return SkColorSpaceXform::kRGBA_8888_ColorFormat; - case kBGRA_8888_SkColorType: - return SkColorSpaceXform::kBGRA_8888_ColorFormat; - case kRGB_565_SkColorType: - case kIndex_8_SkColorType: -#ifdef SK_PMCOLOR_IS_RGBA - return SkColorSpaceXform::kRGBA_8888_ColorFormat; -#else - return SkColorSpaceXform::kBGRA_8888_ColorFormat; -#endif - default: - SkASSERT(false); - return SkColorSpaceXform::kRGBA_8888_ColorFormat; - } -} - #endif // SkCodecPriv_DEFINED diff --git a/src/codec/SkGifCodec.cpp b/src/codec/SkGifCodec.cpp index 1a01c296fc..3f4e551fc8 100644 --- a/src/codec/SkGifCodec.cpp +++ b/src/codec/SkGifCodec.cpp @@ -117,7 +117,7 @@ bool SkGifCodec::onRewind() { SkGifCodec::SkGifCodec(const SkEncodedInfo& encodedInfo, const SkImageInfo& imageInfo, SkGifImageReader* reader) - : INHERITED(encodedInfo, imageInfo, nullptr) + : INHERITED(encodedInfo, imageInfo, SkColorSpaceXform::kRGBA_8888_ColorFormat, nullptr) , fReader(reader) , fTmpBuffer(nullptr) , fSwizzler(nullptr) @@ -176,16 +176,9 @@ void SkGifCodec::initializeColorTable(const SkImageInfo& dstInfo, int frameIndex // This is possible for an empty frame. Create a dummy with one value (transparent). SkPMColor color = SK_ColorTRANSPARENT; fCurrColorTable.reset(new SkColorTable(&color, 1)); - } else if (this->colorXform() && !fXformOnDecode) { + } else if (this->colorXform() && !this->xformOnDecode()) { SkPMColor dstColors[256]; - const SkColorSpaceXform::ColorFormat dstFormat = - select_xform_format_ct(dstInfo.colorType()); - const SkColorSpaceXform::ColorFormat srcFormat = select_xform_format(kXformSrcColorType); - const SkAlphaType xformAlphaType = select_xform_alpha(dstInfo.alphaType(), - this->getInfo().alphaType()); - SkAssertResult(this->colorXform()->apply(dstFormat, dstColors, srcFormat, - currColorTable->readColors(), - currColorTable->count(), xformAlphaType)); + this->applyColorXform(dstColors, currColorTable->readColors(), currColorTable->count()); fCurrColorTable.reset(new SkColorTable(dstColors, currColorTable->count())); } else { fCurrColorTable = std::move(currColorTable); @@ -202,13 +195,9 @@ SkCodec::Result SkGifCodec::prepareToDecode(const SkImageInfo& dstInfo, SkPMColo return gif_error("Cannot convert input type to output type.\n", kInvalidConversion); } - fXformOnDecode = false; - if (this->colorXform()) { - fXformOnDecode = apply_xform_on_decode(dstInfo.colorType(), this->getEncodedInfo().color()); - if (fXformOnDecode) { - fXformBuffer.reset(new uint32_t[dstInfo.width()]); - sk_bzero(fXformBuffer.get(), dstInfo.width() * sizeof(uint32_t)); - } + if (this->xformOnDecode()) { + fXformBuffer.reset(new uint32_t[dstInfo.width()]); + sk_bzero(fXformBuffer.get(), dstInfo.width() * sizeof(uint32_t)); } if (opts.fSubset) { @@ -516,16 +505,12 @@ uint64_t SkGifCodec::onGetFillValue(const SkImageInfo& dstInfo) const { } void SkGifCodec::applyXformRow(const SkImageInfo& dstInfo, void* dst, const uint8_t* src) const { - if (this->colorXform() && fXformOnDecode) { + if (this->xformOnDecode()) { + SkASSERT(this->colorXform()); fSwizzler->swizzle(fXformBuffer.get(), src); - const SkColorSpaceXform::ColorFormat dstFormat = select_xform_format(dstInfo.colorType()); - const SkColorSpaceXform::ColorFormat srcFormat = select_xform_format(kXformSrcColorType); - const SkAlphaType xformAlphaType = select_xform_alpha(dstInfo.alphaType(), - this->getInfo().alphaType()); const int xformWidth = get_scaled_dimension(dstInfo.width(), fSwizzler->sampleX()); - SkAssertResult(this->colorXform()->apply(dstFormat, dst, srcFormat, fXformBuffer.get(), - xformWidth, xformAlphaType)); + this->applyColorXform(dst, fXformBuffer.get(), xformWidth); } else { fSwizzler->swizzle(dst, src); } diff --git a/src/codec/SkGifCodec.h b/src/codec/SkGifCodec.h index 9cb663289a..314b50b798 100644 --- a/src/codec/SkGifCodec.h +++ b/src/codec/SkGifCodec.h @@ -151,7 +151,6 @@ private: // the background, in which case it is set once and left alone. int fRowsDecoded; std::unique_ptr<uint32_t[]> fXformBuffer; - bool fXformOnDecode; typedef SkCodec INHERITED; }; diff --git a/src/codec/SkIcoCodec.cpp b/src/codec/SkIcoCodec.cpp index 9d424f3e4e..14c6fc49e7 100644 --- a/src/codec/SkIcoCodec.cpp +++ b/src/codec/SkIcoCodec.cpp @@ -192,7 +192,10 @@ SkCodec* SkIcoCodec::NewFromStream(SkStream* stream) { SkIcoCodec::SkIcoCodec(int width, int height, const SkEncodedInfo& info, SkTArray<std::unique_ptr<SkCodec>, true>* codecs, sk_sp<SkColorSpace> colorSpace) - : INHERITED(width, height, info, nullptr, std::move(colorSpace)) + // The source SkColorSpaceXform::ColorFormat will not be used. The embedded + // codec's will be used instead. + : INHERITED(width, height, info, SkColorSpaceXform::ColorFormat(), nullptr, + std::move(colorSpace)) , fEmbeddedCodecs(codecs) , fCurrScanlineCodec(nullptr) , fCurrIncrementalCodec(nullptr) diff --git a/src/codec/SkJpegCodec.cpp b/src/codec/SkJpegCodec.cpp index 43d54a86c7..a428b64939 100644 --- a/src/codec/SkJpegCodec.cpp +++ b/src/codec/SkJpegCodec.cpp @@ -281,7 +281,8 @@ SkCodec* SkJpegCodec::NewFromStream(SkStream* stream, sk_sp<SkColorSpace> defaul SkJpegCodec::SkJpegCodec(int width, int height, const SkEncodedInfo& info, SkStream* stream, JpegDecoderMgr* decoderMgr, sk_sp<SkColorSpace> colorSpace, Origin origin) - : INHERITED(width, height, info, stream, std::move(colorSpace), origin) + : INHERITED(width, height, info, SkColorSpaceXform::kRGBA_8888_ColorFormat, stream, + std::move(colorSpace), origin) , fDecoderMgr(decoderMgr) , fReadyState(decoderMgr->dinfo()->global_state) , fSwizzleSrcRow(nullptr) @@ -529,9 +530,7 @@ int SkJpegCodec::readRows(const SkImageInfo& dstInfo, void* dst, size_t rowBytes } if (this->colorXform()) { - SkAssertResult(this->colorXform()->apply(select_xform_format(dstInfo.colorType()), dst, - SkColorSpaceXform::kRGBA_8888_ColorFormat, swizzleDst, dstWidth, - kOpaque_SkAlphaType)); + this->applyColorXform(dst, swizzleDst, dstWidth, kOpaque_SkAlphaType); dst = SkTAddOffset<void>(dst, rowBytes); } diff --git a/src/codec/SkPngCodec.cpp b/src/codec/SkPngCodec.cpp index 1c5f821c65..29057cb298 100644 --- a/src/codec/SkPngCodec.cpp +++ b/src/codec/SkPngCodec.cpp @@ -296,15 +296,8 @@ bool SkPngCodec::createColorTable(const SkImageInfo& dstInfo, int* ctableCount) } } - if (this->colorXform() && - !apply_xform_on_decode(dstInfo.colorType(), this->getEncodedInfo().color())) { - const SkColorSpaceXform::ColorFormat dstFormat = - select_xform_format_ct(dstInfo.colorType()); - const SkColorSpaceXform::ColorFormat srcFormat = select_xform_format(kXformSrcColorType); - const SkAlphaType xformAlphaType = select_xform_alpha(dstInfo.alphaType(), - this->getInfo().alphaType()); - SkAssertResult(this->colorXform()->apply(dstFormat, colorTable, srcFormat, colorTable, - numColors, xformAlphaType)); + if (this->colorXform() && !this->xformOnDecode()) { + this->applyColorXform(colorTable, colorTable, numColors); } // Pad the color table with the last color in the table (or black) in the case that @@ -476,20 +469,16 @@ static SkColorSpaceXform::ColorFormat png_select_xform_format(const SkEncodedInf } void SkPngCodec::applyXformRow(void* dst, const void* src) { - const SkColorSpaceXform::ColorFormat srcColorFormat = - png_select_xform_format(this->getEncodedInfo()); switch (fXformMode) { case kSwizzleOnly_XformMode: fSwizzler->swizzle(dst, (const uint8_t*) src); break; case kColorOnly_XformMode: - SkAssertResult(this->colorXform()->apply(fXformColorFormat, dst, srcColorFormat, src, - fXformWidth, fXformAlphaType)); + this->applyColorXform(dst, src, fXformWidth); break; case kSwizzleColor_XformMode: fSwizzler->swizzle(fColorXformSrcRow, (const uint8_t*) src); - SkAssertResult(this->colorXform()->apply(fXformColorFormat, dst, srcColorFormat, - fColorXformSrcRow, fXformWidth, fXformAlphaType)); + this->applyColorXform(dst, fColorXformSrcRow, fXformWidth); break; } } @@ -958,7 +947,7 @@ void AutoCleanPng::infoCallback(size_t idatLength) { SkPngCodec::SkPngCodec(const SkEncodedInfo& encodedInfo, const SkImageInfo& imageInfo, SkStream* stream, SkPngChunkReader* chunkReader, void* png_ptr, void* info_ptr, int bitDepth) - : INHERITED(encodedInfo, imageInfo, stream) + : INHERITED(encodedInfo, imageInfo, png_select_xform_format(encodedInfo), stream) , fPngChunkReader(SkSafeRef(chunkReader)) , fPng_ptr(png_ptr) , fInfo_ptr(info_ptr) @@ -1039,15 +1028,9 @@ SkCodec::Result SkPngCodec::initializeXforms(const SkImageInfo& dstInfo, const O void SkPngCodec::initializeXformParams() { switch (fXformMode) { case kColorOnly_XformMode: - fXformColorFormat = select_xform_format(this->dstInfo().colorType()); - fXformAlphaType = select_xform_alpha(this->dstInfo().alphaType(), - this->getInfo().alphaType()); fXformWidth = this->dstInfo().width(); break; case kSwizzleColor_XformMode: - fXformColorFormat = select_xform_format(this->dstInfo().colorType()); - fXformAlphaType = select_xform_alpha(this->dstInfo().alphaType(), - this->getInfo().alphaType()); fXformWidth = this->swizzler()->swizzleWidth(); break; default: @@ -1060,9 +1043,7 @@ void SkPngCodec::initializeSwizzler(const SkImageInfo& dstInfo, const Options& o SkImageInfo swizzlerInfo = dstInfo; Options swizzlerOptions = options; fXformMode = kSwizzleOnly_XformMode; - if (this->colorXform() && - apply_xform_on_decode(dstInfo.colorType(), this->getEncodedInfo().color())) - { + if (this->colorXform() && this->xformOnDecode()) { swizzlerInfo = swizzlerInfo.makeColorType(kXformSrcColorType); if (kPremul_SkAlphaType == dstInfo.alphaType()) { swizzlerInfo = swizzlerInfo.makeAlphaType(kUnpremul_SkAlphaType); diff --git a/src/codec/SkPngCodec.h b/src/codec/SkPngCodec.h index d729fb11da..b329fef1b6 100644 --- a/src/codec/SkPngCodec.h +++ b/src/codec/SkPngCodec.h @@ -114,8 +114,6 @@ private: virtual Result decode(int* rowsDecoded) = 0; XformMode fXformMode; - SkColorSpaceXform::ColorFormat fXformColorFormat; - SkAlphaType fXformAlphaType; int fXformWidth; size_t fIdatLength; diff --git a/src/codec/SkRawCodec.cpp b/src/codec/SkRawCodec.cpp index 272f737f18..b8bcf19163 100644 --- a/src/codec/SkRawCodec.cpp +++ b/src/codec/SkRawCodec.cpp @@ -697,11 +697,10 @@ SkCodec::Result SkRawCodec::onGetPixels(const SkImageInfo& dstInfo, void* dst, return kInvalidConversion; } - static const SkColorType kXformSrcColorType = kRGBA_8888_SkColorType; SkImageInfo swizzlerInfo = dstInfo; std::unique_ptr<uint32_t[]> xformBuffer = nullptr; if (this->colorXform()) { - swizzlerInfo = swizzlerInfo.makeColorType(kXformSrcColorType); + swizzlerInfo = swizzlerInfo.makeColorType(kRGBA_8888_SkColorType); xformBuffer.reset(new uint32_t[dstInfo.width()]); } @@ -751,12 +750,7 @@ SkCodec::Result SkRawCodec::onGetPixels(const SkImageInfo& dstInfo, void* dst, if (this->colorXform()) { swizzler->swizzle(xformBuffer.get(), &srcRow[0]); - const SkColorSpaceXform::ColorFormat srcFormat = - select_xform_format(kXformSrcColorType); - const SkColorSpaceXform::ColorFormat dstFormat = - select_xform_format(dstInfo.colorType()); - this->colorXform()->apply(dstFormat, dstRow, srcFormat, xformBuffer.get(), - dstInfo.width(), kOpaque_SkAlphaType); + this->applyColorXform(dstRow, xformBuffer.get(), dstInfo.width(), kOpaque_SkAlphaType); dstRow = SkTAddOffset<void>(dstRow, dstRowBytes); } else { swizzler->swizzle(dstRow, &srcRow[0]); @@ -807,6 +801,7 @@ bool SkRawCodec::onDimensionsSupported(const SkISize& dim) { SkRawCodec::~SkRawCodec() {} SkRawCodec::SkRawCodec(SkDngImage* dngImage) - : INHERITED(dngImage->width(), dngImage->height(), dngImage->getEncodedInfo(), nullptr, + : INHERITED(dngImage->width(), dngImage->height(), dngImage->getEncodedInfo(), + SkColorSpaceXform::kRGBA_8888_ColorFormat, nullptr, SkColorSpace::MakeSRGB()) , fDngImage(dngImage) {} diff --git a/src/codec/SkWbmpCodec.cpp b/src/codec/SkWbmpCodec.cpp index d59789b66e..780ae5e5d0 100644 --- a/src/codec/SkWbmpCodec.cpp +++ b/src/codec/SkWbmpCodec.cpp @@ -107,7 +107,9 @@ bool SkWbmpCodec::readRow(uint8_t* row) { } SkWbmpCodec::SkWbmpCodec(int width, int height, const SkEncodedInfo& info, SkStream* stream) - : INHERITED(width, height, info, stream, SkColorSpace::MakeSRGB()) + // Wbmp does not need a colorXform, so choose an arbitrary srcFormat. + : INHERITED(width, height, info, SkColorSpaceXform::ColorFormat(), + stream, SkColorSpace::MakeSRGB()) , fSrcRowBytes(get_src_row_bytes(this->getInfo().width())) , fSwizzler(nullptr) , fColorTable(nullptr) diff --git a/src/codec/SkWebpCodec.cpp b/src/codec/SkWebpCodec.cpp index 700178ae9f..21d45da233 100644 --- a/src/codec/SkWebpCodec.cpp +++ b/src/codec/SkWebpCodec.cpp @@ -612,10 +612,6 @@ SkCodec::Result SkWebpCodec::onGetPixels(const SkImageInfo& dstInfo, void* dst, const auto dstCT = dstInfo.colorType(); if (this->colorXform()) { - const auto dstColorFormat = select_xform_format(dstInfo.colorType()); - const auto srcColorFormat = SkColorSpaceXform::kBGRA_8888_ColorFormat; - SkASSERT(select_xform_format(webpDst.colorType()) == srcColorFormat); - uint32_t* xformSrc = (uint32_t*) config.output.u.RGBA.rgba; SkBitmap tmp; void* xformDst; @@ -628,8 +624,7 @@ SkCodec::Result SkWebpCodec::onGetPixels(const SkImageInfo& dstInfo, void* dst, xformDst = dst; } for (int y = 0; y < rowsDecoded; y++) { - SkAssertResult(this->colorXform()->apply(dstColorFormat, xformDst, - srcColorFormat, xformSrc, scaledWidth, xformAlphaType)); + this->applyColorXform(xformDst, xformSrc, scaledWidth, xformAlphaType); if (blendWithPrevFrame) { blend_line(dstCT, &dst, dstCT, &xformDst, needsSrgbToLinear, xformAlphaType, scaledWidth); @@ -656,7 +651,8 @@ SkCodec::Result SkWebpCodec::onGetPixels(const SkImageInfo& dstInfo, void* dst, SkWebpCodec::SkWebpCodec(int width, int height, const SkEncodedInfo& info, sk_sp<SkColorSpace> colorSpace, SkStream* stream, WebPDemuxer* demux, sk_sp<SkData> data) - : INHERITED(width, height, info, stream, std::move(colorSpace)) + : INHERITED(width, height, info, SkColorSpaceXform::kBGRA_8888_ColorFormat, stream, + std::move(colorSpace)) , fDemux(demux) , fData(std::move(data)) , fFailed(false) |