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
diff --git a/src/images/SkImageDecoder_libjpeg.cpp b/src/images/SkImageDecoder_libjpeg.cpp
index d32e2a2..5eb8271 100644
--- a/src/images/SkImageDecoder_libjpeg.cpp
+++ b/src/images/SkImageDecoder_libjpeg.cpp
@@ -768,14 +768,31 @@
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 @@
#ifdef TIME_DECODE
SkAutoTime atm("JPEG YUV8 Decode");
#endif
-
if (this->getSampleSize() != 1) {
return false; // Resizing not supported
}
@@ -888,7 +904,7 @@
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 @@
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");
}