home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / gd201.zip / gd-2.0.1 / gd2copypal.c < prev    next >
C/C++ Source or Header  |  2001-04-03  |  1KB  |  65 lines

  1.  
  2. #include <stdio.h>
  3. #include "gd.h"
  4.  
  5. /* A short program which converts a .png file into a .gd file, for
  6.    your convenience in creating images on the fly from a
  7.    basis image that must be loaded quickly. The .gd format
  8.    is not intended to be a general-purpose format. */
  9.  
  10. int
  11. main (int argc, char **argv)
  12. {
  13.   gdImagePtr im;
  14.   gdImagePtr pal;
  15.   FILE *in, *out;
  16.   if (argc != 3)
  17.     {
  18.       fprintf (stderr, "Usage: gd2copypal palettefile.gd2 filename.gd2\n");
  19.       exit (1);
  20.     }
  21.   in = fopen (argv[1], "rb");
  22.   if (!in)
  23.     {
  24.       fprintf (stderr, "Palette file does not exist!\n");
  25.       exit (1);
  26.     }
  27.   pal = gdImageCreateFromGd2 (in);
  28.   fclose (in);
  29.   if (!pal)
  30.     {
  31.       fprintf (stderr, "Palette is not in GD2 format!\n");
  32.       exit (1);
  33.     }
  34.  
  35.   in = fopen (argv[2], "rb");
  36.   if (!in)
  37.     {
  38.       fprintf (stderr, "Input file does not exist!\n");
  39.       exit (1);
  40.     }
  41.   im = gdImageCreateFromGd2 (in);
  42.   fclose (in);
  43.   if (!im)
  44.     {
  45.       fprintf (stderr, "Input is not in GD2 format!\n");
  46.       exit (1);
  47.     }
  48.  
  49.   gdImagePaletteCopy (im, pal);
  50.  
  51.   out = fopen (argv[2], "wb");
  52.   if (!out)
  53.     {
  54.       fprintf (stderr, "Output file cannot be written to!\n");
  55.       gdImageDestroy (im);
  56.       exit (1);
  57.     }
  58.   gdImageGd2 (im, out, 128, 2);
  59.   fclose (out);
  60.   gdImageDestroy (pal);
  61.   gdImageDestroy (im);
  62.  
  63.   return 0;
  64. }
  65.