home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C++ Games Programming
/
CPPGAMES.ISO
/
thx
/
source
/
utils
/
gfxshow.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
1995-05-12
|
4KB
|
164 lines
#include <fastgraf.h>
#include <fstream.h>
#include <stdlib.h>
#include <values.h>
#include <io.h>
const int MAX_BITMAPS = 100;
const int STRLEN = 80;
const int VMODE = 22;
const int PANINC = 4;
const int PANLIM = 3;
struct bitmap_info
{
int w,h;
long size;
};
bitmap_info bitmap[MAX_BITMAPS];
void install_palette(char* fname);
void show_images(char* gfxlib);
void pan_screen();
int count;
int main(int argc,char** argv)
{
if (argc<2)
{
cout << "\nUSAGE : GFXSHOW <gfxlib> [palette]\n";
cout << " GFXSHOW displays the entries of a GFX graphics library.\n";
cout << " The library to be displayed is 'gfxlib', and a palette\n";
cout << " file can be supplied, which GFXSHOW will use to display\n";
cout << " the library.\n\n";
cout << " Also, the UP and DOWN arrow keys can be used to pan the\n";
cout << " images if there is more than will fit on the screen.\n";
return -1;
}
if (access(argv[1],0)!=0)
{
cout << "can't open GFX library '" << argv[1] << "'\n";
return -1;
}
int oldmode=fg_getmode();
fg_waitfor(18);
fg_setmode(VMODE);
fg_resize(320,240*PANLIM);
if (argc==3)
install_palette(argv[2]);
show_images(argv[1]);
pan_screen();
fg_setmode(oldmode);
for (int i=0;i<count;i++)
{
cout << (i+1) << ": " << bitmap[i].w << "x"
<< bitmap[i].h << " "
<< bitmap[i].size << endl;
}
cout << "ok\n";
return 0;
}
void pan_screen()
{
int y=0;
unsigned char ascii,aux;
do{
fg_getkey(&ascii,&aux);
if (aux==0x48) // UP ARROW
{
if (y>0)
fg_pan(0,y-=PANINC);
}
else if (aux==0x50) // DOWN ARROW
{
if (y<PANLIM*240-240)
fg_pan(0,y+=PANINC);
}
} while (ascii!=27);
}
void show_images(char* gfxlib)
{
int x=0,y=0;
int w,h;
long size;
char* buf;
ifstream lib(gfxlib,ios::binary);
lib.read((char*)&count,sizeof(count));
int maxh=0;
for (int i=0;i<count;i++)
{
lib.read((char*)&w,sizeof(w));
lib.read((char*)&h,sizeof(h));
lib.read((char*)&size,sizeof(size));
buf=new char[(size_t)size];
if (size<=(long)MAXINT)
lib.read(buf,(int)size);
else
{
lib.read(buf,(int)MAXINT);
lib.read(buf+MAXINT,(int)(size-(long)MAXINT));
}
if (x+w > 319)
{
x=0;
y+=maxh+2;
maxh=0;
}
fg_move(x,y+h);
fg_drwimage(buf,w,h);
bitmap[i].w=w;
bitmap[i].h=h;
bitmap[i].size=size;
if (maxh < h) maxh=h;
x+=w+2;
delete buf;
}
}
void install_palette(char* fname)
{
struct pal_entry // struct compadible with the
{ // fg_setdacs routine
unsigned char r;
unsigned char g;
unsigned char b;
};
char str[STRLEN];
int i,max;
pal_entry* pal_array;
int r,g,b;
ifstream palfile(fname);
if (palfile.bad()) return;
palfile.getline(str,STRLEN);
palfile.getline(str,STRLEN);
palfile.getline(str,STRLEN);
max=atoi(str);
pal_array=new pal_entry[max];
for (i=0;i<max;i++)
{
palfile >> r;
palfile >> g;
palfile >> b;
pal_array[i].r=(unsigned char)r;
pal_array[i].g=(unsigned char)g;
pal_array[i].b=(unsigned char)b;
}
fg_setdacs(0,max,(char*)pal_array);
delete pal_array;
}