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

Comparing ray/src/px/ra_t16.c (file contents):
Revision 1.10 by greg, Wed Dec 12 14:40:07 1990 UTC vs.
Revision 2.6 by greg, Sat Feb 22 02:07:28 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   *  ra_t16.c - program to convert between RADIANCE and
6   *              Targa 16, 24 and 32-bit images.
# Line 13 | Line 10 | static char SCCSid[] = "$SunId$ LBL";
10  
11   #include  <stdio.h>
12  
13 + #ifdef MSDOS
14 + #include  <fcntl.h>
15 + #endif
16 +
17 + #include  <time.h>
18 +
19 + #include  <math.h>
20 +
21   #include  "color.h"
22  
23 + #include  "resolu.h"
24 +
25   #include  "random.h"
26  
27   #include  "targa.h"
# Line 32 | Line 39 | static char SCCSid[] = "$SunId$ LBL";
39  
40   extern char     *ecalloc(), *emalloc();
41  
42 < extern double  atof(), pow();
42 > double  gamcor = 2.2;                   /* gamma correction */
43  
44 < double  gamma = 2.0;                    /* gamma correction */
44 > int  bradj = 0;                         /* brightness adjustment */
45  
46   char  *progname;
47  
# Line 48 | Line 55 | char  *argv[];
55          struct hdStruct  head;
56          int  reverse = 0;
57          int  i;
58 <        
58 > #ifdef MSDOS
59 >        extern int  _fmode;
60 >        _fmode = O_BINARY;
61 >        setmode(fileno(stdin), O_BINARY);
62 >        setmode(fileno(stdout), O_BINARY);
63 > #endif
64          progname = argv[0];
65  
66          head.dataBits = 16;
# Line 56 | Line 68 | char  *argv[];
68                  if (argv[i][0] == '-')
69                          switch (argv[i][1]) {
70                          case 'g':
71 <                                gamma = atof(argv[++i]);
71 >                                gamcor = atof(argv[++i]);
72                                  break;
73                          case 'r':
74                                  reverse = !reverse;
# Line 67 | Line 79 | char  *argv[];
79                          case '3':
80                                  head.dataBits = 24;
81                                  break;
82 +                        case 'e':
83 +                                if (argv[i+1][0] != '+' && argv[i+1][0] != '-')
84 +                                        goto userr;
85 +                                bradj = atoi(argv[++i]);
86 +                                break;
87                          default:
88                                  goto userr;
89                          }
# Line 86 | Line 103 | char  *argv[];
103                  quiterr(msg);
104          }
105                                          /* set gamma */
106 <        setcolrgam(gamma);
106 >        setcolrgam(gamcor);
107                                          /* convert */
108          if (reverse) {
109                                          /* get header */
# Line 95 | Line 112 | char  *argv[];
112                  if (!goodpic(&head))
113                          quiterr("incompatible format");
114                                          /* put header */
115 +                newheader("RADIANCE", stdout);
116                  printargs(i, argv, stdout);
117 +                fputformat(COLRFMT, stdout);
118                  putchar('\n');
119 <                fputresolu(YMAJOR|YDECR, head.x, head.y, stdout);
119 >                fprtresolu(head.x, head.y, stdout);
120                                          /* convert file */
121                  tg2ra(&head);
122          } else {
123 <                getheader(stdin, NULL);
124 <                if (fgetresolu(&head.x, &head.y, stdin) != (YMAJOR|YDECR))
123 >                if (checkheader(stdin, COLRFMT, NULL) < 0 ||
124 >                                fgetresolu(&head.x, &head.y, stdin) < 0)
125                          quiterr("bad picture file");
126                                          /* assign header */
127                  head.textSize = 0;
# Line 118 | Line 137 | char  *argv[];
137          }
138          exit(0);
139   userr:
140 <        fprintf(stderr, "Usage: %s [-2|-3|-r][-g gamma] [input [output]]\n",
140 >        fprintf(stderr, "Usage: %s [-2|-3|-r][-g gamma][-e +/-stops] [input [output]]\n",
141                          progname);
142          exit(1);
143   }
# Line 154 | Line 173 | char  *err;
173   }
174  
175  
176 + void
177   eputs(s)
178   char *s;
179   {
# Line 161 | Line 181 | char *s;
181   }
182  
183  
184 + void
185   quit(code)
186   int code;
187   {
# Line 266 | Line 287 | struct hdStruct  *hp;
287                          }
288                  }
289                  gambs_colrs(scanline, hp->x);
290 +                if (bradj)
291 +                        shiftcolrs(scanline, hp->x, bradj);
292                  if (fwritecolrs(scanline, hp->x, stdout) < 0)
293                          quiterr("error writing RADIANCE file");
294          }
295 <        free((char *)scanline);
296 <        free((char *)tarData);
295 >        free((void *)scanline);
296 >        free((void *)tarData);
297   }
298  
299  
# Line 287 | Line 310 | struct hdStruct  *hp;
310          for (j = hp->y-1; j >= 0; j--) {
311                  if (freadcolrs(inl, hp->x, stdin) < 0)
312                          quiterr("error reading RADIANCE file");
313 +                if (bradj)
314 +                        shiftcolrs(inl, hp->x, bradj);
315                  colrs_gambs(inl, hp->x);
316                  if (hp->dataBits == 16) {
317                          register unsigned short  *dp;
318 +                        register int  v;
319                          dp = (unsigned short *)tarData + j*hp->x;
320                          for (i = 0; i < hp->x; i++) {
321 <                                *dp = ((inl[i][RED]+(random()&7)) & 0xf8)<<7;
322 <                                *dp |= ((inl[i][GRN]+(random()&7)) & 0xf8)<<2;
323 <                                *dp++ |= (inl[i][BLU]+(random()&7))>>3;
321 >                                v = inl[i][RED] + (random()&7);
322 >                                if (v > 255) v = 255;
323 >                                *dp = (v&0xf8)<<7;
324 >                                v = inl[i][GRN] + (random()&7);
325 >                                if (v > 255) v = 255;
326 >                                *dp |= (v&0xf8)<<2;
327 >                                v = inl[i][BLU] + (random()&7);
328 >                                if (v > 255) v = 255;
329 >                                *dp++ |= v>>3;
330                          }
331                  } else {        /* hp->dataBits == 24 */
332                          register unsigned char  *dp;
# Line 309 | Line 341 | struct hdStruct  *hp;
341                                                  /* write out targa data */
342          writetarga(hp, tarData, stdout);
343  
344 <        free((char *)inl);
345 <        free((char *)tarData);
344 >        free((void *)inl);
345 >        free((void *)tarData);
346   }
347  
348  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines