home *** CD-ROM | disk | FTP | other *** search
- #include <fastgraf.h>
- #include <values.h>
- #include <fstream.h>
- #include <string.h>
- #include <dir.h>
- #include <io.h>
- #include "pcx.h"
- #include "utils.h"
-
- const int MAXFILES = 100;
- const int VMODE = 22;
-
- struct image_info
- {
- int w,h;
- long size;
- };
-
- static image_info image[MAXFILES];
- static int count;
-
- int create_gfxlib(int argc, char *argv[]);
-
- int main(int argc, char *argv[])
- {
- if (argc<3)
- {
- cout << "\nUSAGE : GFXMAKE <gfxlib> <file1, ...> @<listfile>\n"
- " GFXMAKE constructs GFX graphics libraries\n"
- " from the files listed on the command line or in\n"
- " <listfile>. GFXMAKE constructs the GFX library\n"
- " with the entries in the order in which they appear\n"
- " on the command file and/or in <listfile>.\n"
- " The resulting file is given the name 'gfxlib',\n"
- " and can be viewed using GFXSHOW.\n";
- return -1;
- }
-
- if (create_gfxlib(argc, argv))
- cout << "ok\n";
- return 0;
- }
-
- static pcx_header header;
- static ofstream lib;
-
- void bld_gfxlib(char *file);
-
- int create_gfxlib(int argc, char *argv[])
- {
- lib.open(argv[1],ios::binary);
- if (lib.fail())
- {
- cout << "Cannot open " << argv[1] << endl;
- return 0;
- }
- count = 0;
- lib.write((char*)&count,sizeof(count)); // zero at this time
-
- int oldmode=fg_getmode();
- fg_waitfor(18);
- fg_setmode(VMODE);
-
- int rtn = parse_cmdline(argc-2, argv+2, bld_gfxlib);
- if (rtn)
- {
- lib.seekp(0);
- lib.write((char*)&count,sizeof(count));
- }
- lib.close();
- fg_setmode(oldmode);
-
- for (int i=0;i<count;i++)
- {
- cout << (i+1) << ": " << image[i].w << "x" << image[i].h ;
- cout << " " << image[i].size << endl;
- }
-
- return rtn;
- }
-
- void bld_gfxlib(char *file)
- {
- count++;
-
- int w,h;
- long size;
- char* buf;
-
- fg_setcolor(0);
- fg_rect(0,319,0,239);
- fg_move(0,0);
- fg_showpcx(file,2);
- fg_pcxhead(file,(char*)&header);
- w=header.width+1-header.x;
- h=header.height+1-header.y;
- size=fg_imagesiz(w,h);
-
- image[count-1].w=w;
- image[count-1].h=h;
- image[count-1].size=size;
-
- buf=new char[(size_t)size];
- fg_move(0,h-1);
- fg_getimage(buf,w,h);
- lib.write((char*)&w,sizeof(w));
- lib.write((char*)&h,sizeof(h));
- lib.write((char*)&size,sizeof(size));
- if (size<=(long)MAXINT)
- lib.write(buf,(int)size);
- else
- {
- lib.write(buf,(int)MAXINT);
- lib.write(buf+MAXINT,(int)(size-(long)MAXINT));
- }
- delete buf;
- fg_waitfor(2);
- }
-
-