--- ray/src/px/ximage.c 1989/07/24 10:45:12 1.8 +++ ray/src/px/ximage.c 1989/11/29 17:42:27 1.16 @@ -29,6 +29,8 @@ static char SCCSid[] = "$SunId$ LBL"; #include "pic.h" +#include "random.h" + #define controlshift(e) (((XButtonEvent *)(e))->detail & (ShiftMask|ControlMask)) #define FONTNAME "9x15" /* text font we'll use */ @@ -38,7 +40,7 @@ static char SCCSid[] = "$SunId$ LBL"; #define BORWIDTH 5 /* border width */ #define BARHEIGHT 25 /* menu bar size */ -double gamcor = 2.0; /* gamma correction */ +double gamcor = 2.2; /* gamma correction */ XRASTER *ourras = NULL; /* our stored raster image */ @@ -141,7 +143,7 @@ char *argv[]; /* get header */ getheader(fin, headline); /* get picture dimensions */ - if (fscanf(fin, "-Y %d +X %d\n", &ymax, &xmax) != 2) + if (fgetresolu(&xmax, &ymax, fin) != (YMAJOR|YDECR)) quiterr("bad picture size"); /* set view parameters */ if (gotview) { @@ -360,6 +362,7 @@ XKeyEvent *ekey; { char buf[80]; COLOR cval; + Color cvx; char *cp; int n; double comp; @@ -370,7 +373,7 @@ XKeyEvent *ekey; return(0); switch (*cp) { /* interpret command */ case 'q': - case CTRL(D): /* quiterr */ + case CTRL(D): /* quit */ quit(0); case '\n': case '\r': @@ -384,7 +387,7 @@ XKeyEvent *ekey; sprintf(buf, "%-3g", intens(cval)/exposure); break; case 'l': /* luminance */ - sprintf(buf, "%-3gL", bright(cval)*683.0/exposure); + sprintf(buf, "%-3gn", bright(cval)*683.0/exposure); break; case 'c': /* color */ comp = pow(2.0, (double)scale); @@ -397,6 +400,17 @@ XKeyEvent *ekey; XText(wind, box.xmin, box.ymin, buf, strlen(buf), fontid, BlackPixel, WhitePixel); return(0); + case 'i': /* identify (contour) */ + if (ourras->pixels == NULL) + return(-1); + n = ourras->data.bz[ekey->x-xoff+BZPixmapSize(xmax,ekey->y-yoff)]; + n = ourras->pmap[n]; + cvx.pixel = ourras->cdefs[n].pixel; + cvx.red = random() & 65535; + cvx.green = random() & 65535; + cvx.blue = random() & 65535; + XStoreColor(&cvx); + return(0); case 'p': /* position */ sprintf(buf, "(%d,%d)", ekey->x-xoff, ymax-1-ekey->y+yoff); XText(wind, ekey->x, ekey->y, buf, strlen(buf), @@ -430,6 +444,7 @@ XKeyEvent *ekey; /* fall through */ case CTRL(R): /* redraw */ case CTRL(L): + unmap_rcolors(ourras); XClear(wind); return(redraw(0, 0, width, height)); case ' ': /* clear */ @@ -603,24 +618,26 @@ register XRASTER *xr; double sf; { register int i; - int maxv; + long maxv; + if (xr->pixels == NULL) + return; + sf = pow(sf, 1.0/gamcor); - maxv = (1<<16) / sf; + maxv = 65535/sf; for (i = xr->ncolors; i--; ) { - xr->cdefs[i].red = xr->cdefs[i].red >= maxv ? - (1<<16)-1 : + xr->cdefs[i].red = xr->cdefs[i].red > maxv ? + 65535 : xr->cdefs[i].red * sf; - xr->cdefs[i].green = xr->cdefs[i].green >= maxv ? - (1<<16)-1 : + xr->cdefs[i].green = xr->cdefs[i].green > maxv ? + 65535 : xr->cdefs[i].green * sf; - xr->cdefs[i].blue = xr->cdefs[i].blue >= maxv ? - (1<<16)-1 : + xr->cdefs[i].blue = xr->cdefs[i].blue > maxv ? + 65535 : xr->cdefs[i].blue * sf; } - if (xr->pixels != NULL) - XStoreColors(xr->ncolors, xr->cdefs); + XStoreColors(xr->ncolors, xr->cdefs); } @@ -648,35 +665,20 @@ picreadline3(y, l3) /* read in 3-byte scanline */ int y; register rgbpixel *l3; { - register BYTE *l4; - register int shift, c; - int i; - + register int i; + /* read scanline */ if (getscan(y) < 0) quiterr("cannot seek for picreadline"); /* convert scanline */ - for (l4=scanline[0], i=xmax; i--; l4+=4, l3++) { - shift = l4[EXP] - COLXS + scale; - if (shift >= 8) { - l3->r = l3->g = l3->b = 255; - } else if (shift <= -8) { - l3->r = l3->g = l3->b = 0; - } else if (shift > 0) { - c = l4[RED] << shift; - l3->r = c > 255 ? 255 : c; - c = l4[GRN] << shift; - l3->g = c > 255 ? 255 : c; - c = l4[BLU] << shift; - l3->b = c > 255 ? 255 : c; - } else if (shift < 0) { - l3->r = l4[RED] >> -shift; - l3->g = l4[GRN] >> -shift; - l3->b = l4[BLU] >> -shift; - } else { - l3->r = l4[RED]; - l3->g = l4[GRN]; - l3->b = l4[BLU]; - } + if (scale != 0) + for (i = 0; i < xmax; i++) + if (scanline[i][EXP]+scale >= 0) + scanline[i][EXP] += scale; + normcolrs(scanline, xmax); + for (i = 0; i < xmax; i++) { + l3[i].r = scanline[i][RED]; + l3[i].g = scanline[i][GRN]; + l3[i].b = scanline[i][BLU]; } }