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>
This commit is contained in:
parent
348060fa82
commit
c6e6a5f45e
@ -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<SkColorSpace>,
|
||||
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<SkStream> fStream;
|
||||
bool fNeedsRewind;
|
||||
const Origin fOrigin;
|
||||
|
||||
SkImageInfo fDstInfo;
|
||||
SkCodec::Options fOptions;
|
||||
Options fOptions;
|
||||
XformFormat fDstXformFormat; // Based on fDstInfo.
|
||||
std::unique_ptr<SkColorSpaceXform> 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;
|
||||
}
|
||||
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
@ -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:
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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());
|
||||
}
|
||||
|
@ -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;
|
||||
};
|
||||
|
@ -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);
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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;
|
||||
};
|
||||
|
@ -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)
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
@ -114,8 +114,6 @@ private:
|
||||
virtual Result decode(int* rowsDecoded) = 0;
|
||||
|
||||
XformMode fXformMode;
|
||||
SkColorSpaceXform::ColorFormat fXformColorFormat;
|
||||
SkAlphaType fXformAlphaType;
|
||||
int fXformWidth;
|
||||
|
||||
size_t fIdatLength;
|
||||
|
@ -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) {}
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user