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.5 by greg, Sat Feb 22 02:07:27 2003 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1986 Regents of the University of California */
2
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ LBL";
2 > static const char       RCSid[] = "$Id$";
3   #endif
6
4   /*
5   *  aedimage.c - RADIANCE driver for AED 512 terminal.
6   *
# Line 13 | Line 10 | static char SCCSid[] = "$SunId$ LBL";
10  
11   #include  <stdio.h>
12  
13 + #include  <math.h>
14 +
15   #include  <signal.h>
16  
17   #include  <sys/ioctl.h>
# Line 97 | Line 96 | FILE  *fin;
96   extern long  ftell();
97   long  scanpos[NROWS];
98  
100 extern double  atof();
99   double  exposure = 1.0;
100 + int  wrong_fmt = 0;
101  
102  
103   main(argc, argv)
104   int  argc;
105   char  *argv[];
106   {
107 <        int  onintr();
109 <        double  atof();
107 >        int  onintr(), checkhead();
108          char  sbuf[256];
109          register int  i;
110          
# Line 141 | Line 139 | char  *argv[];
139                  quitmsg(errmsg);
140          }
141                                  /* get header */
142 <        while (fgets(sbuf, sizeof(sbuf), fin) != NULL && sbuf[0] != '\n')
143 <                if (!strncmp(sbuf, "EXPOSURE=", 9))
144 <                        exposure *= atof(sbuf+9);
147 <
142 >        getheader(fin, checkhead, NULL);
143 >        if (wrong_fmt)
144 >                quitmsg("input must be a Radiance picture");
145                                  /* get picture dimensions */
146 <        if (fgetresolu(&xmax, &ymax, fin) != (YMAJOR|YDECR))
146 >        if (fgetresolu(&xmax, &ymax, fin) < 0)
147                  quitmsg("bad picture size");
148          if (xmax > NCOLS || ymax > NROWS)
149                  quitmsg("resolution mismatch");
# Line 170 | Line 167 | userr:
167   }
168  
169  
170 + int
171 + checkhead(line)                         /* deal with line from header */
172 + char  *line;
173 + {
174 +        char    fmt[32];
175 +
176 +        if (isexpos(line))
177 +                exposure *= exposval(line);
178 +        else if (isformat(line)) {
179 +                formatval(fmt, line);
180 +                wrong_fmt = strcmp(fmt, COLRFMT);
181 +        }
182 +        return(0);
183 + }
184 +
185 +
186   init()                  /* initialize terminal */
187   {
188          struct sgttyb  flags;
# Line 231 | Line 244 | char  *err;
244   }
245  
246  
247 + void
248   eputs(s)
249   char  *s;
250   {
# Line 238 | Line 252 | char  *s;
252   }
253  
254  
255 + void
256   quit(status)
257   int  status;
258   {
# Line 311 | Line 326 | loopcom()                              /* print pixel values interactively */
326                                  break;
327                          case 'l':
328                          case 'L':
329 <                                printf("%-3gL", bright(cval)*683.0/exposure);
329 >                                printf("%-3gL", luminance(cval)/exposure);
330                                  break;
331                          case 'c':
332                          case 'C':
# Line 392 | Line 407 | picreadline3(y, l3)                    /* read in 3-byte scanline */
407   int  y;
408   register rgbpixel  *l3;
409   {
410 <        register BYTE   *l4;
411 <        register int    shift, c;
397 <        int     i;
398 <
410 >        register int    i;
411 >                                                        /* read scanline */
412          getscan(y);
413                                                          /* convert scanline */
414 <        for (l4=scanline[0], i=xmax; i--; l4+=4, l3++) {
415 <                shift = l4[EXP] - COLXS;
416 <                if (shift >= 8) {
417 <                        l3->r = l3->g = l3->b = 255;
418 <                } 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 <                }
414 >        normcolrs(scanline, xmax, 0);
415 >        for (i = 0; i < xmax; i++) {
416 >                l3[i].r = scanline[i][RED];
417 >                l3[i].g = scanline[i][GRN];
418 >                l3[i].b = scanline[i][BLU];
419          }
420   }
421  
# Line 526 | Line 522 | int  offset[3];
522   picreadcm(map)                  /* do gamma correction */
523   colormap  map;
524   {
529        extern double  pow();
525          register int  i, val;
526  
527          for (i = 0; i < 256; i++) {
528 <                val = pow(i/256.0, 1.0/GAMMA) * 256.0;
528 >                val = pow((i+0.5)/256.0, 1.0/GAMMA) * 256.0;
529                  map[0][i] = map[1][i] = map[2][i] = val;
530          }
531   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines