Support decoding opaque to *premul

If a client requests unpremul or premul from an opaque SkCodec,
support it. The opaque image can be treated as any of them, though
it will be less efficient to draw than if the client had used
opaque.

Change the filling code (i.e. for incomplete images) to base its color on
the source alpha type. Prior to adding the support to decode opaque to
any, it was fine to use either source or dest (which would have yielded
the same result). If the client requests non-opaque, we do not want this
to switch the fill value from black to transparent. This also allows
simplifying the signatures for getFillValue and onGetFillValue.

In CodexTest, expect the same result when decoding opaque to *premul,
and compare to the opaque version.

BUG=skia:4616
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1641273003

Review URL: https://codereview.chromium.org/1641273003
This commit is contained in:
scroggo 2016-02-03 09:42:42 -08:00 committed by Commit bot
parent 8ca88e41aa
commit c5560bef14
16 changed files with 113 additions and 89 deletions

View File

@ -225,7 +225,7 @@ static void push_src(ImplicitString tag, ImplicitString options, Src* s) {
} }
static void push_codec_src(Path path, CodecSrc::Mode mode, CodecSrc::DstColorType dstColorType, static void push_codec_src(Path path, CodecSrc::Mode mode, CodecSrc::DstColorType dstColorType,
float scale) { SkAlphaType dstAlphaType, float scale) {
SkString folder; SkString folder;
switch (mode) { switch (mode) {
case CodecSrc::kCodec_Mode: case CodecSrc::kCodec_Mode:
@ -259,16 +259,30 @@ static void push_codec_src(Path path, CodecSrc::Mode mode, CodecSrc::DstColorTyp
break; break;
} }
switch (dstAlphaType) {
case kOpaque_SkAlphaType:
folder.append("_opaque");
break;
case kPremul_SkAlphaType:
folder.append("_premul");
break;
case kUnpremul_SkAlphaType:
folder.append("_unpremul");
break;
default:
break;
}
if (1.0f != scale) { if (1.0f != scale) {
folder.appendf("_%.3f", scale); folder.appendf("_%.3f", scale);
} }
CodecSrc* src = new CodecSrc(path, mode, dstColorType, scale); CodecSrc* src = new CodecSrc(path, mode, dstColorType, dstAlphaType, scale);
push_src("image", folder, src); push_src("image", folder, src);
} }
static void push_android_codec_src(Path path, AndroidCodecSrc::Mode mode, static void push_android_codec_src(Path path, AndroidCodecSrc::Mode mode,
CodecSrc::DstColorType dstColorType, int sampleSize) { CodecSrc::DstColorType dstColorType, SkAlphaType dstAlphaType, int sampleSize) {
SkString folder; SkString folder;
switch (mode) { switch (mode) {
case AndroidCodecSrc::kFullImage_Mode: case AndroidCodecSrc::kFullImage_Mode:
@ -290,11 +304,22 @@ static void push_android_codec_src(Path path, AndroidCodecSrc::Mode mode,
break; break;
} }
switch (dstAlphaType) {
case kOpaque_SkAlphaType:
folder.append("_opaque");
break;
case kPremul_SkAlphaType:
folder.append("_premul");
break;
default:
break;
}
if (1 != sampleSize) { if (1 != sampleSize) {
folder.appendf("_%.3f", 1.0f / (float) sampleSize); folder.appendf("_%.3f", 1.0f / (float) sampleSize);
} }
AndroidCodecSrc* src = new AndroidCodecSrc(path, mode, dstColorType, sampleSize); AndroidCodecSrc* src = new AndroidCodecSrc(path, mode, dstColorType, dstAlphaType, sampleSize);
push_src("image", folder, src); push_src("image", folder, src);
} }
@ -344,6 +369,13 @@ static void push_codec_srcs(Path path) {
break; break;
} }
SkTArray<SkAlphaType> alphaModes;
alphaModes.push_back(kPremul_SkAlphaType);
// FIXME: Currently we cannot draw unpremultiplied sources. skbug.com/3338 and skbug.com/3339
// alphaModes.push_back(kUnpremul_SkAlphaType);
if (codec->getInfo().alphaType() == kOpaque_SkAlphaType) {
alphaModes.push_back(kOpaque_SkAlphaType);
}
for (CodecSrc::Mode mode : nativeModes) { for (CodecSrc::Mode mode : nativeModes) {
// SkCodecImageGenerator only runs for the default colorType // SkCodecImageGenerator only runs for the default colorType
@ -353,14 +385,17 @@ static void push_codec_srcs(Path path) {
if (CodecSrc::kGen_Mode == mode) { if (CodecSrc::kGen_Mode == mode) {
// FIXME: The gpu backend does not draw kGray sources correctly. (skbug.com/4822) // FIXME: The gpu backend does not draw kGray sources correctly. (skbug.com/4822)
if (kGray_8_SkColorType != codec->getInfo().colorType()) { if (kGray_8_SkColorType != codec->getInfo().colorType()) {
push_codec_src(path, mode, CodecSrc::kGetFromCanvas_DstColorType, 1.0f); push_codec_src(path, mode, CodecSrc::kGetFromCanvas_DstColorType,
codec->getInfo().alphaType(), 1.0f);
} }
continue; continue;
} }
for (float scale : nativeScales) { for (float scale : nativeScales) {
for (uint32_t i = 0; i < numColorTypes; i++) { for (uint32_t i = 0; i < numColorTypes; i++) {
push_codec_src(path, mode, colorTypes[i], scale); for (SkAlphaType alphaType : alphaModes) {
push_codec_src(path, mode, colorTypes[i], alphaType, scale);
}
} }
} }
} }
@ -384,11 +419,13 @@ static void push_codec_srcs(Path path) {
for (int sampleSize : sampleSizes) { for (int sampleSize : sampleSizes) {
for (uint32_t i = 0; i < numColorTypes; i++) { for (uint32_t i = 0; i < numColorTypes; i++) {
push_android_codec_src(path, AndroidCodecSrc::kFullImage_Mode, colorTypes[i], for (SkAlphaType alphaType : alphaModes) {
sampleSize); push_android_codec_src(path, AndroidCodecSrc::kFullImage_Mode, colorTypes[i],
if (subset) { alphaType, sampleSize);
push_android_codec_src(path, AndroidCodecSrc::kDivisor_Mode, colorTypes[i], if (subset) {
sampleSize); push_android_codec_src(path, AndroidCodecSrc::kDivisor_Mode, colorTypes[i],
alphaType, sampleSize);
}
} }
} }
} }

View File

@ -233,10 +233,12 @@ Name BRDSrc::name() const {
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
CodecSrc::CodecSrc(Path path, Mode mode, DstColorType dstColorType, float scale) CodecSrc::CodecSrc(Path path, Mode mode, DstColorType dstColorType, SkAlphaType dstAlphaType,
float scale)
: fPath(path) : fPath(path)
, fMode(mode) , fMode(mode)
, fDstColorType(dstColorType) , fDstColorType(dstColorType)
, fDstAlphaType(dstAlphaType)
, fScale(scale) , fScale(scale)
{} {}
@ -251,30 +253,26 @@ bool CodecSrc::veto(SinkFlags flags) const {
return flags.type != SinkFlags::kRaster || flags.approach != SinkFlags::kDirect; return flags.type != SinkFlags::kRaster || flags.approach != SinkFlags::kDirect;
} }
bool get_decode_info(SkImageInfo* decodeInfo, const SkImageInfo& defaultInfo, bool get_decode_info(SkImageInfo* decodeInfo, SkColorType canvasColorType,
SkColorType canvasColorType, CodecSrc::DstColorType dstColorType) { CodecSrc::DstColorType dstColorType) {
switch (dstColorType) { switch (dstColorType) {
case CodecSrc::kIndex8_Always_DstColorType: case CodecSrc::kIndex8_Always_DstColorType:
if (kRGB_565_SkColorType == canvasColorType) { if (kRGB_565_SkColorType == canvasColorType) {
return false; return false;
} }
*decodeInfo = defaultInfo.makeColorType(kIndex_8_SkColorType); *decodeInfo = decodeInfo->makeColorType(kIndex_8_SkColorType);
break; break;
case CodecSrc::kGrayscale_Always_DstColorType: case CodecSrc::kGrayscale_Always_DstColorType:
if (kRGB_565_SkColorType == canvasColorType) { if (kRGB_565_SkColorType == canvasColorType) {
return false; return false;
} }
*decodeInfo = defaultInfo.makeColorType(kGray_8_SkColorType); *decodeInfo = decodeInfo->makeColorType(kGray_8_SkColorType);
break; break;
default: default:
*decodeInfo = defaultInfo.makeColorType(canvasColorType); *decodeInfo = decodeInfo->makeColorType(canvasColorType);
break; break;
} }
// FIXME: Currently we cannot draw unpremultiplied sources.
if (decodeInfo->alphaType() == kUnpremul_SkAlphaType) {
*decodeInfo = decodeInfo->makeAlphaType(kPremul_SkAlphaType);
}
return true; return true;
} }
@ -319,9 +317,8 @@ Error CodecSrc::draw(SkCanvas* canvas) const {
return SkStringPrintf("Couldn't create codec for %s.", fPath.c_str()); return SkStringPrintf("Couldn't create codec for %s.", fPath.c_str());
} }
SkImageInfo decodeInfo; SkImageInfo decodeInfo = codec->getInfo().makeAlphaType(fDstAlphaType);
if (!get_decode_info(&decodeInfo, codec->getInfo(), canvas->imageInfo().colorType(), if (!get_decode_info(&decodeInfo, canvas->imageInfo().colorType(), fDstColorType)) {
fDstColorType)) {
return Error::Nonfatal("Testing non-565 to 565 is uninteresting."); return Error::Nonfatal("Testing non-565 to 565 is uninteresting.");
} }
@ -570,10 +567,11 @@ Name CodecSrc::name() const {
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
AndroidCodecSrc::AndroidCodecSrc(Path path, Mode mode, CodecSrc::DstColorType dstColorType, AndroidCodecSrc::AndroidCodecSrc(Path path, Mode mode, CodecSrc::DstColorType dstColorType,
int sampleSize) SkAlphaType dstAlphaType, int sampleSize)
: fPath(path) : fPath(path)
, fMode(mode) , fMode(mode)
, fDstColorType(dstColorType) , fDstColorType(dstColorType)
, fDstAlphaType(dstAlphaType)
, fSampleSize(sampleSize) , fSampleSize(sampleSize)
{} {}
@ -593,9 +591,8 @@ Error AndroidCodecSrc::draw(SkCanvas* canvas) const {
return SkStringPrintf("Couldn't create android codec for %s.", fPath.c_str()); return SkStringPrintf("Couldn't create android codec for %s.", fPath.c_str());
} }
SkImageInfo decodeInfo; SkImageInfo decodeInfo = codec->getInfo().makeAlphaType(fDstAlphaType);
if (!get_decode_info(&decodeInfo, codec->getInfo(), canvas->imageInfo().colorType(), if (!get_decode_info(&decodeInfo, canvas->imageInfo().colorType(), fDstColorType)) {
fDstColorType)) {
return Error::Nonfatal("Testing non-565 to 565 is uninteresting."); return Error::Nonfatal("Testing non-565 to 565 is uninteresting.");
} }

View File

@ -118,7 +118,7 @@ public:
kIndex8_Always_DstColorType, kIndex8_Always_DstColorType,
kGrayscale_Always_DstColorType, kGrayscale_Always_DstColorType,
}; };
CodecSrc(Path, Mode, DstColorType, float); CodecSrc(Path, Mode, DstColorType, SkAlphaType, float);
Error draw(SkCanvas*) const override; Error draw(SkCanvas*) const override;
SkISize size() const override; SkISize size() const override;
@ -128,6 +128,7 @@ private:
Path fPath; Path fPath;
Mode fMode; Mode fMode;
DstColorType fDstColorType; DstColorType fDstColorType;
SkAlphaType fDstAlphaType;
float fScale; float fScale;
}; };
@ -140,7 +141,7 @@ public:
kDivisor_Mode, kDivisor_Mode,
}; };
AndroidCodecSrc(Path, Mode, CodecSrc::DstColorType, int sampleSize); AndroidCodecSrc(Path, Mode, CodecSrc::DstColorType, SkAlphaType, int sampleSize);
Error draw(SkCanvas*) const override; Error draw(SkCanvas*) const override;
SkISize size() const override; SkISize size() const override;
@ -150,6 +151,7 @@ private:
Path fPath; Path fPath;
Mode fMode; Mode fMode;
CodecSrc::DstColorType fDstColorType; CodecSrc::DstColorType fDstColorType;
SkAlphaType fDstAlphaType;
int fSampleSize; int fSampleSize;
}; };

View File

@ -570,15 +570,14 @@ protected:
* scanlines. This allows the subclass to indicate what value to fill with. * scanlines. This allows the subclass to indicate what value to fill with.
* *
* @param colorType Destination color type. * @param colorType Destination color type.
* @param alphaType Destination alpha type.
* @return The value with which to fill uninitialized pixels. * @return The value with which to fill uninitialized pixels.
* *
* Note that we can interpret the return value as an SkPMColor, a 16-bit 565 color, * Note that we can interpret the return value as an SkPMColor, a 16-bit 565 color,
* an 8-bit gray color, or an 8-bit index into a color table, depending on the color * an 8-bit gray color, or an 8-bit index into a color table, depending on the color
* type. * type.
*/ */
uint32_t getFillValue(SkColorType colorType, SkAlphaType alphaType) const { uint32_t getFillValue(SkColorType colorType) const {
return this->onGetFillValue(colorType, alphaType); return this->onGetFillValue(colorType);
} }
/** /**
@ -586,13 +585,13 @@ protected:
* types that we support. Note that for color types that do not use the full 32-bits, * types that we support. Note that for color types that do not use the full 32-bits,
* we will simply take the low bits of the fill value. * we will simply take the low bits of the fill value.
* *
* kN32_SkColorType: Transparent or Black * kN32_SkColorType: Transparent or Black, depending on the src alpha type
* kRGB_565_SkColorType: Black * kRGB_565_SkColorType: Black
* kGray_8_SkColorType: Black * kGray_8_SkColorType: Black
* kIndex_8_SkColorType: First color in color table * kIndex_8_SkColorType: First color in color table
*/ */
virtual uint32_t onGetFillValue(SkColorType /*colorType*/, SkAlphaType alphaType) const { virtual uint32_t onGetFillValue(SkColorType /*colorType*/) const {
return kOpaque_SkAlphaType == alphaType ? SK_ColorBLACK : SK_ColorTRANSPARENT; return kOpaque_SkAlphaType == fSrcInfo.alphaType() ? SK_ColorBLACK : SK_ColorTRANSPARENT;
} }
/** /**

View File

@ -182,7 +182,7 @@ bool SkBmpStandardCodec::initializeSwizzler(const SkImageInfo& dstInfo, const Op
config = SkSwizzler::kBGR; config = SkSwizzler::kBGR;
break; break;
case 32: case 32:
if (kOpaque_SkAlphaType == dstInfo.alphaType()) { if (kOpaque_SkAlphaType == this->getInfo().alphaType()) {
config = SkSwizzler::kBGRX; config = SkSwizzler::kBGRX;
} else { } else {
config = SkSwizzler::kBGRA; config = SkSwizzler::kBGRA;
@ -337,10 +337,10 @@ void SkBmpStandardCodec::decodeIcoMask(SkStream* stream, const SkImageInfo& dstI
} }
} }
uint32_t SkBmpStandardCodec::onGetFillValue(SkColorType colorType, SkAlphaType alphaType) const { uint32_t SkBmpStandardCodec::onGetFillValue(SkColorType colorType) const {
const SkPMColor* colorPtr = get_color_ptr(fColorTable.get()); const SkPMColor* colorPtr = get_color_ptr(fColorTable.get());
if (colorPtr) { if (colorPtr) {
return get_color_table_fill_value(colorType, colorPtr, 0); return get_color_table_fill_value(colorType, colorPtr, 0);
} }
return INHERITED::onGetFillValue(colorType, alphaType); return INHERITED::onGetFillValue(colorType);
} }

View File

@ -55,7 +55,7 @@ protected:
int* inputColorCount) override; int* inputColorCount) override;
uint32_t onGetFillValue(SkColorType colorType, SkAlphaType alphaType) const override; uint32_t onGetFillValue(SkColorType) const override;
SkSampler* getSampler(bool createIfNecessary) override { SkSampler* getSampler(bool createIfNecessary) override {
SkASSERT(fSwizzler); SkASSERT(fSwizzler);

View File

@ -352,7 +352,7 @@ void SkCodec::fillIncompleteImage(const SkImageInfo& info, void* dst, size_t row
ZeroInitialized zeroInit, int linesRequested, int linesDecoded) { ZeroInitialized zeroInit, int linesRequested, int linesDecoded) {
void* fillDst; void* fillDst;
const uint32_t fillValue = this->getFillValue(info.colorType(), info.alphaType()); const uint32_t fillValue = this->getFillValue(info.colorType());
const int linesRemaining = linesRequested - linesDecoded; const int linesRemaining = linesRequested - linesDecoded;
SkSampler* sampler = this->getSampler(false); SkSampler* sampler = this->getSampler(false);

View File

@ -14,6 +14,12 @@
#include "SkTypes.h" #include "SkTypes.h"
#include "SkUtils.h" #include "SkUtils.h"
#ifdef SK_PRINT_CODEC_MESSAGES
#define SkCodecPrintf SkDebugf
#else
#define SkCodecPrintf(...)
#endif
// FIXME: Consider sharing with dm, nanbench, and tools. // FIXME: Consider sharing with dm, nanbench, and tools.
inline float get_scale_from_sample_size(int sampleSize) { inline float get_scale_from_sample_size(int sampleSize) {
return 1.0f / ((float) sampleSize); return 1.0f / ((float) sampleSize);
@ -75,11 +81,16 @@ inline bool is_coord_necessary(int srcCoord, int sampleFactor, int scaledDim) {
} }
inline bool valid_alpha(SkAlphaType dstAlpha, SkAlphaType srcAlpha) { inline bool valid_alpha(SkAlphaType dstAlpha, SkAlphaType srcAlpha) {
// Check for supported alpha types if (kUnknown_SkAlphaType == dstAlpha) {
return false;
}
if (srcAlpha != dstAlpha) { if (srcAlpha != dstAlpha) {
if (kOpaque_SkAlphaType == srcAlpha) { if (kOpaque_SkAlphaType == srcAlpha) {
// If the source is opaque, we must decode to opaque // If the source is opaque, we can support any.
return false; SkCodecPrintf("Warning: an opaque image should be decoded as opaque "
"- it is being decoded as non-opaque, which will draw slower\n");
return true;
} }
// The source is not opaque // The source is not opaque
@ -99,7 +110,8 @@ inline bool valid_alpha(SkAlphaType dstAlpha, SkAlphaType srcAlpha) {
/* /*
* Most of our codecs support the same conversions: * Most of our codecs support the same conversions:
* - profileType must be the same * - profileType must be the same
* - opaque only to opaque (and 565 only if opaque) * - opaque to any alpha type
* - 565 only if opaque
* - premul to unpremul and vice versa * - premul to unpremul and vice versa
* - always support N32 * - always support N32
* - otherwise match the src color type * - otherwise match the src color type
@ -230,10 +242,4 @@ inline uint32_t get_int(uint8_t* buffer, uint32_t i) {
#endif #endif
} }
#ifdef SK_PRINT_CODEC_MESSAGES
#define SkCodecPrintf SkDebugf
#else
#define SkCodecPrintf(...)
#endif
#endif // SkCodecPriv_DEFINED #endif // SkCodecPriv_DEFINED

View File

@ -476,8 +476,7 @@ SkCodec::Result SkGifCodec::onGetPixels(const SkImageInfo& dstInfo,
// Initialize the swizzler // Initialize the swizzler
if (fFrameIsSubset) { if (fFrameIsSubset) {
// Fill the background // Fill the background
SkSampler::Fill(dstInfo, dst, dstRowBytes, SkSampler::Fill(dstInfo, dst, dstRowBytes, this->getFillValue(dstInfo.colorType()),
this->getFillValue(dstInfo.colorType(), dstInfo.alphaType()),
opts.fZeroInitialized); opts.fZeroInitialized);
} }
@ -495,7 +494,7 @@ SkCodec::Result SkGifCodec::onGetPixels(const SkImageInfo& dstInfo,
// FIXME: This is similar to the implementation for bmp and png. Can we share more code or // FIXME: This is similar to the implementation for bmp and png. Can we share more code or
// possibly make this non-virtual? // possibly make this non-virtual?
uint32_t SkGifCodec::onGetFillValue(SkColorType colorType, SkAlphaType alphaType) const { uint32_t SkGifCodec::onGetFillValue(SkColorType colorType) const {
const SkPMColor* colorPtr = get_color_ptr(fColorTable.get()); const SkPMColor* colorPtr = get_color_ptr(fColorTable.get());
return get_color_table_fill_value(colorType, colorPtr, fFillIndex); return get_color_table_fill_value(colorType, colorPtr, fFillIndex);
} }
@ -538,8 +537,7 @@ int SkGifCodec::onGetScanlines(void* dst, int count, size_t rowBytes) {
if (fFrameIsSubset) { if (fFrameIsSubset) {
// Fill the requested rows // Fill the requested rows
SkImageInfo fillInfo = this->dstInfo().makeWH(this->dstInfo().width(), count); SkImageInfo fillInfo = this->dstInfo().makeWH(this->dstInfo().width(), count);
uint32_t fillValue = this->onGetFillValue(this->dstInfo().colorType(), uint32_t fillValue = this->onGetFillValue(this->dstInfo().colorType());
this->dstInfo().alphaType());
fSwizzler->fill(fillInfo, dst, rowBytes, fillValue, this->options().fZeroInitialized); fSwizzler->fill(fillInfo, dst, rowBytes, fillValue, this->options().fZeroInitialized);
// Start to write pixels at the start of the image frame // Start to write pixels at the start of the image frame

View File

@ -64,7 +64,7 @@ protected:
bool onRewind() override; bool onRewind() override;
uint32_t onGetFillValue(SkColorType colorType, SkAlphaType alphaType) const override; uint32_t onGetFillValue(SkColorType) const override;
int onOutputScanline(int inputScanline) const override; int onOutputScanline(int inputScanline) const override;

View File

@ -164,11 +164,15 @@ bool SkJpegCodec::setOutputColorSpace(const SkImageInfo& dst) {
return false; return false;
} }
// Ensure that the alpha type is opaque if (kUnknown_SkAlphaType == dst.alphaType()) {
if (kOpaque_SkAlphaType != dst.alphaType()) {
return false; return false;
} }
if (kOpaque_SkAlphaType != dst.alphaType()) {
SkCodecPrintf("Warning: an opaque image should be decoded as opaque "
"- it is being decoded as non-opaque, which will draw slower\n");
}
// Check if we will decode to CMYK because a conversion to RGBA is not supported // Check if we will decode to CMYK because a conversion to RGBA is not supported
J_COLOR_SPACE colorSpace = fDecoderMgr->dinfo()->jpeg_color_space; J_COLOR_SPACE colorSpace = fDecoderMgr->dinfo()->jpeg_color_space;
bool isCMYK = JCS_CMYK == colorSpace || JCS_YCCK == colorSpace; bool isCMYK = JCS_CMYK == colorSpace || JCS_YCCK == colorSpace;

View File

@ -250,13 +250,7 @@ SkMaskSwizzler* SkMaskSwizzler::CreateMaskSwizzler(const SkImageInfo& dstInfo,
} }
break; break;
case kRGB_565_SkColorType: case kRGB_565_SkColorType:
switch (dstInfo.alphaType()) { proc = &swizzle_mask16_to_565;
case kOpaque_SkAlphaType:
proc = &swizzle_mask16_to_565;
break;
default:
break;
}
break; break;
default: default:
break; break;
@ -280,13 +274,7 @@ SkMaskSwizzler* SkMaskSwizzler::CreateMaskSwizzler(const SkImageInfo& dstInfo,
} }
break; break;
case kRGB_565_SkColorType: case kRGB_565_SkColorType:
switch (dstInfo.alphaType()) { proc = &swizzle_mask24_to_565;
case kOpaque_SkAlphaType:
proc = &swizzle_mask24_to_565;
break;
default:
break;
}
break; break;
default: default:
break; break;
@ -310,13 +298,7 @@ SkMaskSwizzler* SkMaskSwizzler::CreateMaskSwizzler(const SkImageInfo& dstInfo,
} }
break; break;
case kRGB_565_SkColorType: case kRGB_565_SkColorType:
switch (dstInfo.alphaType()) { proc = &swizzle_mask32_to_565;
case kOpaque_SkAlphaType:
proc = &swizzle_mask32_to_565;
break;
default:
break;
}
break; break;
default: default:
break; break;

View File

@ -535,12 +535,12 @@ SkCodec::Result SkPngCodec::onGetPixels(const SkImageInfo& requestedInfo, void*
return kSuccess; return kSuccess;
} }
uint32_t SkPngCodec::onGetFillValue(SkColorType colorType, SkAlphaType alphaType) const { uint32_t SkPngCodec::onGetFillValue(SkColorType colorType) const {
const SkPMColor* colorPtr = get_color_ptr(fColorTable.get()); const SkPMColor* colorPtr = get_color_ptr(fColorTable.get());
if (colorPtr) { if (colorPtr) {
return get_color_table_fill_value(colorType, colorPtr, 0); return get_color_table_fill_value(colorType, colorPtr, 0);
} }
return INHERITED::onGetFillValue(colorType, alphaType); return INHERITED::onGetFillValue(colorType);
} }
// Subclass of SkPngCodec which supports scanline decoding // Subclass of SkPngCodec which supports scanline decoding

View File

@ -31,7 +31,7 @@ protected:
override; override;
SkEncodedFormat onGetEncodedFormat() const override { return kPNG_SkEncodedFormat; } SkEncodedFormat onGetEncodedFormat() const override { return kPNG_SkEncodedFormat; }
bool onRewind() override; bool onRewind() override;
uint32_t onGetFillValue(SkColorType colorType, SkAlphaType alphaType) const override; uint32_t onGetFillValue(SkColorType) const override;
// Helper to set up swizzler and color table. Also calls png_read_update_info. // Helper to set up swizzler and color table. Also calls png_read_update_info.
Result initializeSwizzler(const SkImageInfo& requestedInfo, const Options&, Result initializeSwizzler(const SkImageInfo& requestedInfo, const Options&,

View File

@ -253,8 +253,7 @@ SkCodec::Result SkSampledCodec::sampledDecode(const SkImageInfo& info, void* pix
// We handle filling uninitialized memory here instead of using this->codec(). // We handle filling uninitialized memory here instead of using this->codec().
// this->codec() does not know that we are sampling. // this->codec() does not know that we are sampling.
const uint32_t fillValue = this->codec()->getFillValue(info.colorType(), const uint32_t fillValue = this->codec()->getFillValue(info.colorType());
info.alphaType());
const SkImageInfo fillInfo = info.makeWH(info.width(), 1); const SkImageInfo fillInfo = info.makeWH(info.width(), 1);
for (; y < nativeSize.height(); y++) { for (; y < nativeSize.height(); y++) {
int srcY = this->codec()->outputScanline(y); int srcY = this->codec()->outputScanline(y);

View File

@ -130,9 +130,9 @@ static void test_codec(skiatest::Reporter* r, SkCodec* codec, SkBitmap& bm, cons
// Check alpha type conversions // Check alpha type conversions
if (info.alphaType() == kOpaque_SkAlphaType) { if (info.alphaType() == kOpaque_SkAlphaType) {
test_info(r, codec, info.makeAlphaType(kUnpremul_SkAlphaType), test_info(r, codec, info.makeAlphaType(kUnpremul_SkAlphaType),
SkCodec::kInvalidConversion, nullptr); expectedResult, digest);
test_info(r, codec, info.makeAlphaType(kPremul_SkAlphaType), test_info(r, codec, info.makeAlphaType(kPremul_SkAlphaType),
SkCodec::kInvalidConversion, nullptr); expectedResult, digest);
} else { } else {
// Decoding to opaque should fail // Decoding to opaque should fail
test_info(r, codec, info.makeAlphaType(kOpaque_SkAlphaType), test_info(r, codec, info.makeAlphaType(kOpaque_SkAlphaType),
@ -183,9 +183,9 @@ static void test_android_codec(skiatest::Reporter* r, SkAndroidCodec* codec, SkB
// Check alpha type conversions // Check alpha type conversions
if (info.alphaType() == kOpaque_SkAlphaType) { if (info.alphaType() == kOpaque_SkAlphaType) {
test_android_info(r, codec, info.makeAlphaType(kUnpremul_SkAlphaType), test_android_info(r, codec, info.makeAlphaType(kUnpremul_SkAlphaType),
SkCodec::kInvalidConversion, nullptr); expectedResult, digest);
test_android_info(r, codec, info.makeAlphaType(kPremul_SkAlphaType), test_android_info(r, codec, info.makeAlphaType(kPremul_SkAlphaType),
SkCodec::kInvalidConversion, nullptr); expectedResult, digest);
} else { } else {
// Decoding to opaque should fail // Decoding to opaque should fail
test_android_info(r, codec, info.makeAlphaType(kOpaque_SkAlphaType), test_android_info(r, codec, info.makeAlphaType(kOpaque_SkAlphaType),