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

  1. #include <fastgraf.h>
  2. #include <values.h>
  3. #include <fstream.h>
  4. #include <string.h>
  5. #include <dir.h>
  6. #include <io.h>
  7. #include "pcx.h"
  8. #include "utils.h"
  9.  
  10. const int MAXFILES = 100;
  11. const int VMODE = 22;
  12.  
  13. struct image_info
  14.   {
  15.   int w,h;
  16.   long size;
  17.   };
  18.  
  19. static image_info image[MAXFILES];
  20. static int count;
  21.  
  22. int create_gfxlib(int argc, char *argv[]);
  23.  
  24. int main(int argc, char *argv[])
  25.   {
  26.   if (argc<3)    
  27.     {
  28.     cout << "\nUSAGE : GFXMAKE <gfxlib> <file1, ...> @<listfile>\n"
  29.             "  GFXMAKE constructs GFX graphics libraries\n"
  30.             "  from the files listed on the command line or in\n"
  31.             "  <listfile>. GFXMAKE constructs the GFX library\n"
  32.             "  with the entries in the order in which they appear\n"
  33.             "  on the command file and/or in <listfile>.\n"
  34.             "  The resulting file is given the name 'gfxlib',\n"
  35.             "  and can be viewed using GFXSHOW.\n";
  36.          return -1;
  37.     }
  38.  
  39.   if (create_gfxlib(argc, argv))
  40.     cout << "ok\n";
  41.   return 0;
  42.   }
  43.  
  44. static pcx_header header;
  45. static ofstream lib;
  46.  
  47. void bld_gfxlib(char *file);
  48.  
  49. int create_gfxlib(int argc, char *argv[])
  50.   {
  51.   lib.open(argv[1],ios::binary);
  52.   if (lib.fail()) 
  53.     {
  54.     cout << "Cannot open " << argv[1] << endl;
  55.       return 0;
  56.     }
  57.   count = 0;
  58.   lib.write((char*)&count,sizeof(count));   // zero at this time
  59.  
  60.   int oldmode=fg_getmode();
  61.   fg_waitfor(18);
  62.   fg_setmode(VMODE);
  63.  
  64.   int rtn = parse_cmdline(argc-2, argv+2, bld_gfxlib);
  65.   if (rtn)
  66.     {
  67.     lib.seekp(0);
  68.     lib.write((char*)&count,sizeof(count));
  69.     }
  70.   lib.close();
  71.   fg_setmode(oldmode);
  72.  
  73.   for (int i=0;i<count;i++)
  74.     {
  75.     cout << (i+1) << ": " << image[i].w << "x" << image[i].h ;
  76.     cout << "  " << image[i].size << endl;
  77.     }
  78.  
  79.   return rtn;
  80.   }
  81.  
  82. void bld_gfxlib(char *file)
  83.   {
  84.   count++;
  85.  
  86.   int w,h;
  87.   long size;
  88.   char* buf;
  89.  
  90.   fg_setcolor(0);
  91.   fg_rect(0,319,0,239);
  92.   fg_move(0,0);
  93.   fg_showpcx(file,2);
  94.   fg_pcxhead(file,(char*)&header);
  95.   w=header.width+1-header.x;
  96.   h=header.height+1-header.y;
  97.   size=fg_imagesiz(w,h);
  98.  
  99.   image[count-1].w=w;
  100.   image[count-1].h=h;
  101.   image[count-1].size=size;
  102.  
  103.   buf=new char[(size_t)size];
  104.   fg_move(0,h-1);
  105.   fg_getimage(buf,w,h);
  106.   lib.write((char*)&w,sizeof(w));
  107.   lib.write((char*)&h,sizeof(h));
  108.   lib.write((char*)&size,sizeof(size));
  109.   if (size<=(long)MAXINT)
  110.     lib.write(buf,(int)size);
  111.   else
  112.     {
  113.     lib.write(buf,(int)MAXINT);
  114.     lib.write(buf+MAXINT,(int)(size-(long)MAXINT));
  115.     }
  116.   delete buf;
  117.   fg_waitfor(2);
  118.   }
  119.  
  120.