fukasawa e60969
/* Fake a PNG - just write it out directly.
fukasawa e60969
 *
fukasawa e60969
 * COPYRIGHT: Written by John Cunningham Bowler, 2014.
fukasawa e60969
 * To the extent possible under law, the author has waived all copyright and
fukasawa e60969
 * related or neighboring rights to this work.  This work is published from:
fukasawa e60969
 * United States.
fukasawa e60969
 *
fukasawa e60969
 */
fukasawa e60969
fukasawa e60969
#include <stdio.h></stdio.h>
fukasawa e60969
#include <zlib.h> /* for crc32 */</zlib.h>
fukasawa e60969
fukasawa e60969
void
fukasawa e60969
put_uLong(uLong val)
fukasawa e60969
{
fukasawa e60969
   putchar(val >> 24);
fukasawa e60969
   putchar(val >> 16);
fukasawa e60969
   putchar(val >>  8);
fukasawa e60969
   putchar(val >>  0);
fukasawa e60969
}
fukasawa e60969
fukasawa e60969
void
fukasawa e60969
put_chunk(const unsigned char *chunk, uInt length)
fukasawa e60969
{
fukasawa e60969
   uLong crc;
fukasawa e60969
fukasawa e60969
   put_uLong(length-4); /* Exclude the tag */
fukasawa e60969
fukasawa e60969
   fwrite(chunk, length, 1, stdout);
fukasawa e60969
fukasawa e60969
   crc = crc32(0, Z_NULL, 0);
fukasawa e60969
   put_uLong(crc32(crc, chunk, length));
fukasawa e60969
}
fukasawa e60969
fukasawa e60969
const unsigned char signature[] =
fukasawa e60969
{
fukasawa e60969
   137, 80, 78, 71, 13, 10, 26, 10
fukasawa e60969
};
fukasawa e60969
fukasawa e60969
const unsigned char IHDR[] =
fukasawa e60969
{
fukasawa e60969
   73, 72, 68, 82, /* IHDR */
fukasawa e60969
   0, 0, 0, 1, /* width */
fukasawa e60969
   0, 0, 0, 1, /* height */
fukasawa e60969
   1, /* bit depth */
fukasawa e60969
   0, /* color type: greyscale */
fukasawa e60969
   0, /* compression method */
fukasawa e60969
   0, /* filter method */
fukasawa e60969
   0  /* interlace method: none */
fukasawa e60969
};
fukasawa e60969
fukasawa e60969
const unsigned char unknown[] =
fukasawa e60969
{
fukasawa e60969
   'u', 'n', 'K', 'n' /* "unKn" - private safe to copy */
fukasawa e60969
};
fukasawa e60969
fukasawa e60969
int
fukasawa e60969
main(void)
fukasawa e60969
{
fukasawa e60969
   fwrite(signature, sizeof signature, 1, stdout);
fukasawa e60969
   put_chunk(IHDR, sizeof IHDR);
fukasawa e60969
fukasawa e60969
   for (;;)
fukasawa e60969
      put_chunk(unknown, sizeof unknown);
fukasawa e60969
}