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.1 by greg, Thu Feb 2 10:34:29 1989 UTC vs.
Revision 1.11 by greg, Thu Aug 30 09:13:21 1990 UTC

# Line 45 | Line 45 | static BYTE  chroma[3][NINC] = {
45   };
46  
47  
48 < spec_rgb(col, s, e)             /* comput RGB color from spectral range */
48 > spec_rgb(col, s, e)             /* compute RGB color from spectral range */
49   COLOR  col;
50   int  s, e;
51   {
# Line 107 | Line 107 | register COLOR  rgbcolor, ciecolor;
107   #endif
108  
109  
110 + fputresolu(ord, xres, yres, fp)         /* put x and y resolution */
111 + register int  ord;
112 + int  xres, yres;
113 + FILE  *fp;
114 + {
115 +        if (ord&YMAJOR)
116 +                fprintf(fp, "%cY %d %cX %d\n",
117 +                                ord&YDECR ? '-' : '+', yres,
118 +                                ord&XDECR ? '-' : '+', xres);
119 +        else
120 +                fprintf(fp, "%cX %d %cY %d\n",
121 +                                ord&XDECR ? '-' : '+', xres,
122 +                                ord&YDECR ? '-' : '+', yres);
123 + }
124 +
125 +
126 + fgetresolu(xrp, yrp, fp)                /* get x and y resolution */
127 + int  *xrp, *yrp;
128 + FILE  *fp;
129 + {
130 +        char  buf[64], *xndx, *yndx;
131 +        register char  *cp;
132 +        register int  ord;
133 +
134 +        if (fgets(buf, sizeof(buf), fp) == NULL)
135 +                return(-1);
136 +        xndx = yndx = NULL;
137 +        for (cp = buf+1; *cp; cp++)
138 +                if (*cp == 'X')
139 +                        xndx = cp;
140 +                else if (*cp == 'Y')
141 +                        yndx = cp;
142 +        if (xndx == NULL || yndx == NULL)
143 +                return(-1);
144 +        ord = 0;
145 +        if (xndx > yndx) ord |= YMAJOR;
146 +        if (xndx[-1] == '-') ord |= XDECR;
147 +        if (yndx[-1] == '-') ord |= YDECR;
148 +        if ((*xrp = atoi(xndx+1)) <= 0)
149 +                return(-1);
150 +        if ((*yrp = atoi(yndx+1)) <= 0)
151 +                return(-1);
152 +        return(ord);
153 + }
154 +
155 +
156   fwritecolrs(scanline, len, fp)          /* write out a colr scanline */
157   register COLR  *scanline;
158   int  len;
# Line 289 | Line 335 | double  r, g, b;
335          d = r > g ? r : g;
336          if (b > d) d = b;
337  
338 <        if (d <= 0.0) {
338 >        if (d <= 1e-32) {
339                  clr[RED] = clr[GRN] = clr[BLU] = 0;
340                  clr[EXP] = 0;
341                  return;
# Line 308 | Line 354 | colr_color(col, clr)           /* convert short to float color
354   register COLOR  col;
355   register COLR  clr;
356   {
357 <        double  ldexp(), f;
357 >        double  f;
358          
359          if (clr[EXP] == 0)
360                  col[RED] = col[GRN] = col[BLU] = 0.0;
361          else {
362 <                f = ldexp(1.0, clr[EXP]-(COLXS+8));
362 >                f = ldexp(1.0, (int)clr[EXP]-(COLXS+8));
363                  col[RED] = (clr[RED] + 0.5)*f;
364                  col[GRN] = (clr[GRN] + 0.5)*f;
365                  col[BLU] = (clr[BLU] + 0.5)*f;
# Line 321 | Line 367 | register COLR  clr;
367   }
368  
369  
370 < #ifdef  FREXP
371 < double
372 < frexp(x, ip)            /* call it paranoia, I've seen the lib version */
373 < register double  x;
328 < int  *ip;
370 > normcolrs(scan, len, adjust)    /* normalize a scanline of colrs */
371 > register COLR  *scan;
372 > int  len;
373 > int  adjust;
374   {
375 <        int  neg;
376 <        register int  i;
375 >        register int  c;
376 >        register int  shift;
377  
378 <        if (neg = (x < 0.0))
379 <                x = -x;
380 <        else if (x == 0.0) {
381 <                *ip = 0;
382 <                return(0.0);
378 >        while (len-- > 0) {
379 >                shift = scan[0][EXP] + adjust - COLXS;
380 >                if (shift > 0) {
381 >                        if (shift > 8) {
382 >                                scan[0][RED] =
383 >                                scan[0][GRN] =
384 >                                scan[0][BLU] = 255;
385 >                        } else {
386 >                                shift--;
387 >                                c = (scan[0][RED]<<1 | 1) << shift;
388 >                                scan[0][RED] = c > 255 ? 255 : c;
389 >                                c = (scan[0][GRN]<<1 | 1) << shift;
390 >                                scan[0][GRN] = c > 255 ? 255 : c;
391 >                                c = (scan[0][BLU]<<1 | 1) << shift;
392 >                                scan[0][BLU] = c > 255 ? 255 : c;
393 >                        }
394 >                } else if (shift < 0) {
395 >                        if (shift < -8) {
396 >                                scan[0][RED] =
397 >                                scan[0][GRN] =
398 >                                scan[0][BLU] = 0;
399 >                        } else {
400 >                                shift = -1-shift;
401 >                                scan[0][RED] = ((scan[0][RED]>>shift)+1)>>1;
402 >                                scan[0][GRN] = ((scan[0][GRN]>>shift)+1)>>1;
403 >                                scan[0][BLU] = ((scan[0][BLU]>>shift)+1)>>1;
404 >                        }
405 >                }
406 >                scan[0][EXP] = COLXS - adjust;
407 >                scan++;
408          }
339        if (x < 0.5)
340                for (i = 0; x < 0.5; i--)
341                        x *= 2.0;
342        else
343                for (i = 0; x >= 1.0; i++)
344                        x /= 2.0;
345        *ip = i;
346        if (neg)
347                return(-x);
348        else
349                return(x);
409   }
410 < #endif
410 >
411 >
412 > bigdiff(c1, c2, md)                     /* c1 delta c2 > md? */
413 > register COLOR  c1, c2;
414 > double  md;
415 > {
416 >        register int  i;
417 >
418 >        for (i = 0; i < 3; i++)
419 >                if (colval(c1,i)-colval(c2,i) > md*colval(c2,i) ||
420 >                        colval(c2,i)-colval(c1,i) > md*colval(c1,i))
421 >                        return(1);
422 >        return(0);
423 > }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines