Flutter Engine
The Flutter Engine
Classes | Static Public Member Functions | Protected Member Functions | List of all members
SkAvifCodec Class Reference

#include <SkAvifCodec.h>

Inheritance diagram for SkAvifCodec:
SkScalingCodec SkCodec SkNoncopyable

Static Public Member Functions

static bool IsAvif (const void *, size_t)
 
static std::unique_ptr< SkCodecMakeFromStream (std::unique_ptr< SkStream >, Result *)
 
- 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 *))
 

Protected Member Functions

Result onGetPixels (const SkImageInfo &dstInfo, void *dst, size_t dstRowBytes, const Options &options, int *rowsDecoded) override
 
SkEncodedImageFormat onGetEncodedFormat () const override
 
int onGetFrameCount () override
 
bool onGetFrameInfo (int, FrameInfo *) const override
 
int onGetRepetitionCount () override
 
const SkFrameHoldergetFrameHolder () const override
 
- 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 SkISize onGetScaledDimensions (float) const
 
virtual bool onDimensionsSupported (const SkISize &)
 
virtual SkEncodedImageFormat onGetEncodedFormat () const =0
 
virtual Result onGetPixels (const SkImageInfo &info, void *pixels, size_t rowBytes, const Options &, int *rowsDecoded)=0
 
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
 
virtual int onGetFrameCount ()
 
virtual bool onGetFrameInfo (int, FrameInfo *) const
 
virtual int onGetRepetitionCount ()
 

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 }
 
- 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
 
virtual std::unique_ptr< SkStreamgetEncodedData () 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 ()
 
- 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
 

Detailed Description

Definition at line 32 of file SkAvifCodec.h.

Member Function Documentation

◆ getFrameHolder()

const SkFrameHolder * SkAvifCodec::getFrameHolder ( ) const
inlineoverrideprotectedvirtual

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

Reimplemented from SkCodec.

Definition at line 56 of file SkAvifCodec.h.

56{ return &fFrameHolder; }

◆ IsAvif()

bool SkAvifCodec::IsAvif ( const void *  buffer,
size_t  bytesRead 
)
static

Definition at line 33 of file SkAvifCodec.cpp.

33 {
34 avifROData avifData = {static_cast<const uint8_t*>(buffer), bytesRead};
35 bool isAvif = avifPeekCompatibleFileType(&avifData) == AVIF_TRUE;
36 if (isAvif) return true;
37 // Peeking sometimes fails if the ftyp box is too large. Check the signature
38 // just to be sure.
39 const char* bytes = static_cast<const char*>(buffer);
40 isAvif = bytesRead >= 12 && !memcmp(&bytes[4], "ftyp", 4) &&
41 (!memcmp(&bytes[8], "avif", 4) || !memcmp(&bytes[8], "avis", 4));
42 return isAvif;
43}
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace buffer
Definition: switches.h:126

◆ MakeFromStream()

std::unique_ptr< SkCodec > SkAvifCodec::MakeFromStream ( std::unique_ptr< SkStream stream,
Result result 
)
static

Definition at line 45 of file SkAvifCodec.cpp.

46 {
48 if (!stream) {
50 return nullptr;
51 }
52 AvifDecoder avifDecoder(avifDecoderCreate());
53 if (avifDecoder == nullptr) {
55 return nullptr;
56 }
57 avifDecoder->ignoreXMP = AVIF_TRUE;
58 avifDecoder->ignoreExif = AVIF_TRUE;
59 avifDecoder->allowProgressive = AVIF_FALSE;
60 avifDecoder->allowIncremental = AVIF_FALSE;
61 avifDecoder->strictFlags = AVIF_STRICT_DISABLED;
62 // TODO(vigneshv): Enable threading based on number of CPU cores available.
63 avifDecoder->maxThreads = 1;
64
65 // libavif needs a contiguous data buffer.
66 sk_sp<SkData> data = nullptr;
67 if (stream->getMemoryBase()) {
68 // It is safe to make without copy because we'll hold onto the stream.
70 } else {
72 // If we are forced to copy the stream to a data, we can go ahead and
73 // delete the stream.
74 stream.reset(nullptr);
75 }
76
77 avifResult res = avifDecoderSetIOMemory(avifDecoder.get(), data->bytes(), data->size());
78 if (res != AVIF_RESULT_OK) {
80 return nullptr;
81 }
82
83 res = avifDecoderParse(avifDecoder.get());
84 if (res != AVIF_RESULT_OK) {
86 return nullptr;
87 }
88
89 std::unique_ptr<SkEncodedInfo::ICCProfile> profile = nullptr;
90 // TODO(vigneshv): Get ICC Profile from the avif decoder.
91
92 const int bitsPerComponent = avifDecoder->image->depth > 8 ? 16 : 8;
95 if (avifDecoder->alphaPresent) {
98 } else {
101 }
102 SkEncodedInfo info = SkEncodedInfo::Make(avifDecoder->image->width,
103 avifDecoder->image->height,
104 color,
105 alpha,
106 bitsPerComponent,
107 std::move(profile),
108 avifDecoder->image->depth);
109 bool animation = avifDecoder->imageCount > 1;
110 *result = kSuccess;
111 return std::unique_ptr<SkCodec>(new SkAvifCodec(std::move(info),
112 std::move(stream),
113 std::move(data),
114 std::move(avifDecoder),
116 animation));
117}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
#define SkASSERT(cond)
Definition: SkAssert.h:116
std::unique_ptr< avifDecoder, AvifDecoderDeleter > AvifDecoder
Definition: SkAvifCodec.h:30
@ kDefault_SkEncodedOrigin
sk_sp< SkData > SkCopyStreamToData(SkStream *stream)
Definition: SkStream.cpp:937
SkStream * stream()
Definition: SkCodec.h:865
@ kInvalidInput
Definition: SkCodec.h:109
@ kInternalError
Definition: SkCodec.h:118
@ kSuccess
Definition: SkCodec.h:80
static sk_sp< SkData > MakeWithoutCopy(const void *data, size_t length)
Definition: SkData.h:116
virtual size_t getLength() const
Definition: SkStream.h:137
virtual const void * getMemoryBase()
Definition: SkStream.h:141
DlColor color
GAsyncResult * result
static SkEncodedInfo Make(int width, int height, Color color, Alpha alpha, int bitsPerComponent)
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63

◆ onGetEncodedFormat()

SkEncodedImageFormat SkAvifCodec::onGetEncodedFormat ( ) const
inlineoverrideprotectedvirtual

Implements SkCodec.

Definition at line 51 of file SkAvifCodec.h.

◆ onGetFrameCount()

int SkAvifCodec::onGetFrameCount ( )
overrideprotectedvirtual

Reimplemented from SkCodec.

Definition at line 130 of file SkAvifCodec.cpp.

130 {
131 if (!fUseAnimation) {
132 return 1;
133 }
134
135 if (fFrameHolder.size() == 0) {
136 if (fAvifDecoder->imageCount <= 1) {
137 fUseAnimation = false;
138 return 1;
139 }
140 fFrameHolder.reserve(fAvifDecoder->imageCount);
141 for (int i = 0; i < fAvifDecoder->imageCount; i++) {
142 Frame* frame = fFrameHolder.appendNewFrame(fAvifDecoder->alphaPresent == AVIF_TRUE);
143 frame->setXYWH(0, 0, fAvifDecoder->image->width, fAvifDecoder->image->height);
145 avifImageTiming timing;
146 avifDecoderNthImageTiming(fAvifDecoder.get(), i, &timing);
147 frame->setDuration(timing.duration * 1000);
148 frame->setRequiredFrame(SkCodec::kNoFrame);
149 frame->setHasAlpha(fAvifDecoder->alphaPresent == AVIF_TRUE);
150 }
151 }
152
153 return fFrameHolder.size();
154}
static constexpr int kNoFrame
Definition: SkCodec.h:650
double frame
Definition: examples.cpp:31

◆ onGetFrameInfo()

bool SkAvifCodec::onGetFrameInfo ( int  i,
FrameInfo frameInfo 
) const
overrideprotectedvirtual

Reimplemented from SkCodec.

Definition at line 172 of file SkAvifCodec.cpp.

172 {
173 if (i >= fFrameHolder.size()) {
174 return false;
175 }
176
177 const Frame* frame = fFrameHolder.frame(i);
178 if (!frame) {
179 return false;
180 }
181
182 if (frameInfo) {
183 frame->fillIn(frameInfo, true);
184 }
185
186 return true;
187}

◆ onGetPixels()

SkCodec::Result SkAvifCodec::onGetPixels ( const SkImageInfo info,
void *  pixels,
size_t  rowBytes,
const Options ,
int rowsDecoded 
)
overrideprotectedvirtual
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 191 of file SkAvifCodec.cpp.

195 {
196 if (options.fSubset) {
197 return kUnimplemented;
198 }
199
200 const SkColorType dstColorType = dstInfo.colorType();
201 if (dstColorType != kRGBA_8888_SkColorType && dstColorType != kRGBA_F16_SkColorType) {
202 // TODO(vigneshv): Check if more color types need to be supported.
203 // Currently android supports at least RGB565 and BGRA8888 which is not
204 // supported here.
205 return kUnimplemented;
206 }
207
208 avifResult result = avifDecoderNthImage(fAvifDecoder.get(), options.fFrameIndex);
209 if (result != AVIF_RESULT_OK) {
210 return kInvalidInput;
211 }
212
213 if (this->dimensions() != dstInfo.dimensions()) {
214 result = avifImageScale(
215 fAvifDecoder->image, dstInfo.width(), dstInfo.height(), &fAvifDecoder->diag);
216 if (result != AVIF_RESULT_OK) {
217 return kInvalidInput;
218 }
219 }
220
221 avifRGBImage rgbImage;
222 avifRGBImageSetDefaults(&rgbImage, fAvifDecoder->image);
223
224 if (dstColorType == kRGBA_8888_SkColorType) {
225 rgbImage.depth = 8;
226 } else if (dstColorType == kRGBA_F16_SkColorType) {
227 rgbImage.depth = 16;
228 rgbImage.isFloat = AVIF_TRUE;
229 }
230
231 rgbImage.pixels = static_cast<uint8_t*>(dst);
232 rgbImage.rowBytes = dstRowBytes;
233 rgbImage.chromaUpsampling = AVIF_CHROMA_UPSAMPLING_FASTEST;
234
235 result = avifImageYUVToRGB(fAvifDecoder->image, &rgbImage);
236 if (result != AVIF_RESULT_OK) {
237 return kInvalidInput;
238 }
239
240 *rowsDecoded = fAvifDecoder->image->height;
241 return kSuccess;
242}
SkColorType
Definition: SkColorType.h:19
@ kRGBA_F16_SkColorType
pixel with half floats for red, green, blue, alpha;
Definition: SkColorType.h:38
@ 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 SkImageInfo & dstInfo() const
Definition: SkCodec.h:878
@ kUnimplemented
Definition: SkCodec.h:123
const Options & options() const
Definition: SkCodec.h:880
dst
Definition: cp.py:12
const SkIRect * fSubset
Definition: SkCodec.h:347
SkISize dimensions() const
Definition: SkImageInfo.h:421
int width() const
Definition: SkImageInfo.h:365
SkColorType colorType() const
Definition: SkImageInfo.h:373
int height() const
Definition: SkImageInfo.h:371

◆ onGetRepetitionCount()

int SkAvifCodec::onGetRepetitionCount ( )
overrideprotectedvirtual

Reimplemented from SkCodec.

Definition at line 189 of file SkAvifCodec.cpp.

189{ return kRepetitionCountInfinite; }
static constexpr int kRepetitionCountInfinite
Definition: SkCodec.h:759

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