--- ray/src/common/color.c 1989/09/13 16:35:14 1.5 +++ ray/src/common/color.c 1989/10/20 20:35:22 1.8 @@ -354,7 +354,7 @@ colr_color(col, clr) /* convert short to float color register COLOR col; register COLR clr; { - double ldexp(), f; + double f; if (clr[EXP] == 0) col[RED] = col[GRN] = col[BLU] = 0.0; @@ -364,4 +364,57 @@ register COLR clr; col[GRN] = (clr[GRN] + 0.5)*f; col[BLU] = (clr[BLU] + 0.5)*f; } +} + + +normcolrs(scan, len) /* normalize a scanline of colrs */ +register COLR *scan; +int len; +{ + register int c; + register int shift; + + while (len-- > 0) { + shift = scan[0][EXP] - COLXS; + if (shift > 0) { + if (shift >= 8) { + scan[0][RED] = + scan[0][GRN] = + scan[0][BLU] = 255; + } else { + c = scan[0][RED] << shift; + scan[0][RED] = c > 255 ? 255 : c; + c = scan[0][GRN] << shift; + scan[0][GRN] = c > 255 ? 255 : c; + c = scan[0][BLU] << shift; + scan[0][BLU] = c > 255 ? 255 : c; + } + } else if (shift < 0) { + if (shift <= -8) { + scan[0][RED] = + scan[0][GRN] = + scan[0][BLU] = 0; + } else { + scan[0][RED] = scan[0][RED] >> -shift; + scan[0][GRN] = scan[0][GRN] >> -shift; + scan[0][BLU] = scan[0][BLU] >> -shift; + } + } + scan[0][EXP] = COLXS; + scan++; + } +} + + +bigdiff(c1, c2, md) /* c1 delta c2 > md? */ +register COLOR c1, c2; +double md; +{ + register int i; + + for (i = 0; i < 3; i++) + if (colval(c1,i)-colval(c2,i) > md*colval(c2,i) || + colval(c2,i)-colval(c1,i) > md*colval(c1,i)) + return(1); + return(0); }