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.25 by greg, Thu Apr 29 12:17:45 1993 UTC vs.
Revision 2.32 by greg, Thu Oct 28 11:39:59 1993 UTC

# Line 21 | Line 21 | static char SCCSid[] = "$SunId$ LBL";
21  
22   #include  "standard.h"
23  
24 + #include  <signal.h>
25   #include  <X11/Xlib.h>
26   #include  <X11/cursorfont.h>
27   #include  <X11/Xutil.h>
# Line 32 | Line 33 | static char SCCSid[] = "$SunId$ LBL";
33   #include  "random.h"
34   #include  "resolu.h"
35  
36 + #ifdef  __alpha
37 + #define  int4           int
38 + #endif
39 + #ifndef  int4
40 + #define  int4           long
41 + #endif
42 +
43   #define  FONTNAME       "8x13"          /* text font we'll use */
44  
45   #define  CTRL(c)        ((c)-'@')
# Line 64 | Line 72 | int  scale = 0;                                /* scalefactor; power of two */
72   int  xoff = 0;                          /* x image offset */
73   int  yoff = 0;                          /* y image offset */
74  
75 + int  parent = 0;                        /* number of children, -1 if child */
76 +
77   VIEW  ourview = STDVIEW;                /* image view parameters */
78   int  gotview = 0;                       /* got parameters from file */
79  
# Line 109 | Line 119 | extern long  ftell();
119   Display  *thedisplay;
120   Atom  closedownAtom, wmProtocolsAtom;
121  
122 + int  sigrecv;
123  
124 + int  onsig() { sigrecv++; }
125 +
126 +
127   main(argc, argv)
128   int  argc;
129   char  *argv[];
# Line 118 | Line 132 | char  *argv[];
132          char  *gv;
133          int  headline();
134          int  i;
135 +        int  pid;
136          
137          progname = argv[0];
138          if ((gv = getenv("GAMMA")) != NULL)
# Line 163 | Line 178 | char  *argv[];
178                  else
179                          break;
180  
181 <        if (i == argc-1) {
181 >        if (i > argc)
182 >                goto userr;
183 >        while (i < argc-1) {
184 >                sigrecv = 0;
185 >                signal(SIGCONT, onsig);
186 >                if ((pid=fork()) == 0) {        /* a child for each picture */
187 >                        parent = -1;
188 >                        break;
189 >                }
190 >                if (pid < 0)
191 >                        quiterr("fork failed");
192 >                parent++;
193 >                while (!sigrecv)
194 >                        pause();        /* wait for wake-up call */
195 >                i++;
196 >        }
197 >        if (i < argc) {                 /* open picture file */
198                  fname = argv[i];
199                  fin = fopen(fname, "r");
200                  if (fin == NULL) {
201                          sprintf(errmsg, "cannot open file \"%s\"", fname);
202                          quiterr(errmsg);
203                  }
204 <        } else if (i != argc)
174 <                goto userr;
204 >        }
205                                  /* get header */
206          getheader(fin, headline, NULL);
207                                  /* get picture dimensions */
# Line 187 | Line 217 | char  *argv[];
217  
218          init(argc, argv);                       /* get file and open window */
219  
220 +        if (parent < 0) {
221 +                kill(getppid(), SIGCONT);       /* signal parent if child */
222 +                sigrecv--;
223 +        }
224          for ( ; ; )
225                  getevent();             /* main loop */
226   userr:
227          fprintf(stderr,
228 < "Usage: %s [-di disp][[-ge] spec][-b][-m][-d][-f][-c nclrs][-e +/-stops] pic\n",
228 > "Usage: %s [-di disp][[-ge] spec][-b][-m][-d][-f][-c nclrs][-e +/-stops] pic ..\n",
229                          progname);
230          exit(1);
231   }
# Line 282 | Line 316 | char **argv;
316                  quiterr("cannot create window");
317          width = xmax;
318          height = ymax;
319 <        xgcv.foreground = ourblack;
286 <        xgcv.background = ourwhite;
319 >        /* prepare graphics drawing context */
320          if ((xgcv.font = XLoadFont(thedisplay, FONTNAME)) == 0)
321                  quiterr("cannot get font");
322 +        xgcv.foreground = ourblack;
323 +        xgcv.background = ourwhite;
324          ourgc = XCreateGC(thedisplay, wind, GCForeground|GCBackground|
325                          GCFont, &xgcv);
326          xgcv.function = GXinvert;
# Line 321 | Line 356 | char **argv;
356   quiterr(err)            /* print message and exit */
357   char  *err;
358   {
359 <        if (err != NULL) {
360 <                fprintf(stderr, "%s: %s\n", progname, err);
361 <                exit(1);
359 >        register int  es;
360 >        int  cs;
361 >
362 >        if (es = err != NULL)
363 >                fprintf(stderr, "%s: %s: %s\n", progname,
364 >                                fname==NULL?"<stdin>":fname, err);
365 >        if (parent > 0 & wind != 0) {
366 >                XDestroyWindow(thedisplay, wind);
367 >                XFlush(thedisplay);
368 >        } else if (parent < 0 & sigrecv == 0)
369 >                kill(getppid(), SIGCONT);
370 >        while (parent > 0 && wait(&cs) != -1) { /* wait for any children */
371 >                if (es == 0)
372 >                        es = cs>>8 & 0xff;
373 >                parent--;
374          }
375 <        exit(0);
375 >        exit(es);
376   }
377  
378  
# Line 466 | Line 513 | getras()                               /* get raster file */
513                          goto fail;
514                  getmono();
515          } else if (ourvis.class == TrueColor | ourvis.class == DirectColor) {
516 <                ourdata = (unsigned char *)malloc(4*xmax*ymax);
516 >                ourdata = (unsigned char *)malloc(sizeof(int4)*xmax*ymax);
517                  if (ourdata == NULL)
518                          goto fail;
519 <                ourras = make_raster(thedisplay, &ourvis, 32,
519 >                ourras = make_raster(thedisplay, &ourvis, sizeof(int4)*8,
520                                  ourdata, xmax, ymax, 32);
521                  if (ourras == NULL)
522                          goto fail;
# Line 529 | Line 576 | getevent()                             /* process the next event */
576                  else
577                          getbox(&xev.xbutton);
578                  break;
579 <   case ClientMessage:
579 >        case ClientMessage:
580                  if ((xev.xclient.message_type == wmProtocolsAtom) &&
581                                  (xev.xclient.data.l[0] == closedownAtom))
582                          quiterr(NULL);
# Line 628 | Line 675 | XKeyPressedEvent  *ekey;
675                  if (avgbox(cval) == -1)
676                          return(-1);
677                  comp = com=='@'
678 <                ? 59.2/pow(1.219+pow(luminance(cval)/exposure,.4),2.5)/exposure
678 >                ? 106./pow(1.219+pow(luminance(cval)/exposure,.4),2.5)/exposure
679                  : .5/bright(cval) ;
680                  comp = log(comp)/.69315 - scale;
681                  n = comp < 0 ? comp-.5 : comp+.5 ;      /* round */
# Line 653 | Line 700 | XKeyPressedEvent  *ekey;
700                          make_rpixmap(ourras, wind);
701                  redraw(0, 0, width, height);
702                  return(0);
703 +        case 'f':                               /* turn on fast redraw */
704 +                fast = 1;
705 +                make_rpixmap(ourras, wind);
706 +                return(0);
707 +        case 'F':                               /* turn off fast redraw */
708 +                fast = 0;
709 +                free_rpixmap(ourras);
710 +                return(0);
711          case '0':                               /* recenter origin */
712                  if (xoff == 0 & yoff == 0)
713                          return(0);
# Line 868 | Line 923 | COLR  *scan;
923   getfull()                       /* get full (24-bit) data */
924   {
925          int     y;
926 <        register unsigned long  *dp;
926 >        register unsigned int4  *dp;
927          register int    x;
928                                          /* set gamma correction */
929          setcolrgam(gamcor);
930                                          /* read and convert file */
931 <        dp = (unsigned long *)ourdata;
931 >        dp = (unsigned int4 *)ourdata;
932          for (y = 0; y < ymax; y++) {
933                  getscan(y);
934                  add2icon(y, scanline);
# Line 928 | Line 983 | getgrey()                      /* get greyscale data */
983   getmapped()                     /* get color-mapped data */
984   {
985          int     y;
986 +                                        /* make sure we can do it first */
987 +        if (fname == NULL)
988 +                quiterr("cannot map colors from standard input");
989                                          /* set gamma correction */
990          setcolrgam(gamcor);
991                                          /* make histogram */
992          new_histo();
993          for (y = 0; y < ymax; y++) {
994                  if (getscan(y) < 0)
995 <                        quiterr("seek error in getmapped");
995 >                        break;
996                  add2icon(y, scanline);
997                  if (scale)
998                          shiftcolrs(scanline, xmax, scale);
# Line 945 | Line 1003 | getmapped()                    /* get color-mapped data */
1003          if (!new_clrtab(maxcolors))
1004                  quiterr("cannot create color map");
1005          for (y = 0; y < ymax; y++) {
1006 <                if (getscan(y) < 0)
949 <                        quiterr("seek error in getmapped");
1006 >                getscan(y);
1007                  if (scale)
1008                          shiftcolrs(scanline, xmax, scale);
1009                  colrs_gambs(scanline, xmax);
# Line 989 | Line 1046 | double sf;
1046   getscan(y)
1047   int  y;
1048   {
1049 +        static int  trunced = -1;               /* truncated file? */
1050 + skipit:
1051 +        if (trunced >= 0 && y >= trunced) {
1052 +                bzero(scanline, xmax*sizeof(COLR));
1053 +                return(-1);
1054 +        }
1055          if (y != cury) {
1056                  if (scanpos == NULL || scanpos[y] == -1)
1057                          return(-1);
# Line 998 | Line 1061 | int  y;
1061          } else if (scanpos != NULL && scanpos[y] == -1)
1062                  scanpos[y] = ftell(fin);
1063  
1064 <        if (freadcolrs(scanline, xmax, fin) < 0)
1065 <                quiterr("read error");
1066 <
1064 >        if (freadcolrs(scanline, xmax, fin) < 0) {
1065 >                fprintf(stderr, "%s: %s: unfinished picture\n",
1066 >                                progname, fname==NULL?"<stdin>":fname);
1067 >                trunced = y;
1068 >                goto skipit;
1069 >        }
1070          cury++;
1071          return(0);
1072   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines