OLD | NEW |
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 731 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
742 static SkISize compute_yuv_size(const jpeg_decompress_struct& info, int componen
t, | 742 static SkISize compute_yuv_size(const jpeg_decompress_struct& info, int componen
t, |
743 SizeType sizeType) { | 743 SizeType sizeType) { |
744 if (sizeType == kSizeForMemoryAllocation_SizeType) { | 744 if (sizeType == kSizeForMemoryAllocation_SizeType) { |
745 return SkISize::Make(info.cur_comp_info[component]->width_in_blocks * DC
TSIZE, | 745 return SkISize::Make(info.cur_comp_info[component]->width_in_blocks * DC
TSIZE, |
746 info.cur_comp_info[component]->height_in_blocks * D
CTSIZE); | 746 info.cur_comp_info[component]->height_in_blocks * D
CTSIZE); |
747 } | 747 } |
748 return SkISize::Make(info.cur_comp_info[component]->downsampled_width, | 748 return SkISize::Make(info.cur_comp_info[component]->downsampled_width, |
749 info.cur_comp_info[component]->downsampled_height); | 749 info.cur_comp_info[component]->downsampled_height); |
750 } | 750 } |
751 | 751 |
752 // Enum for YUV decoding | |
753 enum YUVSubsampling { | |
754 kUNKNOWN_YUVSubsampling, | |
755 k410_YUVSubsampling, | |
756 k411_YUVSubsampling, | |
757 k420_YUVSubsampling, | |
758 k422_YUVSubsampling, | |
759 k440_YUVSubsampling, | |
760 k444_YUVSubsampling | |
761 }; | |
762 | |
763 static YUVSubsampling yuv_subsampling(const jpeg_decompress_struct& info) { | |
764 if ((DCTSIZE == 8) | |
765 && (info.num_components == 3) | |
766 && (info.comps_in_scan >= info.num_components) | |
767 && (info.scale_denom <= 8) | |
768 && (info.cur_comp_info[0]) | |
769 && (info.cur_comp_info[1]) | |
770 && (info.cur_comp_info[2]) | |
771 && (info.cur_comp_info[1]->h_samp_factor == 1) | |
772 && (info.cur_comp_info[1]->v_samp_factor == 1) | |
773 && (info.cur_comp_info[2]->h_samp_factor == 1) | |
774 && (info.cur_comp_info[2]->v_samp_factor == 1)) | |
775 { | |
776 int h = info.cur_comp_info[0]->h_samp_factor; | |
777 int v = info.cur_comp_info[0]->v_samp_factor; | |
778 // 4:4:4 : (h == 1) && (v == 1) | |
779 // 4:4:0 : (h == 1) && (v == 2) | |
780 // 4:2:2 : (h == 2) && (v == 1) | |
781 // 4:2:0 : (h == 2) && (v == 2) | |
782 // 4:1:1 : (h == 4) && (v == 1) | |
783 // 4:1:0 : (h == 4) && (v == 2) | |
784 if (v == 1) { | |
785 switch (h) { | |
786 case 1: | |
787 return k444_YUVSubsampling; | |
788 case 2: | |
789 return k422_YUVSubsampling; | |
790 case 4: | |
791 return k411_YUVSubsampling; | |
792 default: | |
793 break; | |
794 } | |
795 } else if (v == 2) { | |
796 switch (h) { | |
797 case 1: | |
798 return k440_YUVSubsampling; | |
799 case 2: | |
800 return k420_YUVSubsampling; | |
801 case 4: | |
802 return k410_YUVSubsampling; | |
803 default: | |
804 break; | |
805 } | |
806 } | |
807 } | |
808 | |
809 return kUNKNOWN_YUVSubsampling; | |
810 } | |
811 | |
812 static void update_components_sizes(const jpeg_decompress_struct& cinfo, SkISize
componentSizes[3], | 752 static void update_components_sizes(const jpeg_decompress_struct& cinfo, SkISize
componentSizes[3], |
813 SizeType sizeType) { | 753 SizeType sizeType) { |
814 for (int i = 0; i < 3; ++i) { | 754 for (int i = 0; i < 3; ++i) { |
815 componentSizes[i] = compute_yuv_size(cinfo, i, sizeType); | 755 componentSizes[i] = compute_yuv_size(cinfo, i, sizeType); |
816 } | 756 } |
817 } | 757 } |
818 | 758 |
819 static bool output_raw_data(jpeg_decompress_struct& cinfo, void* planes[3], size
_t rowBytes[3]) { | 759 static bool output_raw_data(jpeg_decompress_struct& cinfo, void* planes[3], size
_t rowBytes[3]) { |
820 // U size and V size have to be the same if we're calling output_raw_data() | 760 // U size and V size have to be the same if we're calling output_raw_data() |
821 SkISize uvSize = compute_yuv_size(cinfo, 1, kSizeForMemoryAllocation_SizeTyp
e); | 761 SkISize uvSize = compute_yuv_size(cinfo, 1, kSizeForMemoryAllocation_SizeTyp
e); |
(...skipping 659 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1481 return SkImageDecoder::kUnknown_Format; | 1421 return SkImageDecoder::kUnknown_Format; |
1482 } | 1422 } |
1483 | 1423 |
1484 static SkImageEncoder* sk_libjpeg_efactory(SkImageEncoder::Type t) { | 1424 static SkImageEncoder* sk_libjpeg_efactory(SkImageEncoder::Type t) { |
1485 return (SkImageEncoder::kJPEG_Type == t) ? SkNEW(SkJPEGImageEncoder) : NULL; | 1425 return (SkImageEncoder::kJPEG_Type == t) ? SkNEW(SkJPEGImageEncoder) : NULL; |
1486 } | 1426 } |
1487 | 1427 |
1488 static SkImageDecoder_DecodeReg gDReg(sk_libjpeg_dfactory); | 1428 static SkImageDecoder_DecodeReg gDReg(sk_libjpeg_dfactory); |
1489 static SkImageDecoder_FormatReg gFormatReg(get_format_jpeg); | 1429 static SkImageDecoder_FormatReg gFormatReg(get_format_jpeg); |
1490 static SkImageEncoder_EncodeReg gEReg(sk_libjpeg_efactory); | 1430 static SkImageEncoder_EncodeReg gEReg(sk_libjpeg_efactory); |
OLD | NEW |