Fix CMYK handling in JPEG codec

Now that the ground-truth color profile is in the skcms profile, we
can't check the info's SkColorSpace (which will never be CMYK) to make
this determination. Look at the profile instead.

Change-Id: I6afda07de35e28b41d73b0b6740e4c46359e5162
Reviewed-on: https://skia-review.googlesource.com/148802
Reviewed-by: Leon Scroggins <scroggo@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
This commit is contained in:
Brian Osman 2018-08-22 15:38:47 -04:00 committed by Skia Commit-Bot
parent d1589c7213
commit f8ae5ce20c

View File

@ -555,16 +555,17 @@ int SkJpegCodec::readRows(const SkImageInfo& dstInfo, void* dst, size_t rowBytes
/*
* This is a bit tricky. We only need the swizzler to do format conversion if the jpeg is
* encoded as CMYK.
* And even then we still may not need it. If the jpeg has a CMYK color space and a color
* And even then we still may not need it. If the jpeg has a CMYK color profile and a color
* xform, the color xform will handle the CMYK->RGB conversion.
*/
static inline bool needs_swizzler_to_convert_from_cmyk(J_COLOR_SPACE jpegColorType,
const SkImageInfo& srcInfo, bool hasColorSpaceXform) {
const skcms_ICCProfile* srcProfile,
bool hasColorSpaceXform) {
if (JCS_CMYK != jpegColorType) {
return false;
}
bool hasCMYKColorSpace = SkColorSpace::kCMYK_Type == srcInfo.colorSpace()->type();
bool hasCMYKColorSpace = srcProfile && srcProfile->data_color_space == skcms_Signature_CMYK;
return !hasCMYKColorSpace || !hasColorSpaceXform;
}
@ -597,8 +598,8 @@ SkCodec::Result SkJpegCodec::onGetPixels(const SkImageInfo& dstInfo,
// If it's not, we want to know because it means our strategy is not optimal.
SkASSERT(1 == dinfo->rec_outbuf_height);
if (needs_swizzler_to_convert_from_cmyk(dinfo->out_color_space, this->getInfo(),
this->colorXform())) {
if (needs_swizzler_to_convert_from_cmyk(dinfo->out_color_space,
this->getEncodedInfo().profile(), this->colorXform())) {
this->initializeSwizzler(dstInfo, options, true);
}
@ -677,7 +678,8 @@ SkSampler* SkJpegCodec::getSampler(bool createIfNecessary) {
}
bool needsCMYKToRGB = needs_swizzler_to_convert_from_cmyk(
fDecoderMgr->dinfo()->out_color_space, this->getInfo(), this->colorXform());
fDecoderMgr->dinfo()->out_color_space, this->getEncodedInfo().profile(),
this->colorXform());
this->initializeSwizzler(this->dstInfo(), this->options(), needsCMYKToRGB);
this->allocateStorage(this->dstInfo());
return fSwizzler.get();
@ -698,7 +700,8 @@ SkCodec::Result SkJpegCodec::onStartScanlineDecode(const SkImageInfo& dstInfo,
}
bool needsCMYKToRGB = needs_swizzler_to_convert_from_cmyk(
fDecoderMgr->dinfo()->out_color_space, this->getInfo(), this->colorXform());
fDecoderMgr->dinfo()->out_color_space, this->getEncodedInfo().profile(),
this->colorXform());
if (options.fSubset) {
uint32_t startX = options.fSubset->x();
uint32_t width = options.fSubset->width();