--- ray/src/common/color.c 1989/03/15 13:48:37 1.2 +++ ray/src/common/color.c 1989/11/06 15:10:24 1.9 @@ -107,6 +107,52 @@ register COLOR rgbcolor, ciecolor; #endif +fputresolu(ord, xres, yres, fp) /* put x and y resolution */ +register int ord; +int xres, yres; +FILE *fp; +{ + if (ord&YMAJOR) + fprintf(fp, "%cY %d %cX %d\n", + ord&YDECR ? '-' : '+', yres, + ord&XDECR ? '-' : '+', xres); + else + fprintf(fp, "%cX %d %cY %d\n", + ord&XDECR ? '-' : '+', xres, + ord&YDECR ? '-' : '+', yres); +} + + +fgetresolu(xrp, yrp, fp) /* get x and y resolution */ +int *xrp, *yrp; +FILE *fp; +{ + char buf[64], *xndx, *yndx; + register char *cp; + register int ord; + + if (fgets(buf, sizeof(buf), fp) == NULL) + return(-1); + xndx = yndx = NULL; + for (cp = buf+1; *cp; cp++) + if (*cp == 'X') + xndx = cp; + else if (*cp == 'Y') + yndx = cp; + if (xndx == NULL || yndx == NULL) + return(-1); + ord = 0; + if (xndx > yndx) ord |= YMAJOR; + if (xndx[-1] == '-') ord |= XDECR; + if (yndx[-1] == '-') ord |= YDECR; + if ((*xrp = atoi(xndx+1)) <= 0) + return(-1); + if ((*yrp = atoi(yndx+1)) <= 0) + return(-1); + return(ord); +} + + fwritecolrs(scanline, len, fp) /* write out a colr scanline */ register COLR *scanline; int len; @@ -289,7 +335,7 @@ double r, g, b; d = r > g ? r : g; if (b > d) d = b; - if (d <= 0.0) { + if (d <= 1e-32) { clr[RED] = clr[GRN] = clr[BLU] = 0; clr[EXP] = 0; return; @@ -308,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; @@ -321,31 +367,56 @@ register COLR clr; } -#ifdef FREXP -double -frexp(x, ip) /* call it paranoia, I've seen the lib version */ -register double x; -int *ip; +normcolrs(scan, len) /* normalize a scanline of colrs */ +register COLR *scan; +int len; { - int neg; - register int i; + register int c; + register int shift; - if (neg = (x < 0.0)) - x = -x; - else if (x == 0.0) { - *ip = 0; - return(0.0); + 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 { + shift--; + c = (scan[0][RED]<<1 | 1) << shift; + scan[0][RED] = c > 255 ? 255 : c; + c = (scan[0][GRN]<<1 | 1) << shift; + scan[0][GRN] = c > 255 ? 255 : c; + c = (scan[0][BLU]<<1 | 1) << 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 { + shift = -1-shift; + scan[0][RED] = ((scan[0][RED]>>shift)+1)>>1; + scan[0][GRN] = ((scan[0][GRN]>>shift)+1)>>1; + scan[0][BLU] = ((scan[0][BLU]>>shift)+1)>>1; + } + } + scan[0][EXP] = COLXS; + scan++; } - if (x < 0.5) - for (i = 0; x < 0.5; i--) - x *= 2.0; - else - for (i = 0; x >= 1.0; i++) - x /= 2.0; - *ip = i; - if (neg) - return(-x); - else - return(x); } -#endif + + +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); +}