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.3 by greg, Sun Jul 23 11:35:48 1989 UTC

# 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],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++ = 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  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines