--- ray/src/px/x11image.c 1993/10/27 16:57:28 2.30 +++ ray/src/px/x11image.c 1993/11/15 10:55:33 2.34 @@ -119,9 +119,11 @@ extern long ftell(); Display *thedisplay; Atom closedownAtom, wmProtocolsAtom; -int noop() {} +int sigrecv; +int onsig() { sigrecv++; } + main(argc, argv) int argc; char *argv[]; @@ -179,6 +181,8 @@ char *argv[]; if (i > argc) goto userr; while (i < argc-1) { + sigrecv = 0; + signal(SIGCONT, onsig); if ((pid=fork()) == 0) { /* a child for each picture */ parent = -1; break; @@ -186,17 +190,15 @@ char *argv[]; if (pid < 0) quiterr("fork failed"); parent++; - signal(SIGCONT, noop); - pause(); /* wait for wake-up call */ + while (!sigrecv) + pause(); /* wait for wake-up call */ i++; } if (i < argc) { /* open picture file */ fname = argv[i]; fin = fopen(fname, "r"); - if (fin == NULL) { - sprintf(errmsg, "cannot open file \"%s\"", fname); - quiterr(errmsg); - } + if (fin == NULL) + quiterr("cannot open picture file"); } /* get header */ getheader(fin, headline, NULL); @@ -213,9 +215,10 @@ char *argv[]; init(argc, argv); /* get file and open window */ - if (parent < 0) + if (parent < 0) { kill(getppid(), SIGCONT); /* signal parent if child */ - + sigrecv--; + } for ( ; ; ) getevent(); /* main loop */ userr: @@ -311,10 +314,11 @@ char **argv; quiterr("cannot create window"); width = xmax; height = ymax; - xgcv.foreground = ourblack; - xgcv.background = ourwhite; + /* prepare graphics drawing context */ if ((xgcv.font = XLoadFont(thedisplay, FONTNAME)) == 0) quiterr("cannot get font"); + xgcv.foreground = ourblack; + xgcv.background = ourwhite; ourgc = XCreateGC(thedisplay, wind, GCForeground|GCBackground| GCFont, &xgcv); xgcv.function = GXinvert; @@ -350,16 +354,23 @@ char **argv; quiterr(err) /* print message and exit */ char *err; { - if (err != NULL) + register int es; + int cs; + + if (es = err != NULL) fprintf(stderr, "%s: %s: %s\n", progname, fname==NULL?"":fname, err); - if (wind) { + if (parent > 0 & wind != 0) { XDestroyWindow(thedisplay, wind); XFlush(thedisplay); - } - while (parent > 0 && wait(0) != -1) /* wait for any children */ + } else if (parent < 0 & sigrecv == 0) + kill(getppid(), SIGCONT); + while (parent > 0 && wait(&cs) != -1) { /* wait for any children */ + if (es == 0) + es = cs>>8 & 0xff; parent--; - exit(err != NULL); + } + exit(es); } @@ -661,9 +672,16 @@ XKeyPressedEvent *ekey; case '@': /* adaptation level */ if (avgbox(cval) == -1) return(-1); - comp = com=='@' - ? 106./pow(1.219+pow(luminance(cval)/exposure,.4),2.5)/exposure - : .5/bright(cval) ; + comp = bright(cval); + if (comp < 1e-20) { + XBell(thedisplay, 0); + return(-1); + } + if (com == '@') + comp = 106./exposure/ + pow(1.219+pow(comp*WHTEFFICACY/exposure,.4),2.5); + else + comp = .5/comp; comp = log(comp)/.69315 - scale; n = comp < 0 ? comp-.5 : comp+.5 ; /* round */ if (n == 0)