aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar Matt Sarett <msarett@google.com>2017-03-24 16:31:19 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-04-03 18:32:42 +0000
commitd531ca038fac8acb3320a78c393c002ca59768fe (patch)
tree2d9891fae706bf8aa7972dda94b01cb6a56cf45c /src
parent8576014d8a8b799b30dbee4b9d86571fc4781807 (diff)
Use SkTransferFunctionBehavior in SkImageGenerator
This fixes SkColorSpaceXformCanvas gms that expect non-linear premuls from the codec. BUG=skia: Change-Id: I5dc236d0cd760c23605a26e9c33ddb18955f9231 Reviewed-on: https://skia-review.googlesource.com/10164 Reviewed-by: Mike Klein <mtklein@chromium.org> Commit-Queue: Matt Sarett <msarett@google.com>
Diffstat (limited to 'src')
-rw-r--r--src/codec/SkCodecImageGenerator.cpp15
-rw-r--r--src/codec/SkCodecImageGenerator.h4
-rw-r--r--src/core/SkImageCacherator.cpp8
-rw-r--r--src/core/SkImageCacherator.h2
-rw-r--r--src/core/SkImageGenerator.cpp9
-rw-r--r--src/image/SkImage_Generator.cpp8
6 files changed, 38 insertions, 8 deletions
diff --git a/src/codec/SkCodecImageGenerator.cpp b/src/codec/SkCodecImageGenerator.cpp
index 56ca21eb76..6467033371 100644
--- a/src/codec/SkCodecImageGenerator.cpp
+++ b/src/codec/SkCodecImageGenerator.cpp
@@ -37,8 +37,19 @@ SkData* SkCodecImageGenerator::onRefEncodedData(GrContext* ctx) {
bool SkCodecImageGenerator::onGetPixels(const SkImageInfo& info, void* pixels, size_t rowBytes,
SkPMColor ctable[], int* ctableCount) {
- SkCodec::Result result = fCodec->getPixels(info, pixels, rowBytes, nullptr, ctable,
- ctableCount);
+ Options opts;
+ opts.fColorTable = ctable;
+ opts.fColorTableCount = ctableCount;
+ opts.fBehavior = SkTransferFunctionBehavior::kRespect;
+ return this->onGetPixels(info, pixels, rowBytes, opts);
+}
+
+bool SkCodecImageGenerator::onGetPixels(const SkImageInfo& info, void* pixels, size_t rowBytes,
+ const Options& opts) {
+ SkCodec::Options codecOpts;
+ codecOpts.fPremulBehavior = opts.fBehavior;
+ SkCodec::Result result = fCodec->getPixels(info, pixels, rowBytes, &codecOpts, opts.fColorTable,
+ opts.fColorTableCount);
switch (result) {
case SkCodec::kSuccess:
case SkCodec::kIncompleteInput:
diff --git a/src/codec/SkCodecImageGenerator.h b/src/codec/SkCodecImageGenerator.h
index 727a747ec2..a435205fa9 100644
--- a/src/codec/SkCodecImageGenerator.h
+++ b/src/codec/SkCodecImageGenerator.h
@@ -24,7 +24,9 @@ protected:
SkData* onRefEncodedData(GrContext* ctx) override;
bool onGetPixels(const SkImageInfo& info, void* pixels, size_t rowBytes, SkPMColor ctable[],
- int* ctableCount) override;
+ int* ctableCount) override;
+ bool onGetPixels(const SkImageInfo& info, void* pixels, size_t rowBytes, const Options& opts)
+ override;
bool onQueryYUV8(SkYUVSizeInfo*, SkYUVColorSpace*) const override;
diff --git a/src/core/SkImageCacherator.cpp b/src/core/SkImageCacherator.cpp
index 4929c6b94c..1a37f3b217 100644
--- a/src/core/SkImageCacherator.cpp
+++ b/src/core/SkImageCacherator.cpp
@@ -166,14 +166,18 @@ bool SkImageCacherator::generateBitmap(SkBitmap* bitmap, const SkImageInfo& deco
}
bool SkImageCacherator::directGeneratePixels(const SkImageInfo& info, void* pixels, size_t rb,
- int srcX, int srcY) {
+ int srcX, int srcY,
+ SkTransferFunctionBehavior behavior) {
ScopedGenerator generator(fSharedGenerator);
const SkImageInfo& genInfo = generator->getInfo();
// Currently generators do not natively handle subsets, so check that first.
if (srcX || srcY || genInfo.width() != info.width() || genInfo.height() != info.height()) {
return false;
}
- return generator->getPixels(info, pixels, rb);
+
+ SkImageGenerator::Options opts;
+ opts.fBehavior = behavior;
+ return generator->getPixels(info, pixels, rb, &opts);
}
//////////////////////////////////////////////////////////////////////////////////////////////////
diff --git a/src/core/SkImageCacherator.h b/src/core/SkImageCacherator.h
index e75aab7a93..233b7db13e 100644
--- a/src/core/SkImageCacherator.h
+++ b/src/core/SkImageCacherator.h
@@ -88,7 +88,7 @@ public:
bool lockAsBitmapOnlyIfAlreadyCached(SkBitmap*, CachedFormat);
// Call the underlying generator directly
bool directGeneratePixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRB,
- int srcX, int srcY);
+ int srcX, int srcY, SkTransferFunctionBehavior behavior);
private:
// Ref-counted tuple(SkImageGenerator, SkMutex) which allows sharing of one generator
diff --git a/src/core/SkImageGenerator.cpp b/src/core/SkImageGenerator.cpp
index 18a6ce2669..2f209ca99c 100644
--- a/src/core/SkImageGenerator.cpp
+++ b/src/core/SkImageGenerator.cpp
@@ -45,6 +45,15 @@ bool SkImageGenerator::getPixels(const SkImageInfo& info, void* pixels, size_t r
return success;
}
+bool SkImageGenerator::getPixels(const SkImageInfo& info, void* pixels, size_t rowBytes,
+ const Options* opts) {
+ Options defaultOpts;
+ if (!opts) {
+ opts = &defaultOpts;
+ }
+ return this->onGetPixels(info, pixels, rowBytes, *opts);
+}
+
bool SkImageGenerator::getPixels(const SkImageInfo& info, void* pixels, size_t rowBytes) {
SkASSERT(kIndex_8_SkColorType != info.colorType());
if (kIndex_8_SkColorType == info.colorType()) {
diff --git a/src/image/SkImage_Generator.cpp b/src/image/SkImage_Generator.cpp
index 15977b9218..51fb281c26 100644
--- a/src/image/SkImage_Generator.cpp
+++ b/src/image/SkImage_Generator.cpp
@@ -60,7 +60,8 @@ bool SkImage_Generator::onReadPixels(const SkImageInfo& dstInfo, void* dstPixels
// Try passing the caller's buffer directly down to the generator. If this fails we
// may still succeed in the general case, as the generator may prefer some other
// config, which we could then convert via SkBitmap::readPixels.
- if (fCache.directGeneratePixels(dstInfo, dstPixels, dstRB, srcX, srcY)) {
+ if (fCache.directGeneratePixels(dstInfo, dstPixels, dstRB, srcX, srcY,
+ SkTransferFunctionBehavior::kRespect)) {
return true;
}
// else fall through
@@ -112,7 +113,10 @@ sk_sp<SkImage> SkImage_Generator::onMakeColorSpace(sk_sp<SkColorSpace> target) c
}
dst.allocPixels(dstInfo);
- if (!fCache.directGeneratePixels(dstInfo, dst.getPixels(), dst.rowBytes(), 0, 0)) {
+ // Use kIgnore for transfer function behavior. This is used by the SkColorSpaceXformCanvas,
+ // which wants to pre-xform the inputs but ignore the transfer function on blends.
+ if (!fCache.directGeneratePixels(dstInfo, dst.getPixels(), dst.rowBytes(), 0, 0,
+ SkTransferFunctionBehavior::kIgnore)) {
return nullptr;
}