fakepng.c 1.0 KB

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