12 static char rcs_ident[] =
"$Header: /software/dmsv/sun4/sunos/SWT-BACKUP/spencer/src/urt/tools/tools/RCS/pyrmask.c,v 3.0.1.2 1992/01/23 16:26:22 spencer Exp $";
28 char * leftname = NULL, * rightname = NULL, * outfname = NULL;
29 char * maskname = NULL, * errname;
30 FILE * leftfile, * rightfile, *maskfile, * outfile;
31 int oflag = 0, lflag = 0;
36 float *mask_mult_table;
38 int level, levels = 0;
40 pyramid leftgausspyr, leftbandpyr;
41 pyramid rightgausspyr, rightbandpyr;
58 "% l%-levels!d o%-outfile!s inmask!s outmask!s maskfile!s",
60 &oflag
, &outfname
, &leftname
, &rightname
, &maskname
) == 0 )
73 mask_mult_table = (
float *) malloc(
sizeof(
float) * 5 * 5 * 256);
77 maskmult = &(mask_mult_table[(i*5) << 8]);
80 for (k=0;k < 256; k++)
81 maskmult[ k ] = (
float) k * mask[i*5+j];
91 for ( rle_cnt = 0; ; rle_cnt++ )
94 &left_hdr
, levels
, mask_mult_table
))
102 &rightbandpyr
, &right_hdr
,
103 levels
, mask_mult_table
))
111 &mask_hdr
, levels
, mask_mult_table
))
121 "%s: Left and right images must have same number of channels\n",
125 if ((leftgausspyr
.xlen[0] != rightgausspyr
.xlen[0]) ||
126 (leftgausspyr
.ylen[0] != rightgausspyr
.ylen[0]))
129 "%s: Left and right images must have same dimensions\n",
136 "%s: Currently, mask image must have a mask per input channel\n",
140 if ((leftgausspyr
.xlen[0] != maskgausspyr
.xlen[0]) ||
141 (leftgausspyr
.ylen[0] != maskgausspyr
.ylen[0]))
144 "%s: Mask image must have same dimensions as input images\n",
153 splitpyr
.xlen = (
int *) malloc( splitpyr
.levels *
sizeof(
int ) );
154 splitpyr
.ylen = (
int *) malloc( splitpyr
.levels *
sizeof(
int ) );
163 for(level = splitpyr
.levels - 1; level >= 0; level--)
166 &splitpyr
,&maskgausspyr
);
191 pyramid * leftbandpyr, * rightbandpyr, *splitbandpyr;
193 int xsize, ysize, x, y, chan, xlinewidth, nchan;
194 rle_pixel *leftbase, *leftrastptr, *leftpxl, *leftsign;
195 rle_pixel *rightbase, *rightrastptr, *rightpxl, *rightsign;
196 rle_pixel *outbase, *outrastptr, *outpxl, *outsign;
198 int rightval, leftval, outval;
201 rightbase = rightbandpyr
->corners[level];
203 xsize = leftbandpyr
->xlen[level];
204 ysize = leftbandpyr
->ylen[level];
205 nchan = leftbandpyr
->nchan - 1;
206 splitbandpyr
->xlen[level] = xsize;
207 splitbandpyr
->ylen[level] = ysize;
210 fprintf(stderr,
"Copying half of level %d, size %d\n",level,xsize);
211 for (y = 0; y < ysize; y++)
214 xlinewidth * (nchan+1)]);
216 xlinewidth * (nchan+1)]);
218 xlinewidth * (nchan+1)]);
220 outsign = &(outrastptr[nchan * xlinewidth]);
221 for(x=0; x < xsize; x++)
226 for (chan = 0; chan < nchan; chan++)
228 leftpxl = &(leftrastptr[chan * xlinewidth]);
229 leftsign = &(leftrastptr[nchan * xlinewidth]);
230 rightpxl = &(rightrastptr[chan * xlinewidth]);
231 rightsign = &(rightrastptr[nchan * xlinewidth]);
232 outpxl = &(outrastptr[chan * xlinewidth]);
233 outsign = &(outrastptr[nchan * xlinewidth]);
234 for(x=0; x < xsize; x++)
237 if (x <= (15 * xsize / 32))
239 *outpxl = (*leftpxl);
240 if ((1 << chan) & (*leftsign))
241 *outsign |= (1 << chan);
243 else if (x >= (17 * xsize / 32))
245 *outpxl = (*rightpxl);
246 if ((1 << chan) & (*rightsign))
247 *outsign |= (1 << chan);
251 tval = ((
float) x - (15.0 * (
float) xsize / 32.0)) /
252 ((
float) xsize / 16.0);
253 leftval = (
int) (*leftpxl) *
254 (((1 << chan) & (*leftsign)) ? -1 : 1);
255 rightval = (
int) (*rightpxl) *
256 (((1 << chan) & (*rightsign)) ? -1 : 1);
257 outval = (
int) (tval * (
float) rightval +
258 (1.0 - tval) * (
float) leftval);
262 *outsign |= (1 << chan);
281 pyramid * leftbandpyr, * rightbandpyr, *splitbandpyr, *maskgausspyr;
283 int xsize, ysize, x, y, chan, xlinewidth, nchan;
284 rle_pixel *leftbase, *leftrastptr, *leftpxl, *leftsign;
285 rle_pixel *rightbase, *rightrastptr, *rightpxl, *rightsign;
286 rle_pixel *outbase, *outrastptr, *outpxl, *outsign;
287 rle_pixel *maskbase, *maskrastptr, *maskpxl;
289 int rightval, leftval, outval;
292 rightbase = rightbandpyr
->corners[level];
295 xsize = leftbandpyr
->xlen[level];
296 ysize = leftbandpyr
->ylen[level];
297 nchan = leftbandpyr
->nchan - 1;
298 splitbandpyr
->xlen[level] = xsize;
299 splitbandpyr
->ylen[level] = ysize;
303 for (y = 0; y < ysize; y++)
306 xlinewidth * (nchan+1)]);
308 xlinewidth * (nchan+1)]);
310 xlinewidth * (nchan+1)]);
312 xlinewidth * nchan]);
314 outsign = &(outrastptr[nchan * xlinewidth]);
315 for(x=0; x < xsize; x++)
320 for (chan = 0; chan < nchan; chan++)
322 leftpxl = &(leftrastptr[chan * xlinewidth]);
323 leftsign = &(leftrastptr[nchan * xlinewidth]);
324 rightpxl = &(rightrastptr[chan * xlinewidth]);
325 rightsign = &(rightrastptr[nchan * xlinewidth]);
326 outpxl = &(outrastptr[chan * xlinewidth]);
327 outsign = &(outrastptr[nchan * xlinewidth]);
328 maskpxl = &(maskrastptr[chan * xlinewidth]);
329 for(x=0; x < xsize; x++)
334 *outpxl = (*leftpxl);
335 if ((1 << chan) & (*leftsign))
336 *outsign |= (1 << chan);
338 else if (*maskpxl == 0)
340 *outpxl = (*rightpxl);
341 if ((1 << chan) & (*rightsign))
342 *outsign |= (1 << chan);
346 tval = ((
float) (*maskpxl)) / 255.0;
347 leftval = (
int) (*leftpxl) *
348 (((1 << chan) & (*leftsign)) ? -1 : 1);
349 rightval = (
int) (*rightpxl) *
350 (((1 << chan) & (*rightsign)) ? -1 : 1);
351 outval = (
int) (tval * (
float) leftval +
352 (1.0 - tval) * (
float) rightval);
356 *outsign |= (1 << chan);
FILE * rle_open_f(char *prog_name, char *file_name, char *mode)
rle_hdr * rle_hdr_cp(rle_hdr *from_hdr, rle_hdr *to_hdr)
void rle_names(rle_hdr *the_hdr, const char *pgmname, const char *fname, int img_num)
char * cmd_name(char **argv)
void main(int argc, char **argv)
int rle_get_error(int code, const char *pgmname, const char *fname)
void copy_mask_bands(int level, pyramid *leftbandpyr, pyramid *rightbandpyr, pyramid *splitbandpyr, pyramid *maskgausspyr)
int scanargs(int argc, char **argv, const char *format,...)
void copy_half_bands(int level, pyramid *leftbandpyr, pyramid *rightbandpyr, pyramid *splitbandpyr)
void rle_addhist(argv, rle_hdr *in_hdr, rle_hdr *out_hdr)
rle_hdr * rle_hdr_init(rle_hdr *the_hdr)
#define RLE_CHECK_ALLOC(pgm, ptr, name)
float * gauss_mask(int siz)