| 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 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 | 203 |
| 204 class SkJPEGImageDecoder : public SkImageDecoder { | 204 class SkJPEGImageDecoder : public SkImageDecoder { |
| 205 public: | 205 public: |
| 206 #ifdef SK_BUILD_FOR_ANDROID | 206 #ifdef SK_BUILD_FOR_ANDROID |
| 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() { delete fImageIndex; } |
| 214 SkDELETE(fImageIndex); | |
| 215 } | |
| 216 #endif | 214 #endif |
| 217 | 215 |
| 218 Format getFormat() const override { | 216 Format getFormat() const override { |
| 219 return kJPEG_Format; | 217 return kJPEG_Format; |
| 220 } | 218 } |
| 221 | 219 |
| 222 protected: | 220 protected: |
| 223 #ifdef SK_BUILD_FOR_ANDROID | 221 #ifdef SK_BUILD_FOR_ANDROID |
| 224 bool onBuildTileIndex(SkStreamRewindable *stream, int *width, int *height) o
verride; | 222 bool onBuildTileIndex(SkStreamRewindable *stream, int *width, int *height) o
verride; |
| 225 bool onDecodeSubset(SkBitmap* bitmap, const SkIRect& rect) override; | 223 bool onDecodeSubset(SkBitmap* bitmap, const SkIRect& rect) override; |
| (...skipping 710 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 936 *colorSpace = kJPEG_SkYUVColorSpace; | 934 *colorSpace = kJPEG_SkYUVColorSpace; |
| 937 } | 935 } |
| 938 | 936 |
| 939 return true; | 937 return true; |
| 940 } | 938 } |
| 941 | 939 |
| 942 /////////////////////////////////////////////////////////////////////////////// | 940 /////////////////////////////////////////////////////////////////////////////// |
| 943 | 941 |
| 944 #ifdef SK_BUILD_FOR_ANDROID | 942 #ifdef SK_BUILD_FOR_ANDROID |
| 945 bool SkJPEGImageDecoder::onBuildTileIndex(SkStreamRewindable* stream, int *width
, int *height) { | 943 bool SkJPEGImageDecoder::onBuildTileIndex(SkStreamRewindable* stream, int *width
, int *height) { |
| 946 | 944 SkAutoTDelete<SkJPEGImageIndex> imageIndex(new SkJPEGImageIndex(stream, this
)); |
| 947 SkAutoTDelete<SkJPEGImageIndex> imageIndex(SkNEW_ARGS(SkJPEGImageIndex, (str
eam, this))); | |
| 948 | 945 |
| 949 skjpeg_error_mgr sk_err; | 946 skjpeg_error_mgr sk_err; |
| 950 set_error_mgr(imageIndex->cinfo(), &sk_err); | 947 set_error_mgr(imageIndex->cinfo(), &sk_err); |
| 951 | 948 |
| 952 // All objects need to be instantiated before this setjmp call so that | 949 // All objects need to be instantiated before this setjmp call so that |
| 953 // they will be cleaned up properly if an error occurs. | 950 // they will be cleaned up properly if an error occurs. |
| 954 if (setjmp(sk_err.fJmpBuf)) { | 951 if (setjmp(sk_err.fJmpBuf)) { |
| 955 return false; | 952 return false; |
| 956 } | 953 } |
| 957 | 954 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 993 fImageWidth = cinfo->output_width; | 990 fImageWidth = cinfo->output_width; |
| 994 fImageHeight = cinfo->output_height; | 991 fImageHeight = cinfo->output_height; |
| 995 | 992 |
| 996 if (width) { | 993 if (width) { |
| 997 *width = fImageWidth; | 994 *width = fImageWidth; |
| 998 } | 995 } |
| 999 if (height) { | 996 if (height) { |
| 1000 *height = fImageHeight; | 997 *height = fImageHeight; |
| 1001 } | 998 } |
| 1002 | 999 |
| 1003 SkDELETE(fImageIndex); | 1000 delete fImageIndex; |
| 1004 fImageIndex = imageIndex.detach(); | 1001 fImageIndex = imageIndex.detach(); |
| 1005 | 1002 |
| 1006 return true; | 1003 return true; |
| 1007 } | 1004 } |
| 1008 | 1005 |
| 1009 bool SkJPEGImageDecoder::onDecodeSubset(SkBitmap* bm, const SkIRect& region) { | 1006 bool SkJPEGImageDecoder::onDecodeSubset(SkBitmap* bm, const SkIRect& region) { |
| 1010 if (NULL == fImageIndex) { | 1007 if (NULL == fImageIndex) { |
| 1011 return false; | 1008 return false; |
| 1012 } | 1009 } |
| 1013 jpeg_decompress_struct* cinfo = fImageIndex->cinfo(); | 1010 jpeg_decompress_struct* cinfo = fImageIndex->cinfo(); |
| (...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1430 } | 1427 } |
| 1431 if (memcmp(buffer, gHeader, HEADER_SIZE)) { | 1428 if (memcmp(buffer, gHeader, HEADER_SIZE)) { |
| 1432 return false; | 1429 return false; |
| 1433 } | 1430 } |
| 1434 return true; | 1431 return true; |
| 1435 } | 1432 } |
| 1436 | 1433 |
| 1437 | 1434 |
| 1438 static SkImageDecoder* sk_libjpeg_dfactory(SkStreamRewindable* stream) { | 1435 static SkImageDecoder* sk_libjpeg_dfactory(SkStreamRewindable* stream) { |
| 1439 if (is_jpeg(stream)) { | 1436 if (is_jpeg(stream)) { |
| 1440 return SkNEW(SkJPEGImageDecoder); | 1437 return new SkJPEGImageDecoder; |
| 1441 } | 1438 } |
| 1442 return NULL; | 1439 return NULL; |
| 1443 } | 1440 } |
| 1444 | 1441 |
| 1445 static SkImageDecoder::Format get_format_jpeg(SkStreamRewindable* stream) { | 1442 static SkImageDecoder::Format get_format_jpeg(SkStreamRewindable* stream) { |
| 1446 if (is_jpeg(stream)) { | 1443 if (is_jpeg(stream)) { |
| 1447 return SkImageDecoder::kJPEG_Format; | 1444 return SkImageDecoder::kJPEG_Format; |
| 1448 } | 1445 } |
| 1449 return SkImageDecoder::kUnknown_Format; | 1446 return SkImageDecoder::kUnknown_Format; |
| 1450 } | 1447 } |
| 1451 | 1448 |
| 1452 static SkImageEncoder* sk_libjpeg_efactory(SkImageEncoder::Type t) { | 1449 static SkImageEncoder* sk_libjpeg_efactory(SkImageEncoder::Type t) { |
| 1453 return (SkImageEncoder::kJPEG_Type == t) ? SkNEW(SkJPEGImageEncoder) : NULL; | 1450 return (SkImageEncoder::kJPEG_Type == t) ? new SkJPEGImageEncoder : NULL; |
| 1454 } | 1451 } |
| 1455 | 1452 |
| 1456 static SkImageDecoder_DecodeReg gDReg(sk_libjpeg_dfactory); | 1453 static SkImageDecoder_DecodeReg gDReg(sk_libjpeg_dfactory); |
| 1457 static SkImageDecoder_FormatReg gFormatReg(get_format_jpeg); | 1454 static SkImageDecoder_FormatReg gFormatReg(get_format_jpeg); |
| 1458 static SkImageEncoder_EncodeReg gEReg(sk_libjpeg_efactory); | 1455 static SkImageEncoder_EncodeReg gEReg(sk_libjpeg_efactory); |
| OLD | NEW |