26 char *
infname = NULL, * outfname = NULL, * maskfname = NULL;
28 int oflag = 0, mflag = 0, no_norm = 0;
29 int xlinewidth, xlen, ylen,
x,
y;
31 int maskskip, origmasksize;
32 int maxmaskskip, maxmasksize, maxmaskbelow;
33 int masksize, maskbelow, maskabove;
36 float *mask_mult_table;
40 rle_pixel *rastptr, *rasterbase, *centerpxl, *calcpxl;
41 rle_pixel *outrastptr, *outrasterbase, *outpxl, *tempbase;
42 rle_pixel *bot_edge_pxl, *bot_data_pxl, *bot_extrap_pxl;
43 rle_pixel *top_edge_pxl, *top_data_pxl, *top_extrap_pxl;
44 rle_pixel *left_edge_pxl, *left_data_pxl, *left_extrap_pxl;
45 rle_pixel *right_edge_pxl, *right_data_pxl, *right_extrap_pxl;
55 "% m%-maskfile!s n%- o%-outfile!s level%d infile%s",
56 &mflag, &maskfname, &no_norm,
57 &oflag, &outfname, &levels, &infname ) == 0 )
62 mask =
read_mask(&origmasksize, maskfname, no_norm);
88 mask_mult_table = (
float *)
malloc(
sizeof(
float) * origmasksize *
91 for (i=0; i < origmasksize; i++)
93 maskmult = &(mask_mult_table[(i*origmasksize) << 8]);
94 for (j=0; j < origmasksize; j++)
96 for (k=0;k < 256; k++)
97 maskmult[ k ] = (
float) k * mask[i*origmasksize+j];
104 fprintf(stderr,
"Level must be greater than 0.\n");
109 maxmaskskip = 1 << (levels - 1);
110 maxmasksize = (origmasksize - 1) * maxmaskskip + 1;
111 maxmaskbelow = (maxmasksize-1) / 2;
114 xlen = in_hdr.
xmax - in_hdr.
xmin + 1;
115 ylen = in_hdr.
ymax - in_hdr.
ymin + 1;
116 xlinewidth = xlen + maxmasksize - 1;
133 rasterbase = (
unsigned char *)
malloc(
134 xlinewidth * (ylen + maxmasksize - 1) *
nchan );
135 outrasterbase = (
unsigned char *)
malloc(
136 xlinewidth * (ylen + maxmasksize - 1) *
nchan );
139 rastptr = &(rasterbase[maxmaskbelow * xlinewidth * nchan + maxmaskbelow]);
145 for (i = in_hdr.
ymin; i <= in_hdr.
ymax; i++)
147 for (chan=0; chan <
nchan; chan++)
149 rows[chan] = rastptr;
151 rastptr = &(rastptr[xlinewidth]);
157 for(level = 1; level <=
levels; level++)
160 maskskip = 1 << (level - 1);
161 masksize = (origmasksize - 1) * maskskip + 1;
162 maskbelow = (masksize-1) / 2;
163 maskabove = masksize / 2;
168 if ((maskbelow > 0) && (maskabove > 0))
170 rastptr = &(rasterbase[maxmaskbelow +
171 maxmaskbelow * xlinewidth *
nchan]);
173 for (chan = 0; chan <
nchan; chan++)
175 bot_edge_pxl = &(rastptr[chan * xlinewidth]);
176 top_edge_pxl = &(rastptr[(ylen-1) * nchan * xlinewidth
177 + chan * xlinewidth]);
178 for(x=0; x < xlen; x++)
180 for (i=1; i <= maskbelow; i++)
182 bot_data_pxl = bot_edge_pxl + i * xlinewidth *
nchan;
183 bot_extrap_pxl = bot_edge_pxl - i * xlinewidth *
nchan;
184 newvalue = 2 * (*bot_edge_pxl) - (*bot_data_pxl);
185 *bot_extrap_pxl = (newvalue < 0) ? 0 :
186 ((newvalue > 255) ? 255 : newvalue);
188 for (i=1; i <= maskabove; i++)
190 top_data_pxl = top_edge_pxl - i * xlinewidth *
nchan;
191 top_extrap_pxl = top_edge_pxl + i * xlinewidth *
nchan;
192 newvalue = 2 * (*top_edge_pxl) - (*top_data_pxl);
193 *top_extrap_pxl = (newvalue < 0) ? 0 :
194 ((newvalue > 255) ? 255 : newvalue);
201 left_edge_pxl = &(rastptr[(-maskbelow) * nchan * xlinewidth]);
202 right_edge_pxl = &(rastptr[(-maskbelow) * nchan * xlinewidth
203 + xlinewidth - masksize]);
204 for (chan = 0; chan <
nchan; chan++)
206 for(y=0; y < ylen + masksize - 1; y++)
208 for (i=1; i <= maskbelow; i++)
210 left_data_pxl = left_edge_pxl +
i;
211 left_extrap_pxl = left_edge_pxl -
i;
212 newvalue = 2 * (*left_edge_pxl) - (*left_data_pxl);
213 *left_extrap_pxl = (newvalue < 0) ? 0 :
214 ((newvalue > 255) ? 255 : newvalue);
216 for (i=1; i <= maskabove; i++)
218 right_data_pxl = right_edge_pxl -
i;
219 right_extrap_pxl = right_edge_pxl +
i;
220 newvalue = 2 * (*right_edge_pxl) - (*right_data_pxl);
221 *right_extrap_pxl = (newvalue < 0) ? 0 :
222 ((newvalue > 255) ? 255 : newvalue);
224 left_edge_pxl += xlinewidth;
225 right_edge_pxl += xlinewidth;
230 for (y = 0; y < ylen; y++)
232 rastptr = &(rasterbase[maxmaskbelow + (y+maxmaskbelow) *
233 xlinewidth * nchan]);
234 outrastptr = &(outrasterbase[maxmaskbelow + (y+maxmaskbelow) *
235 xlinewidth * nchan]);
237 for (chan = 0; chan <
nchan; chan++)
239 centerpxl = &(rastptr[chan * xlinewidth]);
240 outpxl = &(outrastptr[chan * xlinewidth]);
241 for(x=0; x < xlen; x++)
244 for (i=0; i < origmasksize; i++)
246 calcpxl = centerpxl + (i * maskskip - maskbelow)
247 * xlinewidth * nchan - maskbelow;
248 maskmult = &(mask_mult_table[(i*origmasksize) << 8]);
250 for (j=0; j < origmasksize; j++)
253 total += maskmult[ calcpxl[j*maskskip] ];
259 *outpxl = (total < 0.0) ? 0 :
260 ((total > 255.0) ? 255 : (
unsigned char) total );
267 tempbase = rasterbase;
268 rasterbase = outrasterbase;
269 outrasterbase = tempbase;
279 for ( chan=0; chan <
nchan; chan++)
281 rows[chan] = scanout[chan];
285 for (y = 0; y < ylen; y++)
287 rastptr = &(rasterbase[maxmaskbelow + (y+maxmaskbelow) *
288 xlinewidth * nchan]);
290 for (chan = 0; chan <
nchan; chan++)
292 outpxl = &(rastptr[chan * xlinewidth]);
293 for(x=0; x < xlen; x++)
295 scanout[chan][
x] = *outpxl;
304 free( mask_mult_table );
307 free( outrasterbase );
#define RLE_SET_BIT(glob, bit)
void rle_row_free(rle_hdr *the_hdr, rle_pixel **scanp)
int scanargs(int argc, char **argv, const char *format,...)
int rle_row_alloc(rle_hdr *the_hdr, rle_pixel ***scanp)
void rle_putrow(rle_pixel *rows[], int rowlen, rle_hdr *the_hdr)
void rle_addhist(char *argv[], rle_hdr *in_hdr, rle_hdr *out_hdr)
void rle_puteof(rle_hdr *the_hdr)
void rle_names(rle_hdr *the_hdr, const char *pgmname, const char *fname, int img_num)
int rle_get_setup(rle_hdr *the_hdr)
int rle_get_error(int code, const char *pgmname, const char *fname)
rle_hdr * rle_hdr_cp(rle_hdr *from_hdr, rle_hdr *to_hdr)
FILE * rle_open_f(const char *prog_name, const char *f_name, const char *mode)
float * read_mask(int *size, char *fname, int no_norm)
void rle_put_setup(rle_hdr *the_hdr)
char * cmd_name(char **argv)
int rle_getrow(rle_hdr *the_hdr, rle_pixel *scanline[])
#define RLE_CHECK_ALLOC(pgm, ptr, name)
rle_hdr * rle_hdr_init(rle_hdr *the_hdr)
float * gauss_mask(int siz)