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 1.3 by greg, Tue Sep 12 13:04:34 1989 UTC vs.
Revision 2.5 by greg, Sun Feb 27 10:17:12 1994 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1986 Regents of the University of California */
1 > /* Copyright (c) 1991 Regents of the University of California */
2  
3   #ifndef lint
4   static char SCCSid[] = "$SunId$ LBL";
# Line 13 | Line 13 | static char SCCSid[] = "$SunId$ LBL";
13  
14   #include  <stdio.h>
15  
16 + #include  <math.h>
17 +
18   #include  "rasterfile.h"
19  
20   #include  "color.h"
21  
22 + #include  "resolu.h"
23 +
24   #include  "pic.h"
25  
26                          /* descriptor for a picture file or frame buffer */
# Line 37 | Line 41 | extern char    *ecalloc(), *emalloc();
41  
42   extern long  ftell();
43  
44 < extern double  atof(), pow();
44 > double  gamcor = 2.2;                   /* gamma correction */
45  
46 < double  gamma = 2.0;                    /* gamma correction */
46 > int  bradj = 0;                         /* brightness adjustment */
47  
48   pic     *inpic, *outpic;
49  
# Line 47 | Line 51 | char  *progname;
51  
52   char  errmsg[128];
53  
54 < COLR    *inline;
54 > COLR    *inl;
55  
56   int  xmax, ymax;
57  
# Line 73 | Line 77 | char  *argv[];
77                                  dither = !dither;
78                                  break;
79                          case 'g':
80 <                                gamma = atof(argv[++i]);
80 >                                gamcor = atof(argv[++i]);
81                                  break;
82                          case 'b':
83                                  greyscale = !greyscale;
84                                  break;
85 +                        case 'e':
86 +                                if (argv[i+1][0] != '+' && argv[i+1][0] != '-')
87 +                                        goto userr;
88 +                                bradj = atoi(argv[++i]);
89 +                                break;
90                          case 'r':
91                                  reverse = !reverse;
92                                  break;
# Line 102 | Line 111 | char  *argv[];
111                          quiterr(errmsg);
112                  }
113                                          /* get header */
114 <                if (fread(&head, sizeof(head), 1, stdin) != 1)
114 >                if (fread((char *)&head, sizeof(head), 1, stdin) != 1)
115                          quiterr("missing header");
116                  if (head.ras_magic != RAS_MAGIC)
117                          quiterr("bad raster format");
# Line 113 | Line 122 | char  *argv[];
122                                  head.ras_depth != 8)
123                          quiterr("incompatible format");
124                                          /* put header */
125 <                printargs(argc, argv, stdout);
125 >                newheader("RADIANCE", stdout);
126 >                printargs(i, argv, stdout);
127 >                fputformat(COLRFMT, stdout);
128                  putchar('\n');
129 <                fputresolu(YMAJOR|YDECR, xmax, ymax, stdout);
129 >                fprtresolu(xmax, ymax, stdout);
130                                          /* convert file */
131                  pr2ra(&head);
132          } else {
133 <                if (i > argc-1 || i < argc-2)
133 >                if (i < argc-2 || (!greyscale && i > argc-1))
134                          goto userr;
135                  if ((inpic = openinput(argv[i], &head)) == NULL) {
136                          sprintf(errmsg, "can't open input \"%s\"", argv[i]);
# Line 139 | Line 150 | char  *argv[];
150          quiterr(NULL);
151   userr:
152          fprintf(stderr,
153 <        "Usage: %s [-d][-c ncolors][-b][-g gamma] input [output]\n",
153 >        "Usage: %s [-d][-c ncolors][-b][-g gamma][-e +/-stops] input [output]\n",
154                          progname);
155 <        fprintf(stderr, "   Or: %s -r [-g gamma] [input [output]]\n",
155 >        fprintf(stderr, "   Or: %s -r [-g gamma][-e +/-stops] [input [output]]\n",
156                          progname);
157          exit(1);
158   }
# Line 185 | Line 196 | register struct rasterfile  *h;
196                  p->fp = stdin;
197          else if ((p->fp = fopen(fname, "r")) == NULL)
198                  return(NULL);
199 <                                        /* discard header */
200 <        getheader(p->fp, NULL);
201 <        if (fgetresolu(&xmax, &ymax, p->fp) != (YMAJOR|YDECR))
202 <                quiterr("bad picture size");
199 >                                        /* check header */
200 >        if (checkheader(p->fp, COLRFMT, NULL) < 0 ||
201 >                        fgetresolu(&xmax, &ymax, p->fp) < 0)
202 >                quiterr("bad picture format");
203          p->nexty = 0;
204          p->bytes_line = 0;              /* variable length lines */
205          p->pos.y = (long *)ecalloc(ymax, sizeof(long));
# Line 203 | Line 214 | register struct rasterfile  *h;
214          h->ras_maptype = RMT_EQUAL_RGB;
215          h->ras_maplength = 256*3;
216                                          /* allocate scanline */
217 <        inline = (COLR *)emalloc(xmax*sizeof(COLR));
217 >        inl = (COLR *)emalloc(xmax*sizeof(COLR));
218  
219          return(p);
220   }
# Line 223 | Line 234 | register struct rasterfile  *h;
234          else if ((p->fp = fopen(fname, "w")) == NULL)
235                  return(NULL);
236                                          /* write header */
237 <        fwrite(h, sizeof(*h), 1, p->fp);
237 >        fwrite((char *)h, sizeof(*h), 1, p->fp);
238          p->nexty = -1;                  /* needs color map */
239          p->bytes_line = h->ras_width;
240          p->pos.b = 0;
# Line 243 | Line 254 | struct rasterfile  *h;
254          scanline = (COLR *)emalloc(xmax*sizeof(COLR));
255                                          /* get color table */
256          for (i = 0; i < 3; i ++)
257 <                if (fread(cmap[i], h->ras_maplength/3, 1, stdin) != 1)
257 >                if (fread((char *)cmap[i], h->ras_maplength/3, 1, stdin) != 1)
258                          quiterr("error reading color table");
259                                          /* convert table */
260          for (i = 0; i < h->ras_maplength/3; i++)
261                  setcolr(ctab[i],
262 <                                pow((cmap[0][i]+.5)/256.,gamma),
263 <                                pow((cmap[1][i]+.5)/256.,gamma),
264 <                                pow((cmap[2][i]+.5)/256.,gamma));
262 >                                pow((cmap[0][i]+.5)/256.,gamcor),
263 >                                pow((cmap[1][i]+.5)/256.,gamcor),
264 >                                pow((cmap[2][i]+.5)/256.,gamcor));
265 >        if (bradj)
266 >                shiftcolrs(ctab, 256, bradj);
267                                          /* convert file */
268          for (i = 0; i < ymax; i++) {
269                  for (j = 0; j < xmax; j++) {
# Line 271 | Line 284 | picreadline3(y, l3)                    /* read in 3-byte scanline */
284   int  y;
285   register rgbpixel  *l3;
286   {
287 <        register BYTE   *l4;
275 <        register int    shift, c;
276 <        int     i;
287 >        register int    i;
288  
289 <        if (inpic->nexty != y) {                                /* find scanline */
289 >        if (inpic->nexty != y) {                        /* find scanline */
290                  if (inpic->bytes_line == 0) {
291                          if (inpic->pos.y[y] == 0) {
292                                  while (inpic->nexty < y) {
293 <                                        if (freadcolrs(inline, xmax, inpic->fp) < 0)
293 >                                        if (freadcolrs(inl, xmax, inpic->fp) < 0)
294                                                  quiterr("read error in picreadline3");
295                                          inpic->pos.y[++inpic->nexty] = ftell(inpic->fp);
296                                  }
# Line 289 | Line 300 | register rgbpixel  *l3;
300                          quiterr("seek error in picreadline3");
301          } else if (inpic->bytes_line == 0 && inpic->pos.y[inpic->nexty] == 0)
302                  inpic->pos.y[inpic->nexty] = ftell(inpic->fp);
303 <        if (freadcolrs(inline, xmax, inpic->fp) < 0)    /* read scanline */
303 >        if (freadcolrs(inl, xmax, inpic->fp) < 0)       /* read scanline */
304                  quiterr("read error in picreadline3");
305          inpic->nexty = y+1;
306                                                          /* convert scanline */
307 <        for (l4=inline[0], i=xmax; i--; l4+=4, l3++) {
308 <                shift = l4[EXP] - COLXS;
309 <                if (shift >= 8) {
310 <                        l3->r = l3->g = l3->b = 255;
311 <                } else if (shift <= -8) {
301 <                        l3->r = l3->g = l3->b = 0;
302 <                } else if (shift > 0) {
303 <                        c = l4[RED] << shift;
304 <                        l3->r = c > 255 ? 255 : c;
305 <                        c = l4[GRN] << shift;
306 <                        l3->g = c > 255 ? 255 : c;
307 <                        c = l4[BLU] << shift;
308 <                        l3->b = c > 255 ? 255 : c;
309 <                } else if (shift < 0) {
310 <                        l3->r = l4[RED] >> -shift;
311 <                        l3->g = l4[GRN] >> -shift;
312 <                        l3->b = l4[BLU] >> -shift;
313 <                } else {
314 <                        l3->r = l4[RED];
315 <                        l3->g = l4[GRN];
316 <                        l3->b = l4[BLU];
317 <                }
307 >        normcolrs(inl, xmax, bradj);
308 >        for (i = 0; i < xmax; i++) {
309 >                l3[i].r = inl[i][RED];
310 >                l3[i].g = inl[i][GRN];
311 >                l3[i].b = inl[i][BLU];
312          }
313   }
314  
# Line 333 | Line 327 | register pixel  *l;
327                          quiterr("seek error in picwriteline");
328          }
329                                                  /* write scanline */
330 <        if (fwrite(l, sizeof(pixel), xmax, outpic->fp) != xmax)
330 >        if (fwrite((char *)l, sizeof(pixel), xmax, outpic->fp) != xmax)
331                  quiterr("write error in picwriteline");
332          if (xmax&1)                             /* on 16-bit boundary */
333                  putc(l[xmax-1], outpic->fp);
# Line 368 | Line 362 | colormap  map;
362          register int  i, val;
363  
364          for (i = 0; i < 256; i++) {
365 <                val = pow(i/256.0, 1.0/gamma) * 256.0;
365 >                val = pow((i+0.5)/256.0, 1.0/gamcor) * 256.0;
366                  map[0][i] = map[1][i] = map[2][i] = val;
367          }
368   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines