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.5 by greg, Fri Oct 20 16:42:28 1989 UTC vs.
Revision 2.1 by greg, Tue Nov 12 16:04:21 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  "random.h"
21  
22   #include  "targa.h"
# Line 34 | Line 36 | extern char    *ecalloc(), *emalloc();
36  
37   extern double  atof(), pow();
38  
39 < double  gamma = 2.0;                    /* gamma correction */
39 > double  gamma = 2.2;                    /* gamma correction */
40  
41 + int  bradj = 0;                         /* brightness adjustment */
42 +
43   char  *progname;
44  
45   char  msg[128];
# Line 67 | Line 71 | char  *argv[];
71                          case '3':
72                                  head.dataBits = 24;
73                                  break;
74 +                        case 'e':
75 +                                if (argv[i+1][0] != '+' && argv[i+1][0] != '-')
76 +                                        goto userr;
77 +                                bradj = atoi(argv[++i]);
78 +                                break;
79                          default:
80                                  goto userr;
81                          }
# Line 85 | Line 94 | char  *argv[];
94                  sprintf(msg, "can't open output \"%s\"", argv[i+1]);
95                  quiterr(msg);
96          }
97 +                                        /* set gamma */
98 +        setcolrgam(gamma);
99                                          /* convert */
100          if (reverse) {
101                                          /* get header */
# Line 93 | Line 104 | char  *argv[];
104                  if (!goodpic(&head))
105                          quiterr("incompatible format");
106                                          /* put header */
107 <                printargs(argc, argv, stdout);
107 >                printargs(i, argv, stdout);
108 >                fputformat(COLRFMT, stdout);
109                  putchar('\n');
110 <                fputresolu(YMAJOR|YDECR, head.x, head.y, stdout);
110 >                fprtresolu(head.x, head.y, stdout);
111                                          /* convert file */
112                  tg2ra(&head);
113          } else {
114 <                getheader(stdin, NULL);
115 <                if (fgetresolu(&head.x, &head.y, stdin) != (YMAJOR|YDECR))
114 >                if (checkheader(stdin, COLRFMT, NULL) < 0 ||
115 >                                fgetresolu(&head.x, &head.y, stdin) < 0)
116                          quiterr("bad picture file");
117                                          /* assign header */
118                  head.textSize = 0;
# Line 116 | Line 128 | char  *argv[];
128          }
129          exit(0);
130   userr:
131 <        fprintf(stderr, "Usage: %s [-2|-3|-r][-g gamma] [input [output]]\n",
131 >        fprintf(stderr, "Usage: %s [-2|-3|-r][-g gamma][-e +/-stops] [input [output]]\n",
132                          progname);
133          exit(1);
134   }
# Line 189 | Line 201 | register FILE  *fp;
201  
202          if (ip != NULL)
203                  if (nidbytes)
204 <                        fread(ip, nidbytes, 1, fp);
204 >                        fread((char *)ip, nidbytes, 1, fp);
205                  else
206                          *ip = '\0';
207          else if (nidbytes)
# Line 230 | Line 242 | register FILE  *fp;
242   tg2ra(hp)                       /* targa file to RADIANCE file */
243   struct hdStruct  *hp;
244   {
245 <        float  gmap[256];
234 <        COLOR  *scanline;
245 >        COLR  *scanline;
246          unsigned char  *tarData;
247          register int  i, j;
237                                        /* set up gamma correction */
238        for (i = 0; i < 256; i++)
239                gmap[i] = pow((i+.5)/256., gamma);
248                                          /* skip color table */
249          if (hp->mapType == CM_HASMAP)
250                  fseek(stdin, (long)hp->mapLength*hp->CMapBits/8, 1);
# Line 245 | Line 253 | struct hdStruct  *hp;
253                                          /* get data */
254          readtarga(hp, tarData, stdin);
255                                          /* allocate input scanline */
256 <        scanline = (COLOR *)emalloc(hp->x*sizeof(COLOR));
256 >        scanline = (COLR *)emalloc(hp->x*sizeof(COLR));
257                                          /* convert file */
258          for (i = hp->y-1; i >= 0; i--) {
259                  if (hp->dataBits == 16) {
260                          register unsigned short  *dp;
261                          dp = (unsigned short *)tarData + i*hp->x;
262                          for (j = 0; j < hp->x; j++) {
263 <                                setcolor(scanline[j], gmap[*dp>>7 & 0xf8],
264 <                                                gmap[*dp>>2 & 0xf8],
265 <                                                gmap[*dp<<3 & 0xf8]);
263 >                                scanline[j][RED] = *dp>>7 & 0xf8;
264 >                                scanline[j][GRN] = *dp>>2 & 0xf8;
265 >                                scanline[j][BLU] = *dp<<3 & 0xf8;
266                                  dp++;
267                          }
268                  } else {        /* hp->dataBits == 24 */
269                          register unsigned char  *dp;
270                          dp = (unsigned char *)tarData + i*3*hp->x;
271                          for (j = 0; j < hp->x; j++) {
272 <                                setcolor(scanline[j], gmap[dp[2]],
273 <                                                gmap[dp[1]],
274 <                                                gmap[dp[0]]);
272 >                                scanline[j][RED] = dp[2];
273 >                                scanline[j][GRN] = dp[1];
274 >                                scanline[j][BLU] = dp[0];
275                                  dp += 3;
276                          }
277                  }
278 <                if (fwritescan(scanline, hp->x, stdout) < 0)
278 >                gambs_colrs(scanline, hp->x);
279 >                if (bradj)
280 >                        shiftcolrs(scanline, hp->x, bradj);
281 >                if (fwritecolrs(scanline, hp->x, stdout) < 0)
282                          quiterr("error writing RADIANCE file");
283          }
284          free((char *)scanline);
# Line 278 | Line 289 | struct hdStruct  *hp;
289   ra2tg(hp)                       /* convert radiance to targa file */
290   struct hdStruct  *hp;
291   {
281 #define  map(v)         (v >= 1.0 ? 1023 : (int)(v*1023.+.5))
282        unsigned char   gmap[1024];
292          register int    i, j;
293          unsigned char  *tarData;
294 <        COLOR   *inline;
286 <                                        /* set up gamma correction */
287 <        for (i = 0; i < 1024; i++) {
288 <                j = 256.*pow((i+.5)/1024., 1./gamma);
289 <                gmap[i] = hp->dataBits == 16 && j > 248 ? 248 : j;
290 <        }
294 >        COLR    *inl;
295                                          /* allocate space for data */
296 <        inline = (COLOR *)emalloc(hp->x*sizeof(COLOR));
296 >        inl = (COLR *)emalloc(hp->x*sizeof(COLR));
297          tarData = taralloc(hp);
298                                          /* convert file */
299          for (j = hp->y-1; j >= 0; j--) {
300 <                if (freadscan(inline, hp->x, stdin) < 0)
300 >                if (freadcolrs(inl, hp->x, stdin) < 0)
301                          quiterr("error reading RADIANCE file");
302 +                if (bradj)
303 +                        shiftcolrs(inl, hp->x, bradj);
304 +                colrs_gambs(inl, hp->x);
305                  if (hp->dataBits == 16) {
306                          register unsigned short  *dp;
307 +                        register int  v;
308                          dp = (unsigned short *)tarData + j*hp->x;
309                          for (i = 0; i < hp->x; i++) {
310 <                                *dp = ((gmap[map(colval(inline[i],RED))]
311 <                                                +(random()&7)) & 0xf8)<<7;
312 <                                *dp |= ((gmap[map(colval(inline[i],GRN))]
313 <                                                +(random()&7)) & 0xf8)<<2;
314 <                                *dp++ |= (gmap[map(colval(inline[i],BLU))]
315 <                                                +(random()&7))>>3;
310 >                                v = inl[i][RED] + (random()&7);
311 >                                if (v > 255) v = 255;
312 >                                *dp = (v&0xf8)<<7;
313 >                                v = inl[i][GRN] + (random()&7);
314 >                                if (v > 255) v = 255;
315 >                                *dp |= (v&0xf8)<<2;
316 >                                v = inl[i][BLU] + (random()&7);
317 >                                if (v > 255) v = 255;
318 >                                *dp++ |= v>>3;
319                          }
320                  } else {        /* hp->dataBits == 24 */
321                          register unsigned char  *dp;
322                          dp = (unsigned char *)tarData + j*3*hp->x;
323                          for (i = 0; i < hp->x; i++) {
324 <                                *dp++ = gmap[map(colval(inline[i],BLU))];
325 <                                *dp++ = gmap[map(colval(inline[i],GRN))];
326 <                                *dp++ = gmap[map(colval(inline[i],RED))];
324 >                                *dp++ = inl[i][BLU];
325 >                                *dp++ = inl[i][GRN];
326 >                                *dp++ = inl[i][RED];
327                          }
328                  }
329          }
330                                                  /* write out targa data */
331          writetarga(hp, tarData, stdout);
332  
333 <        free((char *)inline);
333 >        free((char *)inl);
334          free((char *)tarData);
324 #undef  map
335   }
336  
337  
# Line 331 | Line 341 | unsigned char  *d;
341   FILE  *fp;
342   {
343          if (h->dataType == IM_RGB) {            /* uncompressed */
344 <                if (fwrite(d, 3*h->x, h->y, fp) != h->y)
344 >                if (fwrite((char *)d, 3*h->x, h->y, fp) != h->y)
345                          quiterr("error writing targa file");
346                  return;
347          }
# Line 367 | Line 377 | FILE  *fp;
377          int  r, g, b;
378  
379          if (h->dataType == IM_RGB) {            /* uncompressed */
380 <                if (fread(data, 3*h->x, h->y, fp) != h->y)
380 >                if (fread((char *)data, 3*h->x, h->y, fp) != h->y)
381                          goto readerr;
382                  return;
383          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines