--- ray/src/px/x11image.c 1992/10/22 17:51:05 2.16 +++ ray/src/px/x11image.c 1993/02/19 10:46:16 2.21 @@ -193,9 +193,9 @@ char *argv[]; getevent(); /* main loop */ userr: fprintf(stderr, - "Usage: %s [-display disp][-geometry spec][-b][-m][-d][-f][-c ncolors][-e +/-stops] file\n", +"Usage: %s [-di disp][[-ge] spec][-b][-m][-d][-f][-c nclrs][-e +/-stops] pic\n", progname); - quit(1); + exit(1); } @@ -234,12 +234,34 @@ init() /* get data and open window */ getbestvis(); /* store image */ getras(); + /* get size and position */ + bzero((char *)&oursizhints, sizeof(oursizhints)); + oursizhints.width = xmax; oursizhints.height = ymax; + if (geometry != NULL) { + i = XParseGeometry(geometry, &oursizhints.x, &oursizhints.y, + (unsigned *)&oursizhints.width, + (unsigned *)&oursizhints.height); + if ((i&(WidthValue|HeightValue)) == (WidthValue|HeightValue)) + oursizhints.flags |= USSize; + else + oursizhints.flags |= PSize; + if ((i&(XValue|YValue)) == (XValue|YValue)) { + oursizhints.flags |= USPosition; + if (i & XNegative) + oursizhints.x += DisplayWidth(thedisplay, + ourscreen)-1-oursizhints.width-2*BORWIDTH; + if (i & YNegative) + oursizhints.y += DisplayHeight(thedisplay, + ourscreen)-1-oursizhints.height-2*BORWIDTH; + } + } /* open window */ ourwinattr.border_pixel = ourblack; ourwinattr.background_pixel = ourwhite; ourwinattr.colormap = XCreateColormap(thedisplay, ourroot, ourvis.visual, AllocNone); - wind = XCreateWindow(thedisplay, ourroot, 0, 0, xmax, ymax, BORWIDTH, + wind = XCreateWindow(thedisplay, ourroot, oursizhints.x, oursizhints.y, + oursizhints.width, oursizhints.height, BORWIDTH, ourvis.depth, InputOutput, ourvis.visual, CWBackPixel|CWBorderPixel|CWColormap, &ourwinattr); if (wind == 0) @@ -258,29 +280,8 @@ init() /* get data and open window */ 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, - (unsigned *)&oursizhints.width, - (unsigned *)&oursizhints.height); - if ((i&(WidthValue|HeightValue)) == (WidthValue|HeightValue)) - oursizhints.flags |= USSize; - else { - oursizhints.width = xmax; - oursizhints.height = ymax; - oursizhints.flags |= PSize; - } - if ((i&(XValue|YValue)) == (XValue|YValue)) { - oursizhints.flags |= USPosition; - if (i & XNegative) - oursizhints.x += DisplayWidth(thedisplay, - ourscreen)-1-oursizhints.width-2*BORWIDTH; - if (i & YNegative) - oursizhints.y += DisplayHeight(thedisplay, - ourscreen)-1-oursizhints.height-2*BORWIDTH; - } + if (oursizhints.flags) XSetNormalHints(thedisplay, wind, &oursizhints); - } ourxwmhints.flags = InputHint|IconPixmapHint; ourxwmhints.input = True; ourxwmhints.icon_pixmap = XCreateBitmapFromData(thedisplay, @@ -532,7 +533,7 @@ XKeyPressedEvent *ekey; switch (com) { /* interpret command */ case 'q': case CTRL('D'): /* quit */ - quit(0); + quiterr(NULL); case '\n': case '\r': case 'l': @@ -614,6 +615,13 @@ XKeyPressedEvent *ekey; make_rpixmap(ourras, wind); redraw(0, 0, width, height); return(0); + case '0': /* recenter origin */ + if (xoff == 0 & yoff == 0) + return(0); + xoff = yoff = 0; + XClearWindow(thedisplay, wind); + redraw(0, 0, width, height); + return(0); case ' ': /* clear */ redraw(box.xmin, box.ymin, box.xsiz, box.ysiz); return(0); @@ -782,8 +790,7 @@ COLR *scan; static short cerr[ICONSIZ]; static int ynext; static char *dp; - double sf; - COLOR col; + COLR clr; register int err; register int x, ti; int errp; @@ -808,17 +815,15 @@ COLR *scan; } if (y < ynext*ymax/iconheight) /* skip this one */ return; - sf = pow(2.0, (double)(scale+8)); err = 0; for (x = 0; x < iconwidth; x++) { if (!(x&7)) *++dp = 0; errp = err; ti = x*xmax/iconwidth; - colr_color(col, scan[ti]); - ti = sf*bright(col); - if (ti > 255) ti = 255; - err += ti + cerr[x]; + copycolr(clr, scan[ti]); + normcolrs(clr, 1, scale); + err += normbright(clr) + cerr[x]; if (err > 127) err -= 255; else @@ -873,18 +878,20 @@ getgrey() /* get greyscale data */ add2icon(y, scanline); if (scale) shiftcolrs(scanline, xmax, scale); + for (x = 0; x < xmax; x++) + scanline[x][GRN] = normbright(scanline[x]); colrs_gambs(scanline, xmax); if (maxcolors < 256) for (x = 0; x < xmax; x++) - *dp++ = ((long)normbright(scanline[x]) * - maxcolors + 128) >> 8; + *dp++ = ((long)scanline[x][GRN] * + maxcolors + maxcolors/2) >> 8; else for (x = 0; x < xmax; x++) - *dp++ = normbright(scanline[x]); + *dp++ = scanline[x][GRN]; } for (x = 0; x < maxcolors; x++) clrtab[x][RED] = clrtab[x][GRN] = - clrtab[x][BLU] = ((long)x*256+maxcolors/2)/maxcolors; + clrtab[x][BLU] = ((long)x*256 + 128)/maxcolors; }