OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2006 Apple Computer, Inc. | 2 * Copyright (C) 2006 Apple Computer, Inc. |
3 * Copyright (C) Research In Motion Limited 2009-2010. All rights reserved. | 3 * Copyright (C) Research In Motion Limited 2009-2010. All rights reserved. |
4 * | 4 * |
5 * Portions are Copyright (C) 2001 mozilla.org | 5 * Portions are Copyright (C) 2001 mozilla.org |
6 * | 6 * |
7 * Other contributors: | 7 * Other contributors: |
8 * Stuart Parmenter <stuart@mozilla.com> | 8 * Stuart Parmenter <stuart@mozilla.com> |
9 * | 9 * |
10 * This library is free software; you can redistribute it and/or | 10 * This library is free software; you can redistribute it and/or |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 m_interlaceBuffer = 0; | 135 m_interlaceBuffer = 0; |
136 m_readOffset = 0; | 136 m_readOffset = 0; |
137 } | 137 } |
138 | 138 |
139 bool decode(const SharedBuffer& data, bool sizeOnly) | 139 bool decode(const SharedBuffer& data, bool sizeOnly) |
140 { | 140 { |
141 m_decodingSizeOnly = sizeOnly; | 141 m_decodingSizeOnly = sizeOnly; |
142 PNGImageDecoder* decoder = static_cast<PNGImageDecoder*>(png_get_progres
sive_ptr(m_png)); | 142 PNGImageDecoder* decoder = static_cast<PNGImageDecoder*>(png_get_progres
sive_ptr(m_png)); |
143 | 143 |
144 // We need to do the setjmp here. Otherwise bad things will happen. | 144 // We need to do the setjmp here. Otherwise bad things will happen. |
| 145 // The libpng manual points out: ".. there are some uncertainties about
the status of local variables after a longjmp, so the |
| 146 // user may want to be careful about doing anything after setjmp returns
non-zero besides returning itself." This is why |
| 147 // we avoid referencing |decoder| in the event of an error. |
145 if (setjmp(JMPBUF(m_png))) | 148 if (setjmp(JMPBUF(m_png))) |
146 return decoder->setFailed(); | 149 return static_cast<PNGImageDecoder*>(png_get_progressive_ptr(m_png))
->setFailed(); |
147 | 150 |
148 const char* segment; | 151 const char* segment; |
149 while (unsigned segmentLength = data.getSomeData(segment, m_readOffset))
{ | 152 while (unsigned segmentLength = data.getSomeData(segment, m_readOffset))
{ |
150 m_readOffset += segmentLength; | 153 m_readOffset += segmentLength; |
151 m_currentBufferSize = m_readOffset; | 154 m_currentBufferSize = m_readOffset; |
152 png_process_data(m_png, m_info, reinterpret_cast<png_bytep>(const_ca
st<char*>(segment)), segmentLength); | 155 png_process_data(m_png, m_info, reinterpret_cast<png_bytep>(const_ca
st<char*>(segment)), segmentLength); |
153 // We explicitly specify the superclass isSizeAvailable() because we | 156 // We explicitly specify the superclass isSizeAvailable() because we |
154 // merely want to check if we've managed to set the size, not | 157 // merely want to check if we've managed to set the size, not |
155 // (recursively) trigger additional decoding if we haven't. | 158 // (recursively) trigger additional decoding if we haven't. |
156 if (sizeOnly ? decoder->ImageDecoder::isSizeAvailable() : decoder->i
sComplete()) | 159 if (sizeOnly ? decoder->ImageDecoder::isSizeAvailable() : decoder->i
sComplete()) |
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
541 // has failed. | 544 // has failed. |
542 if (!m_reader->decode(*m_data, onlySize) && isAllDataReceived()) | 545 if (!m_reader->decode(*m_data, onlySize) && isAllDataReceived()) |
543 setFailed(); | 546 setFailed(); |
544 // If we're done decoding the image, we don't need the PNGImageReader | 547 // If we're done decoding the image, we don't need the PNGImageReader |
545 // anymore. (If we failed, |m_reader| has already been cleared.) | 548 // anymore. (If we failed, |m_reader| has already been cleared.) |
546 else if (isComplete()) | 549 else if (isComplete()) |
547 m_reader.clear(); | 550 m_reader.clear(); |
548 } | 551 } |
549 | 552 |
550 } // namespace blink | 553 } // namespace blink |
OLD | NEW |