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 */ |
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?"); |
206 |
– |
wind = XCreateSimpleWindow(thedisplay, |
207 |
– |
ourroot, 0, 0, xmax, ymax, BORWIDTH, ourblack, ourwhite); |
208 |
– |
if (wind == 0) |
209 |
– |
quiterr("can't create window"); |
210 |
|
if (maxcolors == 0) { /* get number of available colors */ |
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 |
|
} |
233 |
– |
if (i & (WidthValue|HeightValue) == (WidthValue|HeightValue)) |
234 |
– |
oursizhints.flags |= USSize; |
252 |
|
XSetNormalHints(thedisplay, wind, &oursizhints); |
253 |
|
} |
237 |
– |
/* store image */ |
238 |
– |
getras(); |
254 |
|
XSelectInput(thedisplay, wind, ButtonPressMask|ButtonReleaseMask |
255 |
|
|ButtonMotionMask|StructureNotifyMask |
256 |
|
|KeyPressMask|ExposureMask); |
289 |
|
getras() /* get raster file */ |
290 |
|
{ |
291 |
|
colormap ourmap; |
277 |
– |
unsigned char rmap[256], gmap[256], bmap[256]; |
292 |
|
XVisualInfo vinfo; |
279 |
– |
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++) { |
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) |
324 |
> |
if (init_rcolors(ourras, ourmap[0], ourmap[1], ourmap[2]) == 0) |
325 |
|
goto fail; |
326 |
|
} |
327 |
|
return; |
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) |
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); |
481 |
|
XButtonPressedEvent *ebut; |
482 |
|
{ |
483 |
|
union { |
484 |
< |
XEvent u; |
485 |
< |
XButtonReleasedEvent b; |
486 |
< |
} e; |
484 |
> |
XEvent u; |
485 |
> |
XButtonReleasedEvent b; |
486 |
> |
XPointerMovedEvent m; |
487 |
> |
} e; |
488 |
> |
int nxo, nyo; |
489 |
|
|
490 |
< |
XMaskEvent(thedisplay, ButtonReleaseMask, &e.u); |
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); |
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 |
|
} |