--- ray/src/px/ximage.c 1990/10/13 21:31:45 1.25 +++ ray/src/px/ximage.c 1991/05/06 15:19:03 1.31 @@ -72,6 +72,8 @@ int cury = 0; /* current scan location */ double exposure = 1.0; /* exposure compensation used */ +int wrongformat = 0; /* input in another format */ + struct { int xmin, ymin, xsiz, ysiz; } box = {0, 0, 0, 0}; /* current box */ @@ -141,9 +143,9 @@ char *argv[]; } } /* get header */ - getheader(fin, headline); + getheader(fin, headline, NULL); /* get picture dimensions */ - if (fgetresolu(&xmax, &ymax, fin) != (YMAJOR|YDECR)) + if (wrongformat || fgetresolu(&xmax, &ymax, fin) != (YMAJOR|YDECR)) quiterr("bad picture size"); /* set view parameters */ if (gotview && setview(&ourview) != NULL) @@ -168,10 +170,14 @@ char *s; { static char *altname[] = {"rview","rpict",VIEWSTR,NULL}; register char **an; + char fmt[32]; if (isexpos(s)) exposure *= exposval(s); - else + else if (isformat(s)) { + formatval(fmt, s); + wrongformat = strcmp(fmt, COLRFMT); + } else for (an = altname; *an != NULL; an++) if (!strncmp(*an, s, strlen(*an))) { if (sscanview(&ourview, s+strlen(*an)) > 0) @@ -287,7 +293,7 @@ getras() /* get raster file */ } return; memerr: - quit("out of memory"); + quiterr("out of memory"); } @@ -373,7 +379,7 @@ XKeyEvent *ekey; sprintf(buf, "%.3f", intens(cval)/exposure); break; case 'l': /* luminance */ - sprintf(buf, "%.0fn", bright(cval)*683.0/exposure); + sprintf(buf, "%.0fL", luminance(cval)/exposure); break; case 'c': /* color */ comp = pow(2.0, (double)scale); @@ -542,13 +548,13 @@ getmono() /* get monochrome data */ { register unsigned short *dp; register int x, err; - int y; + int y, errp; rgbpixel *inl; short *cerr; if ((inl = (rgbpixel *)malloc(xmax*sizeof(rgbpixel))) == NULL || (cerr = (short *)calloc(xmax,sizeof(short))) == NULL) - quit("out of memory in getmono"); + quiterr("out of memory in getmono"); dp = ourras->data.m - 1; for (y = 0; y < ymax; y++) { picreadline3(y, inl); @@ -556,12 +562,14 @@ getmono() /* get monochrome data */ for (x = 0; x < xmax; x++) { if (!(x&0xf)) *++dp = 0; + errp = err; err += rgb_bright(&inl[x]) + cerr[x]; if (err > 127) err -= 255; else *dp |= 1<<(x&0xf); - cerr[x] = err >>= 1; + err /= 3; + cerr[x] = err + errp; } } free((char *)inl); @@ -635,7 +643,7 @@ int y; if (scanpos == NULL || scanpos[y] == -1) return(-1); if (fseek(fin, scanpos[y], 0) == -1) - quit("fseek error"); + quiterr("fseek error"); cury = y; } else if (scanpos != NULL) scanpos[y] = ftell(fin); @@ -681,7 +689,7 @@ colormap map; register int i, val; for (i = 0; i < 256; i++) { - val = pow(i/256.0, 1.0/gamcor) * 256.0; + val = pow((i+0.5)/256.0, 1.0/gamcor) * 256.0; map[0][i] = map[1][i] = map[2][i] = val; } }