38 { 0, 0, 0 }, { 255, 0, 0 }, { 0, 255, 0 }, { 0, 0, 255 },
39 { 255, 255, 0 }, { 255, 0, 255 }, { 0, 255, 255 }, { 255, 128, 0 },
40 { 128, 0, 255 }, { 128, 255, 0 }, { 0, 128, 255 }, { 255, 0, 128 },
41 { 64, 64, 64 }, { 192, 192, 192 }, { 128, 64, 0 }, { 255, 255, 255 },
158 static const uint8_t
sig[8] = { 137, 80, 78, 71, 13, 10, 26, 10 };
160 uint8_t actl[8] = { 0, 0, 0,
FRAMES, 0, 0, 0, 1 };
161 uint8_t plte[16 * 3], raw[512], fctl[26];
162 Buf out = { 0 }, image = { 0 };
164 int colors = 1 << depth, seq = 0,
frame,
i;
166 for (
i = 0;
i < colors;
i++)
170 chunk(&
out,
"IHDR", ihdr,
sizeof(ihdr));
171 chunk(&
out,
"acTL", actl,
sizeof(actl));
172 chunk(&
out,
"PLTE", plte, colors * 3);
175 int sub =
frame != 0;
176 int x = sub ? 1 + 2 * (
frame - 1) : 0;
177 int y = sub ? 1 + (
frame - 1) : 0;
181 memset(fctl, 0,
sizeof(fctl));
189 chunk(&
out,
"fcTL", fctl,
sizeof(fctl));
195 chunk(&
out, sub ?
"fdAT" :
"IDAT", image.data, image.len);
199 f = fopen(
path,
"wb");
200 if (!
f || fwrite(
out.data, 1,
out.len,
f) != (
size_t)
out.len || fclose(
f))