--- ray/src/px/x11image.c 1993/05/05 10:27:58 2.26 +++ ray/src/px/x11image.c 1993/10/27 13:03:18 2.29 @@ -21,6 +21,7 @@ static char SCCSid[] = "$SunId$ LBL"; #include "standard.h" +#include #include #include #include @@ -32,6 +33,13 @@ static char SCCSid[] = "$SunId$ LBL"; #include "random.h" #include "resolu.h" +#ifdef __alpha +#define int4 int +#endif +#ifndef int4 +#define int4 long +#endif + #define FONTNAME "8x13" /* text font we'll use */ #define CTRL(c) ((c)-'@') @@ -64,6 +72,8 @@ int scale = 0; /* scalefactor; power of two */ int xoff = 0; /* x image offset */ int yoff = 0; /* y image offset */ +int parent = 0; /* number of children, -1 if child */ + VIEW ourview = STDVIEW; /* image view parameters */ int gotview = 0; /* got parameters from file */ @@ -109,7 +119,9 @@ extern long ftell(); Display *thedisplay; Atom closedownAtom, wmProtocolsAtom; +int noop() {} + main(argc, argv) int argc; char *argv[]; @@ -118,6 +130,7 @@ char *argv[]; char *gv; int headline(); int i; + int pid; progname = argv[0]; if ((gv = getenv("GAMMA")) != NULL) @@ -163,15 +176,28 @@ char *argv[]; else break; - if (i == argc-1) { + if (i > argc) + goto userr; + while (i < argc-1) { + if ((pid=fork()) == 0) { /* a child for each picture */ + parent = -1; + break; + } + if (pid < 0) + quiterr("fork failed"); + parent++; + signal(SIGCONT, noop); + pause(); /* wait for wake-up call */ + i++; + } + if (i < argc) { /* open picture file */ fname = argv[i]; fin = fopen(fname, "r"); if (fin == NULL) { sprintf(errmsg, "cannot open file \"%s\"", fname); quiterr(errmsg); } - } else if (i != argc) - goto userr; + } /* get header */ getheader(fin, headline, NULL); /* get picture dimensions */ @@ -187,11 +213,14 @@ char *argv[]; init(argc, argv); /* get file and open window */ + if (parent < 0) + kill(getppid(), SIGCONT); /* signal parent if child */ + for ( ; ; ) getevent(); /* main loop */ userr: fprintf(stderr, -"Usage: %s [-di disp][[-ge] spec][-b][-m][-d][-f][-c nclrs][-e +/-stops] pic\n", +"Usage: %s [-di disp][[-ge] spec][-b][-m][-d][-f][-c nclrs][-e +/-stops] pic ..\n", progname); exit(1); } @@ -321,11 +350,16 @@ char **argv; quiterr(err) /* print message and exit */ char *err; { - if (err != NULL) { - fprintf(stderr, "%s: %s\n", progname, err); - exit(1); + if (err != NULL) + fprintf(stderr, "%s: %s: %s\n", progname, + fname==NULL?"":fname, err); + if (wind) { + XDestroyWindow(thedisplay, wind); + XFlush(thedisplay); } - exit(0); + while (parent > 0 && wait(0) != -1) /* wait for any children */ + parent--; + exit(err != NULL); } @@ -466,10 +500,10 @@ getras() /* get raster file */ goto fail; getmono(); } else if (ourvis.class == TrueColor | ourvis.class == DirectColor) { - ourdata = (unsigned char *)malloc(4*xmax*ymax); + ourdata = (unsigned char *)malloc(sizeof(int4)*xmax*ymax); if (ourdata == NULL) goto fail; - ourras = make_raster(thedisplay, &ourvis, 32, + ourras = make_raster(thedisplay, &ourvis, sizeof(int4)*8, ourdata, xmax, ymax, 32); if (ourras == NULL) goto fail; @@ -529,7 +563,7 @@ getevent() /* process the next event */ else getbox(&xev.xbutton); break; - case ClientMessage: + case ClientMessage: if ((xev.xclient.message_type == wmProtocolsAtom) && (xev.xclient.data.l[0] == closedownAtom)) quiterr(NULL); @@ -653,6 +687,14 @@ XKeyPressedEvent *ekey; make_rpixmap(ourras, wind); redraw(0, 0, width, height); return(0); + case 'f': /* turn on fast redraw */ + fast = 1; + make_rpixmap(ourras, wind); + return(0); + case 'F': /* turn off fast redraw */ + fast = 0; + free_rpixmap(ourras); + return(0); case '0': /* recenter origin */ if (xoff == 0 & yoff == 0) return(0); @@ -868,12 +910,12 @@ COLR *scan; getfull() /* get full (24-bit) data */ { int y; - register unsigned long *dp; + register unsigned int4 *dp; register int x; /* set gamma correction */ setcolrgam(gamcor); /* read and convert file */ - dp = (unsigned long *)ourdata; + dp = (unsigned int4 *)ourdata; for (y = 0; y < ymax; y++) { getscan(y); add2icon(y, scanline);