Stop using SkSwizzler in SkRawCodec

Bug: skia:8473

SkRawCodec doesn't implement scanline decoding or incremental decoding,
so it doesn't take advantage of SkSwizzler's sampling. It just uses it
to do conversion, and then it potentially uses skcms to transform
colors. Instead, always use skcms and avoid creating the SkSwizzler.

Change-Id: Ie0d4f83b0eac18150a6d52382c8283babb6cbfca
Reviewed-on: https://skia-review.googlesource.com/c/175592
Commit-Queue: Leon Scroggins <scroggo@google.com>
Commit-Queue: Mike Klein <mtklein@google.com>
Auto-Submit: Leon Scroggins <scroggo@google.com>
Reviewed-by: Mike Klein <mtklein@google.com>
This commit is contained in:
Leon Scroggins III 2018-12-07 14:04:47 -05:00 committed by Skia Commit-Bot
parent 66c26ac935
commit 96765960dc
2 changed files with 39 additions and 18 deletions

View File

@ -17,7 +17,6 @@
#include "SkRefCnt.h"
#include "SkStream.h"
#include "SkStreamPriv.h"
#include "SkSwizzler.h"
#include "SkTArray.h"
#include "SkTaskGroup.h"
#include "SkTemplates.h"
@ -697,17 +696,6 @@ std::unique_ptr<SkCodec> SkRawCodec::MakeFromStream(std::unique_ptr<SkStream> st
SkCodec::Result SkRawCodec::onGetPixels(const SkImageInfo& dstInfo, void* dst,
size_t dstRowBytes, const Options& options,
int* rowsDecoded) {
SkImageInfo swizzlerInfo = dstInfo;
std::unique_ptr<uint32_t[]> xformBuffer = nullptr;
if (this->colorXform()) {
swizzlerInfo = swizzlerInfo.makeColorType(kRGBA_8888_SkColorType);
xformBuffer.reset(new uint32_t[dstInfo.width()]);
}
std::unique_ptr<SkSwizzler> swizzler = SkSwizzler::Make(
this->getEncodedInfo(), nullptr, swizzlerInfo, options);
SkASSERT(swizzler);
const int width = dstInfo.width();
const int height = dstInfo.height();
std::unique_ptr<dng_image> image(fDngImage->render(width, height));
@ -737,6 +725,34 @@ SkCodec::Result SkRawCodec::onGetPixels(const SkImageInfo& dstInfo, void* dst,
buffer.fPixelSize = sizeof(uint8_t);
buffer.fRowStep = width * 3;
constexpr auto srcFormat = skcms_PixelFormat_RGB_888;
skcms_PixelFormat dstFormat;
switch (dstInfo.colorType()) {
case kRGBA_8888_SkColorType:
dstFormat = skcms_PixelFormat_RGBA_8888;
break;
case kBGRA_8888_SkColorType:
dstFormat = skcms_PixelFormat_BGRA_8888;
break;
case kRGBA_F16_SkColorType:
dstFormat = skcms_PixelFormat_RGBA_hhhh;
break;
case kRGB_565_SkColorType:
dstFormat = skcms_PixelFormat_RGB_565;
break;
default:
return kInvalidConversion;
}
const skcms_ICCProfile* const srcProfile = this->getEncodedInfo().profile();
skcms_ICCProfile dstProfileStorage;
const skcms_ICCProfile* dstProfile = nullptr;
if (auto cs = dstInfo.colorSpace()) {
cs->toProfile(&dstProfileStorage);
dstProfile = &dstProfileStorage;
}
for (int i = 0; i < height; ++i) {
buffer.fArea = dng_rect(i, 0, i + 1, width);
@ -747,13 +763,14 @@ SkCodec::Result SkRawCodec::onGetPixels(const SkImageInfo& dstInfo, void* dst,
return kIncompleteInput;
}
if (this->colorXform()) {
swizzler->swizzle(xformBuffer.get(), &srcRow[0]);
this->applyColorXform(dstRow, xformBuffer.get(), dstInfo.width());
} else {
swizzler->swizzle(dstRow, &srcRow[0]);
if (!skcms_Transform(&srcRow[0], srcFormat, skcms_AlphaFormat_Unpremul, srcProfile,
dstRow, dstFormat, skcms_AlphaFormat_Unpremul, dstProfile,
dstInfo.width())) {
SkDebugf("failed to transform\n");
*rowsDecoded = i;
return kInternalError;
}
dstRow = SkTAddOffset<void>(dstRow, dstRowBytes);
}
return kSuccess;

View File

@ -45,6 +45,10 @@ protected:
bool onDimensionsSupported(const SkISize&) override;
// SkCodec only applies the colorXform if it's necessary for color space
// conversion. SkRawCodec will always convert, so tell SkCodec not to.
bool usesColorXform() const override { return false; }
private:
/*