OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2006 The Android Open Source Project | 2 * Copyright 2006 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 #include "SkImageDecoder.h" | 8 #include "SkImageDecoder.h" |
9 #include "SkImageEncoder.h" | 9 #include "SkImageEncoder.h" |
10 #include "SkColor.h" | 10 #include "SkColor.h" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 SK_CONF_DECLARE(bool, c_suppressPNGImageDecoderWarnings, | 46 SK_CONF_DECLARE(bool, c_suppressPNGImageDecoderWarnings, |
47 "images.png.suppressDecoderWarnings", | 47 "images.png.suppressDecoderWarnings", |
48 DEFAULT_FOR_SUPPRESS_PNG_IMAGE_DECODER_WARNINGS, | 48 DEFAULT_FOR_SUPPRESS_PNG_IMAGE_DECODER_WARNINGS, |
49 "Suppress most PNG warnings when calling image decode " | 49 "Suppress most PNG warnings when calling image decode " |
50 "functions."); | 50 "functions."); |
51 | 51 |
52 | 52 |
53 | 53 |
54 class SkPNGImageIndex { | 54 class SkPNGImageIndex { |
55 public: | 55 public: |
| 56 // Takes ownership of stream. |
56 SkPNGImageIndex(SkStreamRewindable* stream, png_structp png_ptr, png_infop i
nfo_ptr) | 57 SkPNGImageIndex(SkStreamRewindable* stream, png_structp png_ptr, png_infop i
nfo_ptr) |
57 : fStream(stream) | 58 : fStream(stream) |
58 , fPng_ptr(png_ptr) | 59 , fPng_ptr(png_ptr) |
59 , fInfo_ptr(info_ptr) | 60 , fInfo_ptr(info_ptr) |
60 , fColorType(kUnknown_SkColorType) { | 61 , fColorType(kUnknown_SkColorType) { |
61 SkASSERT(stream != NULL); | 62 SkASSERT(stream != NULL); |
62 stream->ref(); | |
63 } | 63 } |
64 ~SkPNGImageIndex() { | 64 ~SkPNGImageIndex() { |
65 if (fPng_ptr) { | 65 if (fPng_ptr) { |
66 png_destroy_read_struct(&fPng_ptr, &fInfo_ptr, png_infopp_NULL); | 66 png_destroy_read_struct(&fPng_ptr, &fInfo_ptr, png_infopp_NULL); |
67 } | 67 } |
68 } | 68 } |
69 | 69 |
70 SkAutoTUnref<SkStreamRewindable> fStream; | 70 SkAutoTDelete<SkStreamRewindable> fStream; |
71 png_structp fPng_ptr; | 71 png_structp fPng_ptr; |
72 png_infop fInfo_ptr; | 72 png_infop fInfo_ptr; |
73 SkColorType fColorType; | 73 SkColorType fColorType; |
74 }; | 74 }; |
75 | 75 |
76 class SkPNGImageDecoder : public SkImageDecoder { | 76 class SkPNGImageDecoder : public SkImageDecoder { |
77 public: | 77 public: |
78 SkPNGImageDecoder() { | 78 SkPNGImageDecoder() { |
79 fImageIndex = NULL; | 79 fImageIndex = NULL; |
80 } | 80 } |
(...skipping 630 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
711 } | 711 } |
712 | 712 |
713 *colorTablep = SkNEW_ARGS(SkColorTable, (colorStorage, colorCount)); | 713 *colorTablep = SkNEW_ARGS(SkColorTable, (colorStorage, colorCount)); |
714 *reallyHasAlphap = reallyHasAlpha; | 714 *reallyHasAlphap = reallyHasAlpha; |
715 return true; | 715 return true; |
716 } | 716 } |
717 | 717 |
718 #ifdef SK_BUILD_FOR_ANDROID | 718 #ifdef SK_BUILD_FOR_ANDROID |
719 | 719 |
720 bool SkPNGImageDecoder::onBuildTileIndex(SkStreamRewindable* sk_stream, int *wid
th, int *height) { | 720 bool SkPNGImageDecoder::onBuildTileIndex(SkStreamRewindable* sk_stream, int *wid
th, int *height) { |
| 721 SkAutoTDelete<SkStreamRewindable> streamDeleter(sk_stream); |
721 png_structp png_ptr; | 722 png_structp png_ptr; |
722 png_infop info_ptr; | 723 png_infop info_ptr; |
723 | 724 |
724 if (!onDecodeInit(sk_stream, &png_ptr, &info_ptr)) { | 725 if (!onDecodeInit(sk_stream, &png_ptr, &info_ptr)) { |
725 return false; | 726 return false; |
726 } | 727 } |
727 | 728 |
728 if (setjmp(png_jmpbuf(png_ptr)) != 0) { | 729 if (setjmp(png_jmpbuf(png_ptr)) != 0) { |
729 png_destroy_read_struct(&png_ptr, &info_ptr, png_infopp_NULL); | 730 png_destroy_read_struct(&png_ptr, &info_ptr, png_infopp_NULL); |
730 return false; | 731 return false; |
731 } | 732 } |
732 | 733 |
733 png_uint_32 origWidth, origHeight; | 734 png_uint_32 origWidth, origHeight; |
734 int bitDepth, colorType; | 735 int bitDepth, colorType; |
735 png_get_IHDR(png_ptr, info_ptr, &origWidth, &origHeight, &bitDepth, | 736 png_get_IHDR(png_ptr, info_ptr, &origWidth, &origHeight, &bitDepth, |
736 &colorType, int_p_NULL, int_p_NULL, int_p_NULL); | 737 &colorType, int_p_NULL, int_p_NULL, int_p_NULL); |
737 | 738 |
738 *width = origWidth; | 739 *width = origWidth; |
739 *height = origHeight; | 740 *height = origHeight; |
740 | 741 |
741 png_build_index(png_ptr); | 742 png_build_index(png_ptr); |
742 | 743 |
743 if (fImageIndex) { | 744 if (fImageIndex) { |
744 SkDELETE(fImageIndex); | 745 SkDELETE(fImageIndex); |
745 } | 746 } |
746 fImageIndex = SkNEW_ARGS(SkPNGImageIndex, (sk_stream, png_ptr, info_ptr)); | 747 fImageIndex = SkNEW_ARGS(SkPNGImageIndex, (streamDeleter.detach(), png_ptr,
info_ptr)); |
747 | 748 |
748 return true; | 749 return true; |
749 } | 750 } |
750 | 751 |
751 bool SkPNGImageDecoder::onDecodeSubset(SkBitmap* bm, const SkIRect& region) { | 752 bool SkPNGImageDecoder::onDecodeSubset(SkBitmap* bm, const SkIRect& region) { |
752 if (NULL == fImageIndex) { | 753 if (NULL == fImageIndex) { |
753 return false; | 754 return false; |
754 } | 755 } |
755 | 756 |
756 png_structp png_ptr = fImageIndex->fPng_ptr; | 757 png_structp png_ptr = fImageIndex->fPng_ptr; |
(...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1269 return SkImageDecoder::kUnknown_Format; | 1270 return SkImageDecoder::kUnknown_Format; |
1270 } | 1271 } |
1271 | 1272 |
1272 SkImageEncoder* sk_libpng_efactory(SkImageEncoder::Type t) { | 1273 SkImageEncoder* sk_libpng_efactory(SkImageEncoder::Type t) { |
1273 return (SkImageEncoder::kPNG_Type == t) ? SkNEW(SkPNGImageEncoder) : NULL; | 1274 return (SkImageEncoder::kPNG_Type == t) ? SkNEW(SkPNGImageEncoder) : NULL; |
1274 } | 1275 } |
1275 | 1276 |
1276 static SkImageDecoder_DecodeReg gDReg(sk_libpng_dfactory); | 1277 static SkImageDecoder_DecodeReg gDReg(sk_libpng_dfactory); |
1277 static SkImageDecoder_FormatReg gFormatReg(get_format_png); | 1278 static SkImageDecoder_FormatReg gFormatReg(get_format_png); |
1278 static SkImageEncoder_EncodeReg gEReg(sk_libpng_efactory); | 1279 static SkImageEncoder_EncodeReg gEReg(sk_libpng_efactory); |
OLD | NEW |