Make SkJpegCodec compatible with libjpeg

BUG=skia:4470
BUG=skia:4520
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1687863003

Review URL: https://codereview.chromium.org/1687863003
This commit is contained in:
msarett 2016-02-12 12:35:48 -08:00 committed by Commit bot
parent e6af96a889
commit 70e418b468
5 changed files with 29 additions and 2245 deletions

View File

@ -66,6 +66,7 @@
},
'defines': [
'TURBO_HAS_SKIP',
'TURBO_HAS_565',
],
'conditions': [
['skia_codec_decodes_raw', {

View File

@ -129,7 +129,6 @@ BASE_SRCS_UNIX = struct(
"src/ports/**/*.h",
],
exclude = [
"src/codec/SkJpegCodec.cpp", # libjpeg_turbo version mismatch.
"src/opts/*arm*",
"src/opts/*mips*",
"src/opts/*NEON*",
@ -178,7 +177,6 @@ BASE_SRCS_ANDROID = struct(
"src/ports/**/*.h",
],
exclude = [
"src/codec/SkJpegCodec.cpp", # libjpeg_turbo version mismatch.
"src/opts/*mips*",
"src/opts/*SSE2*",
"src/opts/*SSSE3*",
@ -477,6 +475,7 @@ COPTS_ALL = []
################################################################################
DEFINES_UNIX = [
"PNG_SKIP_SETJMP_CHECK",
"SK_BUILD_FOR_UNIX",
"SK_SAMPLES_FOR_X",
"SK_SFNTLY_SUBSETTER",

View File

@ -11,9 +11,7 @@
#include "SkData.h"
#include "SkGifCodec.h"
#include "SkIcoCodec.h"
#if !defined(GOOGLE3)
#include "SkJpegCodec.h"
#endif
#include "SkPngCodec.h"
#ifdef SK_CODEC_DECODES_RAW
#include "SkRawCodec.h"
@ -28,9 +26,7 @@ struct DecoderProc {
};
static const DecoderProc gDecoderProcs[] = {
#if !defined(GOOGLE3)
{ SkJpegCodec::IsJpeg, SkJpegCodec::NewFromStream },
#endif
{ SkWebpCodec::IsWebp, SkWebpCodec::NewFromStream },
{ SkGifCodec::IsGif, SkGifCodec::NewFromStream },
{ SkIcoCodec::IsIco, SkIcoCodec::NewFromStream },

View File

@ -86,7 +86,12 @@ SkJpegCodec::SkJpegCodec(const SkImageInfo& srcInfo, SkStream* stream,
* Return the row bytes of a particular image type and width
*/
static size_t get_row_bytes(const j_decompress_ptr dinfo) {
size_t colorBytes = (dinfo->out_color_space == JCS_RGB565) ? 2 : dinfo->out_color_components;
#ifdef TURBO_HAS_565
const size_t colorBytes = (dinfo->out_color_space == JCS_RGB565) ? 2 :
dinfo->out_color_components;
#else
const size_t colorBytes = dinfo->out_color_components;
#endif
return dinfo->output_width * colorBytes;
}
@ -184,12 +189,16 @@ bool SkJpegCodec::setOutputColorSpace(const SkImageInfo& dst) {
if (isCMYK) {
fDecoderMgr->dinfo()->out_color_space = JCS_CMYK;
} else {
// Check the byte ordering of the RGBA color space for the
// current platform
#if defined(SK_PMCOLOR_IS_RGBA)
fDecoderMgr->dinfo()->out_color_space = JCS_EXT_RGBA;
#ifdef LIBJPEG_TURBO_VERSION
// Check the byte ordering of the RGBA color space for the
// current platform
#ifdef SK_PMCOLOR_IS_RGBA
fDecoderMgr->dinfo()->out_color_space = JCS_EXT_RGBA;
#else
fDecoderMgr->dinfo()->out_color_space = JCS_EXT_BGRA;
#endif
#else
fDecoderMgr->dinfo()->out_color_space = JCS_EXT_BGRA;
fDecoderMgr->dinfo()->out_color_space = JCS_RGB;
#endif
}
return true;
@ -197,8 +206,12 @@ bool SkJpegCodec::setOutputColorSpace(const SkImageInfo& dst) {
if (isCMYK) {
fDecoderMgr->dinfo()->out_color_space = JCS_CMYK;
} else {
#ifdef TURBO_HAS_565
fDecoderMgr->dinfo()->dither_mode = JDITHER_NONE;
fDecoderMgr->dinfo()->out_color_space = JCS_RGB565;
#else
fDecoderMgr->dinfo()->out_color_space = JCS_RGB;
#endif
}
return true;
case kGray_8_SkColorType:
@ -290,7 +303,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 (JCS_CMYK == dinfo->out_color_space) {
J_COLOR_SPACE colorSpace = dinfo->out_color_space;
if (JCS_CMYK == colorSpace || JCS_RGB == colorSpace) {
this->initializeSwizzler(dstInfo, options);
}
@ -353,6 +367,10 @@ void SkJpegCodec::initializeSwizzler(const SkImageInfo& dstInfo, const Options&
}
}
if (JCS_RGB == fDecoderMgr->dinfo()->out_color_space) {
srcConfig = SkSwizzler::kRGB;
}
fSwizzler.reset(SkSwizzler::CreateSwizzler(srcConfig, nullptr, dstInfo, options));
fStorage.reset(get_row_bytes(fDecoderMgr->dinfo()));
fSrcRow = fStorage.get();
@ -394,7 +412,8 @@ SkCodec::Result SkJpegCodec::onStartScanlineDecode(const SkImageInfo& dstInfo,
// We will need a swizzler if we are performing a subset decode or
// converting from CMYK.
if (options.fSubset || JCS_CMYK == fDecoderMgr->dinfo()->out_color_space) {
J_COLOR_SPACE colorSpace = fDecoderMgr->dinfo()->out_color_space;
if (options.fSubset || JCS_CMYK == colorSpace || JCS_RGB == colorSpace) {
this->initializeSwizzler(dstInfo, options);
}

File diff suppressed because it is too large Load Diff