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.56 by greg, Sat Feb 22 02:07:28 2003 UTC vs.
Revision 2.66 by schorsch, Sun Mar 28 20:33:14 2004 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 18 | Line 18 | static const char      RCSid[] = "$Id$";
18  
19   #include  "standard.h"
20  
21 + #include  <string.h>
22   #include  <signal.h>
23 + #include  <unistd.h>
24 + #include  <sys/types.h>
25 + #include  <wait.h>
26   #include  <X11/Xlib.h>
27   #include  <X11/cursorfont.h>
28   #include  <X11/Xutil.h>
# Line 26 | 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 116 | Line 121 | char  errmsg[128];
121  
122   BYTE  clrtab[256][3];                   /* global color map */
123  
119 extern long  ftell();
124  
121 extern char  *getenv();
122
125   Display  *thedisplay;
126   Atom  closedownAtom, wmProtocolsAtom;
127  
128   int  sigrecv;
129  
130 < int  onsig() { sigrecv++; }
130 > void  onsig(int i) { sigrecv++; }
131  
132 + typedef void doboxf_t(COLR *scn, int n, void *);
133  
134 < main(argc, argv)
135 < int  argc;
136 < char  *argv[];
134 > static gethfunc headline;
135 > static void init(int argc, char **argv);
136 > static void quiterr(char *err);
137 > static int viscmp(XVisualInfo *v1, XVisualInfo *v2);
138 > static void getbestvis(void);
139 > static void getras(void);
140 > static void getevent(void);
141 > static int traceray(int xpos, int ypos);
142 > static int docom(XKeyPressedEvent *ekey);
143 > static void moveimage(XButtonPressedEvent *ebut);
144 > static void getbox(XButtonPressedEvent *ebut);
145 > static void trackrays(XButtonPressedEvent *ebut);
146 > static void revbox(int x0, int y0, int x1, int y1);
147 > static doboxf_t colavg;
148 > static doboxf_t addfix;
149 > static int avgbox(COLOR cavg);
150 > static int dobox(doboxf_t *f, void *p);
151 > static void make_tonemap(void);
152 > static void tmap_colrs(COLR *scn, int len);
153 > static void getmono(void);
154 > static void add2icon(int y, COLR *scan);
155 > static void getfull(void);
156 > static void getgrey(void);
157 > static void getmapped(void);
158 > static void scale_rcolors(XRASTER *xr, double sf);
159 > static int getscan(int y);
160 >
161 >
162 > int
163 > main(int  argc, char  *argv[])
164   {
135        int  headline();
165          int  i;
166          int  pid;
167          
# Line 245 | Line 274 | userr:
274   }
275  
276  
277 < int
278 < headline(s)             /* get relevant info from header */
279 < char  *s;
277 > static int
278 > headline(               /* get relevant info from header */
279 >        char    *s,
280 >        void    *p
281 > )
282   {
283          char  fmt[32];
284  
# Line 261 | Line 292 | char  *s;
292   }
293  
294  
295 < init(argc, argv)                        /* get data and open window */
296 < int argc;
297 < char **argv;
295 > static void
296 > init(                   /* get data and open window */
297 >        int argc,
298 >        char **argv
299 > )
300   {
301          XSetWindowAttributes    ourwinattr;
302          XClassHint      xclshints;
# Line 377 | Line 410 | char **argv;
410   } /* end of init */
411  
412  
413 < quiterr(err)            /* print message and exit */
414 < char  *err;
413 > static void
414 > quiterr(                /* print message and exit */
415 >        char  *err
416 > )
417   {
418          register int  es;
419          int  cs;
420  
421 <        if (es = err != NULL)
421 >        if ( (es = err != NULL) )
422                  fprintf(stderr, "%s: %s: %s\n", progname,
423                                  fname==NULL?"<stdin>":fname, err);
424          if (thedisplay != NULL)
425                  XCloseDisplay(thedisplay);
426 <        if (parent < 0 & sigrecv == 0)
426 >        if ((parent < 0) & (sigrecv == 0))
427                  kill(getppid(), SIGCONT);
428          while (parent > 0 && wait(&cs) != -1) { /* wait for any children */
429                  if (es == 0)
# Line 400 | Line 435 | char  *err;
435  
436  
437   static int
438 < viscmp(v1,v2)           /* compare visual to see which is better, descending */
439 < register XVisualInfo    *v1, *v2;
438 > viscmp(         /* compare visual to see which is better, descending */
439 >        register XVisualInfo    *v1,
440 >        register XVisualInfo    *v2
441 > )
442   {
443          int     bad1 = 0, bad2 = 0;
444          register int  *rp;
# Line 441 | Line 478 | register XVisualInfo   *v1, *v2;
478   }
479  
480  
481 < getbestvis()                    /* get the best visual for this screen */
481 > static void
482 > getbestvis(void)                        /* get the best visual for this screen */
483   {
484   #ifdef DEBUG
485   static char  vistype[][12] = {
# Line 493 | Line 531 | static char  vistype[][12] = {
531          if (viscmp(&xvi[i],&ourvis) > 0)
532                  quiterr("inadequate visuals on this screen");
533                                          /* OK, we'll use it */
534 <        copystruct(&ourvis, &xvi[i]);
534 >        ourvis = xvi[i];
535   #ifdef DEBUG
536          fprintf(stderr, "Selected visual type %s, depth %d\n",
537                          vistype[ourvis.class], ourvis.depth);
# Line 523 | Line 561 | static char  vistype[][12] = {
561   }
562  
563  
564 < getras()                                /* get raster file */
564 > static void
565 > getras(void)                            /* get raster file */
566   {
528        XVisualInfo     vinfo;
529
567          if (maxcolors <= 2) {           /* monochrome */
568                  ourdata = (unsigned char *)malloc(ymax*((xmax+7)/8));
569                  if (ourdata == NULL)
# Line 536 | Line 573 | getras()                               /* get raster file */
573                  if (ourras == NULL)
574                          goto fail;
575                  getmono();
576 <        } else if (ourvis.class == TrueColor | ourvis.class == DirectColor) {
577 <                int  datsiz = ourvis.depth>16 ? sizeof(int4) : sizeof(int2);
576 >        } else if ((ourvis.class == TrueColor) | (ourvis.class == DirectColor)) {
577 >                int  datsiz = ourvis.depth>16 ? sizeof(int32) : sizeof(int16);
578                  ourdata = (unsigned char *)malloc(datsiz*xmax*ymax);
579                  if (ourdata == NULL)
580                          goto fail;
# Line 567 | Line 604 | fail:
604   }
605  
606  
607 < getevent()                              /* process the next event */
607 > static void
608 > getevent(void)                          /* process the next event */
609   {
610          XEvent xev;
611  
# Line 584 | Line 622 | getevent()                             /* process the next event */
622                  map_rcolors(ourras, wind);
623                  if (fast)
624                          make_rpixmap(ourras, wind);
625 <                if (!sequential & parent < 0 & sigrecv == 0) {
625 >                if ((!sequential) & (parent < 0) & (sigrecv == 0)) {
626                          kill(getppid(), SIGCONT);
627                          sigrecv--;
628                  }
# Line 622 | Line 660 | getevent()                             /* process the next event */
660   }
661  
662  
663 < traceray(xpos, ypos)                    /* print requested pixel data */
664 < int  xpos, ypos;
663 > static int
664 > traceray(                       /* print requested pixel data */
665 >        int  xpos,
666 >        int  ypos
667 > )
668   {
669 <        extern char  *index();
629 <        FLOAT  hv[2];
669 >        RREAL  hv[2];
670          FVECT  rorg, rdir;
671          COLOR  cval;
672          register char  *cp;
# Line 666 | Line 706 | int  xpos, ypos;
706   }
707  
708  
709 < docom(ekey)                             /* execute command */
710 < XKeyPressedEvent  *ekey;
709 > static int
710 > docom(                          /* execute command */
711 >        XKeyPressedEvent  *ekey
712 > )
713   {
714          char  buf[80];
715          COLOR  cval;
716          XColor  cvx;
717          int  com, n;
718          double  comp;
719 <        FLOAT  hv[2];
719 >        RREAL  hv[2];
720  
721          n = XLookupString(ekey, buf, sizeof(buf), NULL, NULL);
722          if (n == 0)
# Line 794 | Line 836 | XKeyPressedEvent  *ekey;
836                  free_rpixmap(ourras);
837                  return(0);
838          case '0':                               /* recenter origin */
839 <                if (xoff == 0 & yoff == 0)
839 >                if ((xoff == 0) & (yoff == 0))
840                          return(0);
841                  xoff = yoff = 0;
842                  XClearWindow(thedisplay, wind);
# Line 810 | Line 852 | XKeyPressedEvent  *ekey;
852   }
853  
854  
855 < moveimage(ebut)                         /* shift the image */
856 < XButtonPressedEvent  *ebut;
855 > static void
856 > moveimage(                              /* shift the image */
857 >        XButtonPressedEvent  *ebut
858 > )
859   {
860          XEvent  e;
861          int     mxo, myo;
# Line 835 | Line 879 | XButtonPressedEvent  *ebut;
879   }
880  
881  
882 < getbox(ebut)                            /* get new bbox */
883 < XButtonPressedEvent  *ebut;
882 > static void
883 > getbox(                         /* get new bbox */
884 >        XButtonPressedEvent  *ebut
885 > )
886   {
887          XEvent  e;
888  
# Line 863 | Line 909 | XButtonPressedEvent  *ebut;
909   }
910  
911  
912 < trackrays(ebut)                         /* trace rays as mouse moves */
913 < XButtonPressedEvent  *ebut;
912 > static void
913 > trackrays(                              /* trace rays as mouse moves */
914 >        XButtonPressedEvent  *ebut
915 > )
916   {
917          XEvent  e;
918          unsigned long   lastrept;
# Line 882 | Line 930 | XButtonPressedEvent  *ebut;
930   }
931  
932  
933 < revbox(x0, y0, x1, y1)                  /* draw bbox with reversed lines */
934 < int  x0, y0, x1, y1;
933 > static void
934 > revbox(                 /* draw bbox with reversed lines */
935 >        int  x0,
936 >        int  y0,
937 >        int  x1,
938 >        int  y1
939 > )
940   {
941          revline(x0, y0, x1, y0);
942          revline(x0, y1, x1, y1);
# Line 892 | Line 945 | int  x0, y0, x1, y1;
945   }
946  
947  
948 < int
949 < colavg(scn, n, cavg)
950 < register COLR   *scn;
951 < register int    n;
952 < COLOR   cavg;
948 > static void
949 > colavg(
950 >        register COLR   *scn,
951 >        register int    n,
952 >        void *cavg
953 > )
954   {
955          COLOR   col;
956  
957          while (n--) {
958                  colr_color(col, *scn++);
959 <                addcolor(cavg, col);
959 >                addcolor((COLORV*)cavg, col);
960          }
961   }
962  
963  
964 < int
965 < avgbox(cavg)                            /* average color over current bbox */
966 < COLOR   cavg;
964 > static int
965 > avgbox(                         /* average color over current bbox */
966 >        COLOR   cavg
967 > )
968   {
969          double  d;
970          register int    rval;
# Line 924 | Line 979 | COLOR  cavg;
979   }
980  
981  
982 < int
983 < dobox(f, p)                             /* run function over bbox */
984 < int     (*f)();                 /* function to call for each subscan */
985 < char    *p;                     /* pointer to private data */
982 > static int
983 > dobox(                          /* run function over bbox */
984 >        //void  (*f)(),                 /* function to call for each subscan */
985 >        doboxf_t *f,                    /* function to call for each subscan */
986 >        void    *p                      /* pointer to private data */
987 > )
988   {
989          int  left, right, top, bottom;
990          int  y;
# Line 957 | Line 1014 | char   *p;                     /* pointer to private data */
1014   }
1015  
1016  
1017 < int
1018 < addfix(scn, n)                  /* add fixation points to histogram */
1019 < COLR    *scn;
1020 < int     n;
1017 > static void
1018 > addfix(                 /* add fixation points to histogram */
1019 >        COLR    *scn,
1020 >        int     n,
1021 >        void    *p  /*NOTUSED*/
1022 > )
1023   {
1024          if (tmCvColrs(lscan, TM_NOCHROM, scn, n))
1025                  goto tmerr;
# Line 972 | Line 1031 | tmerr:
1031   }
1032  
1033  
1034 < make_tonemap()                  /* initialize tone mapping */
1034 > static void
1035 > make_tonemap(void)                      /* initialize tone mapping */
1036   {
1037          int  flags, y;
1038  
# Line 1027 | Line 1087 | tmerr:
1087   }
1088  
1089  
1090 < tmap_colrs(scn, len)            /* apply tone mapping to scanline */
1091 < register COLR  *scn;
1092 < int  len;
1090 > static void
1091 > tmap_colrs(             /* apply tone mapping to scanline */
1092 >        register COLR  *scn,
1093 >        int  len
1094 > )
1095   {
1096          register BYTE  *ps;
1097  
# Line 1066 | Line 1128 | tmerr:
1128   }
1129  
1130  
1131 < getmono()                       /* get monochrome data */
1131 > static void
1132 > getmono(void)                   /* get monochrome data */
1133   {
1134          register unsigned char  *dp;
1135          register int    x, err;
# Line 1098 | Line 1161 | getmono()                      /* get monochrome data */
1161   }
1162  
1163  
1164 < add2icon(y, scan)               /* add a scanline to our icon data */
1165 < int  y;
1166 < COLR  *scan;
1164 > static void
1165 > add2icon(               /* add a scanline to our icon data */
1166 >        int  y,
1167 >        COLR  *scan
1168 > )
1169   {
1170          static short  cerr[ICONSIZ];
1171          static int  ynext;
# Line 1150 | Line 1215 | COLR  *scan;
1215   }
1216  
1217  
1218 < getfull()                       /* get full (24-bit) data */
1218 > static void
1219 > getfull(void)                   /* get full (24-bit) data */
1220   {
1221          int     y;
1222 <        register unsigned int4  *dp;
1223 <        register unsigned int2  *dph;
1222 >        register uint32 *dp;
1223 >        register uint16 *dph;
1224          register int    x;
1225                                          /* initialize tone mapping */
1226          make_tonemap();
1227                                          /* read and convert file */
1228 <        dp = (unsigned int4 *)ourdata;
1229 <        dph = (unsigned int2 *)ourdata;
1228 >        dp = (uint32 *)ourdata;
1229 >        dph = (uint16 *)ourdata;
1230          for (y = 0; y < ymax; y++) {
1231                  getscan(y);
1232                  add2icon(y, scanline);
# Line 1168 | Line 1234 | getfull()                      /* get full (24-bit) data */
1234                  switch (ourras->image->blue_mask) {
1235                  case 0xff:              /* 24-bit RGB */
1236                          for (x = 0; x < xmax; x++)
1237 <                                *dp++ = (unsigned int4)scanline[x][RED] << 16 |
1238 <                                        (unsigned int4)scanline[x][GRN] << 8 |
1239 <                                        (unsigned int4)scanline[x][BLU] ;
1237 >                                *dp++ = (uint32)scanline[x][RED] << 16 |
1238 >                                        (uint32)scanline[x][GRN] << 8 |
1239 >                                        (uint32)scanline[x][BLU] ;
1240                          break;
1241                  case 0xff0000:          /* 24-bit BGR */
1242                          for (x = 0; x < xmax; x++)
1243 <                                *dp++ = (unsigned int4)scanline[x][RED] |
1244 <                                        (unsigned int4)scanline[x][GRN] << 8 |
1245 <                                        (unsigned int4)scanline[x][BLU] << 16 ;
1243 >                                *dp++ = (uint32)scanline[x][RED] |
1244 >                                        (uint32)scanline[x][GRN] << 8 |
1245 >                                        (uint32)scanline[x][BLU] << 16 ;
1246                          break;
1247   #if 0
1248                  case 0x1f:              /* 15-bit RGB */
# Line 1217 | Line 1283 | getfull()                      /* get full (24-bit) data */
1283   }
1284  
1285  
1286 < getgrey()                       /* get greyscale data */
1286 > static void
1287 > getgrey(void)                   /* get greyscale data */
1288   {
1289          int     y;
1290          register unsigned char  *dp;
# Line 1232 | Line 1299 | getgrey()                      /* get greyscale data */
1299                  tmap_colrs(scanline, xmax);
1300                  if (maxcolors < 256)
1301                          for (x = 0; x < xmax; x++)
1302 <                                *dp++ = ((int4)scanline[x][GRN] *
1302 >                                *dp++ = ((int32)scanline[x][GRN] *
1303                                          maxcolors + maxcolors/2) >> 8;
1304                  else
1305                          for (x = 0; x < xmax; x++)
# Line 1240 | Line 1307 | getgrey()                      /* get greyscale data */
1307          }
1308          for (x = 0; x < maxcolors; x++)
1309                  clrtab[x][RED] = clrtab[x][GRN] =
1310 <                        clrtab[x][BLU] = ((int4)x*256 + 128)/maxcolors;
1310 >                        clrtab[x][BLU] = ((int32)x*256 + 128)/maxcolors;
1311   }
1312  
1313  
1314 < getmapped()                     /* get color-mapped data */
1314 > static void
1315 > getmapped(void)                 /* get color-mapped data */
1316   {
1317          int     y;
1318                                          /* make sure we can do it first */
# Line 1253 | Line 1321 | getmapped()                    /* get color-mapped data */
1321                                          /* initialize tone mapping */
1322          make_tonemap();
1323                                          /* make histogram */
1324 <        if (new_histo((int4)xmax*ymax) == -1)
1324 >        if (new_histo((int32)xmax*ymax) == -1)
1325                  quiterr("cannot initialize histogram");
1326          for (y = 0; y < ymax; y++) {
1327                  if (getscan(y) < 0)
# Line 1276 | Line 1344 | getmapped()                    /* get color-mapped data */
1344   }
1345  
1346  
1347 < scale_rcolors(xr, sf)                   /* scale color map */
1348 < register XRASTER        *xr;
1349 < double  sf;
1347 > static void
1348 > scale_rcolors(                  /* scale color map */
1349 >        register XRASTER        *xr,
1350 >        double  sf
1351 > )
1352   {
1353          register int    i;
1354          long    maxv;
# Line 1304 | Line 1374 | double sf;
1374   }
1375  
1376  
1377 < getscan(y)
1378 < int  y;
1377 > static int
1378 > getscan(
1379 >        int  y
1380 > )
1381   {
1382          static int  trunced = -1;               /* truncated file? */
1383   skipit:
1384          if (trunced >= 0 && y >= trunced) {
1385 <                bzero(scanline, xmax*sizeof(COLR));
1385 >                memset(scanline, '\0', xmax*sizeof(COLR));
1386                  return(-1);
1387          }
1388          if (y != cury) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines