11 int fill_cell(int col,int row,int value)
14 for (i=count,epp=files+count-1;i>0;i--,epp--)
15 if ((c=epp_get(*epp,col,row))!=(*epp)->offsite) return c;
19 void help(int exitcode)
21 printf("Usage: mosaic [-%%RA] [-O number] [-o filename] [--help][--version]files\n"
22 "\t--help - displays this message\n"
23 "\t--version - shows version number\n"
24 "\t-%% --verbose - shows progress indicator\n"
25 "\t-R --force-row - process misaligned files using row/col coords\n"
26 "\t-A --force-alt - process misaligned files using alternative coords\n"
27 "\t-O number --offsite=number - set offsite value of output file\n"
28 "\t-o name --output-file=name - sets name of output file\n");
32 int main(int argc,char **argv)
33 {char output_file[1024]="mosaic.out.epp";
34 struct option long_options[]=
40 {"force-row",0,0,'R'},
41 {"force-alt",0,0,'A'},
42 {"output-file",1,0,'o'},
44 int index,i,c;char *endptr;
45 int offsite=-1, x1=32767,y1=32767,x2=-32767,y2=-32767,
46 max=0,min=65535,force=0,use_alt=1,result,verbose=0;
49 while ((c=getopt_long(argc,argv,"O:%RAo:",long_options,&index))!=-1)
51 { case 2:show_version("mosaic","$Revision: 1.1 $");
52 case '%':verbose=1;break;
53 case 'O':offsite=strtol(optarg,&endptr,0);
54 if(*endptr||offsite<0||offsite>65535)
55 { fprintf(stderr,"Invalid offsite value %s\n",optarg); return 2;
58 case 'A':force=1;use_alt=1;break;
59 case 'R':force=1;use_alt=0;break;
60 case 'o':strcpy(output_file,default_ext(optarg,".epp"));break;
68 if (!count) { fprintf(stderr,"No input files specified\n");return 2;}
69 files=malloc(count*sizeof(EPP *));
70 for (i=optind,index=0;i<argc;i++,index++)
71 { files[index]=open_epp(default_ext(argv[i],".epp"));
73 {fprintf(stderr,"Cannot open file %s\n",argv[i]);
76 if (index>0&&!compare_cell_size(files[0],files[index]))
77 { fprintf(stderr,"File %s is incompatible with %s\n",argv[i],argv[optind]);
80 if (index>0&&!is_aligned(files[0],files[index]))
81 { fprintf(stderr,"File %s is misaligned with %s\n",argv[i],argv[optind]);
84 {if (!shift_epp(files[index],epp_row(files[0],files[index]->YTop),
85 epp_col(files[0],files[index]->XLeft)))
86 {fprintf(stderr,"Cannot align file %s\n",argv[i]) ;
91 { files[index]->XLeft=alt_x(files[0],files[index]->fc);
92 files[index]->XRight=alt_x(files[0],files[index]->lc);
93 files[index]->YTop=alt_y(files[0],files[index]->fr);
94 files[index]->YBottom=alt_y(files[0],files[index]->lr);
97 if (!index||x1>files[index]->fc){ x1=files[index]->fc;X1=files[index]->XLeft;}
98 if (!index||x2<files[index]->lc){ x2=files[index]->lc;X2=files[index]->XRight;}
99 if (!index||y1>files[index]->fr){ y1=files[index]->fr;Y1=files[index]->YTop;}
100 if (!index||y2<files[index]->lr){ y2=files[index]->lr;Y2=files[index]->YBottom;}
101 if (max<files[index]->max) max=files[index]->max;
102 if (min>files[index]->min) min=files[index]->min;
103 if (files[index]->kind==16) Create16bit=1;
109 { if (files[0]->offsite<min||files[0]->offsite>max)
110 offsite=files[0]->offsite;
112 offsite=Create16bit?65535:255;
114 install_progress_indicator(verbose?show_percent:check_int);
115 out_f=creat_epp(output_file,x1,y1,x2,y2,X1,Y1,X2,Y2,
117 if (!out_f) {fprintf(stderr,"Cannot create output file %s\n",output_file);
120 result=clear_progress(for_each_cell(out_f,fill_cell));
122 if (result) unlink(output_file);
123 for (i=0;i<count;i++) close_epp(files[i]);