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

Comparing ray/src/px/aedimage.c (file contents):
Revision 1.1 by greg, Thu Feb 2 10:49:04 1989 UTC vs.
Revision 2.3 by greg, Fri Oct 2 16:21:47 1992 UTC

# Line 13 | Line 13 | static char SCCSid[] = "$SunId$ LBL";
13  
14   #include  <stdio.h>
15  
16 + #include  <math.h>
17 +
18   #include  <signal.h>
19  
20   #include  <sys/ioctl.h>
# Line 58 | Line 60 | static char SCCSid[] = "$SunId$ LBL";
60   #define byte(b)         putc(b, stdout)
61   #define flush()         fflush(stdout)
62  
63 < #define  GAMMA          2.0             /* gamma value used in correction */
63 > #define  GAMMA          2.5             /* gamma value used in correction */
64  
65   #define  MINCOLOR       8               /* start of device color table */
66  
# Line 97 | Line 99 | FILE  *fin;
99   extern long  ftell();
100   long  scanpos[NROWS];
101  
100 extern double  atof();
102   double  exposure = 1.0;
103 + int  wrong_fmt = 0;
104  
105  
106   main(argc, argv)
107   int  argc;
108   char  *argv[];
109   {
110 <        int  onintr();
109 <        double  atof();
110 >        int  onintr(), checkhead();
111          char  sbuf[256];
112          register int  i;
113          
# Line 141 | Line 142 | char  *argv[];
142                  quitmsg(errmsg);
143          }
144                                  /* get header */
145 <        while (fgets(sbuf, sizeof(sbuf), fin) != NULL && sbuf[0] != '\n')
146 <                if (!strncmp(sbuf, "EXPOSURE=", 9))
147 <                        exposure *= atof(sbuf+9);
147 <
145 >        getheader(fin, checkhead, NULL);
146 >        if (wrong_fmt)
147 >                quitmsg("input must be a Radiance picture");
148                                  /* get picture dimensions */
149 <        if (fgets(sbuf, sizeof(sbuf), fin) == NULL ||
150 <                        sscanf(sbuf, "-Y %d +X %d\n", &ymax, &xmax) != 2)
149 >        if (fgetresolu(&xmax, &ymax, fin) < 0)
150                  quitmsg("bad picture size");
151          if (xmax > NCOLS || ymax > NROWS)
152                  quitmsg("resolution mismatch");
# Line 171 | Line 170 | userr:
170   }
171  
172  
173 + checkhead(line)                         /* deal with line from header */
174 + char  *line;
175 + {
176 +        char    fmt[32];
177 +
178 +        if (isexpos(line))
179 +                exposure *= exposval(line);
180 +        else if (isformat(line)) {
181 +                formatval(fmt, line);
182 +                wrong_fmt = strcmp(fmt, COLRFMT);
183 +        }
184 + }
185 +
186 +
187   init()                  /* initialize terminal */
188   {
189          struct sgttyb  flags;
# Line 312 | Line 325 | loopcom()                              /* print pixel values interactively */
325                                  break;
326                          case 'l':
327                          case 'L':
328 <                                printf("%-3gL", bright(cval)*683.0/exposure);
328 >                                printf("%-3gL", luminance(cval)/exposure);
329                                  break;
330                          case 'c':
331                          case 'C':
# Line 393 | Line 406 | picreadline3(y, l3)                    /* read in 3-byte scanline */
406   int  y;
407   register rgbpixel  *l3;
408   {
409 <        register BYTE   *l4;
410 <        register int    shift, c;
398 <        int     i;
399 <
409 >        register int    i;
410 >                                                        /* read scanline */
411          getscan(y);
412                                                          /* convert scanline */
413 <        for (l4=scanline[0], i=xmax; i--; l4+=4, l3++) {
414 <                shift = l4[EXP] - COLXS;
415 <                if (shift >= 8) {
416 <                        l3->r = l3->g = l3->b = 255;
417 <                } else if (shift <= -8) {
407 <                        l3->r = l3->g = l3->b = 0;
408 <                } else if (shift > 0) {
409 <                        c = l4[RED] << shift;
410 <                        l3->r = c > 255 ? 255 : c;
411 <                        c = l4[GRN] << shift;
412 <                        l3->g = c > 255 ? 255 : c;
413 <                        c = l4[BLU] << shift;
414 <                        l3->b = c > 255 ? 255 : c;
415 <                } else if (shift < 0) {
416 <                        l3->r = l4[RED] >> -shift;
417 <                        l3->g = l4[GRN] >> -shift;
418 <                        l3->b = l4[BLU] >> -shift;
419 <                } else {
420 <                        l3->r = l4[RED];
421 <                        l3->g = l4[GRN];
422 <                        l3->b = l4[BLU];
423 <                }
413 >        normcolrs(scanline, xmax, 0);
414 >        for (i = 0; i < xmax; i++) {
415 >                l3[i].r = scanline[i][RED];
416 >                l3[i].g = scanline[i][GRN];
417 >                l3[i].b = scanline[i][BLU];
418          }
419   }
420  
# Line 527 | Line 521 | int  offset[3];
521   picreadcm(map)                  /* do gamma correction */
522   colormap  map;
523   {
530        extern double  pow();
524          register int  i, val;
525  
526          for (i = 0; i < 256; i++) {
527 <                val = pow(i/256.0, 1.0/GAMMA) * 256.0;
527 >                val = pow((i+0.5)/256.0, 1.0/GAMMA) * 256.0;
528                  map[0][i] = map[1][i] = map[2][i] = val;
529          }
530   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines