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.55 by gwlarson, Tue Jul 20 14:07:38 1999 UTC vs.
Revision 2.65 by schorsch, Fri Jan 2 12:47:01 2004 UTC

# Line 1 | Line 1
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   *
# Line 21 | Line 18 | static char SCCSid[] = "$SunId$ SGI";
18  
19   #include  "standard.h"
20  
21 + #include  <string.h>
22   #include  <signal.h>
23   #include  <X11/Xlib.h>
24   #include  <X11/cursorfont.h>
25   #include  <X11/Xutil.h>
26   #include  <X11/Xatom.h>
27  
30 #undef  NOPROTO
31 #define NOPROTO 1
28   #include  "color.h"
29   #include  "tonemap.h"
30   #include  "view.h"
31   #include  "x11raster.h"
32   #include  "random.h"
37 #include  "resolu.h"
33  
34   #define  FONTNAME       "8x13"          /* text font we'll use */
35  
# Line 109 | Line 104 | unsigned char  *ourdata;               /* our image data */
104  
105   struct {
106          int  xmin, ymin, xsiz, ysiz;
107 < }  box = {0, 0, 0, 0};                  /* current box */
107 > }  bbox = {0, 0, 0, 0};                 /* current bbox */
108  
109   char  *geometry = NULL;                 /* geometry specification */
110  
# Line 131 | Line 126 | Atom  closedownAtom, wmProtocolsAtom;
126  
127   int  sigrecv;
128  
129 < int  onsig() { sigrecv++; }
129 > void  onsig(int i) { sigrecv++; }
130  
131 + static gethfunc headline;
132  
133 +
134   main(argc, argv)
135   int  argc;
136   char  *argv[];
137   {
141        int  headline();
138          int  i;
139          int  pid;
140          
# Line 251 | Line 247 | userr:
247   }
248  
249  
250 < int
251 < headline(s)             /* get relevant info from header */
252 < char  *s;
250 > static int
251 > headline(               /* get relevant info from header */
252 >        char    *s,
253 >        void    *p
254 > )
255   {
256          char  fmt[32];
257  
# Line 389 | Line 387 | char  *err;
387          register int  es;
388          int  cs;
389  
390 <        if (es = err != NULL)
390 >        if ( (es = err != NULL) )
391                  fprintf(stderr, "%s: %s: %s\n", progname,
392                                  fname==NULL?"<stdin>":fname, err);
393          if (thedisplay != NULL)
394                  XCloseDisplay(thedisplay);
395 <        if (parent < 0 & sigrecv == 0)
395 >        if ((parent < 0) & (sigrecv == 0))
396                  kill(getppid(), SIGCONT);
397          while (parent > 0 && wait(&cs) != -1) { /* wait for any children */
398                  if (es == 0)
# Line 499 | Line 497 | static char  vistype[][12] = {
497          if (viscmp(&xvi[i],&ourvis) > 0)
498                  quiterr("inadequate visuals on this screen");
499                                          /* OK, we'll use it */
500 <        copystruct(&ourvis, &xvi[i]);
500 >        ourvis = xvi[i];
501   #ifdef DEBUG
502          fprintf(stderr, "Selected visual type %s, depth %d\n",
503                          vistype[ourvis.class], ourvis.depth);
# Line 542 | Line 540 | getras()                               /* get raster file */
540                  if (ourras == NULL)
541                          goto fail;
542                  getmono();
543 <        } else if (ourvis.class == TrueColor | ourvis.class == DirectColor) {
544 <                int  datsiz = ourvis.depth>16 ? sizeof(int4) : sizeof(int2);
543 >        } else if ((ourvis.class == TrueColor) | (ourvis.class == DirectColor)) {
544 >                int  datsiz = ourvis.depth>16 ? sizeof(int32) : sizeof(int16);
545                  ourdata = (unsigned char *)malloc(datsiz*xmax*ymax);
546                  if (ourdata == NULL)
547                          goto fail;
# Line 590 | Line 588 | getevent()                             /* process the next event */
588                  map_rcolors(ourras, wind);
589                  if (fast)
590                          make_rpixmap(ourras, wind);
591 <                if (!sequential & parent < 0 & sigrecv == 0) {
591 >                if ((!sequential) & (parent < 0) & (sigrecv == 0)) {
592                          kill(getppid(), SIGCONT);
593                          sigrecv--;
594                  }
# Line 631 | Line 629 | getevent()                             /* process the next event */
629   traceray(xpos, ypos)                    /* print requested pixel data */
630   int  xpos, ypos;
631   {
632 <        extern char  *index();
635 <        FLOAT  hv[2];
632 >        RREAL  hv[2];
633          FVECT  rorg, rdir;
634          COLOR  cval;
635          register char  *cp;
636  
637 <        box.xmin = xpos; box.xsiz = 1;
638 <        box.ymin = ypos; box.ysiz = 1;
637 >        bbox.xmin = xpos; bbox.xsiz = 1;
638 >        bbox.ymin = ypos; bbox.ysiz = 1;
639          avgbox(cval);
640          scalecolor(cval, 1./exposure);
641          pix2loc(hv, &inpres, xpos-xoff, ypos-yoff);
# Line 680 | Line 677 | XKeyPressedEvent  *ekey;
677          XColor  cvx;
678          int  com, n;
679          double  comp;
680 <        FLOAT  hv[2];
680 >        RREAL  hv[2];
681  
682          n = XLookupString(ekey, buf, sizeof(buf), NULL, NULL);
683          if (n == 0)
# Line 703 | Line 700 | XKeyPressedEvent  *ekey;
700                          sprintf(buf, "%.3f", intens(cval)/exposure);
701                          break;
702                  case 'l':                               /* luminance */
703 <                        sprintf(buf, "%.0fL", luminance(cval)/exposure);
703 >                        sprintf(buf, "%.1fL", luminance(cval)/exposure);
704                          break;
705                  case 'c':                               /* color */
706                          comp = pow(2.0, (double)scale);
# Line 714 | Line 711 | XKeyPressedEvent  *ekey;
711                          break;
712                  }
713                  XDrawImageString(thedisplay, wind, ourgc,
714 <                                box.xmin, box.ymin+box.ysiz, buf, strlen(buf));
714 >                                bbox.xmin, bbox.ymin+bbox.ysiz, buf, strlen(buf));
715                  return(0);
716          case 'i':                               /* identify (contour) */
717                  if (ourras->pixels == NULL)
# Line 776 | Line 773 | XKeyPressedEvent  *ekey;
773                  sprintf(buf, "%+d", scale);
774          remap:
775                  XDrawImageString(thedisplay, wind, ourgc,
776 <                                box.xmin, box.ymin+box.ysiz, buf, strlen(buf));
776 >                                bbox.xmin, bbox.ymin+bbox.ysiz, buf, strlen(buf));
777                  XFlush(thedisplay);
778 <                free(ourdata);
778 >                /* free(ourdata);       This is done in XDestroyImage()! */
779                  free_raster(ourras);
780                  getras();
781          /* fall through */
# Line 800 | Line 797 | XKeyPressedEvent  *ekey;
797                  free_rpixmap(ourras);
798                  return(0);
799          case '0':                               /* recenter origin */
800 <                if (xoff == 0 & yoff == 0)
800 >                if ((xoff == 0) & (yoff == 0))
801                          return(0);
802                  xoff = yoff = 0;
803                  XClearWindow(thedisplay, wind);
804                  redraw(0, 0, width, height);
805                  return(0);
806          case ' ':                               /* clear */
807 <                redraw(box.xmin, box.ymin, box.xsiz, box.ysiz);
807 >                redraw(bbox.xmin, bbox.ymin, bbox.xsiz, bbox.ysiz);
808                  return(0);
809          default:
810                  XBell(thedisplay, 0);
# Line 841 | Line 838 | XButtonPressedEvent  *ebut;
838   }
839  
840  
841 < getbox(ebut)                            /* get new box */
841 > getbox(ebut)                            /* get new bbox */
842   XButtonPressedEvent  *ebut;
843   {
844          XEvent  e;
845  
846          XMaskEvent(thedisplay, ButtonReleaseMask|ButtonMotionMask, &e);
847          while (e.type == MotionNotify) {
848 <                revbox(ebut->x, ebut->y, box.xmin = e.xmotion.x, box.ymin = e.xmotion.y);
848 >                revbox(ebut->x, ebut->y, bbox.xmin = e.xmotion.x, bbox.ymin = e.xmotion.y);
849                  XMaskEvent(thedisplay,ButtonReleaseMask|ButtonMotionMask,&e);
850 <                revbox(ebut->x, ebut->y, box.xmin, box.ymin);
850 >                revbox(ebut->x, ebut->y, bbox.xmin, bbox.ymin);
851          }
852 <        box.xmin = e.xbutton.x<0 ? 0 : (e.xbutton.x>=width ? width-1 : e.xbutton.x);
853 <        box.ymin = e.xbutton.y<0 ? 0 : (e.xbutton.y>=height ? height-1 : e.xbutton.y);
854 <        if (box.xmin > ebut->x) {
855 <                box.xsiz = box.xmin - ebut->x + 1;
856 <                box.xmin = ebut->x;
852 >        bbox.xmin = e.xbutton.x<0 ? 0 : (e.xbutton.x>=width ? width-1 : e.xbutton.x);
853 >        bbox.ymin = e.xbutton.y<0 ? 0 : (e.xbutton.y>=height ? height-1 : e.xbutton.y);
854 >        if (bbox.xmin > ebut->x) {
855 >                bbox.xsiz = bbox.xmin - ebut->x + 1;
856 >                bbox.xmin = ebut->x;
857          } else {
858 <                box.xsiz = ebut->x - box.xmin + 1;
858 >                bbox.xsiz = ebut->x - bbox.xmin + 1;
859          }
860 <        if (box.ymin > ebut->y) {
861 <                box.ysiz = box.ymin - ebut->y + 1;
862 <                box.ymin = ebut->y;
860 >        if (bbox.ymin > ebut->y) {
861 >                bbox.ysiz = bbox.ymin - ebut->y + 1;
862 >                bbox.ymin = ebut->y;
863          } else {
864 <                box.ysiz = ebut->y - box.ymin + 1;
864 >                bbox.ysiz = ebut->y - bbox.ymin + 1;
865          }
866   }
867  
# Line 888 | Line 885 | XButtonPressedEvent  *ebut;
885   }
886  
887  
888 < revbox(x0, y0, x1, y1)                  /* draw box with reversed lines */
888 > revbox(x0, y0, x1, y1)                  /* draw bbox with reversed lines */
889   int  x0, y0, x1, y1;
890   {
891          revline(x0, y0, x1, y0);
# Line 898 | Line 895 | int  x0, y0, x1, y1;
895   }
896  
897  
898 < int
898 > void
899   colavg(scn, n, cavg)
900   register COLR   *scn;
901   register int    n;
# Line 907 | Line 904 | COLOR  cavg;
904          COLOR   col;
905  
906          while (n--) {
907 <                colr_color(col, scn++);
907 >                colr_color(col, *scn++);
908                  addcolor(cavg, col);
909          }
910   }
911  
912  
913   int
914 < avgbox(cavg)                            /* average color over current box */
914 > avgbox(cavg)                            /* average color over current bbox */
915   COLOR   cavg;
916   {
917          double  d;
# Line 931 | Line 928 | COLOR  cavg;
928  
929  
930   int
931 < dobox(f, p)                             /* run function over box */
932 < int     (*f)();                 /* function to call for each subscan */
931 > dobox(f, p)                             /* run function over bbox */
932 > void    (*f)();                 /* function to call for each subscan */
933   char    *p;                     /* pointer to private data */
934   {
935          int  left, right, top, bottom;
936          int  y;
937  
938 <        left = box.xmin - xoff;
939 <        right = left + box.xsiz;
938 >        left = bbox.xmin - xoff;
939 >        right = left + bbox.xsiz;
940          if (left < 0)
941                  left = 0;
942          if (right > xmax)
943                  right = xmax;
944          if (left >= right)
945                  return(0);
946 <        top = box.ymin - yoff;
947 <        bottom = top + box.ysiz;
946 >        top = bbox.ymin - yoff;
947 >        bottom = top + bbox.ysiz;
948          if (top < 0)
949                  top = 0;
950          if (bottom > ymax)
# Line 963 | Line 960 | char   *p;                     /* pointer to private data */
960   }
961  
962  
963 < int
963 > void
964   addfix(scn, n)                  /* add fixation points to histogram */
965   COLR    *scn;
966   int     n;
# Line 1100 | Line 1097 | getmono()                      /* get monochrome data */
1097                          cerr[x] = err + errp;
1098                  }
1099          }
1100 <        free((char *)cerr);
1100 >        free((void *)cerr);
1101   }
1102  
1103  
# Line 1143 | Line 1140 | COLR  *scan;
1140                  errp = err;
1141                  ti = x*xmax/iconwidth;
1142                  copycolr(clr, scan[ti]);
1143 <                normcolrs(clr, 1, scale);
1143 >                normcolrs(&clr, 1, scale);
1144                  err += normbright(clr) + cerr[x];
1145                  if (err > 127)
1146                          err -= 255;
# Line 1159 | Line 1156 | COLR  *scan;
1156   getfull()                       /* get full (24-bit) data */
1157   {
1158          int     y;
1159 <        register unsigned int4  *dp;
1160 <        register unsigned int2  *dph;
1159 >        register uint32 *dp;
1160 >        register uint16 *dph;
1161          register int    x;
1162                                          /* initialize tone mapping */
1163          make_tonemap();
1164                                          /* read and convert file */
1165 <        dp = (unsigned int4 *)ourdata;
1166 <        dph = (unsigned int2 *)ourdata;
1165 >        dp = (uint32 *)ourdata;
1166 >        dph = (uint16 *)ourdata;
1167          for (y = 0; y < ymax; y++) {
1168                  getscan(y);
1169                  add2icon(y, scanline);
# Line 1174 | Line 1171 | getfull()                      /* get full (24-bit) data */
1171                  switch (ourras->image->blue_mask) {
1172                  case 0xff:              /* 24-bit RGB */
1173                          for (x = 0; x < xmax; x++)
1174 <                                *dp++ = (unsigned int4)scanline[x][RED] << 16 |
1175 <                                        (unsigned int4)scanline[x][GRN] << 8 |
1176 <                                        (unsigned int4)scanline[x][BLU] ;
1174 >                                *dp++ = (uint32)scanline[x][RED] << 16 |
1175 >                                        (uint32)scanline[x][GRN] << 8 |
1176 >                                        (uint32)scanline[x][BLU] ;
1177                          break;
1178                  case 0xff0000:          /* 24-bit BGR */
1179                          for (x = 0; x < xmax; x++)
1180 <                                *dp++ = (unsigned int4)scanline[x][RED] |
1181 <                                        (unsigned int4)scanline[x][GRN] << 8 |
1182 <                                        (unsigned int4)scanline[x][BLU] << 16 ;
1180 >                                *dp++ = (uint32)scanline[x][RED] |
1181 >                                        (uint32)scanline[x][GRN] << 8 |
1182 >                                        (uint32)scanline[x][BLU] << 16 ;
1183                          break;
1184   #if 0
1185                  case 0x1f:              /* 15-bit RGB */
# Line 1238 | Line 1235 | getgrey()                      /* get greyscale data */
1235                  tmap_colrs(scanline, xmax);
1236                  if (maxcolors < 256)
1237                          for (x = 0; x < xmax; x++)
1238 <                                *dp++ = ((int4)scanline[x][GRN] *
1238 >                                *dp++ = ((int32)scanline[x][GRN] *
1239                                          maxcolors + maxcolors/2) >> 8;
1240                  else
1241                          for (x = 0; x < xmax; x++)
# Line 1246 | Line 1243 | getgrey()                      /* get greyscale data */
1243          }
1244          for (x = 0; x < maxcolors; x++)
1245                  clrtab[x][RED] = clrtab[x][GRN] =
1246 <                        clrtab[x][BLU] = ((int4)x*256 + 128)/maxcolors;
1246 >                        clrtab[x][BLU] = ((int32)x*256 + 128)/maxcolors;
1247   }
1248  
1249  
# Line 1259 | Line 1256 | getmapped()                    /* get color-mapped data */
1256                                          /* initialize tone mapping */
1257          make_tonemap();
1258                                          /* make histogram */
1259 <        if (new_histo((int4)xmax*ymax) == -1)
1259 >        if (new_histo((int32)xmax*ymax) == -1)
1260                  quiterr("cannot initialize histogram");
1261          for (y = 0; y < ymax; y++) {
1262                  if (getscan(y) < 0)
# Line 1316 | Line 1313 | int  y;
1313          static int  trunced = -1;               /* truncated file? */
1314   skipit:
1315          if (trunced >= 0 && y >= trunced) {
1316 <                bzero(scanline, xmax*sizeof(COLR));
1316 >                memset(scanline, '\0', xmax*sizeof(COLR));
1317                  return(-1);
1318          }
1319          if (y != cury) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines