Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Side by Side Diff: src/images/SkImageDecoder_libjpeg.cpp

Issue 1010983004: Lazy SKP image decoding in DM. (Closed) Base URL: https://skia.googlesource.com/skia@master
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « dm/DMSrcSink.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2007 The Android Open Source Project 2 * Copyright 2007 The Android Open Source Project
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 8
9 #include "SkImageDecoder.h" 9 #include "SkImageDecoder.h"
10 #include "SkImageEncoder.h" 10 #include "SkImageEncoder.h"
(...skipping 750 matching lines...) Expand 10 before | Expand all | Expand 10 after
761 static SkISize compute_yuv_size(const jpeg_decompress_struct& info, int componen t, 761 static SkISize compute_yuv_size(const jpeg_decompress_struct& info, int componen t,
762 SizeType sizeType) { 762 SizeType sizeType) {
763 if (sizeType == kSizeForMemoryAllocation_SizeType) { 763 if (sizeType == kSizeForMemoryAllocation_SizeType) {
764 return SkISize::Make(info.cur_comp_info[component]->width_in_blocks * DC TSIZE, 764 return SkISize::Make(info.cur_comp_info[component]->width_in_blocks * DC TSIZE,
765 info.cur_comp_info[component]->height_in_blocks * D CTSIZE); 765 info.cur_comp_info[component]->height_in_blocks * D CTSIZE);
766 } 766 }
767 return SkISize::Make(info.cur_comp_info[component]->downsampled_width, 767 return SkISize::Make(info.cur_comp_info[component]->downsampled_width,
768 info.cur_comp_info[component]->downsampled_height); 768 info.cur_comp_info[component]->downsampled_height);
769 } 769 }
770 770
771 static void update_components_sizes(const jpeg_decompress_struct& cinfo, SkISize componentSizes[3], 771 static bool contains_three_planes(const jpeg_decompress_struct& cinfo) {
hal.canary 2015/03/17 21:32:48 // Either explain why this is needed or note that
772 return cinfo.cur_comp_info[0] && cinfo.cur_comp_info[1] && cinfo.cur_comp_in fo[2];
773 }
774
775 static bool update_components_sizes(const jpeg_decompress_struct& cinfo, SkISize componentSizes[3],
772 SizeType sizeType) { 776 SizeType sizeType) {
777 if (!contains_three_planes(cinfo)) {
778 return false;
779 }
773 for (int i = 0; i < 3; ++i) { 780 for (int i = 0; i < 3; ++i) {
774 componentSizes[i] = compute_yuv_size(cinfo, i, sizeType); 781 componentSizes[i] = compute_yuv_size(cinfo, i, sizeType);
775 } 782 }
783 return true;
776 } 784 }
777 785
778 static bool output_raw_data(jpeg_decompress_struct& cinfo, void* planes[3], size _t rowBytes[3]) { 786 static bool output_raw_data(jpeg_decompress_struct& cinfo, void* planes[3], size _t rowBytes[3]) {
787 if (!contains_three_planes(cinfo)) {
788 return false;
789 }
779 // U size and V size have to be the same if we're calling output_raw_data() 790 // U size and V size have to be the same if we're calling output_raw_data()
780 SkISize uvSize = compute_yuv_size(cinfo, 1, kSizeForMemoryAllocation_SizeTyp e); 791 SkISize uvSize = compute_yuv_size(cinfo, 1, kSizeForMemoryAllocation_SizeTyp e);
781 SkASSERT(uvSize == compute_yuv_size(cinfo, 2, kSizeForMemoryAllocation_SizeT ype)); 792 SkASSERT(uvSize == compute_yuv_size(cinfo, 2, kSizeForMemoryAllocation_SizeT ype));
782 793
783 JSAMPARRAY bufferraw[3]; 794 JSAMPARRAY bufferraw[3];
784 JSAMPROW bufferraw2[32]; 795 JSAMPROW bufferraw2[32];
785 bufferraw[0] = &bufferraw2[0]; // Y channel rows (8 or 16) 796 bufferraw[0] = &bufferraw2[0]; // Y channel rows (8 or 16)
786 bufferraw[1] = &bufferraw2[16]; // U channel rows (8) 797 bufferraw[1] = &bufferraw2[16]; // U channel rows (8)
787 bufferraw[2] = &bufferraw2[24]; // V channel rows (8) 798 bufferraw[2] = &bufferraw2[24]; // V channel rows (8)
788 int yWidth = cinfo.output_width; 799 int yWidth = cinfo.output_width;
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
890 901
891 if (cinfo.jpeg_color_space != JCS_YCbCr) { 902 if (cinfo.jpeg_color_space != JCS_YCbCr) {
892 // It's not an error to not be encoded in YUV, so no need to use return_ false() 903 // It's not an error to not be encoded in YUV, so no need to use return_ false()
893 return false; 904 return false;
894 } 905 }
895 906
896 cinfo.out_color_space = JCS_YCbCr; 907 cinfo.out_color_space = JCS_YCbCr;
897 cinfo.raw_data_out = TRUE; 908 cinfo.raw_data_out = TRUE;
898 909
899 if (!planes || !planes[0] || !rowBytes || !rowBytes[0]) { // Compute size on ly 910 if (!planes || !planes[0] || !rowBytes || !rowBytes[0]) { // Compute size on ly
900 update_components_sizes(cinfo, componentSizes, kSizeForMemoryAllocation_ SizeType); 911 return update_components_sizes(cinfo, componentSizes, kSizeForMemoryAllo cation_SizeType);
901 return true;
902 } 912 }
903 913
904 set_dct_method(*this, &cinfo); 914 set_dct_method(*this, &cinfo);
905 915
906 SkASSERT(1 == cinfo.scale_num); 916 SkASSERT(1 == cinfo.scale_num);
907 cinfo.scale_denom = 1; 917 cinfo.scale_denom = 1;
908 918
909 turn_off_visual_optimizations(&cinfo); 919 turn_off_visual_optimizations(&cinfo);
910 920
911 #ifdef ANDROID_RGB 921 #ifdef ANDROID_RGB
912 cinfo.dither_mode = JDITHER_NONE; 922 cinfo.dither_mode = JDITHER_NONE;
913 #endif 923 #endif
914 924
915 /* image_width and image_height are the original dimensions, available 925 /* image_width and image_height are the original dimensions, available
916 after jpeg_read_header(). To see the scaled dimensions, we have to call 926 after jpeg_read_header(). To see the scaled dimensions, we have to call
917 jpeg_start_decompress(), and then read output_width and output_height. 927 jpeg_start_decompress(), and then read output_width and output_height.
918 */ 928 */
919 if (!jpeg_start_decompress(&cinfo)) { 929 if (!jpeg_start_decompress(&cinfo)) {
920 return return_false(cinfo, "start_decompress YUV8"); 930 return return_false(cinfo, "start_decompress YUV8");
921 } 931 }
922 932
923 if (!output_raw_data(cinfo, planes, rowBytes)) { 933 if (!output_raw_data(cinfo, planes, rowBytes)) {
924 return return_false(cinfo, "output_raw_data"); 934 return return_false(cinfo, "output_raw_data");
925 } 935 }
926 936
927 update_components_sizes(cinfo, componentSizes, kActualSize_SizeType); 937 if (!update_components_sizes(cinfo, componentSizes, kActualSize_SizeType)) {
938 return false;
939 }
928 jpeg_finish_decompress(&cinfo); 940 jpeg_finish_decompress(&cinfo);
929 941
930 if (NULL != colorSpace) { 942 if (NULL != colorSpace) {
931 *colorSpace = kJPEG_SkYUVColorSpace; 943 *colorSpace = kJPEG_SkYUVColorSpace;
932 } 944 }
933 945
934 return true; 946 return true;
935 } 947 }
936 948
937 /////////////////////////////////////////////////////////////////////////////// 949 ///////////////////////////////////////////////////////////////////////////////
(...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after
1445 return SkImageDecoder::kUnknown_Format; 1457 return SkImageDecoder::kUnknown_Format;
1446 } 1458 }
1447 1459
1448 static SkImageEncoder* sk_libjpeg_efactory(SkImageEncoder::Type t) { 1460 static SkImageEncoder* sk_libjpeg_efactory(SkImageEncoder::Type t) {
1449 return (SkImageEncoder::kJPEG_Type == t) ? SkNEW(SkJPEGImageEncoder) : NULL; 1461 return (SkImageEncoder::kJPEG_Type == t) ? SkNEW(SkJPEGImageEncoder) : NULL;
1450 } 1462 }
1451 1463
1452 static SkImageDecoder_DecodeReg gDReg(sk_libjpeg_dfactory); 1464 static SkImageDecoder_DecodeReg gDReg(sk_libjpeg_dfactory);
1453 static SkImageDecoder_FormatReg gFormatReg(get_format_jpeg); 1465 static SkImageDecoder_FormatReg gFormatReg(get_format_jpeg);
1454 static SkImageEncoder_EncodeReg gEReg(sk_libjpeg_efactory); 1466 static SkImageEncoder_EncodeReg gEReg(sk_libjpeg_efactory);
OLDNEW
« no previous file with comments | « dm/DMSrcSink.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698