--- ray/src/px/x11image.c 1991/05/02 17:24:54 1.17 +++ ray/src/px/x11image.c 1991/05/03 12:01:44 1.21 @@ -37,7 +37,7 @@ static char SCCSid[] = "$SunId$ LBL"; #define BORWIDTH 5 /* border width */ -#define ICONSIZ 80 /* maximum icon dimension */ +#define ICONSIZ (8*10) /* maximum icon dimension (even 8) */ #define ourscreen DefaultScreen(thedisplay) #define ourblack BlackPixel(thedisplay,ourscreen) @@ -81,6 +81,8 @@ double exposure = 1.0; /* exposure compensation use int wrongformat = 0; /* input in another format? */ +int imready = 0; /* is image up? */ + GC revgc; /* graphics context with GXinvert */ XRASTER *ourras; /* our stored image */ @@ -92,7 +94,7 @@ struct { char *geometry = NULL; /* geometry specification */ -char icondata[(ICONSIZ+7)/8*ICONSIZ]; /* icon bitmap data */ +char icondata[ICONSIZ*ICONSIZ/8]; /* icon bitmap data */ int iconwidth = 0, iconheight = 0; char *progname; @@ -246,7 +248,6 @@ init() /* get data and open window */ XSetFont(thedisplay, ourgc, fontid); revgc = XCreateGC(thedisplay, wind, 0, 0); XSetFunction(thedisplay, revgc, GXinvert); - XStoreName(thedisplay, wind, fname == NULL ? progname : fname); XDefineCursor(thedisplay, wind, XCreateFontCursor(thedisplay, XC_diamond_cross)); if (geometry != NULL) { @@ -281,6 +282,12 @@ init() /* get data and open window */ |ButtonMotionMask|StructureNotifyMask |KeyPressMask|ExposureMask); XMapWindow(thedisplay, wind); + /* make sure the image is up */ + do + getevent(); + while (!imready); + /* store name as ready signal */ + XStoreName(thedisplay, wind, fname == NULL ? progname : fname); return; memerr: quiterr("out of memory"); @@ -387,6 +394,7 @@ getevent() /* process the next event */ break; case Expose: redraw(e.e.x, e.e.y, e.e.width, e.e.height); + imready++; break; case ButtonPress: if (e.b.state & (ShiftMask|ControlMask)) @@ -652,13 +660,14 @@ add2icon(y, scan) /* add a scanline to our icon data int y; COLR *scan; { - static char *dp = NULL; static short cerr[ICONSIZ]; + static int ynext; + static char *dp; register int err; - register int x, xi; + register int x, ti; if (iconheight == 0) { /* initialize */ - if (xmax < ICONSIZ && ymax < ICONSIZ) { + if (xmax <= ICONSIZ && ymax <= ICONSIZ) { iconwidth = xmax; iconheight = ymax; } else if (xmax > ymax) { @@ -668,26 +677,24 @@ COLR *scan; iconwidth = ICONSIZ*xmax/ymax; iconheight = ICONSIZ; } + ynext = 0; dp = icondata - 1; } - if (dp == NULL) /* done already */ + if (y < ynext*ymax/iconheight) /* skip this one */ return; - if (y % (ymax/iconheight)) /* skip this one */ - return; err = 0; for (x = 0; x < iconwidth; x++) { if (!(x&7)) *++dp = 0; - xi = x*xmax/iconwidth; - err += normbright(scan[xi]) + cerr[x]; + ti = x*xmax/iconwidth; + err += normbright(scan[ti]) + cerr[x]; if (err > 127) err -= 255; else *dp |= 1<<(x&07); cerr[x] = err >>= 1; } - if (y >= ymax-ymax/iconheight) /* all done */ - dp = NULL; + ynext++; }