60 |
|
progname, argv[i+1]); |
61 |
|
exit(1); |
62 |
|
} |
63 |
+ |
setcolrgam(gamma); |
64 |
|
if (reverse) { |
65 |
|
/* get header */ |
66 |
|
if (fread((char *)&head, sizeof(head), 1, stdin) != 1) |
75 |
|
quiterr("incompatible format"); |
76 |
|
/* put header */ |
77 |
|
printargs(i, argv, stdout); |
78 |
+ |
fputformat(COLRFMT, stdout); |
79 |
|
putchar('\n'); |
80 |
|
fputresolu(YMAJOR|YDECR, xmax, ymax, stdout); |
81 |
|
/* convert file */ |
82 |
|
pr2ra(); |
83 |
|
} else { |
84 |
< |
/* discard input header */ |
85 |
< |
getheader(stdin, NULL); |
86 |
< |
/* get resolution */ |
87 |
< |
if (fgetresolu(&xmax, &ymax, stdin) != (YMAJOR|YDECR)) |
86 |
< |
quiterr("bad picture size"); |
84 |
> |
/* get header info. */ |
85 |
> |
if (checkheader(stdin, COLRFMT, NULL) < 0 || |
86 |
> |
fgetresolu(&xmax, &ymax, stdin) != (YMAJOR|YDECR)) |
87 |
> |
quiterr("bad picture format"); |
88 |
|
/* write rasterfile header */ |
89 |
|
head.ras_magic = RAS_MAGIC; |
90 |
|
head.ras_width = xmax; |
119 |
|
|
120 |
|
pr2ra() /* convert 24-bit scanlines to Radiance picture */ |
121 |
|
{ |
122 |
< |
float gmap[256]; |
122 |
< |
int r, g, b; |
123 |
< |
COLOR *scanout; |
122 |
> |
COLR *scanout; |
123 |
|
register int x; |
124 |
|
int y; |
125 |
|
/* allocate scanline */ |
126 |
< |
scanout = (COLOR *)malloc(xmax*sizeof(COLOR)); |
126 |
> |
scanout = (COLR *)malloc(xmax*sizeof(COLR)); |
127 |
|
if (scanout == NULL) |
128 |
|
quiterr("out of memory in pr2ra"); |
130 |
– |
/* compute gamma correction */ |
131 |
– |
for (x = 0; x < 256; x++) |
132 |
– |
gmap[x] = pow((x+.5)/256., gamma); |
129 |
|
/* convert image */ |
130 |
|
for (y = ymax-1; y >= 0; y--) { |
131 |
|
for (x = 0; x < xmax; x++) { |
132 |
< |
r = getc(stdin); g = getc(stdin); |
133 |
< |
if ((b = getc(stdin)) == EOF) |
134 |
< |
quiterr("error reading rasterfile"); |
139 |
< |
setcolor(scanout[x], gmap[r], gmap[g], gmap[b]); |
132 |
> |
scanout[x][BLU] = getc(stdin); |
133 |
> |
scanout[x][GRN] = getc(stdin); |
134 |
> |
scanout[x][RED] = getc(stdin); |
135 |
|
} |
136 |
< |
if (fwritescan(scanout, xmax, stdout) < 0) |
136 |
> |
if (feof(stdin) || ferror(stdin)) |
137 |
> |
quiterr("error reading rasterfile"); |
138 |
> |
gambs_colrs(scanout, xmax); |
139 |
> |
if (fwritecolrs(scanout, xmax, stdout) < 0) |
140 |
|
quiterr("error writing Radiance picture"); |
141 |
|
} |
142 |
|
/* free scanline */ |
146 |
|
|
147 |
|
ra2pr() /* convert Radiance scanlines to 24-bit rasterfile */ |
148 |
|
{ |
149 |
< |
#define map(v) ((v)>=1.0 ? 255 : gmap[(int)(1024.*(v))]) |
152 |
< |
unsigned char gmap[1024]; |
153 |
< |
COLOR *scanin; |
149 |
> |
COLR *scanin; |
150 |
|
register int x; |
155 |
– |
register int c; |
151 |
|
int y; |
152 |
|
/* allocate scanline */ |
153 |
< |
scanin = (COLOR *)malloc(xmax*sizeof(COLOR)); |
153 |
> |
scanin = (COLR *)malloc(xmax*sizeof(COLR)); |
154 |
|
if (scanin == NULL) |
155 |
|
quiterr("out of memory in pr2ra"); |
161 |
– |
/* compute gamma correction */ |
162 |
– |
for (x = 0; x < 1024; x++) |
163 |
– |
gmap[x] = 256.*pow((x+.5)/1024., 1./gamma); |
156 |
|
/* convert image */ |
157 |
|
for (y = ymax-1; y >= 0; y--) { |
158 |
< |
if (freadscan(scanin, xmax, stdin) < 0) |
158 |
> |
if (freadcolrs(scanin, xmax, stdin) < 0) |
159 |
|
quiterr("error reading Radiance picture"); |
160 |
+ |
colrs_gambs(scanin, xmax); |
161 |
|
for (x = 0; x < xmax; x++) { |
162 |
< |
c = map(colval(scanin[x],RED)); |
163 |
< |
putc(c, stdout); |
164 |
< |
c = map(colval(scanin[x],GRN)); |
172 |
< |
putc(c, stdout); |
173 |
< |
c = map(colval(scanin[x],BLU)); |
174 |
< |
putc(c, stdout); |
162 |
> |
putc(scanin[x][BLU], stdout); |
163 |
> |
putc(scanin[x][GRN], stdout); |
164 |
> |
putc(scanin[x][RED], stdout); |
165 |
|
} |
166 |
|
if (ferror(stdout)) |
167 |
|
quiterr("error writing rasterfile"); |
168 |
|
} |
169 |
|
/* free scanline */ |
170 |
|
free((char *)scanin); |
181 |
– |
#undef map |
171 |
|
} |