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

Side by Side Diff: src/codec/SkWebpCodec.cpp

Issue 1332053002: Fill incomplete images in SkCodec parent class (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Response to comments 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright 2015 Google Inc. 2 * Copyright 2015 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkCodecPriv.h" 8 #include "SkCodecPriv.h"
9 #include "SkWebpCodec.h" 9 #include "SkWebpCodec.h"
10 #include "SkTemplates.h" 10 #include "SkTemplates.h"
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 144
145 // As stated below, libwebp snaps to even left and top. Make sure top and le ft are even, so we 145 // As stated below, libwebp snaps to even left and top. Make sure top and le ft are even, so we
146 // decode this exact subset. 146 // decode this exact subset.
147 // Leave right and bottom unmodified, so we suggest a slightly larger subset than requested. 147 // Leave right and bottom unmodified, so we suggest a slightly larger subset than requested.
148 desiredSubset->fLeft = (desiredSubset->fLeft >> 1) << 1; 148 desiredSubset->fLeft = (desiredSubset->fLeft >> 1) << 1;
149 desiredSubset->fTop = (desiredSubset->fTop >> 1) << 1; 149 desiredSubset->fTop = (desiredSubset->fTop >> 1) << 1;
150 return true; 150 return true;
151 } 151 }
152 152
153 SkCodec::Result SkWebpCodec::onGetPixels(const SkImageInfo& dstInfo, void* dst, size_t rowBytes, 153 SkCodec::Result SkWebpCodec::onGetPixels(const SkImageInfo& dstInfo, void* dst, size_t rowBytes,
154 const Options& options, SkPMColor*, int *) { 154 const Options& options, SkPMColor*, int *,
155 int* incompleteScanlines) {
155 if (!this->rewindIfNeeded()) { 156 if (!this->rewindIfNeeded()) {
156 return kCouldNotRewind; 157 return kCouldNotRewind;
157 } 158 }
158 159
159 if (!webp_conversion_possible(dstInfo, this->getInfo())) { 160 if (!webp_conversion_possible(dstInfo, this->getInfo())) {
160 return kInvalidConversion; 161 return kInvalidConversion;
161 } 162 }
162 163
163 WebPDecoderConfig config; 164 WebPDecoderConfig config;
164 if (0 == WebPInitDecoderConfig(&config)) { 165 if (0 == WebPInitDecoderConfig(&config)) {
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 SkAutoTCallVProc<WebPIDecoder, WebPIDelete> idec(WebPIDecode(nullptr, 0, &co nfig)); 225 SkAutoTCallVProc<WebPIDecoder, WebPIDelete> idec(WebPIDecode(nullptr, 0, &co nfig));
225 if (!idec) { 226 if (!idec) {
226 return kInvalidInput; 227 return kInvalidInput;
227 } 228 }
228 229
229 SkAutoMalloc storage(BUFFER_SIZE); 230 SkAutoMalloc storage(BUFFER_SIZE);
230 uint8_t* buffer = static_cast<uint8_t*>(storage.get()); 231 uint8_t* buffer = static_cast<uint8_t*>(storage.get());
231 while (true) { 232 while (true) {
232 const size_t bytesRead = stream()->read(buffer, BUFFER_SIZE); 233 const size_t bytesRead = stream()->read(buffer, BUFFER_SIZE);
233 if (0 == bytesRead) { 234 if (0 == bytesRead) {
234 // FIXME: Maybe this is an incomplete image? How to decide? Based 235 int rowsDecoded;
235 // on the number of rows decoded? We can know the number of rows 236 WebPIDecGetRGB(idec, &rowsDecoded, NULL, NULL, NULL);
236 // decoded using WebPIDecGetRGB. 237 *incompleteScanlines = dstDimensions.height() - rowsDecoded;
237 return kInvalidInput; 238 return kIncompleteInput;
238 } 239 }
239 240
240 switch (WebPIAppend(idec, buffer, bytesRead)) { 241 switch (WebPIAppend(idec, buffer, bytesRead)) {
241 case VP8_STATUS_OK: 242 case VP8_STATUS_OK:
242 return kSuccess; 243 return kSuccess;
243 case VP8_STATUS_SUSPENDED: 244 case VP8_STATUS_SUSPENDED:
244 // Break out of the switch statement. Continue the loop. 245 // Break out of the switch statement. Continue the loop.
245 break; 246 break;
246 default: 247 default:
247 return kInvalidInput; 248 return kInvalidInput;
248 } 249 }
249 } 250 }
250 } 251 }
251 252
252 SkWebpCodec::SkWebpCodec(const SkImageInfo& info, SkStream* stream) 253 SkWebpCodec::SkWebpCodec(const SkImageInfo& info, SkStream* stream)
253 : INHERITED(info, stream) {} 254 : INHERITED(info, stream) {}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698