--- ray/src/px/x11image.c 1993/11/04 12:04:55 2.33 +++ ray/src/px/x11image.c 1994/09/20 15:48:15 2.38 @@ -56,6 +56,7 @@ static char SCCSid[] = "$SunId$ LBL"; #define redraw(x,y,w,h) patch_raster(wind,(x)-xoff,(y)-yoff,x,y,w,h,ourras) double gamcor = 2.2; /* gamma correction */ +char *gamstr = NULL; /* gamma value override */ int dither = 1; /* dither colors? */ int fast = 0; /* keep picture in Pixmap? */ @@ -112,10 +113,12 @@ char *progname; char errmsg[128]; -extern BYTE clrtab[256][3]; /* global color map */ +BYTE clrtab[256][3]; /* global color map */ extern long ftell(); +extern char *getenv(); + Display *thedisplay; Atom closedownAtom, wmProtocolsAtom; @@ -128,15 +131,11 @@ main(argc, argv) int argc; char *argv[]; { - extern char *getenv(); - char *gv; int headline(); int i; int pid; progname = argv[0]; - if ((gv = getenv("GAMMA")) != NULL) - gamcor = atof(gv); for (i = 1; i < argc; i++) if (argv[i][0] == '-') @@ -168,7 +167,7 @@ char *argv[]; if (argv[i][2] == 'e') geometry = argv[++i]; else - gamcor = atof(argv[++i]); + gamstr = argv[++i]; break; default: goto userr; @@ -223,7 +222,7 @@ char *argv[]; getevent(); /* main loop */ userr: fprintf(stderr, -"Usage: %s [-di disp][[-ge] spec][-b][-m][-d][-f][-c nclrs][-e +/-stops] pic ..\n", +"Usage: %s [-di disp][[-ge] spec][-b][-m][-d][-f][-c nclrs][-e +/-stops][-g gamcor] pic ..\n", progname); exit(1); } @@ -273,6 +272,13 @@ char **argv; name += i+1; if ((thedisplay = XOpenDisplay(dispname)) == NULL) quiterr("cannot open display"); + /* set gamma value */ + if (gamstr == NULL) /* get it from the X server */ + gamstr = XGetDefault(thedisplay, "radiance", "gamma"); + if (gamstr == NULL) /* get it from the environment */ + gamstr = getenv("DISPLAY_GAMMA"); + if (gamstr != NULL) + gamcor = atof(gamstr); /* get best visual for default screen */ getbestvis(); /* store image */ @@ -360,10 +366,9 @@ char *err; if (es = err != NULL) fprintf(stderr, "%s: %s: %s\n", progname, fname==NULL?"":fname, err); - if (parent > 0 & wind != 0) { - XDestroyWindow(thedisplay, wind); - XFlush(thedisplay); - } else if (parent < 0 & sigrecv == 0) + if (thedisplay != NULL) + XCloseDisplay(thedisplay); + if (parent < 0 & sigrecv == 0) kill(getppid(), SIGCONT); while (parent > 0 && wait(&cs) != -1) { /* wait for any children */ if (es == 0) @@ -672,9 +677,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) @@ -935,14 +947,14 @@ getfull() /* get full (24-bit) data */ colrs_gambs(scanline, xmax); if (ourras->image->blue_mask & 1) for (x = 0; x < xmax; x++) - *dp++ = scanline[x][RED] << 16 | - scanline[x][GRN] << 8 | - scanline[x][BLU] ; + *dp++ = (unsigned int4)scanline[x][RED] << 16 | + (unsigned int4)scanline[x][GRN] << 8 | + (unsigned int4)scanline[x][BLU] ; else for (x = 0; x < xmax; x++) - *dp++ = scanline[x][RED] | - scanline[x][GRN] << 8 | - scanline[x][BLU] << 16 ; + *dp++ = (unsigned int4)scanline[x][RED] | + (unsigned int4)scanline[x][GRN] << 8 | + (unsigned int4)scanline[x][BLU] << 16 ; } } @@ -987,7 +999,8 @@ getmapped() /* get color-mapped data */ /* set gamma correction */ setcolrgam(gamcor); /* make histogram */ - new_histo(); + if (new_histo((long)xmax*ymax) == -1) + quiterr("cannot initialize histogram"); for (y = 0; y < ymax; y++) { if (getscan(y) < 0) break;