diff options
Diffstat (limited to 'WebCore/platform/image-decoders/jpeg/JPEGImageDecoder.cpp')
-rw-r--r-- | WebCore/platform/image-decoders/jpeg/JPEGImageDecoder.cpp | 52 |
1 files changed, 21 insertions, 31 deletions
diff --git a/WebCore/platform/image-decoders/jpeg/JPEGImageDecoder.cpp b/WebCore/platform/image-decoders/jpeg/JPEGImageDecoder.cpp index 9ed20b6..3d9fb8e 100644 --- a/WebCore/platform/image-decoders/jpeg/JPEGImageDecoder.cpp +++ b/WebCore/platform/image-decoders/jpeg/JPEGImageDecoder.cpp @@ -131,7 +131,8 @@ public: close(); } - void close() { + void close() + { decoder_source_mgr* src = (decoder_source_mgr*)m_info.src; if (src) fastFree(src); @@ -140,13 +141,14 @@ public: jpeg_destroy_decompress(&m_info); } - void skipBytes(long num_bytes) { + void skipBytes(long numBytes) + { decoder_source_mgr* src = (decoder_source_mgr*)m_info.src; - long bytesToSkip = std::min(num_bytes, (long)src->pub.bytes_in_buffer); + long bytesToSkip = std::min(numBytes, (long)src->pub.bytes_in_buffer); src->pub.bytes_in_buffer -= (size_t)bytesToSkip; src->pub.next_input_byte += bytesToSkip; - m_bytesToSkip = std::max(num_bytes - bytesToSkip, static_cast<long>(0)); + m_bytesToSkip = std::max(numBytes - bytesToSkip, static_cast<long>(0)); } bool decode(const Vector<char>& data, bool onlySize) @@ -192,7 +194,6 @@ public: m_info.out_color_space = JCS_CMYK; break; default: - m_state = JPEG_ERROR; return false; } @@ -212,10 +213,8 @@ public: m_state = JPEG_START_DECOMPRESS; // We can fill in the size now that the header is available. - if (!m_decoder->setSize(m_info.image_width, m_info.image_height)) { - m_state = JPEG_ERROR; + if (!m_decoder->setSize(m_info.image_width, m_info.image_height)) return false; - } if (m_decodingSizeOnly) { // We can stop here. Reduce our buffer length and available @@ -316,7 +315,8 @@ public: break; case JPEG_ERROR: - break; + // We can get here if the constructor failed. + return m_decoder->setFailed(); } return true; @@ -380,20 +380,9 @@ JPEGImageDecoder::~JPEGImageDecoder() { } -void JPEGImageDecoder::setData(SharedBuffer* data, bool allDataReceived) -{ - if (m_failed) - return; - - ImageDecoder::setData(data, allDataReceived); - - if (!m_reader && !m_failed) - m_reader.set(new JPEGImageReader(this)); -} - bool JPEGImageDecoder::isSizeAvailable() { - if (!ImageDecoder::isSizeAvailable() && !failed() && m_reader) + if (!ImageDecoder::isSizeAvailable()) decode(true); return ImageDecoder::isSizeAvailable(); @@ -417,7 +406,7 @@ RGBA32Buffer* JPEGImageDecoder::frameBufferAtIndex(size_t index) m_frameBufferCache.resize(1); RGBA32Buffer& frame = m_frameBufferCache[0]; - if (frame.status() != RGBA32Buffer::FrameComplete && m_reader) + if (frame.status() != RGBA32Buffer::FrameComplete) decode(false); return &frame; } @@ -430,10 +419,8 @@ bool JPEGImageDecoder::outputScanlines() // Initialize the framebuffer if needed. RGBA32Buffer& buffer = m_frameBufferCache[0]; if (buffer.status() == RGBA32Buffer::FrameEmpty) { - if (!buffer.setSize(scaledSize().width(), scaledSize().height())) { - m_failed = true; - return false; - } + if (!buffer.setSize(scaledSize().width(), scaledSize().height())) + return setFailed(); buffer.setStatus(RGBA32Buffer::FramePartial); buffer.setHasAlpha(false); @@ -474,8 +461,7 @@ bool JPEGImageDecoder::outputScanlines() buffer.setRGBA(x, destY, jsample[0] * k / 255, jsample[1] * k / 255, jsample[2] * k / 255, 0xFF); } else { ASSERT_NOT_REACHED(); - m_failed = true; - return false; + return setFailed(); } } } @@ -495,12 +481,16 @@ void JPEGImageDecoder::jpegComplete() void JPEGImageDecoder::decode(bool onlySize) { - if (m_failed) + if (failed()) return; - m_failed = !m_reader->decode(m_data->buffer(), onlySize); + if (!m_reader) + m_reader.set(new JPEGImageReader(this)); + + if (!m_reader->decode(m_data->buffer(), onlySize)) + setFailed(); - if (m_failed || (!m_frameBufferCache.isEmpty() && m_frameBufferCache[0].status() == RGBA32Buffer::FrameComplete)) + if (failed() || (!m_frameBufferCache.isEmpty() && m_frameBufferCache[0].status() == RGBA32Buffer::FrameComplete)) m_reader.clear(); } |