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

Unified Diff: third_party/WebKit/Source/platform/image-decoders/ico/ICOImageDecoder.cpp

Issue 2065423003: Re-land: Blink image-decoders: (lazy) deferred image decoding support for ICO (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix decodeFrameCount - copy approach from WebP and GIF decoder Created 4 years, 6 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: third_party/WebKit/Source/platform/image-decoders/ico/ICOImageDecoder.cpp
diff --git a/third_party/WebKit/Source/platform/image-decoders/ico/ICOImageDecoder.cpp b/third_party/WebKit/Source/platform/image-decoders/ico/ICOImageDecoder.cpp
index e50b37c361ee927d03183f39e764da215a702aef..00d19d7eba0776767bf69ae1cb21bd02216c6ecb 100644
--- a/third_party/WebKit/Source/platform/image-decoders/ico/ICOImageDecoder.cpp
+++ b/third_party/WebKit/Source/platform/image-decoders/ico/ICOImageDecoder.cpp
@@ -85,6 +85,14 @@ bool ICOImageDecoder::setSize(unsigned width, unsigned height)
return m_frameSize.isEmpty() ? ImageDecoder::setSize(width, height) : ((IntSize(width, height) == m_frameSize) || setFailed());
}
+bool ICOImageDecoder::frameIsCompleteAtIndex(size_t index) const
+{
+ if (index >= m_dirEntries.size())
+ return false;
+ const IconDirectoryEntry& dirEntry = m_dirEntries[index];
+ return (dirEntry.m_imageOffset + dirEntry.m_byteSize) <= m_data->size();
+}
+
bool ICOImageDecoder::setFailed()
{
m_bmpReaders.clear();
@@ -122,6 +130,19 @@ bool ICOImageDecoder::compareEntries(const IconDirectoryEntry& a, const IconDire
size_t ICOImageDecoder::decodeFrameCount()
{
decodeSize();
+
+ // If decodeSize() fails, return the existing number of frames. This way
+ // if we get halfway through the image before decoding fails, we won't
+ // suddenly start reporting that the image has zero frames.
+ if (failed())
+ return m_frameBufferCache.size();
+
+ // Length of sequence of completely received frames.
+ for (size_t i = 0; i < m_dirEntries.size(); ++i) {
+ const IconDirectoryEntry& dirEntry = m_dirEntries[i];
+ if ((dirEntry.m_imageOffset + dirEntry.m_byteSize) > m_data->size())
+ return i;
+ }
return m_dirEntries.size();
}
@@ -175,13 +196,12 @@ bool ICOImageDecoder::decodeAtIndex(size_t index)
if (imageType == BMP) {
if (!m_bmpReaders[index]) {
- // We need to have already sized m_frameBufferCache before this, and
- // we must not resize it again later (see caution in frameCount()).
- ASSERT(m_frameBufferCache.size() == m_dirEntries.size());
m_bmpReaders[index] = adoptPtr(new BMPImageReader(this, dirEntry.m_imageOffset, 0, true));
m_bmpReaders[index]->setData(m_data.get());
- m_bmpReaders[index]->setBuffer(&m_frameBufferCache[index]);
}
+ // Update the pointer to the buffer as it could change after
+ // m_frameBufferCache.resize().
+ m_bmpReaders[index]->setBuffer(&m_frameBufferCache[index]);
m_frameSize = dirEntry.m_size;
bool result = m_bmpReaders[index]->decodeBMP(false);
m_frameSize = IntSize();
@@ -280,6 +300,7 @@ ICOImageDecoder::IconDirectoryEntry ICOImageDecoder::readDirectoryEntry()
entry.m_bitCount = readUint16(6);
entry.m_hotSpot = IntPoint();
}
+ entry.m_byteSize = readUint32(8);
entry.m_imageOffset = readUint32(12);
// Some icons don't have a bit depth, only a color count. Convert the

Powered by Google App Engine
This is Rietveld 408576698