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 922 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
933 | 933 |
934 return true; | 934 return true; |
935 } | 935 } |
936 | 936 |
937 /////////////////////////////////////////////////////////////////////////////// | 937 /////////////////////////////////////////////////////////////////////////////// |
938 | 938 |
939 #ifdef SK_BUILD_FOR_ANDROID | 939 #ifdef SK_BUILD_FOR_ANDROID |
940 bool SkJPEGImageDecoder::onBuildTileIndex(SkStreamRewindable* stream, int *width
, int *height) { | 940 bool SkJPEGImageDecoder::onBuildTileIndex(SkStreamRewindable* stream, int *width
, int *height) { |
941 | 941 |
942 SkAutoTDelete<SkJPEGImageIndex> imageIndex(SkNEW_ARGS(SkJPEGImageIndex, (str
eam, this))); | 942 SkAutoTDelete<SkJPEGImageIndex> imageIndex(SkNEW_ARGS(SkJPEGImageIndex, (str
eam, this))); |
943 jpeg_decompress_struct* cinfo = imageIndex->cinfo(); | |
944 | 943 |
945 skjpeg_error_mgr sk_err; | 944 skjpeg_error_mgr sk_err; |
946 set_error_mgr(cinfo, &sk_err); | 945 set_error_mgr(imageIndex->cinfo(), &sk_err); |
947 | 946 |
948 // All objects need to be instantiated before this setjmp call so that | 947 // All objects need to be instantiated before this setjmp call so that |
949 // they will be cleaned up properly if an error occurs. | 948 // they will be cleaned up properly if an error occurs. |
950 if (setjmp(sk_err.fJmpBuf)) { | 949 if (setjmp(sk_err.fJmpBuf)) { |
951 return false; | 950 return false; |
952 } | 951 } |
953 | 952 |
954 // create the cinfo used to create/build the huffmanIndex | 953 // create the cinfo used to create/build the huffmanIndex |
955 if (!imageIndex->initializeInfoAndReadHeader()) { | 954 if (!imageIndex->initializeInfoAndReadHeader()) { |
956 return false; | 955 return false; |
957 } | 956 } |
958 | 957 |
959 if (!imageIndex->buildHuffmanIndex()) { | 958 if (!imageIndex->buildHuffmanIndex()) { |
960 return false; | 959 return false; |
961 } | 960 } |
962 | 961 |
963 // destroy the cinfo used to create/build the huffman index | 962 // destroy the cinfo used to create/build the huffman index |
964 imageIndex->destroyInfo(); | 963 imageIndex->destroyInfo(); |
965 | 964 |
966 // Init decoder to image decode mode | 965 // Init decoder to image decode mode |
967 if (!imageIndex->initializeInfoAndReadHeader()) { | 966 if (!imageIndex->initializeInfoAndReadHeader()) { |
968 return false; | 967 return false; |
969 } | 968 } |
970 | 969 |
| 970 jpeg_decompress_struct* cinfo = imageIndex->cinfo(); |
| 971 // We have a new cinfo, so set the error mgr again. |
| 972 set_error_mgr(cinfo, &sk_err); |
| 973 |
971 // FIXME: This sets cinfo->out_color_space, which we may change later | 974 // FIXME: This sets cinfo->out_color_space, which we may change later |
972 // based on the config in onDecodeSubset. This should be fine, since | 975 // based on the config in onDecodeSubset. This should be fine, since |
973 // jpeg_init_read_tile_scanline will check out_color_space again after | 976 // jpeg_init_read_tile_scanline will check out_color_space again after |
974 // that change (when it calls jinit_color_deconverter). | 977 // that change (when it calls jinit_color_deconverter). |
975 (void) this->getBitmapColorType(cinfo); | 978 (void) this->getBitmapColorType(cinfo); |
976 | 979 |
977 turn_off_visual_optimizations(cinfo); | 980 turn_off_visual_optimizations(cinfo); |
978 | 981 |
979 // instead of jpeg_start_decompress() we start a tiled decompress | 982 // instead of jpeg_start_decompress() we start a tiled decompress |
980 if (!imageIndex->startTileDecompress()) { | 983 if (!imageIndex->startTileDecompress()) { |
(...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1442 return SkImageDecoder::kUnknown_Format; | 1445 return SkImageDecoder::kUnknown_Format; |
1443 } | 1446 } |
1444 | 1447 |
1445 static SkImageEncoder* sk_libjpeg_efactory(SkImageEncoder::Type t) { | 1448 static SkImageEncoder* sk_libjpeg_efactory(SkImageEncoder::Type t) { |
1446 return (SkImageEncoder::kJPEG_Type == t) ? SkNEW(SkJPEGImageEncoder) : NULL; | 1449 return (SkImageEncoder::kJPEG_Type == t) ? SkNEW(SkJPEGImageEncoder) : NULL; |
1447 } | 1450 } |
1448 | 1451 |
1449 static SkImageDecoder_DecodeReg gDReg(sk_libjpeg_dfactory); | 1452 static SkImageDecoder_DecodeReg gDReg(sk_libjpeg_dfactory); |
1450 static SkImageDecoder_FormatReg gFormatReg(get_format_jpeg); | 1453 static SkImageDecoder_FormatReg gFormatReg(get_format_jpeg); |
1451 static SkImageEncoder_EncodeReg gEReg(sk_libjpeg_efactory); | 1454 static SkImageEncoder_EncodeReg gEReg(sk_libjpeg_efactory); |
OLD | NEW |