ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/color.c
(Generate patch)

Comparing ray/src/common/color.c (file contents):
Revision 1.14 by greg, Fri Aug 23 12:33:49 1991 UTC vs.
Revision 2.5 by greg, Fri Feb 26 10:08:50 1993 UTC

# Line 15 | Line 15 | static char SCCSid[] = "$SunId$ LBL";
15   #include  "color.h"
16  
17   #define  MINELEN        8       /* minimum scanline length for encoding */
18 + #define  MAXELEN        0x7ffe  /* maximum scanline length for encoding */
19   #define  MINRUN         4       /* minimum run length */
20  
21 + #ifndef frexp
22 + extern double  frexp();
23 + #endif
24  
25 +
26   char *
27   tempbuffer(len)                 /* get a temporary buffer */
28   unsigned  len;
29   {
30          extern char  *malloc(), *realloc();
31          static char  *tempbuf = NULL;
32 <        static int  tempbuflen = 0;
32 >        static unsigned  tempbuflen = 0;
33  
34          if (len > tempbuflen) {
35                  if (tempbuflen > 0)
# Line 39 | Line 44 | unsigned  len;
44  
45   fwritecolrs(scanline, len, fp)          /* write out a colr scanline */
46   register COLR  *scanline;
47 < int  len;
47 > unsigned  len;
48   register FILE  *fp;
49   {
50          register int  i, j, beg, cnt;
51          int  c2;
52          
53 <        if (len < MINELEN)              /* too small to encode */
53 >        if (len < MINELEN | len > MAXELEN)      /* OOBs, write out flat */
54                  return(fwrite((char *)scanline,sizeof(COLR),len,fp) - len);
55 <        if (len > 32767)                /* too big! */
51 <                return(-1);
52 <        putc(2, fp);                    /* put magic header */
55 >                                        /* put magic header */
56          putc(2, fp);
57 +        putc(2, fp);
58          putc(len>>8, fp);
59          putc(len&255, fp);
60                                          /* put components seperately */
# Line 63 | Line 67 | register FILE  *fp;
67                      if (cnt >= MINRUN)
68                          break;                  /* long enough */
69                  }
70 <                while (j < beg) {               /* write out non-run(s) */
70 >                if (beg-j > 1 && beg-j < MINRUN) {
71 >                    c2 = j+1;
72 >                    while (scanline[c2++][i] == scanline[j][i])
73 >                        if (c2 == beg) {        /* short run */
74 >                            putc(128+beg-j, fp);
75 >                            putc(scanline[j][i], fp);
76 >                            j = beg;
77 >                            break;
78 >                        }
79 >                }
80 >                while (j < beg) {               /* write out non-run */
81                      if ((c2 = beg-j) > 128) c2 = 128;
82                      putc(c2, fp);
83                      while (c2--)
# Line 88 | Line 102 | register FILE  *fp;
102          register int  i, j;
103          int  code;
104                                          /* determine scanline type */
105 <        if (len < MINELEN)
105 >        if (len < MINELEN | len > MAXELEN)
106                  return(oldreadcolrs(scanline, len, fp));
107          if ((i = getc(fp)) == EOF)
108                  return(-1);
# Line 216 | Line 230 | setcolr(clr, r, g, b)          /* assign a short color value *
230   register COLR  clr;
231   double  r, g, b;
232   {
219        double  frexp();
233          double  d;
234          int  e;
235          

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines