30 |
|
#include "pic.h" |
31 |
|
#include "x11raster.h" |
32 |
|
#include "random.h" |
33 |
+ |
#include "x11icon.h" |
34 |
|
|
35 |
|
#define FONTNAME "8x13" /* text font we'll use */ |
36 |
|
|
78 |
|
|
79 |
|
double exposure = 1.0; /* exposure compensation used */ |
80 |
|
|
81 |
+ |
int wrongformat = 0; /* input in another format? */ |
82 |
+ |
|
83 |
|
GC revgc; /* graphics context with GXinvert */ |
84 |
|
|
85 |
|
XRASTER *ourras; /* our stored image */ |
159 |
|
} else if (i != argc) |
160 |
|
goto userr; |
161 |
|
/* get header */ |
162 |
< |
getheader(fin, headline); |
162 |
> |
getheader(fin, headline, NULL); |
163 |
|
/* get picture dimensions */ |
164 |
< |
if (fgetresolu(&xmax, &ymax, fin) != (YMAJOR|YDECR)) |
165 |
< |
quiterr("bad picture size"); |
164 |
> |
if (wrongformat || fgetresolu(&xmax, &ymax, fin) != (YMAJOR|YDECR)) |
165 |
> |
quiterr("bad picture format"); |
166 |
|
/* set view parameters */ |
167 |
|
if (gotview && setview(&ourview) != NULL) |
168 |
|
gotview = 0; |
186 |
|
{ |
187 |
|
static char *altname[] = {"rview","rpict","pinterp",VIEWSTR,NULL}; |
188 |
|
register char **an; |
189 |
+ |
char fmt[32]; |
190 |
|
|
191 |
|
if (isexpos(s)) |
192 |
|
exposure *= exposval(s); |
193 |
< |
else |
193 |
> |
else if (isformat(s)) { |
194 |
> |
formatval(fmt, s); |
195 |
> |
wrongformat = strcmp(fmt, COLRFMT); |
196 |
> |
} else |
197 |
|
for (an = altname; *an != NULL; an++) |
198 |
|
if (!strncmp(*an, s, strlen(*an))) { |
199 |
|
if (sscanview(&ourview, s+strlen(*an)) > 0) |
205 |
|
|
206 |
|
init() /* get data and open window */ |
207 |
|
{ |
208 |
+ |
XWMHints ourxwmhints; |
209 |
|
XSetWindowAttributes ourwinattr; |
210 |
|
XSizeHints oursizhints; |
211 |
|
register int i; |
248 |
|
if (geometry != NULL) { |
249 |
|
bzero((char *)&oursizhints, sizeof(oursizhints)); |
250 |
|
i = XParseGeometry(geometry, &oursizhints.x, &oursizhints.y, |
251 |
< |
&oursizhints.width, &oursizhints.height); |
251 |
> |
(unsigned *)&oursizhints.width, |
252 |
> |
(unsigned *)&oursizhints.height); |
253 |
|
if ((i&(WidthValue|HeightValue)) == (WidthValue|HeightValue)) |
254 |
|
oursizhints.flags |= USSize; |
255 |
|
else { |
268 |
|
} |
269 |
|
XSetNormalHints(thedisplay, wind, &oursizhints); |
270 |
|
} |
271 |
+ |
ourxwmhints.flags = InputHint|IconPixmapHint; |
272 |
+ |
ourxwmhints.input = True; |
273 |
+ |
ourxwmhints.icon_pixmap = XCreateBitmapFromData(thedisplay, |
274 |
+ |
wind, x11icon_bits, x11icon_width, x11icon_height); |
275 |
+ |
XSetWMHints(thedisplay, wind, &ourxwmhints); |
276 |
|
XSelectInput(thedisplay, wind, ButtonPressMask|ButtonReleaseMask |
277 |
|
|ButtonMotionMask|StructureNotifyMask |
278 |
|
|KeyPressMask|ExposureMask); |
322 |
|
if (ourras == NULL) |
323 |
|
goto fail; |
324 |
|
getmono(); |
325 |
< |
} else if (XMatchVisualInfo(thedisplay,ourscreen,24,TrueColor,&vinfo)) { |
325 |
> |
} else if (XMatchVisualInfo(thedisplay,ourscreen,24,TrueColor,&vinfo) |
326 |
> |
/* kludge for DirectColor */ |
327 |
> |
|| XMatchVisualInfo(thedisplay,ourscreen,24,DirectColor,&vinfo)) { |
328 |
|
ourdata = (unsigned char *)malloc(xmax*ymax*3); |
329 |
|
if (ourdata == NULL) |
330 |
|
goto fail; |
350 |
|
} |
351 |
|
return; |
352 |
|
fail: |
353 |
< |
quit("could not create raster image"); |
353 |
> |
quiterr("could not create raster image"); |
354 |
|
} |
355 |
|
|
356 |
|
|
424 |
|
sprintf(buf, "%.3f", intens(cval)/exposure); |
425 |
|
break; |
426 |
|
case 'l': /* luminance */ |
427 |
< |
sprintf(buf, "%.0fn", bright(cval)*683.0/exposure); |
427 |
> |
sprintf(buf, "%.0fL", luminance(cval)/exposure); |
428 |
|
break; |
429 |
|
case 'c': /* color */ |
430 |
|
comp = pow(2.0, (double)scale); |
459 |
|
XBell(thedisplay, 0); |
460 |
|
return(-1); |
461 |
|
} |
462 |
< |
viewray(rorg, rdir, &ourview, |
462 |
> |
if (viewray(rorg, rdir, &ourview, |
463 |
|
(ekey->x-xoff+.5)/xmax, |
464 |
< |
(ymax-1-ekey->y+yoff+.5)/ymax); |
464 |
> |
(ymax-1-ekey->y+yoff+.5)/ymax) < 0) |
465 |
> |
return(-1); |
466 |
|
printf("%e %e %e ", rorg[0], rorg[1], rorg[2]); |
467 |
|
printf("%e %e %e\n", rdir[0], rdir[1], rdir[2]); |
468 |
|
fflush(stdout); |
618 |
|
register unsigned char *dp; |
619 |
|
register int x, err; |
620 |
|
int y; |
604 |
– |
rgbpixel *inline; |
621 |
|
short *cerr; |
622 |
|
|
623 |
< |
if ((inline = (rgbpixel *)malloc(xmax*sizeof(rgbpixel))) == NULL |
624 |
< |
|| (cerr = (short *)calloc(xmax,sizeof(short))) == NULL) |
609 |
< |
quit("out of memory in getmono"); |
623 |
> |
if ((cerr = (short *)calloc(xmax,sizeof(short))) == NULL) |
624 |
> |
quiterr("out of memory in getmono"); |
625 |
|
dp = ourdata - 1; |
626 |
|
for (y = 0; y < ymax; y++) { |
627 |
< |
picreadline3(y, inline); |
627 |
> |
if (getscan(y) < 0) |
628 |
> |
quiterr("seek error in getmono"); |
629 |
> |
normcolrs(scanline, xmax, scale); |
630 |
|
err = 0; |
631 |
|
for (x = 0; x < xmax; x++) { |
632 |
|
if (!(x&7)) |
633 |
|
*++dp = 0; |
634 |
< |
err += rgb_bright(&inline[x]) + cerr[x]; |
634 |
> |
err += normbright(scanline[x]) + cerr[x]; |
635 |
|
if (err > 127) |
636 |
|
err -= 255; |
637 |
|
else |
639 |
|
cerr[x] = err >>= 1; |
640 |
|
} |
641 |
|
} |
625 |
– |
free((char *)inline); |
642 |
|
free((char *)cerr); |
643 |
|
} |
644 |
|
|
646 |
|
getfull() /* get full (24-bit) data */ |
647 |
|
{ |
648 |
|
int y; |
649 |
< |
|
650 |
< |
for (y = 0; y < ymax; y++) |
651 |
< |
picreadline3(y, (rgbpixel *)(ourdata+y*xmax*3)); |
649 |
> |
register unsigned char *dp; |
650 |
> |
register int x; |
651 |
> |
/* set gamma correction */ |
652 |
> |
setcolrgam(gamcor); |
653 |
> |
/* read and convert file */ |
654 |
> |
dp = ourdata; |
655 |
> |
for (y = 0; y < ymax; y++) { |
656 |
> |
if (getscan(y) < 0) |
657 |
> |
quiterr("seek error in getfull"); |
658 |
> |
if (scale) |
659 |
> |
shiftcolrs(scanline, xmax, scale); |
660 |
> |
colrs_gambs(scanline, xmax); |
661 |
> |
for (x = 0; x < xmax; x++) { |
662 |
> |
*dp++ = scanline[x][RED]; |
663 |
> |
*dp++ = scanline[x][GRN]; |
664 |
> |
*dp++ = scanline[x][BLU]; |
665 |
> |
} |
666 |
> |
} |
667 |
|
} |
668 |
|
|
669 |
|
|
702 |
|
if (scanpos == NULL || scanpos[y] == -1) |
703 |
|
return(-1); |
704 |
|
if (fseek(fin, scanpos[y], 0) == -1) |
705 |
< |
quit("fseek error"); |
705 |
> |
quiterr("fseek error"); |
706 |
|
cury = y; |
707 |
|
} else if (scanpos != NULL) |
708 |
|
scanpos[y] = ftell(fin); |
748 |
|
register int i, val; |
749 |
|
|
750 |
|
for (i = 0; i < 256; i++) { |
751 |
< |
val = pow(i/256.0, 1.0/gamcor) * 256.0; |
751 |
> |
val = pow((i+0.5)/256.0, 1.0/gamcor) * 256.0; |
752 |
|
map[0][i] = map[1][i] = map[2][i] = val; |
753 |
|
} |
754 |
|
} |