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.6 by greg, Thu Jan 18 23:58:21 1990 UTC vs.
Revision 1.12 by greg, Fri May 17 08:41:52 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 85 | Line 85 | char  *argv[];
85                  sprintf(msg, "can't open output \"%s\"", argv[i+1]);
86                  quiterr(msg);
87          }
88 +                                        /* set gamma */
89 +        setcolrgam(gamma);
90                                          /* convert */
91          if (reverse) {
92                                          /* get header */
# Line 93 | Line 95 | char  *argv[];
95                  if (!goodpic(&head))
96                          quiterr("incompatible format");
97                                          /* put header */
98 <                printargs(argc, argv, stdout);
98 >                printargs(i, argv, stdout);
99 >                fputformat(COLRFMT, stdout);
100                  putchar('\n');
101                  fputresolu(YMAJOR|YDECR, head.x, head.y, stdout);
102                                          /* convert file */
103                  tg2ra(&head);
104          } else {
105 <                getheader(stdin, NULL);
106 <                if (fgetresolu(&head.x, &head.y, stdin) != (YMAJOR|YDECR))
105 >                if (checkheader(stdin, COLRFMT, NULL) < 0 ||
106 >                        fgetresolu(&head.x, &head.y, stdin) != (YMAJOR|YDECR))
107                          quiterr("bad picture file");
108                                          /* assign header */
109                  head.textSize = 0;
# Line 230 | Line 233 | register FILE  *fp;
233   tg2ra(hp)                       /* targa file to RADIANCE file */
234   struct hdStruct  *hp;
235   {
236 <        float  gmap[256];
234 <        COLOR  *scanline;
236 >        COLR  *scanline;
237          unsigned char  *tarData;
238          register int  i, j;
237                                        /* set up gamma correction */
238        for (i = 0; i < 256; i++)
239                gmap[i] = pow((i+.5)/256., gamma);
239                                          /* skip color table */
240          if (hp->mapType == CM_HASMAP)
241                  fseek(stdin, (long)hp->mapLength*hp->CMapBits/8, 1);
# Line 245 | Line 244 | struct hdStruct  *hp;
244                                          /* get data */
245          readtarga(hp, tarData, stdin);
246                                          /* allocate input scanline */
247 <        scanline = (COLOR *)emalloc(hp->x*sizeof(COLOR));
247 >        scanline = (COLR *)emalloc(hp->x*sizeof(COLR));
248                                          /* convert file */
249          for (i = hp->y-1; i >= 0; i--) {
250                  if (hp->dataBits == 16) {
251                          register unsigned short  *dp;
252                          dp = (unsigned short *)tarData + i*hp->x;
253                          for (j = 0; j < hp->x; j++) {
254 <                                setcolor(scanline[j], gmap[*dp>>7 & 0xf8],
255 <                                                gmap[*dp>>2 & 0xf8],
256 <                                                gmap[*dp<<3 & 0xf8]);
254 >                                scanline[j][RED] = *dp>>7 & 0xf8;
255 >                                scanline[j][GRN] = *dp>>2 & 0xf8;
256 >                                scanline[j][BLU] = *dp<<3 & 0xf8;
257                                  dp++;
258                          }
259                  } else {        /* hp->dataBits == 24 */
260                          register unsigned char  *dp;
261                          dp = (unsigned char *)tarData + i*3*hp->x;
262                          for (j = 0; j < hp->x; j++) {
263 <                                setcolor(scanline[j], gmap[dp[2]],
264 <                                                gmap[dp[1]],
265 <                                                gmap[dp[0]]);
263 >                                scanline[j][RED] = dp[2];
264 >                                scanline[j][GRN] = dp[1];
265 >                                scanline[j][BLU] = dp[0];
266                                  dp += 3;
267                          }
268                  }
269 <                if (fwritescan(scanline, hp->x, stdout) < 0)
269 >                gambs_colrs(scanline, hp->x);
270 >                if (fwritecolrs(scanline, hp->x, stdout) < 0)
271                          quiterr("error writing RADIANCE file");
272          }
273          free((char *)scanline);
# Line 278 | Line 278 | struct hdStruct  *hp;
278   ra2tg(hp)                       /* convert radiance to targa file */
279   struct hdStruct  *hp;
280   {
281 #define  map(v)         (v >= 1.0 ? 1023 : (int)(v*1023.+.5))
282        unsigned char   gmap[1024];
281          register int    i, j;
282          unsigned char  *tarData;
283 <        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 <        }
283 >        COLR    *inl;
284                                          /* allocate space for data */
285 <        inline = (COLOR *)emalloc(hp->x*sizeof(COLOR));
285 >        inl = (COLR *)emalloc(hp->x*sizeof(COLR));
286          tarData = taralloc(hp);
287                                          /* convert file */
288          for (j = hp->y-1; j >= 0; j--) {
289 <                if (freadscan(inline, hp->x, stdin) < 0)
289 >                if (freadcolrs(inl, hp->x, stdin) < 0)
290                          quiterr("error reading RADIANCE file");
291 +                colrs_gambs(inl, hp->x);
292                  if (hp->dataBits == 16) {
293                          register unsigned short  *dp;
294 +                        register int  v;
295                          dp = (unsigned short *)tarData + j*hp->x;
296                          for (i = 0; i < hp->x; i++) {
297 <                                *dp = ((gmap[map(colval(inline[i],RED))]
298 <                                                +(random()&7)) & 0xf8)<<7;
299 <                                *dp |= ((gmap[map(colval(inline[i],GRN))]
300 <                                                +(random()&7)) & 0xf8)<<2;
301 <                                *dp++ |= (gmap[map(colval(inline[i],BLU))]
302 <                                                +(random()&7))>>3;
297 >                                v = inl[i][RED] + (random()&7);
298 >                                if (v > 255) v = 255;
299 >                                *dp = (v&0xf8)<<7;
300 >                                v = inl[i][GRN] + (random()&7);
301 >                                if (v > 255) v = 255;
302 >                                *dp |= (v&0xf8)<<2;
303 >                                v = inl[i][BLU] + (random()&7);
304 >                                if (v > 255) v = 255;
305 >                                *dp++ |= v>>3;
306                          }
307                  } else {        /* hp->dataBits == 24 */
308                          register unsigned char  *dp;
309                          dp = (unsigned char *)tarData + j*3*hp->x;
310                          for (i = 0; i < hp->x; i++) {
311 <                                *dp++ = gmap[map(colval(inline[i],BLU))];
312 <                                *dp++ = gmap[map(colval(inline[i],GRN))];
313 <                                *dp++ = gmap[map(colval(inline[i],RED))];
311 >                                *dp++ = inl[i][BLU];
312 >                                *dp++ = inl[i][GRN];
313 >                                *dp++ = inl[i][RED];
314                          }
315                  }
316          }
317                                                  /* write out targa data */
318          writetarga(hp, tarData, stdout);
319  
320 <        free((char *)inline);
320 >        free((char *)inl);
321          free((char *)tarData);
324 #undef  map
322   }
323  
324  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines