126 {
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;
131 break;
132 }
133 }
134
136 if (!codec) {
138 return 1;
139 }
140 codec->getInfo().makeColorSpace(nullptr);
144
145
148
149 uint64_t totalDurationMillis = 0;
150 const int frameCount = codec->getFrameCount();
151 if (frameCount == 0) {
153 return 1;
154 }
155 std::vector<SkCodec::FrameInfo> frameInfos = codec->getFrameInfo();
156 bool stillImage = frameInfos.size() <= 1;
157
158 for (
int i = 0;
i < frameCount;
i++) {
161
162 if (!stillImage) {
163 int durationMillis = frameInfos[
i].fDuration;
164 if (durationMillis < 0) {
165 SkDebugf(
"Negative animation duration.\n");
166 return 1;
167 }
168 totalDurationMillis += static_cast<uint64_t>(durationMillis);
169 if (totalDurationMillis > INT64_MAX) {
170 SkDebugf(
"Unsupported animation duration.\n");
171 return 1;
172 }
173
175 (cachedFrame == frameInfos[
i].fRequiredFrame) && cachedFramePixels.
get()) {
177 memcpy(bm.
getPixels(), cachedFramePixels.
get(), bmByteSize);
178 }
179 }
180
181 if (!firstFrameOnly) {
185 }
186
188 SkDebugf(
"Unsupported animation duration.\n");
189 return 1;
190 }
191 }
192
196 SkDebugf(
"Decode frame pixels #%d failed.\n",
i);
197 return 1;
198 }
199
200
201
202
203 if ((
static_cast<size_t>(
i + 1) < frameInfos.size()) &&
204 (frameInfos[
i + 1].fRequiredFrame ==
i)) {
206 memcpy(cachedFramePixels.
reset(bmByteSize), bm.
getPixels(), bmByteSize);
207 }
208
216 return 1;
217 }
218 if (firstFrameOnly) {
219 return 0;
220 }
222 }
224 return 0;
225}
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
void * reset(size_t size=0, OnShrink shrink=kAlloc_OnShrink)
void allocPixels(const SkImageInfo &info, size_t rowBytes)
size_t computeByteSize() const
static std::unique_ptr< SkCodec > MakeFromData(sk_sp< SkData >, SkSpan< const SkCodecs::Decoder > decoders, SkPngChunkReader *=nullptr)
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)
static bool write_nia_duration(uint64_t totalDurationMillis)
static void write_nix_header(uint32_t magicU32le, uint32_t width, uint32_t height)
static void write_nia_footer(int repetitionCount, bool stillImage)