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 |
|
} |
211 |
|
if (wind == 0) |
212 |
|
quiterr("can't create window"); |
213 |
|
if (maxcolors == 0) { /* get number of available colors */ |
214 |
< |
maxcolors = 1<<DisplayPlanes(thedisplay,ourscreen); |
214 |
> |
i = DisplayPlanes(thedisplay,ourscreen); |
215 |
> |
maxcolors = i > 8 ? 256 : 1<<i; |
216 |
|
if (maxcolors > 4) maxcolors -= 2; |
217 |
|
} |
218 |
|
fontid = XLoadFont(thedisplay, FONTNAME); |
226 |
|
bzero((char *)&oursizhints, sizeof(oursizhints)); |
227 |
|
i = XParseGeometry(geometry, &oursizhints.x, &oursizhints.y, |
228 |
|
&oursizhints.width, &oursizhints.height); |
229 |
< |
if (i & (XValue|YValue) == (XValue|YValue)) { |
229 |
> |
if ((i&(WidthValue|HeightValue)) == (WidthValue|HeightValue)) |
230 |
> |
oursizhints.flags |= USSize; |
231 |
> |
else { |
232 |
> |
oursizhints.width = xmax; |
233 |
> |
oursizhints.height = ymax; |
234 |
> |
oursizhints.flags |= PSize; |
235 |
> |
} |
236 |
> |
if ((i&(XValue|YValue)) == (XValue|YValue)) { |
237 |
|
oursizhints.flags |= USPosition; |
238 |
|
if (i & XNegative) |
239 |
< |
oursizhints.x += DisplayWidth(thedisplay,ourscreen)-1; |
239 |
> |
oursizhints.x += DisplayWidth(thedisplay, |
240 |
> |
ourscreen)-1-oursizhints.width-2*BORWIDTH; |
241 |
|
if (i & YNegative) |
242 |
< |
oursizhints.y += DisplayHeight(thedisplay,ourscreen)-1; |
242 |
> |
oursizhints.y += DisplayHeight(thedisplay, |
243 |
> |
ourscreen)-1-oursizhints.height-2*BORWIDTH; |
244 |
|
} |
230 |
– |
if (i & (WidthValue|HeightValue) == (WidthValue|HeightValue)) |
231 |
– |
oursizhints.flags |= USSize; |
245 |
|
XSetNormalHints(thedisplay, wind, &oursizhints); |
246 |
|
} |
247 |
|
/* store image */ |
248 |
|
getras(); |
249 |
< |
XSelectInput(thedisplay, wind, ButtonPressMask|ButtonReleaseMask| |
250 |
< |
StructureNotifyMask|ButtonMotionMask| |
251 |
< |
KeyPressMask|ExposureMask); |
249 |
> |
XSelectInput(thedisplay, wind, ButtonPressMask|ButtonReleaseMask |
250 |
> |
|ButtonMotionMask|StructureNotifyMask |
251 |
> |
|KeyPressMask|ExposureMask); |
252 |
|
XMapWindow(thedisplay, wind); |
253 |
|
return; |
254 |
|
memerr: |
284 |
|
getras() /* get raster file */ |
285 |
|
{ |
286 |
|
colormap ourmap; |
274 |
– |
unsigned char rmap[256], gmap[256], bmap[256]; |
287 |
|
XVisualInfo vinfo; |
276 |
– |
register int i; |
288 |
|
|
289 |
|
if (maxcolors <= 2) { /* monochrome */ |
290 |
|
ourdata = (unsigned char *)malloc(ymax*((xmax+7)/8)); |
316 |
|
biq(dither,maxcolors,1,ourmap); |
317 |
|
else |
318 |
|
ciq(dither,maxcolors,1,ourmap); |
319 |
< |
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) |
319 |
> |
if (init_rcolors(ourras, ourmap[0], ourmap[1], ourmap[2]) == 0) |
320 |
|
goto fail; |
321 |
|
} |
322 |
|
return; |
365 |
|
} |
366 |
|
|
367 |
|
|
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 |
– |
|
368 |
|
docom(ekey) /* execute command */ |
369 |
|
XKeyPressedEvent *ekey; |
370 |
|
{ |
405 |
|
colval(cval,BLU)*comp); |
406 |
|
break; |
407 |
|
} |
408 |
< |
XDrawImageString(thedisplay, wind, ourgc, box.xmin, box.ymin, |
409 |
< |
buf, strlen(buf)); |
408 |
> |
XDrawImageString(thedisplay, wind, ourgc, |
409 |
> |
box.xmin, box.ymin+box.ysiz, buf, strlen(buf)); |
410 |
|
return(0); |
411 |
|
case 'i': /* identify (contour) */ |
412 |
|
if (ourras->pixels == NULL) |
417 |
|
cvx.red = random() & 65535; |
418 |
|
cvx.green = random() & 65535; |
419 |
|
cvx.blue = random() & 65535; |
420 |
< |
XStoreColors(thedisplay, ourras->cmap, &cvx, 1); |
420 |
> |
cvx.flags = DoRed|DoGreen|DoBlue; |
421 |
> |
XStoreColor(thedisplay, ourras->cmap, &cvx); |
422 |
|
return(0); |
423 |
|
case 'p': /* position */ |
424 |
|
sprintf(buf, "(%d,%d)", ekey->x-xoff, ymax-1-ekey->y+yoff); |
446 |
|
scale_rcolors(ourras, pow(2.0, (double)n)); |
447 |
|
scale += n; |
448 |
|
sprintf(buf, "%+d", scale); |
449 |
< |
XDrawImageString(thedisplay, wind, ourgc, box.xmin, box.ymin, |
450 |
< |
buf, strlen(buf)); |
449 |
> |
XDrawImageString(thedisplay, wind, ourgc, |
450 |
> |
box.xmin, box.ymin+box.ysiz, buf, strlen(buf)); |
451 |
|
XFlush(thedisplay); |
452 |
|
free(ourdata); |
453 |
|
free_raster(ourras); |
466 |
|
redraw(box.xmin, box.ymin, box.xsiz, box.ysiz); |
467 |
|
return(0); |
468 |
|
default: |
469 |
< |
XBell(0); |
469 |
> |
XBell(thedisplay, 0); |
470 |
|
return(-1); |
471 |
|
} |
472 |
|
} |
473 |
|
|
474 |
|
|
475 |
< |
moveimage(ep) /* shift the image */ |
476 |
< |
XButtonPressedEvent *ep; |
475 |
> |
moveimage(ebut) /* shift the image */ |
476 |
> |
XButtonPressedEvent *ebut; |
477 |
|
{ |
478 |
< |
XButtonPressedEvent eb; |
478 |
> |
union { |
479 |
> |
XEvent u; |
480 |
> |
XButtonReleasedEvent b; |
481 |
> |
XPointerMovedEvent m; |
482 |
> |
} e; |
483 |
> |
int nxo, nyo; |
484 |
|
|
485 |
< |
XMaskEvent(thedisplay, ButtonReleaseMask, &eb); |
486 |
< |
xoff += eb.x - ep->x; |
487 |
< |
yoff += eb.y - ep->y; |
485 |
> |
XMaskEvent(thedisplay, ButtonReleaseMask|ButtonMotionMask, &e.u); |
486 |
> |
while (e.u.type == MotionNotify) { |
487 |
> |
nxo = xoff + e.m.x - ebut->x; |
488 |
> |
nyo = yoff + e.m.y - ebut->y; |
489 |
> |
revbox(nxo, nyo, nxo+xmax, nyo+ymax); |
490 |
> |
XMaskEvent(thedisplay,ButtonReleaseMask|ButtonMotionMask,&e.u); |
491 |
> |
revbox(nxo, nyo, nxo+xmax, nyo+ymax); |
492 |
> |
} |
493 |
> |
xoff += e.b.x - ebut->x; |
494 |
> |
yoff += e.b.y - ebut->y; |
495 |
|
XClearWindow(thedisplay, wind); |
496 |
|
redraw(0, 0, width, height); |
486 |
– |
return(0); |
497 |
|
} |
498 |
|
|
499 |
|
|
501 |
|
XButtonPressedEvent *ebut; |
502 |
|
{ |
503 |
|
union { |
504 |
< |
XEvent e; |
504 |
> |
XEvent u; |
505 |
|
XButtonReleasedEvent b; |
506 |
|
XPointerMovedEvent m; |
507 |
|
} e; |
508 |
|
|
509 |
< |
XMaskEvent(thedisplay, ButtonReleaseMask|ButtonMotionMask, &e.e); |
510 |
< |
while (e.e.type == ButtonMotionMask) { |
509 |
> |
XMaskEvent(thedisplay, ButtonReleaseMask|ButtonMotionMask, &e.u); |
510 |
> |
while (e.u.type == MotionNotify) { |
511 |
|
revbox(ebut->x, ebut->y, box.xmin = e.m.x, box.ymin = e.m.y); |
512 |
< |
XMaskEvent(thedisplay, ButtonReleaseMask|ButtonMotionMask, |
503 |
< |
&e.e); |
512 |
> |
XMaskEvent(thedisplay,ButtonReleaseMask|ButtonMotionMask,&e.u); |
513 |
|
revbox(ebut->x, ebut->y, box.xmin, box.ymin); |
514 |
|
} |
515 |
|
box.xmin = e.b.x<0 ? 0 : (e.b.x>=width ? width-1 : e.b.x); |
536 |
|
|
537 |
|
if (mygc == 0) { |
538 |
|
mygc = XCreateGC(thedisplay, wind, 0, 0); |
530 |
– |
XSetPlaneMask(thedisplay, mygc, ~0L); |
539 |
|
XSetFunction(thedisplay, mygc, GXinvert); |
540 |
|
} |
541 |
|
XDrawLine(thedisplay, wind, mygc, x0, y0, x1, y0); |
607 |
|
if (err > 127) |
608 |
|
err -= 255; |
609 |
|
else |
610 |
< |
*dp |= 1<<(x&07); |
610 |
> |
*dp |= 1<<(7-(x&07)); |
611 |
|
cerr[x] = err >>= 1; |
612 |
|
} |
613 |
|
} |