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.27 by greg, Fri Jun 18 10:22:26 1993 UTC vs.
Revision 2.31 by greg, Thu Oct 28 10:00:58 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  noop() {}
123  
124 +
125   main(argc, argv)
126   int  argc;
127   char  *argv[];
# Line 118 | Line 130 | char  *argv[];
130          char  *gv;
131          int  headline();
132          int  i;
133 +        int  pid;
134          
135          progname = argv[0];
136          if ((gv = getenv("GAMMA")) != NULL)
# Line 163 | Line 176 | char  *argv[];
176                  else
177                          break;
178  
179 <        if (i == argc-1) {
179 >        if (i > argc)
180 >                goto userr;
181 >        while (i < argc-1) {
182 >                if ((pid=fork()) == 0) {        /* a child for each picture */
183 >                        parent = -1;
184 >                        break;
185 >                }
186 >                if (pid < 0)
187 >                        quiterr("fork failed");
188 >                parent++;
189 >                signal(SIGCONT, noop);
190 >                pause();                /* wait for wake-up call */
191 >                i++;
192 >        }
193 >        if (i < argc) {                 /* open picture file */
194                  fname = argv[i];
195                  fin = fopen(fname, "r");
196                  if (fin == NULL) {
197                          sprintf(errmsg, "cannot open file \"%s\"", fname);
198                          quiterr(errmsg);
199                  }
200 <        } else if (i != argc)
174 <                goto userr;
200 >        }
201                                  /* get header */
202          getheader(fin, headline, NULL);
203                                  /* get picture dimensions */
# Line 187 | Line 213 | char  *argv[];
213  
214          init(argc, argv);                       /* get file and open window */
215  
216 +        if (parent < 0)
217 +                kill(getppid(), SIGCONT);       /* signal parent if child */
218 +
219          for ( ; ; )
220                  getevent();             /* main loop */
221   userr:
222          fprintf(stderr,
223 < "Usage: %s [-di disp][[-ge] spec][-b][-m][-d][-f][-c nclrs][-e +/-stops] pic\n",
223 > "Usage: %s [-di disp][[-ge] spec][-b][-m][-d][-f][-c nclrs][-e +/-stops] pic ..\n",
224                          progname);
225          exit(1);
226   }
# Line 321 | Line 350 | char **argv;
350   quiterr(err)            /* print message and exit */
351   char  *err;
352   {
353 <        if (err != NULL) {
354 <                fprintf(stderr, "%s: %s\n", progname, err);
355 <                exit(1);
353 >        register int  es;
354 >        int  cs;
355 >
356 >        if (es = err != NULL)
357 >                fprintf(stderr, "%s: %s: %s\n", progname,
358 >                                fname==NULL?"<stdin>":fname, err);
359 >        if (parent > 0 & wind != 0) {
360 >                XDestroyWindow(thedisplay, wind);
361 >                XFlush(thedisplay);
362          }
363 <        exit(0);
363 >        while (parent > 0 && wait(&cs) != -1) { /* wait for any children */
364 >                if (es == 0)
365 >                        es = cs>>8 & 0xff;
366 >                parent--;
367 >        }
368 >        exit(es);
369   }
370  
371  
# Line 466 | Line 506 | getras()                               /* get raster file */
506                          goto fail;
507                  getmono();
508          } else if (ourvis.class == TrueColor | ourvis.class == DirectColor) {
509 <                ourdata = (unsigned char *)malloc(4*xmax*ymax);
509 >                ourdata = (unsigned char *)malloc(sizeof(int4)*xmax*ymax);
510                  if (ourdata == NULL)
511                          goto fail;
512 <                ourras = make_raster(thedisplay, &ourvis, 32,
512 >                ourras = make_raster(thedisplay, &ourvis, sizeof(int4)*8,
513                                  ourdata, xmax, ymax, 32);
514                  if (ourras == NULL)
515                          goto fail;
# Line 529 | Line 569 | getevent()                             /* process the next event */
569                  else
570                          getbox(&xev.xbutton);
571                  break;
572 <   case ClientMessage:
572 >        case ClientMessage:
573                  if ((xev.xclient.message_type == wmProtocolsAtom) &&
574                                  (xev.xclient.data.l[0] == closedownAtom))
575                          quiterr(NULL);
# Line 876 | Line 916 | COLR  *scan;
916   getfull()                       /* get full (24-bit) data */
917   {
918          int     y;
919 <        register unsigned long  *dp;
919 >        register unsigned int4  *dp;
920          register int    x;
921                                          /* set gamma correction */
922          setcolrgam(gamcor);
923                                          /* read and convert file */
924 <        dp = (unsigned long *)ourdata;
924 >        dp = (unsigned int4 *)ourdata;
925          for (y = 0; y < ymax; y++) {
926                  getscan(y);
927                  add2icon(y, scanline);
# Line 936 | Line 976 | getgrey()                      /* get greyscale data */
976   getmapped()                     /* get color-mapped data */
977   {
978          int     y;
979 +                                        /* make sure we can do it first */
980 +        if (fname == NULL)
981 +                quiterr("cannot map colors from standard input");
982                                          /* set gamma correction */
983          setcolrgam(gamcor);
984                                          /* make histogram */
985          new_histo();
986          for (y = 0; y < ymax; y++) {
987                  if (getscan(y) < 0)
988 <                        quiterr("seek error in getmapped");
988 >                        break;
989                  add2icon(y, scanline);
990                  if (scale)
991                          shiftcolrs(scanline, xmax, scale);
# Line 953 | Line 996 | getmapped()                    /* get color-mapped data */
996          if (!new_clrtab(maxcolors))
997                  quiterr("cannot create color map");
998          for (y = 0; y < ymax; y++) {
999 <                if (getscan(y) < 0)
957 <                        quiterr("seek error in getmapped");
999 >                getscan(y);
1000                  if (scale)
1001                          shiftcolrs(scanline, xmax, scale);
1002                  colrs_gambs(scanline, xmax);
# Line 997 | Line 1039 | double sf;
1039   getscan(y)
1040   int  y;
1041   {
1042 +        static int  trunced = -1;               /* truncated file? */
1043 + skipit:
1044 +        if (trunced >= 0 && y >= trunced) {
1045 +                bzero(scanline, xmax*sizeof(COLR));
1046 +                return(-1);
1047 +        }
1048          if (y != cury) {
1049                  if (scanpos == NULL || scanpos[y] == -1)
1050                          return(-1);
# Line 1006 | Line 1054 | int  y;
1054          } else if (scanpos != NULL && scanpos[y] == -1)
1055                  scanpos[y] = ftell(fin);
1056  
1057 <        if (freadcolrs(scanline, xmax, fin) < 0)
1058 <                quiterr("read error");
1059 <
1057 >        if (freadcolrs(scanline, xmax, fin) < 0) {
1058 >                fprintf(stderr, "%s: %s: unfinished picture\n",
1059 >                                progname, fname==NULL?"<stdin>":fname);
1060 >                trunced = y;
1061 >                goto skipit;
1062 >        }
1063          cury++;
1064          return(0);
1065   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines