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.7 by greg, Fri Feb 9 13:59:21 1990 UTC vs.
Revision 1.14 by greg, Fri Aug 23 13:40:04 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 34 | Line 34 | extern char    *ecalloc(), *emalloc();
34  
35   extern double  atof(), pow();
36  
37 < double  gamma = 2.0;                    /* gamma correction */
37 > double  gamma = 2.2;                    /* gamma correction */
38  
39 + int  bradj = 0;                         /* brightness adjustment */
40 +
41   char  *progname;
42  
43   char  msg[128];
# Line 67 | Line 69 | char  *argv[];
69                          case '3':
70                                  head.dataBits = 24;
71                                  break;
72 +                        case 'e':
73 +                                if (argv[i+1][0] != '+' && argv[i+1][0] != '-')
74 +                                        goto userr;
75 +                                bradj = atoi(argv[++i]);
76 +                                break;
77                          default:
78                                  goto userr;
79                          }
# Line 85 | Line 92 | char  *argv[];
92                  sprintf(msg, "can't open output \"%s\"", argv[i+1]);
93                  quiterr(msg);
94          }
95 +                                        /* set gamma */
96 +        setcolrgam(gamma);
97                                          /* convert */
98          if (reverse) {
99                                          /* get header */
# Line 94 | Line 103 | char  *argv[];
103                          quiterr("incompatible format");
104                                          /* put header */
105                  printargs(i, argv, stdout);
106 +                fputformat(COLRFMT, stdout);
107                  putchar('\n');
108                  fputresolu(YMAJOR|YDECR, head.x, head.y, stdout);
109                                          /* convert file */
110                  tg2ra(&head);
111          } else {
112 <                getheader(stdin, NULL);
113 <                if (fgetresolu(&head.x, &head.y, stdin) != (YMAJOR|YDECR))
112 >                if (checkheader(stdin, COLRFMT, NULL) < 0 ||
113 >                        fgetresolu(&head.x, &head.y, stdin) != (YMAJOR|YDECR))
114                          quiterr("bad picture file");
115                                          /* assign header */
116                  head.textSize = 0;
# Line 116 | Line 126 | char  *argv[];
126          }
127          exit(0);
128   userr:
129 <        fprintf(stderr, "Usage: %s [-2|-3|-r][-g gamma] [input [output]]\n",
129 >        fprintf(stderr, "Usage: %s [-2|-3|-r][-g gamma][-e +/-stops] [input [output]]\n",
130                          progname);
131          exit(1);
132   }
# Line 230 | Line 240 | register FILE  *fp;
240   tg2ra(hp)                       /* targa file to RADIANCE file */
241   struct hdStruct  *hp;
242   {
243 <        float  gmap[256];
234 <        COLOR  *scanline;
243 >        COLR  *scanline;
244          unsigned char  *tarData;
245          register int  i, j;
237                                        /* set up gamma correction */
238        for (i = 0; i < 256; i++)
239                gmap[i] = pow((i+.5)/256., gamma);
246                                          /* skip color table */
247          if (hp->mapType == CM_HASMAP)
248                  fseek(stdin, (long)hp->mapLength*hp->CMapBits/8, 1);
# Line 245 | Line 251 | struct hdStruct  *hp;
251                                          /* get data */
252          readtarga(hp, tarData, stdin);
253                                          /* allocate input scanline */
254 <        scanline = (COLOR *)emalloc(hp->x*sizeof(COLOR));
254 >        scanline = (COLR *)emalloc(hp->x*sizeof(COLR));
255                                          /* convert file */
256          for (i = hp->y-1; i >= 0; i--) {
257                  if (hp->dataBits == 16) {
258                          register unsigned short  *dp;
259                          dp = (unsigned short *)tarData + i*hp->x;
260                          for (j = 0; j < hp->x; j++) {
261 <                                setcolor(scanline[j], gmap[*dp>>7 & 0xf8],
262 <                                                gmap[*dp>>2 & 0xf8],
263 <                                                gmap[*dp<<3 & 0xf8]);
261 >                                scanline[j][RED] = *dp>>7 & 0xf8;
262 >                                scanline[j][GRN] = *dp>>2 & 0xf8;
263 >                                scanline[j][BLU] = *dp<<3 & 0xf8;
264                                  dp++;
265                          }
266                  } else {        /* hp->dataBits == 24 */
267                          register unsigned char  *dp;
268                          dp = (unsigned char *)tarData + i*3*hp->x;
269                          for (j = 0; j < hp->x; j++) {
270 <                                setcolor(scanline[j], gmap[dp[2]],
271 <                                                gmap[dp[1]],
272 <                                                gmap[dp[0]]);
270 >                                scanline[j][RED] = dp[2];
271 >                                scanline[j][GRN] = dp[1];
272 >                                scanline[j][BLU] = dp[0];
273                                  dp += 3;
274                          }
275                  }
276 <                if (fwritescan(scanline, hp->x, stdout) < 0)
276 >                gambs_colrs(scanline, hp->x);
277 >                if (bradj)
278 >                        shiftcolrs(scanline, hp->x, bradj);
279 >                if (fwritecolrs(scanline, hp->x, stdout) < 0)
280                          quiterr("error writing RADIANCE file");
281          }
282          free((char *)scanline);
# Line 278 | Line 287 | struct hdStruct  *hp;
287   ra2tg(hp)                       /* convert radiance to targa file */
288   struct hdStruct  *hp;
289   {
281 #define  map(v)         (v >= 1.0 ? 1023 : (int)(v*1023.+.5))
282        unsigned char   gmap[1024];
290          register int    i, j;
291          unsigned char  *tarData;
292 <        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 <        }
292 >        COLR    *inl;
293                                          /* allocate space for data */
294 <        inline = (COLOR *)emalloc(hp->x*sizeof(COLOR));
294 >        inl = (COLR *)emalloc(hp->x*sizeof(COLR));
295          tarData = taralloc(hp);
296                                          /* convert file */
297          for (j = hp->y-1; j >= 0; j--) {
298 <                if (freadscan(inline, hp->x, stdin) < 0)
298 >                if (freadcolrs(inl, hp->x, stdin) < 0)
299                          quiterr("error reading RADIANCE file");
300 +                if (bradj)
301 +                        shiftcolrs(inl, hp->x, bradj);
302 +                colrs_gambs(inl, hp->x);
303                  if (hp->dataBits == 16) {
304                          register unsigned short  *dp;
305 +                        register int  v;
306                          dp = (unsigned short *)tarData + j*hp->x;
307                          for (i = 0; i < hp->x; i++) {
308 <                                *dp = ((gmap[map(colval(inline[i],RED))]
309 <                                                +(random()&7)) & 0xf8)<<7;
310 <                                *dp |= ((gmap[map(colval(inline[i],GRN))]
311 <                                                +(random()&7)) & 0xf8)<<2;
312 <                                *dp++ |= (gmap[map(colval(inline[i],BLU))]
313 <                                                +(random()&7))>>3;
308 >                                v = inl[i][RED] + (random()&7);
309 >                                if (v > 255) v = 255;
310 >                                *dp = (v&0xf8)<<7;
311 >                                v = inl[i][GRN] + (random()&7);
312 >                                if (v > 255) v = 255;
313 >                                *dp |= (v&0xf8)<<2;
314 >                                v = inl[i][BLU] + (random()&7);
315 >                                if (v > 255) v = 255;
316 >                                *dp++ |= v>>3;
317                          }
318                  } else {        /* hp->dataBits == 24 */
319                          register unsigned char  *dp;
320                          dp = (unsigned char *)tarData + j*3*hp->x;
321                          for (i = 0; i < hp->x; i++) {
322 <                                *dp++ = gmap[map(colval(inline[i],BLU))];
323 <                                *dp++ = gmap[map(colval(inline[i],GRN))];
324 <                                *dp++ = gmap[map(colval(inline[i],RED))];
322 >                                *dp++ = inl[i][BLU];
323 >                                *dp++ = inl[i][GRN];
324 >                                *dp++ = inl[i][RED];
325                          }
326                  }
327          }
328                                                  /* write out targa data */
329          writetarga(hp, tarData, stdout);
330  
331 <        free((char *)inline);
331 >        free((char *)inl);
332          free((char *)tarData);
324 #undef  map
333   }
334  
335  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines