| 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 */ |
| 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 |
|
fputresolu(YMAJOR|YDECR, head.x, head.y, stdout); |
| 102 |
|
/* convert file */ |
| 103 |
|
tg2ra(&head); |
| 104 |
|
} else { |
| 105 |
< |
getheader(stdin, NULL); |
| 106 |
< |
if (fgetresolu(&head.x, &head.y, stdin) != (YMAJOR|YDECR)) |
| 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; |
| 233 |
|
tg2ra(hp) /* targa file to RADIANCE file */ |
| 234 |
|
struct hdStruct *hp; |
| 235 |
|
{ |
| 236 |
< |
float gmap[256]; |
| 234 |
< |
COLOR *scanline; |
| 236 |
> |
COLR *scanline; |
| 237 |
|
unsigned char *tarData; |
| 238 |
|
register int i, j; |
| 237 |
– |
/* set up gamma correction */ |
| 238 |
– |
for (i = 0; i < 256; i++) |
| 239 |
– |
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); |
| 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); |
| 278 |
|
ra2tg(hp) /* convert radiance to targa file */ |
| 279 |
|
struct hdStruct *hp; |
| 280 |
|
{ |
| 281 |
– |
#define map(v) (v >= 1.0 ? 1023 : (int)(v*1023.+.5)) |
| 282 |
– |
unsigned char gmap[1024]; |
| 281 |
|
register int i, j; |
| 282 |
|
unsigned char *tarData; |
| 283 |
< |
COLOR *inline; |
| 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 |
< |
} |
| 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 |
< |
*dp = ((gmap[map(colval(inline[i],RED))] |
| 297 |
< |
+(random()&7)) & 0xf8)<<7; |
| 298 |
< |
*dp |= ((gmap[map(colval(inline[i],GRN))] |
| 305 |
< |
+(random()&7)) & 0xf8)<<2; |
| 306 |
< |
*dp++ |= (gmap[map(colval(inline[i],BLU))] |
| 307 |
< |
+(random()&7))>>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 |
< |
*dp++ = gmap[map(colval(inline[i],BLU))]; |
| 305 |
< |
*dp++ = gmap[map(colval(inline[i],GRN))]; |
| 306 |
< |
*dp++ = gmap[map(colval(inline[i],RED))]; |
| 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); |
| 324 |
– |
#undef map |
| 315 |
|
} |
| 316 |
|
|
| 317 |
|
|