--- ray/src/common/color.c 2003/02/25 02:47:21 2.10 +++ ray/src/common/color.c 2004/09/14 02:53:50 2.15 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: color.c,v 2.10 2003/02/25 02:47:21 greg Exp $"; +static const char RCSid[] = "$Id: color.c,v 2.15 2004/09/14 02:53:50 greg Exp $"; #endif /* * color.c - routines for color calculations. @@ -17,6 +17,13 @@ static const char RCSid[] = "$Id: color.c,v 2.10 2003/ #include "color.h" +#ifdef getc_unlocked /* avoid horrendous overhead of flockfile */ +#undef getc +#undef putc +#define getc getc_unlocked +#define putc putc_unlocked +#endif + #define MINELEN 8 /* minimum scanline length for encoding */ #define MAXELEN 0x7fff /* maximum scanline length for encoding */ #define MINRUN 4 /* minimum run length */ @@ -31,7 +38,7 @@ unsigned int len; if (len > tempbuflen) { if (tempbuflen > 0) - tempbuf = (char *)realloc(tempbuf, len); + tempbuf = (char *)realloc((void *)tempbuf, len); else tempbuf = (char *)malloc(len); tempbuflen = tempbuf==NULL ? 0 : len; @@ -49,7 +56,7 @@ register FILE *fp; register int i, j, beg, cnt = 1; int c2; - if (len < MINELEN | len > MAXELEN) /* OOBs, write out flat */ + if ((len < MINELEN) | (len > MAXELEN)) /* OOBs, write out flat */ return(fwrite((char *)scanline,sizeof(COLR),len,fp) - len); /* put magic header */ putc(2, fp); @@ -139,7 +146,7 @@ register FILE *fp; register int i, j; int code, val; /* determine scanline type */ - if (len < MINELEN | len > MAXELEN) + if ((len < MINELEN) | (len > MAXELEN)) return(oldreadcolrs(scanline, len, fp)); if ((i = getc(fp)) == EOF) return(-1); @@ -253,9 +260,19 @@ double r, g, b; d = frexp(d, &e) * 255.9999 / d; - clr[RED] = r * d; - clr[GRN] = g * d; - clr[BLU] = b * d; + if (r > 0.0) + clr[RED] = r * d; + else + clr[RED] = 0; + if (g > 0.0) + clr[GRN] = g * d; + else + clr[GRN] = 0; + if (b > 0.0) + clr[BLU] = b * d; + else + clr[BLU] = 0; + clr[EXP] = e + COLXS; }