40static inline void set_u32le(uint8_t* ptr, uint32_t val) {
47static inline void set_u64le(uint8_t* ptr, uint64_t val) {
64 fwrite(
data, 1, 16, stdout);
70 static constexpr uint64_t flicksPerMilli = 705600;
71 if (totalDurationMillis > (INT64_MAX / flicksPerMilli)) {
78 fwrite(
data, 1, 8, stdout);
87 for (uint32_t
x = 0;
x <
width;
x++) {
94 fwrite(buf, 1, n, stdout);
100 fwrite(buf, 1, n, stdout);
109 fwrite(
data, 1, 4, stdout);
123 fwrite(
data, 1, 8, stdout);
127 bool firstFrameOnly =
false;
128 for (
int a = 1;
a < argc;
a++) {
129 if ((strcmp(
argv[
a],
"-1") == 0) || (strcmp(
argv[
a],
"-first-frame-only") == 0)) {
130 firstFrameOnly =
true;
140 codec->getInfo().makeColorSpace(
nullptr);
149 uint64_t totalDurationMillis = 0;
150 const int frameCount = codec->getFrameCount();
151 if (frameCount == 0) {
155 std::vector<SkCodec::FrameInfo> frameInfos = codec->getFrameInfo();
156 bool stillImage = frameInfos.size() <= 1;
158 for (
int i = 0;
i < frameCount;
i++) {
163 int durationMillis = frameInfos[
i].fDuration;
164 if (durationMillis < 0) {
165 SkDebugf(
"Negative animation duration.\n");
168 totalDurationMillis +=
static_cast<uint64_t
>(durationMillis);
169 if (totalDurationMillis > INT64_MAX) {
170 SkDebugf(
"Unsupported animation duration.\n");
175 (cachedFrame == frameInfos[
i].fRequiredFrame) && cachedFramePixels.
get()) {
177 memcpy(bm.
getPixels(), cachedFramePixels.
get(), bmByteSize);
181 if (!firstFrameOnly) {
188 SkDebugf(
"Unsupported animation duration.\n");
196 SkDebugf(
"Decode frame pixels #%d failed.\n",
i);
203 if ((
static_cast<size_t>(
i + 1) < frameInfos.size()) &&
204 (frameInfos[
i + 1].fRequiredFrame ==
i)) {
206 memcpy(cachedFramePixels.
reset(bmByteSize), bm.
getPixels(), bmByteSize);
218 if (firstFrameOnly) {
#define SkColorGetR(color)
#define SkColorGetG(color)
#define SkColorGetA(color)
#define SkColorGetB(color)
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
static const size_t kBufferSize
void * reset(size_t size=0, OnShrink shrink=kAlloc_OnShrink)
void allocPixels(const SkImageInfo &info, size_t rowBytes)
SkColor getColor(int x, int y) const
size_t computeByteSize() const
static std::unique_ptr< SkCodec > MakeFromData(sk_sp< SkData >, SkSpan< const SkCodecs::Decoder > decoders, SkPngChunkReader *=nullptr)
static constexpr int kRepetitionCountInfinite
static constexpr int kNoFrame
static sk_sp< SkData > MakeFromFILE(FILE *f)
static void write_nie_pixels(uint32_t width, uint32_t height, const SkBitmap &bm)
static void write_nia_padding(uint32_t width, uint32_t height)
int main(int argc, char **argv)
static void set_u64le(uint8_t *ptr, uint64_t val)
static bool write_nia_duration(uint64_t totalDurationMillis)
static void set_u32le(uint8_t *ptr, uint32_t val)
static void write_nix_header(uint32_t magicU32le, uint32_t width, uint32_t height)
static void write_nia_footer(int repetitionCount, bool stillImage)
std::shared_ptr< const fml::Mapping > data