7 int color_to_not_expand=-1;/* 1 in eppl */
8 int cells_filled,cells_remain;
11 void add_color(int color,int *col_list,int *col_count,int *list_len)
13 if(color==color_to_fill||color==color_to_not_expand) return;
14 for (i=0;i<*list_len;i++,col_list++,col_count++)
15 if (color==col_list[i]) {col_count[i]++;return;}
16 *col_list=color;*col_count=1;(*list_len)++;
18 #define addcolor(i) add_color(i,color,count,&cc);
19 void fillrow(unsigned short *out_row,unsigned short *prev_row,
20 unsigned short *cur_row,unsigned short *next_row,
23 for (i=1;i<=ncols;i++)
24 if (cur_row[i]!=color_to_fill) *(out_row++)=cur_row[i];
26 { int color[8],count[8],ii,jj,cc=0,cnt=0;
27 unsigned short *clr_ptr=prev_row+i-1;
28 addcolor(*(clr_ptr++));
29 addcolor(*(clr_ptr++));
30 addcolor(*(clr_ptr++));
31 addcolor(cur_row[i-1]);
32 addcolor(cur_row[i+1]);
33 addcolor(*(clr_ptr=next_row+i-1));
34 addcolor(*(++clr_ptr));
35 addcolor(*(++clr_ptr));
36 for(ii=0,jj=color_to_fill;ii<cc;ii++)
37 if(count[ii]>cnt) {cnt=count[ii];jj=color[ii];}
38 if (jj==color_to_fill)
39 {cells_remain++;*(out_row++)=color_to_fill;}
41 {cells_filled++;*(out_row++)=jj;};
44 int fill(char *in_file_name,char *out_file_name)
45 { unsigned short int *prev_row,*cur_row,*next_row,*rptr,*dest;
46 int i,j,nrows,seqrow,ncols;
53 in_file=open_epp(in_file_name);
55 { fprintf(stderr,"Cannot open file %s\n",in_file_name);
58 Create16bit=in_file->kind==16;
59 out_file=creat_epp_as(out_file_name,in_file);
61 { fprintf(stderr,"Cannt create file %s\n",out_file_name);
64 ncols=in_file->lc-in_file->fc;
65 prev_row=malloc(sizeof(short)*(ncols+2));
66 cur_row=malloc(sizeof(short)*(ncols+2));
67 next_row=malloc(sizeof(short)*(ncols+2));
68 for(i=0;i<=ncols+1;prev_row[i++]=color_to_fill);
69 cur_row[0]=cur_row[ncols+1]=next_row[0]=next_row[ncols+1]=color_to_fill;
70 rptr=epp_getline(in_file,in_file->fc,in_file->fr);
71 for(i=1,dest=cur_row+1;i<=ncols;*(dest++)=*(rptr++),i++);
72 rptr=epp_getline(in_file,in_file->fc,in_file->fr+1);
73 for(i=1,dest=next_row+1;i<=ncols;*(dest++)=*(rptr++),i++);
74 nrows=in_file->lr-in_file->fr;
75 for(seqrow=1,i=in_file->fr+2;seqrow<=nrows;i++,seqrow++)
78 if ((*EndLineProc)(i,seqrow,nrows)) return 1;
79 epp_put(out_file,out_file->fc,i-2,out_file->offsite);
80 fillrow(out_file->row,prev_row,cur_row,next_row,ncols);
81 {unsigned short int *tmp;
88 { rptr=epp_getline(in_file,in_file->fc,i);
89 for(j=1,dest=next_row+1;j<=ncols;*(dest++)=*(rptr++),j++);
92 for(j=1,dest=next_row+1;j<=ncols;*(dest++)=color_to_fill,j++);
94 out_file->max=in_file->max;
95 out_file->min=in_file->min;
100 int main(int argc,char **argv)
103 char out_name[256]="fill.out.epp";
105 char out_name[256]="fill.epp";
107 struct option long_options[]={
111 {"gap-size",required_argument,0,'g'},
112 {"color-to-fill",required_argument,0,'f'},
113 {"exclude-color",required_argument,0,'x'},
114 {"output-file",required_argument,0,'o'},
118 while ((c=getopt_long(argc,argv,"%g:c:f:x:o:",long_options,&index))!=-1)
122 show_version("fill","$Revision: 1.1 $");
124 case '%':verbose=1;break;
125 case 'g':/*gap size is unused now*/
126 gap_size=atoi(optarg);break;
127 case 'c':/*color to fill*/
128 color_to_fill=atoi(optarg);break;
129 case 'x':color_to_not_expand=atoi(optarg);break;
130 case 'o':strcpy(out_name,optarg);break;
135 printf("Usage %s [--help] [--version] [-v] [-g gap size]\n"
136 "\t[-c color to fill] [-x color to exclude] [-o output file]\n"
137 "\tepp file\n",argv[0]);
142 {fprintf(stderr,"No input files specified\n");
146 { fprintf(stderr,"Too many input files\n");
149 install_progress_indicator(verbose?show_percent:check_int);
150 if((c=clear_progress(fill(argv[optind],out_name))))
154 printf("Cells filled %d\nCells of class %d remain:%d\n",
155 cells_filled,color_to_fill,cells_remain);
156 return cells_remain?1:0;