aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/images
diff options
context:
space:
mode:
authorGravatar mtklein <mtklein@chromium.org>2015-03-25 13:13:43 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2015-03-25 13:13:43 -0700
commitb3e5e4d314301617d2d48b7589dfd426bd68a671 (patch)
treeedbe2dfebdc6dcb1a90f63e4760df7632359fc20 /src/images
parentc4a933be63c71e92193792c020e6263b6ccabc89 (diff)
Lazy SKP image decoding in DM.
@sugoi: Early out to avoid some segfaults in SkImageDecoder_libjpeg.cpp. I am just flailing here... things seem to work, but I have no idea why. This prints out a lot: libjpeg error 85 <End Of Image> from output_raw_data [0 0] @halcanary: I'm skipping on ImageSrc for now. Leon's refactoring that quite a lot. This causes minor diffs for the GPU backend, given that we're now going through the YUV path. It also reduced peak RAM usage on my desktop from 1.26GB to 1.08GB. BUG=skia: Review URL: https://codereview.chromium.org/1010983004
Diffstat (limited to 'src/images')
-rw-r--r--src/images/SkImageDecoder_libjpeg.cpp26
1 files changed, 24 insertions, 2 deletions
diff --git a/src/images/SkImageDecoder_libjpeg.cpp b/src/images/SkImageDecoder_libjpeg.cpp
index d32e2a21c9..5eb827122f 100644
--- a/src/images/SkImageDecoder_libjpeg.cpp
+++ b/src/images/SkImageDecoder_libjpeg.cpp
@@ -768,14 +768,31 @@ static SkISize compute_yuv_size(const jpeg_decompress_struct& info, int componen
info.cur_comp_info[component]->downsampled_height);
}
+static bool appears_to_be_yuv(const jpeg_decompress_struct& info) {
+ return (info.jpeg_color_space == JCS_YCbCr)
+ && (DCTSIZE == 8)
+ && (info.num_components == 3)
+ && (info.comps_in_scan >= info.num_components)
+ && (info.scale_denom <= 8)
+ && (info.cur_comp_info[0])
+ && (info.cur_comp_info[1])
+ && (info.cur_comp_info[2])
+ && (info.cur_comp_info[1]->h_samp_factor == 1)
+ && (info.cur_comp_info[1]->v_samp_factor == 1)
+ && (info.cur_comp_info[2]->h_samp_factor == 1)
+ && (info.cur_comp_info[2]->v_samp_factor == 1);
+}
+
static void update_components_sizes(const jpeg_decompress_struct& cinfo, SkISize componentSizes[3],
SizeType sizeType) {
+ SkASSERT(appears_to_be_yuv(cinfo));
for (int i = 0; i < 3; ++i) {
componentSizes[i] = compute_yuv_size(cinfo, i, sizeType);
}
}
static bool output_raw_data(jpeg_decompress_struct& cinfo, void* planes[3], size_t rowBytes[3]) {
+ SkASSERT(appears_to_be_yuv(cinfo));
// U size and V size have to be the same if we're calling output_raw_data()
SkISize uvSize = compute_yuv_size(cinfo, 1, kSizeForMemoryAllocation_SizeType);
SkASSERT(uvSize == compute_yuv_size(cinfo, 2, kSizeForMemoryAllocation_SizeType));
@@ -861,7 +878,6 @@ bool SkJPEGImageDecoder::onDecodeYUV8Planes(SkStream* stream, SkISize componentS
#ifdef TIME_DECODE
SkAutoTime atm("JPEG YUV8 Decode");
#endif
-
if (this->getSampleSize() != 1) {
return false; // Resizing not supported
}
@@ -888,7 +904,7 @@ bool SkJPEGImageDecoder::onDecodeYUV8Planes(SkStream* stream, SkISize componentS
return return_false(cinfo, "read_header YUV8");
}
- if (cinfo.jpeg_color_space != JCS_YCbCr) {
+ if (!appears_to_be_yuv(cinfo)) {
// It's not an error to not be encoded in YUV, so no need to use return_false()
return false;
}
@@ -920,6 +936,12 @@ bool SkJPEGImageDecoder::onDecodeYUV8Planes(SkStream* stream, SkISize componentS
return return_false(cinfo, "start_decompress YUV8");
}
+ // Seems like jpeg_start_decompress is updating our opinion of whether cinfo represents YUV.
+ // Again, not really an error.
+ if (!appears_to_be_yuv(cinfo)) {
+ return false;
+ }
+
if (!output_raw_data(cinfo, planes, rowBytes)) {
return return_false(cinfo, "output_raw_data");
}