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 */ |
232 |
|
tg2ra(hp) /* targa file to RADIANCE file */ |
233 |
|
struct hdStruct *hp; |
234 |
|
{ |
235 |
< |
float gmap[256]; |
234 |
< |
COLOR *scanline; |
235 |
> |
COLR *scanline; |
236 |
|
unsigned char *tarData; |
237 |
|
register int i, j; |
237 |
– |
/* set up gamma correction */ |
238 |
– |
for (i = 0; i < 256; i++) |
239 |
– |
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); |
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[2]], |
263 |
< |
gmap[dp[1]], |
264 |
< |
gmap[dp[0]]); |
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); |
277 |
|
ra2tg(hp) /* convert radiance to targa file */ |
278 |
|
struct hdStruct *hp; |
279 |
|
{ |
281 |
– |
#define map(v) (v >= 1.0 ? 1023 : (int)(v*1023.+.5)) |
282 |
– |
unsigned char gmap[1024]; |
280 |
|
register int i, j; |
281 |
|
unsigned char *tarData; |
282 |
< |
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 |
< |
} |
282 |
> |
COLR *inl; |
283 |
|
/* allocate space for data */ |
284 |
< |
inl = (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(inl, 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 |
< |
*dp = ((gmap[map(colval(inl[i],RED))] |
296 |
< |
+(random()&7)) & 0xf8)<<7; |
297 |
< |
*dp |= ((gmap[map(colval(inl[i],GRN))] |
305 |
< |
+(random()&7)) & 0xf8)<<2; |
306 |
< |
*dp++ |= (gmap[map(colval(inl[i],BLU))] |
307 |
< |
+(random()&7))>>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 |
< |
*dp++ = gmap[map(colval(inl[i],BLU))]; |
304 |
< |
*dp++ = gmap[map(colval(inl[i],GRN))]; |
305 |
< |
*dp++ = gmap[map(colval(inl[i],RED))]; |
303 |
> |
*dp++ = inl[i][RED]; |
304 |
> |
*dp++ = inl[i][GRN]; |
305 |
> |
*dp++ = inl[i][BLU]; |
306 |
|
} |
307 |
|
} |
308 |
|
} |
311 |
|
|
312 |
|
free((char *)inl); |
313 |
|
free((char *)tarData); |
324 |
– |
#undef map |
314 |
|
} |
315 |
|
|
316 |
|
|