| @@ -1,80 +1,123 @@ | | | @@ -1,80 +1,123 @@ |
1 | $NetBSD: patch-ab,v 1.3 2011/01/14 12:34:25 wiz Exp $ | | 1 | $NetBSD: patch-ab,v 1.4 2011/01/15 14:51:26 wiz Exp $ |
2 | | | 2 | |
3 | Fix build with png-1.5. | | 3 | Fix build with png-1.5. |
4 | | | 4 | |
5 | --- WebCore/platform/image-decoders/png/PNGImageDecoder.cpp.orig 2010-12-28 12:28:51.000000000 +0000 | | 5 | --- WebCore/platform/image-decoders/png/PNGImageDecoder.cpp.orig 2010-12-28 12:28:51.000000000 +0000 |
6 | +++ WebCore/platform/image-decoders/png/PNGImageDecoder.cpp | | 6 | +++ WebCore/platform/image-decoders/png/PNGImageDecoder.cpp |
7 | @@ -60,7 +60,11 @@ const unsigned long cMaxPNGSize = 100000 | | 7 | @@ -60,7 +60,11 @@ const unsigned long cMaxPNGSize = 100000 |
8 | // Called if the decoding of the image fails. | | 8 | // Called if the decoding of the image fails. |
9 | static void PNGAPI decodingFailed(png_structp png, png_const_charp) | | 9 | static void PNGAPI decodingFailed(png_structp png, png_const_charp) |
10 | { | | 10 | { |
11 | +#if (PNG_LIBPNG_VER < 10500) | | 11 | +#if (PNG_LIBPNG_VER < 10500) |
12 | longjmp(JMPBUF(png), 1); | | 12 | longjmp(JMPBUF(png), 1); |
13 | +#else | | 13 | +#else |
14 | + png_longjmp(png, 1); | | 14 | + png_longjmp(png, 1); |
15 | +#endif | | 15 | +#endif |
16 | } | | 16 | } |
17 | | | 17 | |
18 | // Callbacks given to the read struct. The first is for warnings (we want to | | 18 | // Callbacks given to the read struct. The first is for warnings (we want to |
19 | @@ -216,18 +220,26 @@ void PNGImageDecoder::headerAvailable() | | 19 | @@ -139,14 +143,31 @@ public: |
| | | 20 | |
| | | 21 | const char* segment; |
| | | 22 | while (unsigned segmentLength = data.getSomeData(segment, m_readOffset)) { |
| | | 23 | - m_readOffset += segmentLength; |
| | | 24 | - m_currentBufferSize = m_readOffset; |
| | | 25 | - png_process_data(m_png, m_info, reinterpret_cast<png_bytep>(const_cast<char*>(segment)), segmentLength); |
| | | 26 | - // We explicitly specify the superclass isSizeAvailable() because we |
| | | 27 | - // merely want to check if we've managed to set the size, not |
| | | 28 | - // (recursively) trigger additional decoding if we haven't. |
| | | 29 | - if (sizeOnly ? decoder->ImageDecoder::isSizeAvailable() : decoder->isComplete()) |
| | | 30 | - return; |
| | | 31 | + if (sizeOnly) { |
| | | 32 | + while (segmentLength > 0) { |
| | | 33 | + // Unfortunately if we read the image at this point it will be ignored, |
| | | 34 | + // therefore take small steps through the data until the head is read. |
| | | 35 | + // This is crude but effective. |
| | | 36 | + m_currentBufferSize = ++m_readOffset; |
| | | 37 | + png_process_data(m_png, m_info, reinterpret_cast<png_bytep>(const_cast<char*>(segment)), 1); |
| | | 38 | + |
| | | 39 | + // We explicitly specify the superclass isSizeAvailable() because we |
| | | 40 | + // merely want to check if we've managed to set the size, not |
| | | 41 | + // (recursively) trigger additional decoding if we haven't. |
| | | 42 | + if (decoder->ImageDecoder::isSizeAvailable()) |
| | | 43 | + return; |
| | | 44 | + |
| | | 45 | + --segmentLength; |
| | | 46 | + ++segment; |
| | | 47 | + } |
| | | 48 | + } else { |
| | | 49 | + // Just process the whole segment at once: |
| | | 50 | + m_readOffset += segmentLength; |
| | | 51 | + m_currentBufferSize = m_readOffset; |
| | | 52 | + png_process_data(m_png, m_info, reinterpret_cast<png_bytep>(const_cast<char*>(segment)), segmentLength); |
| | | 53 | + if (decoder->isComplete()) |
| | | 54 | + return; |
| | | 55 | + } |
| | | 56 | } |
| | | 57 | if (!decoder->isComplete() && decoder->isAllDataReceived()) |
| | | 58 | decoder->pngComplete(); |
| | | 59 | @@ -216,18 +237,26 @@ void PNGImageDecoder::headerAvailable() |
20 | { | | 60 | { |
21 | png_structp png = m_reader->pngPtr(); | | 61 | png_structp png = m_reader->pngPtr(); |
22 | png_infop info = m_reader->infoPtr(); | | 62 | png_infop info = m_reader->infoPtr(); |
23 | - png_uint_32 width = png->width; | | 63 | - png_uint_32 width = png->width; |
24 | - png_uint_32 height = png->height; | | 64 | - png_uint_32 height = png->height; |
25 | + png_uint_32 width = png_get_image_width(png, info); | | 65 | + png_uint_32 width = png_get_image_width(png, info); |
26 | + png_uint_32 height = png_get_image_height(png, info); | | 66 | + png_uint_32 height = png_get_image_height(png, info); |
27 | | | 67 | |
28 | // Protect against large images. | | 68 | // Protect against large images. |
29 | - if (png->width > cMaxPNGSize || png->height > cMaxPNGSize) { | | 69 | - if (png->width > cMaxPNGSize || png->height > cMaxPNGSize) { |
30 | + if (png_get_image_width(png, info) > cMaxPNGSize || png_get_image_height(png, info) > cMaxPNGSize) { | | 70 | + if (width > cMaxPNGSize || height > cMaxPNGSize) { |
31 | +#if (PNG_LIBPNG_VER < 10500) | | 71 | +#if (PNG_LIBPNG_VER < 10500) |
32 | longjmp(JMPBUF(png), 1); | | 72 | longjmp(JMPBUF(png), 1); |
33 | +#else | | 73 | +#else |
34 | + png_longjmp(png, 1); | | 74 | + png_longjmp(png, 1); |
35 | +#endif | | 75 | +#endif |
36 | return; | | 76 | return; |
37 | } | | 77 | } |
38 | | | 78 | |
39 | // We can fill in the size now that the header is available. | | 79 | // We can fill in the size now that the header is available. |
40 | if (!setSize(width, height)) { | | 80 | if (!setSize(width, height)) { |
41 | +#if (PNG_LIBPNG_VER < 10500) | | 81 | +#if (PNG_LIBPNG_VER < 10500) |
42 | longjmp(JMPBUF(png), 1); | | 82 | longjmp(JMPBUF(png), 1); |
43 | +#else | | 83 | +#else |
44 | + png_longjmp(png, 1); | | 84 | + png_longjmp(png, 1); |
45 | +#endif | | 85 | +#endif |
46 | return; | | 86 | return; |
47 | } | | 87 | } |
48 | | | 88 | |
49 | @@ -277,8 +289,8 @@ void PNGImageDecoder::headerAvailable() | | 89 | @@ -274,12 +303,6 @@ void PNGImageDecoder::headerAvailable() |
| | | 90 | ASSERT(channels == 3 || channels == 4); |
50 | | | 91 | |
51 | if (m_reader->decodingSizeOnly()) { | | 92 | m_reader->setHasAlpha(channels == 4); |
52 | // If we only needed the size, halt the reader. | | 93 | - |
| | | 94 | - if (m_reader->decodingSizeOnly()) { |
| | | 95 | - // If we only needed the size, halt the reader. |
53 | - m_reader->setReadOffset(m_reader->currentBufferSize() - png->buffer_size); | | 96 | - m_reader->setReadOffset(m_reader->currentBufferSize() - png->buffer_size); |
54 | - png->buffer_size = 0; | | 97 | - png->buffer_size = 0; |
55 | + m_reader->setReadOffset(m_reader->currentBufferSize() - png_get_compression_buffer_size(png)); | | 98 | - } |
56 | + png_set_compression_buffer_size(png, 0); | | | |
57 | } | | | |
58 | } | | 99 | } |
59 | | | 100 | |
60 | @@ -291,7 +303,11 @@ void PNGImageDecoder::rowAvailable(unsig | | 101 | void PNGImageDecoder::rowAvailable(unsigned char* rowBuffer, unsigned rowIndex, int interlacePass) |
| | | 102 | @@ -291,7 +314,11 @@ void PNGImageDecoder::rowAvailable(unsig |
61 | RGBA32Buffer& buffer = m_frameBufferCache[0]; | | 103 | RGBA32Buffer& buffer = m_frameBufferCache[0]; |
62 | if (buffer.status() == RGBA32Buffer::FrameEmpty) { | | 104 | if (buffer.status() == RGBA32Buffer::FrameEmpty) { |
63 | if (!buffer.setSize(scaledSize().width(), scaledSize().height())) { | | 105 | if (!buffer.setSize(scaledSize().width(), scaledSize().height())) { |
64 | +#if (PNG_LIBPNG_VER < 10500) | | 106 | +#if (PNG_LIBPNG_VER < 10500) |
65 | longjmp(JMPBUF(m_reader->pngPtr()), 1); | | 107 | longjmp(JMPBUF(m_reader->pngPtr()), 1); |
66 | +#else | | 108 | +#else |
67 | + png_longjmp(m_reader->pngPtr(), 1); | | 109 | + png_longjmp(m_reader->pngPtr(), 1); |
68 | +#endif | | 110 | +#endif |
69 | return; | | 111 | return; |
70 | } | | 112 | } |
71 | buffer.setStatus(RGBA32Buffer::FramePartial); | | 113 | buffer.setStatus(RGBA32Buffer::FramePartial); |
72 | @@ -300,7 +316,7 @@ void PNGImageDecoder::rowAvailable(unsig | | 114 | @@ -300,7 +327,8 @@ void PNGImageDecoder::rowAvailable(unsig |
73 | // For PNGs, the frame always fills the entire image. | | 115 | // For PNGs, the frame always fills the entire image. |
74 | buffer.setRect(IntRect(IntPoint(), size())); | | 116 | buffer.setRect(IntRect(IntPoint(), size())); |
75 | | | 117 | |
76 | - if (m_reader->pngPtr()->interlaced) | | 118 | - if (m_reader->pngPtr()->interlaced) |
77 | + if (png_get_interlace_type(m_reader->pngPtr(), m_reader->infoPtr()) != PNG_INTERLACE_NONE) | | 119 | + if (png_get_interlace_type(m_reader->pngPtr(), m_reader->infoPtr()) |
| | | 120 | + != PNG_INTERLACE_NONE) |
78 | m_reader->createInterlaceBuffer((m_reader->hasAlpha() ? 4 : 3) * size().width() * size().height()); | | 121 | m_reader->createInterlaceBuffer((m_reader->hasAlpha() ? 4 : 3) * size().width() * size().height()); |
79 | } | | 122 | } |
80 | | | 123 | |