OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
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 "SkCodec_libpng.h" | 8 #include "SkCodec_libpng.h" |
9 #include "SkCodecPriv.h" | 9 #include "SkCodecPriv.h" |
10 #include "SkColorPriv.h" | 10 #include "SkColorPriv.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 | 43 |
44 /////////////////////////////////////////////////////////////////////////////// | 44 /////////////////////////////////////////////////////////////////////////////// |
45 // Callback functions | 45 // Callback functions |
46 /////////////////////////////////////////////////////////////////////////////// | 46 /////////////////////////////////////////////////////////////////////////////// |
47 | 47 |
48 static void sk_error_fn(png_structp png_ptr, png_const_charp msg) { | 48 static void sk_error_fn(png_structp png_ptr, png_const_charp msg) { |
49 SkCodecPrintf("------ png error %s\n", msg); | 49 SkCodecPrintf("------ png error %s\n", msg); |
50 longjmp(png_jmpbuf(png_ptr), 1); | 50 longjmp(png_jmpbuf(png_ptr), 1); |
51 } | 51 } |
52 | 52 |
| 53 void sk_warning_fn(png_structp, png_const_charp msg) { |
| 54 SkCodecPrintf("----- png warning %s\n", msg); |
| 55 } |
| 56 |
53 static void sk_read_fn(png_structp png_ptr, png_bytep data, | 57 static void sk_read_fn(png_structp png_ptr, png_bytep data, |
54 png_size_t length) { | 58 png_size_t length) { |
55 SkStream* stream = static_cast<SkStream*>(png_get_io_ptr(png_ptr)); | 59 SkStream* stream = static_cast<SkStream*>(png_get_io_ptr(png_ptr)); |
56 const size_t bytes = stream->read(data, length); | 60 const size_t bytes = stream->read(data, length); |
57 if (bytes != length) { | 61 if (bytes != length) { |
58 // FIXME: We want to report the fact that the stream was truncated. | 62 // FIXME: We want to report the fact that the stream was truncated. |
59 // One way to do that might be to pass a enum to longjmp so setjmp can | 63 // One way to do that might be to pass a enum to longjmp so setjmp can |
60 // specify the failure. | 64 // specify the failure. |
61 png_error(png_ptr, "Read Error!"); | 65 png_error(png_ptr, "Read Error!"); |
62 } | 66 } |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 return false; | 196 return false; |
193 } | 197 } |
194 if (png_sig_cmp((png_bytep) buf, (png_size_t)0, PNG_BYTES_TO_CHECK)) { | 198 if (png_sig_cmp((png_bytep) buf, (png_size_t)0, PNG_BYTES_TO_CHECK)) { |
195 return false; | 199 return false; |
196 } | 200 } |
197 return true; | 201 return true; |
198 } | 202 } |
199 | 203 |
200 SkCodec* SkPngCodec::NewFromStream(SkStream* stream) { | 204 SkCodec* SkPngCodec::NewFromStream(SkStream* stream) { |
201 // The image is known to be a PNG. Decode enough to know the SkImageInfo. | 205 // The image is known to be a PNG. Decode enough to know the SkImageInfo. |
202 // FIXME: Allow silencing warnings. | |
203 png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, | 206 png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, |
204 sk_error_fn, NULL); | 207 sk_error_fn, sk_warning_fn); |
205 if (!png_ptr) { | 208 if (!png_ptr) { |
206 return NULL; | 209 return NULL; |
207 } | 210 } |
208 | 211 |
209 AutoCleanPng autoClean(png_ptr); | 212 AutoCleanPng autoClean(png_ptr); |
210 | 213 |
211 png_infop info_ptr = png_create_info_struct(png_ptr); | 214 png_infop info_ptr = png_create_info_struct(png_ptr); |
212 if (info_ptr == NULL) { | 215 if (info_ptr == NULL) { |
213 return NULL; | 216 return NULL; |
214 } | 217 } |
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
569 | 572 |
570 SkASSERT(fNumberPasses != INVALID_NUMBER_PASSES); | 573 SkASSERT(fNumberPasses != INVALID_NUMBER_PASSES); |
571 if (fNumberPasses > 1) { | 574 if (fNumberPasses > 1) { |
572 // We cannot efficiently do scanline decoding. | 575 // We cannot efficiently do scanline decoding. |
573 return NULL; | 576 return NULL; |
574 } | 577 } |
575 | 578 |
576 return SkNEW_ARGS(SkPngScanlineDecoder, (dstInfo, this)); | 579 return SkNEW_ARGS(SkPngScanlineDecoder, (dstInfo, this)); |
577 } | 580 } |
578 | 581 |
OLD | NEW |