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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 | 78 |
79 class SkPNGImageDecoder : public SkImageDecoder { | 79 class SkPNGImageDecoder : public SkImageDecoder { |
80 public: | 80 public: |
81 SkPNGImageDecoder() { | 81 SkPNGImageDecoder() { |
82 fImageIndex = NULL; | 82 fImageIndex = NULL; |
83 } | 83 } |
84 Format getFormat() const override { | 84 Format getFormat() const override { |
85 return kPNG_Format; | 85 return kPNG_Format; |
86 } | 86 } |
87 | 87 |
88 virtual ~SkPNGImageDecoder() { | 88 virtual ~SkPNGImageDecoder() { delete fImageIndex; } |
89 SkDELETE(fImageIndex); | |
90 } | |
91 | 89 |
92 protected: | 90 protected: |
93 #ifdef SK_BUILD_FOR_ANDROID | 91 #ifdef SK_BUILD_FOR_ANDROID |
94 bool onBuildTileIndex(SkStreamRewindable *stream, int *width, int *height) o
verride; | 92 bool onBuildTileIndex(SkStreamRewindable *stream, int *width, int *height) o
verride; |
95 bool onDecodeSubset(SkBitmap* bitmap, const SkIRect& region) override; | 93 bool onDecodeSubset(SkBitmap* bitmap, const SkIRect& region) override; |
96 #endif | 94 #endif |
97 Result onDecode(SkStream* stream, SkBitmap* bm, Mode) override; | 95 Result onDecode(SkStream* stream, SkBitmap* bm, Mode) override; |
98 | 96 |
99 private: | 97 private: |
100 SkPNGImageIndex* fImageIndex; | 98 SkPNGImageIndex* fImageIndex; |
(...skipping 615 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
716 ensure this doesn't happen, we grow the colortable to the maximum size t
hat can be | 714 ensure this doesn't happen, we grow the colortable to the maximum size t
hat can be |
717 addressed by the bitdepth of the image and fill it with the last palette
color or black if | 715 addressed by the bitdepth of the image and fill it with the last palette
color or black if |
718 the palette is empty (really broken image). | 716 the palette is empty (really broken image). |
719 */ | 717 */ |
720 int colorCount = SkTMax(numPalette, 1 << SkTMin(bitDepth, 8)); | 718 int colorCount = SkTMax(numPalette, 1 << SkTMin(bitDepth, 8)); |
721 SkPMColor lastColor = index > 0 ? colorPtr[-1] : SkPackARGB32(0xFF, 0, 0, 0)
; | 719 SkPMColor lastColor = index > 0 ? colorPtr[-1] : SkPackARGB32(0xFF, 0, 0, 0)
; |
722 for (; index < colorCount; index++) { | 720 for (; index < colorCount; index++) { |
723 *colorPtr++ = lastColor; | 721 *colorPtr++ = lastColor; |
724 } | 722 } |
725 | 723 |
726 *colorTablep = SkNEW_ARGS(SkColorTable, (colorStorage, colorCount)); | 724 *colorTablep = new SkColorTable(colorStorage, colorCount); |
727 *reallyHasAlphap = reallyHasAlpha; | 725 *reallyHasAlphap = reallyHasAlpha; |
728 return true; | 726 return true; |
729 } | 727 } |
730 | 728 |
731 #ifdef SK_BUILD_FOR_ANDROID | 729 #ifdef SK_BUILD_FOR_ANDROID |
732 | 730 |
733 bool SkPNGImageDecoder::onBuildTileIndex(SkStreamRewindable* sk_stream, int *wid
th, int *height) { | 731 bool SkPNGImageDecoder::onBuildTileIndex(SkStreamRewindable* sk_stream, int *wid
th, int *height) { |
734 SkAutoTDelete<SkStreamRewindable> streamDeleter(sk_stream); | 732 SkAutoTDelete<SkStreamRewindable> streamDeleter(sk_stream); |
735 png_structp png_ptr; | 733 png_structp png_ptr; |
736 png_infop info_ptr; | 734 png_infop info_ptr; |
(...skipping 11 matching lines...) Expand all Loading... |
748 int bitDepth, colorType; | 746 int bitDepth, colorType; |
749 png_get_IHDR(png_ptr, info_ptr, &origWidth, &origHeight, &bitDepth, | 747 png_get_IHDR(png_ptr, info_ptr, &origWidth, &origHeight, &bitDepth, |
750 &colorType, int_p_NULL, int_p_NULL, int_p_NULL); | 748 &colorType, int_p_NULL, int_p_NULL, int_p_NULL); |
751 | 749 |
752 *width = origWidth; | 750 *width = origWidth; |
753 *height = origHeight; | 751 *height = origHeight; |
754 | 752 |
755 png_build_index(png_ptr); | 753 png_build_index(png_ptr); |
756 | 754 |
757 if (fImageIndex) { | 755 if (fImageIndex) { |
758 SkDELETE(fImageIndex); | 756 delete fImageIndex; |
759 } | 757 } |
760 fImageIndex = SkNEW_ARGS(SkPNGImageIndex, (streamDeleter.detach(), png_ptr,
info_ptr)); | 758 fImageIndex = new SkPNGImageIndex(streamDeleter.detach(), png_ptr, info_ptr)
; |
761 | 759 |
762 return true; | 760 return true; |
763 } | 761 } |
764 | 762 |
765 bool SkPNGImageDecoder::onDecodeSubset(SkBitmap* bm, const SkIRect& region) { | 763 bool SkPNGImageDecoder::onDecodeSubset(SkBitmap* bm, const SkIRect& region) { |
766 if (NULL == fImageIndex) { | 764 if (NULL == fImageIndex) { |
767 return false; | 765 return false; |
768 } | 766 } |
769 | 767 |
770 png_structp png_ptr = fImageIndex->fPng_ptr; | 768 png_structp png_ptr = fImageIndex->fPng_ptr; |
(...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1264 char buf[PNG_BYTES_TO_CHECK]; | 1262 char buf[PNG_BYTES_TO_CHECK]; |
1265 if (stream->read(buf, PNG_BYTES_TO_CHECK) == PNG_BYTES_TO_CHECK && | 1263 if (stream->read(buf, PNG_BYTES_TO_CHECK) == PNG_BYTES_TO_CHECK && |
1266 !png_sig_cmp((png_bytep) buf, (png_size_t)0, PNG_BYTES_TO_CHECK)) { | 1264 !png_sig_cmp((png_bytep) buf, (png_size_t)0, PNG_BYTES_TO_CHECK)) { |
1267 return true; | 1265 return true; |
1268 } | 1266 } |
1269 return false; | 1267 return false; |
1270 } | 1268 } |
1271 | 1269 |
1272 SkImageDecoder* sk_libpng_dfactory(SkStreamRewindable* stream) { | 1270 SkImageDecoder* sk_libpng_dfactory(SkStreamRewindable* stream) { |
1273 if (is_png(stream)) { | 1271 if (is_png(stream)) { |
1274 return SkNEW(SkPNGImageDecoder); | 1272 return new SkPNGImageDecoder; |
1275 } | 1273 } |
1276 return NULL; | 1274 return NULL; |
1277 } | 1275 } |
1278 | 1276 |
1279 static SkImageDecoder::Format get_format_png(SkStreamRewindable* stream) { | 1277 static SkImageDecoder::Format get_format_png(SkStreamRewindable* stream) { |
1280 if (is_png(stream)) { | 1278 if (is_png(stream)) { |
1281 return SkImageDecoder::kPNG_Format; | 1279 return SkImageDecoder::kPNG_Format; |
1282 } | 1280 } |
1283 return SkImageDecoder::kUnknown_Format; | 1281 return SkImageDecoder::kUnknown_Format; |
1284 } | 1282 } |
1285 | 1283 |
1286 SkImageEncoder* sk_libpng_efactory(SkImageEncoder::Type t) { | 1284 SkImageEncoder* sk_libpng_efactory(SkImageEncoder::Type t) { |
1287 return (SkImageEncoder::kPNG_Type == t) ? SkNEW(SkPNGImageEncoder) : NULL; | 1285 return (SkImageEncoder::kPNG_Type == t) ? new SkPNGImageEncoder : NULL; |
1288 } | 1286 } |
1289 | 1287 |
1290 static SkImageDecoder_DecodeReg gDReg(sk_libpng_dfactory); | 1288 static SkImageDecoder_DecodeReg gDReg(sk_libpng_dfactory); |
1291 static SkImageDecoder_FormatReg gFormatReg(get_format_png); | 1289 static SkImageDecoder_FormatReg gFormatReg(get_format_png); |
1292 static SkImageEncoder_EncodeReg gEReg(sk_libpng_efactory); | 1290 static SkImageEncoder_EncodeReg gEReg(sk_libpng_efactory); |
OLD | NEW |