43 |
|
#define ourroot RootWindow(thedisplay,ourscreen) |
44 |
|
#define ourgc DefaultGC(thedisplay,ourscreen) |
45 |
|
|
46 |
+ |
#define revline(x0,y0,x1,y1) XDrawLine(thedisplay,wind,revgc,x0,y0,x1,y1) |
47 |
+ |
|
48 |
|
#define redraw(x,y,w,h) patch_raster(wind,(x)-xoff,(y)-yoff,x,y,w,h,ourras) |
49 |
|
|
50 |
|
double gamcor = 2.2; /* gamma correction */ |
77 |
|
|
78 |
|
double exposure = 1.0; /* exposure compensation used */ |
79 |
|
|
80 |
+ |
GC revgc; /* graphics context with GXinvert */ |
81 |
+ |
|
82 |
|
XRASTER *ourras; /* our stored image */ |
83 |
|
unsigned char *ourdata; /* our image data */ |
84 |
|
|
198 |
|
|
199 |
|
init() /* get data and open window */ |
200 |
|
{ |
201 |
+ |
XSetWindowAttributes ourwinattr; |
202 |
|
XSizeHints oursizhints; |
203 |
|
register int i; |
204 |
|
|
211 |
|
} |
212 |
|
if ((thedisplay = XOpenDisplay(NULL)) == NULL) |
213 |
|
quiterr("can't open display; DISPLAY variable set?"); |
209 |
– |
wind = XCreateSimpleWindow(thedisplay, |
210 |
– |
ourroot, 0, 0, xmax, ymax, BORWIDTH, ourblack, ourwhite); |
211 |
– |
if (wind == 0) |
212 |
– |
quiterr("can't create window"); |
214 |
|
if (maxcolors == 0) { /* get number of available colors */ |
215 |
|
i = DisplayPlanes(thedisplay,ourscreen); |
216 |
|
maxcolors = i > 8 ? 256 : 1<<i; |
217 |
|
if (maxcolors > 4) maxcolors -= 2; |
218 |
|
} |
219 |
+ |
/* store image */ |
220 |
+ |
getras(); |
221 |
+ |
/* open window */ |
222 |
+ |
ourwinattr.border_pixel = ourblack; |
223 |
+ |
ourwinattr.background_pixel = ourwhite; |
224 |
+ |
wind = XCreateWindow(thedisplay, ourroot, 0, 0, xmax, ymax, BORWIDTH, |
225 |
+ |
0, InputOutput, ourras->visual, |
226 |
+ |
CWBackPixel|CWBorderPixel, &ourwinattr); |
227 |
+ |
if (wind == 0) |
228 |
+ |
quiterr("can't create window"); |
229 |
+ |
width = xmax; |
230 |
+ |
height = ymax; |
231 |
|
fontid = XLoadFont(thedisplay, FONTNAME); |
232 |
|
if (fontid == 0) |
233 |
|
quiterr("can't get font"); |
234 |
|
XSetFont(thedisplay, ourgc, fontid); |
235 |
+ |
revgc = XCreateGC(thedisplay, wind, 0, 0); |
236 |
+ |
XSetFunction(thedisplay, revgc, GXinvert); |
237 |
|
XStoreName(thedisplay, wind, fname == NULL ? progname : fname); |
238 |
|
XDefineCursor(thedisplay, wind, XCreateFontCursor(thedisplay, |
239 |
|
XC_diamond_cross)); |
259 |
|
} |
260 |
|
XSetNormalHints(thedisplay, wind, &oursizhints); |
261 |
|
} |
247 |
– |
/* store image */ |
248 |
– |
getras(); |
262 |
|
XSelectInput(thedisplay, wind, ButtonPressMask|ButtonReleaseMask |
263 |
|
|ButtonMotionMask|StructureNotifyMask |
264 |
|
|KeyPressMask|ExposureMask); |
308 |
|
if (ourras == NULL) |
309 |
|
goto fail; |
310 |
|
getmono(); |
311 |
< |
} else if (XMatchVisualInfo(thedisplay,ourscreen,24,TrueColor,&vinfo)) { |
311 |
> |
} else if (XMatchVisualInfo(thedisplay,ourscreen,24,TrueColor,&vinfo) |
312 |
> |
/* kludge for DirectColor */ |
313 |
> |
|| XMatchVisualInfo(thedisplay,ourscreen,24,DirectColor,&vinfo)) { |
314 |
|
ourdata = (unsigned char *)malloc(xmax*ymax*3); |
315 |
|
if (ourdata == NULL) |
316 |
|
goto fail; |
336 |
|
} |
337 |
|
return; |
338 |
|
fail: |
339 |
< |
quit("could not create raster image"); |
339 |
> |
quiterr("could not create raster image"); |
340 |
|
} |
341 |
|
|
342 |
|
|
445 |
|
XBell(thedisplay, 0); |
446 |
|
return(-1); |
447 |
|
} |
448 |
< |
viewray(rorg, rdir, &ourview, |
448 |
> |
if (viewray(rorg, rdir, &ourview, |
449 |
|
(ekey->x-xoff+.5)/xmax, |
450 |
< |
(ymax-1-ekey->y+yoff+.5)/ymax); |
450 |
> |
(ymax-1-ekey->y+yoff+.5)/ymax) < 0) |
451 |
> |
return(-1); |
452 |
|
printf("%e %e %e ", rorg[0], rorg[1], rorg[2]); |
453 |
|
printf("%e %e %e\n", rdir[0], rdir[1], rdir[2]); |
454 |
|
fflush(stdout); |
496 |
|
XButtonReleasedEvent b; |
497 |
|
XPointerMovedEvent m; |
498 |
|
} e; |
499 |
< |
int nxo, nyo; |
499 |
> |
int mxo, myo; |
500 |
|
|
501 |
|
XMaskEvent(thedisplay, ButtonReleaseMask|ButtonMotionMask, &e.u); |
502 |
|
while (e.u.type == MotionNotify) { |
503 |
< |
nxo = xoff + e.m.x - ebut->x; |
504 |
< |
nyo = yoff + e.m.y - ebut->y; |
505 |
< |
revbox(nxo, nyo, nxo+xmax, nyo+ymax); |
503 |
> |
mxo = e.m.x; |
504 |
> |
myo = e.m.y; |
505 |
> |
revline(ebut->x, ebut->y, mxo, myo); |
506 |
> |
revbox(xoff+mxo-ebut->x, yoff+myo-ebut->y, |
507 |
> |
xoff+mxo-ebut->x+xmax, yoff+myo-ebut->y+ymax); |
508 |
|
XMaskEvent(thedisplay,ButtonReleaseMask|ButtonMotionMask,&e.u); |
509 |
< |
revbox(nxo, nyo, nxo+xmax, nyo+ymax); |
509 |
> |
revline(ebut->x, ebut->y, mxo, myo); |
510 |
> |
revbox(xoff+mxo-ebut->x, yoff+myo-ebut->y, |
511 |
> |
xoff+mxo-ebut->x+xmax, yoff+myo-ebut->y+ymax); |
512 |
|
} |
513 |
|
xoff += e.b.x - ebut->x; |
514 |
|
yoff += e.b.y - ebut->y; |
552 |
|
revbox(x0, y0, x1, y1) /* draw box with reversed lines */ |
553 |
|
int x0, y0, x1, y1; |
554 |
|
{ |
555 |
< |
static GC mygc = 0; |
555 |
> |
revline(x0, y0, x1, y0); |
556 |
> |
revline(x0, y1, x1, y1); |
557 |
> |
revline(x0, y0, x0, y1); |
558 |
> |
revline(x1, y0, x1, y1); |
559 |
> |
} |
560 |
|
|
537 |
– |
if (mygc == 0) { |
538 |
– |
mygc = XCreateGC(thedisplay, wind, 0, 0); |
539 |
– |
XSetFunction(thedisplay, mygc, GXinvert); |
540 |
– |
} |
541 |
– |
XDrawLine(thedisplay, wind, mygc, x0, y0, x1, y0); |
542 |
– |
XDrawLine(thedisplay, wind, mygc, x0, y1, x1, y1); |
543 |
– |
XDrawLine(thedisplay, wind, mygc, x0, y0, x0, y1); |
544 |
– |
XDrawLine(thedisplay, wind, mygc, x1, y0, x1, y1); |
545 |
– |
} /* end of revbox */ |
561 |
|
|
547 |
– |
|
562 |
|
avgbox(clr) /* average color over current box */ |
563 |
|
COLOR clr; |
564 |
|
{ |
604 |
|
register unsigned char *dp; |
605 |
|
register int x, err; |
606 |
|
int y; |
593 |
– |
rgbpixel *inline; |
607 |
|
short *cerr; |
608 |
|
|
609 |
< |
if ((inline = (rgbpixel *)malloc(xmax*sizeof(rgbpixel))) == NULL |
610 |
< |
|| (cerr = (short *)calloc(xmax,sizeof(short))) == NULL) |
598 |
< |
quit("out of memory in getmono"); |
609 |
> |
if ((cerr = (short *)calloc(xmax,sizeof(short))) == NULL) |
610 |
> |
quiterr("out of memory in getmono"); |
611 |
|
dp = ourdata - 1; |
612 |
|
for (y = 0; y < ymax; y++) { |
613 |
< |
picreadline3(y, inline); |
613 |
> |
if (getscan(y) < 0) |
614 |
> |
quiterr("seek error in getmono"); |
615 |
> |
normcolrs(scanline, xmax, scale); |
616 |
|
err = 0; |
617 |
|
for (x = 0; x < xmax; x++) { |
618 |
|
if (!(x&7)) |
619 |
|
*++dp = 0; |
620 |
< |
err += rgb_bright(&inline[x]) + cerr[x]; |
620 |
> |
err += normbright(scanline[x]) + cerr[x]; |
621 |
|
if (err > 127) |
622 |
|
err -= 255; |
623 |
|
else |
625 |
|
cerr[x] = err >>= 1; |
626 |
|
} |
627 |
|
} |
614 |
– |
free((char *)inline); |
628 |
|
free((char *)cerr); |
629 |
|
} |
630 |
|
|
632 |
|
getfull() /* get full (24-bit) data */ |
633 |
|
{ |
634 |
|
int y; |
635 |
< |
|
636 |
< |
for (y = 0; y < ymax; y++) |
637 |
< |
picreadline3(y, (rgbpixel *)(ourdata+y*xmax*3)); |
635 |
> |
register unsigned char *dp; |
636 |
> |
register int x; |
637 |
> |
/* set gamma correction */ |
638 |
> |
setcolrgam(gamcor); |
639 |
> |
/* read and convert file */ |
640 |
> |
dp = ourdata; |
641 |
> |
for (y = 0; y < ymax; y++) { |
642 |
> |
if (getscan(y) < 0) |
643 |
> |
quiterr("seek error in getfull"); |
644 |
> |
if (scale) |
645 |
> |
shiftcolrs(scanline, xmax, scale); |
646 |
> |
colrs_gambs(scanline, xmax); |
647 |
> |
for (x = 0; x < xmax; x++) { |
648 |
> |
*dp++ = scanline[x][RED]; |
649 |
> |
*dp++ = scanline[x][GRN]; |
650 |
> |
*dp++ = scanline[x][BLU]; |
651 |
> |
} |
652 |
> |
} |
653 |
|
} |
654 |
|
|
655 |
|
|
688 |
|
if (scanpos == NULL || scanpos[y] == -1) |
689 |
|
return(-1); |
690 |
|
if (fseek(fin, scanpos[y], 0) == -1) |
691 |
< |
quit("fseek error"); |
691 |
> |
quiterr("fseek error"); |
692 |
|
cury = y; |
693 |
|
} else if (scanpos != NULL) |
694 |
|
scanpos[y] = ftell(fin); |
734 |
|
register int i, val; |
735 |
|
|
736 |
|
for (i = 0; i < 256; i++) { |
737 |
< |
val = pow(i/256.0, 1.0/gamcor) * 256.0; |
737 |
> |
val = pow((i+0.5)/256.0, 1.0/gamcor) * 256.0; |
738 |
|
map[0][i] = map[1][i] = map[2][i] = val; |
739 |
|
} |
740 |
|
} |