beta-0.89.2
[luatex.git] / source / libs / libpng / libpng-src / contrib / libtests / fakepng.c
blob6512c1401049bed7b1f2ab3aff163e7dd3ef53d2
1 /* Fake a PNG - just write it out directly.
3 * COPYRIGHT: Written by John Cunningham Bowler, 2014.
4 * To the extent possible under law, the author has waived all copyright and
5 * related or neighboring rights to this work. This work is published from:
6 * United States.
8 */
10 #include <stdio.h>
11 #include <zlib.h> /* for crc32 */
13 void
14 put_uLong(uLong val)
16 putchar(val >> 24);
17 putchar(val >> 16);
18 putchar(val >> 8);
19 putchar(val >> 0);
22 void
23 put_chunk(const unsigned char *chunk, uInt length)
25 uLong crc;
27 put_uLong(length-4); /* Exclude the tag */
29 fwrite(chunk, length, 1, stdout);
31 crc = crc32(0, Z_NULL, 0);
32 put_uLong(crc32(crc, chunk, length));
35 const unsigned char signature[] =
37 137, 80, 78, 71, 13, 10, 26, 10
40 const unsigned char IHDR[] =
42 73, 72, 68, 82, /* IHDR */
43 0, 0, 0, 1, /* width */
44 0, 0, 0, 1, /* height */
45 1, /* bit depth */
46 0, /* color type: greyscale */
47 0, /* compression method */
48 0, /* filter method */
49 0 /* interlace method: none */
52 const unsigned char unknown[] =
54 'u', 'n', 'K', 'n' /* "unKn" - private safe to copy */
57 int
58 main(void)
60 fwrite(signature, sizeof signature, 1, stdout);
61 put_chunk(IHDR, sizeof IHDR);
63 for (;;)
64 put_chunk(unknown, sizeof unknown);