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

Unified Diff: Source/platform/image-decoders/jpeg/JPEGImageDecoder.cpp

Issue 1358643002: Fix caching bug in JPEGImageDecoder (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 3 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/platform/image-decoders/jpeg/JPEGImageDecoder.cpp
diff --git a/Source/platform/image-decoders/jpeg/JPEGImageDecoder.cpp b/Source/platform/image-decoders/jpeg/JPEGImageDecoder.cpp
index baf4bd09222f76f2f765c980953084c19d8b515b..f4ba504991c6da6878cff5cdfd7b0e96fe96c296 100644
--- a/Source/platform/image-decoders/jpeg/JPEGImageDecoder.cpp
+++ b/Source/platform/image-decoders/jpeg/JPEGImageDecoder.cpp
@@ -392,20 +392,14 @@ public:
if (m_needsRestart) {
m_needsRestart = false;
m_nextReadPosition = m_restartPosition;
- } else if (m_lastSetByte != m_info.src->next_input_byte) {
- // next_input_byte was updated by jpeg, meaning that it found a restart position.
- m_restartPosition = m_nextReadPosition - m_info.src->bytes_in_buffer;
+ } else {
+ updateRestartPosition();
}
const char* segment;
const unsigned bytes = m_data->getSomeData(segment, m_nextReadPosition);
if (bytes == 0) {
- // We had to suspend. When we resume, we will need to start from the restart position.
- m_needsRestart = true;
- // Let libjpeg know that the buffer needs to be refilled.
- m_info.src->bytes_in_buffer = 0;
- m_info.src->next_input_byte = nullptr;
- m_lastSetByte = nullptr;
+ suspend();
return false;
}
@@ -531,6 +525,8 @@ public:
}
if (onlySize) {
+ updateRestartPosition();
Peter Kasting 2015/09/19 00:51:34 You should probably have comments here about why y
scroggo_chromium 2015/09/21 18:21:28 Done. (My instinct is include lots of comments, b
+ suspend();
return true;
}
// FALL THROUGH
@@ -682,6 +678,24 @@ public:
#endif
private:
+ void updateRestartPosition()
+ {
+ if (m_lastSetByte != m_info.src->next_input_byte) {
+ // next_input_byte was updated by jpeg, meaning that it found a restart position.
+ m_restartPosition = m_nextReadPosition - m_info.src->bytes_in_buffer;
+ }
+ }
+
+ void suspend()
+ {
+ // We had to suspend. When we resume, we will need to start from the restart position.
+ m_needsRestart = true;
+ // Let libjpeg know that the buffer needs to be refilled.
+ m_info.src->bytes_in_buffer = 0;
+ m_info.src->next_input_byte = nullptr;
+ m_lastSetByte = nullptr;
+ }
+
RefPtr<SharedBuffer> m_data;
JPEGImageDecoder* m_decoder;
// True if we need to back up to m_restartPosition.

Powered by Google App Engine
This is Rietveld 408576698