1 |
– |
/* Copyright (c) 1999 Regents of the University of California */ |
2 |
– |
|
1 |
|
#ifndef lint |
2 |
< |
static char SCCSid[] = "$SunId$ SGI"; |
2 |
> |
static const char RCSid[] = "$Id"; |
3 |
|
#endif |
6 |
– |
|
4 |
|
/* |
5 |
|
* x11image.c - driver for X-windows |
6 |
|
* |
24 |
|
#include <X11/Xutil.h> |
25 |
|
#include <X11/Xatom.h> |
26 |
|
|
30 |
– |
#undef NOPROTO |
31 |
– |
#define NOPROTO 1 |
27 |
|
#include "color.h" |
28 |
|
#include "tonemap.h" |
29 |
|
#include "view.h" |
30 |
|
#include "x11raster.h" |
31 |
|
#include "random.h" |
37 |
– |
#include "resolu.h" |
32 |
|
|
33 |
|
#define FONTNAME "8x13" /* text font we'll use */ |
34 |
|
|
103 |
|
|
104 |
|
struct { |
105 |
|
int xmin, ymin, xsiz, ysiz; |
106 |
< |
} box = {0, 0, 0, 0}; /* current box */ |
106 |
> |
} bbox = {0, 0, 0, 0}; /* current bbox */ |
107 |
|
|
108 |
|
char *geometry = NULL; /* geometry specification */ |
109 |
|
|
625 |
|
traceray(xpos, ypos) /* print requested pixel data */ |
626 |
|
int xpos, ypos; |
627 |
|
{ |
634 |
– |
extern char *index(); |
628 |
|
FLOAT hv[2]; |
629 |
|
FVECT rorg, rdir; |
630 |
|
COLOR cval; |
631 |
|
register char *cp; |
632 |
|
|
633 |
< |
box.xmin = xpos; box.xsiz = 1; |
634 |
< |
box.ymin = ypos; box.ysiz = 1; |
633 |
> |
bbox.xmin = xpos; bbox.xsiz = 1; |
634 |
> |
bbox.ymin = ypos; bbox.ysiz = 1; |
635 |
|
avgbox(cval); |
636 |
|
scalecolor(cval, 1./exposure); |
637 |
|
pix2loc(hv, &inpres, xpos-xoff, ypos-yoff); |
696 |
|
sprintf(buf, "%.3f", intens(cval)/exposure); |
697 |
|
break; |
698 |
|
case 'l': /* luminance */ |
699 |
< |
sprintf(buf, "%.0fL", luminance(cval)/exposure); |
699 |
> |
sprintf(buf, "%.1fL", luminance(cval)/exposure); |
700 |
|
break; |
701 |
|
case 'c': /* color */ |
702 |
|
comp = pow(2.0, (double)scale); |
707 |
|
break; |
708 |
|
} |
709 |
|
XDrawImageString(thedisplay, wind, ourgc, |
710 |
< |
box.xmin, box.ymin+box.ysiz, buf, strlen(buf)); |
710 |
> |
bbox.xmin, bbox.ymin+bbox.ysiz, buf, strlen(buf)); |
711 |
|
return(0); |
712 |
|
case 'i': /* identify (contour) */ |
713 |
|
if (ourras->pixels == NULL) |
769 |
|
sprintf(buf, "%+d", scale); |
770 |
|
remap: |
771 |
|
XDrawImageString(thedisplay, wind, ourgc, |
772 |
< |
box.xmin, box.ymin+box.ysiz, buf, strlen(buf)); |
772 |
> |
bbox.xmin, bbox.ymin+bbox.ysiz, buf, strlen(buf)); |
773 |
|
XFlush(thedisplay); |
774 |
< |
free(ourdata); |
774 |
> |
/* free(ourdata); This is done in XDestroyImage()! */ |
775 |
|
free_raster(ourras); |
776 |
|
getras(); |
777 |
|
/* fall through */ |
800 |
|
redraw(0, 0, width, height); |
801 |
|
return(0); |
802 |
|
case ' ': /* clear */ |
803 |
< |
redraw(box.xmin, box.ymin, box.xsiz, box.ysiz); |
803 |
> |
redraw(bbox.xmin, bbox.ymin, bbox.xsiz, bbox.ysiz); |
804 |
|
return(0); |
805 |
|
default: |
806 |
|
XBell(thedisplay, 0); |
834 |
|
} |
835 |
|
|
836 |
|
|
837 |
< |
getbox(ebut) /* get new box */ |
837 |
> |
getbox(ebut) /* get new bbox */ |
838 |
|
XButtonPressedEvent *ebut; |
839 |
|
{ |
840 |
|
XEvent e; |
841 |
|
|
842 |
|
XMaskEvent(thedisplay, ButtonReleaseMask|ButtonMotionMask, &e); |
843 |
|
while (e.type == MotionNotify) { |
844 |
< |
revbox(ebut->x, ebut->y, box.xmin = e.xmotion.x, box.ymin = e.xmotion.y); |
844 |
> |
revbox(ebut->x, ebut->y, bbox.xmin = e.xmotion.x, bbox.ymin = e.xmotion.y); |
845 |
|
XMaskEvent(thedisplay,ButtonReleaseMask|ButtonMotionMask,&e); |
846 |
< |
revbox(ebut->x, ebut->y, box.xmin, box.ymin); |
846 |
> |
revbox(ebut->x, ebut->y, bbox.xmin, bbox.ymin); |
847 |
|
} |
848 |
< |
box.xmin = e.xbutton.x<0 ? 0 : (e.xbutton.x>=width ? width-1 : e.xbutton.x); |
849 |
< |
box.ymin = e.xbutton.y<0 ? 0 : (e.xbutton.y>=height ? height-1 : e.xbutton.y); |
850 |
< |
if (box.xmin > ebut->x) { |
851 |
< |
box.xsiz = box.xmin - ebut->x + 1; |
852 |
< |
box.xmin = ebut->x; |
848 |
> |
bbox.xmin = e.xbutton.x<0 ? 0 : (e.xbutton.x>=width ? width-1 : e.xbutton.x); |
849 |
> |
bbox.ymin = e.xbutton.y<0 ? 0 : (e.xbutton.y>=height ? height-1 : e.xbutton.y); |
850 |
> |
if (bbox.xmin > ebut->x) { |
851 |
> |
bbox.xsiz = bbox.xmin - ebut->x + 1; |
852 |
> |
bbox.xmin = ebut->x; |
853 |
|
} else { |
854 |
< |
box.xsiz = ebut->x - box.xmin + 1; |
854 |
> |
bbox.xsiz = ebut->x - bbox.xmin + 1; |
855 |
|
} |
856 |
< |
if (box.ymin > ebut->y) { |
857 |
< |
box.ysiz = box.ymin - ebut->y + 1; |
858 |
< |
box.ymin = ebut->y; |
856 |
> |
if (bbox.ymin > ebut->y) { |
857 |
> |
bbox.ysiz = bbox.ymin - ebut->y + 1; |
858 |
> |
bbox.ymin = ebut->y; |
859 |
|
} else { |
860 |
< |
box.ysiz = ebut->y - box.ymin + 1; |
860 |
> |
bbox.ysiz = ebut->y - bbox.ymin + 1; |
861 |
|
} |
862 |
|
} |
863 |
|
|
881 |
|
} |
882 |
|
|
883 |
|
|
884 |
< |
revbox(x0, y0, x1, y1) /* draw box with reversed lines */ |
884 |
> |
revbox(x0, y0, x1, y1) /* draw bbox with reversed lines */ |
885 |
|
int x0, y0, x1, y1; |
886 |
|
{ |
887 |
|
revline(x0, y0, x1, y0); |
900 |
|
COLOR col; |
901 |
|
|
902 |
|
while (n--) { |
903 |
< |
colr_color(col, scn++); |
903 |
> |
colr_color(col, *scn++); |
904 |
|
addcolor(cavg, col); |
905 |
|
} |
906 |
|
} |
907 |
|
|
908 |
|
|
909 |
|
int |
910 |
< |
avgbox(cavg) /* average color over current box */ |
910 |
> |
avgbox(cavg) /* average color over current bbox */ |
911 |
|
COLOR cavg; |
912 |
|
{ |
913 |
|
double d; |
924 |
|
|
925 |
|
|
926 |
|
int |
927 |
< |
dobox(f, p) /* run function over box */ |
927 |
> |
dobox(f, p) /* run function over bbox */ |
928 |
|
int (*f)(); /* function to call for each subscan */ |
929 |
|
char *p; /* pointer to private data */ |
930 |
|
{ |
931 |
|
int left, right, top, bottom; |
932 |
|
int y; |
933 |
|
|
934 |
< |
left = box.xmin - xoff; |
935 |
< |
right = left + box.xsiz; |
934 |
> |
left = bbox.xmin - xoff; |
935 |
> |
right = left + bbox.xsiz; |
936 |
|
if (left < 0) |
937 |
|
left = 0; |
938 |
|
if (right > xmax) |
939 |
|
right = xmax; |
940 |
|
if (left >= right) |
941 |
|
return(0); |
942 |
< |
top = box.ymin - yoff; |
943 |
< |
bottom = top + box.ysiz; |
942 |
> |
top = bbox.ymin - yoff; |
943 |
> |
bottom = top + bbox.ysiz; |
944 |
|
if (top < 0) |
945 |
|
top = 0; |
946 |
|
if (bottom > ymax) |
1093 |
|
cerr[x] = err + errp; |
1094 |
|
} |
1095 |
|
} |
1096 |
< |
free((char *)cerr); |
1096 |
> |
free((void *)cerr); |
1097 |
|
} |
1098 |
|
|
1099 |
|
|
1136 |
|
errp = err; |
1137 |
|
ti = x*xmax/iconwidth; |
1138 |
|
copycolr(clr, scan[ti]); |
1139 |
< |
normcolrs(clr, 1, scale); |
1139 |
> |
normcolrs(&clr, 1, scale); |
1140 |
|
err += normbright(clr) + cerr[x]; |
1141 |
|
if (err > 127) |
1142 |
|
err -= 255; |