| 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 |
|
|
| 141 |
|
default: |
| 142 |
|
goto userr; |
| 143 |
|
} |
| 144 |
+ |
else if (argv[i][0] == '=') |
| 145 |
+ |
geometry = argv[i]; |
| 146 |
|
else |
| 147 |
|
break; |
| 148 |
|
|
| 149 |
< |
if (argc-i == 1) { |
| 149 |
> |
if (i == argc-1) { |
| 150 |
|
fname = argv[i]; |
| 151 |
|
fin = fopen(fname, "r"); |
| 152 |
|
if (fin == NULL) { |
| 153 |
|
sprintf(errmsg, "can't open file \"%s\"", fname); |
| 154 |
|
quiterr(errmsg); |
| 155 |
|
} |
| 156 |
< |
} |
| 156 |
> |
} else if (i != argc) |
| 157 |
> |
goto userr; |
| 158 |
|
/* get header */ |
| 159 |
|
getheader(fin, headline); |
| 160 |
|
/* get picture dimensions */ |
| 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?"); |
| 206 |
– |
wind = XCreateSimpleWindow(thedisplay, |
| 207 |
– |
ourroot, 0, 0, xmax, ymax, BORWIDTH, ourblack, ourwhite); |
| 208 |
– |
if (wind == 0) |
| 209 |
– |
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)); |
| 241 |
|
bzero((char *)&oursizhints, sizeof(oursizhints)); |
| 242 |
|
i = XParseGeometry(geometry, &oursizhints.x, &oursizhints.y, |
| 243 |
|
&oursizhints.width, &oursizhints.height); |
| 244 |
< |
if (i & (XValue|YValue) == (XValue|YValue)) { |
| 244 |
> |
if ((i&(WidthValue|HeightValue)) == (WidthValue|HeightValue)) |
| 245 |
> |
oursizhints.flags |= USSize; |
| 246 |
> |
else { |
| 247 |
> |
oursizhints.width = xmax; |
| 248 |
> |
oursizhints.height = ymax; |
| 249 |
> |
oursizhints.flags |= PSize; |
| 250 |
> |
} |
| 251 |
> |
if ((i&(XValue|YValue)) == (XValue|YValue)) { |
| 252 |
|
oursizhints.flags |= USPosition; |
| 253 |
|
if (i & XNegative) |
| 254 |
< |
oursizhints.x += DisplayWidth(thedisplay,ourscreen)-1; |
| 254 |
> |
oursizhints.x += DisplayWidth(thedisplay, |
| 255 |
> |
ourscreen)-1-oursizhints.width-2*BORWIDTH; |
| 256 |
|
if (i & YNegative) |
| 257 |
< |
oursizhints.y += DisplayHeight(thedisplay,ourscreen)-1; |
| 257 |
> |
oursizhints.y += DisplayHeight(thedisplay, |
| 258 |
> |
ourscreen)-1-oursizhints.height-2*BORWIDTH; |
| 259 |
|
} |
| 233 |
– |
if (i & (WidthValue|HeightValue) == (WidthValue|HeightValue)) |
| 234 |
– |
oursizhints.flags |= USSize; |
| 260 |
|
XSetNormalHints(thedisplay, wind, &oursizhints); |
| 261 |
|
} |
| 237 |
– |
/* store image */ |
| 238 |
– |
getras(); |
| 262 |
|
XSelectInput(thedisplay, wind, ButtonPressMask|ButtonReleaseMask |
| 263 |
|
|ButtonMotionMask|StructureNotifyMask |
| 264 |
|
|KeyPressMask|ExposureMask); |
| 297 |
|
getras() /* get raster file */ |
| 298 |
|
{ |
| 299 |
|
colormap ourmap; |
| 277 |
– |
unsigned char rmap[256], gmap[256], bmap[256]; |
| 300 |
|
XVisualInfo vinfo; |
| 279 |
– |
register int i; |
| 301 |
|
|
| 302 |
|
if (maxcolors <= 2) { /* monochrome */ |
| 303 |
|
ourdata = (unsigned char *)malloc(ymax*((xmax+7)/8)); |
| 329 |
|
biq(dither,maxcolors,1,ourmap); |
| 330 |
|
else |
| 331 |
|
ciq(dither,maxcolors,1,ourmap); |
| 332 |
< |
for (i = 0; i < 256; i++) { |
| 312 |
< |
rmap[i] = ourmap[0][i]; |
| 313 |
< |
gmap[i] = ourmap[1][i]; |
| 314 |
< |
bmap[i] = ourmap[2][i]; |
| 315 |
< |
} |
| 316 |
< |
if (init_rcolors(ourras, rmap, gmap, bmap) == 0) |
| 332 |
> |
if (init_rcolors(ourras, ourmap[0], ourmap[1], ourmap[2]) == 0) |
| 333 |
|
goto fail; |
| 334 |
|
} |
| 335 |
|
return; |
| 418 |
|
colval(cval,BLU)*comp); |
| 419 |
|
break; |
| 420 |
|
} |
| 421 |
< |
XDrawImageString(thedisplay, wind, ourgc, box.xmin, box.ymin, |
| 422 |
< |
buf, strlen(buf)); |
| 421 |
> |
XDrawImageString(thedisplay, wind, ourgc, |
| 422 |
> |
box.xmin, box.ymin+box.ysiz, buf, strlen(buf)); |
| 423 |
|
return(0); |
| 424 |
|
case 'i': /* identify (contour) */ |
| 425 |
|
if (ourras->pixels == NULL) |
| 459 |
|
scale_rcolors(ourras, pow(2.0, (double)n)); |
| 460 |
|
scale += n; |
| 461 |
|
sprintf(buf, "%+d", scale); |
| 462 |
< |
XDrawImageString(thedisplay, wind, ourgc, box.xmin, box.ymin, |
| 463 |
< |
buf, strlen(buf)); |
| 462 |
> |
XDrawImageString(thedisplay, wind, ourgc, |
| 463 |
> |
box.xmin, box.ymin+box.ysiz, buf, strlen(buf)); |
| 464 |
|
XFlush(thedisplay); |
| 465 |
|
free(ourdata); |
| 466 |
|
free_raster(ourras); |
| 489 |
|
XButtonPressedEvent *ebut; |
| 490 |
|
{ |
| 491 |
|
union { |
| 492 |
< |
XEvent u; |
| 493 |
< |
XButtonReleasedEvent b; |
| 494 |
< |
} e; |
| 492 |
> |
XEvent u; |
| 493 |
> |
XButtonReleasedEvent b; |
| 494 |
> |
XPointerMovedEvent m; |
| 495 |
> |
} e; |
| 496 |
> |
int mxo, myo; |
| 497 |
|
|
| 498 |
< |
XMaskEvent(thedisplay, ButtonReleaseMask, &e.u); |
| 498 |
> |
XMaskEvent(thedisplay, ButtonReleaseMask|ButtonMotionMask, &e.u); |
| 499 |
> |
while (e.u.type == MotionNotify) { |
| 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 |
> |
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; |
| 512 |
|
XClearWindow(thedisplay, wind); |
| 549 |
|
revbox(x0, y0, x1, y1) /* draw box with reversed lines */ |
| 550 |
|
int x0, y0, x1, y1; |
| 551 |
|
{ |
| 552 |
< |
static GC mygc = 0; |
| 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 |
|
|
| 525 |
– |
if (mygc == 0) { |
| 526 |
– |
mygc = XCreateGC(thedisplay, wind, 0, 0); |
| 527 |
– |
XSetFunction(thedisplay, mygc, GXinvert); |
| 528 |
– |
} |
| 529 |
– |
XDrawLine(thedisplay, wind, mygc, x0, y0, x1, y0); |
| 530 |
– |
XDrawLine(thedisplay, wind, mygc, x0, y1, x1, y1); |
| 531 |
– |
XDrawLine(thedisplay, wind, mygc, x0, y0, x0, y1); |
| 532 |
– |
XDrawLine(thedisplay, wind, mygc, x1, y0, x1, y1); |
| 533 |
– |
} /* end of revbox */ |
| 558 |
|
|
| 535 |
– |
|
| 559 |
|
avgbox(clr) /* average color over current box */ |
| 560 |
|
COLOR clr; |
| 561 |
|
{ |
| 601 |
|
register unsigned char *dp; |
| 602 |
|
register int x, err; |
| 603 |
|
int y; |
| 604 |
< |
rgbpixel *inline; |
| 604 |
> |
rgbpixel *inl; |
| 605 |
|
short *cerr; |
| 606 |
|
|
| 607 |
< |
if ((inline = (rgbpixel *)malloc(xmax*sizeof(rgbpixel))) == NULL |
| 607 |
> |
if ((inl = (rgbpixel *)malloc(xmax*sizeof(rgbpixel))) == NULL |
| 608 |
|
|| (cerr = (short *)calloc(xmax,sizeof(short))) == NULL) |
| 609 |
|
quit("out of memory in getmono"); |
| 610 |
|
dp = ourdata - 1; |
| 611 |
|
for (y = 0; y < ymax; y++) { |
| 612 |
< |
picreadline3(y, inline); |
| 612 |
> |
picreadline3(y, inl); |
| 613 |
|
err = 0; |
| 614 |
|
for (x = 0; x < xmax; x++) { |
| 615 |
|
if (!(x&7)) |
| 616 |
|
*++dp = 0; |
| 617 |
< |
err += rgb_bright(&inline[x]) + cerr[x]; |
| 617 |
> |
err += rgb_bright(&inl[x]) + cerr[x]; |
| 618 |
|
if (err > 127) |
| 619 |
|
err -= 255; |
| 620 |
|
else |
| 621 |
< |
*dp |= 1<<(x&07); |
| 621 |
> |
*dp |= 1<<(7-(x&07)); |
| 622 |
|
cerr[x] = err >>= 1; |
| 623 |
|
} |
| 624 |
|
} |
| 625 |
< |
free((char *)inline); |
| 625 |
> |
free((char *)inl); |
| 626 |
|
free((char *)cerr); |
| 627 |
|
} |
| 628 |
|
|