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

Comparing ray/src/px/ra_t8.c (file contents):
Revision 1.5 by greg, Fri Jan 26 08:17:39 1990 UTC vs.
Revision 1.10 by greg, Wed Aug 7 08:36:37 1991 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 53 | Line 53 | extern double  atof(), pow();
53  
54   double  gamma = 2.0;                    /* gamma correction */
55  
56 + int  bradj = 0;                         /* brightness adjustment */
57 +
58   pic     *inpic;
59  
60   char  *progname;
61  
62   char  errmsg[128];
63  
64 < COLR    *inline;
64 > COLR    *inl;
65  
66   pixel   *tarData;
67  
# Line 95 | Line 97 | char  *argv[];
97                          case 'b':
98                                  greyscale = 1;
99                                  break;
100 +                        case 'e':
101 +                                if (argv[i+1][0] != '+' && argv[i+1][0] != '-')
102 +                                        goto userr;
103 +                                bradj = atoi(argv[++i]);
104 +                                break;
105                          case 'c':
106                                  ncolors = atoi(argv[++i]);
107                                  break;
# Line 124 | Line 131 | char  *argv[];
131                          quiterr(errmsg);
132                  }
133                                          /* put header */
134 <                printargs(argc, argv, stdout);
134 >                printargs(i, argv, stdout);
135 >                fputformat(COLRFMT, stdout);
136                  putchar('\n');
137                  fputresolu(YMAJOR|YDECR, xmax, ymax, stdout);
138                                          /* convert file */
139                  tg2ra(&head);
140          } else {
141 <                if (i > argc-1 || i < argc-2)
141 >                if (i < argc-2 || (!greyscale && i > argc-1))
142                          goto userr;
143                  if ((inpic = openinput(argv[i], &head)) == NULL) {
144                          sprintf(errmsg, "can't open input \"%s\"", argv[i]);
# Line 153 | Line 161 | char  *argv[];
161          quiterr(NULL);
162   userr:
163          fprintf(stderr,
164 <        "Usage: %s [-d][-c ncolors][-b][-g gamma] input [output]\n",
164 >        "Usage: %s [-d][-c ncolors][-b][-g gamma][-e +/-stops] input [output]\n",
165                          progname);
166 <        fprintf(stderr, "   Or: %s -r [-g gamma] [input [output]]\n",
166 >        fprintf(stderr, "   Or: %s -r [-g gamma][-e +/-stops] [input [output]]\n",
167                          progname);
168          exit(1);
169   }
# Line 282 | Line 290 | register struct hdStruct  *h;
290                  p->fp = stdin;
291          else if ((p->fp = fopen(fname, "r")) == NULL)
292                  return(NULL);
293 <                                        /* discard header */
294 <        getheader(p->fp, NULL);
295 <        if (fgetresolu(&xmax, &ymax, p->fp) != (YMAJOR|YDECR))
296 <                quiterr("bad picture size");
293 >                                        /* get header info. */
294 >        if (checkheader(p->fp, COLRFMT, NULL) < 0 ||
295 >                        fgetresolu(&xmax, &ymax, p->fp) != (YMAJOR|YDECR))
296 >                quiterr("bad picture format");
297          p->nexty = 0;
298          p->bytes_line = 0;              /* variable length lines */
299          p->pos.y = (long *)ecalloc(ymax, sizeof(long));
# Line 304 | Line 312 | register struct hdStruct  *h;
312          h->dataBits = 8;
313          h->imType = 0;
314                                          /* allocate scanline */
315 <        inline = (COLR *)emalloc(xmax*sizeof(COLR));
315 >        inl = (COLR *)emalloc(xmax*sizeof(COLR));
316                                          /* allocate targa data */
317          tarData = taralloc(h);
318  
# Line 339 | Line 347 | struct hdStruct  *hp;
347                                          pow((map.c4[i][3]+.5)/256.,gamma),
348                                          pow((map.c4[i][2]+.5)/256.,gamma),
349                                          pow((map.c4[i][1]+.5)/256.,gamma));
350 <
350 >        if (bradj)
351 >                shiftcolrs(ctab, 256, bradj);
352                                          /* allocate targa data */
353          tarData = taralloc(hp);
354                                          /* get data */
# Line 368 | Line 377 | register rgbpixel  *l3;
377                  if (inpic->bytes_line == 0) {
378                          if (inpic->pos.y[y] == 0) {
379                                  while (inpic->nexty < y) {
380 <                                        if (freadcolrs(inline, xmax, inpic->fp) < 0)
380 >                                        if (freadcolrs(inl, xmax, inpic->fp) < 0)
381                                                  quiterr("read error in picreadline3");
382                                          inpic->pos.y[++inpic->nexty] = ftell(inpic->fp);
383                                  }
# Line 378 | Line 387 | register rgbpixel  *l3;
387                          quiterr("seek error in picreadline3");
388          } else if (inpic->bytes_line == 0 && inpic->pos.y[inpic->nexty] == 0)
389                  inpic->pos.y[inpic->nexty] = ftell(inpic->fp);
390 <        if (freadcolrs(inline, xmax, inpic->fp) < 0)    /* read scanline */
390 >        if (freadcolrs(inl, xmax, inpic->fp) < 0)       /* read scanline */
391                  quiterr("read error in picreadline3");
392          inpic->nexty = y+1;
393                                                          /* convert scanline */
394 <        normcolrs(inline, xmax, 0);
394 >        normcolrs(inl, xmax, bradj);
395          for (i = 0; i < xmax; i++) {
396 <                l3[i].r = inline[i][RED];
397 <                l3[i].g = inline[i][GRN];
398 <                l3[i].b = inline[i][BLU];
396 >                l3[i].r = inl[i][RED];
397 >                l3[i].g = inl[i][GRN];
398 >                l3[i].b = inl[i][BLU];
399          }
400   }
401  
# Line 465 | Line 474 | colormap  map;
474          register int  i, val;
475  
476          for (i = 0; i < 256; i++) {
477 <                val = pow(i/256.0, 1.0/gamma) * 256.0;
477 >                val = pow((i+0.5)/256.0, 1.0/gamma) * 256.0;
478                  map[0][i] = map[1][i] = map[2][i] = val;
479          }
480   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines