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.2 by greg, Wed May 31 17:27:18 1989 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 15 | Line 15 | static char SCCSid[] = "$SunId$ LBL";
15  
16   #include  "color.h"
17  
18 + #include  "random.h"
19 +
20   #include  "targa.h"
21  
22   #define  goodpic(h)     (((h)->dataType==IM_RGB || (h)->dataType==IM_CRGB) \
# Line 83 | 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 91 | 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 <                printf("-Y %d +X %d\n", head.y, head.x);
101 >                fputresolu(YMAJOR|YDECR, head.x, head.y, stdout);
102                                          /* convert file */
103                  tg2ra(&head);
104          } else {
105 <                getheader(stdin, NULL);
106 <                if (scanf("-Y %d +X %d\n", &head.y, &head.x) != 2)
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 187 | Line 192 | register FILE  *fp;
192  
193          if (ip != NULL)
194                  if (nidbytes)
195 <                        fread(ip, nidbytes, 1, fp);
195 >                        fread((char *)ip, nidbytes, 1, fp);
196                  else
197                          *ip = '\0';
198          else if (nidbytes)
# Line 228 | Line 233 | register FILE  *fp;
233   tg2ra(hp)                       /* targa file to RADIANCE file */
234   struct hdStruct  *hp;
235   {
236 <        float  gmap[256];
232 <        COLOR  *scanline;
236 >        COLR  *scanline;
237          unsigned char  *tarData;
238          register int  i, j;
235                                        /* set up gamma correction */
236        for (i = 0; i < 256; i++)
237                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 243 | 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 276 | Line 278 | struct hdStruct  *hp;
278   ra2tg(hp)                       /* convert radiance to targa file */
279   struct hdStruct  *hp;
280   {
281 <        unsigned char   gmap[1024];
280 <        register int    i, j, c;
281 >        register int    i, j;
282          unsigned char  *tarData;
283 <        COLOR   *inline;
283 <                                        /* set up gamma correction */
284 <        for (i = 0; i < 1024; i++)
285 <                gmap[i] = 256.*pow((i+.5)/1024., 1./gamma);
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 <                                c = 1024.*colval(inline[i],RED);
298 <                                if (c > 1023) c = 1023;
299 <                                *dp = (gmap[c] & 0xf8)<<7;
300 <                                c = 1024.*colval(inline[i],GRN);
301 <                                if (c > 1023) c = 1023;
302 <                                *dp |= (gmap[c] & 0xf8)<<2;
303 <                                c = 1024.*colval(inline[i],BLU);
304 <                                if (c > 1023) c = 1023;
305 <                                *dp++ |= gmap[c]>>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 <                                c = 1024.*colval(inline[i],BLU);
312 <                                if (c > 1023) c = 1023;
313 <                                *dp++ = gmap[c];
314 <                                c = 1024.*colval(inline[i],GRN);
315 <                                if (c > 1023) c = 1023;
316 <                                *dp++ = gmap[c];
317 <                                c = 1024.*colval(inline[i],RED);
318 <                                if (c > 1023) c = 1023;
319 <                                *dp++ = gmap[c];
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);
322   }
323  
# Line 334 | Line 328 | unsigned char  *d;
328   FILE  *fp;
329   {
330          if (h->dataType == IM_RGB) {            /* uncompressed */
331 <                if (fwrite(d, 3*h->x, h->y, fp) != h->y)
331 >                if (fwrite((char *)d, 3*h->x, h->y, fp) != h->y)
332                          quiterr("error writing targa file");
333                  return;
334          }
# Line 370 | Line 364 | FILE  *fp;
364          int  r, g, b;
365  
366          if (h->dataType == IM_RGB) {            /* uncompressed */
367 <                if (fread(data, 3*h->x, h->y, fp) != h->y)
367 >                if (fread((char *)data, 3*h->x, h->y, fp) != h->y)
368                          goto readerr;
369                  return;
370          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines