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.2 by greg, Tue Sep 12 13:04:38 1989 UTC vs.
Revision 2.1 by greg, Tue Nov 12 16:05:11 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 15 | Line 15 | static char SCCSid[] = "$SunId$ LBL";
15  
16   #include  "color.h"
17  
18 + #include  "resolu.h"
19 +
20   #include  "pic.h"
21  
22   #include  "targa.h"
23  
24 + #ifndef  BSD
25 + #define  bcopy(s,d,n)           (void)memcpy(d,s,n)
26 + extern char  *memcpy();
27 + #endif
28                          /* descriptor for a picture file or frame buffer */
29   typedef struct {
30          char    *name;                  /* file name */
# Line 47 | Line 53 | extern long  ftell();
53  
54   extern double  atof(), pow();
55  
56 < double  gamma = 2.0;                    /* gamma correction */
56 > double  gamma = 2.2;                    /* gamma correction */
57  
58 + int  bradj = 0;                         /* brightness adjustment */
59 +
60   pic     *inpic;
61  
62   char  *progname;
63  
64   char  errmsg[128];
65  
66 < COLR    *inline;
66 > COLR    *inl;
67  
68   pixel   *tarData;
69  
# Line 91 | Line 99 | char  *argv[];
99                          case 'b':
100                                  greyscale = 1;
101                                  break;
102 +                        case 'e':
103 +                                if (argv[i+1][0] != '+' && argv[i+1][0] != '-')
104 +                                        goto userr;
105 +                                bradj = atoi(argv[++i]);
106 +                                break;
107                          case 'c':
108                                  ncolors = atoi(argv[++i]);
109                                  break;
# Line 120 | Line 133 | char  *argv[];
133                          quiterr(errmsg);
134                  }
135                                          /* put header */
136 <                printargs(argc, argv, stdout);
136 >                printargs(i, argv, stdout);
137 >                fputformat(COLRFMT, stdout);
138                  putchar('\n');
139 <                fputresolu(YMAJOR|YDECR, xmax, ymax, stdout);
139 >                fprtresolu(xmax, ymax, stdout);
140                                          /* convert file */
141                  tg2ra(&head);
142          } else {
143 <                if (i > argc-1 || i < argc-2)
143 >                if (i < argc-2 || (!greyscale && i > argc-1))
144                          goto userr;
145                  if ((inpic = openinput(argv[i], &head)) == NULL) {
146                          sprintf(errmsg, "can't open input \"%s\"", argv[i]);
# Line 149 | Line 163 | char  *argv[];
163          quiterr(NULL);
164   userr:
165          fprintf(stderr,
166 <        "Usage: %s [-d][-c ncolors][-b][-g gamma] input [output]\n",
166 >        "Usage: %s [-d][-c ncolors][-b][-g gamma][-e +/-stops] input [output]\n",
167                          progname);
168 <        fprintf(stderr, "   Or: %s -r [-g gamma] [input [output]]\n",
168 >        fprintf(stderr, "   Or: %s -r [-g gamma][-e +/-stops] [input [output]]\n",
169                          progname);
170          exit(1);
171   }
# Line 227 | Line 241 | register FILE  *fp;
241  
242          if (ip != NULL)
243                  if (nidbytes)
244 <                        fread(ip, nidbytes, 1, fp);
244 >                        fread((char *)ip, nidbytes, 1, fp);
245                  else
246                          *ip = '\0';
247          else if (nidbytes)
# Line 278 | Line 292 | register struct hdStruct  *h;
292                  p->fp = stdin;
293          else if ((p->fp = fopen(fname, "r")) == NULL)
294                  return(NULL);
295 <                                        /* discard header */
296 <        getheader(p->fp, NULL);
297 <        if (fgetresolu(&xmax, &ymax, p->fp) != (YMAJOR|YDECR))
298 <                quiterr("bad picture size");
295 >                                        /* get header info. */
296 >        if (checkheader(p->fp, COLRFMT, NULL) < 0 ||
297 >                        fgetresolu(&xmax, &ymax, p->fp) < 0)
298 >                quiterr("bad picture format");
299          p->nexty = 0;
300          p->bytes_line = 0;              /* variable length lines */
301          p->pos.y = (long *)ecalloc(ymax, sizeof(long));
# Line 300 | Line 314 | register struct hdStruct  *h;
314          h->dataBits = 8;
315          h->imType = 0;
316                                          /* allocate scanline */
317 <        inline = (COLR *)emalloc(xmax*sizeof(COLR));
317 >        inl = (COLR *)emalloc(xmax*sizeof(COLR));
318                                          /* allocate targa data */
319          tarData = taralloc(h);
320  
# Line 320 | Line 334 | struct hdStruct  *hp;
334          register int  i, j;
335  
336                                          /* get color table */
337 <        if ((hp->CMapBits==24 ? fread(map.c3, sizeof(map.c3), 1, stdin) :
338 <                        fread(map.c4, sizeof(map.c4), 1, stdin)) != 1)
337 >        if ((hp->CMapBits==24 ? fread((char *)(map.c3+hp->mapOrig),
338 >                                3*hp->mapLength,1,stdin) :
339 >                        fread((char *)(map.c4+hp->mapOrig),
340 >                                4*hp->mapLength,1,stdin)) != 1)
341                  quiterr("error reading color table");
342                                          /* convert table */
343          for (i = hp->mapOrig; i < hp->mapOrig+hp->mapLength; i++)
# Line 335 | Line 351 | struct hdStruct  *hp;
351                                          pow((map.c4[i][3]+.5)/256.,gamma),
352                                          pow((map.c4[i][2]+.5)/256.,gamma),
353                                          pow((map.c4[i][1]+.5)/256.,gamma));
354 <
354 >        if (bradj)
355 >                shiftcolrs(ctab, 256, bradj);
356                                          /* allocate targa data */
357          tarData = taralloc(hp);
358                                          /* get data */
# Line 358 | Line 375 | picreadline3(y, l3)                    /* read in 3-byte scanline */
375   int  y;
376   register rgbpixel  *l3;
377   {
378 <        register BYTE   *l4;
362 <        register int    shift, c;
363 <        int     i;
378 >        register int    i;
379  
380 <        if (inpic->nexty != y) {                                /* find scanline */
380 >        if (inpic->nexty != y) {                        /* find scanline */
381                  if (inpic->bytes_line == 0) {
382                          if (inpic->pos.y[y] == 0) {
383                                  while (inpic->nexty < y) {
384 <                                        if (freadcolrs(inline, xmax, inpic->fp) < 0)
384 >                                        if (freadcolrs(inl, xmax, inpic->fp) < 0)
385                                                  quiterr("read error in picreadline3");
386                                          inpic->pos.y[++inpic->nexty] = ftell(inpic->fp);
387                                  }
# Line 376 | Line 391 | register rgbpixel  *l3;
391                          quiterr("seek error in picreadline3");
392          } else if (inpic->bytes_line == 0 && inpic->pos.y[inpic->nexty] == 0)
393                  inpic->pos.y[inpic->nexty] = ftell(inpic->fp);
394 <        if (freadcolrs(inline, xmax, inpic->fp) < 0)    /* read scanline */
394 >        if (freadcolrs(inl, xmax, inpic->fp) < 0)       /* read scanline */
395                  quiterr("read error in picreadline3");
396          inpic->nexty = y+1;
397                                                          /* convert scanline */
398 <        for (l4=inline[0], i=xmax; i--; l4+=4, l3++) {
399 <                shift = l4[EXP] - COLXS;
400 <                if (shift >= 8) {
401 <                        l3->r = l3->g = l3->b = 255;
402 <                } else if (shift <= -8) {
388 <                        l3->r = l3->g = l3->b = 0;
389 <                } else if (shift > 0) {
390 <                        c = l4[RED] << shift;
391 <                        l3->r = c > 255 ? 255 : c;
392 <                        c = l4[GRN] << shift;
393 <                        l3->g = c > 255 ? 255 : c;
394 <                        c = l4[BLU] << shift;
395 <                        l3->b = c > 255 ? 255 : c;
396 <                } else if (shift < 0) {
397 <                        l3->r = l4[RED] >> -shift;
398 <                        l3->g = l4[GRN] >> -shift;
399 <                        l3->b = l4[BLU] >> -shift;
400 <                } else {
401 <                        l3->r = l4[RED];
402 <                        l3->g = l4[GRN];
403 <                        l3->b = l4[BLU];
404 <                }
398 >        normcolrs(inl, xmax, bradj);
399 >        for (i = 0; i < xmax; i++) {
400 >                l3[i].r = inl[i][RED];
401 >                l3[i].g = inl[i][GRN];
402 >                l3[i].b = inl[i][BLU];
403          }
404   }
405  
# Line 410 | Line 408 | picwriteline(y, l)                     /* save output scanline */
408   int  y;
409   pixel  *l;
410   {
411 <        bcopy(l, &tarData[(ymax-1-y)*xmax], xmax*sizeof(pixel));
411 >        bcopy((char *)l, (char *)&tarData[(ymax-1-y)*xmax], xmax*sizeof(pixel));
412   }
413  
414  
# Line 420 | Line 418 | pixel  *d;
418   FILE  *fp;
419   {
420          if (h->dataType == IM_CMAP) {           /* uncompressed */
421 <                if (fwrite(d, h->x*sizeof(pixel), h->y, fp) != h->y)
421 >                if (fwrite((char *)d,h->x*sizeof(pixel),h->y,fp) != h->y)
422                          quiterr("error writing targa file");
423                  return;
424          }
# Line 437 | Line 435 | FILE  *fp;
435          register pixel  *dp;
436  
437          if (h->dataType == IM_CMAP) {           /* uncompressed */
438 <                if (fread(data, h->x*sizeof(pixel), h->y, fp) != h->y)
438 >                if (fread((char *)data,h->x*sizeof(pixel),h->y,fp) != h->y)
439                          goto readerr;
440                  return;
441          }
# Line 480 | Line 478 | colormap  map;
478          register int  i, val;
479  
480          for (i = 0; i < 256; i++) {
481 <                val = pow(i/256.0, 1.0/gamma) * 256.0;
481 >                val = pow((i+0.5)/256.0, 1.0/gamma) * 256.0;
482                  map[0][i] = map[1][i] = map[2][i] = val;
483          }
484   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines