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.11 by greg, Thu Apr 18 14:35:42 1991 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 >                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                          dp = (unsigned short *)tarData + j*hp->x;
295                          for (i = 0; i < hp->x; i++) {
296 <                                c = 1024.*colval(inline[i],RED);
297 <                                if (c > 1023) c = 1023;
298 <                                *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;
296 >                                *dp = ((inl[i][RED]+(random()&7)) & 0xf8)<<7;
297 >                                *dp |= ((inl[i][GRN]+(random()&7)) & 0xf8)<<2;
298 >                                *dp++ |= (inl[i][BLU]+(random()&7))>>3;
299                          }
300                  } else {        /* hp->dataBits == 24 */
301                          register unsigned char  *dp;
302                          dp = (unsigned char *)tarData + j*3*hp->x;
303                          for (i = 0; i < hp->x; i++) {
304 <                                c = 1024.*colval(inline[i],BLU);
305 <                                if (c > 1023) c = 1023;
306 <                                *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];
304 >                                *dp++ = inl[i][BLU];
305 >                                *dp++ = inl[i][GRN];
306 >                                *dp++ = inl[i][RED];
307                          }
308                  }
309          }
310                                                  /* write out targa data */
311          writetarga(hp, tarData, stdout);
312  
313 <        free((char *)inline);
313 >        free((char *)inl);
314          free((char *)tarData);
315   }
316  
# Line 334 | Line 321 | unsigned char  *d;
321   FILE  *fp;
322   {
323          if (h->dataType == IM_RGB) {            /* uncompressed */
324 <                if (fwrite(d, 3*h->x, h->y, fp) != h->y)
324 >                if (fwrite((char *)d, 3*h->x, h->y, fp) != h->y)
325                          quiterr("error writing targa file");
326                  return;
327          }
# Line 370 | Line 357 | FILE  *fp;
357          int  r, g, b;
358  
359          if (h->dataType == IM_RGB) {            /* uncompressed */
360 <                if (fread(data, 3*h->x, h->y, fp) != h->y)
360 >                if (fread((char *)data, 3*h->x, h->y, fp) != h->y)
361                          goto readerr;
362                  return;
363          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines