--- ray/src/px/x11image.c 1991/05/03 12:01:44 1.21 +++ ray/src/px/x11image.c 1991/05/23 12:00:38 1.24 @@ -81,8 +81,6 @@ 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 */ @@ -250,6 +248,7 @@ init() /* get data and open window */ XSetFunction(thedisplay, revgc, GXinvert); XDefineCursor(thedisplay, wind, XCreateFontCursor(thedisplay, XC_diamond_cross)); + XStoreName(thedisplay, wind, fname == NULL ? progname : fname); if (geometry != NULL) { bzero((char *)&oursizhints, sizeof(oursizhints)); i = XParseGeometry(geometry, &oursizhints.x, &oursizhints.y, @@ -282,12 +281,6 @@ 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"); @@ -394,7 +387,6 @@ 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)) @@ -629,7 +621,7 @@ getmono() /* get monochrome data */ { register unsigned char *dp; register int x, err; - int y; + int y, errp; short *cerr; if ((cerr = (short *)calloc(xmax,sizeof(short))) == NULL) @@ -644,12 +636,14 @@ getmono() /* get monochrome data */ for (x = 0; x < xmax; x++) { if (!(x&7)) *++dp = 0; + errp = err; err += normbright(scanline[x]) + cerr[x]; if (err > 127) err -= 255; else *dp |= 1<<(7-(x&07)); - cerr[x] = err >>= 1; + err /= 3; + cerr[x] = err + errp; } } free((char *)cerr); @@ -665,6 +659,7 @@ COLR *scan; static char *dp; register int err; register int x, ti; + int errp; if (iconheight == 0) { /* initialize */ if (xmax <= ICONSIZ && ymax <= ICONSIZ) { @@ -673,8 +668,12 @@ COLR *scan; } else if (xmax > ymax) { iconwidth = ICONSIZ; iconheight = ICONSIZ*ymax/xmax; + if (iconheight < 1) + iconheight = 1; } else { iconwidth = ICONSIZ*xmax/ymax; + if (iconwidth < 1) + iconwidth = 1; iconheight = ICONSIZ; } ynext = 0; @@ -686,13 +685,15 @@ COLR *scan; for (x = 0; x < iconwidth; x++) { if (!(x&7)) *++dp = 0; + errp = err; ti = x*xmax/iconwidth; err += normbright(scan[ti]) + cerr[x]; if (err > 127) err -= 255; else *dp |= 1<<(x&07); - cerr[x] = err >>= 1; + err /= 3; + cerr[x] = err + errp; } ynext++; }