1 |
< |
/* Copyright (c) 1992 Regents of the University of California */ |
1 |
> |
/* Copyright (c) 1993 Regents of the University of California */ |
2 |
|
|
3 |
|
#ifndef lint |
4 |
|
static char SCCSid[] = "$SunId$ LBL"; |
21 |
|
|
22 |
|
#include "standard.h" |
23 |
|
|
24 |
+ |
#include <signal.h> |
25 |
|
#include <X11/Xlib.h> |
26 |
|
#include <X11/cursorfont.h> |
27 |
|
#include <X11/Xutil.h> |
28 |
+ |
#include <X11/Xatom.h> |
29 |
|
|
30 |
|
#include "color.h" |
31 |
|
#include "view.h" |
33 |
|
#include "random.h" |
34 |
|
#include "resolu.h" |
35 |
|
|
36 |
+ |
#ifdef __alpha |
37 |
+ |
#define int4 int |
38 |
+ |
#endif |
39 |
+ |
#ifndef int4 |
40 |
+ |
#define int4 long |
41 |
+ |
#endif |
42 |
+ |
|
43 |
|
#define FONTNAME "8x13" /* text font we'll use */ |
44 |
|
|
45 |
|
#define CTRL(c) ((c)-'@') |
64 |
|
|
65 |
|
Window wind = 0; /* our output window */ |
66 |
|
unsigned long ourblack=0, ourwhite=1; /* black and white for this visual */ |
58 |
– |
Font fontid; /* our font */ |
59 |
– |
|
67 |
|
int maxcolors = 0; /* maximum colors */ |
68 |
|
int greyscale = 0; /* in grey */ |
69 |
|
|
72 |
|
int xoff = 0; /* x image offset */ |
73 |
|
int yoff = 0; /* y image offset */ |
74 |
|
|
75 |
+ |
int parent = 0; /* number of children, -1 if child */ |
76 |
+ |
|
77 |
|
VIEW ourview = STDVIEW; /* image view parameters */ |
78 |
|
int gotview = 0; /* got parameters from file */ |
79 |
|
|
116 |
|
|
117 |
|
extern long ftell(); |
118 |
|
|
110 |
– |
extern char *malloc(), *calloc(); |
111 |
– |
|
119 |
|
Display *thedisplay; |
120 |
+ |
Atom closedownAtom, wmProtocolsAtom; |
121 |
|
|
122 |
+ |
int noop() {} |
123 |
|
|
124 |
+ |
|
125 |
|
main(argc, argv) |
126 |
|
int argc; |
127 |
|
char *argv[]; |
130 |
|
char *gv; |
131 |
|
int headline(); |
132 |
|
int i; |
133 |
+ |
int pid; |
134 |
|
|
135 |
|
progname = argv[0]; |
136 |
|
if ((gv = getenv("GAMMA")) != NULL) |
176 |
|
else |
177 |
|
break; |
178 |
|
|
179 |
< |
if (i == argc-1) { |
179 |
> |
if (i > argc) |
180 |
> |
goto userr; |
181 |
> |
while (i < argc-1) { |
182 |
> |
if ((pid=fork()) == 0) { /* a child for each picture */ |
183 |
> |
parent = -1; |
184 |
> |
break; |
185 |
> |
} |
186 |
> |
if (pid < 0) |
187 |
> |
quiterr("fork failed"); |
188 |
> |
parent++; |
189 |
> |
signal(SIGCONT, noop); |
190 |
> |
pause(); /* wait for wake-up call */ |
191 |
> |
i++; |
192 |
> |
} |
193 |
> |
if (i < argc) { /* open picture file */ |
194 |
|
fname = argv[i]; |
195 |
|
fin = fopen(fname, "r"); |
196 |
|
if (fin == NULL) { |
197 |
|
sprintf(errmsg, "cannot open file \"%s\"", fname); |
198 |
|
quiterr(errmsg); |
199 |
|
} |
200 |
< |
} else if (i != argc) |
176 |
< |
goto userr; |
200 |
> |
} |
201 |
|
/* get header */ |
202 |
|
getheader(fin, headline, NULL); |
203 |
|
/* get picture dimensions */ |
211 |
|
if ((scanline = (COLR *)malloc(xmax*sizeof(COLR))) == NULL) |
212 |
|
quiterr("out of memory"); |
213 |
|
|
214 |
< |
init(); /* get file and open window */ |
214 |
> |
init(argc, argv); /* get file and open window */ |
215 |
|
|
216 |
+ |
if (parent < 0) |
217 |
+ |
kill(getppid(), SIGCONT); /* signal parent if child */ |
218 |
+ |
|
219 |
|
for ( ; ; ) |
220 |
|
getevent(); /* main loop */ |
221 |
|
userr: |
222 |
|
fprintf(stderr, |
223 |
< |
"Usage: %s [-display disp][-geometry spec][-b][-m][-d][-f][-c ncolors][-e +/-stops] file\n", |
223 |
> |
"Usage: %s [-di disp][[-ge] spec][-b][-m][-d][-f][-c nclrs][-e +/-stops] pic ..\n", |
224 |
|
progname); |
225 |
< |
quit(1); |
225 |
> |
exit(1); |
226 |
|
} |
227 |
|
|
228 |
|
|
241 |
|
} |
242 |
|
|
243 |
|
|
244 |
< |
init() /* get data and open window */ |
244 |
> |
init(argc, argv) /* get data and open window */ |
245 |
> |
int argc; |
246 |
> |
char **argv; |
247 |
|
{ |
219 |
– |
XWMHints ourxwmhints; |
248 |
|
XSetWindowAttributes ourwinattr; |
249 |
< |
XSizeHints oursizhints; |
249 |
> |
XClassHint xclshints; |
250 |
> |
XWMHints xwmhints; |
251 |
> |
XSizeHints xszhints; |
252 |
> |
XTextProperty windowName, iconName; |
253 |
> |
XGCValues xgcv; |
254 |
> |
char *name; |
255 |
|
register int i; |
256 |
|
|
257 |
|
if (fname != NULL) { |
258 |
|
scanpos = (long *)malloc(ymax*sizeof(long)); |
259 |
|
if (scanpos == NULL) |
260 |
< |
goto memerr; |
260 |
> |
quiterr("out of memory"); |
261 |
|
for (i = 0; i < ymax; i++) |
262 |
|
scanpos[i] = -1; |
263 |
< |
} |
263 |
> |
name = fname; |
264 |
> |
} else |
265 |
> |
name = progname; |
266 |
> |
/* remove directory prefix from name */ |
267 |
> |
for (i = strlen(name); i-- > 0; ) |
268 |
> |
if (name[i] == '/') |
269 |
> |
break; |
270 |
> |
name += i+1; |
271 |
|
if ((thedisplay = XOpenDisplay(dispname)) == NULL) |
272 |
|
quiterr("cannot open display"); |
273 |
|
/* get best visual for default screen */ |
274 |
|
getbestvis(); |
275 |
|
/* store image */ |
276 |
|
getras(); |
277 |
< |
/* open window */ |
278 |
< |
ourwinattr.border_pixel = ourblack; |
279 |
< |
ourwinattr.background_pixel = ourwhite; |
240 |
< |
ourwinattr.colormap = XCreateColormap(thedisplay, ourroot, |
241 |
< |
ourvis.visual, AllocNone); |
242 |
< |
wind = XCreateWindow(thedisplay, ourroot, 0, 0, xmax, ymax, BORWIDTH, |
243 |
< |
ourvis.depth, InputOutput, ourvis.visual, |
244 |
< |
CWBackPixel|CWBorderPixel|CWColormap, &ourwinattr); |
245 |
< |
if (wind == 0) |
246 |
< |
quiterr("cannot create window"); |
247 |
< |
XFreeColormap(thedisplay, ourwinattr.colormap); |
248 |
< |
width = xmax; |
249 |
< |
height = ymax; |
250 |
< |
ourgc = XCreateGC(thedisplay, wind, 0, 0); |
251 |
< |
XSetState(thedisplay, ourgc, ourblack, ourwhite, GXcopy, AllPlanes); |
252 |
< |
revgc = XCreateGC(thedisplay, wind, 0, 0); |
253 |
< |
XSetFunction(thedisplay, revgc, GXinvert); |
254 |
< |
fontid = XLoadFont(thedisplay, FONTNAME); |
255 |
< |
if (fontid == 0) |
256 |
< |
quiterr("cannot get font"); |
257 |
< |
XSetFont(thedisplay, ourgc, fontid); |
258 |
< |
XDefineCursor(thedisplay, wind, XCreateFontCursor(thedisplay, |
259 |
< |
XC_diamond_cross)); |
260 |
< |
XStoreName(thedisplay, wind, fname == NULL ? progname : fname); |
277 |
> |
/* get size and position */ |
278 |
> |
xszhints.flags = 0; |
279 |
> |
xszhints.width = xmax; xszhints.height = ymax; |
280 |
|
if (geometry != NULL) { |
281 |
< |
bzero((char *)&oursizhints, sizeof(oursizhints)); |
282 |
< |
i = XParseGeometry(geometry, &oursizhints.x, &oursizhints.y, |
283 |
< |
(unsigned *)&oursizhints.width, |
265 |
< |
(unsigned *)&oursizhints.height); |
281 |
> |
i = XParseGeometry(geometry, &xszhints.x, &xszhints.y, |
282 |
> |
(unsigned *)&xszhints.width, |
283 |
> |
(unsigned *)&xszhints.height); |
284 |
|
if ((i&(WidthValue|HeightValue)) == (WidthValue|HeightValue)) |
285 |
< |
oursizhints.flags |= USSize; |
286 |
< |
else { |
287 |
< |
oursizhints.width = xmax; |
270 |
< |
oursizhints.height = ymax; |
271 |
< |
oursizhints.flags |= PSize; |
272 |
< |
} |
285 |
> |
xszhints.flags |= USSize; |
286 |
> |
else |
287 |
> |
xszhints.flags |= PSize; |
288 |
|
if ((i&(XValue|YValue)) == (XValue|YValue)) { |
289 |
< |
oursizhints.flags |= USPosition; |
289 |
> |
xszhints.flags |= USPosition; |
290 |
|
if (i & XNegative) |
291 |
< |
oursizhints.x += DisplayWidth(thedisplay, |
292 |
< |
ourscreen)-1-oursizhints.width-2*BORWIDTH; |
291 |
> |
xszhints.x += DisplayWidth(thedisplay, |
292 |
> |
ourscreen)-1-xszhints.width-2*BORWIDTH; |
293 |
|
if (i & YNegative) |
294 |
< |
oursizhints.y += DisplayHeight(thedisplay, |
295 |
< |
ourscreen)-1-oursizhints.height-2*BORWIDTH; |
294 |
> |
xszhints.y += DisplayHeight(thedisplay, |
295 |
> |
ourscreen)-1-xszhints.height-2*BORWIDTH; |
296 |
|
} |
282 |
– |
XSetNormalHints(thedisplay, wind, &oursizhints); |
297 |
|
} |
298 |
< |
ourxwmhints.flags = InputHint|IconPixmapHint; |
299 |
< |
ourxwmhints.input = True; |
300 |
< |
ourxwmhints.icon_pixmap = XCreateBitmapFromData(thedisplay, |
298 |
> |
/* open window */ |
299 |
> |
ourwinattr.border_pixel = ourwhite; |
300 |
> |
ourwinattr.background_pixel = ourblack; |
301 |
> |
ourwinattr.colormap = XCreateColormap(thedisplay, ourroot, |
302 |
> |
ourvis.visual, AllocNone); |
303 |
> |
ourwinattr.event_mask = ExposureMask|KeyPressMask|ButtonPressMask| |
304 |
> |
ButtonReleaseMask|ButtonMotionMask|StructureNotifyMask; |
305 |
> |
ourwinattr.cursor = XCreateFontCursor(thedisplay, XC_diamond_cross); |
306 |
> |
wind = XCreateWindow(thedisplay, ourroot, xszhints.x, xszhints.y, |
307 |
> |
xszhints.width, xszhints.height, BORWIDTH, |
308 |
> |
ourvis.depth, InputOutput, ourvis.visual, CWEventMask| |
309 |
> |
CWCursor|CWBackPixel|CWBorderPixel|CWColormap, &ourwinattr); |
310 |
> |
if (wind == 0) |
311 |
> |
quiterr("cannot create window"); |
312 |
> |
width = xmax; |
313 |
> |
height = ymax; |
314 |
> |
xgcv.foreground = ourblack; |
315 |
> |
xgcv.background = ourwhite; |
316 |
> |
if ((xgcv.font = XLoadFont(thedisplay, FONTNAME)) == 0) |
317 |
> |
quiterr("cannot get font"); |
318 |
> |
ourgc = XCreateGC(thedisplay, wind, GCForeground|GCBackground| |
319 |
> |
GCFont, &xgcv); |
320 |
> |
xgcv.function = GXinvert; |
321 |
> |
revgc = XCreateGC(thedisplay, wind, GCForeground|GCBackground| |
322 |
> |
GCFunction, &xgcv); |
323 |
> |
|
324 |
> |
/* set up the window manager */ |
325 |
> |
xwmhints.flags = InputHint|IconPixmapHint; |
326 |
> |
xwmhints.input = True; |
327 |
> |
xwmhints.icon_pixmap = XCreateBitmapFromData(thedisplay, |
328 |
|
wind, icondata, iconwidth, iconheight); |
329 |
< |
XSetWMHints(thedisplay, wind, &ourxwmhints); |
330 |
< |
XSelectInput(thedisplay, wind, ButtonPressMask|ButtonReleaseMask |
331 |
< |
|ButtonMotionMask|StructureNotifyMask |
332 |
< |
|KeyPressMask|ExposureMask); |
329 |
> |
|
330 |
> |
windowName.encoding = iconName.encoding = XA_STRING; |
331 |
> |
windowName.format = iconName.format = 8; |
332 |
> |
windowName.value = (u_char *)name; |
333 |
> |
windowName.nitems = strlen(windowName.value); |
334 |
> |
iconName.value = (u_char *)name; |
335 |
> |
iconName.nitems = strlen(windowName.value); |
336 |
> |
|
337 |
> |
xclshints.res_name = NULL; |
338 |
> |
xclshints.res_class = "Ximage"; |
339 |
> |
XSetWMProperties(thedisplay, wind, &windowName, &iconName, |
340 |
> |
argv, argc, &xszhints, &xwmhints, &xclshints); |
341 |
> |
closedownAtom = XInternAtom(thedisplay, "WM_DELETE_WINDOW", False); |
342 |
> |
wmProtocolsAtom = XInternAtom(thedisplay, "WM_PROTOCOLS", False); |
343 |
> |
XSetWMProtocols(thedisplay, wind, &closedownAtom, 1); |
344 |
> |
|
345 |
|
XMapWindow(thedisplay, wind); |
346 |
|
return; |
294 |
– |
memerr: |
295 |
– |
quiterr("out of memory"); |
347 |
|
} /* end of init */ |
348 |
|
|
349 |
|
|
350 |
|
quiterr(err) /* print message and exit */ |
351 |
|
char *err; |
352 |
|
{ |
353 |
< |
if (err != NULL) { |
354 |
< |
fprintf(stderr, "%s: %s\n", progname, err); |
355 |
< |
exit(1); |
353 |
> |
register int es; |
354 |
> |
int cs; |
355 |
> |
|
356 |
> |
if (es = err != NULL) |
357 |
> |
fprintf(stderr, "%s: %s: %s\n", progname, |
358 |
> |
fname==NULL?"<stdin>":fname, err); |
359 |
> |
if (parent > 0 & wind != 0) { |
360 |
> |
XDestroyWindow(thedisplay, wind); |
361 |
> |
XFlush(thedisplay); |
362 |
|
} |
363 |
< |
exit(0); |
363 |
> |
while (parent > 0 && wait(&cs) != -1) { /* wait for any children */ |
364 |
> |
if (es == 0) |
365 |
> |
es = cs>>8 & 0xff; |
366 |
> |
parent--; |
367 |
> |
} |
368 |
> |
exit(es); |
369 |
|
} |
370 |
|
|
371 |
|
|
506 |
|
goto fail; |
507 |
|
getmono(); |
508 |
|
} else if (ourvis.class == TrueColor | ourvis.class == DirectColor) { |
509 |
< |
ourdata = (unsigned char *)malloc(4*xmax*ymax); |
509 |
> |
ourdata = (unsigned char *)malloc(sizeof(int4)*xmax*ymax); |
510 |
|
if (ourdata == NULL) |
511 |
|
goto fail; |
512 |
< |
ourras = make_raster(thedisplay, &ourvis, 32, |
512 |
> |
ourras = make_raster(thedisplay, &ourvis, sizeof(int4)*8, |
513 |
|
ourdata, xmax, ymax, 32); |
514 |
|
if (ourras == NULL) |
515 |
|
goto fail; |
537 |
|
|
538 |
|
getevent() /* process the next event */ |
539 |
|
{ |
540 |
< |
union { |
479 |
< |
XEvent u; |
480 |
< |
XConfigureEvent c; |
481 |
< |
XExposeEvent e; |
482 |
< |
XButtonPressedEvent b; |
483 |
< |
XKeyPressedEvent k; |
484 |
< |
} e; |
540 |
> |
XEvent xev; |
541 |
|
|
542 |
< |
XNextEvent(thedisplay, &e.u); |
543 |
< |
switch (e.u.type) { |
542 |
> |
XNextEvent(thedisplay, &xev); |
543 |
> |
switch ((int)xev.type) { |
544 |
|
case KeyPress: |
545 |
< |
docom(&e.k); |
545 |
> |
docom(&xev.xkey); |
546 |
|
break; |
547 |
|
case ConfigureNotify: |
548 |
< |
width = e.c.width; |
549 |
< |
height = e.c.height; |
548 |
> |
width = xev.xconfigure.width; |
549 |
> |
height = xev.xconfigure.height; |
550 |
|
break; |
551 |
|
case MapNotify: |
552 |
|
map_rcolors(ourras, wind); |
558 |
|
unmap_rcolors(ourras); |
559 |
|
break; |
560 |
|
case Expose: |
561 |
< |
redraw(e.e.x, e.e.y, e.e.width, e.e.height); |
561 |
> |
redraw(xev.xexpose.x, xev.xexpose.y, |
562 |
> |
xev.xexpose.width, xev.xexpose.height); |
563 |
|
break; |
564 |
|
case ButtonPress: |
565 |
< |
if (e.b.state & (ShiftMask|ControlMask)) |
566 |
< |
moveimage(&e.b); |
565 |
> |
if (xev.xbutton.state & (ShiftMask|ControlMask)) |
566 |
> |
moveimage(&xev.xbutton); |
567 |
> |
else if (xev.xbutton.button == Button2) |
568 |
> |
traceray(xev.xbutton.x, xev.xbutton.y); |
569 |
|
else |
570 |
< |
getbox(&e.b); |
570 |
> |
getbox(&xev.xbutton); |
571 |
|
break; |
572 |
+ |
case ClientMessage: |
573 |
+ |
if ((xev.xclient.message_type == wmProtocolsAtom) && |
574 |
+ |
(xev.xclient.data.l[0] == closedownAtom)) |
575 |
+ |
quiterr(NULL); |
576 |
+ |
break; |
577 |
|
} |
578 |
|
} |
579 |
|
|
580 |
|
|
581 |
< |
docom(ekey) /* execute command */ |
581 |
> |
traceray(xpos, ypos) /* print ray corresponding to pixel */ |
582 |
> |
int xpos, ypos; |
583 |
> |
{ |
584 |
> |
FLOAT hv[2]; |
585 |
> |
FVECT rorg, rdir; |
586 |
> |
|
587 |
> |
if (!gotview) { /* no view, no can do */ |
588 |
> |
XBell(thedisplay, 0); |
589 |
> |
return(-1); |
590 |
> |
} |
591 |
> |
pix2loc(hv, &inpres, xpos-xoff, ypos-yoff); |
592 |
> |
if (viewray(rorg, rdir, &ourview, hv[0], hv[1]) < 0) |
593 |
> |
return(-1); |
594 |
> |
printf("%e %e %e ", rorg[0], rorg[1], rorg[2]); |
595 |
> |
printf("%e %e %e\n", rdir[0], rdir[1], rdir[2]); |
596 |
> |
fflush(stdout); |
597 |
> |
return(0); |
598 |
> |
} |
599 |
> |
|
600 |
> |
|
601 |
> |
docom(ekey) /* execute command */ |
602 |
|
XKeyPressedEvent *ekey; |
603 |
|
{ |
604 |
|
char buf[80]; |
607 |
|
int com, n; |
608 |
|
double comp; |
609 |
|
FLOAT hv[2]; |
526 |
– |
FVECT rorg, rdir; |
610 |
|
|
611 |
|
n = XLookupString(ekey, buf, sizeof(buf), NULL, NULL); |
612 |
|
if (n == 0) |
614 |
|
com = buf[0]; |
615 |
|
switch (com) { /* interpret command */ |
616 |
|
case 'q': |
617 |
+ |
case 'Q': |
618 |
|
case CTRL('D'): /* quit */ |
619 |
< |
quit(0); |
619 |
> |
quiterr(NULL); |
620 |
|
case '\n': |
621 |
|
case '\r': |
622 |
|
case 'l': |
662 |
|
buf, strlen(buf)); |
663 |
|
return(0); |
664 |
|
case 't': /* trace */ |
665 |
< |
if (!gotview) { |
582 |
< |
XBell(thedisplay, 0); |
583 |
< |
return(-1); |
584 |
< |
} |
585 |
< |
pix2loc(hv, &inpres, ekey->x-xoff, ekey->y-yoff); |
586 |
< |
if (viewray(rorg, rdir, &ourview, hv[0], hv[1]) < 0) |
587 |
< |
return(-1); |
588 |
< |
printf("%e %e %e ", rorg[0], rorg[1], rorg[2]); |
589 |
< |
printf("%e %e %e\n", rdir[0], rdir[1], rdir[2]); |
590 |
< |
fflush(stdout); |
591 |
< |
return(0); |
665 |
> |
return(traceray(ekey->x, ekey->y)); |
666 |
|
case '=': /* adjust exposure */ |
667 |
+ |
case '@': /* adaptation level */ |
668 |
|
if (avgbox(cval) == -1) |
669 |
|
return(-1); |
670 |
< |
n = log(.5/bright(cval))/.69315 - scale; /* truncate */ |
670 |
> |
comp = com=='@' |
671 |
> |
? 106./pow(1.219+pow(luminance(cval)/exposure,.4),2.5)/exposure |
672 |
> |
: .5/bright(cval) ; |
673 |
> |
comp = log(comp)/.69315 - scale; |
674 |
> |
n = comp < 0 ? comp-.5 : comp+.5 ; /* round */ |
675 |
|
if (n == 0) |
676 |
|
return(0); |
677 |
|
scale_rcolors(ourras, pow(2.0, (double)n)); |
693 |
|
make_rpixmap(ourras, wind); |
694 |
|
redraw(0, 0, width, height); |
695 |
|
return(0); |
696 |
+ |
case 'f': /* turn on fast redraw */ |
697 |
+ |
fast = 1; |
698 |
+ |
make_rpixmap(ourras, wind); |
699 |
+ |
return(0); |
700 |
+ |
case 'F': /* turn off fast redraw */ |
701 |
+ |
fast = 0; |
702 |
+ |
free_rpixmap(ourras); |
703 |
+ |
return(0); |
704 |
+ |
case '0': /* recenter origin */ |
705 |
+ |
if (xoff == 0 & yoff == 0) |
706 |
+ |
return(0); |
707 |
+ |
xoff = yoff = 0; |
708 |
+ |
XClearWindow(thedisplay, wind); |
709 |
+ |
redraw(0, 0, width, height); |
710 |
+ |
return(0); |
711 |
|
case ' ': /* clear */ |
712 |
|
redraw(box.xmin, box.ymin, box.xsiz, box.ysiz); |
713 |
|
return(0); |
721 |
|
moveimage(ebut) /* shift the image */ |
722 |
|
XButtonPressedEvent *ebut; |
723 |
|
{ |
724 |
< |
union { |
631 |
< |
XEvent u; |
632 |
< |
XButtonReleasedEvent b; |
633 |
< |
XPointerMovedEvent m; |
634 |
< |
} e; |
724 |
> |
XEvent e; |
725 |
|
int mxo, myo; |
726 |
|
|
727 |
< |
XMaskEvent(thedisplay, ButtonReleaseMask|ButtonMotionMask, &e.u); |
728 |
< |
while (e.u.type == MotionNotify) { |
729 |
< |
mxo = e.m.x; |
730 |
< |
myo = e.m.y; |
727 |
> |
XMaskEvent(thedisplay, ButtonReleaseMask|ButtonMotionMask, &e); |
728 |
> |
while (e.type == MotionNotify) { |
729 |
> |
mxo = e.xmotion.x; |
730 |
> |
myo = e.xmotion.y; |
731 |
|
revline(ebut->x, ebut->y, mxo, myo); |
732 |
|
revbox(xoff+mxo-ebut->x, yoff+myo-ebut->y, |
733 |
|
xoff+mxo-ebut->x+xmax, yoff+myo-ebut->y+ymax); |
734 |
< |
XMaskEvent(thedisplay,ButtonReleaseMask|ButtonMotionMask,&e.u); |
734 |
> |
XMaskEvent(thedisplay,ButtonReleaseMask|ButtonMotionMask,&e); |
735 |
|
revline(ebut->x, ebut->y, mxo, myo); |
736 |
|
revbox(xoff+mxo-ebut->x, yoff+myo-ebut->y, |
737 |
|
xoff+mxo-ebut->x+xmax, yoff+myo-ebut->y+ymax); |
738 |
|
} |
739 |
< |
xoff += e.b.x - ebut->x; |
740 |
< |
yoff += e.b.y - ebut->y; |
739 |
> |
xoff += e.xbutton.x - ebut->x; |
740 |
> |
yoff += e.xbutton.y - ebut->y; |
741 |
|
XClearWindow(thedisplay, wind); |
742 |
|
redraw(0, 0, width, height); |
743 |
|
} |
746 |
|
getbox(ebut) /* get new box */ |
747 |
|
XButtonPressedEvent *ebut; |
748 |
|
{ |
749 |
< |
union { |
660 |
< |
XEvent u; |
661 |
< |
XButtonReleasedEvent b; |
662 |
< |
XPointerMovedEvent m; |
663 |
< |
} e; |
749 |
> |
XEvent e; |
750 |
|
|
751 |
< |
XMaskEvent(thedisplay, ButtonReleaseMask|ButtonMotionMask, &e.u); |
752 |
< |
while (e.u.type == MotionNotify) { |
753 |
< |
revbox(ebut->x, ebut->y, box.xmin = e.m.x, box.ymin = e.m.y); |
754 |
< |
XMaskEvent(thedisplay,ButtonReleaseMask|ButtonMotionMask,&e.u); |
751 |
> |
XMaskEvent(thedisplay, ButtonReleaseMask|ButtonMotionMask, &e); |
752 |
> |
while (e.type == MotionNotify) { |
753 |
> |
revbox(ebut->x, ebut->y, box.xmin = e.xmotion.x, box.ymin = e.xmotion.y); |
754 |
> |
XMaskEvent(thedisplay,ButtonReleaseMask|ButtonMotionMask,&e); |
755 |
|
revbox(ebut->x, ebut->y, box.xmin, box.ymin); |
756 |
|
} |
757 |
< |
box.xmin = e.b.x<0 ? 0 : (e.b.x>=width ? width-1 : e.b.x); |
758 |
< |
box.ymin = e.b.y<0 ? 0 : (e.b.y>=height ? height-1 : e.b.y); |
757 |
> |
box.xmin = e.xbutton.x<0 ? 0 : (e.xbutton.x>=width ? width-1 : e.xbutton.x); |
758 |
> |
box.ymin = e.xbutton.y<0 ? 0 : (e.xbutton.y>=height ? height-1 : e.xbutton.y); |
759 |
|
if (box.xmin > ebut->x) { |
760 |
|
box.xsiz = box.xmin - ebut->x + 1; |
761 |
|
box.xmin = ebut->x; |
868 |
|
static short cerr[ICONSIZ]; |
869 |
|
static int ynext; |
870 |
|
static char *dp; |
871 |
< |
double sf; |
786 |
< |
COLOR col; |
871 |
> |
COLR clr; |
872 |
|
register int err; |
873 |
|
register int x, ti; |
874 |
|
int errp; |
893 |
|
} |
894 |
|
if (y < ynext*ymax/iconheight) /* skip this one */ |
895 |
|
return; |
811 |
– |
sf = pow(2.0, (double)(scale+8)); |
896 |
|
err = 0; |
897 |
|
for (x = 0; x < iconwidth; x++) { |
898 |
|
if (!(x&7)) |
899 |
|
*++dp = 0; |
900 |
|
errp = err; |
901 |
|
ti = x*xmax/iconwidth; |
902 |
< |
colr_color(col, scan[ti]); |
903 |
< |
ti = sf*bright(col); |
904 |
< |
if (ti > 255) ti = 255; |
821 |
< |
err += ti + cerr[x]; |
902 |
> |
copycolr(clr, scan[ti]); |
903 |
> |
normcolrs(clr, 1, scale); |
904 |
> |
err += normbright(clr) + cerr[x]; |
905 |
|
if (err > 127) |
906 |
|
err -= 255; |
907 |
|
else |
916 |
|
getfull() /* get full (24-bit) data */ |
917 |
|
{ |
918 |
|
int y; |
919 |
< |
register unsigned long *dp; |
919 |
> |
register unsigned int4 *dp; |
920 |
|
register int x; |
921 |
|
/* set gamma correction */ |
922 |
|
setcolrgam(gamcor); |
923 |
|
/* read and convert file */ |
924 |
< |
dp = (unsigned long *)ourdata; |
924 |
> |
dp = (unsigned int4 *)ourdata; |
925 |
|
for (y = 0; y < ymax; y++) { |
926 |
|
getscan(y); |
927 |
|
add2icon(y, scanline); |
956 |
|
add2icon(y, scanline); |
957 |
|
if (scale) |
958 |
|
shiftcolrs(scanline, xmax, scale); |
959 |
+ |
for (x = 0; x < xmax; x++) |
960 |
+ |
scanline[x][GRN] = normbright(scanline[x]); |
961 |
|
colrs_gambs(scanline, xmax); |
962 |
|
if (maxcolors < 256) |
963 |
|
for (x = 0; x < xmax; x++) |
964 |
< |
*dp++ = ((long)normbright(scanline[x]) * |
965 |
< |
maxcolors + 128) >> 8; |
964 |
> |
*dp++ = ((long)scanline[x][GRN] * |
965 |
> |
maxcolors + maxcolors/2) >> 8; |
966 |
|
else |
967 |
|
for (x = 0; x < xmax; x++) |
968 |
< |
*dp++ = normbright(scanline[x]); |
968 |
> |
*dp++ = scanline[x][GRN]; |
969 |
|
} |
970 |
|
for (x = 0; x < maxcolors; x++) |
971 |
|
clrtab[x][RED] = clrtab[x][GRN] = |
972 |
< |
clrtab[x][BLU] = ((long)x*256+maxcolors/2)/maxcolors; |
972 |
> |
clrtab[x][BLU] = ((long)x*256 + 128)/maxcolors; |
973 |
|
} |
974 |
|
|
975 |
|
|
976 |
|
getmapped() /* get color-mapped data */ |
977 |
|
{ |
978 |
|
int y; |
979 |
+ |
/* make sure we can do it first */ |
980 |
+ |
if (fname == NULL) |
981 |
+ |
quiterr("cannot map colors from standard input"); |
982 |
|
/* set gamma correction */ |
983 |
|
setcolrgam(gamcor); |
984 |
|
/* make histogram */ |
985 |
|
new_histo(); |
986 |
|
for (y = 0; y < ymax; y++) { |
987 |
|
if (getscan(y) < 0) |
988 |
< |
quiterr("seek error in getmapped"); |
988 |
> |
break; |
989 |
|
add2icon(y, scanline); |
990 |
|
if (scale) |
991 |
|
shiftcolrs(scanline, xmax, scale); |
996 |
|
if (!new_clrtab(maxcolors)) |
997 |
|
quiterr("cannot create color map"); |
998 |
|
for (y = 0; y < ymax; y++) { |
999 |
< |
if (getscan(y) < 0) |
912 |
< |
quiterr("seek error in getmapped"); |
999 |
> |
getscan(y); |
1000 |
|
if (scale) |
1001 |
|
shiftcolrs(scanline, xmax, scale); |
1002 |
|
colrs_gambs(scanline, xmax); |
1039 |
|
getscan(y) |
1040 |
|
int y; |
1041 |
|
{ |
1042 |
+ |
static int trunced = -1; /* truncated file? */ |
1043 |
+ |
skipit: |
1044 |
+ |
if (trunced >= 0 && y >= trunced) { |
1045 |
+ |
bzero(scanline, xmax*sizeof(COLR)); |
1046 |
+ |
return(-1); |
1047 |
+ |
} |
1048 |
|
if (y != cury) { |
1049 |
|
if (scanpos == NULL || scanpos[y] == -1) |
1050 |
|
return(-1); |
1054 |
|
} else if (scanpos != NULL && scanpos[y] == -1) |
1055 |
|
scanpos[y] = ftell(fin); |
1056 |
|
|
1057 |
< |
if (freadcolrs(scanline, xmax, fin) < 0) |
1058 |
< |
quiterr("read error"); |
1059 |
< |
|
1057 |
> |
if (freadcolrs(scanline, xmax, fin) < 0) { |
1058 |
> |
fprintf(stderr, "%s: %s: unfinished picture\n", |
1059 |
> |
progname, fname==NULL?"<stdin>":fname); |
1060 |
> |
trunced = y; |
1061 |
> |
goto skipit; |
1062 |
> |
} |
1063 |
|
cury++; |
1064 |
|
return(0); |
1065 |
|
} |