Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(110)

Side by Side Diff: src/images/SkImageDecoder_libpng.cpp

Issue 1401283003: Supply separate flags for onBuildTileIndex (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/images/SkImageDecoder_libjpeg.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 #define DEFAULT_FOR_SUPPRESS_PNG_IMAGE_DECODER_WARNINGS false 45 #define DEFAULT_FOR_SUPPRESS_PNG_IMAGE_DECODER_WARNINGS false
46 #else // !defined(SK_DEBUG) 46 #else // !defined(SK_DEBUG)
47 #define DEFAULT_FOR_SUPPRESS_PNG_IMAGE_DECODER_WARNINGS true 47 #define DEFAULT_FOR_SUPPRESS_PNG_IMAGE_DECODER_WARNINGS true
48 #endif // defined(SK_DEBUG) 48 #endif // defined(SK_DEBUG)
49 SK_CONF_DECLARE(bool, c_suppressPNGImageDecoderWarnings, 49 SK_CONF_DECLARE(bool, c_suppressPNGImageDecoderWarnings,
50 "images.png.suppressDecoderWarnings", 50 "images.png.suppressDecoderWarnings",
51 DEFAULT_FOR_SUPPRESS_PNG_IMAGE_DECODER_WARNINGS, 51 DEFAULT_FOR_SUPPRESS_PNG_IMAGE_DECODER_WARNINGS,
52 "Suppress most PNG warnings when calling image decode " 52 "Suppress most PNG warnings when calling image decode "
53 "functions."); 53 "functions.");
54 54
55 55 #if defined(SK_BUILD_FOR_ANDROID) && !defined(SK_PNG_NO_INDEX_SUPPORTED)
56 #define SK_PNG_INDEX_SUPPORTED
57 #endif
56 58
57 class SkPNGImageIndex { 59 class SkPNGImageIndex {
58 public: 60 public:
59 // Takes ownership of stream. 61 // Takes ownership of stream.
60 SkPNGImageIndex(SkStreamRewindable* stream, png_structp png_ptr, png_infop i nfo_ptr) 62 SkPNGImageIndex(SkStreamRewindable* stream, png_structp png_ptr, png_infop i nfo_ptr)
61 : fStream(stream) 63 : fStream(stream)
62 , fPng_ptr(png_ptr) 64 , fPng_ptr(png_ptr)
63 , fInfo_ptr(info_ptr) 65 , fInfo_ptr(info_ptr)
64 , fColorType(kUnknown_SkColorType) { 66 , fColorType(kUnknown_SkColorType) {
65 SkASSERT(stream != nullptr); 67 SkASSERT(stream != nullptr);
(...skipping 15 matching lines...) Expand all
81 SkPNGImageDecoder() { 83 SkPNGImageDecoder() {
82 fImageIndex = nullptr; 84 fImageIndex = nullptr;
83 } 85 }
84 Format getFormat() const override { 86 Format getFormat() const override {
85 return kPNG_Format; 87 return kPNG_Format;
86 } 88 }
87 89
88 virtual ~SkPNGImageDecoder() { delete fImageIndex; } 90 virtual ~SkPNGImageDecoder() { delete fImageIndex; }
89 91
90 protected: 92 protected:
91 #ifdef SK_BUILD_FOR_ANDROID 93 #ifdef SK_PNG_INDEX_SUPPORTED
92 bool onBuildTileIndex(SkStreamRewindable *stream, int *width, int *height) o verride; 94 bool onBuildTileIndex(SkStreamRewindable *stream, int *width, int *height) o verride;
93 bool onDecodeSubset(SkBitmap* bitmap, const SkIRect& region) override; 95 bool onDecodeSubset(SkBitmap* bitmap, const SkIRect& region) override;
94 #endif 96 #endif
95 Result onDecode(SkStream* stream, SkBitmap* bm, Mode) override; 97 Result onDecode(SkStream* stream, SkBitmap* bm, Mode) override;
96 98
97 private: 99 private:
98 SkPNGImageIndex* fImageIndex; 100 SkPNGImageIndex* fImageIndex;
99 101
100 bool onDecodeInit(SkStream* stream, png_structp *png_ptrp, png_infop *info_p trp); 102 bool onDecodeInit(SkStream* stream, png_structp *png_ptrp, png_infop *info_p trp);
101 bool decodePalette(png_structp png_ptr, png_infop info_ptr, int bitDepth, 103 bool decodePalette(png_structp png_ptr, png_infop info_ptr, int bitDepth,
(...skipping 23 matching lines...) Expand all
125 }; 127 };
126 128
127 static void sk_read_fn(png_structp png_ptr, png_bytep data, png_size_t length) { 129 static void sk_read_fn(png_structp png_ptr, png_bytep data, png_size_t length) {
128 SkStream* sk_stream = (SkStream*) png_get_io_ptr(png_ptr); 130 SkStream* sk_stream = (SkStream*) png_get_io_ptr(png_ptr);
129 size_t bytes = sk_stream->read(data, length); 131 size_t bytes = sk_stream->read(data, length);
130 if (bytes != length) { 132 if (bytes != length) {
131 png_error(png_ptr, "Read Error!"); 133 png_error(png_ptr, "Read Error!");
132 } 134 }
133 } 135 }
134 136
135 #ifdef SK_BUILD_FOR_ANDROID 137 #ifdef SK_PNG_INDEX_SUPPORTED
136 static void sk_seek_fn(png_structp png_ptr, png_uint_32 offset) { 138 static void sk_seek_fn(png_structp png_ptr, png_uint_32 offset) {
137 SkStreamRewindable* sk_stream = (SkStreamRewindable*) png_get_io_ptr(png_ptr ); 139 SkStreamRewindable* sk_stream = (SkStreamRewindable*) png_get_io_ptr(png_ptr );
138 if (!sk_stream->rewind()) { 140 if (!sk_stream->rewind()) {
139 png_error(png_ptr, "Failed to rewind stream!"); 141 png_error(png_ptr, "Failed to rewind stream!");
140 } 142 }
141 (void)sk_stream->skip(offset); 143 (void)sk_stream->skip(offset);
142 } 144 }
143 #endif 145 #endif
144 146
145 #ifdef PNG_READ_UNKNOWN_CHUNKS_SUPPORTED 147 #ifdef PNG_READ_UNKNOWN_CHUNKS_SUPPORTED
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 */ 257 */
256 if (setjmp(png_jmpbuf(png_ptr))) { 258 if (setjmp(png_jmpbuf(png_ptr))) {
257 png_destroy_read_struct(&png_ptr, &info_ptr, png_infopp_NULL); 259 png_destroy_read_struct(&png_ptr, &info_ptr, png_infopp_NULL);
258 return false; 260 return false;
259 } 261 }
260 262
261 /* If you are using replacement read functions, instead of calling 263 /* If you are using replacement read functions, instead of calling
262 * png_init_io() here you would call: 264 * png_init_io() here you would call:
263 */ 265 */
264 png_set_read_fn(png_ptr, (void *)sk_stream, sk_read_fn); 266 png_set_read_fn(png_ptr, (void *)sk_stream, sk_read_fn);
265 #ifdef SK_BUILD_FOR_ANDROID 267 #ifdef SK_PNG_INDEX_SUPPORTED
266 png_set_seek_fn(png_ptr, sk_seek_fn); 268 png_set_seek_fn(png_ptr, sk_seek_fn);
267 #endif 269 #endif
268 /* where user_io_ptr is a structure you want available to the callbacks */ 270 /* where user_io_ptr is a structure you want available to the callbacks */
269 /* If we have already read some of the signature */ 271 /* If we have already read some of the signature */
270 // png_set_sig_bytes(png_ptr, 0 /* sig_read */ ); 272 // png_set_sig_bytes(png_ptr, 0 /* sig_read */ );
271 273
272 #ifdef PNG_READ_UNKNOWN_CHUNKS_SUPPORTED 274 #ifdef PNG_READ_UNKNOWN_CHUNKS_SUPPORTED
273 // hookup our peeker so we can see any user-chunks the caller may be interes ted in 275 // hookup our peeker so we can see any user-chunks the caller may be interes ted in
274 png_set_keep_unknown_chunks(png_ptr, PNG_HANDLE_CHUNK_ALWAYS, (png_byte*)"", 0); 276 png_set_keep_unknown_chunks(png_ptr, PNG_HANDLE_CHUNK_ALWAYS, (png_byte*)"", 0);
275 if (this->getPeeker()) { 277 if (this->getPeeker()) {
(...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after
719 SkPMColor lastColor = index > 0 ? colorPtr[-1] : SkPackARGB32(0xFF, 0, 0, 0) ; 721 SkPMColor lastColor = index > 0 ? colorPtr[-1] : SkPackARGB32(0xFF, 0, 0, 0) ;
720 for (; index < colorCount; index++) { 722 for (; index < colorCount; index++) {
721 *colorPtr++ = lastColor; 723 *colorPtr++ = lastColor;
722 } 724 }
723 725
724 *colorTablep = new SkColorTable(colorStorage, colorCount); 726 *colorTablep = new SkColorTable(colorStorage, colorCount);
725 *reallyHasAlphap = reallyHasAlpha; 727 *reallyHasAlphap = reallyHasAlpha;
726 return true; 728 return true;
727 } 729 }
728 730
729 #ifdef SK_BUILD_FOR_ANDROID 731 #ifdef SK_PNG_INDEX_SUPPORTED
730 732
731 bool SkPNGImageDecoder::onBuildTileIndex(SkStreamRewindable* sk_stream, int *wid th, int *height) { 733 bool SkPNGImageDecoder::onBuildTileIndex(SkStreamRewindable* sk_stream, int *wid th, int *height) {
732 SkAutoTDelete<SkStreamRewindable> streamDeleter(sk_stream); 734 SkAutoTDelete<SkStreamRewindable> streamDeleter(sk_stream);
733 png_structp png_ptr; 735 png_structp png_ptr;
734 png_infop info_ptr; 736 png_infop info_ptr;
735 737
736 if (!onDecodeInit(sk_stream, &png_ptr, &info_ptr)) { 738 if (!onDecodeInit(sk_stream, &png_ptr, &info_ptr)) {
737 return false; 739 return false;
738 } 740 }
739 741
(...skipping 541 matching lines...) Expand 10 before | Expand all | Expand 10 after
1281 return SkImageDecoder::kUnknown_Format; 1283 return SkImageDecoder::kUnknown_Format;
1282 } 1284 }
1283 1285
1284 SkImageEncoder* sk_libpng_efactory(SkImageEncoder::Type t) { 1286 SkImageEncoder* sk_libpng_efactory(SkImageEncoder::Type t) {
1285 return (SkImageEncoder::kPNG_Type == t) ? new SkPNGImageEncoder : nullptr; 1287 return (SkImageEncoder::kPNG_Type == t) ? new SkPNGImageEncoder : nullptr;
1286 } 1288 }
1287 1289
1288 static SkImageDecoder_DecodeReg gDReg(sk_libpng_dfactory); 1290 static SkImageDecoder_DecodeReg gDReg(sk_libpng_dfactory);
1289 static SkImageDecoder_FormatReg gFormatReg(get_format_png); 1291 static SkImageDecoder_FormatReg gFormatReg(get_format_png);
1290 static SkImageEncoder_EncodeReg gEReg(sk_libpng_efactory); 1292 static SkImageEncoder_EncodeReg gEReg(sk_libpng_efactory);
OLDNEW
« no previous file with comments | « src/images/SkImageDecoder_libjpeg.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698