blob: 80125e44d11ef3a2473509a305ceb1aa7465ff8d [file] [log] [blame]
Leon Scroggins IIIe93ec682018-10-26 09:25:51 -04001/*
2 * Copyright 2018 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 "SkWuffsCodec.h"
9
10#include "../private/SkMalloc.h"
11#include "SkFrameHolder.h"
12#include "SkSampler.h"
Nigel Tao0185b952018-11-08 10:47:24 +110013#include "SkSwizzler.h"
14#include "SkUtils.h"
Nigel Taoa6766482019-01-07 13:41:53 +110015
16// Wuffs ships as a "single file C library" or "header file library" as per
17// https://github.com/nothings/stb/blob/master/docs/stb_howto.txt
18//
19// As we have not #define'd WUFFS_IMPLEMENTATION, the #include here is
20// including a header file, even though that file name ends in ".c".
21#include "wuffs-v0.2.c"
Nigel Tao91f96f82019-02-09 15:10:45 +110022#if WUFFS_VERSION_BUILD_METADATA_COMMIT_COUNT < 1605
Nigel Taoa6766482019-01-07 13:41:53 +110023#error "Wuffs version is too old. Upgrade to the latest version."
24#endif
Leon Scroggins IIIe93ec682018-10-26 09:25:51 -040025
26#define SK_WUFFS_CODEC_BUFFER_SIZE 4096
27
Leon Scroggins IIIe93ec682018-10-26 09:25:51 -040028static bool fill_buffer(wuffs_base__io_buffer* b, SkStream* s) {
29 b->compact();
30 size_t num_read = s->read(b->data.ptr + b->meta.wi, b->data.len - b->meta.wi);
31 b->meta.wi += num_read;
32 b->meta.closed = s->isAtEnd();
33 return num_read > 0;
34}
35
36static bool seek_buffer(wuffs_base__io_buffer* b, SkStream* s, uint64_t pos) {
37 // Try to re-position the io_buffer's meta.ri read-index first, which is
38 // cheaper than seeking in the backing SkStream.
39 if ((pos >= b->meta.pos) && (pos - b->meta.pos <= b->meta.wi)) {
40 b->meta.ri = pos - b->meta.pos;
41 return true;
42 }
43 // Seek in the backing SkStream.
44 if ((pos > SIZE_MAX) || (!s->seek(pos))) {
45 return false;
46 }
47 b->meta.wi = 0;
48 b->meta.ri = 0;
49 b->meta.pos = pos;
50 b->meta.closed = false;
51 return true;
52}
53
54static SkEncodedInfo::Alpha wuffs_blend_to_skia_alpha(wuffs_base__animation_blend w) {
55 return (w == WUFFS_BASE__ANIMATION_BLEND__OPAQUE) ? SkEncodedInfo::kOpaque_Alpha
56 : SkEncodedInfo::kUnpremul_Alpha;
57}
58
59static SkCodecAnimation::Blend wuffs_blend_to_skia_blend(wuffs_base__animation_blend w) {
60 return (w == WUFFS_BASE__ANIMATION_BLEND__SRC) ? SkCodecAnimation::Blend::kBG
61 : SkCodecAnimation::Blend::kPriorFrame;
62}
63
64static SkCodecAnimation::DisposalMethod wuffs_disposal_to_skia_disposal(
65 wuffs_base__animation_disposal w) {
66 switch (w) {
67 case WUFFS_BASE__ANIMATION_DISPOSAL__RESTORE_BACKGROUND:
68 return SkCodecAnimation::DisposalMethod::kRestoreBGColor;
69 case WUFFS_BASE__ANIMATION_DISPOSAL__RESTORE_PREVIOUS:
70 return SkCodecAnimation::DisposalMethod::kRestorePrevious;
71 default:
72 return SkCodecAnimation::DisposalMethod::kKeep;
73 }
74}
75
76// -------------------------------- Class definitions
77
78class SkWuffsCodec;
79
80class SkWuffsFrame final : public SkFrame {
81public:
82 SkWuffsFrame(wuffs_base__frame_config* fc);
83
84 SkCodec::FrameInfo frameInfo(bool fullyReceived) const;
85 uint64_t ioPosition() const;
86
87 // SkFrame overrides.
88 SkEncodedInfo::Alpha onReportedAlpha() const override;
89
90private:
91 uint64_t fIOPosition;
92 SkEncodedInfo::Alpha fReportedAlpha;
93
94 typedef SkFrame INHERITED;
95};
96
97// SkWuffsFrameHolder is a trivial indirector that forwards its calls onto a
98// SkWuffsCodec. It is a separate class as SkWuffsCodec would otherwise
99// inherit from both SkCodec and SkFrameHolder, and Skia style discourages
100// multiple inheritance (e.g. with its "typedef Foo INHERITED" convention).
101class SkWuffsFrameHolder final : public SkFrameHolder {
102public:
103 SkWuffsFrameHolder() : INHERITED() {}
104
105 void init(SkWuffsCodec* codec, int width, int height);
106
107 // SkFrameHolder overrides.
108 const SkFrame* onGetFrame(int i) const override;
109
110private:
111 const SkWuffsCodec* fCodec;
112
113 typedef SkFrameHolder INHERITED;
114};
115
Nigel Tao0185b952018-11-08 10:47:24 +1100116// SkWuffsSpySampler is a placeholder SkSampler implementation. The Skia API
117// expects to manipulate the codec's sampler (i.e. call setSampleX and
118// setSampleY) in between the startIncrementalDecode (SID) and
119// incrementalDecode (ID) calls. But creating the SkSwizzler (the real sampler)
120// requires knowing the destination buffer's dimensions, i.e. the animation
121// frame's width and height. That width and height are decoded in ID, not SID.
122//
123// To break that circle, the SkWuffsSpySampler always exists, so its methods
124// can be called between SID and ID. It doesn't actually do any sampling, it
125// merely records the arguments given to setSampleX (explicitly) and setSampleY
126// (implicitly, via the superclass' implementation). Inside ID, those recorded
127// arguments are forwarded on to the SkSwizzler (the real sampler) when that
128// SkSwizzler is created, after the frame width and height are known.
129//
130// Roughly speaking, the SkWuffsSpySampler is an eager proxy for the lazily
131// constructed real sampler. But that laziness is out of necessity.
132//
133// The "Spy" name is because it records its arguments. See
134// https://martinfowler.com/articles/mocksArentStubs.html#TheDifferenceBetweenMocksAndStubs
135class SkWuffsSpySampler final : public SkSampler {
136public:
137 SkWuffsSpySampler(int imageWidth)
138 : INHERITED(), fFillWidth(0), fImageWidth(imageWidth), fSampleX(1) {}
139
140 void reset();
141 int sampleX() const;
142
143 int fFillWidth;
144
145private:
146 // SkSampler overrides.
147 int fillWidth() const override;
148 int onSetSampleX(int sampleX) override;
149
150 const int fImageWidth;
151
152 int fSampleX;
153
154 typedef SkSampler INHERITED;
155};
156
Leon Scroggins IIIe93ec682018-10-26 09:25:51 -0400157class SkWuffsCodec final : public SkCodec {
158public:
159 SkWuffsCodec(SkEncodedInfo&& encodedInfo,
160 std::unique_ptr<SkStream> stream,
161 std::unique_ptr<wuffs_gif__decoder, decltype(&sk_free)> dec,
162 std::unique_ptr<uint8_t, decltype(&sk_free)> pixbuf_ptr,
163 std::unique_ptr<uint8_t, decltype(&sk_free)> workbuf_ptr,
164 size_t workbuf_len,
165 wuffs_base__image_config imgcfg,
166 wuffs_base__pixel_buffer pixbuf,
167 wuffs_base__io_buffer iobuf);
168
169 const SkWuffsFrame* frame(int i) const;
170
171private:
172 // SkCodec overrides.
173 SkEncodedImageFormat onGetEncodedFormat() const override;
174 Result onGetPixels(const SkImageInfo&, void*, size_t, const Options&, int*) override;
175 const SkFrameHolder* getFrameHolder() const override;
176 Result onStartIncrementalDecode(const SkImageInfo& dstInfo,
177 void* dst,
178 size_t rowBytes,
179 const SkCodec::Options& options) override;
180 Result onIncrementalDecode(int* rowsDecoded) override;
181 int onGetFrameCount() override;
182 bool onGetFrameInfo(int, FrameInfo*) const override;
183 int onGetRepetitionCount() override;
Nigel Tao0185b952018-11-08 10:47:24 +1100184 SkSampler* getSampler(bool createIfNecessary) override;
Leon Scroggins III9b0ba2c2018-11-19 14:52:37 -0500185 bool conversionSupported(const SkImageInfo& dst, bool, bool) override;
Leon Scroggins IIIe93ec682018-10-26 09:25:51 -0400186
187 void readFrames();
188 Result seekFrame(int frameIndex);
189
190 Result resetDecoder();
191 const char* decodeFrameConfig();
192 const char* decodeFrame();
193 void updateNumFullyReceivedFrames();
194
Nigel Tao0185b952018-11-08 10:47:24 +1100195 SkWuffsSpySampler fSpySampler;
Leon Scroggins IIIe93ec682018-10-26 09:25:51 -0400196 SkWuffsFrameHolder fFrameHolder;
197 std::unique_ptr<SkStream> fStream;
198 std::unique_ptr<wuffs_gif__decoder, decltype(&sk_free)> fDecoder;
199 std::unique_ptr<uint8_t, decltype(&sk_free)> fPixbufPtr;
200 std::unique_ptr<uint8_t, decltype(&sk_free)> fWorkbufPtr;
201 size_t fWorkbufLen;
202
203 const uint64_t fFirstFrameIOPosition;
204 wuffs_base__frame_config fFrameConfig;
205 wuffs_base__pixel_buffer fPixelBuffer;
206 wuffs_base__io_buffer fIOBuffer;
207
208 // Incremental decoding state.
Nigel Tao0185b952018-11-08 10:47:24 +1100209 uint8_t* fIncrDecDst;
Nigel Tao0185b952018-11-08 10:47:24 +1100210 size_t fIncrDecRowBytes;
211
212 std::unique_ptr<SkSwizzler> fSwizzler;
Nigel Tao9859ef82019-02-13 13:20:02 +1100213 int fScaledHeight;
Leon Scroggins IIIe93ec682018-10-26 09:25:51 -0400214
215 uint64_t fNumFullyReceivedFrames;
216 std::vector<SkWuffsFrame> fFrames;
217 bool fFramesComplete;
218
219 // If calling an fDecoder method returns an incomplete status, then
220 // fDecoder is suspended in a coroutine (i.e. waiting on I/O or halted on a
221 // non-recoverable error). To keep its internal proof-of-safety invariants
222 // consistent, there's only two things you can safely do with a suspended
223 // Wuffs object: resume the coroutine, or reset all state (memset to zero
224 // and start again).
225 //
226 // If fDecoderIsSuspended, and we aren't sure that we're going to resume
227 // the coroutine, then we will need to call this->resetDecoder before
228 // calling other fDecoder methods.
229 bool fDecoderIsSuspended;
230
231 uint8_t fBuffer[SK_WUFFS_CODEC_BUFFER_SIZE];
232
233 typedef SkCodec INHERITED;
234};
235
236// -------------------------------- SkWuffsFrame implementation
237
238SkWuffsFrame::SkWuffsFrame(wuffs_base__frame_config* fc)
239 : INHERITED(fc->index()),
240 fIOPosition(fc->io_position()),
241 fReportedAlpha(wuffs_blend_to_skia_alpha(fc->blend())) {
242 wuffs_base__rect_ie_u32 r = fc->bounds();
243 this->setXYWH(r.min_incl_x, r.min_incl_y, r.width(), r.height());
244 this->setDisposalMethod(wuffs_disposal_to_skia_disposal(fc->disposal()));
245 this->setDuration(fc->duration() / WUFFS_BASE__FLICKS_PER_MILLISECOND);
246 this->setBlend(wuffs_blend_to_skia_blend(fc->blend()));
247}
248
249SkCodec::FrameInfo SkWuffsFrame::frameInfo(bool fullyReceived) const {
250 return ((SkCodec::FrameInfo){
251 .fRequiredFrame = getRequiredFrame(),
252 .fDuration = getDuration(),
253 .fFullyReceived = fullyReceived,
254 .fAlphaType = hasAlpha() ? kUnpremul_SkAlphaType : kOpaque_SkAlphaType,
255 .fDisposalMethod = getDisposalMethod(),
256 });
257}
258
259uint64_t SkWuffsFrame::ioPosition() const {
260 return fIOPosition;
261}
262
263SkEncodedInfo::Alpha SkWuffsFrame::onReportedAlpha() const {
264 return fReportedAlpha;
265}
266
267// -------------------------------- SkWuffsFrameHolder implementation
268
269void SkWuffsFrameHolder::init(SkWuffsCodec* codec, int width, int height) {
270 fCodec = codec;
271 // Initialize SkFrameHolder's (the superclass) fields.
272 fScreenWidth = width;
273 fScreenHeight = height;
274}
275
276const SkFrame* SkWuffsFrameHolder::onGetFrame(int i) const {
277 return fCodec->frame(i);
278};
279
Nigel Tao0185b952018-11-08 10:47:24 +1100280// -------------------------------- SkWuffsSpySampler implementation
281
282void SkWuffsSpySampler::reset() {
283 fFillWidth = 0;
284 fSampleX = 1;
285 this->setSampleY(1);
286}
287
288int SkWuffsSpySampler::sampleX() const {
289 return fSampleX;
290}
291
292int SkWuffsSpySampler::fillWidth() const {
293 return fFillWidth;
294}
295
296int SkWuffsSpySampler::onSetSampleX(int sampleX) {
297 fSampleX = sampleX;
298 return get_scaled_dimension(fImageWidth, sampleX);
299}
300
Leon Scroggins IIIe93ec682018-10-26 09:25:51 -0400301// -------------------------------- SkWuffsCodec implementation
302
303SkWuffsCodec::SkWuffsCodec(SkEncodedInfo&& encodedInfo,
304 std::unique_ptr<SkStream> stream,
305 std::unique_ptr<wuffs_gif__decoder, decltype(&sk_free)> dec,
306 std::unique_ptr<uint8_t, decltype(&sk_free)> pixbuf_ptr,
307 std::unique_ptr<uint8_t, decltype(&sk_free)> workbuf_ptr,
308 size_t workbuf_len,
309 wuffs_base__image_config imgcfg,
310 wuffs_base__pixel_buffer pixbuf,
311 wuffs_base__io_buffer iobuf)
312 : INHERITED(std::move(encodedInfo),
313 skcms_PixelFormat_RGBA_8888,
314 // Pass a nullptr SkStream to the SkCodec constructor. We
315 // manage the stream ourselves, as the default SkCodec behavior
316 // is too trigger-happy on rewinding the stream.
317 nullptr),
Nigel Tao0185b952018-11-08 10:47:24 +1100318 fSpySampler(imgcfg.pixcfg.width()),
319 fFrameHolder(),
Leon Scroggins IIIe93ec682018-10-26 09:25:51 -0400320 fStream(std::move(stream)),
321 fDecoder(std::move(dec)),
322 fPixbufPtr(std::move(pixbuf_ptr)),
323 fWorkbufPtr(std::move(workbuf_ptr)),
324 fWorkbufLen(workbuf_len),
325 fFirstFrameIOPosition(imgcfg.first_frame_io_position()),
326 fFrameConfig((wuffs_base__frame_config){}),
327 fPixelBuffer(pixbuf),
328 fIOBuffer((wuffs_base__io_buffer){}),
Leon Scroggins IIIe93ec682018-10-26 09:25:51 -0400329 fIncrDecDst(nullptr),
Leon Scroggins IIIe93ec682018-10-26 09:25:51 -0400330 fIncrDecRowBytes(0),
Nigel Tao0185b952018-11-08 10:47:24 +1100331 fSwizzler(nullptr),
Nigel Tao9859ef82019-02-13 13:20:02 +1100332 fScaledHeight(0),
Leon Scroggins IIIe93ec682018-10-26 09:25:51 -0400333 fNumFullyReceivedFrames(0),
334 fFramesComplete(false),
335 fDecoderIsSuspended(false) {
336 fFrameHolder.init(this, imgcfg.pixcfg.width(), imgcfg.pixcfg.height());
337
338 // Initialize fIOBuffer's fields, copying any outstanding data from iobuf to
339 // fIOBuffer, as iobuf's backing array may not be valid for the lifetime of
340 // this SkWuffsCodec object, but fIOBuffer's backing array (fBuffer) is.
341 SkASSERT(iobuf.data.len == SK_WUFFS_CODEC_BUFFER_SIZE);
342 memmove(fBuffer, iobuf.data.ptr, iobuf.meta.wi);
343 fIOBuffer = ((wuffs_base__io_buffer){
344 .data = ((wuffs_base__slice_u8){
345 .ptr = fBuffer,
346 .len = SK_WUFFS_CODEC_BUFFER_SIZE,
347 }),
348 .meta = iobuf.meta,
349 });
350}
351
352const SkWuffsFrame* SkWuffsCodec::frame(int i) const {
353 if ((0 <= i) && (static_cast<size_t>(i) < fFrames.size())) {
354 return &fFrames[i];
355 }
356 return nullptr;
357}
358
359SkEncodedImageFormat SkWuffsCodec::onGetEncodedFormat() const {
360 return SkEncodedImageFormat::kGIF;
361}
362
363SkCodec::Result SkWuffsCodec::onGetPixels(const SkImageInfo& dstInfo,
364 void* dst,
365 size_t rowBytes,
366 const Options& options,
367 int* rowsDecoded) {
368 SkCodec::Result result = this->onStartIncrementalDecode(dstInfo, dst, rowBytes, options);
369 if (result != kSuccess) {
370 return result;
371 }
372 return this->onIncrementalDecode(rowsDecoded);
373}
374
375const SkFrameHolder* SkWuffsCodec::getFrameHolder() const {
376 return &fFrameHolder;
377}
378
379SkCodec::Result SkWuffsCodec::onStartIncrementalDecode(const SkImageInfo& dstInfo,
380 void* dst,
381 size_t rowBytes,
382 const SkCodec::Options& options) {
383 if (options.fSubset) {
384 return SkCodec::kUnimplemented;
385 }
386 SkCodec::Result result = this->seekFrame(options.fFrameIndex);
387 if (result != SkCodec::kSuccess) {
388 return result;
389 }
390
Nigel Tao0185b952018-11-08 10:47:24 +1100391 fSpySampler.reset();
Nigel Tao0185b952018-11-08 10:47:24 +1100392 fSwizzler = nullptr;
Nigel Tao9859ef82019-02-13 13:20:02 +1100393 fScaledHeight = 0;
Leon Scroggins IIIe93ec682018-10-26 09:25:51 -0400394
Leon Scroggins IIIcb6b8842018-12-04 13:55:13 -0500395 const char* status = this->decodeFrameConfig();
Nigel Taob7a1b512019-02-10 12:19:50 +1100396 if (status == wuffs_base__suspension__short_read) {
Leon Scroggins IIIcb6b8842018-12-04 13:55:13 -0500397 return SkCodec::kIncompleteInput;
Nigel Taob7a1b512019-02-10 12:19:50 +1100398 } else if (status != nullptr) {
Leon Scroggins IIIcb6b8842018-12-04 13:55:13 -0500399 SkCodecPrintf("decodeFrameConfig: %s", status);
400 return SkCodec::kErrorInInput;
401 }
Nigel Taob7a1b512019-02-10 12:19:50 +1100402
Nigel Tao490e6472019-02-14 14:50:53 +1100403 uint32_t src_bits_per_pixel =
404 wuffs_base__pixel_format__bits_per_pixel(fPixelBuffer.pixcfg.pixel_format());
405 if ((src_bits_per_pixel == 0) || (src_bits_per_pixel % 8 != 0)) {
406 return SkCodec::kInternalError;
407 }
408 size_t src_bytes_per_pixel = src_bits_per_pixel / 8;
Nigel Taob7a1b512019-02-10 12:19:50 +1100409
410 // Zero-initialize Wuffs' buffer covering the frame rect.
411 wuffs_base__rect_ie_u32 frame_rect = fFrameConfig.bounds();
412 wuffs_base__table_u8 pixels = fPixelBuffer.plane(0);
413 for (uint32_t y = frame_rect.min_incl_y; y < frame_rect.max_excl_y; y++) {
Nigel Tao490e6472019-02-14 14:50:53 +1100414 sk_bzero(pixels.ptr + (y * pixels.stride) + (frame_rect.min_incl_x * src_bytes_per_pixel),
415 frame_rect.width() * src_bytes_per_pixel);
Nigel Taob7a1b512019-02-10 12:19:50 +1100416 }
417
418 fIncrDecDst = static_cast<uint8_t*>(dst);
419 fIncrDecRowBytes = rowBytes;
420 return SkCodec::kSuccess;
Leon Scroggins IIIe93ec682018-10-26 09:25:51 -0400421}
422
Leon Scroggins III9b0ba2c2018-11-19 14:52:37 -0500423static bool independent_frame(SkCodec* codec, int frameIndex) {
424 if (frameIndex == 0) {
425 return true;
426 }
427
428 SkCodec::FrameInfo frameInfo;
429 SkAssertResult(codec->getFrameInfo(frameIndex, &frameInfo));
430 return frameInfo.fRequiredFrame == SkCodec::kNoFrame;
431}
432
433static void blend(uint32_t* dst, const uint32_t* src, int width) {
434 while (width --> 0) {
435 if (*src != 0) {
436 *dst = *src;
437 }
438 src++;
439 dst++;
440 }
441}
442
Leon Scroggins IIIe93ec682018-10-26 09:25:51 -0400443SkCodec::Result SkWuffsCodec::onIncrementalDecode(int* rowsDecoded) {
444 if (!fIncrDecDst) {
445 return SkCodec::kInternalError;
446 }
447
Leon Scroggins III699d41e2019-02-07 09:25:51 -0500448 SkCodec::Result result = SkCodec::kSuccess;
449 const char* status = this->decodeFrame();
450 const bool independent = independent_frame(this, options().fFrameIndex);
451 if (status != nullptr) {
452 if (status == wuffs_base__suspension__short_read) {
453 result = SkCodec::kIncompleteInput;
454 } else {
455 SkCodecPrintf("decodeFrame: %s", status);
456 result = SkCodec::kErrorInInput;
457 }
458
459 if (!independent) {
460 // For a dependent frame, we cannot blend the partial result, since
461 // that will overwrite the contribution from prior frames.
462 return result;
463 }
464 }
465
Nigel Tao490e6472019-02-14 14:50:53 +1100466 uint32_t src_bits_per_pixel =
467 wuffs_base__pixel_format__bits_per_pixel(fPixelBuffer.pixcfg.pixel_format());
468 if ((src_bits_per_pixel == 0) || (src_bits_per_pixel % 8 != 0)) {
469 return SkCodec::kInternalError;
470 }
471 size_t src_bytes_per_pixel = src_bits_per_pixel / 8;
472
Leon Scroggins IIIdad4bfc2018-12-10 12:37:10 -0500473 wuffs_base__rect_ie_u32 frame_rect = fFrameConfig.bounds();
Leon Scroggins III699d41e2019-02-07 09:25:51 -0500474 wuffs_base__rect_ie_u32 dirty_rect = fDecoder->frame_dirty_rect();
Nigel Tao0185b952018-11-08 10:47:24 +1100475 if (!fSwizzler) {
Leon Scroggins IIIdad4bfc2018-12-10 12:37:10 -0500476 auto bounds = SkIRect::MakeLTRB(frame_rect.min_incl_x, frame_rect.min_incl_y,
477 frame_rect.max_excl_x, frame_rect.max_excl_y);
Nigel Tao490e6472019-02-14 14:50:53 +1100478 fSwizzler =
479 SkSwizzler::Make(this->getEncodedInfo(), nullptr, dstInfo(), this->options(), &bounds);
Nigel Tao0185b952018-11-08 10:47:24 +1100480 fSwizzler->setSampleX(fSpySampler.sampleX());
481 fSwizzler->setSampleY(fSpySampler.sampleY());
Nigel Tao9859ef82019-02-13 13:20:02 +1100482 fScaledHeight = get_scaled_dimension(dstInfo().height(), fSpySampler.sampleY());
Nigel Tao0185b952018-11-08 10:47:24 +1100483
Nigel Tao490e6472019-02-14 14:50:53 +1100484 if (frame_rect.width() > (SIZE_MAX / src_bytes_per_pixel)) {
485 return SkCodec::kInternalError;
486 }
487
Leon Scroggins IIIcb6b8842018-12-04 13:55:13 -0500488 // If the frame rect does not fill the output, ensure that those pixels are not
Nigel Taob7a1b512019-02-10 12:19:50 +1100489 // left uninitialized.
Leon Scroggins III699d41e2019-02-07 09:25:51 -0500490 if (independent && (bounds != this->bounds() || dirty_rect.is_empty())) {
Nigel Tao9859ef82019-02-13 13:20:02 +1100491 auto fillInfo = dstInfo().makeWH(fSwizzler->fillWidth(), fScaledHeight);
Leon Scroggins III9b0ba2c2018-11-19 14:52:37 -0500492 SkSampler::Fill(fillInfo, fIncrDecDst, fIncrDecRowBytes, options().fZeroInitialized);
493 }
Nigel Tao0185b952018-11-08 10:47:24 +1100494 }
Nigel Tao9859ef82019-02-13 13:20:02 +1100495 if (fScaledHeight == 0) {
496 return SkCodec::kInternalError;
497 }
Nigel Tao0185b952018-11-08 10:47:24 +1100498
Leon Scroggins IIIe93ec682018-10-26 09:25:51 -0400499 // The semantics of *rowsDecoded is: say you have a 10 pixel high image
500 // (both the frame and the image). If you only decoded the first 3 rows,
501 // set this to 3, and then SkCodec (or the caller of incrementalDecode)
502 // would zero-initialize the remaining 7 (unless the memory was already
503 // zero-initialized).
504 //
505 // Now let's say that the image is still 10 pixels high, but the frame is
506 // from row 5 to 9. If you only decoded 3 rows, but you initialized the
507 // first 5, you could return 8, and the caller would zero-initialize the
508 // final 2. For GIF (where a frame can be smaller than the image and can be
509 // interlaced), we just zero-initialize all 10 rows ahead of time and
510 // return the height of the image, so the caller knows it doesn't need to
511 // do anything.
Leon Scroggins III9b0ba2c2018-11-19 14:52:37 -0500512 //
513 // Similarly, if the output is scaled, we zero-initialized all
Nigel Tao9859ef82019-02-13 13:20:02 +1100514 // |fScaledHeight| rows (the scaled image height), so we inform the caller
Leon Scroggins III9b0ba2c2018-11-19 14:52:37 -0500515 // that it doesn't need to do anything.
Leon Scroggins IIIe93ec682018-10-26 09:25:51 -0400516 if (rowsDecoded) {
Nigel Tao9859ef82019-02-13 13:20:02 +1100517 *rowsDecoded = fScaledHeight;
Leon Scroggins IIIe93ec682018-10-26 09:25:51 -0400518 }
519
Leon Scroggins IIIdad4bfc2018-12-10 12:37:10 -0500520 // If the frame's dirty rect is empty, no need to swizzle.
Leon Scroggins IIIdad4bfc2018-12-10 12:37:10 -0500521 if (!dirty_rect.is_empty()) {
Leon Scroggins III7a3805c2018-12-07 09:21:30 -0500522 std::unique_ptr<uint8_t[]> tmpBuffer;
523 if (!independent) {
524 tmpBuffer.reset(new uint8_t[dstInfo().minRowBytes()]);
525 }
Nigel Tao490e6472019-02-14 14:50:53 +1100526 wuffs_base__table_u8 pixels = fPixelBuffer.plane(0);
527 const int sampleY = fSwizzler->sampleY();
Leon Scroggins IIIdad4bfc2018-12-10 12:37:10 -0500528 for (uint32_t y = dirty_rect.min_incl_y; y < dirty_rect.max_excl_y; y++) {
Leon Scroggins III7a3805c2018-12-07 09:21:30 -0500529 int dstY = y;
530 if (sampleY != 1) {
531 if (!fSwizzler->rowNeeded(y)) {
532 continue;
533 }
534 dstY /= sampleY;
Nigel Tao9859ef82019-02-13 13:20:02 +1100535 if (dstY >= fScaledHeight) {
Leon Scroggins III7a3805c2018-12-07 09:21:30 -0500536 break;
537 }
538 }
539
Leon Scroggins IIIdad4bfc2018-12-10 12:37:10 -0500540 // We don't adjust d by (frame_rect.min_incl_x * dst_bpp) as we
541 // have already accounted for that in swizzleRect, above.
Leon Scroggins III7a3805c2018-12-07 09:21:30 -0500542 uint8_t* d = fIncrDecDst + (dstY * fIncrDecRowBytes);
543
544 // The Wuffs model is that the dst buffer is the image, not the frame.
545 // The expectation is that you allocate the buffer once, but re-use it
546 // for the N frames, regardless of each frame's top-left co-ordinate.
547 //
548 // To get from the start (in the X-direction) of the image to the start
Nigel Tao490e6472019-02-14 14:50:53 +1100549 // of the frame, we adjust s by (frame_rect.min_incl_x *
550 // src_bytes_per_pixel).
Leon Scroggins IIIdad4bfc2018-12-10 12:37:10 -0500551 //
552 // We adjust (in the X-direction) by the frame rect, not the dirty
553 // rect, because the swizzler (which operates on rows) was
554 // configured with the frame rect's X range.
Nigel Tao490e6472019-02-14 14:50:53 +1100555 uint8_t* s =
556 pixels.ptr + (y * pixels.stride) + (frame_rect.min_incl_x * src_bytes_per_pixel);
Leon Scroggins III7a3805c2018-12-07 09:21:30 -0500557 if (independent) {
558 fSwizzler->swizzle(d, s);
559 } else {
560 SkASSERT(tmpBuffer.get());
561 fSwizzler->swizzle(tmpBuffer.get(), s);
562 d = SkTAddOffset<uint8_t>(d, fSwizzler->swizzleOffsetBytes());
563 const auto* swizzled = SkTAddOffset<uint32_t>(tmpBuffer.get(),
564 fSwizzler->swizzleOffsetBytes());
565 blend(reinterpret_cast<uint32_t*>(d), swizzled, fSwizzler->swizzleWidth());
566 }
567 }
568 }
569
Leon Scroggins IIIe93ec682018-10-26 09:25:51 -0400570 if (result == SkCodec::kSuccess) {
Nigel Tao0185b952018-11-08 10:47:24 +1100571 fSpySampler.reset();
Leon Scroggins IIIe93ec682018-10-26 09:25:51 -0400572 fIncrDecDst = nullptr;
Leon Scroggins IIIe93ec682018-10-26 09:25:51 -0400573 fIncrDecRowBytes = 0;
Nigel Tao0185b952018-11-08 10:47:24 +1100574 fSwizzler = nullptr;
575 } else {
576 // Make fSpySampler return whatever fSwizzler would have for fillWidth.
577 fSpySampler.fFillWidth = fSwizzler->fillWidth();
Leon Scroggins IIIe93ec682018-10-26 09:25:51 -0400578 }
579 return result;
580}
581
582int SkWuffsCodec::onGetFrameCount() {
583 if (!fFramesComplete) {
584 this->readFrames();
585 this->updateNumFullyReceivedFrames();
586 }
587 return fFrames.size();
588}
589
590bool SkWuffsCodec::onGetFrameInfo(int i, SkCodec::FrameInfo* frameInfo) const {
591 const SkWuffsFrame* f = this->frame(i);
592 if (!f) {
593 return false;
594 }
595 if (frameInfo) {
596 *frameInfo = f->frameInfo(static_cast<uint64_t>(i) < this->fNumFullyReceivedFrames);
597 }
598 return true;
599}
600
601int SkWuffsCodec::onGetRepetitionCount() {
602 // Convert from Wuffs's loop count to Skia's repeat count. Wuffs' uint32_t
603 // number is how many times to play the loop. Skia's int number is how many
604 // times to play the loop *after the first play*. Wuffs and Skia use 0 and
605 // kRepetitionCountInfinite respectively to mean loop forever.
Nigel Tao6af1edc2019-01-19 15:12:39 +1100606 uint32_t n = fDecoder->num_animation_loops();
Leon Scroggins IIIe93ec682018-10-26 09:25:51 -0400607 if (n == 0) {
608 return SkCodec::kRepetitionCountInfinite;
609 }
610 n--;
611 return n < INT_MAX ? n : INT_MAX;
612}
613
Nigel Tao0185b952018-11-08 10:47:24 +1100614SkSampler* SkWuffsCodec::getSampler(bool createIfNecessary) {
615 // fIncrDst being non-nullptr means that we are between an
616 // onStartIncrementalDecode call and the matching final (successful)
617 // onIncrementalDecode call.
618 if (createIfNecessary || fIncrDecDst) {
619 return &fSpySampler;
620 }
621 return nullptr;
622}
623
Leon Scroggins III9b0ba2c2018-11-19 14:52:37 -0500624bool SkWuffsCodec::conversionSupported(const SkImageInfo& dst, bool srcIsOpaque, bool needsColorXform) {
625 if (!this->INHERITED::conversionSupported(dst, srcIsOpaque, needsColorXform)) {
626 return false;
627 }
628
629 switch (dst.colorType()) {
630 case kRGBA_8888_SkColorType:
631 case kBGRA_8888_SkColorType:
632 return true;
633 default:
634 // FIXME: Add skcms to support F16
635 // FIXME: Add support for 565 on the first frame
636 return false;
637 }
638}
639
Leon Scroggins IIIe93ec682018-10-26 09:25:51 -0400640void SkWuffsCodec::readFrames() {
641 size_t n = fFrames.size();
642 int i = n ? n - 1 : 0;
643 if (this->seekFrame(i) != SkCodec::kSuccess) {
644 return;
645 }
646
647 // Iterate through the frames, converting from Wuffs'
648 // wuffs_base__frame_config type to Skia's SkWuffsFrame type.
649 for (; i < INT_MAX; i++) {
650 const char* status = this->decodeFrameConfig();
651 if (status == nullptr) {
652 // No-op.
653 } else if (status == wuffs_base__warning__end_of_data) {
654 break;
655 } else {
656 return;
657 }
658
659 if (static_cast<size_t>(i) < fFrames.size()) {
660 continue;
661 }
662 fFrames.emplace_back(&fFrameConfig);
663 SkWuffsFrame* f = &fFrames[fFrames.size() - 1];
664 fFrameHolder.setAlphaAndRequiredFrame(f);
665 }
666
667 fFramesComplete = true;
668}
669
670SkCodec::Result SkWuffsCodec::seekFrame(int frameIndex) {
671 if (fDecoderIsSuspended) {
672 SkCodec::Result res = this->resetDecoder();
673 if (res != SkCodec::kSuccess) {
674 return res;
675 }
676 }
677
678 uint64_t pos = 0;
679 if (frameIndex < 0) {
680 return SkCodec::kInternalError;
681 } else if (frameIndex == 0) {
682 pos = fFirstFrameIOPosition;
683 } else if (static_cast<size_t>(frameIndex) < fFrames.size()) {
684 pos = fFrames[frameIndex].ioPosition();
685 } else {
686 return SkCodec::kInternalError;
687 }
688
689 if (!seek_buffer(&fIOBuffer, fStream.get(), pos)) {
690 return SkCodec::kInternalError;
691 }
Nigel Tao6af1edc2019-01-19 15:12:39 +1100692 const char* status = fDecoder->restart_frame(frameIndex, fIOBuffer.reader_io_position());
Leon Scroggins IIIe93ec682018-10-26 09:25:51 -0400693 if (status != nullptr) {
694 return SkCodec::kInternalError;
695 }
696 return SkCodec::kSuccess;
697}
698
699// An overview of the Wuffs decoding API:
700//
701// An animated image (such as GIF) has an image header and then N frames. The
702// image header gives e.g. the overall image's width and height. Each frame
703// consists of a frame header (e.g. frame rectangle bounds, display duration)
704// and a payload (the pixels).
705//
706// In Wuffs terminology, there is one image config and then N pairs of
707// (frame_config, frame). To decode everything (without knowing N in advance)
708// sequentially:
709// - call wuffs_gif__decoder::decode_image_config
710// - while (true) {
711// - call wuffs_gif__decoder::decode_frame_config
712// - if that returned wuffs_base__warning__end_of_data, break
713// - call wuffs_gif__decoder::decode_frame
714// - }
715//
716// The first argument to each decode_foo method is the destination struct to
717// store the decoded information.
718//
719// For random (instead of sequential) access to an image's frames, call
720// wuffs_gif__decoder::restart_frame to prepare to decode the i'th frame.
721// Essentially, it restores the state to be at the top of the while loop above.
722// The wuffs_base__io_buffer's reader position will also need to be set at the
723// right point in the source data stream. The position for the i'th frame is
724// calculated by the i'th decode_frame_config call. You can only call
725// restart_frame after decode_image_config is called, explicitly or implicitly
726// (see below), as decoding a single frame might require for-all-frames
727// information like the overall image dimensions and the global palette.
728//
729// All of those decode_xxx calls are optional. For example, if
730// decode_image_config is not called, then the first decode_frame_config call
731// will implicitly parse and verify the image header, before parsing the first
732// frame's header. Similarly, you can call only decode_frame N times, without
733// calling decode_image_config or decode_frame_config, if you already know
734// metadata like N and each frame's rectangle bounds by some other means (e.g.
735// this is a first party, statically known image).
736//
737// Specifically, starting with an unknown (but re-windable) GIF image, if you
738// want to just find N (i.e. count the number of frames), you can loop calling
739// only the decode_frame_config method and avoid calling the more expensive
740// decode_frame method. In terms of the underlying GIF image format, this will
741// skip over the LZW-encoded pixel data, avoiding the costly LZW decompression.
742//
743// Those decode_xxx methods are also suspendible. They will return early (with
744// a status code that is_suspendible and therefore isn't is_complete) if there
745// isn't enough source data to complete the operation: an incremental decode.
746// Calling decode_xxx again with additional source data will resume the
747// previous operation, instead of starting a new operation. Calling decode_yyy
748// whilst decode_xxx is suspended will result in an error.
749//
750// Once an error is encountered, whether from invalid source data or from a
751// programming error such as calling decode_yyy while suspended in decode_xxx,
752// all subsequent calls will be no-ops that return an error. To reset the
753// decoder into something that does productive work, memset the entire struct
754// to zero, check the Wuffs version and then, in order to be able to call
755// restart_frame, call decode_image_config. The io_buffer and its associated
756// stream will also need to be rewound.
757
758static SkCodec::Result reset_and_decode_image_config(wuffs_gif__decoder* decoder,
759 wuffs_base__image_config* imgcfg,
760 wuffs_base__io_buffer* b,
761 SkStream* s) {
762 memset(decoder, 0, sizeof__wuffs_gif__decoder());
Nigel Tao6af1edc2019-01-19 15:12:39 +1100763 const char* status = decoder->check_wuffs_version(sizeof__wuffs_gif__decoder(), WUFFS_VERSION);
Leon Scroggins IIIe93ec682018-10-26 09:25:51 -0400764 if (status != nullptr) {
765 SkCodecPrintf("check_wuffs_version: %s", status);
766 return SkCodec::kInternalError;
767 }
768 while (true) {
Nigel Tao6af1edc2019-01-19 15:12:39 +1100769 status = decoder->decode_image_config(imgcfg, b->reader());
Leon Scroggins IIIe93ec682018-10-26 09:25:51 -0400770 if (status == nullptr) {
Nigel Tao490e6472019-02-14 14:50:53 +1100771 break;
Leon Scroggins IIIe93ec682018-10-26 09:25:51 -0400772 } else if (status != wuffs_base__suspension__short_read) {
773 SkCodecPrintf("decode_image_config: %s", status);
774 return SkCodec::kErrorInInput;
775 } else if (!fill_buffer(b, s)) {
776 return SkCodec::kIncompleteInput;
777 }
778 }
Nigel Tao490e6472019-02-14 14:50:53 +1100779
780 // A GIF image's natural color model is indexed color: 1 byte per pixel,
781 // indexing a 256-element palette.
782 //
783 // For Skia, we override that to decode to 4 bytes per pixel, BGRA or RGBA.
784 wuffs_base__pixel_format pixfmt = 0;
785 switch (kN32_SkColorType) {
786 case kBGRA_8888_SkColorType:
787 pixfmt = WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL;
788 break;
789 case kRGBA_8888_SkColorType:
790 pixfmt = WUFFS_BASE__PIXEL_FORMAT__RGBA_NONPREMUL;
791 break;
792 default:
793 return SkCodec::kInternalError;
794 }
795 imgcfg->pixcfg.set(pixfmt, WUFFS_BASE__PIXEL_SUBSAMPLING__NONE, imgcfg->pixcfg.width(),
796 imgcfg->pixcfg.height());
797
798 return SkCodec::kSuccess;
Leon Scroggins IIIe93ec682018-10-26 09:25:51 -0400799}
800
801SkCodec::Result SkWuffsCodec::resetDecoder() {
802 if (!fStream->rewind()) {
803 return SkCodec::kInternalError;
804 }
805 fIOBuffer.meta = ((wuffs_base__io_buffer_meta){});
806
807 SkCodec::Result result =
808 reset_and_decode_image_config(fDecoder.get(), nullptr, &fIOBuffer, fStream.get());
809 if (result == SkCodec::kIncompleteInput) {
810 return SkCodec::kInternalError;
811 } else if (result != SkCodec::kSuccess) {
812 return result;
813 }
814
815 fDecoderIsSuspended = false;
816 return SkCodec::kSuccess;
817}
818
819const char* SkWuffsCodec::decodeFrameConfig() {
820 while (true) {
Nigel Tao6af1edc2019-01-19 15:12:39 +1100821 const char* status = fDecoder->decode_frame_config(&fFrameConfig, fIOBuffer.reader());
Leon Scroggins IIIe93ec682018-10-26 09:25:51 -0400822 if ((status == wuffs_base__suspension__short_read) &&
823 fill_buffer(&fIOBuffer, fStream.get())) {
824 continue;
825 }
826 fDecoderIsSuspended = !wuffs_base__status__is_complete(status);
827 this->updateNumFullyReceivedFrames();
828 return status;
829 }
830}
831
832const char* SkWuffsCodec::decodeFrame() {
833 while (true) {
Nigel Tao6af1edc2019-01-19 15:12:39 +1100834 const char* status = fDecoder->decode_frame(&fPixelBuffer, fIOBuffer.reader(),
835 ((wuffs_base__slice_u8){
836 .ptr = fWorkbufPtr.get(),
837 .len = fWorkbufLen,
838 }),
839 NULL);
Leon Scroggins IIIe93ec682018-10-26 09:25:51 -0400840 if ((status == wuffs_base__suspension__short_read) &&
841 fill_buffer(&fIOBuffer, fStream.get())) {
842 continue;
843 }
844 fDecoderIsSuspended = !wuffs_base__status__is_complete(status);
845 this->updateNumFullyReceivedFrames();
846 return status;
847 }
848}
849
850void SkWuffsCodec::updateNumFullyReceivedFrames() {
Nigel Tao6af1edc2019-01-19 15:12:39 +1100851 // num_decoded_frames's return value, n, can change over time, both up and
852 // down, as we seek back and forth in the underlying stream.
853 // fNumFullyReceivedFrames is the highest n we've seen.
854 uint64_t n = fDecoder->num_decoded_frames();
Leon Scroggins IIIe93ec682018-10-26 09:25:51 -0400855 if (fNumFullyReceivedFrames < n) {
856 fNumFullyReceivedFrames = n;
857 }
858}
859
860// -------------------------------- SkWuffsCodec.h functions
861
862bool SkWuffsCodec_IsFormat(const void* buf, size_t bytesRead) {
863 constexpr const char* gif_ptr = "GIF8";
864 constexpr size_t gif_len = 4;
865 return (bytesRead >= gif_len) && (memcmp(buf, gif_ptr, gif_len) == 0);
866}
867
868std::unique_ptr<SkCodec> SkWuffsCodec_MakeFromStream(std::unique_ptr<SkStream> stream,
869 SkCodec::Result* result) {
870 uint8_t buffer[SK_WUFFS_CODEC_BUFFER_SIZE];
871 wuffs_base__io_buffer iobuf = ((wuffs_base__io_buffer){
872 .data = ((wuffs_base__slice_u8){
873 .ptr = buffer,
874 .len = SK_WUFFS_CODEC_BUFFER_SIZE,
875 }),
876 .meta = ((wuffs_base__io_buffer_meta){}),
877 });
878 wuffs_base__image_config imgcfg = ((wuffs_base__image_config){});
879
880 // Wuffs is primarily a C library, not a C++ one. Furthermore, outside of
881 // the wuffs_base__etc types, the sizeof a file format specific type like
882 // GIF's wuffs_gif__decoder can vary between Wuffs versions. If p is of
883 // type wuffs_gif__decoder*, then the supported API treats p as a pointer
884 // to an opaque type: a private implementation detail. The API is always
885 // "set_foo(p, etc)" and not "p->foo = etc".
886 //
887 // See https://en.wikipedia.org/wiki/Opaque_pointer#C
888 //
889 // Thus, we don't use C++'s new operator (which requires knowing the sizeof
890 // the struct at compile time). Instead, we use sk_malloc_canfail, with
891 // sizeof__wuffs_gif__decoder returning the appropriate value for the
892 // (statically or dynamically) linked version of the Wuffs library.
893 //
894 // As a C (not C++) library, none of the Wuffs types have constructors or
895 // destructors.
896 //
897 // In RAII style, we can still use std::unique_ptr with these pointers, but
898 // we pair the pointer with sk_free instead of C++'s delete.
899 void* decoder_raw = sk_malloc_canfail(sizeof__wuffs_gif__decoder());
900 if (!decoder_raw) {
901 *result = SkCodec::kInternalError;
902 return nullptr;
903 }
904 std::unique_ptr<wuffs_gif__decoder, decltype(&sk_free)> decoder(
905 reinterpret_cast<wuffs_gif__decoder*>(decoder_raw), &sk_free);
906
907 SkCodec::Result reset_result =
908 reset_and_decode_image_config(decoder.get(), &imgcfg, &iobuf, stream.get());
909 if (reset_result != SkCodec::kSuccess) {
910 *result = reset_result;
911 return nullptr;
912 }
913
914 uint32_t width = imgcfg.pixcfg.width();
915 uint32_t height = imgcfg.pixcfg.height();
916 if ((width == 0) || (width > INT_MAX) || (height == 0) || (height > INT_MAX)) {
917 *result = SkCodec::kInvalidInput;
918 return nullptr;
919 }
920
Nigel Tao6af1edc2019-01-19 15:12:39 +1100921 uint64_t workbuf_len = decoder->workbuf_len().max_incl;
Nigel Tao22e86242019-01-26 16:04:01 +1100922 void* workbuf_ptr_raw = nullptr;
923 if (workbuf_len) {
924 workbuf_ptr_raw = workbuf_len <= SIZE_MAX ? sk_malloc_canfail(workbuf_len) : nullptr;
925 if (!workbuf_ptr_raw) {
926 *result = SkCodec::kInternalError;
927 return nullptr;
928 }
Leon Scroggins IIIe93ec682018-10-26 09:25:51 -0400929 }
930 std::unique_ptr<uint8_t, decltype(&sk_free)> workbuf_ptr(
931 reinterpret_cast<uint8_t*>(workbuf_ptr_raw), &sk_free);
932
933 uint64_t pixbuf_len = imgcfg.pixcfg.pixbuf_len();
934 void* pixbuf_ptr_raw = pixbuf_len <= SIZE_MAX ? sk_malloc_canfail(pixbuf_len) : nullptr;
935 if (!pixbuf_ptr_raw) {
936 *result = SkCodec::kInternalError;
937 return nullptr;
938 }
939 std::unique_ptr<uint8_t, decltype(&sk_free)> pixbuf_ptr(
940 reinterpret_cast<uint8_t*>(pixbuf_ptr_raw), &sk_free);
941 wuffs_base__pixel_buffer pixbuf = ((wuffs_base__pixel_buffer){});
942
943 const char* status = pixbuf.set_from_slice(&imgcfg.pixcfg, ((wuffs_base__slice_u8){
944 .ptr = pixbuf_ptr.get(),
945 .len = pixbuf_len,
946 }));
947 if (status != nullptr) {
948 SkCodecPrintf("set_from_slice: %s", status);
949 *result = SkCodec::kInternalError;
950 return nullptr;
951 }
952
Nigel Tao490e6472019-02-14 14:50:53 +1100953 SkEncodedInfo::Color color =
954 (imgcfg.pixcfg.pixel_format() == WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL)
955 ? SkEncodedInfo::kBGRA_Color
956 : SkEncodedInfo::kRGBA_Color;
957
Leon Scroggins IIIe93ec682018-10-26 09:25:51 -0400958 // In Skia's API, the alpha we calculate here and return is only for the
959 // first frame.
960 SkEncodedInfo::Alpha alpha = imgcfg.first_frame_is_opaque() ? SkEncodedInfo::kOpaque_Alpha
961 : SkEncodedInfo::kBinary_Alpha;
962
Nigel Tao490e6472019-02-14 14:50:53 +1100963 SkEncodedInfo encodedInfo = SkEncodedInfo::Make(width, height, color, alpha, 8);
Leon Scroggins IIIe93ec682018-10-26 09:25:51 -0400964
965 *result = SkCodec::kSuccess;
966 return std::unique_ptr<SkCodec>(new SkWuffsCodec(
967 std::move(encodedInfo), std::move(stream), std::move(decoder), std::move(pixbuf_ptr),
968 std::move(workbuf_ptr), workbuf_len, imgcfg, pixbuf, iobuf));
969}