home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C++ Games Programming
/
CPPGAMES.ISO
/
thx
/
source
/
utils
/
paste.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
1995-05-12
|
2KB
|
73 lines
#include <fastgraf.h>
#include <iostream.h>
#include <io.h>
#include "pcx.h"
const int VMODE = 22;
int main(int argc,char** argv)
{
if (argc<3)
{
cout << "\nUSAGE : PASTE <background.pcx> <foreground.pcx> [outputname]\n";
cout << " PASTE takes the foreground image, and pastes any\n";
cout << " pixels that are not zero onto the background image.\n";
cout << " If the optional outputname parameter is not supplied\n";
cout << " the final image is saved as \"out.pcx.\"\n";
return 1;
}
if (access(argv[1],0)!=0)
{
cout << "can't open file '" << argv[1] << "'\n";
return 1;
}
if (access(argv[2],0)!=0)
{
cout << "can't open file '" << argv[2] << "'\n";
return 1;
}
static pcx_header header;
fg_pcxhead(argv[1],(char*)&header);
int w=header.width+1-header.x;
int h=header.height+1-header.y;
int x,y,mx,my,clr;
int oldmode=fg_getmode();
fg_setmode(VMODE);
mx=fg_getmaxx();
my=fg_getmaxy();
fg_setpage(1);
fg_move(0,0);
fg_showpcx(argv[2],2);
fg_setpage(0);
fg_move(0,0);
fg_showpcx(argv[1],2);
for (y=0;y<my;y++)
{
for (x=0;x<mx;x++)
{
fg_setpage(1);
clr=fg_getpixel(x,y);
if (clr!=0)
{
fg_setpage(0);
fg_setcolor(clr);
fg_point(x,y);
}
}
}
fg_setpage(0);
if (argc>3)
fg_makepcx(0,w-1,0,h-1,argv[3]);
else
fg_makepcx(0,w-1,0,h-1,"out.pcx");
fg_setmode(oldmode);
return 0;
}