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.9 by greg, Sat Oct 20 11:49:02 1990 UTC

# 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                  putchar('\n');
100 <                printf("-Y %d +X %d\n", head.y, head.x);
100 >                fputresolu(YMAJOR|YDECR, head.x, head.y, stdout);
101                                          /* convert file */
102                  tg2ra(&head);
103          } else {
104                  getheader(stdin, NULL);
105 <                if (scanf("-Y %d +X %d\n", &head.y, &head.x) != 2)
105 >                if (fgetresolu(&head.x, &head.y, stdin) != (YMAJOR|YDECR))
106                          quiterr("bad picture file");
107                                          /* assign header */
108                  head.textSize = 0;
# Line 187 | Line 191 | register FILE  *fp;
191  
192          if (ip != NULL)
193                  if (nidbytes)
194 <                        fread(ip, nidbytes, 1, fp);
194 >                        fread((char *)ip, nidbytes, 1, fp);
195                  else
196                          *ip = '\0';
197          else if (nidbytes)
# Line 228 | Line 232 | register FILE  *fp;
232   tg2ra(hp)                       /* targa file to RADIANCE file */
233   struct hdStruct  *hp;
234   {
235 <        float  gmap[256];
232 <        COLOR  *scanline;
235 >        COLR  *scanline;
236          unsigned char  *tarData;
237          register int  i, j;
235                                        /* set up gamma correction */
236        for (i = 0; i < 256; i++)
237                gmap[i] = pow((i+.5)/256., gamma);
238                                          /* skip color table */
239          if (hp->mapType == CM_HASMAP)
240                  fseek(stdin, (long)hp->mapLength*hp->CMapBits/8, 1);
# Line 243 | Line 243 | struct hdStruct  *hp;
243                                          /* get data */
244          readtarga(hp, tarData, stdin);
245                                          /* allocate input scanline */
246 <        scanline = (COLOR *)emalloc(hp->x*sizeof(COLOR));
246 >        scanline = (COLR *)emalloc(hp->x*sizeof(COLR));
247                                          /* convert file */
248          for (i = hp->y-1; i >= 0; i--) {
249                  if (hp->dataBits == 16) {
250                          register unsigned short  *dp;
251                          dp = (unsigned short *)tarData + i*hp->x;
252                          for (j = 0; j < hp->x; j++) {
253 <                                setcolor(scanline[j], gmap[*dp>>7 & 0xf8],
254 <                                                gmap[*dp>>2 & 0xf8],
255 <                                                gmap[*dp<<3 & 0xf8]);
253 >                                scanline[j][RED] = *dp>>7 & 0xf8;
254 >                                scanline[j][GRN] = *dp>>2 & 0xf8;
255 >                                scanline[j][BLU] = *dp<<3 & 0xf8;
256                                  dp++;
257                          }
258                  } else {        /* hp->dataBits == 24 */
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]],
263 <                                                gmap[dp[1]],
264 <                                                gmap[dp[2]]);
262 >                                scanline[j][RED] = dp[2];
263 >                                scanline[j][GRN] = dp[1];
264 >                                scanline[j][BLU] = dp[0];
265                                  dp += 3;
266                          }
267                  }
268 <                if (fwritescan(scanline, hp->x, stdout) < 0)
268 >                gambs_colrs(scanline, hp->x);
269 >                if (fwritecolrs(scanline, hp->x, stdout) < 0)
270                          quiterr("error writing RADIANCE file");
271          }
272          free((char *)scanline);
# Line 276 | Line 277 | struct hdStruct  *hp;
277   ra2tg(hp)                       /* convert radiance to targa file */
278   struct hdStruct  *hp;
279   {
280 <        unsigned char   gmap[1024];
280 <        register int    i, j, c;
280 >        register int    i, j;
281          unsigned char  *tarData;
282 <        COLOR   *inline;
283 <                                        /* set up gamma correction */
284 <        for (i = 0; i < 1024; i++)
285 <                gmap[i] = 256.*pow((i+.5)/1024., 1./gamma);
282 >        COLR    *inl;
283                                          /* allocate space for data */
284 <        inline = (COLOR *)emalloc(hp->x*sizeof(COLOR));
284 >        inl = (COLR *)emalloc(hp->x*sizeof(COLR));
285          tarData = taralloc(hp);
286                                          /* convert file */
287          for (j = hp->y-1; j >= 0; j--) {
288 <                if (freadscan(inline, hp->x, stdin) < 0)
288 >                if (freadcolrs(inl, hp->x, stdin) < 0)
289                          quiterr("error reading RADIANCE file");
290 +                colrs_gambs(inl, hp->x);
291                  if (hp->dataBits == 16) {
292                          register unsigned short  *dp;
293                          dp = (unsigned short *)tarData + j*hp->x;
294                          for (i = 0; i < hp->x; i++) {
295 <                                c = 1024.*colval(inline[i],RED);
296 <                                if (c > 1023) c = 1023;
297 <                                *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;
295 >                                *dp = ((inl[i][RED]+(random()&7)) & 0xf8)<<7;
296 >                                *dp |= ((inl[i][GRN]+(random()&7)) & 0xf8)<<2;
297 >                                *dp++ |= (inl[i][BLU]+(random()&7))>>3;
298                          }
299                  } else {        /* hp->dataBits == 24 */
300                          register unsigned char  *dp;
301                          dp = (unsigned char *)tarData + j*3*hp->x;
302                          for (i = 0; i < hp->x; i++) {
303 <                                c = 1024.*colval(inline[i],RED);
304 <                                if (c > 1023) c = 1023;
305 <                                *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];
303 >                                *dp++ = inl[i][RED];
304 >                                *dp++ = inl[i][GRN];
305 >                                *dp++ = inl[i][BLU];
306                          }
307                  }
308          }
309                                                  /* write out targa data */
310          writetarga(hp, tarData, stdout);
311  
312 <        free((char *)inline);
312 >        free((char *)inl);
313          free((char *)tarData);
314   }
315  
# Line 334 | Line 320 | unsigned char  *d;
320   FILE  *fp;
321   {
322          if (h->dataType == IM_RGB) {            /* uncompressed */
323 <                if (fwrite(d, 3*h->x, h->y, fp) != h->y)
323 >                if (fwrite((char *)d, 3*h->x, h->y, fp) != h->y)
324                          quiterr("error writing targa file");
325                  return;
326          }
# Line 370 | Line 356 | FILE  *fp;
356          int  r, g, b;
357  
358          if (h->dataType == IM_RGB) {            /* uncompressed */
359 <                if (fread(data, 3*h->x, h->y, fp) != h->y)
359 >                if (fread((char *)data, 3*h->x, h->y, fp) != h->y)
360                          goto readerr;
361                  return;
362          }
# Line 379 | Line 365 | FILE  *fp;
365                          goto readerr;
366                  cnt = (c & 0x7f) + 1;
367                  if (c & 0x80) {                 /* repeated pixel */
368 <                        r = getc(fp); g = getc(fp);
369 <                        if ((b = getc(fp)) == EOF)
368 >                        b = getc(fp); g = getc(fp);
369 >                        if ((r = getc(fp)) == EOF)
370                                  goto readerr;
371                          while (cnt--) {
386                                *dp++ = r;
387                                *dp++ = g;
372                                  *dp++ = b;
373 +                                *dp++ = g;
374 +                                *dp++ = r;
375                          }
376                  } else                          /* non-repeating pixels */
377                          while (cnt--) {
378                                  *dp++ = getc(fp); *dp++ = getc(fp);
379 <                                if ((b = getc(fp)) == EOF)
379 >                                if ((r = getc(fp)) == EOF)
380                                          goto readerr;
381 <                                *dp++ = b;
381 >                                *dp++ = r;
382                          }
383          }
384          return;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines