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.3 by greg, Tue Sep 12 13:04:16 1989 UTC vs.
Revision 2.4 by gwlarson, Tue Oct 27 09:08:25 1998 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 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 (fgetresolu(&xmax, &ymax, fin) != (YMAJOR|YDECR))
149 >        if (fgetresolu(&xmax, &ymax, fin) < 0)
150                  quitmsg("bad picture size");
151          if (xmax > NCOLS || ymax > NROWS)
152                  quitmsg("resolution mismatch");
# Line 170 | Line 170 | userr:
170   }
171  
172  
173 + int
174 + checkhead(line)                         /* deal with line from header */
175 + char  *line;
176 + {
177 +        char    fmt[32];
178 +
179 +        if (isexpos(line))
180 +                exposure *= exposval(line);
181 +        else if (isformat(line)) {
182 +                formatval(fmt, line);
183 +                wrong_fmt = strcmp(fmt, COLRFMT);
184 +        }
185 +        return(0);
186 + }
187 +
188 +
189   init()                  /* initialize terminal */
190   {
191          struct sgttyb  flags;
# Line 311 | Line 327 | loopcom()                              /* print pixel values interactively */
327                                  break;
328                          case 'l':
329                          case 'L':
330 <                                printf("%-3gL", bright(cval)*683.0/exposure);
330 >                                printf("%-3gL", luminance(cval)/exposure);
331                                  break;
332                          case 'c':
333                          case 'C':
# Line 392 | Line 408 | picreadline3(y, l3)                    /* read in 3-byte scanline */
408   int  y;
409   register rgbpixel  *l3;
410   {
411 <        register BYTE   *l4;
412 <        register int    shift, c;
397 <        int     i;
398 <
411 >        register int    i;
412 >                                                        /* read scanline */
413          getscan(y);
414                                                          /* convert scanline */
415 <        for (l4=scanline[0], i=xmax; i--; l4+=4, l3++) {
416 <                shift = l4[EXP] - COLXS;
417 <                if (shift >= 8) {
418 <                        l3->r = l3->g = l3->b = 255;
419 <                } else if (shift <= -8) {
406 <                        l3->r = l3->g = l3->b = 0;
407 <                } else if (shift > 0) {
408 <                        c = l4[RED] << shift;
409 <                        l3->r = c > 255 ? 255 : c;
410 <                        c = l4[GRN] << shift;
411 <                        l3->g = c > 255 ? 255 : c;
412 <                        c = l4[BLU] << shift;
413 <                        l3->b = c > 255 ? 255 : c;
414 <                } else if (shift < 0) {
415 <                        l3->r = l4[RED] >> -shift;
416 <                        l3->g = l4[GRN] >> -shift;
417 <                        l3->b = l4[BLU] >> -shift;
418 <                } else {
419 <                        l3->r = l4[RED];
420 <                        l3->g = l4[GRN];
421 <                        l3->b = l4[BLU];
422 <                }
415 >        normcolrs(scanline, xmax, 0);
416 >        for (i = 0; i < xmax; i++) {
417 >                l3[i].r = scanline[i][RED];
418 >                l3[i].g = scanline[i][GRN];
419 >                l3[i].b = scanline[i][BLU];
420          }
421   }
422  
# Line 526 | Line 523 | int  offset[3];
523   picreadcm(map)                  /* do gamma correction */
524   colormap  map;
525   {
529        extern double  pow();
526          register int  i, val;
527  
528          for (i = 0; i < 256; i++) {
529 <                val = pow(i/256.0, 1.0/GAMMA) * 256.0;
529 >                val = pow((i+0.5)/256.0, 1.0/GAMMA) * 256.0;
530                  map[0][i] = map[1][i] = map[2][i] = val;
531          }
532   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines