| 43 |
|
#define ourroot RootWindow(thedisplay,ourscreen) |
| 44 |
|
#define ourgc DefaultGC(thedisplay,ourscreen) |
| 45 |
|
|
| 46 |
+ |
#define redraw(x,y,w,h) patch_raster(wind,(x)-xoff,(y)-yoff,x,y,w,h,ourras) |
| 47 |
+ |
|
| 48 |
|
double gamcor = 2.2; /* gamma correction */ |
| 49 |
|
|
| 50 |
|
int dither = 1; /* dither colors? */ |
| 53 |
|
Window wind = 0; /* our output window */ |
| 54 |
|
Font fontid; /* our font */ |
| 55 |
|
|
| 56 |
< |
long maxcolors = 0; /* maximum colors */ |
| 56 |
> |
int maxcolors = 0; /* maximum colors */ |
| 57 |
|
int greyscale = 0; /* in grey */ |
| 58 |
|
|
| 59 |
|
int scale = 0; /* scalefactor; power of two */ |
| 137 |
|
default: |
| 138 |
|
goto userr; |
| 139 |
|
} |
| 140 |
+ |
else if (argv[i][0] == '=') |
| 141 |
+ |
geometry = argv[i]; |
| 142 |
|
else |
| 143 |
|
break; |
| 144 |
|
|
| 145 |
< |
if (argc-i == 1) { |
| 145 |
> |
if (i == argc-1) { |
| 146 |
|
fname = argv[i]; |
| 147 |
|
fin = fopen(fname, "r"); |
| 148 |
|
if (fin == NULL) { |
| 149 |
|
sprintf(errmsg, "can't open file \"%s\"", fname); |
| 150 |
|
quiterr(errmsg); |
| 151 |
|
} |
| 152 |
< |
} |
| 152 |
> |
} else if (i != argc) |
| 153 |
> |
goto userr; |
| 154 |
|
/* get header */ |
| 155 |
|
getheader(fin, headline); |
| 156 |
|
/* get picture dimensions */ |
| 180 |
|
static char *altname[] = {"rview","rpict","pinterp",VIEWSTR,NULL}; |
| 181 |
|
register char **an; |
| 182 |
|
|
| 183 |
< |
if (!strncmp(s, "EXPOSURE=", 9)) |
| 184 |
< |
exposure *= atof(s+9); |
| 183 |
> |
if (isexpos(s)) |
| 184 |
> |
exposure *= exposval(s); |
| 185 |
|
else |
| 186 |
|
for (an = altname; *an != NULL; an++) |
| 187 |
|
if (!strncmp(*an, s, strlen(*an))) { |
| 188 |
< |
if (sscanview(&ourview, s+strlen(*an)) == 0) |
| 188 |
> |
if (sscanview(&ourview, s+strlen(*an)) > 0) |
| 189 |
|
gotview++; |
| 190 |
|
return; |
| 191 |
|
} |
| 194 |
|
|
| 195 |
|
init() /* get data and open window */ |
| 196 |
|
{ |
| 197 |
+ |
XSetWindowAttributes ourwinattr; |
| 198 |
|
XSizeHints oursizhints; |
| 199 |
|
register int i; |
| 200 |
|
|
| 207 |
|
} |
| 208 |
|
if ((thedisplay = XOpenDisplay(NULL)) == NULL) |
| 209 |
|
quiterr("can't open display; DISPLAY variable set?"); |
| 204 |
– |
wind = XCreateSimpleWindow(thedisplay, |
| 205 |
– |
ourroot, 0, 0, xmax, ymax, BORWIDTH, ourblack, ourwhite); |
| 206 |
– |
if (wind == 0) |
| 207 |
– |
quiterr("can't create window"); |
| 210 |
|
if (maxcolors == 0) { /* get number of available colors */ |
| 211 |
< |
maxcolors = 1<<DisplayPlanes(thedisplay,ourscreen); |
| 211 |
> |
i = DisplayPlanes(thedisplay,ourscreen); |
| 212 |
> |
maxcolors = i > 8 ? 256 : 1<<i; |
| 213 |
|
if (maxcolors > 4) maxcolors -= 2; |
| 214 |
|
} |
| 215 |
+ |
/* store image */ |
| 216 |
+ |
getras(); |
| 217 |
+ |
/* open window */ |
| 218 |
+ |
ourwinattr.border_pixel = ourblack; |
| 219 |
+ |
ourwinattr.background_pixel = ourwhite; |
| 220 |
+ |
wind = XCreateWindow(thedisplay, ourroot, 0, 0, xmax, ymax, BORWIDTH, |
| 221 |
+ |
0, InputOutput, ourras->visual, |
| 222 |
+ |
CWBackPixel|CWBorderPixel, &ourwinattr); |
| 223 |
+ |
if (wind == 0) |
| 224 |
+ |
quiterr("can't create window"); |
| 225 |
|
fontid = XLoadFont(thedisplay, FONTNAME); |
| 226 |
|
if (fontid == 0) |
| 227 |
|
quiterr("can't get font"); |
| 233 |
|
bzero((char *)&oursizhints, sizeof(oursizhints)); |
| 234 |
|
i = XParseGeometry(geometry, &oursizhints.x, &oursizhints.y, |
| 235 |
|
&oursizhints.width, &oursizhints.height); |
| 236 |
< |
if (i & (XValue|YValue) == (XValue|YValue)) { |
| 236 |
> |
if ((i&(WidthValue|HeightValue)) == (WidthValue|HeightValue)) |
| 237 |
> |
oursizhints.flags |= USSize; |
| 238 |
> |
else { |
| 239 |
> |
oursizhints.width = xmax; |
| 240 |
> |
oursizhints.height = ymax; |
| 241 |
> |
oursizhints.flags |= PSize; |
| 242 |
> |
} |
| 243 |
> |
if ((i&(XValue|YValue)) == (XValue|YValue)) { |
| 244 |
|
oursizhints.flags |= USPosition; |
| 245 |
|
if (i & XNegative) |
| 246 |
< |
oursizhints.x += DisplayWidth(thedisplay,ourscreen)-1; |
| 246 |
> |
oursizhints.x += DisplayWidth(thedisplay, |
| 247 |
> |
ourscreen)-1-oursizhints.width-2*BORWIDTH; |
| 248 |
|
if (i & YNegative) |
| 249 |
< |
oursizhints.y += DisplayHeight(thedisplay,ourscreen)-1; |
| 249 |
> |
oursizhints.y += DisplayHeight(thedisplay, |
| 250 |
> |
ourscreen)-1-oursizhints.height-2*BORWIDTH; |
| 251 |
|
} |
| 230 |
– |
if (i & (WidthValue|HeightValue) == (WidthValue|HeightValue)) |
| 231 |
– |
oursizhints.flags |= USSize; |
| 252 |
|
XSetNormalHints(thedisplay, wind, &oursizhints); |
| 253 |
|
} |
| 254 |
< |
/* store image */ |
| 255 |
< |
getras(); |
| 256 |
< |
XSelectInput(thedisplay, wind, ButtonPressMask|ButtonReleaseMask| |
| 237 |
< |
StructureNotifyMask|ButtonMotionMask| |
| 238 |
< |
KeyPressMask|ExposureMask); |
| 254 |
> |
XSelectInput(thedisplay, wind, ButtonPressMask|ButtonReleaseMask |
| 255 |
> |
|ButtonMotionMask|StructureNotifyMask |
| 256 |
> |
|KeyPressMask|ExposureMask); |
| 257 |
|
XMapWindow(thedisplay, wind); |
| 258 |
|
return; |
| 259 |
|
memerr: |
| 289 |
|
getras() /* get raster file */ |
| 290 |
|
{ |
| 291 |
|
colormap ourmap; |
| 274 |
– |
unsigned char rmap[256], gmap[256], bmap[256]; |
| 292 |
|
XVisualInfo vinfo; |
| 276 |
– |
register int i; |
| 293 |
|
|
| 294 |
|
if (maxcolors <= 2) { /* monochrome */ |
| 295 |
|
ourdata = (unsigned char *)malloc(ymax*((xmax+7)/8)); |
| 321 |
|
biq(dither,maxcolors,1,ourmap); |
| 322 |
|
else |
| 323 |
|
ciq(dither,maxcolors,1,ourmap); |
| 324 |
< |
for (i = 0; i < 256; i++) { |
| 309 |
< |
rmap[i] = ourmap[0][i]; |
| 310 |
< |
gmap[i] = ourmap[1][i]; |
| 311 |
< |
bmap[i] = ourmap[2][i]; |
| 312 |
< |
} |
| 313 |
< |
if (init_rcolors(ourras, rmap, gmap, bmap) == 0) |
| 324 |
> |
if (init_rcolors(ourras, ourmap[0], ourmap[1], ourmap[2]) == 0) |
| 325 |
|
goto fail; |
| 326 |
|
} |
| 327 |
|
return; |
| 370 |
|
} |
| 371 |
|
|
| 372 |
|
|
| 362 |
– |
redraw(x, y, w, h) /* redraw section of window */ |
| 363 |
– |
int x, y; |
| 364 |
– |
int w, h; |
| 365 |
– |
{ |
| 366 |
– |
patch_raster(wind,x-xoff,y-yoff,x,y,w,h,ourras); |
| 367 |
– |
} |
| 368 |
– |
|
| 369 |
– |
|
| 373 |
|
docom(ekey) /* execute command */ |
| 374 |
|
XKeyPressedEvent *ekey; |
| 375 |
|
{ |
| 410 |
|
colval(cval,BLU)*comp); |
| 411 |
|
break; |
| 412 |
|
} |
| 413 |
< |
XDrawImageString(thedisplay, wind, ourgc, box.xmin, box.ymin, |
| 414 |
< |
buf, strlen(buf)); |
| 413 |
> |
XDrawImageString(thedisplay, wind, ourgc, |
| 414 |
> |
box.xmin, box.ymin+box.ysiz, buf, strlen(buf)); |
| 415 |
|
return(0); |
| 416 |
|
case 'i': /* identify (contour) */ |
| 417 |
|
if (ourras->pixels == NULL) |
| 422 |
|
cvx.red = random() & 65535; |
| 423 |
|
cvx.green = random() & 65535; |
| 424 |
|
cvx.blue = random() & 65535; |
| 425 |
< |
XStoreColors(thedisplay, ourras->cmap, &cvx, 1); |
| 425 |
> |
cvx.flags = DoRed|DoGreen|DoBlue; |
| 426 |
> |
XStoreColor(thedisplay, ourras->cmap, &cvx); |
| 427 |
|
return(0); |
| 428 |
|
case 'p': /* position */ |
| 429 |
|
sprintf(buf, "(%d,%d)", ekey->x-xoff, ymax-1-ekey->y+yoff); |
| 451 |
|
scale_rcolors(ourras, pow(2.0, (double)n)); |
| 452 |
|
scale += n; |
| 453 |
|
sprintf(buf, "%+d", scale); |
| 454 |
< |
XDrawImageString(thedisplay, wind, ourgc, box.xmin, box.ymin, |
| 455 |
< |
buf, strlen(buf)); |
| 454 |
> |
XDrawImageString(thedisplay, wind, ourgc, |
| 455 |
> |
box.xmin, box.ymin+box.ysiz, buf, strlen(buf)); |
| 456 |
|
XFlush(thedisplay); |
| 457 |
|
free(ourdata); |
| 458 |
|
free_raster(ourras); |
| 471 |
|
redraw(box.xmin, box.ymin, box.xsiz, box.ysiz); |
| 472 |
|
return(0); |
| 473 |
|
default: |
| 474 |
< |
XBell(0); |
| 474 |
> |
XBell(thedisplay, 0); |
| 475 |
|
return(-1); |
| 476 |
|
} |
| 477 |
|
} |
| 478 |
|
|
| 479 |
|
|
| 480 |
< |
moveimage(ep) /* shift the image */ |
| 481 |
< |
XButtonPressedEvent *ep; |
| 480 |
> |
moveimage(ebut) /* shift the image */ |
| 481 |
> |
XButtonPressedEvent *ebut; |
| 482 |
|
{ |
| 483 |
< |
XButtonPressedEvent eb; |
| 483 |
> |
union { |
| 484 |
> |
XEvent u; |
| 485 |
> |
XButtonReleasedEvent b; |
| 486 |
> |
XPointerMovedEvent m; |
| 487 |
> |
} e; |
| 488 |
> |
int nxo, nyo; |
| 489 |
|
|
| 490 |
< |
XMaskEvent(thedisplay, ButtonReleaseMask, &eb); |
| 491 |
< |
xoff += eb.x - ep->x; |
| 492 |
< |
yoff += eb.y - ep->y; |
| 490 |
> |
XMaskEvent(thedisplay, ButtonReleaseMask|ButtonMotionMask, &e.u); |
| 491 |
> |
while (e.u.type == MotionNotify) { |
| 492 |
> |
nxo = xoff + e.m.x - ebut->x; |
| 493 |
> |
nyo = yoff + e.m.y - ebut->y; |
| 494 |
> |
revbox(nxo, nyo, nxo+xmax, nyo+ymax); |
| 495 |
> |
XMaskEvent(thedisplay,ButtonReleaseMask|ButtonMotionMask,&e.u); |
| 496 |
> |
revbox(nxo, nyo, nxo+xmax, nyo+ymax); |
| 497 |
> |
} |
| 498 |
> |
xoff += e.b.x - ebut->x; |
| 499 |
> |
yoff += e.b.y - ebut->y; |
| 500 |
|
XClearWindow(thedisplay, wind); |
| 501 |
|
redraw(0, 0, width, height); |
| 486 |
– |
return(0); |
| 502 |
|
} |
| 503 |
|
|
| 504 |
|
|
| 506 |
|
XButtonPressedEvent *ebut; |
| 507 |
|
{ |
| 508 |
|
union { |
| 509 |
< |
XEvent e; |
| 509 |
> |
XEvent u; |
| 510 |
|
XButtonReleasedEvent b; |
| 511 |
|
XPointerMovedEvent m; |
| 512 |
|
} e; |
| 513 |
|
|
| 514 |
< |
XMaskEvent(thedisplay, ButtonReleaseMask|ButtonMotionMask, &e.e); |
| 515 |
< |
while (e.e.type == ButtonMotionMask) { |
| 514 |
> |
XMaskEvent(thedisplay, ButtonReleaseMask|ButtonMotionMask, &e.u); |
| 515 |
> |
while (e.u.type == MotionNotify) { |
| 516 |
|
revbox(ebut->x, ebut->y, box.xmin = e.m.x, box.ymin = e.m.y); |
| 517 |
< |
XMaskEvent(thedisplay, ButtonReleaseMask|ButtonMotionMask, |
| 503 |
< |
&e.e); |
| 517 |
> |
XMaskEvent(thedisplay,ButtonReleaseMask|ButtonMotionMask,&e.u); |
| 518 |
|
revbox(ebut->x, ebut->y, box.xmin, box.ymin); |
| 519 |
|
} |
| 520 |
|
box.xmin = e.b.x<0 ? 0 : (e.b.x>=width ? width-1 : e.b.x); |
| 541 |
|
|
| 542 |
|
if (mygc == 0) { |
| 543 |
|
mygc = XCreateGC(thedisplay, wind, 0, 0); |
| 530 |
– |
XSetPlaneMask(thedisplay, mygc, ~0L); |
| 544 |
|
XSetFunction(thedisplay, mygc, GXinvert); |
| 545 |
|
} |
| 546 |
|
XDrawLine(thedisplay, wind, mygc, x0, y0, x1, y0); |
| 612 |
|
if (err > 127) |
| 613 |
|
err -= 255; |
| 614 |
|
else |
| 615 |
< |
*dp |= 1<<(x&07); |
| 615 |
> |
*dp |= 1<<(7-(x&07)); |
| 616 |
|
cerr[x] = err >>= 1; |
| 617 |
|
} |
| 618 |
|
} |