12 static char rcs_ident[] =
"$Id: pyrlib.c,v 3.0.1.2 1992/04/30 14:10:36 spencer Exp $";
31 float * mask_mult_table;
35 int xlen, ylen, nchan;
36 int xsize, ysize, levels, xlinewidth;
37 int i, chan, x, y, minlen;
63 fprintf(stderr,
"pyrlib: %d is too many input channels, 8 max\n",nchan);
72 minlen = (xlen < ylen) ? xlen : ylen;
75 for(levels = 1; minlen > 8; minlen = minlen >> 1, levels++);
76 else if ((minlen >> (levels - 1)) <= 4)
79 "pyrlib: %d is too many levels to make a pyramid\n",levels);
86 "pyrlib: %d is too few levels to make a pyramid\n",levels);
92 gausspyr
->xlen = (
int *) malloc( levels *
sizeof(
int ) );
93 gausspyr
->ylen = (
int *) malloc( levels *
sizeof(
int ) );
110 bandpyr
->xlen = (
int *) malloc( levels *
sizeof(
int ) );
111 bandpyr
->ylen = (
int *) malloc( levels *
sizeof(
int ) );
138 for (chan=0; chan < nchan; chan++)
140 rows[chan] = rastptr;
142 rastptr = &(rastptr[xlinewidth]);
151 for(i=1; i < levels; i++)
169 for(i=levels - 2; i >= 0; i--)
180 firstbase = gausspyr
->corners[levels - 1];
182 xsize = xlen >> (levels - 1);
183 ysize = ylen >> (levels - 1);
186 for (y = 0; y < ysize; y++)
189 xlinewidth * nchan]);
191 xlinewidth * (nchan + 1)]);
193 signpxl = &(outrastptr[nchan * xlinewidth]);
194 for(x=0; x < xsize; x++)
200 for (chan = 0; chan < nchan; chan++)
202 firstpxl = &(firstrastptr[chan * xlinewidth]);
203 outpxl = &(outrastptr[chan * xlinewidth]);
204 for(x=0; x < xsize; x++)
256 int chan, x, y, i, newvalue, xsize, ysize;
257 int xlinewidth, nchan;
259 rle_pixel *bot_edge_pxl, *bot_data_pxl, *bot_extrap_pxl;
260 rle_pixel *top_edge_pxl, *top_data_pxl, *top_extrap_pxl;
261 rle_pixel *left_edge_pxl, *left_data_pxl, *left_extrap_pxl;
262 rle_pixel *right_edge_pxl, *right_data_pxl, *right_extrap_pxl;
271 for (chan = 0; chan < nchan; chan++)
273 bot_edge_pxl = &(rastptr[chan * xlinewidth]);
274 top_edge_pxl = &(rastptr[(ysize-1) * nchan * xlinewidth
275 + chan * xlinewidth]);
276 for(x=0; x < xsize; x++)
280 bot_data_pxl = bot_edge_pxl + i * xlinewidth * nchan;
281 bot_extrap_pxl = bot_edge_pxl - i * xlinewidth * nchan;
282 newvalue = 2 * (*bot_edge_pxl) - (*bot_data_pxl);
283 *bot_extrap_pxl = (newvalue < 0) ? 0 :
284 ((newvalue > 255) ? 255 : newvalue);
288 top_data_pxl = top_edge_pxl - i * xlinewidth * nchan;
289 top_extrap_pxl = top_edge_pxl + i * xlinewidth * nchan;
290 newvalue = 2 * (*top_edge_pxl) - (*top_data_pxl);
291 *top_extrap_pxl = (newvalue < 0) ? 0 :
292 ((newvalue > 255) ? 255 : newvalue);
299 left_edge_pxl = &(rastptr[(-
MASKBELOW) * nchan * xlinewidth]);
300 right_edge_pxl = &(rastptr[(-
MASKBELOW) * nchan * xlinewidth
302 for (chan = 0; chan < nchan; chan++)
304 for(y=0; y < ysize +
MASKSIZE - 1; y++)
308 left_data_pxl = left_edge_pxl + i;
309 left_extrap_pxl = left_edge_pxl - i;
310 newvalue = 2 * (*left_edge_pxl) - (*left_data_pxl);
311 *left_extrap_pxl = (newvalue < 0) ? 0 :
312 ((newvalue > 255) ? 255 : newvalue);
316 right_data_pxl = right_edge_pxl - i;
317 right_extrap_pxl = right_edge_pxl + i;
318 newvalue = 2 * (*right_edge_pxl) - (*right_data_pxl);
319 *right_extrap_pxl = (newvalue < 0) ? 0 :
320 ((newvalue > 255) ? 255 : newvalue);
322 left_edge_pxl += xlinewidth;
323 right_edge_pxl += xlinewidth;
346 mptr = (
float *) malloc(
sizeof(
float) * siz * siz );
351 fprintf(stderr,
"mask size not 5\n");
359 mptr[j+i*siz] = w[j]*w[i];
376 float *mask_mult_table;
378 int xsize, ysize, x, y, xlinewidth, lilxlinewidth;
380 rle_pixel *inbase, *outbase, *inrastptr, *outrastptr;
389 xsize = pyr
->xlen[level - 1];
390 ysize = pyr
->ylen[level - 1];
393 lilxlinewidth = (xsize >> 1) +
MASKSIZE - 1;
395 for (y = 0; y < ysize; y+=2)
398 xlinewidth * nchan]);
400 lilxlinewidth * nchan]);
402 for (chan = 0; chan < nchan; chan++)
404 centerpxl = &(inrastptr[chan * xlinewidth]);
405 outpxl = &(outrastptr[chan * lilxlinewidth]);
406 for(x=0; x < xsize; x+=2)
409 for (i=0; i < 5; i++)
413 maskmult = &(mask_mult_table[(i*5) << 8]);
415 for (j=0; j < 5; j++)
418 total += maskmult[ calcpxl[j] ];
424 *outpxl = (total < 0.0) ? 0 :
425 ((total > 255.0) ? 255 : (
rle_pixel) total );
426 centerpxl++; centerpxl++;
448 float *mask_mult_table;
450 int xsize, ysize, x, y, xlinewidth;
451 int chan,subtractval,nchan;
452 rle_pixel *firstbase, *secondbase, *outbase;
453 rle_pixel *firstrastptr, *secondrastptr, *outrastptr;
454 rle_pixel *firstpxl, *secondpxl, *outpxl, *signpxl;
464 xsize = gausspyr
->xlen[level];
465 ysize = gausspyr
->ylen[level];
469 for (y = 0; y < ysize; y++)
472 xlinewidth * nchan]);
474 xlinewidth * nchan]);
476 xlinewidth * (nchan + 1)]);
478 signpxl = &(outrastptr[nchan * xlinewidth]);
479 for(x=0; x < xsize; x++)
485 for (chan = 0; chan < nchan; chan++)
487 firstpxl = &(firstrastptr[chan * xlinewidth]);
488 secondpxl = &(secondrastptr[chan * xlinewidth]);
489 outpxl = &(outrastptr[chan * xlinewidth]);
490 signpxl = &(outrastptr[nchan * xlinewidth]);
491 for(x=0; x < xsize; x++)
493 subtractval = (
int) (*firstpxl) - (
int) (*secondpxl);
494 if (subtractval >= 0)
499 *signpxl = (1 << chan) | (*signpxl);
522 float *mask_mult_table;
524 int xsize, ysize, x, y, xlinewidth, lilxlinewidth;
528 rle_pixel *centerpxl, *outpxl, *calcpxl, expandedval;
534 xsize = gausspyr
->xlen[level - 1];
535 ysize = gausspyr
->ylen[level - 1];
545 lilxlinewidth = (xsize >> 1) +
MASKSIZE - 1;
547 for (y = 0; y < ysize; y++)
550 lilxlinewidth * nchan]);
552 xlinewidth * nchan]);
554 for (chan = 0; chan < nchan; chan++)
556 centerpxl = &(inrastptr[chan * lilxlinewidth]);
557 outpxl = &(outrastptr[chan * xlinewidth]);
558 for(x=0; x < xsize; x++)
561 for (i=0; i < 5; i++)
566 calcpxl = centerpxl + ((i -
MASKBELOW) / 2)
567 * lilxlinewidth * nchan - (
MASKBELOW / 2);
569 calcpxl = centerpxl + ((i + 1 -
MASKBELOW) / 2)
570 * lilxlinewidth * nchan - (
MASKBELOW / 2);
571 maskmult = &(mask_mult_table[(i*5) << 8]);
573 for (j=0; j < 5; j++)
579 total += maskmult[ calcpxl[j / 2] ];
581 total += maskmult[ calcpxl[(j + 1) / 2] ];
590 expandedval = (total < 0.0) ? 0 :
591 ((total > 255.0) ? 255 : (
rle_pixel) total );
593 if ((x % 2) == 1) centerpxl++;
613 int xlen,ylen,channels;
617 int chan, level, x, y, activelevels, adjust_alpha = 0;
624 if ((levels == 1) && (in_hdr
.alpha))
627 out_hdr
.alpha = adjust_alpha;
628 out_hdr
.ncolors = channels * levels - adjust_alpha;
631 for ( chan=0; chan < channels*levels - adjust_alpha; chan++)
640 if (adjust_alpha) scanout--;
641 for ( chan=0; chan < channels*levels; chan++)
643 outrows[chan] = scanout[chan];
645 for (x = 0; x < xlen; x++)
646 scanout[chan][x] = 0;
651 activelevels = levels;
652 for (y = 0; y < ylen; y++)
657 for (level = 0; level < activelevels; level++)
666 if (y == (ylen >> (activelevels -1)))
668 for (chan = 0; chan < channels; chan++)
669 for (x = 0; x < (xlen >> (activelevels -1)); x++)
670 scanout[chan + channels * (activelevels-1)][x] = 0;
684 int xsize, x, chan, xlinewidth;
685 rle_pixel * outpxl, * outrastptr, *outbase, *scanoutptr;
687 xsize = xlen >> level;
689 outbase = corners[level];
695 for ( chan=0; chan < nchan; chan++)
697 outpxl = &(outrastptr[chan * xlinewidth]);
698 scanoutptr = scanout[chan + nchan * level];
699 for (x=0; x < xsize; x++)
701 *scanoutptr = *outpxl;
712 float *mask_mult_table;
714 int i, xsize, ysize, level, nchan, xlen, ylen;
715 int x, y, chan, xlinewidth,levels;
717 int *intbase, *intrastptr, *intpxl;
718 rle_pixel *outbase, *outrastptr, *outpxl;
738 intcorners = (
int **) malloc( levels *
sizeof(
int *) );
741 xsize = xlen; ysize = ylen;
742 for(i=0; i < levels; i++)
744 intcorners[i] = (
int *) malloc( (xsize +
MASKSIZE - 1)
745 * (ysize +
MASKSIZE - 1) * nchan *
sizeof(
int) );
753 for(level = levels - 1; level >= 0; level--)
761 for(level = levels - 1; level >= 1; level--)
767 nchan
,mask_mult_table
);
779 intbase = intcorners[0];
780 outbase = *imgcorner;
785 for (y = 0; y < ysize; y++)
788 xlinewidth * nchan]);
790 xlinewidth * nchan]);
792 for (chan = 0; chan < nchan; chan++)
794 intpxl = &(intrastptr[chan * xlinewidth]);
795 outpxl = &(outrastptr[chan * xlinewidth]);
796 for(x=0; x < xsize; x++)
798 *outpxl = (
rle_pixel) ((*intpxl) > 255) ? 255 :
799 (((*intpxl) < 0) ? 0 : (*intpxl));
808 for(i=0; i < levels; i++)
819 int xsize, ysize, x, y, chan, xlinewidth, sign;
820 rle_pixel *firstbase, *firstrastptr, *firstpxl, *signpxl;
821 int *outbase, *outrastptr, *outpxl;
824 firstbase = bandcorners[level];
825 outbase = intcorners[level];
826 xsize = xlen >> level;
827 ysize = ylen >> level;
830 for (y = 0; y < ysize; y++)
833 xlinewidth * (nchan + 1)]);
835 xlinewidth * nchan]);
837 for (chan = 0; chan < nchan; chan++)
839 firstpxl = &(firstrastptr[chan * xlinewidth]);
840 outpxl = &(outrastptr[chan * xlinewidth]);
841 signpxl = &(firstrastptr[nchan * xlinewidth]);
842 for(x=0; x < xsize; x++)
844 sign = ((1 << chan) & (*signpxl)) ? -1 : 1;
845 *outpxl = (
int) (*firstpxl) * sign;
860 int chan, x, y, i, newvalue, xsize, ysize;
862 int *rastptr, *rasterbase;
863 int *bot_edge_pxl, *bot_data_pxl, *bot_extrap_pxl;
864 int *top_edge_pxl, *top_data_pxl, *top_extrap_pxl;
865 int *left_edge_pxl, *left_data_pxl, *left_extrap_pxl;
866 int *right_edge_pxl, *right_data_pxl, *right_extrap_pxl;
868 rasterbase = corners[level];
869 xsize = xlen >> level;
870 ysize = ylen >> level;
874 for (chan = 0; chan < nchan; chan++)
876 bot_edge_pxl = &(rastptr[chan * xlinewidth]);
877 top_edge_pxl = &(rastptr[(ysize-1) * nchan * xlinewidth
878 + chan * xlinewidth]);
879 for(x=0; x < xsize; x++)
883 bot_data_pxl = bot_edge_pxl + i * xlinewidth * nchan;
884 bot_extrap_pxl = bot_edge_pxl - i * xlinewidth * nchan;
885 newvalue = 2 * (*bot_edge_pxl) - (*bot_data_pxl);
886 *bot_extrap_pxl = newvalue;
890 top_data_pxl = top_edge_pxl - i * xlinewidth * nchan;
891 top_extrap_pxl = top_edge_pxl + i * xlinewidth * nchan;
892 newvalue = 2 * (*top_edge_pxl) - (*top_data_pxl);
893 *top_extrap_pxl = newvalue;
900 left_edge_pxl = &(rastptr[(-
MASKBELOW) * nchan * xlinewidth]);
901 right_edge_pxl = &(rastptr[(-
MASKBELOW) * nchan * xlinewidth
903 for (chan = 0; chan < nchan; chan++)
905 for(y=0; y < ysize +
MASKSIZE - 1; y++)
909 left_data_pxl = left_edge_pxl + i;
910 left_extrap_pxl = left_edge_pxl - i;
911 newvalue = 2 * (*left_edge_pxl) - (*left_data_pxl);
912 *left_extrap_pxl = newvalue;
916 right_data_pxl = right_edge_pxl - i;
917 right_extrap_pxl = right_edge_pxl + i;
918 newvalue = 2 * (*right_edge_pxl) - (*right_data_pxl);
919 *right_extrap_pxl = newvalue;
921 left_edge_pxl += xlinewidth;
922 right_edge_pxl += xlinewidth;
932 float *mask_mult_table;
934 int xsize, ysize, x, y, xlinewidth, lilxlinewidth;
936 int *inbase, *outbase;
937 int *inrastptr, *outrastptr;
938 int *centerpxl, *outpxl, *calcpxl, expandedval;
944 xsize = xlen >> (level - 1);
945 ysize = ylen >> (level - 1);
947 inbase = intcorners[level];
948 outbase = intcorners[level-1];
950 lilxlinewidth = (xsize >> 1) +
MASKSIZE - 1;
952 for (y = 0; y < ysize; y++)
955 lilxlinewidth * nchan]);
957 xlinewidth * nchan]);
959 for (chan = 0; chan < nchan; chan++)
961 centerpxl = &(inrastptr[chan * lilxlinewidth]);
962 outpxl = &(outrastptr[chan * xlinewidth]);
963 for(x=0; x < xsize; x++)
966 for (i=0; i < 5; i++)
971 calcpxl = centerpxl + ((i -
MASKBELOW) / 2)
972 * lilxlinewidth * nchan - (
MASKBELOW / 2);
974 calcpxl = centerpxl + ((i + 1 -
MASKBELOW) / 2)
975 * lilxlinewidth * nchan - (
MASKBELOW / 2);
976 maskmult = &(mask_mult_table[(i*5) << 8]);
978 for (j=0; j < 5; j++)
986 total += maskmult[ 1 ] * calcpxl[j / 2];
990 total += maskmult[ 1 ] *
991 calcpxl[(j + 1) / 2];
1000 expandedval = (
int) total;
1001 *outpxl += expandedval;
1002 if ((x % 2) == 1) centerpxl++;
void extrap_level(int level, pyramid *pyr)
#define RLE_SET_BIT(glob, bit)
rle_hdr * rle_hdr_cp(rle_hdr *from_hdr, rle_hdr *to_hdr)
void dump_level_line(rle_pixel **scanout, int y, int level, rle_pixel **corners, int xlen, int nchan)
int rle_get_setup(rle_hdr *the_hdr)
int rle_row_alloc(rle_hdr *the_hdr, rle_pixel ***scanp)
void add_int_level(int level, int **intcorners, int xlen, int ylen, int nchan, float *mask_mult_table)
int rle_getrow(rle_hdr *the_hdr, scanline)
void band_to_int_level(int level, rle_pixel **bandcorners, int **intcorners, int xlen, int ylen, int nchan)
void rle_puteof(rle_hdr *the_hdr)
void rle_putrow(rows, int rowlen, rle_hdr *the_hdr)
void band_level(int level, pyramid *bandpyr, pyramid *gausspyr, float *mask_mult_table)
void extrap_int_level(int level, int **corners, int xlen, int ylen, int nchan)
void expand_level(int level, pyramid *gausspyr, rle_pixel **corner, float *mask_mult_table)
void rle_put_setup(rle_hdr *the_hdr)
void gauss_level(int level, pyramid *pyr, float *mask_mult_table)
#define RLE_CHECK_ALLOC(pgm, ptr, name)
float * gauss_mask(int siz)