diff options
author | Matt Sarett <msarett@google.com> | 2016-11-03 16:15:20 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2016-11-03 20:58:13 +0000 |
commit | 1b96c6f91377431cd407c43fedac613fff21c2ed (patch) | |
tree | 0a4d5899f2cae7573aa85d56866ad7613338b6f2 /src/codec/SkBmpStandardCodec.cpp | |
parent | 6e437b7d177cabdb9822b437ed2caefebe6b469b (diff) |
Add F16, SkColorSpaceXform support to SkBmpCodec
BUG=skia:4895
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=4390
Change-Id: I9cb727e7f13816b0ac882f62ec635a4528c3a524
Reviewed-on: https://skia-review.googlesource.com/4390
Reviewed-by: Matt Sarett <msarett@google.com>
Commit-Queue: Matt Sarett <msarett@google.com>
Diffstat (limited to 'src/codec/SkBmpStandardCodec.cpp')
-rw-r--r-- | src/codec/SkBmpStandardCodec.cpp | 43 |
1 files changed, 31 insertions, 12 deletions
diff --git a/src/codec/SkBmpStandardCodec.cpp b/src/codec/SkBmpStandardCodec.cpp index 2dbb338a07..2a703fdff9 100644 --- a/src/codec/SkBmpStandardCodec.cpp +++ b/src/codec/SkBmpStandardCodec.cpp @@ -48,10 +48,6 @@ SkCodec::Result SkBmpStandardCodec::onGetPixels(const SkImageInfo& dstInfo, SkCodecPrintf("Error: scaling not supported.\n"); return kInvalidScale; } - if (!conversion_possible_ignore_color_space(dstInfo, this->getInfo())) { - SkCodecPrintf("Error: cannot convert input type to output type.\n"); - return kInvalidConversion; - } Result result = this->prepareToDecode(dstInfo, opts, inputColorPtr, inputColorCount); if (kSuccess != result) { @@ -153,13 +149,13 @@ void SkBmpStandardCodec::initializeSwizzler(const SkImageInfo& dstInfo, const Op // In the case of bmp-in-icos, we will report BGRA to the client, // since we may be required to apply an alpha mask after the decode. // However, the swizzler needs to know the actual format of the bmp. - SkEncodedInfo swizzlerInfo = this->getEncodedInfo(); + SkEncodedInfo encodedInfo = this->getEncodedInfo(); if (fInIco) { if (this->bitsPerPixel() <= 8) { - swizzlerInfo = SkEncodedInfo::Make(SkEncodedInfo::kPalette_Color, - swizzlerInfo.alpha(), this->bitsPerPixel()); + encodedInfo = SkEncodedInfo::Make(SkEncodedInfo::kPalette_Color, + encodedInfo.alpha(), this->bitsPerPixel()); } else if (this->bitsPerPixel() == 24) { - swizzlerInfo = SkEncodedInfo::Make(SkEncodedInfo::kBGR_Color, + encodedInfo = SkEncodedInfo::Make(SkEncodedInfo::kBGR_Color, SkEncodedInfo::kOpaque_Alpha, 8); } } @@ -167,13 +163,29 @@ void SkBmpStandardCodec::initializeSwizzler(const SkImageInfo& dstInfo, const Op // Get a pointer to the color table if it exists const SkPMColor* colorPtr = get_color_ptr(fColorTable.get()); - // Create swizzler - fSwizzler.reset(SkSwizzler::CreateSwizzler(swizzlerInfo, colorPtr, dstInfo, opts)); + SkImageInfo swizzlerInfo = dstInfo; + SkCodec::Options swizzlerOptions = opts; + if (this->colorXform()) { + swizzlerInfo = swizzlerInfo.makeColorType(kBGRA_8888_SkColorType); + if (kPremul_SkAlphaType == dstInfo.alphaType()) { + swizzlerInfo = swizzlerInfo.makeAlphaType(kUnpremul_SkAlphaType); + } + + swizzlerOptions.fZeroInitialized = kNo_ZeroInitialized; + } + + + fSwizzler.reset(SkSwizzler::CreateSwizzler(encodedInfo, colorPtr, swizzlerInfo, + swizzlerOptions)); SkASSERT(fSwizzler); } -SkCodec::Result SkBmpStandardCodec::prepareToDecode(const SkImageInfo& dstInfo, +SkCodec::Result SkBmpStandardCodec::onPrepareToDecode(const SkImageInfo& dstInfo, const SkCodec::Options& options, SkPMColor inputColorPtr[], int* inputColorCount) { + if (this->colorXform()) { + this->resetXformBuffer(dstInfo.width()); + } + // Create the color table if necessary and prepare the stream for decode // Note that if it is non-NULL, inputColorCount will be modified if (!this->createColorTable(dstInfo.colorType(), dstInfo.alphaType(), inputColorCount)) { @@ -207,7 +219,14 @@ int SkBmpStandardCodec::decodeRows(const SkImageInfo& dstInfo, void* dst, size_t uint32_t row = this->getDstRow(y, dstInfo.height()); void* dstRow = SkTAddOffset<void>(dst, row * dstRowBytes); - fSwizzler->swizzle(dstRow, fSrcBuffer.get()); + + if (this->colorXform()) { + SkImageInfo xformInfo = dstInfo.makeWH(fSwizzler->swizzleWidth(), dstInfo.height()); + fSwizzler->swizzle(this->xformBuffer(), fSrcBuffer.get()); + this->applyColorXform(xformInfo, dstRow, this->xformBuffer()); + } else { + fSwizzler->swizzle(dstRow, fSrcBuffer.get()); + } } if (fInIco && fIsOpaque) { |