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

Unified Diff: Source/core/platform/image-decoders/gif/GIFImageReader.cpp

Issue 15350006: Decode GIF image frames on demand. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 7 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: Source/core/platform/image-decoders/gif/GIFImageReader.cpp
diff --git a/Source/core/platform/image-decoders/gif/GIFImageReader.cpp b/Source/core/platform/image-decoders/gif/GIFImageReader.cpp
index 1a7268a19ba20c71a3e76a1bbd410d6ca1fe63cf..c21eafc618bb9cb61e6c11da76b58c5f802cf0c2 100644
--- a/Source/core/platform/image-decoders/gif/GIFImageReader.cpp
+++ b/Source/core/platform/image-decoders/gif/GIFImageReader.cpp
@@ -351,45 +351,34 @@ bool GIFFrameContext::decode(const unsigned char* data, size_t length, WebCore::
return true;
}
-// Decode all frames before haltAtFrame.
-// This method uses GIFFrameContext:decode() to decode each frame; decoding error is reported to client as a critical failure.
+// Decode a frame.
+// This method uses GIFFrameContext:decode() to decode the frame; decoding error is reported to client as a critical failure.
// Return true if decoding has progressed. Return false if an error has occurred.
-bool GIFImageReader::decode(GIFImageDecoder::GIFQuery query, unsigned haltAtFrame)
+bool GIFImageReader::decode(size_t frameIndex)
{
- ASSERT(m_bytesRead <= m_data->size());
+ bool frameDecoded = false;
+ GIFFrameContext* currentFrame = m_frames[frameIndex].get();
- if (!parse(m_bytesRead, m_data->size() - m_bytesRead, query == GIFImageDecoder::GIFSizeQuery))
+ if (!currentFrame->decode(data(0), m_data->size(), m_client, &frameDecoded))
Peter Kasting 2013/05/24 03:15:22 Nit: Simpler: return currentFrame->decode(dat
Xianzhu 2013/05/28 22:54:21 Done.
return false;
- if (query != GIFImageDecoder::GIFFullQuery)
- return true;
-
- while (m_currentDecodingFrame < std::min(m_frames.size(), static_cast<size_t>(haltAtFrame))) {
- bool frameDecoded = false;
- GIFFrameContext* currentFrame = m_frames[m_currentDecodingFrame].get();
-
- if (!currentFrame->decode(data(0), m_data->size(), m_client, &frameDecoded))
- return false;
+ if (frameDecoded && !m_client->frameComplete(frameIndex))
+ return false;
- // We need more data to continue decoding.
- if (!frameDecoded)
- break;
+ return true;
+}
- if (!m_client->frameComplete(m_currentDecodingFrame, currentFrame->delayTime, currentFrame->disposalMethod))
- return false;
- ++m_currentDecodingFrame;
- }
+bool GIFImageReader::parse(GIFImageDecoder::GIFParseQuery query)
+{
+ ASSERT(m_bytesRead <= m_data->size());
- // All frames decoded.
- if (m_currentDecodingFrame == m_frames.size() && m_parseCompleted)
- m_client->gifComplete();
- return true;
+ return parseData(m_bytesRead, m_data->size() - m_bytesRead, query);
}
// Parse incoming GIF data stream into internal data structures.
// Return true if parsing has progressed or there is not enough data.
// Return false if a fatal error is encountered.
-bool GIFImageReader::parse(size_t dataPosition, size_t len, bool parseSizeOnly)
+bool GIFImageReader::parseData(size_t dataPosition, size_t len, GIFImageDecoder::GIFParseQuery query)
{
if (!len) {
// No new data has come in since the last call, just ignore this call.
@@ -676,7 +665,7 @@ bool GIFImageReader::parse(size_t dataPosition, size_t len, bool parseSizeOnly)
return false;
}
- if (parseSizeOnly) {
+ if (query == GIFImageDecoder::GIFSizeQuery) {
// The decoder needs to stop. Hand back the number of bytes we consumed from
// buffer minus 9 (the amount we consumed to read the header).
setRemainingBytes(len + 9);

Powered by Google App Engine
This is Rietveld 408576698