• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2015 Google Inc.
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 
8 #include "src/codec/SkWebpCodec.h"
9 
10 #include "include/codec/SkCodec.h"
11 #include "include/codec/SkCodecAnimation.h"
12 #include "include/core/SkAlphaType.h"
13 #include "include/core/SkBitmap.h"
14 #include "include/core/SkColorType.h"
15 #include "include/core/SkImageInfo.h"
16 #include "include/core/SkRect.h"
17 #include "include/core/SkSize.h"
18 #include "include/core/SkStream.h"
19 #include "include/private/base/SkAlign.h"
20 #include "include/private/base/SkMath.h"
21 #include "include/private/base/SkTFitsIn.h"
22 #include "include/private/base/SkTemplates.h"
23 #include "include/private/base/SkTo.h"
24 #include "modules/skcms/skcms.h"
25 #include "src/codec/SkParseEncodedOrigin.h"
26 #include "src/codec/SkSampler.h"
27 #include "src/core/SkRasterPipeline.h"
28 #include "src/core/SkRasterPipelineOpContexts.h"
29 #include "src/core/SkRasterPipelineOpList.h"
30 #include "src/core/SkStreamPriv.h"
31 
32 #include <algorithm>
33 #include <cstdint>
34 #include <cstring>
35 #include <utility>
36 
37 // A WebP decoder on top of (subset of) libwebp
38 // For more information on WebP image format, and libwebp library, see:
39 //   https://code.google.com/speed/webp/
40 //   http://www.webmproject.org/code/#libwebp-webp-image-library
41 //   https://chromium.googlesource.com/webm/libwebp
42 
43 // If moving libwebp out of skia source tree, path for webp headers must be
44 // updated accordingly. Here, we enforce using local copy in webp sub-directory.
45 #include "webp/decode.h"
46 #include "webp/demux.h"
47 #include "webp/mux_types.h"
48 
IsWebp(const void * buf,size_t bytesRead)49 bool SkWebpCodec::IsWebp(const void* buf, size_t bytesRead) {
50     // WEBP starts with the following:
51     // RIFFXXXXWEBPVP
52     // Where XXXX is unspecified.
53     const char* bytes = static_cast<const char*>(buf);
54     return bytesRead >= 14 && !memcmp(bytes, "RIFF", 4) && !memcmp(&bytes[8], "WEBPVP", 6);
55 }
56 
57 // Parse headers of RIFF container, and check for valid Webp (VP8) content.
58 // Returns an SkWebpCodec on success
MakeFromStream(std::unique_ptr<SkStream> stream,Result * result)59 std::unique_ptr<SkCodec> SkWebpCodec::MakeFromStream(std::unique_ptr<SkStream> stream,
60                                                      Result* result) {
61     // Webp demux needs a contiguous data buffer.
62     sk_sp<SkData> data = nullptr;
63     if (stream->getMemoryBase()) {
64         // It is safe to make without copy because we'll hold onto the stream.
65         data = SkData::MakeWithoutCopy(stream->getMemoryBase(), stream->getLength());
66     } else {
67         data = SkCopyStreamToData(stream.get());
68 
69         // If we are forced to copy the stream to a data, we can go ahead and delete the stream.
70         stream.reset(nullptr);
71     }
72 
73     // It's a little strange that the |demux| will outlive |webpData|, though it needs the
74     // pointer in |webpData| to remain valid.  This works because the pointer remains valid
75     // until the SkData is freed.
76     WebPData webpData = { data->bytes(), data->size() };
77     WebPDemuxState state;
78     SkAutoTCallVProc<WebPDemuxer, WebPDemuxDelete> demux(WebPDemuxPartial(&webpData, &state));
79     switch (state) {
80         case WEBP_DEMUX_PARSE_ERROR:
81             *result = kInvalidInput;
82             return nullptr;
83         case WEBP_DEMUX_PARSING_HEADER:
84             *result = kIncompleteInput;
85             return nullptr;
86         case WEBP_DEMUX_PARSED_HEADER:
87         case WEBP_DEMUX_DONE:
88             SkASSERT(demux);
89             break;
90     }
91 
92     const int width = WebPDemuxGetI(demux, WEBP_FF_CANVAS_WIDTH);
93     const int height = WebPDemuxGetI(demux, WEBP_FF_CANVAS_HEIGHT);
94 
95     // Validate the image size that's about to be decoded.
96     {
97         const int64_t size = sk_64_mul(width, height);
98         // now check that if we are 4-bytes per pixel, we also don't overflow
99         if (!SkTFitsIn<int32_t>(size) || SkTo<int32_t>(size) > (0x7FFFFFFF >> 2)) {
100             *result = kInvalidInput;
101             return nullptr;
102         }
103     }
104 
105     std::unique_ptr<SkEncodedInfo::ICCProfile> profile = nullptr;
106     {
107         WebPChunkIterator chunkIterator;
108         SkAutoTCallVProc<WebPChunkIterator, WebPDemuxReleaseChunkIterator> autoCI(&chunkIterator);
109         if (WebPDemuxGetChunk(demux, "ICCP", 1, &chunkIterator)) {
110             // FIXME: I think this could be MakeWithoutCopy
111             auto chunk = SkData::MakeWithCopy(chunkIterator.chunk.bytes, chunkIterator.chunk.size);
112             profile = SkEncodedInfo::ICCProfile::Make(std::move(chunk));
113         }
114         if (profile && profile->profile()->data_color_space != skcms_Signature_RGB) {
115             profile = nullptr;
116         }
117     }
118 
119     SkEncodedOrigin origin = kDefault_SkEncodedOrigin;
120     {
121         WebPChunkIterator chunkIterator;
122         SkAutoTCallVProc<WebPChunkIterator, WebPDemuxReleaseChunkIterator> autoCI(&chunkIterator);
123         if (WebPDemuxGetChunk(demux, "EXIF", 1, &chunkIterator)) {
124             SkParseEncodedOrigin(chunkIterator.chunk.bytes, chunkIterator.chunk.size, &origin);
125         }
126     }
127 
128     // Get the first frame and its "features" to determine the color and alpha types.
129     WebPIterator frame;
130     SkAutoTCallVProc<WebPIterator, WebPDemuxReleaseIterator> autoFrame(&frame);
131     if (!WebPDemuxGetFrame(demux, 1, &frame)) {
132         *result = kIncompleteInput;
133         return nullptr;
134     }
135 
136     WebPBitstreamFeatures features;
137     switch (WebPGetFeatures(frame.fragment.bytes, frame.fragment.size, &features)) {
138         case VP8_STATUS_OK:
139             break;
140         case VP8_STATUS_SUSPENDED:
141         case VP8_STATUS_NOT_ENOUGH_DATA:
142             *result = kIncompleteInput;
143             return nullptr;
144         default:
145             *result = kInvalidInput;
146             return nullptr;
147     }
148 
149     const bool hasAlpha = SkToBool(frame.has_alpha)
150             || frame.width != width || frame.height != height;
151     SkEncodedInfo::Color color;
152     SkEncodedInfo::Alpha alpha;
153     switch (features.format) {
154         case 0:
155             // This indicates a "mixed" format.  We could see this for
156             // animated webps (multiple fragments).
157             // We could also guess kYUV here, but I think it makes more
158             // sense to guess kBGRA which is likely closer to the final
159             // output.  Otherwise, we might end up converting
160             // BGRA->YUVA->BGRA.
161             [[fallthrough]];
162         case 2:
163             // This is the lossless format (BGRA).
164             if (hasAlpha) {
165                 color = SkEncodedInfo::kBGRA_Color;
166                 alpha = SkEncodedInfo::kUnpremul_Alpha;
167             } else {
168                 color = SkEncodedInfo::kBGRX_Color;
169                 alpha = SkEncodedInfo::kOpaque_Alpha;
170             }
171             break;
172         case 1:
173             // This is the lossy format (YUV).
174             if (hasAlpha) {
175                 color = SkEncodedInfo::kYUVA_Color;
176                 alpha = SkEncodedInfo::kUnpremul_Alpha;
177             } else {
178                 color = SkEncodedInfo::kYUV_Color;
179                 alpha = SkEncodedInfo::kOpaque_Alpha;
180             }
181             break;
182         default:
183             *result = kInvalidInput;
184             return nullptr;
185     }
186 
187 
188     *result = kSuccess;
189     SkEncodedInfo info = SkEncodedInfo::Make(width, height, color, alpha, 8, std::move(profile));
190     return std::unique_ptr<SkCodec>(new SkWebpCodec(std::move(info), std::move(stream),
191                                                     demux.release(), std::move(data), origin));
192 }
193 
webp_decode_mode(SkColorType dstCT,bool premultiply)194 static WEBP_CSP_MODE webp_decode_mode(SkColorType dstCT, bool premultiply) {
195     switch (dstCT) {
196         case kBGRA_8888_SkColorType:
197             return premultiply ? MODE_bgrA : MODE_BGRA;
198         case kRGBA_8888_SkColorType:
199             return premultiply ? MODE_rgbA : MODE_RGBA;
200         case kRGB_565_SkColorType:
201             return MODE_RGB_565;
202         default:
203             return MODE_LAST;
204     }
205 }
206 
appendNewFrame(bool hasAlpha)207 SkWebpCodec::Frame* SkWebpCodec::FrameHolder::appendNewFrame(bool hasAlpha) {
208     const int i = this->size();
209     fFrames.emplace_back(i, hasAlpha ? SkEncodedInfo::kUnpremul_Alpha
210                                      : SkEncodedInfo::kOpaque_Alpha);
211     return &fFrames[i];
212 }
213 
onGetValidSubset(SkIRect * desiredSubset) const214 bool SkWebpCodec::onGetValidSubset(SkIRect* desiredSubset) const {
215     if (!desiredSubset) {
216         return false;
217     }
218 
219     if (!this->bounds().contains(*desiredSubset)) {
220         return false;
221     }
222 
223     // As stated below, libwebp snaps to even left and top. Make sure top and left are even, so we
224     // decode this exact subset.
225     // Leave right and bottom unmodified, so we suggest a slightly larger subset than requested.
226     desiredSubset->fLeft = (desiredSubset->fLeft >> 1) << 1;
227     desiredSubset->fTop = (desiredSubset->fTop >> 1) << 1;
228     return true;
229 }
230 
onGetRepetitionCount()231 int SkWebpCodec::onGetRepetitionCount() {
232     auto flags = WebPDemuxGetI(fDemux.get(), WEBP_FF_FORMAT_FLAGS);
233     if (!(flags & ANIMATION_FLAG)) {
234         return 0;
235     }
236 
237     int loopCount = WebPDemuxGetI(fDemux.get(), WEBP_FF_LOOP_COUNT);
238     if (0 == loopCount) {
239         return kRepetitionCountInfinite;
240     }
241 
242     loopCount--;
243     return loopCount;
244 }
245 
onGetFrameCount()246 int SkWebpCodec::onGetFrameCount() {
247     auto flags = WebPDemuxGetI(fDemux.get(), WEBP_FF_FORMAT_FLAGS);
248     if (!(flags & ANIMATION_FLAG)) {
249         return 1;
250     }
251 
252     const uint32_t oldFrameCount = fFrameHolder.size();
253     if (fFailed) {
254         return oldFrameCount;
255     }
256 
257     const uint32_t frameCount = WebPDemuxGetI(fDemux, WEBP_FF_FRAME_COUNT);
258     if (oldFrameCount == frameCount) {
259         // We have already parsed this.
260         return frameCount;
261     }
262 
263     fFrameHolder.reserve(frameCount);
264 
265     for (uint32_t i = oldFrameCount; i < frameCount; i++) {
266         WebPIterator iter;
267         SkAutoTCallVProc<WebPIterator, WebPDemuxReleaseIterator> autoIter(&iter);
268 
269         if (!WebPDemuxGetFrame(fDemux.get(), i + 1, &iter)) {
270             fFailed = true;
271             break;
272         }
273 
274         // libwebp only reports complete frames of an animated image.
275         SkASSERT(iter.complete);
276 
277         Frame* frame = fFrameHolder.appendNewFrame(iter.has_alpha);
278         frame->setXYWH(iter.x_offset, iter.y_offset, iter.width, iter.height);
279         frame->setDisposalMethod(iter.dispose_method == WEBP_MUX_DISPOSE_BACKGROUND ?
280                 SkCodecAnimation::DisposalMethod::kRestoreBGColor :
281                 SkCodecAnimation::DisposalMethod::kKeep);
282         frame->setDuration(iter.duration);
283         if (WEBP_MUX_BLEND != iter.blend_method) {
284             frame->setBlend(SkCodecAnimation::Blend::kSrc);
285         }
286         fFrameHolder.setAlphaAndRequiredFrame(frame);
287     }
288 
289     return fFrameHolder.size();
290 
291 }
292 
onGetFrame(int i) const293 const SkFrame* SkWebpCodec::FrameHolder::onGetFrame(int i) const {
294     return static_cast<const SkFrame*>(this->frame(i));
295 }
296 
frame(int i) const297 const SkWebpCodec::Frame* SkWebpCodec::FrameHolder::frame(int i) const {
298     SkASSERT(i >= 0 && i < this->size());
299     return &fFrames[i];
300 }
301 
onGetFrameInfo(int i,FrameInfo * frameInfo) const302 bool SkWebpCodec::onGetFrameInfo(int i, FrameInfo* frameInfo) const {
303     if (i >= fFrameHolder.size()) {
304         return false;
305     }
306 
307     const Frame* frame = fFrameHolder.frame(i);
308     if (!frame) {
309         return false;
310     }
311 
312     if (frameInfo) {
313         // libwebp only reports fully received frames for an
314         // animated image.
315         frame->fillIn(frameInfo, true);
316     }
317 
318     return true;
319 }
320 
is_8888(SkColorType colorType)321 static bool is_8888(SkColorType colorType) {
322     switch (colorType) {
323         case kRGBA_8888_SkColorType:
324         case kBGRA_8888_SkColorType:
325             return true;
326         default:
327             return false;
328     }
329 }
330 
331 // Requires that the src input be unpremultiplied (or opaque).
blend_line(SkColorType dstCT,void * dst,SkColorType srcCT,const void * src,SkAlphaType dstAt,bool srcHasAlpha,int width)332 static void blend_line(SkColorType dstCT, void* dst,
333                        SkColorType srcCT, const void* src,
334                        SkAlphaType dstAt,
335                        bool srcHasAlpha,
336                        int width) {
337     SkRasterPipeline_MemoryCtx dst_ctx = { (void*)dst, 0 },
338                                src_ctx = { (void*)src, 0 };
339 
340     SkRasterPipeline_<256> p;
341 
342     p.append_load_dst(dstCT, &dst_ctx);
343     if (kUnpremul_SkAlphaType == dstAt) {
344         p.append(SkRasterPipelineOp::premul_dst);
345     }
346 
347     p.append_load(srcCT, &src_ctx);
348     if (srcHasAlpha) {
349         p.append(SkRasterPipelineOp::premul);
350     }
351 
352     p.append(SkRasterPipelineOp::srcover);
353 
354     if (kUnpremul_SkAlphaType == dstAt) {
355         p.append(SkRasterPipelineOp::unpremul);
356     }
357     p.append_store(dstCT, &dst_ctx);
358 
359     p.run(0,0, width,1);
360 }
361 
onGetPixels(const SkImageInfo & dstInfo,void * dst,size_t rowBytes,const Options & options,int * rowsDecodedPtr)362 SkCodec::Result SkWebpCodec::onGetPixels(const SkImageInfo& dstInfo, void* dst, size_t rowBytes,
363                                          const Options& options, int* rowsDecodedPtr) {
364     const int index = options.fFrameIndex;
365     SkASSERT(0 == index || index < fFrameHolder.size());
366     SkASSERT(0 == index || !options.fSubset);
367 
368     WebPDecoderConfig config;
369     if (0 == WebPInitDecoderConfig(&config)) {
370         // ABI mismatch.
371         // FIXME: New enum for this?
372         return kInvalidInput;
373     }
374 
375     // Free any memory associated with the buffer. Must be called last, so we declare it first.
376     SkAutoTCallVProc<WebPDecBuffer, WebPFreeDecBuffer> autoFree(&(config.output));
377 
378     WebPIterator frame;
379     SkAutoTCallVProc<WebPIterator, WebPDemuxReleaseIterator> autoFrame(&frame);
380     // If this succeeded in onGetFrameCount(), it should succeed again here.
381     SkAssertResult(WebPDemuxGetFrame(fDemux, index + 1, &frame));
382 
383     const bool independent = index == 0 ? true :
384             (fFrameHolder.frame(index)->getRequiredFrame() == kNoFrame);
385     // Get the frameRect.  libwebp will have already signaled an error if this is not fully
386     // contained by the canvas.
387     auto frameRect = SkIRect::MakeXYWH(frame.x_offset, frame.y_offset, frame.width, frame.height);
388     SkASSERT(this->bounds().contains(frameRect));
389     const bool frameIsSubset = frameRect != this->bounds();
390     if (independent && frameIsSubset) {
391         SkSampler::Fill(dstInfo, dst, rowBytes, options.fZeroInitialized);
392     }
393 
394     int dstX = frameRect.x();
395     int dstY = frameRect.y();
396     int subsetWidth = frameRect.width();
397     int subsetHeight = frameRect.height();
398     if (options.fSubset) {
399         SkIRect subset = *options.fSubset;
400         SkASSERT(this->bounds().contains(subset));
401         SkASSERT(SkIsAlign2(subset.fLeft) && SkIsAlign2(subset.fTop));
402         SkASSERT(this->getValidSubset(&subset) && subset == *options.fSubset);
403 
404         if (!SkIRect::Intersects(subset, frameRect)) {
405             return kSuccess;
406         }
407 
408         int minXOffset = std::min(dstX, subset.x());
409         int minYOffset = std::min(dstY, subset.y());
410         dstX -= minXOffset;
411         dstY -= minYOffset;
412         frameRect.offset(-minXOffset, -minYOffset);
413         subset.offset(-minXOffset, -minYOffset);
414 
415         // Just like we require that the requested subset x and y offset are even, libwebp
416         // guarantees that the frame x and y offset are even (it's actually impossible to specify
417         // an odd frame offset).  So we can still guarantee that the adjusted offsets are even.
418         SkASSERT(SkIsAlign2(subset.fLeft) && SkIsAlign2(subset.fTop));
419 
420         SkIRect intersection;
421         SkAssertResult(intersection.intersect(frameRect, subset));
422         subsetWidth = intersection.width();
423         subsetHeight = intersection.height();
424 
425         config.options.use_cropping = 1;
426         config.options.crop_left = subset.x();
427         config.options.crop_top = subset.y();
428         config.options.crop_width = subsetWidth;
429         config.options.crop_height = subsetHeight;
430     }
431 
432     // Ignore the frame size and offset when determining if scaling is necessary.
433     int scaledWidth = subsetWidth;
434     int scaledHeight = subsetHeight;
435     SkISize srcSize = options.fSubset ? options.fSubset->size() : this->dimensions();
436     if (srcSize != dstInfo.dimensions()) {
437         config.options.use_scaling = 1;
438 
439         if (frameIsSubset) {
440             float scaleX = ((float) dstInfo.width()) / srcSize.width();
441             float scaleY = ((float) dstInfo.height()) / srcSize.height();
442 
443             // We need to be conservative here and floor rather than round.
444             // Otherwise, we may find ourselves decoding off the end of memory.
445             dstX = scaleX * dstX;
446             scaledWidth = scaleX * scaledWidth;
447             dstY = scaleY * dstY;
448             scaledHeight = scaleY * scaledHeight;
449             if (0 == scaledWidth || 0 == scaledHeight) {
450                 return kSuccess;
451             }
452         } else {
453             scaledWidth = dstInfo.width();
454             scaledHeight = dstInfo.height();
455         }
456 
457         config.options.scaled_width = scaledWidth;
458         config.options.scaled_height = scaledHeight;
459     }
460 
461     const bool blendWithPrevFrame = !independent && frame.blend_method == WEBP_MUX_BLEND
462         && frame.has_alpha;
463 
464     auto webpInfo = dstInfo;
465     if (!frame.has_alpha) {
466         webpInfo = webpInfo.makeAlphaType(kOpaque_SkAlphaType);
467     } else if (this->colorXform() || blendWithPrevFrame) {
468         // the colorXform and blend_line expect unpremul.
469         webpInfo = webpInfo.makeAlphaType(kUnpremul_SkAlphaType);
470     }
471     if (this->colorXform()) {
472         // Swizzling between RGBA and BGRA is zero cost in a color transform.  So when we have a
473         // color transform, we should decode to whatever is easiest for libwebp, and then let the
474         // color transform swizzle if necessary.
475         // Lossy webp is encoded as YUV (so RGBA and BGRA are the same cost).  Lossless webp is
476         // encoded as BGRA. This means decoding to BGRA is either faster or the same cost as RGBA.
477         webpInfo = webpInfo.makeColorType(kBGRA_8888_SkColorType);
478     }
479 
480     SkBitmap webpDst;
481     if ((this->colorXform() && !is_8888(dstInfo.colorType())) || blendWithPrevFrame) {
482         // We will decode the entire image and then perform the color transform.  libwebp
483         // does not provide a row-by-row API.  This is a shame particularly when we do not want
484         // 8888, since we will need to create another image sized buffer.
485         webpDst.allocPixels(webpInfo);
486     } else {
487         // libwebp can decode directly into the output memory.
488         webpDst.installPixels(webpInfo, dst, rowBytes);
489     }
490 
491     config.output.colorspace = webp_decode_mode(webpInfo.colorType(),
492             webpInfo.alphaType() == kPremul_SkAlphaType);
493     config.output.is_external_memory = 1;
494 
495     config.output.u.RGBA.rgba = reinterpret_cast<uint8_t*>(webpDst.getAddr(dstX, dstY));
496     config.output.u.RGBA.stride = static_cast<int>(webpDst.rowBytes());
497     config.output.u.RGBA.size = webpDst.computeByteSize();
498 
499     SkAutoTCallVProc<WebPIDecoder, WebPIDelete> idec(WebPIDecode(nullptr, 0, &config));
500     if (!idec) {
501         return kInvalidInput;
502     }
503 
504     int rowsDecoded = 0;
505     SkCodec::Result result;
506     switch (WebPIUpdate(idec, frame.fragment.bytes, frame.fragment.size)) {
507         case VP8_STATUS_OK:
508             rowsDecoded = scaledHeight;
509             result = kSuccess;
510             break;
511         case VP8_STATUS_SUSPENDED:
512             if (!WebPIDecGetRGB(idec, &rowsDecoded, nullptr, nullptr, nullptr)
513                     || rowsDecoded <= 0) {
514                 return kInvalidInput;
515             }
516             *rowsDecodedPtr = rowsDecoded + dstY;
517             result = kIncompleteInput;
518             break;
519         default:
520             return kInvalidInput;
521     }
522 
523     const size_t dstBpp = dstInfo.bytesPerPixel();
524     dst = SkTAddOffset<void>(dst, dstBpp * dstX + rowBytes * dstY);
525     const size_t srcRowBytes = config.output.u.RGBA.stride;
526 
527     const auto dstCT = dstInfo.colorType();
528     if (this->colorXform()) {
529         uint32_t* xformSrc = (uint32_t*) config.output.u.RGBA.rgba;
530         SkBitmap tmp;
531         void* xformDst;
532 
533         if (blendWithPrevFrame) {
534             // Xform into temporary bitmap big enough for one row.
535             tmp.allocPixels(dstInfo.makeWH(scaledWidth, 1));
536             xformDst = tmp.getPixels();
537         } else {
538             xformDst = dst;
539         }
540 
541         for (int y = 0; y < rowsDecoded; y++) {
542             this->applyColorXform(xformDst, xformSrc, scaledWidth);
543             if (blendWithPrevFrame) {
544                 blend_line(dstCT, dst, dstCT, xformDst,
545                         dstInfo.alphaType(), frame.has_alpha, scaledWidth);
546                 dst = SkTAddOffset<void>(dst, rowBytes);
547             } else {
548                 xformDst = SkTAddOffset<void>(xformDst, rowBytes);
549             }
550             xformSrc = SkTAddOffset<uint32_t>(xformSrc, srcRowBytes);
551         }
552     } else if (blendWithPrevFrame) {
553         const uint8_t* src = config.output.u.RGBA.rgba;
554 
555         for (int y = 0; y < rowsDecoded; y++) {
556             blend_line(dstCT, dst, webpDst.colorType(), src,
557                     dstInfo.alphaType(), frame.has_alpha, scaledWidth);
558             src = SkTAddOffset<const uint8_t>(src, srcRowBytes);
559             dst = SkTAddOffset<void>(dst, rowBytes);
560         }
561     }
562 
563     return result;
564 }
565 
SkWebpCodec(SkEncodedInfo && info,std::unique_ptr<SkStream> stream,WebPDemuxer * demux,sk_sp<SkData> data,SkEncodedOrigin origin)566 SkWebpCodec::SkWebpCodec(SkEncodedInfo&& info, std::unique_ptr<SkStream> stream,
567                          WebPDemuxer* demux, sk_sp<SkData> data, SkEncodedOrigin origin)
568     : INHERITED(std::move(info), skcms_PixelFormat_BGRA_8888, std::move(stream),
569                 origin)
570     , fDemux(demux)
571     , fData(std::move(data))
572     , fFailed(false)
573 {
574     const auto& eInfo = this->getEncodedInfo();
575     fFrameHolder.setScreenSize(eInfo.width(), eInfo.height());
576 }
577