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

  1. #include <fastgraf.h>
  2. #include <iostream.h>
  3. #include <io.h>
  4. #include "pcx.h"
  5.  
  6.  
  7. const int VMODE = 22;
  8.  
  9. int main(int argc,char** argv)
  10.   {
  11.   if (argc<3)
  12.     {
  13.     cout << "\nUSAGE : PASTE <background.pcx> <foreground.pcx> [outputname]\n";
  14.     cout << "  PASTE takes the foreground image, and pastes any\n";
  15.     cout << "  pixels that are not zero onto the background image.\n";
  16.     cout << "  If the optional outputname parameter is not supplied\n";
  17.     cout << "  the final image is saved as \"out.pcx.\"\n";
  18.     return 1;
  19.     }
  20.   if (access(argv[1],0)!=0)
  21.     {
  22.     cout << "can't open file '" << argv[1] << "'\n";
  23.     return 1;
  24.     }
  25.   if (access(argv[2],0)!=0)
  26.     {
  27.     cout << "can't open file '" << argv[2] << "'\n";
  28.     return 1;
  29.     }
  30.  
  31.   static pcx_header header;
  32.   fg_pcxhead(argv[1],(char*)&header);
  33.   int w=header.width+1-header.x;
  34.   int h=header.height+1-header.y;
  35.  
  36.   int x,y,mx,my,clr;
  37.   int oldmode=fg_getmode();
  38.   fg_setmode(VMODE);
  39.   mx=fg_getmaxx();
  40.   my=fg_getmaxy();
  41.  
  42.   fg_setpage(1);
  43.   fg_move(0,0);
  44.   fg_showpcx(argv[2],2);
  45.  
  46.   fg_setpage(0);
  47.   fg_move(0,0);
  48.   fg_showpcx(argv[1],2);
  49.  
  50.   for (y=0;y<my;y++)
  51.     {
  52.     for (x=0;x<mx;x++)
  53.       {
  54.       fg_setpage(1);
  55.       clr=fg_getpixel(x,y);
  56.       if (clr!=0)
  57.         {
  58.         fg_setpage(0);
  59.         fg_setcolor(clr);
  60.         fg_point(x,y);
  61.         }
  62.       }
  63.     }
  64.  
  65.   fg_setpage(0);
  66.   if (argc>3)
  67.     fg_makepcx(0,w-1,0,h-1,argv[3]);
  68.   else
  69.     fg_makepcx(0,w-1,0,h-1,"out.pcx");
  70.   fg_setmode(oldmode);
  71.   return 0;
  72.   }
  73.