Skip to content

Commit

Permalink
external/skia: Take Fast Jpeg Decoding Path
Browse files Browse the repository at this point in the history
For smaller pictures, we use fast upsampler. To do so, we disable fancy
upsampler. However, when fancy upsampler disabled, libjpeg-turbo may
choose to use merged upsampler, causing unwanted behavior. We need to
make sure merged upsampler is disabled so that only fast upsampler will
be used. We only use fast upsampler for smaller pictures because the
visual difference(if there is any) will be even less noticeable.

Change-Id: Id4031df1d5cd2be566c1de8f345993ef8880dcc3
Signed-off-by: Jason Edson <jaysonedson@gmail.com>
  • Loading branch information
Mort (Tianqi) Guo authored and Hikari-no-Tenshi committed Jul 6, 2020
1 parent 33a11ed commit 13bad33
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/codec/SkJpegCodec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,21 @@ static inline bool needs_swizzler_to_convert_from_cmyk(J_COLOR_SPACE jpegColorTy
return !hasCMYKColorSpace || !hasColorSpaceXform;
}

void SkJpegCodec::setupJpegDecoding(jpeg_decompress_struct* dinfo)
{
/* We only prefer speed over quality for small/medium pictures,
* where the difference will be even less noticeable.
*/
if(dinfo->image_width > kMedium_JpegDecodingSize ||
dinfo->image_height > kMedium_JpegDecodingSize) {
return;
}

dinfo->do_fancy_upsampling = FALSE;
dinfo->disable_merged_upsampling = TRUE;
dinfo->dct_method = JDCT_IFAST;
}

/*
* Performs the jpeg decode
*/
Expand All @@ -590,6 +605,8 @@ SkCodec::Result SkJpegCodec::onGetPixels(const SkImageInfo& dstInfo,
return fDecoderMgr->returnFailure("setjmp", kInvalidInput);
}

setupJpegDecoding(dinfo);

if (!jpeg_start_decompress(dinfo)) {
return fDecoderMgr->returnFailure("startDecompress", kInvalidInput);
}
Expand Down Expand Up @@ -709,6 +726,8 @@ SkCodec::Result SkJpegCodec::onStartScanlineDecode(const SkImageInfo& dstInfo,
return kInvalidInput;
}

setupJpegDecoding(fDecoderMgr->dinfo());

if (!jpeg_start_decompress(fDecoderMgr->dinfo())) {
SkCodecPrintf("start decompress failed\n");
return kInvalidInput;
Expand Down
14 changes: 14 additions & 0 deletions src/codec/SkJpegCodec.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
#include "SkStream.h"
#include "SkTemplates.h"

extern "C" {
#include "jpeglib.h"
}

class JpegDecoderMgr;

/*
Expand Down Expand Up @@ -109,6 +113,16 @@ class SkJpegCodec : public SkCodec {
void allocateStorage(const SkImageInfo& dstInfo);
int readRows(const SkImageInfo& dstInfo, void* dst, size_t rowBytes, int count, const Options&);

/*
* Categorize JPEG image dimension.
* Can be used to apply different settings for different sizes.
*/
enum JpegDecodingSize: JDIMENSION {
kSmall_JpegDecodingSize = 400,
kMedium_JpegDecodingSize = 1600
};
static void setupJpegDecoding(jpeg_decompress_struct* dinfo);

/*
* Scanline decoding.
*/
Expand Down

0 comments on commit 13bad33

Please sign in to comment.