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

Side by Side Diff: third_party/WebKit/Source/platform/image-decoders/webp/WEBPImageDecoder.cpp

Issue 1962563002: Fix ImageDecoder::frameIsCompleteAtIndex - fully received instead of decoded. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: ASSERT if frameCount not called to parse before calling... 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2010 Google Inc. All rights reserved. 2 * Copyright (C) 2010 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 121
122 namespace blink { 122 namespace blink {
123 123
124 WEBPImageDecoder::WEBPImageDecoder(AlphaOption alphaOption, GammaAndColorProfile Option colorOptions, size_t maxDecodedBytes) 124 WEBPImageDecoder::WEBPImageDecoder(AlphaOption alphaOption, GammaAndColorProfile Option colorOptions, size_t maxDecodedBytes)
125 : ImageDecoder(alphaOption, colorOptions, maxDecodedBytes) 125 : ImageDecoder(alphaOption, colorOptions, maxDecodedBytes)
126 , m_decoder(0) 126 , m_decoder(0)
127 , m_formatFlags(0) 127 , m_formatFlags(0)
128 , m_frameBackgroundHasAlpha(false) 128 , m_frameBackgroundHasAlpha(false)
129 , m_demux(0) 129 , m_demux(0)
130 , m_demuxState(WEBP_DEMUX_PARSING_HEADER) 130 , m_demuxState(WEBP_DEMUX_PARSING_HEADER)
131 , m_haveAlreadyParsedThisData(false)
132 , m_repetitionCount(cAnimationLoopOnce) 131 , m_repetitionCount(cAnimationLoopOnce)
133 , m_decodedHeight(0) 132 , m_decodedHeight(0)
134 { 133 {
135 m_blendFunction = (alphaOption == AlphaPremultiplied) ? alphaBlendPremultipl ied : alphaBlendNonPremultiplied; 134 m_blendFunction = (alphaOption == AlphaPremultiplied) ? alphaBlendPremultipl ied : alphaBlendNonPremultiplied;
136 } 135 }
137 136
138 WEBPImageDecoder::~WEBPImageDecoder() 137 WEBPImageDecoder::~WEBPImageDecoder()
139 { 138 {
140 clear(); 139 clear();
141 } 140 }
142 141
143 void WEBPImageDecoder::clear() 142 void WEBPImageDecoder::clear()
144 { 143 {
145 WebPDemuxDelete(m_demux); 144 WebPDemuxDelete(m_demux);
146 m_demux = 0; 145 m_demux = 0;
147 m_consolidatedData.clear(); 146 m_consolidatedData.clear();
148 clearDecoder(); 147 clearDecoder();
149 } 148 }
150 149
151 void WEBPImageDecoder::clearDecoder() 150 void WEBPImageDecoder::clearDecoder()
152 { 151 {
153 WebPIDelete(m_decoder); 152 WebPIDelete(m_decoder);
154 m_decoder = 0; 153 m_decoder = 0;
155 m_decodedHeight = 0; 154 m_decodedHeight = 0;
156 m_frameBackgroundHasAlpha = false; 155 m_frameBackgroundHasAlpha = false;
157 } 156 }
158 157
159 void WEBPImageDecoder::onSetData(SegmentReader*)
160 {
161 m_haveAlreadyParsedThisData = false;
162 }
163
164 int WEBPImageDecoder::repetitionCount() const 158 int WEBPImageDecoder::repetitionCount() const
165 { 159 {
166 return failed() ? cAnimationLoopOnce : m_repetitionCount; 160 return failed() ? cAnimationLoopOnce : m_repetitionCount;
167 } 161 }
168 162
169 bool WEBPImageDecoder::frameIsCompleteAtIndex(size_t index) const 163 bool WEBPImageDecoder::frameIsFullyReceivedAtIndex(size_t index) const
170 { 164 {
171 if (!m_demux || m_demuxState <= WEBP_DEMUX_PARSING_HEADER) 165 ASSERT(m_haveUpdatedFrameCount);
172 return false;
173 if (!(m_formatFlags & ANIMATION_FLAG)) 166 if (!(m_formatFlags & ANIMATION_FLAG))
174 return ImageDecoder::frameIsCompleteAtIndex(index); 167 return ImageDecoder::frameIsFullyReceivedAtIndex(index);
175 bool frameIsLoadedAtIndex = index < m_frameBufferCache.size(); 168
176 return frameIsLoadedAtIndex; 169 // Multi-frame WebP frame gets added to m_frameBufferCache through
170 // initializeNewFrame() only when the frame data is fully received.
171 return index < m_frameBufferCache.size();
177 } 172 }
178 173
179 float WEBPImageDecoder::frameDurationAtIndex(size_t index) const 174 float WEBPImageDecoder::frameDurationAtIndex(size_t index) const
180 { 175 {
181 return index < m_frameBufferCache.size() ? m_frameBufferCache[index].duratio n() : 0; 176 return index < m_frameBufferCache.size() ? m_frameBufferCache[index].duratio n() : 0;
182 } 177 }
183 178
184 bool WEBPImageDecoder::updateDemuxer() 179 bool WEBPImageDecoder::updateDemuxer()
185 { 180 {
186 if (failed()) 181 if (failed())
187 return false; 182 return false;
scroggo_chromium 2016/06/02 21:00:14 Don't you want to return if (haveUpdatedFrameCount
aleksandar.stojiljkovic 2016/06/03 19:33:57 Reverted this code - having ImageDecoder::haveUpda
188 183
189 if (m_haveAlreadyParsedThisData)
190 return true;
191
192 m_haveAlreadyParsedThisData = true;
193
194 const unsigned webpHeaderSize = 30; 184 const unsigned webpHeaderSize = 30;
195 if (m_data->size() < webpHeaderSize) 185 if (m_data->size() < webpHeaderSize)
196 return false; // Await VP8X header so WebPDemuxPartial succeeds. 186 return false; // Await VP8X header so WebPDemuxPartial succeeds.
197 187
198 WebPDemuxDelete(m_demux); 188 WebPDemuxDelete(m_demux);
199 m_consolidatedData = m_data->getAsSkData(); 189 m_consolidatedData = m_data->getAsSkData();
200 WebPData inputData = { reinterpret_cast<const uint8_t*>(m_consolidatedData-> data()), m_consolidatedData->size() }; 190 WebPData inputData = { reinterpret_cast<const uint8_t*>(m_consolidatedData-> data()), m_consolidatedData->size() };
201 m_demux = WebPDemuxPartial(&inputData, &m_demuxState); 191 m_demux = WebPDemuxPartial(&inputData, &m_demuxState);
202 if (!m_demux || (isAllDataReceived() && m_demuxState != WEBP_DEMUX_DONE)) { 192 if (!m_demux || (isAllDataReceived() && m_demuxState != WEBP_DEMUX_DONE)) {
203 if (!m_demux) 193 if (!m_demux)
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
505 return false; 495 return false;
506 } 496 }
507 // FALLTHROUGH 497 // FALLTHROUGH
508 default: 498 default:
509 clear(); 499 clear();
510 return setFailed(); 500 return setFailed();
511 } 501 }
512 } 502 }
513 503
514 } // namespace blink 504 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698