Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | List of all members
SkWuffsCodec Class Referencefinal
Inheritance diagram for SkWuffsCodec:
SkScalingCodec SkCodec SkNoncopyable

Public Member Functions

 SkWuffsCodec (SkEncodedInfo &&encodedInfo, std::unique_ptr< SkStream > stream, bool canSeek, std::unique_ptr< wuffs_gif__decoder, decltype(&sk_free)> dec, std::unique_ptr< uint8_t, decltype(&sk_free)> workbuf_ptr, size_t workbuf_len, wuffs_base__image_config imgcfg, wuffs_base__io_buffer iobuf)
 
const SkWuffsFrameframe (int i) const
 
std::unique_ptr< SkStreamgetEncodedData () const override
 
- Public Member Functions inherited from SkCodec
virtual ~SkCodec ()
 
SkImageInfo getInfo () const
 
SkISize dimensions () const
 
SkIRect bounds () const
 
const skcms_ICCProfilegetICCProfile () const
 
SkEncodedOrigin getOrigin () const
 
SkISize getScaledDimensions (float desiredScale) const
 
bool getValidSubset (SkIRect *desiredSubset) const
 
SkEncodedImageFormat getEncodedFormat () const
 
Result getPixels (const SkImageInfo &info, void *pixels, size_t rowBytes, const Options *)
 
Result getPixels (const SkImageInfo &info, void *pixels, size_t rowBytes)
 
Result getPixels (const SkPixmap &pm, const Options *opts=nullptr)
 
std::tuple< sk_sp< SkImage >, SkCodec::ResultgetImage (const SkImageInfo &info, const Options *opts=nullptr)
 
std::tuple< sk_sp< SkImage >, SkCodec::ResultgetImage ()
 
bool queryYUVAInfo (const SkYUVAPixmapInfo::SupportedDataTypes &supportedDataTypes, SkYUVAPixmapInfo *yuvaPixmapInfo) const
 
Result getYUVAPlanes (const SkYUVAPixmaps &yuvaPixmaps)
 
Result startIncrementalDecode (const SkImageInfo &dstInfo, void *dst, size_t rowBytes, const Options *)
 
Result startIncrementalDecode (const SkImageInfo &dstInfo, void *dst, size_t rowBytes)
 
Result incrementalDecode (int *rowsDecoded=nullptr)
 
Result startScanlineDecode (const SkImageInfo &dstInfo, const Options *options)
 
Result startScanlineDecode (const SkImageInfo &dstInfo)
 
int getScanlines (void *dst, int countLines, size_t rowBytes)
 
bool skipScanlines (int countLines)
 
SkScanlineOrder getScanlineOrder () const
 
int nextScanline () const
 
int outputScanline (int inputScanline) const
 
int getFrameCount ()
 
bool getFrameInfo (int index, FrameInfo *info) const
 
std::vector< FrameInfogetFrameInfo ()
 
int getRepetitionCount ()
 

Private Member Functions

SkEncodedImageFormat onGetEncodedFormat () const override
 
Result onGetPixels (const SkImageInfo &, void *, size_t, const Options &, int *) override
 
const SkFrameHoldergetFrameHolder () const override
 
Result onStartIncrementalDecode (const SkImageInfo &dstInfo, void *dst, size_t rowBytes, const SkCodec::Options &options) override
 
Result onIncrementalDecode (int *rowsDecoded) override
 
int onGetFrameCount () override
 
bool onGetFrameInfo (int, FrameInfo *) const override
 
int onGetRepetitionCount () override
 

Additional Inherited Members

- Public Types inherited from SkCodec
enum  Result {
  kSuccess , kIncompleteInput , kErrorInInput , kInvalidConversion ,
  kInvalidScale , kInvalidParameters , kInvalidInput , kCouldNotRewind ,
  kInternalError , kUnimplemented
}
 
enum class  SelectionPolicy { kPreferStillImage , kPreferAnimation }
 
enum  ZeroInitialized { kYes_ZeroInitialized , kNo_ZeroInitialized }
 
enum  SkScanlineOrder { kTopDown_SkScanlineOrder , kBottomUp_SkScanlineOrder }
 
- Static Public Member Functions inherited from SkCodec
static constexpr size_t MinBufferedBytesNeeded ()
 
static const char * ResultToString (Result)
 
static std::unique_ptr< SkCodecMakeFromStream (std::unique_ptr< SkStream >, SkSpan< const SkCodecs::Decoder > decoders, Result *=nullptr, SkPngChunkReader *=nullptr, SelectionPolicy selectionPolicy=SelectionPolicy::kPreferStillImage)
 
static std::unique_ptr< SkCodecMakeFromStream (std::unique_ptr< SkStream >, Result *=nullptr, SkPngChunkReader *=nullptr, SelectionPolicy selectionPolicy=SelectionPolicy::kPreferStillImage)
 
static std::unique_ptr< SkCodecMakeFromData (sk_sp< SkData >, SkSpan< const SkCodecs::Decoder > decoders, SkPngChunkReader *=nullptr)
 
static std::unique_ptr< SkCodecMakeFromData (sk_sp< SkData >, SkPngChunkReader *=nullptr)
 
static void Register (bool(*peek)(const void *, size_t), std::unique_ptr< SkCodec >(*make)(std::unique_ptr< SkStream >, SkCodec::Result *))
 
- Static Public Attributes inherited from SkCodec
static constexpr int kNoFrame = -1
 
static constexpr int kRepetitionCountInfinite = -1
 
- Protected Types inherited from SkCodec
using XformFormat = skcms_PixelFormat
 
- Protected Member Functions inherited from SkScalingCodec
 SkScalingCodec (SkEncodedInfo &&info, XformFormat srcFormat, std::unique_ptr< SkStream > stream, SkEncodedOrigin origin=kTopLeft_SkEncodedOrigin)
 
SkISize onGetScaledDimensions (float desiredScale) const override
 
bool onDimensionsSupported (const SkISize &requested) override
 
- Protected Member Functions inherited from SkCodec
const SkEncodedInfogetEncodedInfo () const
 
 SkCodec (SkEncodedInfo &&, XformFormat srcFormat, std::unique_ptr< SkStream >, SkEncodedOrigin=kTopLeft_SkEncodedOrigin)
 
void setSrcXformFormat (XformFormat pixelFormat)
 
XformFormat getSrcXformFormat () const
 
virtual bool onGetGainmapInfo (SkGainmapInfo *, std::unique_ptr< SkStream > *)
 
virtual bool onQueryYUVAInfo (const SkYUVAPixmapInfo::SupportedDataTypes &, SkYUVAPixmapInfo *) const
 
virtual Result onGetYUVAPlanes (const SkYUVAPixmaps &)
 
virtual bool onGetValidSubset (SkIRect *) const
 
bool rewindIfNeeded ()
 
virtual bool onRewind ()
 
SkStreamstream ()
 
virtual SkScanlineOrder onGetScanlineOrder () const
 
const SkImageInfodstInfo () const
 
const Optionsoptions () const
 
int currScanline () const
 
virtual int onOutputScanline (int inputScanline) const
 
virtual bool conversionSupported (const SkImageInfo &dst, bool srcIsOpaque, bool needsColorXform)
 
virtual bool usesColorXform () const
 
void applyColorXform (void *dst, const void *src, int count) const
 
bool colorXform () const
 
bool xformOnDecode () const
 

Detailed Description

Definition at line 237 of file SkWuffsCodec.cpp.

Constructor & Destructor Documentation

◆ SkWuffsCodec()

SkWuffsCodec::SkWuffsCodec ( SkEncodedInfo &&  encodedInfo,
std::unique_ptr< SkStream stream,
bool  canSeek,
std::unique_ptr< wuffs_gif__decoder, decltype(&sk_free)>  dec,
std::unique_ptr< uint8_t, decltype(&sk_free)>  workbuf_ptr,
size_t  workbuf_len,
wuffs_base__image_config  imgcfg,
wuffs_base__io_buffer  iobuf 
)

Definition at line 380 of file SkWuffsCodec.cpp.

388 : INHERITED(std::move(encodedInfo),
390 // Pass a nullptr SkStream to the SkCodec constructor. We
391 // manage the stream ourselves, as the default SkCodec behavior
392 // is too trigger-happy on rewinding the stream.
393 nullptr),
394 fFrameHolder(),
395 fPrivStream(std::move(stream)),
396 fWorkbufPtr(std::move(workbuf_ptr)),
397 fWorkbufLen(workbuf_len),
398 fDecoder(std::move(dec)),
399 fFirstFrameIOPosition(imgcfg.first_frame_io_position()),
400 fFrameConfig(wuffs_base__null_frame_config()),
401 fPixelConfig(imgcfg.pixcfg),
402 fPixelBuffer(wuffs_base__null_pixel_buffer()),
403 fIOBuffer(wuffs_base__empty_io_buffer()),
404 fIncrDecDst(nullptr),
405 fIncrDecRowBytes(0),
406 fIncrDecPixelBlend(WUFFS_BASE__PIXEL_BLEND__SRC),
407 fIncrDecOnePass(false),
408 fFirstCallToIncrementalDecode(false),
409 fTwoPassPixbufPtr(nullptr, &sk_free),
410 fTwoPassPixbufLen(0),
411 fNumFullyReceivedFrames(0),
412 fFramesComplete(false),
413 fDecoderIsSuspended(false),
414 fCanSeek(canSeek) {
415 fFrameHolder.init(this, imgcfg.pixcfg.width(), imgcfg.pixcfg.height());
416
417 // Initialize fIOBuffer's fields, copying any outstanding data from iobuf to
418 // fIOBuffer, as iobuf's backing array may not be valid for the lifetime of
419 // this SkWuffsCodec object, but fIOBuffer's backing array (fBuffer) is.
420 SkASSERT(iobuf.data.len == SK_WUFFS_CODEC_BUFFER_SIZE);
421 memmove(fBuffer, iobuf.data.ptr, iobuf.meta.wi);
422 fIOBuffer.data = wuffs_base__make_slice_u8(fBuffer, SK_WUFFS_CODEC_BUFFER_SIZE);
423 fIOBuffer.meta = iobuf.meta;
424}
#define SkASSERT(cond)
Definition SkAssert.h:116
SK_API void sk_free(void *)
#define SK_WUFFS_CODEC_BUFFER_SIZE
SkStream * stream()
Definition SkCodec.h:865
void init(SkWuffsCodec *codec, int width, int height)
@ skcms_PixelFormat_RGBA_8888

Member Function Documentation

◆ frame()

const SkWuffsFrame * SkWuffsCodec::frame ( int  i) const

Definition at line 426 of file SkWuffsCodec.cpp.

426 {
427 if ((0 <= i) && (static_cast<size_t>(i) < fFrames.size())) {
428 return &fFrames[i];
429 }
430 return nullptr;
431}

◆ getEncodedData()

std::unique_ptr< SkStream > SkWuffsCodec::getEncodedData ( ) const
overridevirtual

Return the underlying encoded data stream. This may be nullptr if the original stream could not be duplicated.

Reimplemented from SkCodec.

Definition at line 970 of file SkWuffsCodec.cpp.

970 {
971 SkASSERT(fPrivStream);
972 return fPrivStream->duplicate();
973}

◆ getFrameHolder()

const SkFrameHolder * SkWuffsCodec::getFrameHolder ( ) const
overrideprivatevirtual

For multi-framed images, return the object with information about the frames.

Reimplemented from SkCodec.

Definition at line 449 of file SkWuffsCodec.cpp.

449 {
450 return &fFrameHolder;
451}

◆ onGetEncodedFormat()

SkEncodedImageFormat SkWuffsCodec::onGetEncodedFormat ( ) const
overrideprivatevirtual

Implements SkCodec.

Definition at line 433 of file SkWuffsCodec.cpp.

◆ onGetFrameCount()

int SkWuffsCodec::onGetFrameCount ( )
overrideprivatevirtual

Reimplemented from SkCodec.

Definition at line 780 of file SkWuffsCodec.cpp.

780 {
781 if (!fCanSeek) {
782 return 1;
783 }
784
785 // It is valid, in terms of the SkCodec API, to call SkCodec::getFrameCount
786 // while in an incremental decode (after onStartIncrementalDecode returns
787 // and before onIncrementalDecode returns kSuccess).
788 //
789 // We should not advance the SkWuffsCodec' stream while doing so, even
790 // though other SkCodec implementations can return increasing values from
791 // onGetFrameCount when given more data. If we tried to do so, the
792 // subsequent resume of the incremental decode would continue reading from
793 // a different position in the I/O stream, leading to an incorrect error.
794 //
795 // Other SkCodec implementations can move the stream forward during
796 // onGetFrameCount because they assume that the stream is rewindable /
797 // seekable. For example, an alternative GIF implementation may choose to
798 // store, for each frame walked past when merely counting the number of
799 // frames, the I/O position of each of the frame's GIF data blocks. (A GIF
800 // frame's compressed data can have multiple data blocks, each at most 255
801 // bytes in length). Obviously, this can require O(numberOfFrames) extra
802 // memory to store these I/O positions. The constant factor is small, but
803 // it's still O(N), not O(1).
804 //
805 // Wuffs and SkWuffsCodec try to minimize relying on the rewindable /
806 // seekable assumption. By design, Wuffs per se aims for O(1) memory use
807 // (after any pixel buffers are allocated) instead of O(N), and its I/O
808 // type, wuffs_base__io_buffer, is not necessarily rewindable or seekable.
809 //
810 // The Wuffs API provides a limited, optional form of seeking, to the start
811 // of an animation frame's data, but does not provide arbitrary save and
812 // load of its internal state whilst in the middle of an animation frame.
813 bool incrementalDecodeIsInProgress = fIncrDecDst != nullptr;
814
815 if (!fFramesComplete && !incrementalDecodeIsInProgress) {
816 this->onGetFrameCountInternal();
817 this->updateNumFullyReceivedFrames();
818 }
819 return fFrames.size();
820}

◆ onGetFrameInfo()

bool SkWuffsCodec::onGetFrameInfo ( int  i,
SkCodec::FrameInfo frameInfo 
) const
overrideprivatevirtual

Reimplemented from SkCodec.

Definition at line 852 of file SkWuffsCodec.cpp.

852 {
853 if (!fCanSeek) {
854 // We haven't read forward in the stream, so this info isn't available.
855 return false;
856 }
857
858 const SkWuffsFrame* f = this->frame(i);
859 if (!f) {
860 return false;
861 }
862 if (frameInfo) {
863 f->fillIn(frameInfo, static_cast<uint64_t>(i) < this->fNumFullyReceivedFrames);
864 }
865 return true;
866}
double frame
Definition examples.cpp:31

◆ onGetPixels()

SkCodec::Result SkWuffsCodec::onGetPixels ( const SkImageInfo info,
void *  pixels,
size_t  rowBytes,
const Options ,
int rowsDecoded 
)
overrideprivatevirtual
Parameters
rowsDecodedWhen the encoded image stream is incomplete, this function will return kIncompleteInput and rowsDecoded will be set to the number of scanlines that were successfully decoded. This will allow getPixels() to fill the uninitialized memory.

Implements SkCodec.

Definition at line 437 of file SkWuffsCodec.cpp.

441 {
443 if (result != kSuccess) {
444 return result;
445 }
446 return this->onIncrementalDecode(rowsDecoded);
447}
const SkImageInfo & dstInfo() const
Definition SkCodec.h:878
@ kSuccess
Definition SkCodec.h:80
const Options & options() const
Definition SkCodec.h:880
Result onIncrementalDecode(int *rowsDecoded) override
Result onStartIncrementalDecode(const SkImageInfo &dstInfo, void *dst, size_t rowBytes, const SkCodec::Options &options) override
GAsyncResult * result

◆ onGetRepetitionCount()

int SkWuffsCodec::onGetRepetitionCount ( )
overrideprivatevirtual

Reimplemented from SkCodec.

Definition at line 868 of file SkWuffsCodec.cpp.

868 {
869 // Convert from Wuffs's loop count to Skia's repeat count. Wuffs' uint32_t
870 // number is how many times to play the loop. Skia's int number is how many
871 // times to play the loop *after the first play*. Wuffs and Skia use 0 and
872 // kRepetitionCountInfinite respectively to mean loop forever.
873 uint32_t n = fDecoder->num_animation_loops();
874 if (n == 0) {
876 }
877 n--;
878 return n < INT_MAX ? n : INT_MAX;
879}
static constexpr int kRepetitionCountInfinite
Definition SkCodec.h:759

◆ onIncrementalDecode()

SkCodec::Result SkWuffsCodec::onIncrementalDecode ( int rowsDecoded)
overrideprivatevirtual

Reimplemented from SkCodec.

Definition at line 610 of file SkWuffsCodec.cpp.

610 {
611 if (!fIncrDecDst) {
613 }
614
615 if (rowsDecoded) {
616 *rowsDecoded = dstInfo().height();
617 }
618
620 fIncrDecOnePass ? this->onIncrementalDecodeOnePass() : this->onIncrementalDecodeTwoPass();
621 if (result == SkCodec::kSuccess) {
622 fIncrDecDst = nullptr;
623 fIncrDecRowBytes = 0;
624 fIncrDecPixelBlend = WUFFS_BASE__PIXEL_BLEND__SRC;
625 fIncrDecOnePass = false;
626 }
627 return result;
628}
@ kInternalError
Definition SkCodec.h:118
int height() const

◆ onStartIncrementalDecode()

SkCodec::Result SkWuffsCodec::onStartIncrementalDecode ( const SkImageInfo dstInfo,
void *  dst,
size_t  rowBytes,
const SkCodec::Options options 
)
overrideprivatevirtual

Reimplemented from SkCodec.

Definition at line 453 of file SkWuffsCodec.cpp.

456 {
457 if (!dst) {
459 }
460 if (options.fSubset) {
462 }
463 SkCodec::Result result = this->seekFrame(options.fFrameIndex);
464 if (result != SkCodec::kSuccess) {
465 return result;
466 }
467
468 const char* status = this->decodeFrameConfig();
469 if (status == wuffs_base__suspension__short_read) {
471 } else if (status != nullptr) {
472 SkCodecPrintf("decodeFrameConfig: %s", status);
474 }
475
476 uint32_t pixelFormat = WUFFS_BASE__PIXEL_FORMAT__INVALID;
477 size_t bytesPerPixel = 0;
478
479 switch (dstInfo.colorType()) {
481 pixelFormat = WUFFS_BASE__PIXEL_FORMAT__BGR_565;
482 bytesPerPixel = 2;
483 break;
485 pixelFormat = WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL;
486 bytesPerPixel = 4;
487 break;
489 pixelFormat = WUFFS_BASE__PIXEL_FORMAT__RGBA_NONPREMUL;
490 bytesPerPixel = 4;
491 break;
492 default:
493 break;
494 }
495
496 // We can use "one pass" decoding if we have a Skia pixel format that Wuffs
497 // supports...
498 fIncrDecOnePass = (pixelFormat != WUFFS_BASE__PIXEL_FORMAT__INVALID) &&
499 // ...and no color profile (as Wuffs does not support them)...
500 (!getEncodedInfo().profile()) &&
501 // ...and we use the identity transform (as Wuffs does
502 // not support scaling).
503 (this->dimensions() == dstInfo.dimensions());
504
505 result = fIncrDecOnePass ? this->onStartIncrementalDecodeOnePass(
506 dstInfo, static_cast<uint8_t*>(dst), rowBytes, options,
507 pixelFormat, bytesPerPixel)
508 : this->onStartIncrementalDecodeTwoPass();
509 if (result != SkCodec::kSuccess) {
510 return result;
511 }
512
513 fIncrDecDst = static_cast<uint8_t*>(dst);
514 fIncrDecRowBytes = rowBytes;
515 fFirstCallToIncrementalDecode = true;
516 return SkCodec::kSuccess;
517}
#define SkCodecPrintf(...)
Definition SkCodecPriv.h:23
@ kBGRA_8888_SkColorType
pixel with 8 bits for blue, green, red, alpha; in 32-bit word
Definition SkColorType.h:26
@ kRGB_565_SkColorType
pixel with 5 bits red, 6 bits green, 5 bits blue, in 16-bit word
Definition SkColorType.h:22
@ kRGBA_8888_SkColorType
pixel with 8 bits for red, green, blue, alpha; in 32-bit word
Definition SkColorType.h:24
SkISize dimensions() const
Definition SkCodec.h:230
const SkEncodedInfo & getEncodedInfo() const
Definition SkCodec.h:788
@ kIncompleteInput
Definition SkCodec.h:84
@ kInvalidParameters
Definition SkCodec.h:105
@ kUnimplemented
Definition SkCodec.h:123
@ kErrorInInput
Definition SkCodec.h:91
dst
Definition cp.py:12
const SkIRect * fSubset
Definition SkCodec.h:347
const skcms_ICCProfile * profile() const
SkISize dimensions() const
SkColorType colorType() const

The documentation for this class was generated from the following file: