cglue.c
1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
* cglue -
* Glue together 3 images into a color image
*
* Paul Haeberli - 1986
*/
#include "image.h"
short rowbuf[8192];
main(argc,argv)
int argc;
char **argv;
{
IMAGE *rimage, *gimage, *bimage, *aimage, *oimage;
unsigned int xsize, ysize;
unsigned int y;
int havealpha;
havealpha = 0;
if( argc<5 ) {
printf("usage: cglue red.bw grn.bw blu.bw [alp.bw] outimage.rgb\n");
exit(0);
}
if(argc>5)
havealpha++;
if( (rimage=iopen(argv[1],"r")) == NULL ) {
printf("cglue: can't open input file %s\n",argv[1]);
exit(0);
}
if( (gimage=iopen(argv[2],"r")) == NULL ) {
printf("cglue: can't open input file %s\n",argv[2]);
exit(0);
}
if( (bimage=iopen(argv[3],"r")) == NULL ) {
printf("cglue: can't open input file %s\n",argv[3]);
exit(0);
}
if(havealpha) {
if( (aimage=iopen(argv[4],"r")) == NULL ) {
printf("cglue: can't open input file %s\n",argv[3]);
exit(0);
}
oimage = iopen(argv[5],"w",RLE(1),3,rimage->xsize,rimage->ysize,4);
} else {
oimage = iopen(argv[4],"w",RLE(1),3,rimage->xsize,rimage->ysize,3);
}
isetname(oimage,rimage->name);
ysize = rimage->ysize;
xsize = rimage->xsize;
for(y=0; y<ysize; y++) {
getrow(rimage,rowbuf,y,0);
putrow(oimage,rowbuf,y,0);
}
for(y=0; y<ysize; y++) {
getrow(gimage,rowbuf,y,0);
putrow(oimage,rowbuf,y,1);
}
for(y=0; y<ysize; y++) {
getrow(bimage,rowbuf,y,0);
putrow(oimage,rowbuf,y,2);
}
if(havealpha) {
for(y=0; y<ysize; y++) {
getrow(aimage,rowbuf,y,0);
putrow(oimage,rowbuf,y,3);
}
}
iclose(oimage);
exit(0);
}