ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/x11image.c
(Generate patch)

Comparing ray/src/px/x11image.c (file contents):
Revision 2.64 by schorsch, Sun Jul 27 22:12:03 2003 UTC vs.
Revision 2.70 by greg, Fri Jan 7 22:05:30 2005 UTC

# Line 1 | Line 1
1   #ifndef lint
2 < static const char RCSid[] = "$Id";
2 > static const char RCSid[] = "$Id$";
3   #endif
4   /*
5   *  x11image.c - driver for X-windows
# Line 20 | Line 20 | static const char RCSid[] = "$Id";
20  
21   #include  <string.h>
22   #include  <signal.h>
23 + #include  <unistd.h>
24 + #include  <sys/types.h>
25 + #include  <sys/wait.h>
26   #include  <X11/Xlib.h>
27   #include  <X11/cursorfont.h>
28   #include  <X11/Xutil.h>
# Line 27 | Line 30 | static const char RCSid[] = "$Id";
30  
31   #include  "color.h"
32   #include  "tonemap.h"
33 + #include  "clrtab.h"
34   #include  "view.h"
35   #include  "x11raster.h"
36   #include  "random.h"
# Line 94 | Line 98 | double  exposure = 1.0;                        /* exposure compensation use
98  
99   int  wrongformat = 0;                   /* input in another format? */
100  
101 + TMstruct        *tmGlobal;              /* base tone-mapping */
102 + TMstruct        *tmCurrent;             /* curren tone-mapping */
103 +
104   GC      ourgc;                          /* standard graphics context */
105   GC      revgc;                          /* graphics context with GXinvert */
106  
# Line 117 | Line 124 | char  errmsg[128];
124  
125   BYTE  clrtab[256][3];                   /* global color map */
126  
120 extern long  ftell();
127  
122 extern char  *getenv();
123
128   Display  *thedisplay;
129   Atom  closedownAtom, wmProtocolsAtom;
130  
# Line 128 | Line 132 | int  sigrecv;
132  
133   void  onsig(int i) { sigrecv++; }
134  
135 + typedef void doboxf_t(COLR *scn, int n, void *);
136  
137 < main(argc, argv)
138 < int  argc;
139 < char  *argv[];
137 > static gethfunc headline;
138 > static void init(int argc, char **argv);
139 > static void quiterr(char *err);
140 > static int viscmp(XVisualInfo *v1, XVisualInfo *v2);
141 > static void getbestvis(void);
142 > static void getras(void);
143 > static void getevent(void);
144 > static int traceray(int xpos, int ypos);
145 > static int docom(XKeyPressedEvent *ekey);
146 > static void moveimage(XButtonPressedEvent *ebut);
147 > static void getbox(XButtonPressedEvent *ebut);
148 > static void trackrays(XButtonPressedEvent *ebut);
149 > static void revbox(int x0, int y0, int x1, int y1);
150 > static doboxf_t colavg;
151 > static doboxf_t addfix;
152 > static int avgbox(COLOR cavg);
153 > static int dobox(doboxf_t *f, void *p);
154 > static void make_tonemap(void);
155 > static void tmap_colrs(COLR *scn, int len);
156 > static void getmono(void);
157 > static void add2icon(int y, COLR *scan);
158 > static void getfull(void);
159 > static void getgrey(void);
160 > static void getmapped(void);
161 > static void scale_rcolors(XRASTER *xr, double sf);
162 > static int getscan(int y);
163 >
164 >
165 > int
166 > main(int  argc, char  *argv[])
167   {
136        int  headline();
168          int  i;
169          int  pid;
170          
# Line 246 | Line 277 | userr:
277   }
278  
279  
280 < int
281 < headline(s)             /* get relevant info from header */
282 < char  *s;
280 > static int
281 > headline(               /* get relevant info from header */
282 >        char    *s,
283 >        void    *p
284 > )
285   {
286          char  fmt[32];
287  
# Line 262 | Line 295 | char  *s;
295   }
296  
297  
298 < init(argc, argv)                        /* get data and open window */
299 < int argc;
300 < char **argv;
298 > static void
299 > init(                   /* get data and open window */
300 >        int argc,
301 >        char **argv
302 > )
303   {
304          XSetWindowAttributes    ourwinattr;
305          XClassHint      xclshints;
# Line 378 | Line 413 | char **argv;
413   } /* end of init */
414  
415  
416 < quiterr(err)            /* print message and exit */
417 < char  *err;
416 > static void
417 > quiterr(                /* print message and exit */
418 >        char  *err
419 > )
420   {
421          register int  es;
422          int  cs;
# Line 401 | Line 438 | char  *err;
438  
439  
440   static int
441 < viscmp(v1,v2)           /* compare visual to see which is better, descending */
442 < register XVisualInfo    *v1, *v2;
441 > viscmp(         /* compare visual to see which is better, descending */
442 >        register XVisualInfo    *v1,
443 >        register XVisualInfo    *v2
444 > )
445   {
446          int     bad1 = 0, bad2 = 0;
447          register int  *rp;
# Line 442 | Line 481 | register XVisualInfo   *v1, *v2;
481   }
482  
483  
484 < getbestvis()                    /* get the best visual for this screen */
484 > static void
485 > getbestvis(void)                        /* get the best visual for this screen */
486   {
487   #ifdef DEBUG
488   static char  vistype[][12] = {
# Line 524 | Line 564 | static char  vistype[][12] = {
564   }
565  
566  
567 < getras()                                /* get raster file */
567 > static void
568 > getras(void)                            /* get raster file */
569   {
529        XVisualInfo     vinfo;
530
570          if (maxcolors <= 2) {           /* monochrome */
571                  ourdata = (unsigned char *)malloc(ymax*((xmax+7)/8));
572                  if (ourdata == NULL)
# Line 568 | Line 607 | fail:
607   }
608  
609  
610 < getevent()                              /* process the next event */
610 > static void
611 > getevent(void)                          /* process the next event */
612   {
613          XEvent xev;
614  
# Line 623 | Line 663 | getevent()                             /* process the next event */
663   }
664  
665  
666 < traceray(xpos, ypos)                    /* print requested pixel data */
667 < int  xpos, ypos;
666 > static int
667 > traceray(                       /* print requested pixel data */
668 >        int  xpos,
669 >        int  ypos
670 > )
671   {
672          RREAL  hv[2];
673          FVECT  rorg, rdir;
# Line 666 | Line 709 | int  xpos, ypos;
709   }
710  
711  
712 < docom(ekey)                             /* execute command */
713 < XKeyPressedEvent  *ekey;
712 > static int
713 > docom(                          /* execute command */
714 >        XKeyPressedEvent  *ekey
715 > )
716   {
717          char  buf[80];
718          COLOR  cval;
# Line 810 | Line 855 | XKeyPressedEvent  *ekey;
855   }
856  
857  
858 < moveimage(ebut)                         /* shift the image */
859 < XButtonPressedEvent  *ebut;
858 > static void
859 > moveimage(                              /* shift the image */
860 >        XButtonPressedEvent  *ebut
861 > )
862   {
863          XEvent  e;
864          int     mxo, myo;
# Line 835 | Line 882 | XButtonPressedEvent  *ebut;
882   }
883  
884  
885 < getbox(ebut)                            /* get new bbox */
886 < XButtonPressedEvent  *ebut;
885 > static void
886 > getbox(                         /* get new bbox */
887 >        XButtonPressedEvent  *ebut
888 > )
889   {
890          XEvent  e;
891  
# Line 863 | Line 912 | XButtonPressedEvent  *ebut;
912   }
913  
914  
915 < trackrays(ebut)                         /* trace rays as mouse moves */
916 < XButtonPressedEvent  *ebut;
915 > static void
916 > trackrays(                              /* trace rays as mouse moves */
917 >        XButtonPressedEvent  *ebut
918 > )
919   {
920          XEvent  e;
921          unsigned long   lastrept;
# Line 882 | Line 933 | XButtonPressedEvent  *ebut;
933   }
934  
935  
936 < revbox(x0, y0, x1, y1)                  /* draw bbox with reversed lines */
937 < int  x0, y0, x1, y1;
936 > static void
937 > revbox(                 /* draw bbox with reversed lines */
938 >        int  x0,
939 >        int  y0,
940 >        int  x1,
941 >        int  y1
942 > )
943   {
944          revline(x0, y0, x1, y0);
945          revline(x0, y1, x1, y1);
# Line 892 | Line 948 | int  x0, y0, x1, y1;
948   }
949  
950  
951 < void
952 < colavg(scn, n, cavg)
953 < register COLR   *scn;
954 < register int    n;
955 < COLOR   cavg;
951 > static void
952 > colavg(
953 >        register COLR   *scn,
954 >        register int    n,
955 >        void *cavg
956 > )
957   {
958          COLOR   col;
959  
960          while (n--) {
961                  colr_color(col, *scn++);
962 <                addcolor(cavg, col);
962 >                addcolor((COLORV*)cavg, col);
963          }
964   }
965  
966  
967 < int
968 < avgbox(cavg)                            /* average color over current bbox */
969 < COLOR   cavg;
967 > static int
968 > avgbox(                         /* average color over current bbox */
969 >        COLOR   cavg
970 > )
971   {
972          double  d;
973          register int    rval;
974  
975          setcolor(cavg, 0., 0., 0.);
976 <        rval = dobox(colavg, (char *)cavg);
976 >        rval = dobox(colavg, (void *)cavg);
977          if (rval > 0) {
978                  d = 1./rval;
979                  scalecolor(cavg, d);
# Line 924 | Line 982 | COLOR  cavg;
982   }
983  
984  
985 < int
986 < dobox(f, p)                             /* run function over bbox */
987 < void    (*f)();                 /* function to call for each subscan */
988 < char    *p;                     /* pointer to private data */
985 > static int
986 > dobox(                          /* run function over bbox */
987 >        //void  (*f)(),                 /* function to call for each subscan */
988 >        doboxf_t *f,                    /* function to call for each subscan */
989 >        void    *p                      /* pointer to private data */
990 > )
991   {
992          int  left, right, top, bottom;
993          int  y;
# Line 957 | Line 1017 | char   *p;                     /* pointer to private data */
1017   }
1018  
1019  
1020 < void
1021 < addfix(scn, n)                  /* add fixation points to histogram */
1022 < COLR    *scn;
1023 < int     n;
1020 > static void
1021 > addfix(                 /* add fixation points to histogram */
1022 >        COLR    *scn,
1023 >        int     n,
1024 >        void    *p
1025 > )
1026   {
1027 <        if (tmCvColrs(lscan, TM_NOCHROM, scn, n))
1027 >        TMstruct *      tms = (TMstruct *)p;
1028 >        
1029 >        if (tmCvColrs(tms, lscan, TM_NOCHROM, scn, n))
1030                  goto tmerr;
1031 <        if (tmAddHisto(lscan, n, FIXWEIGHT))
1031 >        if (tmAddHisto(tms, lscan, n, FIXWEIGHT))
1032                  goto tmerr;
1033          return;
1034   tmerr:
# Line 972 | Line 1036 | tmerr:
1036   }
1037  
1038  
1039 < make_tonemap()                  /* initialize tone mapping */
1039 > static void
1040 > make_tonemap(void)                      /* initialize tone mapping */
1041   {
1042          int  flags, y;
1043  
# Line 987 | Line 1052 | make_tonemap()                 /* initialize tone mapping */
1052          }
1053          flags = tmflags;                /* histogram adjustment */
1054          if (greyscale) flags |= TM_F_BW;
1055 <        if (tmTop != NULL) {            /* reuse old histogram if one */
1056 <                tmDone(tmTop);
1057 <                tmTop->flags = flags;
1055 >        if (tmGlobal != NULL) {         /* reuse old histogram if one */
1056 >                tmDone(tmCurrent); tmCurrent = NULL;
1057 >                tmGlobal->flags = flags;
1058          } else {                        /* else initialize */
1059                  if ((lscan = (TMbright *)malloc(xmax*sizeof(TMbright))) == NULL)
1060                          goto memerr;
# Line 1001 | Line 1066 | make_tonemap()                 /* initialize tone mapping */
1066                                  == NULL)
1067                          goto memerr;
1068                                                  /* initialize tm library */
1069 <                if (tmInit(flags, stdprims, gamcor) == NULL)
1069 >                tmGlobal = tmInit(flags, stdprims, gamcor);
1070 >                if (tmGlobal == NULL)
1071                          goto memerr;
1072 <                if (tmSetSpace(stdprims, WHTEFFICACY/exposure))
1072 >                if (tmSetSpace(tmGlobal, stdprims, WHTEFFICACY/exposure, NULL))
1073                          goto tmerr;
1074                                                  /* compute picture histogram */
1075                  for (y = 0; y < ymax; y++) {
1076                          getscan(y);
1077 <                        if (tmCvColrs(lscan, TM_NOCHROM, scanline, xmax))
1077 >                        if (tmCvColrs(tmGlobal, lscan, TM_NOCHROM,
1078 >                                        scanline, xmax))
1079                                  goto tmerr;
1080 <                        if (tmAddHisto(lscan, xmax, 1))
1080 >                        if (tmAddHisto(tmGlobal, lscan, xmax, 1))
1081                                  goto tmerr;
1082                  }
1083          }
1084 <        tmDup();                        /* add fixations to duplicate map */
1085 <        dobox(addfix, NULL);
1084 >        tmCurrent = tmDup(tmGlobal);    /* add fixations to duplicate map */
1085 >        dobox(addfix, (void *)tmCurrent);
1086                                          /* (re)compute tone mapping */
1087 <        if (tmComputeMapping(gamcor, 0., 0.))
1087 >        if (tmComputeMapping(tmCurrent, gamcor, 0., 0.))
1088                  goto tmerr;
1089          return;
1090   memerr:
# Line 1027 | Line 1094 | tmerr:
1094   }
1095  
1096  
1097 < tmap_colrs(scn, len)            /* apply tone mapping to scanline */
1098 < register COLR  *scn;
1099 < int  len;
1097 > static void
1098 > tmap_colrs(             /* apply tone mapping to scanline */
1099 >        register COLR  *scn,
1100 >        int  len
1101 > )
1102   {
1103          register BYTE  *ps;
1104  
# Line 1041 | Line 1110 | int  len;
1110          }
1111          if (len > xmax)
1112                  quiterr("code error 1 in tmap_colrs");
1113 <        if (tmCvColrs(lscan, cscan, scn, len))
1113 >        if (tmCvColrs(tmCurrent, lscan, cscan, scn, len))
1114                  goto tmerr;
1115 <        if (tmMapPixels(pscan, lscan, cscan, len))
1115 >        if (tmMapPixels(tmCurrent, pscan, lscan, cscan, len))
1116                  goto tmerr;
1117          ps = pscan;
1118          if (greyscale)
# Line 1066 | Line 1135 | tmerr:
1135   }
1136  
1137  
1138 < getmono()                       /* get monochrome data */
1138 > static void
1139 > getmono(void)                   /* get monochrome data */
1140   {
1141          register unsigned char  *dp;
1142          register int    x, err;
# Line 1098 | Line 1168 | getmono()                      /* get monochrome data */
1168   }
1169  
1170  
1171 < add2icon(y, scan)               /* add a scanline to our icon data */
1172 < int  y;
1173 < COLR  *scan;
1171 > static void
1172 > add2icon(               /* add a scanline to our icon data */
1173 >        int  y,
1174 >        COLR  *scan
1175 > )
1176   {
1177          static short  cerr[ICONSIZ];
1178          static int  ynext;
# Line 1150 | Line 1222 | COLR  *scan;
1222   }
1223  
1224  
1225 < getfull()                       /* get full (24-bit) data */
1225 > static void
1226 > getfull(void)                   /* get full (24-bit) data */
1227   {
1228          int     y;
1229          register uint32 *dp;
# Line 1217 | Line 1290 | getfull()                      /* get full (24-bit) data */
1290   }
1291  
1292  
1293 < getgrey()                       /* get greyscale data */
1293 > static void
1294 > getgrey(void)                   /* get greyscale data */
1295   {
1296          int     y;
1297          register unsigned char  *dp;
# Line 1244 | Line 1318 | getgrey()                      /* get greyscale data */
1318   }
1319  
1320  
1321 < getmapped()                     /* get color-mapped data */
1321 > static void
1322 > getmapped(void)                 /* get color-mapped data */
1323   {
1324          int     y;
1325                                          /* make sure we can do it first */
# Line 1276 | Line 1351 | getmapped()                    /* get color-mapped data */
1351   }
1352  
1353  
1354 < scale_rcolors(xr, sf)                   /* scale color map */
1355 < register XRASTER        *xr;
1356 < double  sf;
1354 > static void
1355 > scale_rcolors(                  /* scale color map */
1356 >        register XRASTER        *xr,
1357 >        double  sf
1358 > )
1359   {
1360          register int    i;
1361          long    maxv;
# Line 1304 | Line 1381 | double sf;
1381   }
1382  
1383  
1384 < getscan(y)
1385 < int  y;
1384 > static int
1385 > getscan(
1386 >        int  y
1387 > )
1388   {
1389          static int  trunced = -1;               /* truncated file? */
1390   skipit:

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines