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; |
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); |
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 |
|
} |
319 |
|
|
320 |
|
free((char *)inline); |
321 |
|
free((char *)tarData); |
322 |
+ |
#undef map |
323 |
|
} |
324 |
|
|
325 |
|
|