Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(122)

Unified Diff: src/codec/SkJpegCodec.cpp

Issue 2328663002: Revert of Checking for valid colorType, alphaType, colorSpace in SkCodec (Closed)
Patch Set: Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/codec/SkJpegCodec.h ('k') | src/codec/SkPngCodec.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/codec/SkJpegCodec.cpp
diff --git a/src/codec/SkJpegCodec.cpp b/src/codec/SkJpegCodec.cpp
index d2f7cdb0fa382db95a0e69c9ca9dea607a691f3b..fcf89d0c1d23b7c3ca6d55ec2674754602778cbb 100644
--- a/src/codec/SkJpegCodec.cpp
+++ b/src/codec/SkJpegCodec.cpp
@@ -357,7 +357,7 @@
* image has been implemented
* Sets the output color space
*/
-bool SkJpegCodec::setOutputColorSpace(const SkImageInfo& dstInfo) {
+bool SkJpegCodec::setOutputColorSpace(const SkImageInfo& dstInfo, bool needsColorXform) {
if (kUnknown_SkAlphaType == dstInfo.alphaType()) {
return false;
}
@@ -384,7 +384,7 @@
case kBGRA_8888_SkColorType:
if (isCMYK) {
fDecoderMgr->dinfo()->out_color_space = JCS_CMYK;
- } else if (fColorXform) {
+ } else if (needsColorXform) {
// Our color transformation code requires RGBA order inputs, but it'll swizzle
// to BGRA for us.
fDecoderMgr->dinfo()->out_color_space = JCS_EXT_RGBA;
@@ -393,7 +393,7 @@
}
return true;
case kRGB_565_SkColorType:
- if (fColorXform) {
+ if (needsColorXform) {
return false;
}
@@ -405,17 +405,14 @@
}
return true;
case kGray_8_SkColorType:
- if (fColorXform || JCS_GRAYSCALE != encodedColorType) {
+ if (needsColorXform || JCS_GRAYSCALE != encodedColorType) {
return false;
}
fDecoderMgr->dinfo()->out_color_space = JCS_GRAYSCALE;
return true;
case kRGBA_F16_SkColorType:
- SkASSERT(fColorXform);
- if (!dstInfo.colorSpace()->gammaIsLinear()) {
- return false;
- }
+ SkASSERT(needsColorXform);
if (isCMYK) {
fDecoderMgr->dinfo()->out_color_space = JCS_CMYK;
@@ -548,11 +545,14 @@
return fDecoderMgr->returnFailure("setjmp", kInvalidInput);
}
- this->initializeColorXform(dstInfo);
-
// Check if we can decode to the requested destination and set the output color space
- if (!this->setOutputColorSpace(dstInfo)) {
+ bool needsColorXform = needs_color_xform(dstInfo, this->getInfo());
+ if (!this->setOutputColorSpace(dstInfo, needsColorXform)) {
return fDecoderMgr->returnFailure("setOutputColorSpace", kInvalidConversion);
+ }
+
+ if (!this->initializeColorXform(dstInfo, needsColorXform)) {
+ return fDecoderMgr->returnFailure("initializeColorXform", kInvalidParameters);
}
if (!jpeg_start_decompress(dinfo)) {
@@ -630,12 +630,16 @@
SkASSERT(fSwizzler);
}
-void SkJpegCodec::initializeColorXform(const SkImageInfo& dstInfo) {
- if (needs_color_xform(dstInfo, this->getInfo())) {
+bool SkJpegCodec::initializeColorXform(const SkImageInfo& dstInfo, bool needsColorXform) {
+ if (needsColorXform) {
fColorXform = SkColorSpaceXform::New(sk_ref_sp(this->getInfo().colorSpace()),
sk_ref_sp(dstInfo.colorSpace()));
- SkASSERT(fColorXform);
- }
+ if (!fColorXform && kRGBA_F16_SkColorType == dstInfo.colorType()) {
+ return false;
+ }
+ }
+
+ return true;
}
SkSampler* SkJpegCodec::getSampler(bool createIfNecessary) {
@@ -657,11 +661,14 @@
return kInvalidInput;
}
- this->initializeColorXform(dstInfo);
-
// Check if we can decode to the requested destination and set the output color space
- if (!this->setOutputColorSpace(dstInfo)) {
- return fDecoderMgr->returnFailure("setOutputColorSpace", kInvalidConversion);
+ bool needsColorXform = needs_color_xform(dstInfo, this->getInfo());
+ if (!this->setOutputColorSpace(dstInfo, needsColorXform)) {
+ return kInvalidConversion;
+ }
+
+ if (!this->initializeColorXform(dstInfo, needsColorXform)) {
+ return fDecoderMgr->returnFailure("initializeColorXform", kInvalidParameters);
}
if (!jpeg_start_decompress(fDecoderMgr->dinfo())) {
« no previous file with comments | « src/codec/SkJpegCodec.h ('k') | src/codec/SkPngCodec.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698