56 |
|
#define redraw(x,y,w,h) patch_raster(wind,(x)-xoff,(y)-yoff,x,y,w,h,ourras) |
57 |
|
|
58 |
|
double gamcor = 2.2; /* gamma correction */ |
59 |
+ |
char *gamstr = NULL; /* gamma value override */ |
60 |
|
|
61 |
|
int dither = 1; /* dither colors? */ |
62 |
|
int fast = 0; /* keep picture in Pixmap? */ |
117 |
|
|
118 |
|
extern long ftell(); |
119 |
|
|
120 |
+ |
extern char *getenv(); |
121 |
+ |
|
122 |
|
Display *thedisplay; |
123 |
|
Atom closedownAtom, wmProtocolsAtom; |
124 |
|
|
125 |
< |
int noop() {} |
125 |
> |
int sigrecv; |
126 |
|
|
127 |
+ |
int onsig() { sigrecv++; } |
128 |
|
|
129 |
+ |
|
130 |
|
main(argc, argv) |
131 |
|
int argc; |
132 |
|
char *argv[]; |
133 |
|
{ |
129 |
– |
extern char *getenv(); |
130 |
– |
char *gv; |
134 |
|
int headline(); |
135 |
|
int i; |
136 |
|
int pid; |
137 |
|
|
138 |
|
progname = argv[0]; |
136 |
– |
if ((gv = getenv("GAMMA")) != NULL) |
137 |
– |
gamcor = atof(gv); |
139 |
|
|
140 |
|
for (i = 1; i < argc; i++) |
141 |
|
if (argv[i][0] == '-') |
167 |
|
if (argv[i][2] == 'e') |
168 |
|
geometry = argv[++i]; |
169 |
|
else |
170 |
< |
gamcor = atof(argv[++i]); |
170 |
> |
gamstr = argv[++i]; |
171 |
|
break; |
172 |
|
default: |
173 |
|
goto userr; |
180 |
|
if (i > argc) |
181 |
|
goto userr; |
182 |
|
while (i < argc-1) { |
183 |
+ |
sigrecv = 0; |
184 |
+ |
signal(SIGCONT, onsig); |
185 |
|
if ((pid=fork()) == 0) { /* a child for each picture */ |
186 |
|
parent = -1; |
187 |
|
break; |
189 |
|
if (pid < 0) |
190 |
|
quiterr("fork failed"); |
191 |
|
parent++; |
192 |
< |
signal(SIGCONT, noop); |
193 |
< |
pause(); /* wait for wake-up call */ |
192 |
> |
while (!sigrecv) |
193 |
> |
pause(); /* wait for wake-up call */ |
194 |
|
i++; |
195 |
|
} |
196 |
|
if (i < argc) { /* open picture file */ |
197 |
|
fname = argv[i]; |
198 |
|
fin = fopen(fname, "r"); |
199 |
< |
if (fin == NULL) { |
200 |
< |
sprintf(errmsg, "cannot open file \"%s\"", fname); |
198 |
< |
quiterr(errmsg); |
199 |
< |
} |
199 |
> |
if (fin == NULL) |
200 |
> |
quiterr("cannot open picture file"); |
201 |
|
} |
202 |
|
/* get header */ |
203 |
|
getheader(fin, headline, NULL); |
214 |
|
|
215 |
|
init(argc, argv); /* get file and open window */ |
216 |
|
|
217 |
< |
if (parent < 0) |
217 |
> |
if (parent < 0) { |
218 |
|
kill(getppid(), SIGCONT); /* signal parent if child */ |
219 |
< |
|
219 |
> |
sigrecv--; |
220 |
> |
} |
221 |
|
for ( ; ; ) |
222 |
|
getevent(); /* main loop */ |
223 |
|
userr: |
224 |
|
fprintf(stderr, |
225 |
< |
"Usage: %s [-di disp][[-ge] spec][-b][-m][-d][-f][-c nclrs][-e +/-stops] pic ..\n", |
225 |
> |
"Usage: %s [-di disp][[-ge] spec][-b][-m][-d][-f][-c nclrs][-e +/-stops][-g gamcor] pic ..\n", |
226 |
|
progname); |
227 |
|
exit(1); |
228 |
|
} |
272 |
|
name += i+1; |
273 |
|
if ((thedisplay = XOpenDisplay(dispname)) == NULL) |
274 |
|
quiterr("cannot open display"); |
275 |
+ |
/* set gamma value */ |
276 |
+ |
if (gamstr == NULL) /* get it from the X server */ |
277 |
+ |
gamstr = XGetDefault(thedisplay, "radiance", "gamma"); |
278 |
+ |
if (gamstr == NULL) /* get it from the environment */ |
279 |
+ |
gamstr = getenv("GAMMA"); |
280 |
+ |
if (gamstr != NULL) |
281 |
+ |
gamcor = atof(gamstr); |
282 |
|
/* get best visual for default screen */ |
283 |
|
getbestvis(); |
284 |
|
/* store image */ |
320 |
|
quiterr("cannot create window"); |
321 |
|
width = xmax; |
322 |
|
height = ymax; |
323 |
< |
xgcv.foreground = ourblack; |
315 |
< |
xgcv.background = ourwhite; |
323 |
> |
/* prepare graphics drawing context */ |
324 |
|
if ((xgcv.font = XLoadFont(thedisplay, FONTNAME)) == 0) |
325 |
|
quiterr("cannot get font"); |
326 |
+ |
xgcv.foreground = ourblack; |
327 |
+ |
xgcv.background = ourwhite; |
328 |
|
ourgc = XCreateGC(thedisplay, wind, GCForeground|GCBackground| |
329 |
|
GCFont, &xgcv); |
330 |
|
xgcv.function = GXinvert; |
369 |
|
if (parent > 0 & wind != 0) { |
370 |
|
XDestroyWindow(thedisplay, wind); |
371 |
|
XFlush(thedisplay); |
372 |
< |
} |
372 |
> |
} else if (parent < 0 & sigrecv == 0) |
373 |
> |
kill(getppid(), SIGCONT); |
374 |
|
while (parent > 0 && wait(&cs) != -1) { /* wait for any children */ |
375 |
|
if (es == 0) |
376 |
|
es = cs>>8 & 0xff; |
678 |
|
case '@': /* adaptation level */ |
679 |
|
if (avgbox(cval) == -1) |
680 |
|
return(-1); |
681 |
< |
comp = com=='@' |
682 |
< |
? 106./pow(1.219+pow(luminance(cval)/exposure,.4),2.5)/exposure |
683 |
< |
: .5/bright(cval) ; |
681 |
> |
comp = bright(cval); |
682 |
> |
if (comp < 1e-20) { |
683 |
> |
XBell(thedisplay, 0); |
684 |
> |
return(-1); |
685 |
> |
} |
686 |
> |
if (com == '@') |
687 |
> |
comp = 106./exposure/ |
688 |
> |
pow(1.219+pow(comp*WHTEFFICACY/exposure,.4),2.5); |
689 |
> |
else |
690 |
> |
comp = .5/comp; |
691 |
|
comp = log(comp)/.69315 - scale; |
692 |
|
n = comp < 0 ? comp-.5 : comp+.5 ; /* round */ |
693 |
|
if (n == 0) |
948 |
|
colrs_gambs(scanline, xmax); |
949 |
|
if (ourras->image->blue_mask & 1) |
950 |
|
for (x = 0; x < xmax; x++) |
951 |
< |
*dp++ = scanline[x][RED] << 16 | |
952 |
< |
scanline[x][GRN] << 8 | |
953 |
< |
scanline[x][BLU] ; |
951 |
> |
*dp++ = (unsigned int4)scanline[x][RED] << 16 | |
952 |
> |
(unsigned int4)scanline[x][GRN] << 8 | |
953 |
> |
(unsigned int4)scanline[x][BLU] ; |
954 |
|
else |
955 |
|
for (x = 0; x < xmax; x++) |
956 |
< |
*dp++ = scanline[x][RED] | |
957 |
< |
scanline[x][GRN] << 8 | |
958 |
< |
scanline[x][BLU] << 16 ; |
956 |
> |
*dp++ = (unsigned int4)scanline[x][RED] | |
957 |
> |
(unsigned int4)scanline[x][GRN] << 8 | |
958 |
> |
(unsigned int4)scanline[x][BLU] << 16 ; |
959 |
|
} |
960 |
|
} |
961 |
|
|