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

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: Forgot to add SkSampler.cpp Created 5 years, 2 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 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 151
152 // As stated below, libwebp snaps to even left and top. Make sure top and le ft are even, so we 152 // As stated below, libwebp snaps to even left and top. Make sure top and le ft are even, so we
153 // decode this exact subset. 153 // decode this exact subset.
154 // Leave right and bottom unmodified, so we suggest a slightly larger subset than requested. 154 // Leave right and bottom unmodified, so we suggest a slightly larger subset than requested.
155 desiredSubset->fLeft = (desiredSubset->fLeft >> 1) << 1; 155 desiredSubset->fLeft = (desiredSubset->fLeft >> 1) << 1;
156 desiredSubset->fTop = (desiredSubset->fTop >> 1) << 1; 156 desiredSubset->fTop = (desiredSubset->fTop >> 1) << 1;
157 return true; 157 return true;
158 } 158 }
159 159
160 SkCodec::Result SkWebpCodec::onGetPixels(const SkImageInfo& dstInfo, void* dst, size_t rowBytes, 160 SkCodec::Result SkWebpCodec::onGetPixels(const SkImageInfo& dstInfo, void* dst, size_t rowBytes,
161 const Options& options, SkPMColor*, int *) { 161 const Options& options, SkPMColor*, int *,
162 int* rowsDecoded) {
162 if (!webp_conversion_possible(dstInfo, this->getInfo())) { 163 if (!webp_conversion_possible(dstInfo, this->getInfo())) {
163 return kInvalidConversion; 164 return kInvalidConversion;
164 } 165 }
165 166
166 WebPDecoderConfig config; 167 WebPDecoderConfig config;
167 if (0 == WebPInitDecoderConfig(&config)) { 168 if (0 == WebPInitDecoderConfig(&config)) {
168 // ABI mismatch. 169 // ABI mismatch.
169 // FIXME: New enum for this? 170 // FIXME: New enum for this?
170 return kInvalidInput; 171 return kInvalidInput;
171 } 172 }
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 config.options.crop_height = bounds.height(); 210 config.options.crop_height = bounds.height();
210 } 211 }
211 212
212 SkISize dstDimensions = dstInfo.dimensions(); 213 SkISize dstDimensions = dstInfo.dimensions();
213 if (bounds.size() != dstDimensions) { 214 if (bounds.size() != dstDimensions) {
214 // Caller is requesting scaling. 215 // Caller is requesting scaling.
215 config.options.use_scaling = 1; 216 config.options.use_scaling = 1;
216 config.options.scaled_width = dstDimensions.width(); 217 config.options.scaled_width = dstDimensions.width();
217 config.options.scaled_height = dstDimensions.height(); 218 config.options.scaled_height = dstDimensions.height();
218 } 219 }
220 fDstWidth = dstDimensions.width();
219 221
220 config.output.colorspace = webp_decode_mode(dstInfo.colorType(), 222 config.output.colorspace = webp_decode_mode(dstInfo.colorType(),
221 dstInfo.alphaType() == kPremul_SkAlphaType); 223 dstInfo.alphaType() == kPremul_SkAlphaType);
222 config.output.u.RGBA.rgba = (uint8_t*) dst; 224 config.output.u.RGBA.rgba = (uint8_t*) dst;
223 config.output.u.RGBA.stride = (int) rowBytes; 225 config.output.u.RGBA.stride = (int) rowBytes;
224 config.output.u.RGBA.size = dstInfo.getSafeSize(rowBytes); 226 config.output.u.RGBA.size = dstInfo.getSafeSize(rowBytes);
225 config.output.is_external_memory = 1; 227 config.output.is_external_memory = 1;
226 228
227 SkAutoTCallVProc<WebPIDecoder, WebPIDelete> idec(WebPIDecode(nullptr, 0, &co nfig)); 229 SkAutoTCallVProc<WebPIDecoder, WebPIDelete> idec(WebPIDecode(nullptr, 0, &co nfig));
228 if (!idec) { 230 if (!idec) {
229 return kInvalidInput; 231 return kInvalidInput;
230 } 232 }
231 233
232 SkAutoMalloc storage(BUFFER_SIZE); 234 SkAutoMalloc storage(BUFFER_SIZE);
233 uint8_t* buffer = static_cast<uint8_t*>(storage.get()); 235 uint8_t* buffer = static_cast<uint8_t*>(storage.get());
234 while (true) { 236 while (true) {
235 const size_t bytesRead = stream()->read(buffer, BUFFER_SIZE); 237 const size_t bytesRead = stream()->read(buffer, BUFFER_SIZE);
236 if (0 == bytesRead) { 238 if (0 == bytesRead) {
237 // FIXME: Maybe this is an incomplete image? How to decide? Based 239 WebPIDecGetRGB(idec, rowsDecoded, NULL, NULL, NULL);
238 // on the number of rows decoded? We can know the number of rows 240 return kIncompleteInput;
239 // decoded using WebPIDecGetRGB.
240 return kInvalidInput;
241 } 241 }
242 242
243 switch (WebPIAppend(idec, buffer, bytesRead)) { 243 switch (WebPIAppend(idec, buffer, bytesRead)) {
244 case VP8_STATUS_OK: 244 case VP8_STATUS_OK:
245 return kSuccess; 245 return kSuccess;
246 case VP8_STATUS_SUSPENDED: 246 case VP8_STATUS_SUSPENDED:
247 // Break out of the switch statement. Continue the loop. 247 // Break out of the switch statement. Continue the loop.
248 break; 248 break;
249 default: 249 default:
250 return kInvalidInput; 250 return kInvalidInput;
251 } 251 }
252 } 252 }
253 } 253 }
254 254
255 SkWebpCodec::SkWebpCodec(const SkImageInfo& info, SkStream* stream) 255 SkWebpCodec::SkWebpCodec(const SkImageInfo& info, SkStream* stream)
256 : INHERITED(info, stream) {} 256 : INHERITED(info, stream)
257 , fDstWidth(info.width())
258 {}
259
260 class SkWebpSampler : public SkSampler {
261 public:
262 SkWebpSampler(SkWebpCodec* codec)
263 : fCodec(codec)
264 {
265 SkASSERT(fCodec);
266 }
267
268 private:
269 // We not support sampling of webps. Webps support arbitrary native scaling .
270 int onSetSampleX(int sampleX) {
271 SkASSERT(false);
272 return fCodec->fDstWidth;
273 }
274
275
276 int onGetScaledWidth() override {
277 return fCodec->fDstWidth;
278 }
279
280 // Unowned pointer. fCodec will delete this class in its destructor.
281 SkWebpCodec* fCodec;
282 };
283
284 SkSampler* SkWebpCodec::getSampler() {
285 if (!fSampler) {
286 fSampler.reset(new SkWebpSampler(this));
287 }
288
289 return fSampler;
290 }
OLDNEW
« src/codec/SkWebpCodec.h ('K') | « src/codec/SkWebpCodec.h ('k') | tests/CodexTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698