| 1 |
< |
/* Copyright (c) 1992 Regents of the University of California */ |
| 1 |
> |
/* Copyright (c) 1997 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)-'@') |
| 56 |
|
#define redraw(x,y,w,h) patch_raster(wind,(x)-xoff,(y)-yoff,x,y,w,h,ourras) |
| 57 |
|
|
| 58 |
|
double gamcor = 2.2; /* gamma correction */ |
| 59 |
+ |
char *gamstr = NULL; /* gamma value override */ |
| 60 |
|
|
| 61 |
|
int dither = 1; /* dither colors? */ |
| 62 |
|
int fast = 0; /* keep picture in Pixmap? */ |
| 65 |
|
|
| 66 |
|
Window wind = 0; /* our output window */ |
| 67 |
|
unsigned long ourblack=0, ourwhite=1; /* black and white for this visual */ |
| 58 |
– |
Font fontid; /* our font */ |
| 59 |
– |
|
| 68 |
|
int maxcolors = 0; /* maximum colors */ |
| 69 |
|
int greyscale = 0; /* in grey */ |
| 70 |
|
|
| 73 |
|
int xoff = 0; /* x image offset */ |
| 74 |
|
int yoff = 0; /* y image offset */ |
| 75 |
|
|
| 76 |
+ |
int parent = 0; /* number of children, -1 if child */ |
| 77 |
+ |
int sequential = 0; /* display images in sequence */ |
| 78 |
+ |
|
| 79 |
+ |
char *tout = "od"; /* output of 't' command */ |
| 80 |
+ |
int tinterv = 0; /* interval between mouse reports */ |
| 81 |
+ |
|
| 82 |
|
VIEW ourview = STDVIEW; /* image view parameters */ |
| 83 |
|
int gotview = 0; /* got parameters from file */ |
| 84 |
|
|
| 117 |
|
|
| 118 |
|
char errmsg[128]; |
| 119 |
|
|
| 120 |
< |
extern BYTE clrtab[256][3]; /* global color map */ |
| 120 |
> |
BYTE clrtab[256][3]; /* global color map */ |
| 121 |
|
|
| 122 |
|
extern long ftell(); |
| 123 |
|
|
| 124 |
< |
extern char *malloc(), *calloc(); |
| 124 |
> |
extern char *getenv(); |
| 125 |
|
|
| 126 |
|
Display *thedisplay; |
| 127 |
+ |
Atom closedownAtom, wmProtocolsAtom; |
| 128 |
|
|
| 129 |
+ |
int sigrecv; |
| 130 |
|
|
| 131 |
+ |
int onsig() { sigrecv++; } |
| 132 |
+ |
|
| 133 |
+ |
|
| 134 |
|
main(argc, argv) |
| 135 |
|
int argc; |
| 136 |
|
char *argv[]; |
| 137 |
|
{ |
| 119 |
– |
extern char *getenv(); |
| 120 |
– |
char *gv; |
| 138 |
|
int headline(); |
| 139 |
|
int i; |
| 140 |
+ |
int pid; |
| 141 |
|
|
| 142 |
|
progname = argv[0]; |
| 125 |
– |
if ((gv = getenv("GAMMA")) != NULL) |
| 126 |
– |
gamcor = atof(gv); |
| 143 |
|
|
| 144 |
|
for (i = 1; i < argc; i++) |
| 145 |
|
if (argv[i][0] == '-') |
| 146 |
|
switch (argv[i][1]) { |
| 147 |
< |
case 'c': |
| 147 |
> |
case 'c': /* number of colors */ |
| 148 |
|
maxcolors = atoi(argv[++i]); |
| 149 |
|
break; |
| 150 |
< |
case 'b': |
| 150 |
> |
case 'b': /* greyscale only */ |
| 151 |
|
greyscale = !greyscale; |
| 152 |
|
break; |
| 153 |
< |
case 'm': |
| 153 |
> |
case 'm': /* monochrome */ |
| 154 |
> |
greyscale = 1; |
| 155 |
|
maxcolors = 2; |
| 156 |
|
break; |
| 157 |
< |
case 'd': |
| 157 |
> |
case 'd': /* display or dither */ |
| 158 |
|
if (argv[i][2] == 'i') |
| 159 |
|
dispname = argv[++i]; |
| 160 |
|
else |
| 161 |
|
dither = !dither; |
| 162 |
|
break; |
| 163 |
< |
case 'f': |
| 163 |
> |
case 'f': /* save pixmap */ |
| 164 |
|
fast = !fast; |
| 165 |
|
break; |
| 166 |
< |
case 'e': |
| 166 |
> |
case 's': /* one at a time */ |
| 167 |
> |
sequential = !sequential; |
| 168 |
> |
break; |
| 169 |
> |
case 'o': /* 't' output */ |
| 170 |
> |
tout = argv[i]+2; |
| 171 |
> |
break; |
| 172 |
> |
case 't': /* msec interval */ |
| 173 |
> |
tinterv = atoi(argv[++i]); |
| 174 |
> |
break; |
| 175 |
> |
case 'e': /* exposure comp. */ |
| 176 |
|
if (argv[i+1][0] != '+' && argv[i+1][0] != '-') |
| 177 |
|
goto userr; |
| 178 |
|
scale = atoi(argv[++i]); |
| 179 |
|
break; |
| 180 |
< |
case 'g': |
| 180 |
> |
case 'g': /* gamma comp. */ |
| 181 |
|
if (argv[i][2] == 'e') |
| 182 |
|
geometry = argv[++i]; |
| 183 |
|
else |
| 184 |
< |
gamcor = atof(argv[++i]); |
| 184 |
> |
gamstr = argv[++i]; |
| 185 |
|
break; |
| 186 |
|
default: |
| 187 |
|
goto userr; |
| 191 |
|
else |
| 192 |
|
break; |
| 193 |
|
|
| 194 |
< |
if (i == argc-1) { |
| 194 |
> |
if (i > argc) |
| 195 |
> |
goto userr; |
| 196 |
> |
while (i < argc-1) { |
| 197 |
> |
sigrecv = 0; |
| 198 |
> |
signal(SIGCONT, onsig); |
| 199 |
> |
if ((pid=fork()) == 0) { /* a child for each picture */ |
| 200 |
> |
parent = -1; |
| 201 |
> |
break; |
| 202 |
> |
} |
| 203 |
> |
if (pid < 0) |
| 204 |
> |
quiterr("fork failed"); |
| 205 |
> |
parent++; |
| 206 |
> |
while (!sigrecv) |
| 207 |
> |
pause(); /* wait for wake-up call */ |
| 208 |
> |
i++; |
| 209 |
> |
} |
| 210 |
> |
if (i < argc) { /* open picture file */ |
| 211 |
|
fname = argv[i]; |
| 212 |
|
fin = fopen(fname, "r"); |
| 213 |
< |
if (fin == NULL) { |
| 214 |
< |
sprintf(errmsg, "cannot open file \"%s\"", fname); |
| 215 |
< |
quiterr(errmsg); |
| 174 |
< |
} |
| 175 |
< |
} else if (i != argc) |
| 176 |
< |
goto userr; |
| 213 |
> |
if (fin == NULL) |
| 214 |
> |
quiterr("cannot open picture file"); |
| 215 |
> |
} |
| 216 |
|
/* get header */ |
| 217 |
|
getheader(fin, headline, NULL); |
| 218 |
|
/* get picture dimensions */ |
| 226 |
|
if ((scanline = (COLR *)malloc(xmax*sizeof(COLR))) == NULL) |
| 227 |
|
quiterr("out of memory"); |
| 228 |
|
|
| 229 |
< |
init(); /* get file and open window */ |
| 229 |
> |
init(argc, argv); /* get file and open window */ |
| 230 |
|
|
| 231 |
|
for ( ; ; ) |
| 232 |
|
getevent(); /* main loop */ |
| 233 |
|
userr: |
| 234 |
|
fprintf(stderr, |
| 235 |
< |
"Usage: %s [-display disp][-geometry spec][-b][-m][-d][-f][-c ncolors][-e +/-stops] file\n", |
| 235 |
> |
"Usage: %s [-di disp][[-ge] spec][-b][-m][-d][-f][-c nclrs][-e +/-stops][-g gamcor][-s][-ospec][-t intvl] pic ..\n", |
| 236 |
|
progname); |
| 237 |
< |
quit(1); |
| 237 |
> |
exit(1); |
| 238 |
|
} |
| 239 |
|
|
| 240 |
|
|
| 253 |
|
} |
| 254 |
|
|
| 255 |
|
|
| 256 |
< |
init() /* get data and open window */ |
| 256 |
> |
init(argc, argv) /* get data and open window */ |
| 257 |
> |
int argc; |
| 258 |
> |
char **argv; |
| 259 |
|
{ |
| 219 |
– |
XWMHints ourxwmhints; |
| 260 |
|
XSetWindowAttributes ourwinattr; |
| 261 |
< |
XSizeHints oursizhints; |
| 261 |
> |
XClassHint xclshints; |
| 262 |
> |
XWMHints xwmhints; |
| 263 |
> |
XSizeHints xszhints; |
| 264 |
> |
XTextProperty windowName, iconName; |
| 265 |
> |
XGCValues xgcv; |
| 266 |
> |
char *name; |
| 267 |
|
register int i; |
| 268 |
|
|
| 269 |
|
if (fname != NULL) { |
| 270 |
|
scanpos = (long *)malloc(ymax*sizeof(long)); |
| 271 |
|
if (scanpos == NULL) |
| 272 |
< |
goto memerr; |
| 272 |
> |
quiterr("out of memory"); |
| 273 |
|
for (i = 0; i < ymax; i++) |
| 274 |
|
scanpos[i] = -1; |
| 275 |
< |
} |
| 275 |
> |
name = fname; |
| 276 |
> |
} else |
| 277 |
> |
name = progname; |
| 278 |
> |
/* remove directory prefix from name */ |
| 279 |
> |
for (i = strlen(name); i-- > 0; ) |
| 280 |
> |
if (name[i] == '/') |
| 281 |
> |
break; |
| 282 |
> |
name += i+1; |
| 283 |
|
if ((thedisplay = XOpenDisplay(dispname)) == NULL) |
| 284 |
|
quiterr("cannot open display"); |
| 285 |
+ |
/* set gamma value */ |
| 286 |
+ |
if (gamstr == NULL) /* get it from the X server */ |
| 287 |
+ |
gamstr = XGetDefault(thedisplay, "radiance", "gamma"); |
| 288 |
+ |
if (gamstr == NULL) /* get it from the environment */ |
| 289 |
+ |
gamstr = getenv("DISPLAY_GAMMA"); |
| 290 |
+ |
if (gamstr != NULL) |
| 291 |
+ |
gamcor = atof(gamstr); |
| 292 |
|
/* get best visual for default screen */ |
| 293 |
|
getbestvis(); |
| 294 |
|
/* store image */ |
| 295 |
|
getras(); |
| 296 |
< |
/* open window */ |
| 297 |
< |
ourwinattr.border_pixel = ourblack; |
| 298 |
< |
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); |
| 296 |
> |
/* get size and position */ |
| 297 |
> |
xszhints.flags = 0; |
| 298 |
> |
xszhints.width = xmax; xszhints.height = ymax; |
| 299 |
|
if (geometry != NULL) { |
| 300 |
< |
bzero((char *)&oursizhints, sizeof(oursizhints)); |
| 301 |
< |
i = XParseGeometry(geometry, &oursizhints.x, &oursizhints.y, |
| 302 |
< |
(unsigned *)&oursizhints.width, |
| 265 |
< |
(unsigned *)&oursizhints.height); |
| 300 |
> |
i = XParseGeometry(geometry, &xszhints.x, &xszhints.y, |
| 301 |
> |
(unsigned *)&xszhints.width, |
| 302 |
> |
(unsigned *)&xszhints.height); |
| 303 |
|
if ((i&(WidthValue|HeightValue)) == (WidthValue|HeightValue)) |
| 304 |
< |
oursizhints.flags |= USSize; |
| 305 |
< |
else { |
| 306 |
< |
oursizhints.width = xmax; |
| 270 |
< |
oursizhints.height = ymax; |
| 271 |
< |
oursizhints.flags |= PSize; |
| 272 |
< |
} |
| 304 |
> |
xszhints.flags |= USSize; |
| 305 |
> |
else |
| 306 |
> |
xszhints.flags |= PSize; |
| 307 |
|
if ((i&(XValue|YValue)) == (XValue|YValue)) { |
| 308 |
< |
oursizhints.flags |= USPosition; |
| 308 |
> |
xszhints.flags |= USPosition; |
| 309 |
|
if (i & XNegative) |
| 310 |
< |
oursizhints.x += DisplayWidth(thedisplay, |
| 311 |
< |
ourscreen)-1-oursizhints.width-2*BORWIDTH; |
| 310 |
> |
xszhints.x += DisplayWidth(thedisplay, |
| 311 |
> |
ourscreen)-1-xszhints.width-2*BORWIDTH; |
| 312 |
|
if (i & YNegative) |
| 313 |
< |
oursizhints.y += DisplayHeight(thedisplay, |
| 314 |
< |
ourscreen)-1-oursizhints.height-2*BORWIDTH; |
| 313 |
> |
xszhints.y += DisplayHeight(thedisplay, |
| 314 |
> |
ourscreen)-1-xszhints.height-2*BORWIDTH; |
| 315 |
|
} |
| 282 |
– |
XSetNormalHints(thedisplay, wind, &oursizhints); |
| 316 |
|
} |
| 317 |
< |
ourxwmhints.flags = InputHint|IconPixmapHint; |
| 318 |
< |
ourxwmhints.input = True; |
| 319 |
< |
ourxwmhints.icon_pixmap = XCreateBitmapFromData(thedisplay, |
| 317 |
> |
/* open window */ |
| 318 |
> |
i = CWEventMask|CWCursor|CWBackPixel|CWBorderPixel; |
| 319 |
> |
ourwinattr.border_pixel = ourwhite; |
| 320 |
> |
ourwinattr.background_pixel = ourblack; |
| 321 |
> |
if (ourvis.visual != DefaultVisual(thedisplay,ourscreen)) { |
| 322 |
> |
ourwinattr.colormap = newcmap(thedisplay, ourscreen, ourvis.visual); |
| 323 |
> |
i |= CWColormap; |
| 324 |
> |
} |
| 325 |
> |
ourwinattr.event_mask = ExposureMask|KeyPressMask|ButtonPressMask| |
| 326 |
> |
ButtonReleaseMask|ButtonMotionMask|StructureNotifyMask; |
| 327 |
> |
ourwinattr.cursor = XCreateFontCursor(thedisplay, XC_diamond_cross); |
| 328 |
> |
wind = XCreateWindow(thedisplay, ourroot, xszhints.x, xszhints.y, |
| 329 |
> |
xszhints.width, xszhints.height, BORWIDTH, |
| 330 |
> |
ourvis.depth, InputOutput, ourvis.visual, |
| 331 |
> |
i, &ourwinattr); |
| 332 |
> |
if (wind == 0) |
| 333 |
> |
quiterr("cannot create window"); |
| 334 |
> |
width = xmax; |
| 335 |
> |
height = ymax; |
| 336 |
> |
/* prepare graphics drawing context */ |
| 337 |
> |
if ((xgcv.font = XLoadFont(thedisplay, FONTNAME)) == 0) |
| 338 |
> |
quiterr("cannot get font"); |
| 339 |
> |
xgcv.foreground = ourblack; |
| 340 |
> |
xgcv.background = ourwhite; |
| 341 |
> |
ourgc = XCreateGC(thedisplay, wind, GCForeground|GCBackground| |
| 342 |
> |
GCFont, &xgcv); |
| 343 |
> |
xgcv.function = GXinvert; |
| 344 |
> |
revgc = XCreateGC(thedisplay, wind, GCForeground|GCBackground| |
| 345 |
> |
GCFunction, &xgcv); |
| 346 |
> |
|
| 347 |
> |
/* set up the window manager */ |
| 348 |
> |
xwmhints.flags = InputHint|IconPixmapHint; |
| 349 |
> |
xwmhints.input = True; |
| 350 |
> |
xwmhints.icon_pixmap = XCreateBitmapFromData(thedisplay, |
| 351 |
|
wind, icondata, iconwidth, iconheight); |
| 352 |
< |
XSetWMHints(thedisplay, wind, &ourxwmhints); |
| 353 |
< |
XSelectInput(thedisplay, wind, ButtonPressMask|ButtonReleaseMask |
| 354 |
< |
|ButtonMotionMask|StructureNotifyMask |
| 355 |
< |
|KeyPressMask|ExposureMask); |
| 352 |
> |
|
| 353 |
> |
windowName.encoding = iconName.encoding = XA_STRING; |
| 354 |
> |
windowName.format = iconName.format = 8; |
| 355 |
> |
windowName.value = (u_char *)name; |
| 356 |
> |
windowName.nitems = strlen(windowName.value); |
| 357 |
> |
iconName.value = (u_char *)name; |
| 358 |
> |
iconName.nitems = strlen(windowName.value); |
| 359 |
> |
|
| 360 |
> |
xclshints.res_name = NULL; |
| 361 |
> |
xclshints.res_class = "Ximage"; |
| 362 |
> |
XSetWMProperties(thedisplay, wind, &windowName, &iconName, |
| 363 |
> |
argv, argc, &xszhints, &xwmhints, &xclshints); |
| 364 |
> |
closedownAtom = XInternAtom(thedisplay, "WM_DELETE_WINDOW", False); |
| 365 |
> |
wmProtocolsAtom = XInternAtom(thedisplay, "WM_PROTOCOLS", False); |
| 366 |
> |
XSetWMProtocols(thedisplay, wind, &closedownAtom, 1); |
| 367 |
> |
|
| 368 |
|
XMapWindow(thedisplay, wind); |
| 293 |
– |
return; |
| 294 |
– |
memerr: |
| 295 |
– |
quiterr("out of memory"); |
| 369 |
|
} /* end of init */ |
| 370 |
|
|
| 371 |
|
|
| 372 |
|
quiterr(err) /* print message and exit */ |
| 373 |
|
char *err; |
| 374 |
|
{ |
| 375 |
< |
if (err != NULL) { |
| 376 |
< |
fprintf(stderr, "%s: %s\n", progname, err); |
| 377 |
< |
exit(1); |
| 375 |
> |
register int es; |
| 376 |
> |
int cs; |
| 377 |
> |
|
| 378 |
> |
if (es = err != NULL) |
| 379 |
> |
fprintf(stderr, "%s: %s: %s\n", progname, |
| 380 |
> |
fname==NULL?"<stdin>":fname, err); |
| 381 |
> |
if (thedisplay != NULL) |
| 382 |
> |
XCloseDisplay(thedisplay); |
| 383 |
> |
if (parent < 0 & sigrecv == 0) |
| 384 |
> |
kill(getppid(), SIGCONT); |
| 385 |
> |
while (parent > 0 && wait(&cs) != -1) { /* wait for any children */ |
| 386 |
> |
if (es == 0) |
| 387 |
> |
es = cs>>8 & 0xff; |
| 388 |
> |
parent--; |
| 389 |
|
} |
| 390 |
< |
exit(0); |
| 390 |
> |
exit(es); |
| 391 |
|
} |
| 392 |
|
|
| 393 |
|
|
| 528 |
|
goto fail; |
| 529 |
|
getmono(); |
| 530 |
|
} else if (ourvis.class == TrueColor | ourvis.class == DirectColor) { |
| 531 |
< |
ourdata = (unsigned char *)malloc(4*xmax*ymax); |
| 531 |
> |
ourdata = (unsigned char *)malloc(sizeof(int4)*xmax*ymax); |
| 532 |
|
if (ourdata == NULL) |
| 533 |
|
goto fail; |
| 534 |
< |
ourras = make_raster(thedisplay, &ourvis, 32, |
| 534 |
> |
ourras = make_raster(thedisplay, &ourvis, sizeof(int4)*8, |
| 535 |
|
ourdata, xmax, ymax, 32); |
| 536 |
|
if (ourras == NULL) |
| 537 |
|
goto fail; |
| 559 |
|
|
| 560 |
|
getevent() /* process the next event */ |
| 561 |
|
{ |
| 562 |
< |
union { |
| 479 |
< |
XEvent u; |
| 480 |
< |
XConfigureEvent c; |
| 481 |
< |
XExposeEvent e; |
| 482 |
< |
XButtonPressedEvent b; |
| 483 |
< |
XKeyPressedEvent k; |
| 484 |
< |
} e; |
| 562 |
> |
XEvent xev; |
| 563 |
|
|
| 564 |
< |
XNextEvent(thedisplay, &e.u); |
| 565 |
< |
switch (e.u.type) { |
| 564 |
> |
XNextEvent(thedisplay, &xev); |
| 565 |
> |
switch ((int)xev.type) { |
| 566 |
|
case KeyPress: |
| 567 |
< |
docom(&e.k); |
| 567 |
> |
docom(&xev.xkey); |
| 568 |
|
break; |
| 569 |
|
case ConfigureNotify: |
| 570 |
< |
width = e.c.width; |
| 571 |
< |
height = e.c.height; |
| 570 |
> |
width = xev.xconfigure.width; |
| 571 |
> |
height = xev.xconfigure.height; |
| 572 |
|
break; |
| 573 |
|
case MapNotify: |
| 574 |
|
map_rcolors(ourras, wind); |
| 575 |
|
if (fast) |
| 576 |
|
make_rpixmap(ourras, wind); |
| 577 |
+ |
if (!sequential & parent < 0 & sigrecv == 0) { |
| 578 |
+ |
kill(getppid(), SIGCONT); |
| 579 |
+ |
sigrecv--; |
| 580 |
+ |
} |
| 581 |
|
break; |
| 582 |
|
case UnmapNotify: |
| 583 |
|
if (!fast) |
| 584 |
|
unmap_rcolors(ourras); |
| 585 |
|
break; |
| 586 |
|
case Expose: |
| 587 |
< |
redraw(e.e.x, e.e.y, e.e.width, e.e.height); |
| 587 |
> |
redraw(xev.xexpose.x, xev.xexpose.y, |
| 588 |
> |
xev.xexpose.width, xev.xexpose.height); |
| 589 |
|
break; |
| 590 |
|
case ButtonPress: |
| 591 |
< |
if (e.b.state & (ShiftMask|ControlMask)) |
| 592 |
< |
moveimage(&e.b); |
| 591 |
> |
if (xev.xbutton.state & (ShiftMask|ControlMask)) |
| 592 |
> |
moveimage(&xev.xbutton); |
| 593 |
|
else |
| 594 |
< |
getbox(&e.b); |
| 594 |
> |
switch (xev.xbutton.button) { |
| 595 |
> |
case Button1: |
| 596 |
> |
getbox(&xev.xbutton); |
| 597 |
> |
break; |
| 598 |
> |
case Button2: |
| 599 |
> |
traceray(xev.xbutton.x, xev.xbutton.y); |
| 600 |
> |
break; |
| 601 |
> |
case Button3: |
| 602 |
> |
trackrays(&xev.xbutton); |
| 603 |
> |
break; |
| 604 |
> |
} |
| 605 |
|
break; |
| 606 |
+ |
case ClientMessage: |
| 607 |
+ |
if ((xev.xclient.message_type == wmProtocolsAtom) && |
| 608 |
+ |
(xev.xclient.data.l[0] == closedownAtom)) |
| 609 |
+ |
quiterr(NULL); |
| 610 |
+ |
break; |
| 611 |
|
} |
| 612 |
|
} |
| 613 |
|
|
| 614 |
|
|
| 615 |
< |
docom(ekey) /* execute command */ |
| 615 |
> |
traceray(xpos, ypos) /* print requested pixel data */ |
| 616 |
> |
int xpos, ypos; |
| 617 |
> |
{ |
| 618 |
> |
extern char *index(); |
| 619 |
> |
FLOAT hv[2]; |
| 620 |
> |
FVECT rorg, rdir; |
| 621 |
> |
COLOR cval; |
| 622 |
> |
register char *cp; |
| 623 |
> |
|
| 624 |
> |
box.xmin = xpos; box.xsiz = 1; |
| 625 |
> |
box.ymin = ypos; box.ysiz = 1; |
| 626 |
> |
avgbox(cval); |
| 627 |
> |
scalecolor(cval, 1./exposure); |
| 628 |
> |
pix2loc(hv, &inpres, xpos-xoff, ypos-yoff); |
| 629 |
> |
if (!gotview || viewray(rorg, rdir, &ourview, hv[0], hv[1]) < 0) |
| 630 |
> |
rorg[0] = rorg[1] = rorg[2] = |
| 631 |
> |
rdir[0] = rdir[1] = rdir[2] = 0.; |
| 632 |
> |
|
| 633 |
> |
for (cp = tout; *cp; cp++) /* print what they asked for */ |
| 634 |
> |
switch (*cp) { |
| 635 |
> |
case 'o': /* origin */ |
| 636 |
> |
printf("%e %e %e ", rorg[0], rorg[1], rorg[2]); |
| 637 |
> |
break; |
| 638 |
> |
case 'd': /* direction */ |
| 639 |
> |
printf("%e %e %e ", rdir[0], rdir[1], rdir[2]); |
| 640 |
> |
break; |
| 641 |
> |
case 'v': /* radiance value */ |
| 642 |
> |
printf("%e %e %e ", colval(cval,RED), |
| 643 |
> |
colval(cval,GRN), colval(cval,BLU)); |
| 644 |
> |
break; |
| 645 |
> |
case 'l': /* luminance */ |
| 646 |
> |
printf("%e ", luminance(cval)); |
| 647 |
> |
break; |
| 648 |
> |
case 'p': /* pixel position */ |
| 649 |
> |
printf("%d %d ", (int)(hv[0]*inpres.xr), |
| 650 |
> |
(int)(hv[1]*inpres.yr)); |
| 651 |
> |
break; |
| 652 |
> |
} |
| 653 |
> |
putchar('\n'); |
| 654 |
> |
fflush(stdout); |
| 655 |
> |
return(0); |
| 656 |
> |
} |
| 657 |
> |
|
| 658 |
> |
|
| 659 |
> |
docom(ekey) /* execute command */ |
| 660 |
|
XKeyPressedEvent *ekey; |
| 661 |
|
{ |
| 662 |
|
char buf[80]; |
| 665 |
|
int com, n; |
| 666 |
|
double comp; |
| 667 |
|
FLOAT hv[2]; |
| 526 |
– |
FVECT rorg, rdir; |
| 668 |
|
|
| 669 |
|
n = XLookupString(ekey, buf, sizeof(buf), NULL, NULL); |
| 670 |
|
if (n == 0) |
| 672 |
|
com = buf[0]; |
| 673 |
|
switch (com) { /* interpret command */ |
| 674 |
|
case 'q': |
| 675 |
+ |
case 'Q': |
| 676 |
|
case CTRL('D'): /* quit */ |
| 677 |
< |
quit(0); |
| 677 |
> |
quiterr(NULL); |
| 678 |
|
case '\n': |
| 679 |
|
case '\r': |
| 680 |
|
case 'l': |
| 720 |
|
buf, strlen(buf)); |
| 721 |
|
return(0); |
| 722 |
|
case 't': /* trace */ |
| 723 |
< |
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); |
| 723 |
> |
return(traceray(ekey->x, ekey->y)); |
| 724 |
|
case '=': /* adjust exposure */ |
| 725 |
+ |
case '@': /* adaptation level */ |
| 726 |
|
if (avgbox(cval) == -1) |
| 727 |
|
return(-1); |
| 728 |
< |
n = log(.5/bright(cval))/.69315 - scale; /* truncate */ |
| 728 |
> |
comp = bright(cval); |
| 729 |
> |
if (comp < 1e-20) { |
| 730 |
> |
XBell(thedisplay, 0); |
| 731 |
> |
return(-1); |
| 732 |
> |
} |
| 733 |
> |
if (com == '@') |
| 734 |
> |
comp = 106./exposure/ |
| 735 |
> |
pow(1.219+pow(comp*WHTEFFICACY/exposure,.4),2.5); |
| 736 |
> |
else |
| 737 |
> |
comp = .5/comp; |
| 738 |
> |
comp = log(comp)/.69315 - scale; |
| 739 |
> |
n = comp < 0 ? comp-.5 : comp+.5 ; /* round */ |
| 740 |
|
if (n == 0) |
| 741 |
|
return(0); |
| 742 |
|
scale_rcolors(ourras, pow(2.0, (double)n)); |
| 758 |
|
make_rpixmap(ourras, wind); |
| 759 |
|
redraw(0, 0, width, height); |
| 760 |
|
return(0); |
| 761 |
+ |
case 'f': /* turn on fast redraw */ |
| 762 |
+ |
fast = 1; |
| 763 |
+ |
make_rpixmap(ourras, wind); |
| 764 |
+ |
return(0); |
| 765 |
+ |
case 'F': /* turn off fast redraw */ |
| 766 |
+ |
fast = 0; |
| 767 |
+ |
free_rpixmap(ourras); |
| 768 |
+ |
return(0); |
| 769 |
+ |
case '0': /* recenter origin */ |
| 770 |
+ |
if (xoff == 0 & yoff == 0) |
| 771 |
+ |
return(0); |
| 772 |
+ |
xoff = yoff = 0; |
| 773 |
+ |
XClearWindow(thedisplay, wind); |
| 774 |
+ |
redraw(0, 0, width, height); |
| 775 |
+ |
return(0); |
| 776 |
|
case ' ': /* clear */ |
| 777 |
|
redraw(box.xmin, box.ymin, box.xsiz, box.ysiz); |
| 778 |
|
return(0); |
| 786 |
|
moveimage(ebut) /* shift the image */ |
| 787 |
|
XButtonPressedEvent *ebut; |
| 788 |
|
{ |
| 789 |
< |
union { |
| 631 |
< |
XEvent u; |
| 632 |
< |
XButtonReleasedEvent b; |
| 633 |
< |
XPointerMovedEvent m; |
| 634 |
< |
} e; |
| 789 |
> |
XEvent e; |
| 790 |
|
int mxo, myo; |
| 791 |
|
|
| 792 |
< |
XMaskEvent(thedisplay, ButtonReleaseMask|ButtonMotionMask, &e.u); |
| 793 |
< |
while (e.u.type == MotionNotify) { |
| 794 |
< |
mxo = e.m.x; |
| 795 |
< |
myo = e.m.y; |
| 792 |
> |
XMaskEvent(thedisplay, ButtonReleaseMask|ButtonMotionMask, &e); |
| 793 |
> |
while (e.type == MotionNotify) { |
| 794 |
> |
mxo = e.xmotion.x; |
| 795 |
> |
myo = e.xmotion.y; |
| 796 |
|
revline(ebut->x, ebut->y, mxo, myo); |
| 797 |
|
revbox(xoff+mxo-ebut->x, yoff+myo-ebut->y, |
| 798 |
|
xoff+mxo-ebut->x+xmax, yoff+myo-ebut->y+ymax); |
| 799 |
< |
XMaskEvent(thedisplay,ButtonReleaseMask|ButtonMotionMask,&e.u); |
| 799 |
> |
XMaskEvent(thedisplay,ButtonReleaseMask|ButtonMotionMask,&e); |
| 800 |
|
revline(ebut->x, ebut->y, mxo, myo); |
| 801 |
|
revbox(xoff+mxo-ebut->x, yoff+myo-ebut->y, |
| 802 |
|
xoff+mxo-ebut->x+xmax, yoff+myo-ebut->y+ymax); |
| 803 |
|
} |
| 804 |
< |
xoff += e.b.x - ebut->x; |
| 805 |
< |
yoff += e.b.y - ebut->y; |
| 804 |
> |
xoff += e.xbutton.x - ebut->x; |
| 805 |
> |
yoff += e.xbutton.y - ebut->y; |
| 806 |
|
XClearWindow(thedisplay, wind); |
| 807 |
|
redraw(0, 0, width, height); |
| 808 |
|
} |
| 811 |
|
getbox(ebut) /* get new box */ |
| 812 |
|
XButtonPressedEvent *ebut; |
| 813 |
|
{ |
| 814 |
< |
union { |
| 660 |
< |
XEvent u; |
| 661 |
< |
XButtonReleasedEvent b; |
| 662 |
< |
XPointerMovedEvent m; |
| 663 |
< |
} e; |
| 814 |
> |
XEvent e; |
| 815 |
|
|
| 816 |
< |
XMaskEvent(thedisplay, ButtonReleaseMask|ButtonMotionMask, &e.u); |
| 817 |
< |
while (e.u.type == MotionNotify) { |
| 818 |
< |
revbox(ebut->x, ebut->y, box.xmin = e.m.x, box.ymin = e.m.y); |
| 819 |
< |
XMaskEvent(thedisplay,ButtonReleaseMask|ButtonMotionMask,&e.u); |
| 816 |
> |
XMaskEvent(thedisplay, ButtonReleaseMask|ButtonMotionMask, &e); |
| 817 |
> |
while (e.type == MotionNotify) { |
| 818 |
> |
revbox(ebut->x, ebut->y, box.xmin = e.xmotion.x, box.ymin = e.xmotion.y); |
| 819 |
> |
XMaskEvent(thedisplay,ButtonReleaseMask|ButtonMotionMask,&e); |
| 820 |
|
revbox(ebut->x, ebut->y, box.xmin, box.ymin); |
| 821 |
|
} |
| 822 |
< |
box.xmin = e.b.x<0 ? 0 : (e.b.x>=width ? width-1 : e.b.x); |
| 823 |
< |
box.ymin = e.b.y<0 ? 0 : (e.b.y>=height ? height-1 : e.b.y); |
| 822 |
> |
box.xmin = e.xbutton.x<0 ? 0 : (e.xbutton.x>=width ? width-1 : e.xbutton.x); |
| 823 |
> |
box.ymin = e.xbutton.y<0 ? 0 : (e.xbutton.y>=height ? height-1 : e.xbutton.y); |
| 824 |
|
if (box.xmin > ebut->x) { |
| 825 |
|
box.xsiz = box.xmin - ebut->x + 1; |
| 826 |
|
box.xmin = ebut->x; |
| 836 |
|
} |
| 837 |
|
|
| 838 |
|
|
| 839 |
+ |
trackrays(ebut) /* trace rays as mouse moves */ |
| 840 |
+ |
XButtonPressedEvent *ebut; |
| 841 |
+ |
{ |
| 842 |
+ |
XEvent e; |
| 843 |
+ |
unsigned long lastrept; |
| 844 |
+ |
|
| 845 |
+ |
traceray(ebut->x, ebut->y); |
| 846 |
+ |
lastrept = ebut->time; |
| 847 |
+ |
XMaskEvent(thedisplay, ButtonReleaseMask|ButtonMotionMask, &e); |
| 848 |
+ |
while (e.type == MotionNotify) { |
| 849 |
+ |
if (e.xmotion.time >= lastrept + tinterv) { |
| 850 |
+ |
traceray(e.xmotion.x, e.xmotion.y); |
| 851 |
+ |
lastrept = e.xmotion.time; |
| 852 |
+ |
} |
| 853 |
+ |
XMaskEvent(thedisplay,ButtonReleaseMask|ButtonMotionMask,&e); |
| 854 |
+ |
} |
| 855 |
+ |
} |
| 856 |
+ |
|
| 857 |
+ |
|
| 858 |
|
revbox(x0, y0, x1, y1) /* draw box with reversed lines */ |
| 859 |
|
int x0, y0, x1, y1; |
| 860 |
|
{ |
| 925 |
|
dp = ourdata - 1; |
| 926 |
|
for (y = 0; y < ymax; y++) { |
| 927 |
|
getscan(y); |
| 758 |
– |
normcolrs(scanline, xmax, scale); |
| 928 |
|
add2icon(y, scanline); |
| 929 |
+ |
normcolrs(scanline, xmax, scale); |
| 930 |
|
err = 0; |
| 931 |
|
for (x = 0; x < xmax; x++) { |
| 932 |
|
if (!(x&7)) |
| 952 |
|
static short cerr[ICONSIZ]; |
| 953 |
|
static int ynext; |
| 954 |
|
static char *dp; |
| 955 |
+ |
COLR clr; |
| 956 |
|
register int err; |
| 957 |
|
register int x, ti; |
| 958 |
|
int errp; |
| 983 |
|
*++dp = 0; |
| 984 |
|
errp = err; |
| 985 |
|
ti = x*xmax/iconwidth; |
| 986 |
< |
err += normbright(scan[ti]) + cerr[x]; |
| 986 |
> |
copycolr(clr, scan[ti]); |
| 987 |
> |
normcolrs(clr, 1, scale); |
| 988 |
> |
err += normbright(clr) + cerr[x]; |
| 989 |
|
if (err > 127) |
| 990 |
|
err -= 255; |
| 991 |
|
else |
| 1000 |
|
getfull() /* get full (24-bit) data */ |
| 1001 |
|
{ |
| 1002 |
|
int y; |
| 1003 |
< |
register unsigned long *dp; |
| 1003 |
> |
register unsigned int4 *dp; |
| 1004 |
|
register int x; |
| 1005 |
|
/* set gamma correction */ |
| 1006 |
|
setcolrgam(gamcor); |
| 1007 |
|
/* read and convert file */ |
| 1008 |
< |
dp = (unsigned long *)ourdata; |
| 1008 |
> |
dp = (unsigned int4 *)ourdata; |
| 1009 |
|
for (y = 0; y < ymax; y++) { |
| 1010 |
|
getscan(y); |
| 1011 |
+ |
add2icon(y, scanline); |
| 1012 |
|
if (scale) |
| 1013 |
|
shiftcolrs(scanline, xmax, scale); |
| 1014 |
|
colrs_gambs(scanline, xmax); |
| 841 |
– |
add2icon(y, scanline); |
| 1015 |
|
if (ourras->image->blue_mask & 1) |
| 1016 |
|
for (x = 0; x < xmax; x++) |
| 1017 |
< |
*dp++ = scanline[x][RED] << 16 | |
| 1018 |
< |
scanline[x][GRN] << 8 | |
| 1019 |
< |
scanline[x][BLU] ; |
| 1017 |
> |
*dp++ = (unsigned int4)scanline[x][RED] << 16 | |
| 1018 |
> |
(unsigned int4)scanline[x][GRN] << 8 | |
| 1019 |
> |
(unsigned int4)scanline[x][BLU] ; |
| 1020 |
|
else |
| 1021 |
|
for (x = 0; x < xmax; x++) |
| 1022 |
< |
*dp++ = scanline[x][RED] | |
| 1023 |
< |
scanline[x][GRN] << 8 | |
| 1024 |
< |
scanline[x][BLU] << 16 ; |
| 1022 |
> |
*dp++ = (unsigned int4)scanline[x][RED] | |
| 1023 |
> |
(unsigned int4)scanline[x][GRN] << 8 | |
| 1024 |
> |
(unsigned int4)scanline[x][BLU] << 16 ; |
| 1025 |
|
} |
| 1026 |
|
} |
| 1027 |
|
|
| 1037 |
|
dp = ourdata; |
| 1038 |
|
for (y = 0; y < ymax; y++) { |
| 1039 |
|
getscan(y); |
| 1040 |
+ |
add2icon(y, scanline); |
| 1041 |
|
if (scale) |
| 1042 |
|
shiftcolrs(scanline, xmax, scale); |
| 1043 |
+ |
for (x = 0; x < xmax; x++) |
| 1044 |
+ |
scanline[x][GRN] = normbright(scanline[x]); |
| 1045 |
|
colrs_gambs(scanline, xmax); |
| 870 |
– |
add2icon(y, scanline); |
| 1046 |
|
if (maxcolors < 256) |
| 1047 |
|
for (x = 0; x < xmax; x++) |
| 1048 |
< |
*dp++ = ((long)normbright(scanline[x]) * |
| 1049 |
< |
maxcolors + 128) >> 8; |
| 1048 |
> |
*dp++ = ((long)scanline[x][GRN] * |
| 1049 |
> |
maxcolors + maxcolors/2) >> 8; |
| 1050 |
|
else |
| 1051 |
|
for (x = 0; x < xmax; x++) |
| 1052 |
< |
*dp++ = normbright(scanline[x]); |
| 1052 |
> |
*dp++ = scanline[x][GRN]; |
| 1053 |
|
} |
| 1054 |
|
for (x = 0; x < maxcolors; x++) |
| 1055 |
|
clrtab[x][RED] = clrtab[x][GRN] = |
| 1056 |
< |
clrtab[x][BLU] = ((long)x*256+maxcolors/2)/maxcolors; |
| 1056 |
> |
clrtab[x][BLU] = ((long)x*256 + 128)/maxcolors; |
| 1057 |
|
} |
| 1058 |
|
|
| 1059 |
|
|
| 1060 |
|
getmapped() /* get color-mapped data */ |
| 1061 |
|
{ |
| 1062 |
|
int y; |
| 1063 |
+ |
/* make sure we can do it first */ |
| 1064 |
+ |
if (fname == NULL) |
| 1065 |
+ |
quiterr("cannot map colors from standard input"); |
| 1066 |
|
/* set gamma correction */ |
| 1067 |
|
setcolrgam(gamcor); |
| 1068 |
|
/* make histogram */ |
| 1069 |
< |
new_histo(); |
| 1069 |
> |
if (new_histo((long)xmax*ymax) == -1) |
| 1070 |
> |
quiterr("cannot initialize histogram"); |
| 1071 |
|
for (y = 0; y < ymax; y++) { |
| 1072 |
|
if (getscan(y) < 0) |
| 1073 |
< |
quiterr("seek error in getmapped"); |
| 1073 |
> |
break; |
| 1074 |
> |
add2icon(y, scanline); |
| 1075 |
|
if (scale) |
| 1076 |
|
shiftcolrs(scanline, xmax, scale); |
| 1077 |
|
colrs_gambs(scanline, xmax); |
| 898 |
– |
add2icon(y, scanline); |
| 1078 |
|
cnt_colrs(scanline, xmax); |
| 1079 |
|
} |
| 1080 |
|
/* map pixels */ |
| 1081 |
|
if (!new_clrtab(maxcolors)) |
| 1082 |
|
quiterr("cannot create color map"); |
| 1083 |
|
for (y = 0; y < ymax; y++) { |
| 1084 |
< |
if (getscan(y) < 0) |
| 906 |
< |
quiterr("seek error in getmapped"); |
| 1084 |
> |
getscan(y); |
| 1085 |
|
if (scale) |
| 1086 |
|
shiftcolrs(scanline, xmax, scale); |
| 1087 |
|
colrs_gambs(scanline, xmax); |
| 1124 |
|
getscan(y) |
| 1125 |
|
int y; |
| 1126 |
|
{ |
| 1127 |
+ |
static int trunced = -1; /* truncated file? */ |
| 1128 |
+ |
skipit: |
| 1129 |
+ |
if (trunced >= 0 && y >= trunced) { |
| 1130 |
+ |
bzero(scanline, xmax*sizeof(COLR)); |
| 1131 |
+ |
return(-1); |
| 1132 |
+ |
} |
| 1133 |
|
if (y != cury) { |
| 1134 |
|
if (scanpos == NULL || scanpos[y] == -1) |
| 1135 |
|
return(-1); |
| 1139 |
|
} else if (scanpos != NULL && scanpos[y] == -1) |
| 1140 |
|
scanpos[y] = ftell(fin); |
| 1141 |
|
|
| 1142 |
< |
if (freadcolrs(scanline, xmax, fin) < 0) |
| 1143 |
< |
quiterr("read error"); |
| 1144 |
< |
|
| 1142 |
> |
if (freadcolrs(scanline, xmax, fin) < 0) { |
| 1143 |
> |
fprintf(stderr, "%s: %s: unfinished picture\n", |
| 1144 |
> |
progname, fname==NULL?"<stdin>":fname); |
| 1145 |
> |
trunced = y; |
| 1146 |
> |
goto skipit; |
| 1147 |
> |
} |
| 1148 |
|
cury++; |
| 1149 |
|
return(0); |
| 1150 |
|
} |