282 |
|
unsigned char gmap[1024]; |
283 |
|
register int i, j; |
284 |
|
unsigned char *tarData; |
285 |
< |
COLOR *inline; |
285 |
> |
COLOR *inl; |
286 |
|
/* set up gamma correction */ |
287 |
|
for (i = 0; i < 1024; i++) { |
288 |
|
j = 256.*pow((i+.5)/1024., 1./gamma); |
289 |
|
gmap[i] = hp->dataBits == 16 && j > 248 ? 248 : j; |
290 |
|
} |
291 |
|
/* allocate space for data */ |
292 |
< |
inline = (COLOR *)emalloc(hp->x*sizeof(COLOR)); |
292 |
> |
inl = (COLOR *)emalloc(hp->x*sizeof(COLOR)); |
293 |
|
tarData = taralloc(hp); |
294 |
|
/* convert file */ |
295 |
|
for (j = hp->y-1; j >= 0; j--) { |
296 |
< |
if (freadscan(inline, hp->x, stdin) < 0) |
296 |
> |
if (freadscan(inl, hp->x, stdin) < 0) |
297 |
|
quiterr("error reading RADIANCE file"); |
298 |
|
if (hp->dataBits == 16) { |
299 |
|
register unsigned short *dp; |
300 |
|
dp = (unsigned short *)tarData + j*hp->x; |
301 |
|
for (i = 0; i < hp->x; i++) { |
302 |
< |
*dp = ((gmap[map(colval(inline[i],RED))] |
302 |
> |
*dp = ((gmap[map(colval(inl[i],RED))] |
303 |
|
+(random()&7)) & 0xf8)<<7; |
304 |
< |
*dp |= ((gmap[map(colval(inline[i],GRN))] |
304 |
> |
*dp |= ((gmap[map(colval(inl[i],GRN))] |
305 |
|
+(random()&7)) & 0xf8)<<2; |
306 |
< |
*dp++ |= (gmap[map(colval(inline[i],BLU))] |
306 |
> |
*dp++ |= (gmap[map(colval(inl[i],BLU))] |
307 |
|
+(random()&7))>>3; |
308 |
|
} |
309 |
|
} else { /* hp->dataBits == 24 */ |
310 |
|
register unsigned char *dp; |
311 |
|
dp = (unsigned char *)tarData + j*3*hp->x; |
312 |
|
for (i = 0; i < hp->x; i++) { |
313 |
< |
*dp++ = gmap[map(colval(inline[i],BLU))]; |
314 |
< |
*dp++ = gmap[map(colval(inline[i],GRN))]; |
315 |
< |
*dp++ = gmap[map(colval(inline[i],RED))]; |
313 |
> |
*dp++ = gmap[map(colval(inl[i],BLU))]; |
314 |
> |
*dp++ = gmap[map(colval(inl[i],GRN))]; |
315 |
> |
*dp++ = gmap[map(colval(inl[i],RED))]; |
316 |
|
} |
317 |
|
} |
318 |
|
} |
319 |
|
/* write out targa data */ |
320 |
|
writetarga(hp, tarData, stdout); |
321 |
|
|
322 |
< |
free((char *)inline); |
322 |
> |
free((char *)inl); |
323 |
|
free((char *)tarData); |
324 |
|
#undef map |
325 |
|
} |