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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
78 } | 78 } |
79 /* To suppress error messages with a SK_DEBUG binary, set the | 79 /* To suppress error messages with a SK_DEBUG binary, set the |
80 * environment variable "skia_images_jpeg_suppressDecoderErrors" | 80 * environment variable "skia_images_jpeg_suppressDecoderErrors" |
81 * to "true". Inside a program that links to skia: | 81 * to "true". Inside a program that links to skia: |
82 * SK_CONF_SET("images.jpeg.suppressDecoderErrors", true); */ | 82 * SK_CONF_SET("images.jpeg.suppressDecoderErrors", true); */ |
83 if (c_suppressJPEGImageDecoderErrors) { | 83 if (c_suppressJPEGImageDecoderErrors) { |
84 cinfo->err->output_message = &do_nothing_output_message; | 84 cinfo->err->output_message = &do_nothing_output_message; |
85 } | 85 } |
86 } | 86 } |
87 | 87 |
88 #ifdef SK_BUILD_FOR_ANDROID | 88 #if 0 |
scroggo
2015/06/16 20:39:23
Derek knows the magic to make SkCodec using libjpe
msarett
2015/06/18 21:06:10
Done.
| |
89 class SkJPEGImageIndex { | 89 class SkJPEGImageIndex { |
90 public: | 90 public: |
91 // Takes ownership of stream. | 91 // Takes ownership of stream. |
92 SkJPEGImageIndex(SkStreamRewindable* stream, SkImageDecoder* decoder) | 92 SkJPEGImageIndex(SkStreamRewindable* stream, SkImageDecoder* decoder) |
93 : fSrcMgr(stream, decoder) | 93 : fSrcMgr(stream, decoder) |
94 , fStream(stream) | 94 , fStream(stream) |
95 , fInfoInitialized(false) | 95 , fInfoInitialized(false) |
96 , fHuffmanCreated(false) | 96 , fHuffmanCreated(false) |
97 , fDecompressStarted(false) | 97 , fDecompressStarted(false) |
98 { | 98 { |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
196 huffman_index fHuffmanIndex; | 196 huffman_index fHuffmanIndex; |
197 bool fInfoInitialized; | 197 bool fInfoInitialized; |
198 bool fHuffmanCreated; | 198 bool fHuffmanCreated; |
199 bool fDecompressStarted; | 199 bool fDecompressStarted; |
200 SkDEBUGCODE(bool fReadHeaderSucceeded;) | 200 SkDEBUGCODE(bool fReadHeaderSucceeded;) |
201 }; | 201 }; |
202 #endif | 202 #endif |
203 | 203 |
204 class SkJPEGImageDecoder : public SkImageDecoder { | 204 class SkJPEGImageDecoder : public SkImageDecoder { |
205 public: | 205 public: |
206 #ifdef SK_BUILD_FOR_ANDROID | 206 #if 0 |
207 SkJPEGImageDecoder() { | 207 SkJPEGImageDecoder() { |
208 fImageIndex = NULL; | 208 fImageIndex = NULL; |
209 fImageWidth = 0; | 209 fImageWidth = 0; |
210 fImageHeight = 0; | 210 fImageHeight = 0; |
211 } | 211 } |
212 | 212 |
213 virtual ~SkJPEGImageDecoder() { | 213 virtual ~SkJPEGImageDecoder() { |
214 SkDELETE(fImageIndex); | 214 SkDELETE(fImageIndex); |
215 } | 215 } |
216 #endif | 216 #endif |
217 | 217 |
218 Format getFormat() const override { | 218 Format getFormat() const override { |
219 return kJPEG_Format; | 219 return kJPEG_Format; |
220 } | 220 } |
221 | 221 |
222 protected: | 222 protected: |
223 #ifdef SK_BUILD_FOR_ANDROID | 223 #if 0 |
224 bool onBuildTileIndex(SkStreamRewindable *stream, int *width, int *height) o verride; | 224 bool onBuildTileIndex(SkStreamRewindable *stream, int *width, int *height) o verride; |
225 bool onDecodeSubset(SkBitmap* bitmap, const SkIRect& rect) override; | 225 bool onDecodeSubset(SkBitmap* bitmap, const SkIRect& rect) override; |
226 #endif | 226 #endif |
227 Result onDecode(SkStream* stream, SkBitmap* bm, Mode) override; | 227 Result onDecode(SkStream* stream, SkBitmap* bm, Mode) override; |
228 bool onDecodeYUV8Planes(SkStream* stream, SkISize componentSizes[3], | 228 bool onDecodeYUV8Planes(SkStream* stream, SkISize componentSizes[3], |
229 void* planes[3], size_t rowBytes[3], | 229 void* planes[3], size_t rowBytes[3], |
230 SkYUVColorSpace* colorSpace) override; | 230 SkYUVColorSpace* colorSpace) override; |
231 | 231 |
232 private: | 232 private: |
233 #ifdef SK_BUILD_FOR_ANDROID | 233 #if 0 |
234 SkJPEGImageIndex* fImageIndex; | 234 SkJPEGImageIndex* fImageIndex; |
235 int fImageWidth; | 235 int fImageWidth; |
236 int fImageHeight; | 236 int fImageHeight; |
237 #endif | 237 #endif |
238 | 238 |
239 /** | 239 /** |
240 * Determine the appropriate bitmap colortype and out_color_space based on | 240 * Determine the appropriate bitmap colortype and out_color_space based on |
241 * both the preference of the caller and the jpeg_color_space on the | 241 * both the preference of the caller and the jpeg_color_space on the |
242 * jpeg_decompress_struct passed in. | 242 * jpeg_decompress_struct passed in. |
243 * Must be called after jpeg_read_header. | 243 * Must be called after jpeg_read_header. |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
290 for (int i = 0; i < count; i++) { | 290 for (int i = 0; i < count; i++) { |
291 JSAMPLE* rowptr = (JSAMPLE*)buffer; | 291 JSAMPLE* rowptr = (JSAMPLE*)buffer; |
292 int row_count = jpeg_read_scanlines(cinfo, &rowptr, 1); | 292 int row_count = jpeg_read_scanlines(cinfo, &rowptr, 1); |
293 if (1 != row_count) { | 293 if (1 != row_count) { |
294 return false; | 294 return false; |
295 } | 295 } |
296 } | 296 } |
297 return true; | 297 return true; |
298 } | 298 } |
299 | 299 |
300 #ifdef SK_BUILD_FOR_ANDROID | 300 #if 0 |
301 static bool skip_src_rows_tile(jpeg_decompress_struct* cinfo, | 301 static bool skip_src_rows_tile(jpeg_decompress_struct* cinfo, |
302 huffman_index *index, void* buffer, int count) { | 302 huffman_index *index, void* buffer, int count) { |
303 for (int i = 0; i < count; i++) { | 303 for (int i = 0; i < count; i++) { |
304 JSAMPLE* rowptr = (JSAMPLE*)buffer; | 304 JSAMPLE* rowptr = (JSAMPLE*)buffer; |
305 int row_count = jpeg_read_tile_scanline(cinfo, index, &rowptr); | 305 int row_count = jpeg_read_tile_scanline(cinfo, index, &rowptr); |
306 if (1 != row_count) { | 306 if (1 != row_count) { |
307 return false; | 307 return false; |
308 } | 308 } |
309 } | 309 } |
310 return true; | 310 return true; |
(...skipping 13 matching lines...) Expand all Loading... | |
324 cinfo.err->msg_code, buffer, caller, width, height); | 324 cinfo.err->msg_code, buffer, caller, width, height); |
325 } | 325 } |
326 } | 326 } |
327 | 327 |
328 static bool return_false(const jpeg_decompress_struct& cinfo, | 328 static bool return_false(const jpeg_decompress_struct& cinfo, |
329 const char caller[]) { | 329 const char caller[]) { |
330 print_jpeg_decoder_errors(cinfo, 0, 0, caller); | 330 print_jpeg_decoder_errors(cinfo, 0, 0, caller); |
331 return false; | 331 return false; |
332 } | 332 } |
333 | 333 |
334 #ifdef SK_BUILD_FOR_ANDROID | 334 #if 0 |
335 static bool return_false(const jpeg_decompress_struct& cinfo, | 335 static bool return_false(const jpeg_decompress_struct& cinfo, |
336 const SkBitmap& bm, const char caller[]) { | 336 const SkBitmap& bm, const char caller[]) { |
337 print_jpeg_decoder_errors(cinfo, bm.width(), bm.height(), caller); | 337 print_jpeg_decoder_errors(cinfo, bm.width(), bm.height(), caller); |
338 return false; | 338 return false; |
339 } | 339 } |
340 #endif | 340 #endif |
341 | 341 |
342 static SkImageDecoder::Result return_failure(const jpeg_decompress_struct& cinfo , | 342 static SkImageDecoder::Result return_failure(const jpeg_decompress_struct& cinfo , |
343 const SkBitmap& bm, const char call er[]) { | 343 const SkBitmap& bm, const char call er[]) { |
344 print_jpeg_decoder_errors(cinfo, bm.width(), bm.height(), caller); | 344 print_jpeg_decoder_errors(cinfo, bm.width(), bm.height(), caller); |
(...skipping 589 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
934 | 934 |
935 if (NULL != colorSpace) { | 935 if (NULL != colorSpace) { |
936 *colorSpace = kJPEG_SkYUVColorSpace; | 936 *colorSpace = kJPEG_SkYUVColorSpace; |
937 } | 937 } |
938 | 938 |
939 return true; | 939 return true; |
940 } | 940 } |
941 | 941 |
942 /////////////////////////////////////////////////////////////////////////////// | 942 /////////////////////////////////////////////////////////////////////////////// |
943 | 943 |
944 #ifdef SK_BUILD_FOR_ANDROID | 944 #if 0 |
945 bool SkJPEGImageDecoder::onBuildTileIndex(SkStreamRewindable* stream, int *width , int *height) { | 945 bool SkJPEGImageDecoder::onBuildTileIndex(SkStreamRewindable* stream, int *width , int *height) { |
946 | 946 |
947 SkAutoTDelete<SkJPEGImageIndex> imageIndex(SkNEW_ARGS(SkJPEGImageIndex, (str eam, this))); | 947 SkAutoTDelete<SkJPEGImageIndex> imageIndex(SkNEW_ARGS(SkJPEGImageIndex, (str eam, this))); |
948 | 948 |
949 skjpeg_error_mgr sk_err; | 949 skjpeg_error_mgr sk_err; |
950 set_error_mgr(imageIndex->cinfo(), &sk_err); | 950 set_error_mgr(imageIndex->cinfo(), &sk_err); |
951 | 951 |
952 // All objects need to be instantiated before this setjmp call so that | 952 // All objects need to be instantiated before this setjmp call so that |
953 // they will be cleaned up properly if an error occurs. | 953 // they will be cleaned up properly if an error occurs. |
954 if (setjmp(sk_err.fJmpBuf)) { | 954 if (setjmp(sk_err.fJmpBuf)) { |
(...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1449 return SkImageDecoder::kUnknown_Format; | 1449 return SkImageDecoder::kUnknown_Format; |
1450 } | 1450 } |
1451 | 1451 |
1452 static SkImageEncoder* sk_libjpeg_efactory(SkImageEncoder::Type t) { | 1452 static SkImageEncoder* sk_libjpeg_efactory(SkImageEncoder::Type t) { |
1453 return (SkImageEncoder::kJPEG_Type == t) ? SkNEW(SkJPEGImageEncoder) : NULL; | 1453 return (SkImageEncoder::kJPEG_Type == t) ? SkNEW(SkJPEGImageEncoder) : NULL; |
1454 } | 1454 } |
1455 | 1455 |
1456 static SkImageDecoder_DecodeReg gDReg(sk_libjpeg_dfactory); | 1456 static SkImageDecoder_DecodeReg gDReg(sk_libjpeg_dfactory); |
1457 static SkImageDecoder_FormatReg gFormatReg(get_format_jpeg); | 1457 static SkImageDecoder_FormatReg gFormatReg(get_format_jpeg); |
1458 static SkImageEncoder_EncodeReg gEReg(sk_libjpeg_efactory); | 1458 static SkImageEncoder_EncodeReg gEReg(sk_libjpeg_efactory); |
OLD | NEW |