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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 * to "true". Inside a program that links to skia: | 98 * to "true". Inside a program that links to skia: |
99 * SK_CONF_SET("images.jpeg.suppressDecoderErrors", true); */ | 99 * SK_CONF_SET("images.jpeg.suppressDecoderErrors", true); */ |
100 if (c_suppressJPEGImageDecoderErrors) { | 100 if (c_suppressJPEGImageDecoderErrors) { |
101 cinfo->err->output_message = &do_nothing_output_message; | 101 cinfo->err->output_message = &do_nothing_output_message; |
102 } | 102 } |
103 } | 103 } |
104 | 104 |
105 #ifdef SK_BUILD_FOR_ANDROID | 105 #ifdef SK_BUILD_FOR_ANDROID |
106 class SkJPEGImageIndex { | 106 class SkJPEGImageIndex { |
107 public: | 107 public: |
| 108 // Takes ownership of stream. |
108 SkJPEGImageIndex(SkStreamRewindable* stream, SkImageDecoder* decoder) | 109 SkJPEGImageIndex(SkStreamRewindable* stream, SkImageDecoder* decoder) |
109 : fSrcMgr(stream, decoder) | 110 : fSrcMgr(stream, decoder) |
| 111 , fStream(stream) |
110 , fInfoInitialized(false) | 112 , fInfoInitialized(false) |
111 , fHuffmanCreated(false) | 113 , fHuffmanCreated(false) |
112 , fDecompressStarted(false) | 114 , fDecompressStarted(false) |
113 { | 115 { |
114 SkDEBUGCODE(fReadHeaderSucceeded = false;) | 116 SkDEBUGCODE(fReadHeaderSucceeded = false;) |
115 } | 117 } |
116 | 118 |
117 ~SkJPEGImageIndex() { | 119 ~SkJPEGImageIndex() { |
118 if (fHuffmanCreated) { | 120 if (fHuffmanCreated) { |
119 // Set to false before calling the libjpeg function, in case | 121 // Set to false before calling the libjpeg function, in case |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 SkASSERT(!fDecompressStarted); | 201 SkASSERT(!fDecompressStarted); |
200 if (jpeg_start_tile_decompress(&fCInfo)) { | 202 if (jpeg_start_tile_decompress(&fCInfo)) { |
201 fDecompressStarted = true; | 203 fDecompressStarted = true; |
202 return true; | 204 return true; |
203 } | 205 } |
204 return false; | 206 return false; |
205 } | 207 } |
206 | 208 |
207 private: | 209 private: |
208 skjpeg_source_mgr fSrcMgr; | 210 skjpeg_source_mgr fSrcMgr; |
| 211 SkAutoTDelete<SkStream> fStream; |
209 jpeg_decompress_struct fCInfo; | 212 jpeg_decompress_struct fCInfo; |
210 huffman_index fHuffmanIndex; | 213 huffman_index fHuffmanIndex; |
211 bool fInfoInitialized; | 214 bool fInfoInitialized; |
212 bool fHuffmanCreated; | 215 bool fHuffmanCreated; |
213 bool fDecompressStarted; | 216 bool fDecompressStarted; |
214 SkDEBUGCODE(bool fReadHeaderSucceeded;) | 217 SkDEBUGCODE(bool fReadHeaderSucceeded;) |
215 }; | 218 }; |
216 #endif | 219 #endif |
217 | 220 |
218 class SkJPEGImageDecoder : public SkImageDecoder { | 221 class SkJPEGImageDecoder : public SkImageDecoder { |
(...skipping 1220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1439 return SkImageDecoder::kUnknown_Format; | 1442 return SkImageDecoder::kUnknown_Format; |
1440 } | 1443 } |
1441 | 1444 |
1442 static SkImageEncoder* sk_libjpeg_efactory(SkImageEncoder::Type t) { | 1445 static SkImageEncoder* sk_libjpeg_efactory(SkImageEncoder::Type t) { |
1443 return (SkImageEncoder::kJPEG_Type == t) ? SkNEW(SkJPEGImageEncoder) : NULL; | 1446 return (SkImageEncoder::kJPEG_Type == t) ? SkNEW(SkJPEGImageEncoder) : NULL; |
1444 } | 1447 } |
1445 | 1448 |
1446 static SkImageDecoder_DecodeReg gDReg(sk_libjpeg_dfactory); | 1449 static SkImageDecoder_DecodeReg gDReg(sk_libjpeg_dfactory); |
1447 static SkImageDecoder_FormatReg gFormatReg(get_format_jpeg); | 1450 static SkImageDecoder_FormatReg gFormatReg(get_format_jpeg); |
1448 static SkImageEncoder_EncodeReg gEReg(sk_libjpeg_efactory); | 1451 static SkImageEncoder_EncodeReg gEReg(sk_libjpeg_efactory); |
OLD | NEW |