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.1 by greg, Thu Feb 2 10:49:36 1989 UTC vs.
Revision 1.4 by greg, Tue Sep 12 13:04:36 1989 UTC

# Line 93 | Line 93 | char  *argv[];
93                                          /* put header */
94                  printargs(argc, argv, stdout);
95                  putchar('\n');
96 <                printf("-Y %d +X %d\n", head.y, head.x);
96 >                fputresolu(YMAJOR|YDECR, head.x, head.y, stdout);
97                                          /* convert file */
98                  tg2ra(&head);
99          } else {
100                  getheader(stdin, NULL);
101 <                if (scanf("-Y %d +X %d\n", &head.y, &head.x) != 2)
101 >                if (fgetresolu(&head.x, &head.y, stdin) != (YMAJOR|YDECR))
102                          quiterr("bad picture file");
103                                          /* assign header */
104                  head.textSize = 0;
# Line 259 | Line 259 | struct hdStruct  *hp;
259                          register unsigned char  *dp;
260                          dp = (unsigned char *)tarData + i*3*hp->x;
261                          for (j = 0; j < hp->x; j++) {
262 <                                setcolor(scanline[j], gmap[dp[0]],
262 >                                setcolor(scanline[j], gmap[dp[2]],
263                                                  gmap[dp[1]],
264 <                                                gmap[dp[2]]);
264 >                                                gmap[dp[0]]);
265                                  dp += 3;
266                          }
267                  }
# Line 276 | Line 276 | struct hdStruct  *hp;
276   ra2tg(hp)                       /* convert radiance to targa file */
277   struct hdStruct  *hp;
278   {
279 + #define  map(v)         (v >= 1.0 ? 1023 : (int)(v*1023.+.5))
280          unsigned char   gmap[1024];
281 <        register int    i, j, c;
281 >        register int    i, j;
282          unsigned char  *tarData;
283          COLOR   *inline;
284                                          /* set up gamma correction */
285 <        for (i = 0; i < 1024; i++)
286 <                gmap[i] = 256.*pow((i+.5)/1024., 1./gamma);
285 >        for (i = 0; i < 1024; i++) {
286 >                j = 256.*pow((i+.5)/1024., 1./gamma);
287 >                gmap[i] = hp->dataBits == 16 && j > 248 ? 248 : j;
288 >        }
289                                          /* allocate space for data */
290          inline = (COLOR *)emalloc(hp->x*sizeof(COLOR));
291          tarData = taralloc(hp);
# Line 294 | Line 297 | struct hdStruct  *hp;
297                          register unsigned short  *dp;
298                          dp = (unsigned short *)tarData + j*hp->x;
299                          for (i = 0; i < hp->x; i++) {
300 <                                c = 1024.*colval(inline[i],RED);
301 <                                if (c > 1023) c = 1023;
302 <                                *dp = (gmap[c] & 0xf8)<<7;
303 <                                c = 1024.*colval(inline[i],GRN);
304 <                                if (c > 1023) c = 1023;
305 <                                *dp |= (gmap[c] & 0xf8)<<2;
303 <                                c = 1024.*colval(inline[i],BLU);
304 <                                if (c > 1023) c = 1023;
305 <                                *dp++ |= gmap[c]>>3;
300 >                                *dp = ((gmap[map(colval(inline[i],RED))]
301 >                                                +(random()&7)) & 0xf8)<<7;
302 >                                *dp |= ((gmap[map(colval(inline[i],GRN))]
303 >                                                +(random()&7)) & 0xf8)<<2;
304 >                                *dp++ |= (gmap[map(colval(inline[i],BLU))]
305 >                                                +(random()&7))>>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],RED);
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],BLU);
318 <                                if (c > 1023) c = 1023;
319 <                                *dp++ = gmap[c];
311 >                                *dp++ = gmap[map(colval(inline[i],BLU))];
312 >                                *dp++ = gmap[map(colval(inline[i],GRN))];
313 >                                *dp++ = gmap[map(colval(inline[i],RED))];
314                          }
315                  }
316          }
# Line 325 | Line 319 | struct hdStruct  *hp;
319  
320          free((char *)inline);
321          free((char *)tarData);
322 + #undef  map
323   }
324  
325  
# Line 379 | Line 374 | FILE  *fp;
374                          goto readerr;
375                  cnt = (c & 0x7f) + 1;
376                  if (c & 0x80) {                 /* repeated pixel */
377 <                        r = getc(fp); g = getc(fp);
378 <                        if ((b = getc(fp)) == EOF)
377 >                        b = getc(fp); g = getc(fp);
378 >                        if ((r = getc(fp)) == EOF)
379                                  goto readerr;
380                          while (cnt--) {
386                                *dp++ = r;
387                                *dp++ = g;
381                                  *dp++ = b;
382 +                                *dp++ = g;
383 +                                *dp++ = r;
384                          }
385                  } else                          /* non-repeating pixels */
386                          while (cnt--) {
387                                  *dp++ = getc(fp); *dp++ = getc(fp);
388 <                                if ((b = getc(fp)) == EOF)
388 >                                if ((r = getc(fp)) == EOF)
389                                          goto readerr;
390 <                                *dp++ = b;
390 >                                *dp++ = r;
391                          }
392          }
393          return;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines