--- ray/src/px/ximage.c 1989/04/11 17:09:13 1.3 +++ ray/src/px/ximage.c 1989/10/20 20:36:10 1.12 @@ -38,7 +38,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 */ @@ -137,21 +137,17 @@ char *argv[]; sprintf(errmsg, "can't open file \"%s\"", fname); quiterr(errmsg); } - } else - goto userr; - + } /* 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) { - ourview.hresolu = xmax; - ourview.vresolu = ymax; + if (gotview) if (setview(&ourview) != NULL) gotview = 0; - } + if ((scanline = (COLR *)malloc(xmax*sizeof(COLR))) == NULL) quiterr("out of memory"); @@ -170,7 +166,7 @@ userr: headline(s) /* get relevant info from header */ char *s; { - static char *altname[] = {"rview","rpict","VIEW=",NULL}; + static char *altname[] = {"rview","rpict",VIEWSTR,NULL}; register char **an; if (!strncmp(s, "EXPOSURE=", 9)) @@ -347,7 +343,7 @@ redraw(x, y, w, h) /* redraw section of window */ int x, y; int w, h; { - if (map_rcolors(ourras) == NULL) { + if (ourras->ncolors && map_rcolors(ourras) == NULL) { fprintf(stderr, "%s: cannot allocate colors\n", progname); return(-1); } @@ -419,10 +415,8 @@ XKeyEvent *ekey; if (avgbox(cval) == -1) return(-1); n = log(.5/bright(cval))/.69315 - scale; /* truncate */ - if (n == 0) { - XFeep(0); + if (n == 0) return(0); - } scale_rcolors(ourras, pow(2.0, (double)n)); scale += n; sprintf(buf, "%+d", scale); @@ -433,6 +427,7 @@ XKeyEvent *ekey; getras(); /* fall through */ case CTRL(R): /* redraw */ + case CTRL(L): XClear(wind); return(redraw(0, 0, width, height)); case ' ': /* clear */ @@ -651,35 +646,16 @@ 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]; - } + 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]; } } @@ -692,7 +668,7 @@ pixel *l; } -picreadcm(map) /* do gamcor correction */ +picreadcm(map) /* do gamma correction */ colormap map; { extern double pow();