5#ifndef FLUTTER_LIB_UI_PAINTING_IMAGE_GENERATOR_APNG_H_
6#define FLUTTER_LIB_UI_PAINTING_IMAGE_GENERATOR_APNG_H_
10#include "flutter/fml/endianness.h"
11#include "flutter/fml/logging.h"
13#define PNG_FIELD(T, name) \
18 T get_##name() const { \
19 return fml::BigEndianToArch<T>(name); \
21 void set_##name(T n) { \
22 name = fml::BigEndianToArch<T>(n); \
42 unsigned int frame_index)
override;
51 unsigned int frame_index,
52 std::optional<unsigned int> prior_frame)
override;
57 static constexpr uint8_t kPngSignature[8] = {137, 80, 78, 71, 13, 10, 26, 10};
58 static constexpr size_t kChunkCrcSize = 4;
61 kImageHeaderChunkType =
'IHDR',
62 kAnimationControlChunkType =
'acTL',
63 kImageDataChunkType =
'IDAT',
64 kFrameControlChunkType =
'fcTL',
65 kFrameDataChunkType =
'fdAT',
66 kImageTrailerChunkType =
'IEND',
74 void UpdateChunkCrc32();
77 uint32_t ComputeChunkCrc32();
80 class __attribute__((packed, aligned(1))) ImageHeaderChunkData {
90 class __attribute__((packed, aligned(1))) AnimationControlChunkData {
95 class __attribute__((packed, aligned(1))) FrameControlChunkData {
120 std::unique_ptr<SkCodec> codec;
123 std::vector<uint8_t> pixels;
126 std::optional<ImageGenerator::FrameInfo> frame_info;
129 unsigned int x_offset;
132 unsigned int y_offset;
137 APNGImage&& default_image,
138 unsigned int frame_count,
139 unsigned int play_count,
140 const void* next_chunk_p,
141 const std::vector<uint8_t>&
header);
143 static bool IsValidChunkHeader(
const void*
buffer,
145 const ChunkHeader* chunk);
147 static const ChunkHeader* GetNextChunk(
const void*
buffer,
149 const ChunkHeader* current_chunk);
154 template <
typename T>
155 static constexpr const T* CastChunkData(
const ChunkHeader* chunk) {
156 if constexpr (std::is_same_v<T, ImageHeaderChunkData>) {
157 FML_DCHECK(chunk->get_type() == kImageHeaderChunkType);
158 }
else if constexpr (std::is_same_v<T, AnimationControlChunkData>) {
159 FML_DCHECK(chunk->get_type() == kAnimationControlChunkType);
160 }
else if constexpr (std::is_same_v<T, FrameControlChunkData>) {
161 FML_DCHECK(chunk->get_type() == kFrameControlChunkType);
163 static_assert(!
sizeof(
T),
"Invalid chunk struct");
166 return reinterpret_cast<const T*
>(
reinterpret_cast<const uint8_t*
>(chunk) +
167 sizeof(ChunkHeader));
170 static constexpr size_t GetChunkSize(
const ChunkHeader* chunk) {
171 return sizeof(ChunkHeader) + chunk->get_data_length() + kChunkCrcSize;
174 static constexpr bool IsChunkCopySafe(
const ChunkHeader* chunk) {
177 return (chunk->get_type() & 0x20) != 0;
182 static std::pair<std::optional<std::vector<uint8_t>>,
const void*>
183 ExtractHeader(
const void* buffer_p,
size_t buffer_size);
189 static std::pair<std::optional<APNGImage>,
const void*> DemuxNextImage(
190 const void* buffer_p,
192 const std::vector<uint8_t>&
header,
193 const void* chunk_p);
195 bool DemuxNextImageInternal();
197 bool DemuxToImageIndex(
unsigned int image_index);
203 FML_DISALLOW_COPY_ASSIGN_AND_MOVE(APNGImageGenerator);
206 unsigned int frame_count_;
207 unsigned int play_count_;
211 std::vector<APNGImage> images_;
213 unsigned int first_frame_index_;
215 const void* next_chunk_p_;
216 std::vector<uint8_t> header_;
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
static uint32_t buffer_size(uint32_t offset, uint32_t maxAlignment)
unsigned int GetPlayCount() const override
The number of times an animated image should play through before playback stops.
unsigned int GetFrameCount() const override
Get the number of frames that the encoded image stores. This method is always expected to be called b...
const SkImageInfo & GetInfo() override
Returns basic information about the contents of the encoded image. This information can almost always...
SkISize GetScaledDimensions(float desired_scale) override
Given a scale value, find the closest image size that can be used for efficiently decoding the image....
const ImageGenerator::FrameInfo GetFrameInfo(unsigned int frame_index) override
Get information about a single frame in the context of a multi-frame image, useful for animation and ...
static std::unique_ptr< ImageGenerator > MakeFromData(sk_sp< SkData > data)
bool GetPixels(const SkImageInfo &info, void *pixels, size_t row_bytes, unsigned int frame_index, std::optional< unsigned int > prior_frame) override
Decode the image into a given buffer. This method is currently always used for sub-pixel image decodi...
The minimal interface necessary for defining a decoder that can be used for both single and multi-fra...
#define FML_DCHECK(condition)
#define PNG_FIELD(T, name)
__attribute__((visibility("default"))) int RunBenchmarks(int argc
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot data
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
static const char header[]
Info about a single frame in the context of a multi-frame image, useful for animation and blending.