pngtogd2.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include "gd.h"
  4. /* A short program which converts a .png file into a .gd file, for
  5. your convenience in creating images on the fly from a
  6. basis image that must be loaded quickly. The .gd format
  7. is not intended to be a general-purpose format. */
  8. int
  9. main (int argc, char **argv)
  10. {
  11. gdImagePtr im;
  12. FILE *in, *out;
  13. int cs, fmt;
  14. if (argc != 5)
  15. {
  16. fprintf (stderr, "Usage: pngtogd2 filename.png filename.gd2 cs fmt\n");
  17. fprintf (stderr, " where cs is the chunk size\n");
  18. fprintf (stderr, " fmt is 1 for raw, 2 for compressed\n");
  19. exit (1);
  20. }
  21. in = fopen (argv[1], "rb");
  22. if (!in)
  23. {
  24. fprintf (stderr, "Input file does not exist!\n");
  25. exit (1);
  26. }
  27. im = gdImageCreateFromPng (in);
  28. fclose (in);
  29. if (!im)
  30. {
  31. fprintf (stderr, "Input is not in PNG format!\n");
  32. exit (1);
  33. }
  34. out = fopen (argv[2], "wb");
  35. if (!out)
  36. {
  37. fprintf (stderr, "Output file cannot be written to!\n");
  38. gdImageDestroy (im);
  39. exit (1);
  40. }
  41. cs = atoi (argv[3]);
  42. fmt = atoi (argv[4]);
  43. gdImageGd2 (im, out, cs, fmt);
  44. fclose (out);
  45. gdImageDestroy (im);
  46. return 0;
  47. }