--- ray/src/common/color.c 1992/10/02 15:59:58 2.4 +++ ray/src/common/color.c 1993/06/04 14:51:39 2.7 @@ -12,23 +12,22 @@ static char SCCSid[] = "$SunId$ LBL"; #include +#include + #include "color.h" #define MINELEN 8 /* minimum scanline length for encoding */ +#define MAXELEN 0x7fff /* maximum scanline length for encoding */ #define MINRUN 4 /* minimum run length */ -#ifndef frexp -extern double frexp(); -#endif - char * tempbuffer(len) /* get a temporary buffer */ unsigned len; { extern char *malloc(), *realloc(); static char *tempbuf = NULL; - static int tempbuflen = 0; + static unsigned tempbuflen = 0; if (len > tempbuflen) { if (tempbuflen > 0) @@ -49,7 +48,7 @@ register FILE *fp; register int i, j, beg, cnt; int c2; - if (len < MINELEN | len > 0x7fff) /* 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); @@ -99,9 +98,9 @@ int len; register FILE *fp; { register int i, j; - int code; + int code, val; /* determine scanline type */ - if (len < MINELEN | len > 0x7fff) + if (len < MINELEN | len > MAXELEN) return(oldreadcolrs(scanline, len, fp)); if ((i = getc(fp)) == EOF) return(-1); @@ -126,9 +125,10 @@ register FILE *fp; if ((code = getc(fp)) == EOF) return(-1); if (code > 128) { /* run */ - scanline[j++][i] = getc(fp); - for (code &= 127; --code; j++) - scanline[j][i] = scanline[j-1][i]; + code &= 127; + val = getc(fp); + while (code--) + scanline[j++][i] = val; } else /* non-run */ while (code--) scanline[j++][i] = getc(fp);