--- ray/src/px/x11image.c 1990/03/02 12:22:37 1.3 +++ ray/src/px/x11image.c 1990/10/17 14:56:18 1.9 @@ -43,6 +43,8 @@ static char SCCSid[] = "$SunId$ LBL"; #define ourroot RootWindow(thedisplay,ourscreen) #define ourgc DefaultGC(thedisplay,ourscreen) +#define revline(x0,y0,x1,y1) XDrawLine(thedisplay,wind,revgc,x0,y0,x1,y1) + #define redraw(x,y,w,h) patch_raster(wind,(x)-xoff,(y)-yoff,x,y,w,h,ourras) double gamcor = 2.2; /* gamma correction */ @@ -75,6 +77,8 @@ int cury = 0; /* current scan location */ double exposure = 1.0; /* exposure compensation used */ +GC revgc; /* graphics context with GXinvert */ + XRASTER *ourras; /* our stored image */ unsigned char *ourdata; /* our image data */ @@ -194,6 +198,7 @@ char *s; init() /* get data and open window */ { + XSetWindowAttributes ourwinattr; XSizeHints oursizhints; register int i; @@ -206,19 +211,29 @@ init() /* get data and open window */ } if ((thedisplay = XOpenDisplay(NULL)) == NULL) quiterr("can't open display; DISPLAY variable set?"); - wind = XCreateSimpleWindow(thedisplay, - ourroot, 0, 0, xmax, ymax, BORWIDTH, ourblack, ourwhite); - if (wind == 0) - quiterr("can't create window"); if (maxcolors == 0) { /* get number of available colors */ i = DisplayPlanes(thedisplay,ourscreen); maxcolors = i > 8 ? 256 : 1< 4) maxcolors -= 2; } + /* store image */ + getras(); + /* open window */ + ourwinattr.border_pixel = ourblack; + ourwinattr.background_pixel = ourwhite; + wind = XCreateWindow(thedisplay, ourroot, 0, 0, xmax, ymax, BORWIDTH, + 0, InputOutput, ourras->visual, + CWBackPixel|CWBorderPixel, &ourwinattr); + if (wind == 0) + quiterr("can't create window"); + width = xmax; + height = ymax; fontid = XLoadFont(thedisplay, FONTNAME); if (fontid == 0) quiterr("can't get font"); XSetFont(thedisplay, ourgc, fontid); + revgc = XCreateGC(thedisplay, wind, 0, 0); + XSetFunction(thedisplay, revgc, GXinvert); XStoreName(thedisplay, wind, fname == NULL ? progname : fname); XDefineCursor(thedisplay, wind, XCreateFontCursor(thedisplay, XC_diamond_cross)); @@ -244,8 +259,6 @@ init() /* get data and open window */ } XSetNormalHints(thedisplay, wind, &oursizhints); } - /* store image */ - getras(); XSelectInput(thedisplay, wind, ButtonPressMask|ButtonReleaseMask |ButtonMotionMask|StructureNotifyMask |KeyPressMask|ExposureMask); @@ -295,7 +308,9 @@ getras() /* get raster file */ if (ourras == NULL) goto fail; getmono(); - } else if (XMatchVisualInfo(thedisplay,ourscreen,24,TrueColor,&vinfo)) { + } else if (XMatchVisualInfo(thedisplay,ourscreen,24,TrueColor,&vinfo) + /* kludge for DirectColor */ + || XMatchVisualInfo(thedisplay,ourscreen,24,DirectColor,&vinfo)) { ourdata = (unsigned char *)malloc(xmax*ymax*3); if (ourdata == NULL) goto fail; @@ -321,7 +336,7 @@ getras() /* get raster file */ } return; fail: - quit("could not create raster image"); + quiterr("could not create raster image"); } @@ -430,9 +445,10 @@ XKeyPressedEvent *ekey; XBell(thedisplay, 0); return(-1); } - viewray(rorg, rdir, &ourview, + if (viewray(rorg, rdir, &ourview, (ekey->x-xoff+.5)/xmax, - (ymax-1-ekey->y+yoff+.5)/ymax); + (ymax-1-ekey->y+yoff+.5)/ymax) < 0) + return(-1); printf("%e %e %e ", rorg[0], rorg[1], rorg[2]); printf("%e %e %e\n", rdir[0], rdir[1], rdir[2]); fflush(stdout); @@ -480,15 +496,19 @@ XButtonPressedEvent *ebut; XButtonReleasedEvent b; XPointerMovedEvent m; } e; - int nxo, nyo; + int mxo, myo; XMaskEvent(thedisplay, ButtonReleaseMask|ButtonMotionMask, &e.u); while (e.u.type == MotionNotify) { - nxo = xoff + e.m.x - ebut->x; - nyo = yoff + e.m.y - ebut->y; - revbox(nxo, nyo, nxo+xmax, nyo+ymax); + mxo = e.m.x; + myo = e.m.y; + revline(ebut->x, ebut->y, mxo, myo); + revbox(xoff+mxo-ebut->x, yoff+myo-ebut->y, + xoff+mxo-ebut->x+xmax, yoff+myo-ebut->y+ymax); XMaskEvent(thedisplay,ButtonReleaseMask|ButtonMotionMask,&e.u); - revbox(nxo, nyo, nxo+xmax, nyo+ymax); + revline(ebut->x, ebut->y, mxo, myo); + revbox(xoff+mxo-ebut->x, yoff+myo-ebut->y, + xoff+mxo-ebut->x+xmax, yoff+myo-ebut->y+ymax); } xoff += e.b.x - ebut->x; yoff += e.b.y - ebut->y; @@ -532,19 +552,13 @@ XButtonPressedEvent *ebut; revbox(x0, y0, x1, y1) /* draw box with reversed lines */ int x0, y0, x1, y1; { - static GC mygc = 0; + revline(x0, y0, x1, y0); + revline(x0, y1, x1, y1); + revline(x0, y0, x0, y1); + revline(x1, y0, x1, y1); +} - if (mygc == 0) { - mygc = XCreateGC(thedisplay, wind, 0, 0); - XSetFunction(thedisplay, mygc, GXinvert); - } - XDrawLine(thedisplay, wind, mygc, x0, y0, x1, y0); - XDrawLine(thedisplay, wind, mygc, x0, y1, x1, y1); - XDrawLine(thedisplay, wind, mygc, x0, y0, x0, y1); - XDrawLine(thedisplay, wind, mygc, x1, y0, x1, y1); -} /* end of revbox */ - avgbox(clr) /* average color over current box */ COLOR clr; { @@ -590,20 +604,20 @@ getmono() /* get monochrome data */ register unsigned char *dp; register int x, err; int y; - rgbpixel *inline; + rgbpixel *inl; short *cerr; - if ((inline = (rgbpixel *)malloc(xmax*sizeof(rgbpixel))) == NULL + if ((inl = (rgbpixel *)malloc(xmax*sizeof(rgbpixel))) == NULL || (cerr = (short *)calloc(xmax,sizeof(short))) == NULL) - quit("out of memory in getmono"); + quiterr("out of memory in getmono"); dp = ourdata - 1; for (y = 0; y < ymax; y++) { - picreadline3(y, inline); + picreadline3(y, inl); err = 0; for (x = 0; x < xmax; x++) { if (!(x&7)) *++dp = 0; - err += rgb_bright(&inline[x]) + cerr[x]; + err += rgb_bright(&inl[x]) + cerr[x]; if (err > 127) err -= 255; else @@ -611,7 +625,7 @@ getmono() /* get monochrome data */ cerr[x] = err >>= 1; } } - free((char *)inline); + free((char *)inl); free((char *)cerr); } @@ -660,7 +674,7 @@ int y; if (scanpos == NULL || scanpos[y] == -1) return(-1); if (fseek(fin, scanpos[y], 0) == -1) - quit("fseek error"); + quiterr("fseek error"); cury = y; } else if (scanpos != NULL) scanpos[y] = ftell(fin);