home *** CD-ROM | disk | FTP | other *** search
/ C++ Games Programming / CPPGAMES.ISO / thx / source / utils / getpal.cpp < prev    next >
C/C++ Source or Header  |  1995-05-12  |  2KB  |  74 lines

  1. #include <fastgraf.h>
  2.  
  3. #include <fstream.h>
  4. #include <io.h>
  5. #include <dir.h>
  6. #include <string.h>
  7.  
  8. const int OK = 1;
  9.  
  10. int save_palette(char* fname);
  11.  
  12. int main(int argc,char** argv)
  13.   {
  14.   char palfilename[MAXPATH];
  15.   if (argc<2)
  16.     {
  17.     cout << "\nUSAGE : GETPAL <pcxfile> [palettefile]\n";
  18.     cout << "  GETPAL extracts a palette from 'pcxfile', and stores\n";
  19.     cout << "  it in the ASCII file 'palettefile'.  If no palettefile\n";
  20.     cout << "  name is supplied, the palette is stored in a file with\n";
  21.     cout << "  the same name as the pcxfile, but with a .PAL extension.\n";
  22.     return -1;
  23.     }
  24.  
  25.   if (argc==2)
  26.     {
  27.     strcpy(palfilename,argv[1]);
  28.     char* p=strchr(palfilename,'.');
  29.     if (p)  *p='\0';
  30.     strcat(palfilename,".pal");
  31.     }
  32.   else
  33.     strcpy(palfilename,argv[2]);
  34.  
  35.   if (access(argv[1],0)!=0)
  36.     {
  37.     cout << "can't open file '" << argv[1] << "'\n",argv[1];
  38.     return -1;
  39.     }
  40.  
  41.   int oldmode=fg_getmode();
  42.   fg_waitfor(18);
  43.   fg_setmode(22);
  44.   fg_showpcx(argv[1],0);
  45.  
  46.   save_palette(palfilename);
  47.  
  48.   fg_setmode(oldmode);
  49.   return 0;
  50.   }
  51.  
  52.  
  53. struct pal_entry       // struct compatible with the
  54.   {                    // fg_setdacs routine
  55.   unsigned char r;
  56.   unsigned char g;
  57.   unsigned char b;
  58.   };
  59.  
  60. pal_entry entry[256];
  61.  
  62. int save_palette(char* fname)
  63.   {
  64.   ofstream pal(fname);
  65.   pal << "NeoPaint Palette File\n";
  66.   pal << "(C)1992-93 NeoSoft Corp.\n";
  67.   pal << "256\n";
  68.   fg_getdacs(0,256,(char*)entry);
  69.   for (int i=0;i<256;i++)
  70.     pal << (int)entry[i].r << " " << (int)entry[i].g << " " << (int)entry[i].b << '\n';
  71.   return OK;
  72.   }
  73.  
  74.