9 |
|
*/ |
10 |
|
|
11 |
|
#include <stdio.h> |
12 |
+ |
#include <math.h> |
13 |
|
#ifdef MSDOS |
14 |
|
#include <fcntl.h> |
15 |
|
#endif |
16 |
|
#include "color.h" |
17 |
|
|
18 |
+ |
#define GAMVAL 1.5 /* gamma value for pixels */ |
19 |
+ |
|
20 |
|
#define GRY -1 /* artificial index for grey */ |
21 |
|
|
22 |
|
#define HMARGIN (.5*72) /* horizontal margin */ |
106 |
|
getheader(stdin, headline, NULL); |
107 |
|
if (wrongformat || fgetresolu(&xmax, &ymax, stdin) < 0) |
108 |
|
quiterr("bad picture format"); |
109 |
+ |
/* gamma compression */ |
110 |
+ |
setcolrgam(GAMVAL); |
111 |
|
/* write header */ |
112 |
|
PSheader(i <= argc-1 ? argv[i] : "<stdin>"); |
113 |
|
/* convert file */ |
175 |
|
HMARGIN+(pwidth-iwidth)*.5+iwidth, |
176 |
|
VMARGIN+(pheight-iheight)*.5+iheight); |
177 |
|
puts("%%EndComments"); |
178 |
< |
puts("save"); |
178 |
> |
puts("gsave save"); |
179 |
|
puts("64 dict begin"); |
180 |
|
/* define image reader */ |
181 |
|
if (docolor) { |
191 |
|
/* set up transformation matrix */ |
192 |
|
printf("%f %f translate\n", HMARGIN, VMARGIN); |
193 |
|
if (pwidth == PHEIGHT) { |
194 |
< |
printf("0 %f translate\n", PHEIGHT); |
195 |
< |
puts("-90 rotate"); |
194 |
> |
printf("%f 0 translate\n", PWIDTH); |
195 |
> |
puts("90 rotate"); |
196 |
|
} |
197 |
|
printf("%f %f translate\n", (pwidth-iwidth)*.5, (pheight-iheight)*.5); |
198 |
|
printf("%f %f scale\n", iwidth, iheight); |
199 |
< |
puts("%%%%EndProlog"); |
199 |
> |
puts("%%EndProlog"); |
200 |
|
/* start image procedure */ |
201 |
|
printf("%d %d 8 [%d 0 0 %d 0 %d] ", xmax, ymax, xmax, -ymax, ymax); |
202 |
|
if (docolor) { |
214 |
|
printf("/#copies %d def\n", ncopies); |
215 |
|
puts("showpage"); |
216 |
|
puts("end"); |
217 |
< |
puts("restore"); |
217 |
> |
puts("restore grestore"); |
218 |
|
puts("%%EOF"); |
219 |
|
} |
220 |
|
|
228 |
|
for (i = 0; i < 128; i++) /* clear */ |
229 |
|
itab[i] = -1; |
230 |
|
for (i = 1; i < 63; i++) /* assign greys */ |
231 |
< |
itab[code[i]] = i<<2 | 2; |
231 |
> |
itab[code[i]] = 256.0*pow(((i<<2)+2.5)/256.0, GAMVAL); |
232 |
|
itab[code[0]] = 0; /* black is black */ |
233 |
|
itab[code[63]] = 255; /* and white is white */ |
234 |
|
printf("/codetab ["); |
286 |
|
for (y = ymax-1; y >= 0; y--) { |
287 |
|
if (freadcolrs(scanin, xmax, stdin) < 0) |
288 |
|
quiterr("error reading Radiance picture"); |
289 |
< |
normcolrs(scanin, xmax, bradj); /* normalize */ |
289 |
> |
if (bradj) /* adjust exposure */ |
290 |
> |
shiftcolrs(scanin, xmax, bradj); |
291 |
> |
colrs_gambs(scanin, xmax); /* gamma compression */ |
292 |
|
if (docolor) { |
293 |
|
putprim(scanin, RED); |
294 |
|
putprim(scanin, GRN); |