77 |
|
|
78 |
|
double exposure = 1.0; /* exposure compensation used */ |
79 |
|
|
80 |
+ |
int wrongformat = 0; /* input in another format? */ |
81 |
+ |
|
82 |
|
GC revgc; /* graphics context with GXinvert */ |
83 |
|
|
84 |
|
XRASTER *ourras; /* our stored image */ |
158 |
|
} else if (i != argc) |
159 |
|
goto userr; |
160 |
|
/* get header */ |
161 |
< |
getheader(fin, headline); |
161 |
> |
getheader(fin, headline, NULL); |
162 |
|
/* get picture dimensions */ |
163 |
< |
if (fgetresolu(&xmax, &ymax, fin) != (YMAJOR|YDECR)) |
164 |
< |
quiterr("bad picture size"); |
163 |
> |
if (wrongformat || fgetresolu(&xmax, &ymax, fin) != (YMAJOR|YDECR)) |
164 |
> |
quiterr("bad picture format"); |
165 |
|
/* set view parameters */ |
166 |
|
if (gotview && setview(&ourview) != NULL) |
167 |
|
gotview = 0; |
185 |
|
{ |
186 |
|
static char *altname[] = {"rview","rpict","pinterp",VIEWSTR,NULL}; |
187 |
|
register char **an; |
188 |
+ |
char fmt[32]; |
189 |
|
|
190 |
|
if (isexpos(s)) |
191 |
|
exposure *= exposval(s); |
192 |
< |
else |
192 |
> |
else if (isformat(s)) { |
193 |
> |
formatval(fmt, s); |
194 |
> |
wrongformat = strcmp(fmt, COLRFMT); |
195 |
> |
} else |
196 |
|
for (an = altname; *an != NULL; an++) |
197 |
|
if (!strncmp(*an, s, strlen(*an))) { |
198 |
|
if (sscanview(&ourview, s+strlen(*an)) > 0) |
246 |
|
if (geometry != NULL) { |
247 |
|
bzero((char *)&oursizhints, sizeof(oursizhints)); |
248 |
|
i = XParseGeometry(geometry, &oursizhints.x, &oursizhints.y, |
249 |
< |
&oursizhints.width, &oursizhints.height); |
249 |
> |
(unsigned *)&oursizhints.width, |
250 |
> |
(unsigned *)&oursizhints.height); |
251 |
|
if ((i&(WidthValue|HeightValue)) == (WidthValue|HeightValue)) |
252 |
|
oursizhints.flags |= USSize; |
253 |
|
else { |
315 |
|
if (ourras == NULL) |
316 |
|
goto fail; |
317 |
|
getmono(); |
318 |
< |
} else if (XMatchVisualInfo(thedisplay,ourscreen,24,TrueColor,&vinfo)) { |
318 |
> |
} else if (XMatchVisualInfo(thedisplay,ourscreen,24,TrueColor,&vinfo) |
319 |
> |
/* kludge for DirectColor */ |
320 |
> |
|| XMatchVisualInfo(thedisplay,ourscreen,24,DirectColor,&vinfo)) { |
321 |
|
ourdata = (unsigned char *)malloc(xmax*ymax*3); |
322 |
|
if (ourdata == NULL) |
323 |
|
goto fail; |
343 |
|
} |
344 |
|
return; |
345 |
|
fail: |
346 |
< |
quit("could not create raster image"); |
346 |
> |
quiterr("could not create raster image"); |
347 |
|
} |
348 |
|
|
349 |
|
|
417 |
|
sprintf(buf, "%.3f", intens(cval)/exposure); |
418 |
|
break; |
419 |
|
case 'l': /* luminance */ |
420 |
< |
sprintf(buf, "%.0fn", bright(cval)*683.0/exposure); |
420 |
> |
sprintf(buf, "%.0fn", luminance(cval)/exposure); |
421 |
|
break; |
422 |
|
case 'c': /* color */ |
423 |
|
comp = pow(2.0, (double)scale); |
452 |
|
XBell(thedisplay, 0); |
453 |
|
return(-1); |
454 |
|
} |
455 |
< |
viewray(rorg, rdir, &ourview, |
455 |
> |
if (viewray(rorg, rdir, &ourview, |
456 |
|
(ekey->x-xoff+.5)/xmax, |
457 |
< |
(ymax-1-ekey->y+yoff+.5)/ymax); |
457 |
> |
(ymax-1-ekey->y+yoff+.5)/ymax) < 0) |
458 |
> |
return(-1); |
459 |
|
printf("%e %e %e ", rorg[0], rorg[1], rorg[2]); |
460 |
|
printf("%e %e %e\n", rdir[0], rdir[1], rdir[2]); |
461 |
|
fflush(stdout); |
611 |
|
register unsigned char *dp; |
612 |
|
register int x, err; |
613 |
|
int y; |
604 |
– |
rgbpixel *inl; |
614 |
|
short *cerr; |
615 |
|
|
616 |
< |
if ((inl = (rgbpixel *)malloc(xmax*sizeof(rgbpixel))) == NULL |
617 |
< |
|| (cerr = (short *)calloc(xmax,sizeof(short))) == NULL) |
609 |
< |
quit("out of memory in getmono"); |
616 |
> |
if ((cerr = (short *)calloc(xmax,sizeof(short))) == NULL) |
617 |
> |
quiterr("out of memory in getmono"); |
618 |
|
dp = ourdata - 1; |
619 |
|
for (y = 0; y < ymax; y++) { |
620 |
< |
picreadline3(y, inl); |
620 |
> |
if (getscan(y) < 0) |
621 |
> |
quiterr("seek error in getmono"); |
622 |
> |
normcolrs(scanline, xmax, scale); |
623 |
|
err = 0; |
624 |
|
for (x = 0; x < xmax; x++) { |
625 |
|
if (!(x&7)) |
626 |
|
*++dp = 0; |
627 |
< |
err += rgb_bright(&inl[x]) + cerr[x]; |
627 |
> |
err += normbright(scanline[x]) + cerr[x]; |
628 |
|
if (err > 127) |
629 |
|
err -= 255; |
630 |
|
else |
632 |
|
cerr[x] = err >>= 1; |
633 |
|
} |
634 |
|
} |
625 |
– |
free((char *)inl); |
635 |
|
free((char *)cerr); |
636 |
|
} |
637 |
|
|
639 |
|
getfull() /* get full (24-bit) data */ |
640 |
|
{ |
641 |
|
int y; |
642 |
< |
|
643 |
< |
for (y = 0; y < ymax; y++) |
644 |
< |
picreadline3(y, (rgbpixel *)(ourdata+y*xmax*3)); |
642 |
> |
register unsigned char *dp; |
643 |
> |
register int x; |
644 |
> |
/* set gamma correction */ |
645 |
> |
setcolrgam(gamcor); |
646 |
> |
/* read and convert file */ |
647 |
> |
dp = ourdata; |
648 |
> |
for (y = 0; y < ymax; y++) { |
649 |
> |
if (getscan(y) < 0) |
650 |
> |
quiterr("seek error in getfull"); |
651 |
> |
if (scale) |
652 |
> |
shiftcolrs(scanline, xmax, scale); |
653 |
> |
colrs_gambs(scanline, xmax); |
654 |
> |
for (x = 0; x < xmax; x++) { |
655 |
> |
*dp++ = scanline[x][RED]; |
656 |
> |
*dp++ = scanline[x][GRN]; |
657 |
> |
*dp++ = scanline[x][BLU]; |
658 |
> |
} |
659 |
> |
} |
660 |
|
} |
661 |
|
|
662 |
|
|
695 |
|
if (scanpos == NULL || scanpos[y] == -1) |
696 |
|
return(-1); |
697 |
|
if (fseek(fin, scanpos[y], 0) == -1) |
698 |
< |
quit("fseek error"); |
698 |
> |
quiterr("fseek error"); |
699 |
|
cury = y; |
700 |
|
} else if (scanpos != NULL) |
701 |
|
scanpos[y] = ftell(fin); |
741 |
|
register int i, val; |
742 |
|
|
743 |
|
for (i = 0; i < 256; i++) { |
744 |
< |
val = pow(i/256.0, 1.0/gamcor) * 256.0; |
744 |
> |
val = pow((i+0.5)/256.0, 1.0/gamcor) * 256.0; |
745 |
|
map[0][i] = map[1][i] = map[2][i] = val; |
746 |
|
} |
747 |
|
} |