28 if (decoder !=
nullptr) {
29 avifDecoderDestroy(decoder);
34 avifROData avifData = {
static_cast<const uint8_t*
>(
buffer), bytesRead};
35 bool isAvif = avifPeekCompatibleFileType(&avifData) == AVIF_TRUE;
36 if (isAvif)
return true;
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));
53 if (avifDecoder ==
nullptr) {
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;
63 avifDecoder->maxThreads = 1;
77 avifResult res = avifDecoderSetIOMemory(avifDecoder.get(),
data->bytes(),
data->size());
78 if (res != AVIF_RESULT_OK) {
83 res = avifDecoderParse(avifDecoder.get());
84 if (res != AVIF_RESULT_OK) {
89 std::unique_ptr<SkEncodedInfo::ICCProfile>
profile =
nullptr;
92 const int bitsPerComponent = avifDecoder->image->depth > 8 ? 16 : 8;
95 if (avifDecoder->alphaPresent) {
103 avifDecoder->image->height,
108 avifDecoder->image->depth);
109 bool animation = avifDecoder->imageCount > 1;
114 std::move(avifDecoder),
120 std::unique_ptr<SkStream>
stream,
127 , fAvifDecoder(
std::move(avifDecoder))
128 , fUseAnimation(useAnimation) {}
131 if (!fUseAnimation) {
135 if (fFrameHolder.size() == 0) {
136 if (fAvifDecoder->imageCount <= 1) {
137 fUseAnimation =
false;
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);
149 frame->setHasAlpha(fAvifDecoder->alphaPresent == AVIF_TRUE);
153 return fFrameHolder.size();
156const SkFrame* SkAvifCodec::FrameHolder::onGetFrame(
int i)
const {
160SkAvifCodec::Frame* SkAvifCodec::FrameHolder::appendNewFrame(
bool hasAlpha) {
161 const int i = this->
size();
162 fFrames.emplace_back(
i,
173 if (
i >= fFrameHolder.size()) {
177 const Frame*
frame = fFrameHolder.frame(
i);
183 frame->fillIn(frameInfo,
true);
209 if (
result != AVIF_RESULT_OK) {
216 if (
result != AVIF_RESULT_OK) {
221 avifRGBImage rgbImage;
222 avifRGBImageSetDefaults(&rgbImage, fAvifDecoder->image);
228 rgbImage.isFloat = AVIF_TRUE;
231 rgbImage.pixels =
static_cast<uint8_t*
>(
dst);
232 rgbImage.rowBytes = dstRowBytes;
233 rgbImage.chromaUpsampling = AVIF_CHROMA_UPSAMPLING_FASTEST;
235 result = avifImageYUVToRGB(fAvifDecoder->image, &rgbImage);
236 if (
result != AVIF_RESULT_OK) {
240 *rowsDecoded = fAvifDecoder->image->height;
254 outResult = &resultStorage;
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
std::unique_ptr< avifDecoder, AvifDecoderDeleter > AvifDecoder
@ kRGBA_F16_SkColorType
pixel with half floats for red, green, blue, alpha;
@ kRGBA_8888_SkColorType
pixel with 8 bits for red, green, blue, alpha; in 32-bit word
@ kDefault_SkEncodedOrigin
#define INHERITED(method,...)
sk_sp< SkData > SkCopyStreamToData(SkStream *stream)
int onGetRepetitionCount() override
static std::unique_ptr< SkCodec > MakeFromStream(std::unique_ptr< SkStream >, Result *)
static bool IsAvif(const void *, size_t)
bool onGetFrameInfo(int, FrameInfo *) const override
int onGetFrameCount() override
Result onGetPixels(const SkImageInfo &dstInfo, void *dst, size_t dstRowBytes, const Options &options, int *rowsDecoded) override
SkISize dimensions() const
const SkImageInfo & dstInfo() const
static constexpr int kRepetitionCountInfinite
static constexpr int kNoFrame
const Options & options() const
static sk_sp< SkData > MakeWithoutCopy(const void *data, size_t length)
static std::unique_ptr< SkMemoryStream > Make(sk_sp< SkData > data)
virtual size_t getLength() const
virtual const void * getMemoryBase()
SK_API bool IsAvif(const void *, size_t)
SK_API std::unique_ptr< SkCodec > Decode(std::unique_ptr< SkStream >, SkCodec::Result *, SkCodecs::DecodeContext=nullptr)
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
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
@ skcms_PixelFormat_RGBA_8888
void operator()(avifDecoder *decoder) const
static SkEncodedInfo Make(int width, int height, Color color, Alpha alpha, int bitsPerComponent)
SkISize dimensions() const
SkColorType colorType() const
std::shared_ptr< const fml::Mapping > data