--- ray/src/common/color.c 1991/08/23 12:33:49 1.14 +++ ray/src/common/color.c 1992/06/23 10:59:34 2.2 @@ -39,18 +39,17 @@ unsigned len; fwritecolrs(scanline, len, fp) /* write out a colr scanline */ register COLR *scanline; -int len; +unsigned len; register FILE *fp; { register int i, j, beg, cnt; int c2; - if (len < MINELEN) /* too small to encode */ + if (len < MINELEN | len > 0x7fff) /* OOBs, write out flat */ return(fwrite((char *)scanline,sizeof(COLR),len,fp) - len); - if (len > 32767) /* too big! */ - return(-1); - putc(2, fp); /* put magic header */ + /* put magic header */ putc(2, fp); + putc(2, fp); putc(len>>8, fp); putc(len&255, fp); /* put components seperately */ @@ -63,7 +62,17 @@ register FILE *fp; if (cnt >= MINRUN) break; /* long enough */ } - while (j < beg) { /* write out non-run(s) */ + if (beg-j > 1 && beg-j < MINRUN) { + c2 = j+1; + while (scanline[c2++][i] == scanline[j][i]) + if (c2 == beg) { /* short run */ + putc(128+beg-j, fp); + putc(scanline[j][i], fp); + j = beg; + break; + } + } + while (j < beg) { /* write out non-run */ if ((c2 = beg-j) > 128) c2 = 128; putc(c2, fp); while (c2--)