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 |
|
|
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)); |
308 |
|
if (ourras == NULL) |
309 |
|
goto fail; |
310 |
|
getmono(); |
311 |
< |
} else if (XMatchVisualInfo(thedisplay,ourscreen,24,TrueColor,&vinfo)) { |
311 |
> |
} else if (XMatchVisualInfo(thedisplay,ourscreen,24,TrueColor,&vinfo) |
312 |
> |
/* kludge for DirectColor */ |
313 |
> |
|| XMatchVisualInfo(thedisplay,ourscreen,24,DirectColor,&vinfo)) { |
314 |
|
ourdata = (unsigned char *)malloc(xmax*ymax*3); |
315 |
|
if (ourdata == NULL) |
316 |
|
goto fail; |
495 |
|
XButtonReleasedEvent b; |
496 |
|
XPointerMovedEvent m; |
497 |
|
} e; |
498 |
< |
int nxo, nyo; |
498 |
> |
int mxo, myo; |
499 |
|
|
500 |
|
XMaskEvent(thedisplay, ButtonReleaseMask|ButtonMotionMask, &e.u); |
501 |
|
while (e.u.type == MotionNotify) { |
502 |
< |
nxo = xoff + e.m.x - ebut->x; |
503 |
< |
nyo = yoff + e.m.y - ebut->y; |
504 |
< |
revbox(nxo, nyo, nxo+xmax, nyo+ymax); |
502 |
> |
mxo = e.m.x; |
503 |
> |
myo = e.m.y; |
504 |
> |
revline(ebut->x, ebut->y, mxo, myo); |
505 |
> |
revbox(xoff+mxo-ebut->x, yoff+myo-ebut->y, |
506 |
> |
xoff+mxo-ebut->x+xmax, yoff+myo-ebut->y+ymax); |
507 |
|
XMaskEvent(thedisplay,ButtonReleaseMask|ButtonMotionMask,&e.u); |
508 |
< |
revbox(nxo, nyo, nxo+xmax, nyo+ymax); |
508 |
> |
revline(ebut->x, ebut->y, mxo, myo); |
509 |
> |
revbox(xoff+mxo-ebut->x, yoff+myo-ebut->y, |
510 |
> |
xoff+mxo-ebut->x+xmax, yoff+myo-ebut->y+ymax); |
511 |
|
} |
512 |
|
xoff += e.b.x - ebut->x; |
513 |
|
yoff += e.b.y - ebut->y; |
551 |
|
revbox(x0, y0, x1, y1) /* draw box with reversed lines */ |
552 |
|
int x0, y0, x1, y1; |
553 |
|
{ |
554 |
< |
static GC mygc = 0; |
554 |
> |
revline(x0, y0, x1, y0); |
555 |
> |
revline(x0, y1, x1, y1); |
556 |
> |
revline(x0, y0, x0, y1); |
557 |
> |
revline(x1, y0, x1, y1); |
558 |
> |
} |
559 |
|
|
542 |
– |
if (mygc == 0) { |
543 |
– |
mygc = XCreateGC(thedisplay, wind, 0, 0); |
544 |
– |
XSetFunction(thedisplay, mygc, GXinvert); |
545 |
– |
} |
546 |
– |
XDrawLine(thedisplay, wind, mygc, x0, y0, x1, y0); |
547 |
– |
XDrawLine(thedisplay, wind, mygc, x0, y1, x1, y1); |
548 |
– |
XDrawLine(thedisplay, wind, mygc, x0, y0, x0, y1); |
549 |
– |
XDrawLine(thedisplay, wind, mygc, x1, y0, x1, y1); |
550 |
– |
} /* end of revbox */ |
560 |
|
|
552 |
– |
|
561 |
|
avgbox(clr) /* average color over current box */ |
562 |
|
COLOR clr; |
563 |
|
{ |
603 |
|
register unsigned char *dp; |
604 |
|
register int x, err; |
605 |
|
int y; |
606 |
< |
rgbpixel *inline; |
606 |
> |
rgbpixel *inl; |
607 |
|
short *cerr; |
608 |
|
|
609 |
< |
if ((inline = (rgbpixel *)malloc(xmax*sizeof(rgbpixel))) == NULL |
609 |
> |
if ((inl = (rgbpixel *)malloc(xmax*sizeof(rgbpixel))) == NULL |
610 |
|
|| (cerr = (short *)calloc(xmax,sizeof(short))) == NULL) |
611 |
|
quit("out of memory in getmono"); |
612 |
|
dp = ourdata - 1; |
613 |
|
for (y = 0; y < ymax; y++) { |
614 |
< |
picreadline3(y, inline); |
614 |
> |
picreadline3(y, inl); |
615 |
|
err = 0; |
616 |
|
for (x = 0; x < xmax; x++) { |
617 |
|
if (!(x&7)) |
618 |
|
*++dp = 0; |
619 |
< |
err += rgb_bright(&inline[x]) + cerr[x]; |
619 |
> |
err += rgb_bright(&inl[x]) + cerr[x]; |
620 |
|
if (err > 127) |
621 |
|
err -= 255; |
622 |
|
else |
624 |
|
cerr[x] = err >>= 1; |
625 |
|
} |
626 |
|
} |
627 |
< |
free((char *)inline); |
627 |
> |
free((char *)inl); |
628 |
|
free((char *)cerr); |
629 |
|
} |
630 |
|
|