51 { 0, 0, 0 }, { 255, 0, 0 }, { 0, 255, 0 }, { 0, 0, 255 },
52 { 255, 255, 0 }, { 255, 0, 255 }, { 0, 255, 255 }, { 255, 128, 0 },
53 { 128, 0, 255 }, { 128, 255, 0 }, { 0, 128, 255 }, { 255, 0, 128 },
54 { 64, 64, 64 }, { 192, 192, 192 }, { 128, 64, 0 }, { 255, 255, 255 },
172 static const uint8_t
sig[8] = { 137, 80, 78, 71, 13, 10, 26, 10 };
174 uint8_t actl[8] = { 0, 0, 0,
FRAMES, 0, 0, 0, 1 };
175 uint8_t plte[16 * 3], raw[512], fctl[26];
176 Buf out = { 0 }, image = { 0 };
180 if (anc_after_ihdr < 0 || anc_after_ihdr >
ANC_SIZE) {
181 fprintf(stderr,
"apnggen: ancillary payload does not fit\n");
185 for (
i = 0;
i < colors;
i++)
189 chunk(&
out,
"IHDR", ihdr,
sizeof(ihdr));
193 chunk(&
out,
"acTL", actl,
sizeof(actl));
194 chunk(&
out,
"PLTE", plte, colors * 3);
199 int sub =
frame != 0;
200 int x = sub ? 1 + 2 * (
frame - 1) : 0;
201 int y = sub ? 1 + (
frame - 1) : 0;
206 memset(fctl, 0,
sizeof(fctl));
214 chunk(&
out,
"fcTL", fctl,
sizeof(fctl));
221 chunk(&
out, sub ?
"fdAT" :
"IDAT", image.data, image.len);
225 f = fopen(
path,
"wb");
226 if (!
f || fwrite(
out.data, 1,
out.len,
f) != (
size_t)
out.len || fclose(
f))