1/* Fake a PNG - just write it out directly. */ 2#include <stdio.h> 3#include <zlib.h> /* for crc32 */ 4 5void 6put_uLong(uLong val) 7{ 8 putchar(val >> 24); 9 putchar(val >> 16); 10 putchar(val >> 8); 11 putchar(val >> 0); 12} 13 14void 15put_chunk(const unsigned char *chunk, uInt length) 16{ 17 uLong crc; 18 19 put_uLong(length-4); /* Exclude the tag */ 20 21 fwrite(chunk, length, 1, stdout); 22 23 crc = crc32(0, Z_NULL, 0); 24 put_uLong(crc32(crc, chunk, length)); 25} 26 27const unsigned char signature[] = 28{ 29 137, 80, 78, 71, 13, 10, 26, 10 30}; 31 32const unsigned char IHDR[] = 33{ 34 73, 72, 68, 82, /* IHDR */ 35 0, 0, 0, 1, /* width */ 36 0, 0, 0, 1, /* height */ 37 1, /* bit depth */ 38 0, /* color type: greyscale */ 39 0, /* compression method */ 40 0, /* filter method */ 41 0 /* interlace method: none */ 42}; 43 44const unsigned char unknown[] = 45{ 46 'u', 'n', 'K', 'n' /* "unKn" - private safe to copy */ 47}; 48 49int 50main(void) 51{ 52 fwrite(signature, sizeof signature, 1, stdout); 53 put_chunk(IHDR, sizeof IHDR); 54 55 for(;;) 56 put_chunk(unknown, sizeof unknown); 57} 58