aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/codec/SkBmpStandardCodec.cpp
diff options
context:
space:
mode:
authorGravatar Matt Sarett <msarett@google.com>2016-11-04 11:52:48 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2016-11-04 16:25:27 +0000
commit1a85ca5c908b421ea8f07798d56c4481bbc5d5af (patch)
tree950dc8aa3dbba05f4ad987d5a76d8461b2fc5ac5 /src/codec/SkBmpStandardCodec.cpp
parent4d53c44aa6e8e0d1b6537f83e4287e5a1423ac75 (diff)
Fix color xforms for Index8 bmps
Thanks to Gold for catching this. BUG=skia:4895 GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=4426 Change-Id: Icc816d933e9e2fd312858a5430fa21a47722563e Reviewed-on: https://skia-review.googlesource.com/4426 Commit-Queue: Matt Sarett <msarett@google.com> Reviewed-by: Leon Scroggins <scroggo@google.com>
Diffstat (limited to 'src/codec/SkBmpStandardCodec.cpp')
-rw-r--r--src/codec/SkBmpStandardCodec.cpp32
1 files changed, 27 insertions, 5 deletions
diff --git a/src/codec/SkBmpStandardCodec.cpp b/src/codec/SkBmpStandardCodec.cpp
index 2a703fdff9..9b346f3be6 100644
--- a/src/codec/SkBmpStandardCodec.cpp
+++ b/src/codec/SkBmpStandardCodec.cpp
@@ -25,10 +25,11 @@ SkBmpStandardCodec::SkBmpStandardCodec(int width, int height, const SkEncodedInf
, fBytesPerColor(bytesPerColor)
, fOffset(offset)
, fSwizzler(nullptr)
- , fSrcBuffer(new uint8_t [this->srcRowBytes()])
+ , fSrcBuffer(new uint8_t[this->srcRowBytes()])
, fIsOpaque(isOpaque)
, fInIco(inIco)
, fAndMaskRowBytes(fInIco ? SkAlign4(compute_row_bytes(this->getInfo().width(), 1)) : 0)
+ , fXformOnDecode(false)
{}
/*
@@ -90,9 +91,16 @@ SkCodec::Result SkBmpStandardCodec::onGetPixels(const SkImageInfo& dstInfo,
return false;
}
+ SkColorType packColorType = dstColorType;
+ SkAlphaType packAlphaType = dstAlphaType;
+ if (this->colorXform()) {
+ packColorType = kBGRA_8888_SkColorType;
+ packAlphaType = kUnpremul_SkAlphaType;
+ }
+
// Choose the proper packing function
- bool isPremul = (kPremul_SkAlphaType == dstAlphaType) && !fIsOpaque;
- PackColorProc packARGB = choose_pack_color_proc(isPremul, dstColorType);
+ bool isPremul = (kPremul_SkAlphaType == packAlphaType) && !fIsOpaque;
+ PackColorProc packARGB = choose_pack_color_proc(isPremul, packColorType);
// Fill in the color table
uint32_t i = 0;
@@ -116,6 +124,15 @@ SkCodec::Result SkBmpStandardCodec::onGetPixels(const SkImageInfo& dstInfo,
colorTable[i] = SkPackARGB32NoCheck(0xFF, 0, 0, 0);
}
+ if (this->colorXform() && !fXformOnDecode) {
+ SkColorSpaceXform::ColorFormat dstFormat = select_xform_format(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));
+ }
+
// Set the color table
fColorTable.reset(new SkColorTable(colorTable, maxColors));
}
@@ -182,8 +199,12 @@ 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()) {
- this->resetXformBuffer(dstInfo.width());
+ fXformOnDecode = apply_xform_on_decode(dstInfo.colorType(), this->getEncodedInfo().color());
+ if (fXformOnDecode) {
+ this->resetXformBuffer(dstInfo.width());
+ }
}
// Create the color table if necessary and prepare the stream for decode
@@ -220,7 +241,8 @@ int SkBmpStandardCodec::decodeRows(const SkImageInfo& dstInfo, void* dst, size_t
void* dstRow = SkTAddOffset<void>(dst, row * dstRowBytes);
- if (this->colorXform()) {
+ if (fXformOnDecode) {
+ SkASSERT(this->colorXform());
SkImageInfo xformInfo = dstInfo.makeWH(fSwizzler->swizzleWidth(), dstInfo.height());
fSwizzler->swizzle(this->xformBuffer(), fSrcBuffer.get());
this->applyColorXform(xformInfo, dstRow, this->xformBuffer());