home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C++ Games Programming
/
CPPGAMES.ISO
/
thx
/
source
/
utils
/
getpal.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
1995-05-12
|
2KB
|
74 lines
#include <fastgraf.h>
#include <fstream.h>
#include <io.h>
#include <dir.h>
#include <string.h>
const int OK = 1;
int save_palette(char* fname);
int main(int argc,char** argv)
{
char palfilename[MAXPATH];
if (argc<2)
{
cout << "\nUSAGE : GETPAL <pcxfile> [palettefile]\n";
cout << " GETPAL extracts a palette from 'pcxfile', and stores\n";
cout << " it in the ASCII file 'palettefile'. If no palettefile\n";
cout << " name is supplied, the palette is stored in a file with\n";
cout << " the same name as the pcxfile, but with a .PAL extension.\n";
return -1;
}
if (argc==2)
{
strcpy(palfilename,argv[1]);
char* p=strchr(palfilename,'.');
if (p) *p='\0';
strcat(palfilename,".pal");
}
else
strcpy(palfilename,argv[2]);
if (access(argv[1],0)!=0)
{
cout << "can't open file '" << argv[1] << "'\n",argv[1];
return -1;
}
int oldmode=fg_getmode();
fg_waitfor(18);
fg_setmode(22);
fg_showpcx(argv[1],0);
save_palette(palfilename);
fg_setmode(oldmode);
return 0;
}
struct pal_entry // struct compatible with the
{ // fg_setdacs routine
unsigned char r;
unsigned char g;
unsigned char b;
};
pal_entry entry[256];
int save_palette(char* fname)
{
ofstream pal(fname);
pal << "NeoPaint Palette File\n";
pal << "(C)1992-93 NeoSoft Corp.\n";
pal << "256\n";
fg_getdacs(0,256,(char*)entry);
for (int i=0;i<256;i++)
pal << (int)entry[i].r << " " << (int)entry[i].g << " " << (int)entry[i].b << '\n';
return OK;
}