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

Comparing ray/src/px/ra_pr.c (file contents):
Revision 2.2 by greg, Thu Dec 19 14:52:14 1991 UTC vs.
Revision 2.7 by schorsch, Sun Mar 28 20:33:14 2004 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1991 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   *  ra_pr.c - program to convert between RADIANCE and pixrect picture format.
6   *
# Line 12 | Line 9 | static char SCCSid[] = "$SunId$ LBL";
9   */
10  
11   #include  <stdio.h>
12 + #include  <math.h>
13 + #include  <time.h>
14  
15 + #include  "rtmisc.h"
16   #include  "rasterfile.h"
17
17   #include  "color.h"
19
18   #include  "resolu.h"
21
19   #include  "pic.h"
20  
21                          /* descriptor for a picture file or frame buffer */
# Line 33 | Line 30 | typedef struct {
30          } pos;                          /* position(s) */
31   } pic;
32  
36 extern pic      *openinput(), *openoutput();
33  
34 < extern char     *ecalloc(), *emalloc();
39 <
40 < extern long  ftell();
41 <
42 < extern double  pow();
43 <
44 < double  gamma = 2.2;                    /* gamma correction */
45 <
34 > double  gamcor = 2.2;                   /* gamma correction */
35   int  bradj = 0;                         /* brightness adjustment */
47
36   pic     *inpic, *outpic;
49
37   char  *progname;
51
38   char  errmsg[128];
53
39   COLR    *inl;
55
40   int  xmax, ymax;
41  
42 + static void quiterr(char  *err);
43 + static pic * openinput(char  *fname, struct rasterfile  *h);
44 + static pic * openoutput(char  *fname, struct rasterfile  *h);
45 + static void pr2ra(struct rasterfile  *h);
46  
47 < main(argc, argv)
48 < int  argc;
49 < char  *argv[];
47 >
48 > int
49 > main(int  argc, char  *argv[])
50   {
51          colormap  rasmap;
52          struct rasterfile  head;
# Line 77 | Line 65 | char  *argv[];
65                                  dither = !dither;
66                                  break;
67                          case 'g':
68 <                                gamma = atof(argv[++i]);
68 >                                gamcor = atof(argv[++i]);
69                                  break;
70                          case 'b':
71                                  greyscale = !greyscale;
# Line 122 | Line 110 | char  *argv[];
110                                  head.ras_depth != 8)
111                          quiterr("incompatible format");
112                                          /* put header */
113 +                newheader("RADIANCE", stdout);
114                  printargs(i, argv, stdout);
115                  fputformat(COLRFMT, stdout);
116                  putchar('\n');
# Line 157 | Line 146 | userr:
146   }
147  
148  
149 < quiterr(err)            /* print message and exit */
150 < char  *err;
149 > static void
150 > quiterr(                /* print message and exit */
151 >        char  *err
152 > )
153   {
154          if (err != NULL) {
155                  fprintf(stderr, "%s: %s\n", progname, err);
# Line 168 | Line 159 | char  *err;
159   }
160  
161  
162 + void
163   eputs(s)
164   char *s;
165   {
# Line 175 | Line 167 | char *s;
167   }
168  
169  
170 + void
171   quit(code)
172   int code;
173   {
# Line 182 | Line 175 | int code;
175   }
176  
177  
178 < pic *
179 < openinput(fname, h)             /* open RADIANCE input file */
180 < char  *fname;
181 < register struct rasterfile  *h;
178 > static pic *
179 > openinput(              /* open RADIANCE input file */
180 >        char  *fname,
181 >        register struct rasterfile  *h
182 > )
183   {
184          register pic  *p;
185  
# Line 219 | Line 213 | register struct rasterfile  *h;
213   }
214  
215  
216 < pic *
217 < openoutput(fname, h)            /* open output rasterfile */
218 < char  *fname;
219 < register struct rasterfile  *h;
216 > static pic *
217 > openoutput(             /* open output rasterfile */
218 >        char  *fname,
219 >        register struct rasterfile  *h
220 > )
221   {
222          register pic  *p;
223  
# Line 242 | Line 237 | register struct rasterfile  *h;
237   }
238  
239  
240 < pr2ra(h)                        /* pixrect file to RADIANCE file */
241 < struct rasterfile  *h;
240 > static void
241 > pr2ra(                  /* pixrect file to RADIANCE file */
242 >        struct rasterfile  *h
243 > )
244   {
245          BYTE  cmap[3][256];
246          COLR  ctab[256];
# Line 258 | Line 255 | struct rasterfile  *h;
255                                          /* convert table */
256          for (i = 0; i < h->ras_maplength/3; i++)
257                  setcolr(ctab[i],
258 <                                pow((cmap[0][i]+.5)/256.,gamma),
259 <                                pow((cmap[1][i]+.5)/256.,gamma),
260 <                                pow((cmap[2][i]+.5)/256.,gamma));
258 >                                pow((cmap[0][i]+.5)/256.,gamcor),
259 >                                pow((cmap[1][i]+.5)/256.,gamcor),
260 >                                pow((cmap[2][i]+.5)/256.,gamcor));
261          if (bradj)
262                  shiftcolrs(ctab, 256, bradj);
263                                          /* convert file */
# Line 275 | Line 272 | struct rasterfile  *h;
272                  if (fwritecolrs(scanline, xmax, stdout) < 0)
273                          quiterr("error writing RADIANCE file");
274          }
275 <        free((char *)scanline);
275 >        free((void *)scanline);
276   }
277  
278  
279 < picreadline3(y, l3)                     /* read in 3-byte scanline */
280 < int  y;
281 < register rgbpixel  *l3;
279 > extern void
280 > picreadline3(                   /* read in 3-byte scanline */
281 >        int  y,
282 >        register rgbpixel  *l3
283 > )
284   {
285          register int    i;
286  
# Line 312 | Line 311 | register rgbpixel  *l3;
311   }
312  
313  
314 < picwriteline(y, l)                      /* write out scanline */
315 < int  y;
316 < register pixel  *l;
314 > extern void
315 > picwriteline(                   /* write out scanline */
316 >        int  y,
317 >        register pixel  *l
318 > )
319   {
320          if (outpic->nexty != y) {                       /* seek to scanline */
321                  if (outpic->bytes_line == 0) {
# Line 336 | Line 337 | register pixel  *l;
337   }
338  
339  
340 < picwritecm(cm)                  /* write out color map */
341 < colormap  cm;
340 > extern void
341 > picwritecm(                     /* write out color map */
342 >        colormap  cm
343 > )
344   {
345          register int  i, j;
346  
# Line 355 | Line 358 | colormap  cm;
358   }
359  
360  
361 < picreadcm(map)                  /* do gamma correction if requested */
362 < colormap  map;
361 > extern void
362 > picreadcm(                      /* do gamma correction if requested */
363 >        colormap  map
364 > )
365   {
366          register int  i, val;
367  
368          for (i = 0; i < 256; i++) {
369 <                val = pow((i+0.5)/256.0, 1.0/gamma) * 256.0;
369 >                val = pow((i+0.5)/256.0, 1.0/gamcor) * 256.0;
370                  map[0][i] = map[1][i] = map[2][i] = val;
371          }
372   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines