43 |
|
#define ourroot RootWindow(thedisplay,ourscreen) |
44 |
|
#define ourgc DefaultGC(thedisplay,ourscreen) |
45 |
|
|
46 |
+ |
#define revline(x0,y0,x1,y1) XDrawLine(thedisplay,wind,revgc,x0,y0,x1,y1) |
47 |
+ |
|
48 |
|
#define redraw(x,y,w,h) patch_raster(wind,(x)-xoff,(y)-yoff,x,y,w,h,ourras) |
49 |
|
|
50 |
|
double gamcor = 2.2; /* gamma correction */ |
77 |
|
|
78 |
|
double exposure = 1.0; /* exposure compensation used */ |
79 |
|
|
80 |
+ |
GC revgc; /* graphics context with GXinvert */ |
81 |
+ |
|
82 |
|
XRASTER *ourras; /* our stored image */ |
83 |
|
unsigned char *ourdata; /* our image data */ |
84 |
|
|
198 |
|
|
199 |
|
init() /* get data and open window */ |
200 |
|
{ |
201 |
+ |
XSetWindowAttributes ourwinattr; |
202 |
|
XSizeHints oursizhints; |
203 |
|
register int i; |
204 |
|
|
211 |
|
} |
212 |
|
if ((thedisplay = XOpenDisplay(NULL)) == NULL) |
213 |
|
quiterr("can't open display; DISPLAY variable set?"); |
209 |
– |
wind = XCreateSimpleWindow(thedisplay, |
210 |
– |
ourroot, 0, 0, xmax, ymax, BORWIDTH, ourblack, ourwhite); |
211 |
– |
if (wind == 0) |
212 |
– |
quiterr("can't create window"); |
214 |
|
if (maxcolors == 0) { /* get number of available colors */ |
215 |
|
i = DisplayPlanes(thedisplay,ourscreen); |
216 |
|
maxcolors = i > 8 ? 256 : 1<<i; |
217 |
|
if (maxcolors > 4) maxcolors -= 2; |
218 |
|
} |
219 |
+ |
/* store image */ |
220 |
+ |
getras(); |
221 |
+ |
/* open window */ |
222 |
+ |
ourwinattr.border_pixel = ourblack; |
223 |
+ |
ourwinattr.background_pixel = ourwhite; |
224 |
+ |
wind = XCreateWindow(thedisplay, ourroot, 0, 0, xmax, ymax, BORWIDTH, |
225 |
+ |
0, InputOutput, ourras->visual, |
226 |
+ |
CWBackPixel|CWBorderPixel, &ourwinattr); |
227 |
+ |
if (wind == 0) |
228 |
+ |
quiterr("can't create window"); |
229 |
+ |
width = xmax; |
230 |
+ |
height = ymax; |
231 |
|
fontid = XLoadFont(thedisplay, FONTNAME); |
232 |
|
if (fontid == 0) |
233 |
|
quiterr("can't get font"); |
234 |
|
XSetFont(thedisplay, ourgc, fontid); |
235 |
+ |
revgc = XCreateGC(thedisplay, wind, 0, 0); |
236 |
+ |
XSetFunction(thedisplay, revgc, GXinvert); |
237 |
|
XStoreName(thedisplay, wind, fname == NULL ? progname : fname); |
238 |
|
XDefineCursor(thedisplay, wind, XCreateFontCursor(thedisplay, |
239 |
|
XC_diamond_cross)); |
259 |
|
} |
260 |
|
XSetNormalHints(thedisplay, wind, &oursizhints); |
261 |
|
} |
247 |
– |
/* store image */ |
248 |
– |
getras(); |
262 |
|
XSelectInput(thedisplay, wind, ButtonPressMask|ButtonReleaseMask |
263 |
|
|ButtonMotionMask|StructureNotifyMask |
264 |
|
|KeyPressMask|ExposureMask); |
493 |
|
XButtonReleasedEvent b; |
494 |
|
XPointerMovedEvent m; |
495 |
|
} e; |
496 |
< |
int nxo, nyo; |
496 |
> |
int mxo, myo; |
497 |
|
|
498 |
|
XMaskEvent(thedisplay, ButtonReleaseMask|ButtonMotionMask, &e.u); |
499 |
|
while (e.u.type == MotionNotify) { |
500 |
< |
nxo = xoff + e.m.x - ebut->x; |
501 |
< |
nyo = yoff + e.m.y - ebut->y; |
502 |
< |
revbox(nxo, nyo, nxo+xmax, nyo+ymax); |
500 |
> |
mxo = e.m.x; |
501 |
> |
myo = e.m.y; |
502 |
> |
revline(ebut->x, ebut->y, mxo, myo); |
503 |
> |
revbox(xoff+mxo-ebut->x, yoff+myo-ebut->y, |
504 |
> |
xoff+mxo-ebut->x+xmax, yoff+myo-ebut->y+ymax); |
505 |
|
XMaskEvent(thedisplay,ButtonReleaseMask|ButtonMotionMask,&e.u); |
506 |
< |
revbox(nxo, nyo, nxo+xmax, nyo+ymax); |
506 |
> |
revline(ebut->x, ebut->y, mxo, myo); |
507 |
> |
revbox(xoff+mxo-ebut->x, yoff+myo-ebut->y, |
508 |
> |
xoff+mxo-ebut->x+xmax, yoff+myo-ebut->y+ymax); |
509 |
|
} |
510 |
|
xoff += e.b.x - ebut->x; |
511 |
|
yoff += e.b.y - ebut->y; |
549 |
|
revbox(x0, y0, x1, y1) /* draw box with reversed lines */ |
550 |
|
int x0, y0, x1, y1; |
551 |
|
{ |
552 |
< |
static GC mygc = 0; |
553 |
< |
|
554 |
< |
if (mygc == 0) { |
555 |
< |
mygc = XCreateGC(thedisplay, wind, 0, 0); |
556 |
< |
XSetFunction(thedisplay, mygc, GXinvert); |
540 |
< |
} |
541 |
< |
XDrawLine(thedisplay, wind, mygc, x0, y0, x1, y0); |
542 |
< |
XDrawLine(thedisplay, wind, mygc, x0, y1, x1, y1); |
543 |
< |
XDrawLine(thedisplay, wind, mygc, x0, y0, x0, y1); |
544 |
< |
XDrawLine(thedisplay, wind, mygc, x1, y0, x1, y1); |
545 |
< |
} /* end of revbox */ |
552 |
> |
revline(x0, y0, x1, y0); |
553 |
> |
revline(x0, y1, x1, y1); |
554 |
> |
revline(x0, y0, x0, y1); |
555 |
> |
revline(x1, y0, x1, y1); |
556 |
> |
} |
557 |
|
|
558 |
|
|
559 |
|
avgbox(clr) /* average color over current box */ |