/* (c) SPDsoft & GTIC 12 noviembre 1993 */ #include #include #include #include "pict.h" #ifdef THINK_C #include #endif #define MAX_PICT 32 #ifdef MYGETOPT char getopt( int argc, char *argv[], char *format ); #endif void usage(char *name); void fatalError(char *name,char *str); void catrow( Pict p1, Pict p2, Pict p, unsigned char color[]); void catrow( Pict p1, Pict p2, Pict p, unsigned char color[] ) { unsigned char *c1, *c2, *c, *cf; unsigned char *bc, *cff; unsigned int nc; bc=&(color[((p->n_comp==4)?(0):(1))]); if (p1) c1=p1->pixels; if (p2) c2=p2->pixels; for( c=p->pixels, cf=p->pixels+p->n_comp*p->image_W;cimage_W)); c += p1->image_W; c1 += p1->image_W; memcpy( c,c2,(size_t)(p2->image_W)); c += p2->image_W; c2 += p2->image_W; } else if (p1!=NULL) { cff=c+p->image_W; memcpy( c,c1,(size_t)(p1->image_W)); c += p1->image_W; c1 += p1->image_W; for ( ; cimage_W - p2->image_W ); for ( ; cimage_W)); c += p2->image_W; c2 += p2->image_W; } } } void usage(char *name) { fprintf(stderr, "usage: %s [-o output] -{u|d|r|l}{p|n} [-b color] [-v] files file\n", name); exit(-1); } void fatalError(char *name,char *str) { fprintf(stderr, "%s: Fatal Error: %s. bye...\n",name,str); exit(-2); } main(int argc,char *argv[]) { char *fname="joined.pict",format; char tmpStr[32]; char dir=0, sdir=0; int OutputOpt=0; char Verbose=0; unsigned char back_color[]={0,0,0,0}; Pict pictIn[2],pictOut; int np,i,j,opcion; int theError=0; int ih=0, iw=0; extern char *optarg; extern int optind,opterr; #ifdef THINK_C argc = ccommand(&argv); #endif while ( (opcion=getopt(argc,argv,"o:u:d:r:l:b:vh")) != EOF ) { switch(opcion) { case 'o': theError += ( *optarg==0x00 ); OutputOpt=optind-1; break; case 'l': case 'r': case 'd': case 'u': theError += ( dir!=0 ); theError += ( strlen(optarg)!=1 ); dir=(char)opcion; sdir=*optarg; theError += ((sdir!='p')&&(sdir!='n')); break; case 'b': theError += ( *optarg==0x00 ); { char *tmpstr; int filter_w = 0; for( tmpstr=strtok(optarg," "); tmpstr!=NULL ; tmpstr = strtok(NULL," ")) { if(filter_w == 3 ) theError ++; else back_color[1+filter_w++]=(unsigned char)atoi(tmpstr); } if(filter_w != 3 ) theError ++; } break; case 'v': printf("%s:v. 12 nov. 1993\n",argv[0]); Verbose=1; break; defatult: printf("%s: ??? -%c\n",argv[0],opcion); usage(argv[0]); } } if (( theError!=0) || ( optind != argc-2)) usage(argv[0]); if(Verbose) { printf("%s:output)\t%s\n",argv[0],OutputOpt!=0?argv[OutputOpt]:fname); fflush(stdout); } for(i=optind;i<=optind+1;i++) { np=i-optind; if(Verbose) printf("%s: %d)\t%s\n",argv[0],np,argv[i]); fflush(stdout); pictIn[np] = pict_open(argv[i],P_READ,0,0,0,NULL); if(pictIn[np]->n_comp==1) fatalError(argv[0],"Not True Color!"); iw=pictIn[np]->image_W; ih=pictIn[np]->image_H; if ((pictIn[np]->pixels = (U_char*)malloc((size_t)iw *pictIn[np]->n_comp))==NULL) fatalError(argv[0],"Buy more memory!"); } if ((dir=='u')||(dir=='d')) { ih=pictIn[0]->image_H+pictIn[1]->image_H; iw=pictIn[0]->image_W; } else { ih=pictIn[0]->image_H; iw=pictIn[0]->image_W+pictIn[1]->image_W; } pictOut = pict_open(OutputOpt!=0?argv[OutputOpt]:fname,P_WRITE, ih,iw,pictIn[0]->clr_mode,pictIn[0]->map); if ((pictOut->pixels = (U_char*)malloc((size_t)iw *pictIn[0]->n_comp))==NULL) fatalError(argv[0],"Buy more memory!"); /******************************************************************/ /* This is the real work */ for(j=0;jimage_H) { pict_get_line(pictIn[1],pictIn[1]->pixels); if(sdir=='p') catrow( NULL,pictIn[1],pictOut,back_color); else catrow( pictIn[1],NULL,pictOut,back_color); pict_put_line(pictOut,pictOut->pixels); } else { pict_get_line(pictIn[0],pictIn[0]->pixels); pict_put_line(pictOut,pictIn[0]->pixels); } break; case 'd': if(j>=pictIn[0]->image_H) { pict_get_line(pictIn[1],pictIn[1]->pixels); if(sdir=='n') catrow( NULL,pictIn[1],pictOut,back_color); else catrow( pictIn[1],NULL,pictOut,back_color); pict_put_line(pictOut,pictOut->pixels); } else { pict_get_line(pictIn[0],pictIn[0]->pixels); pict_put_line(pictOut,pictIn[0]->pixels); } break; case 'l': if (((sdir=='p')&&(jimage_H)) || ((sdir=='n')&&(j>=pictOut->image_H-pictIn[1]->image_H)) ) { pict_get_line(pictIn[1],pictIn[1]->pixels); pict_get_line(pictIn[0],pictIn[0]->pixels); catrow(pictIn[1],pictIn[0],pictOut,back_color); } else { pict_get_line(pictIn[0],pictIn[0]->pixels); catrow(NULL,pictIn[0],pictOut,back_color); } pict_put_line(pictOut,pictOut->pixels); break; case 'r': if (((sdir=='n')&&(jimage_H)) || ((sdir=='p')&&(j>=pictOut->image_H-pictIn[1]->image_H)) ) { pict_get_line(pictIn[1],pictIn[1]->pixels); pict_get_line(pictIn[0],pictIn[0]->pixels); catrow(pictIn[0],pictIn[1],pictOut,back_color); } else { pict_get_line(pictIn[0],pictIn[0]->pixels); catrow(pictIn[0],NULL,pictOut,back_color); } pict_put_line(pictOut,pictOut->pixels); break; } }/* lines */ /* End of real work */ /******************************************************************/ for(i=0;i<2;i++) { pict_close(pictIn[i]); pict_free(pictIn[i]); } pict_close(pictOut); pict_free(pictOut); }