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.6 by greg, Wed May 27 14:28:50 1992 UTC vs.
Revision 2.8 by greg, Fri May 29 14:21:12 1992 UTC

# Line 41 | Line 41 | static char SCCSid[] = "$SunId$ LBL";
41   #define  ICONSIZ        (8*10)          /* maximum icon dimension (even 8) */
42  
43   #define  ourscreen      DefaultScreen(thedisplay)
44 #define  ourblack       BlackPixel(thedisplay,ourscreen)
45 #define  ourwhite       WhitePixel(thedisplay,ourscreen)
44   #define  ourroot        RootWindow(thedisplay,ourscreen)
45  
46   #define  revline(x0,y0,x1,y1)   XDrawLine(thedisplay,wind,revgc,x0,y0,x1,y1)
# Line 57 | Line 55 | int  fast = 0;                         /* keep picture in Pixmap? */
55   char    *dispname = NULL;               /* our display name */
56  
57   Window  wind = 0;                       /* our output window */
58 + unsigned long  ourblack=1, ourwhite=0;  /* black and white for this visual */
59   Font  fontid;                           /* our font */
60  
61   int  maxcolors = 0;                     /* maximum colors */
# Line 135 | Line 134 | char  *argv[];
134                                  maxcolors = 2;
135                                  break;
136                          case 'd':
137 <                                if (argv[i][2] == 'i') {
137 >                                if (argv[i][2] == 'i')
138                                          dispname = argv[++i];
139 <                                        break;
140 <                                }
142 <                                dither = !dither;
139 >                                else
140 >                                        dither = !dither;
141                                  break;
142                          case 'f':
143                                  fast = !fast;
# Line 150 | Line 148 | char  *argv[];
148                                  scale = atoi(argv[++i]);
149                                  break;
150                          case 'g':
151 <                                if (!strcmp(argv[i], "-geometry"))
151 >                                if (argv[i][2] == 'e')
152                                          geometry = argv[++i];
153                                  else
154                                          gamcor = atof(argv[++i]);
# Line 191 | Line 189 | char  *argv[];
189                  getevent();             /* main loop */
190   userr:
191          fprintf(stderr,
192 <        "Usage: %s [-geometry spec][-b][-m][-d][-f][-c ncolors][-e +/-stops] file\n",
192 >        "Usage: %s [-display disp][-geometry spec][-b][-m][-d][-f][-c ncolors][-e +/-stops] file\n",
193                          progname);
194          quit(1);
195   }
# Line 245 | Line 243 | init()                 /* get data and open window */
243          width = xmax;
244          height = ymax;
245          ourgc = XCreateGC(thedisplay, wind, 0, 0);
246 <        XSetState(thedisplay, ourgc, BlackPixel(thedisplay,ourscreen),
249 <                        WhitePixel(thedisplay,ourscreen), GXcopy, AllPlanes);
246 >        XSetState(thedisplay, ourgc, ourblack, ourwhite, GXcopy, AllPlanes);
247          revgc = XCreateGC(thedisplay, wind, 0, 0);
248          XSetFunction(thedisplay, revgc, GXinvert);
249          fontid = XLoadFont(thedisplay, FONTNAME);
# Line 362 | Line 359 | register XVisualInfo   *v1, *v2;
359  
360   getbestvis()                    /* get the best visual for this screen */
361   {
362 + #ifdef DEBUG
363   static char  vistype[][12] = {
364                  "StaticGray",
365                  "GrayScale",
# Line 370 | Line 368 | static char  vistype[][12] = {
368                  "TrueColor",
369                  "DirectColor"
370   };
371 + #endif
372          static int      rankings[3][6] = {
373                  {TrueColor,DirectColor,PseudoColor,GrayScale,StaticGray,-1},
374 <                {PseudoColor,GrayScale,-1},
375 <                {PseudoColor,GrayScale,-1}
374 >                {PseudoColor,GrayScale,StaticGray,-1},
375 >                {PseudoColor,GrayScale,StaticGray,-1}
376          };
377          XVisualInfo     *xvi;
378          int     vismatched;
# Line 393 | Line 392 | static char  vistype[][12] = {
392          xvi = XGetVisualInfo(thedisplay,VisualScreenMask,&ourvis,&vismatched);
393          if (xvi == NULL)
394                  quiterr("no visuals for this screen!");
395 < for (i = 0; i < vismatched; i++)
396 < fprintf(stderr, "Type %s, depth %d\n", vistype[xvi[i].class], xvi[i].depth);
395 > #ifdef DEBUG
396 >        fprintf(stderr, "Supported visuals:\n");
397 >        for (i = 0; i < vismatched; i++)
398 >                fprintf(stderr, "\ttype %s, depth %d\n",
399 >                                vistype[xvi[i].class], xvi[i].depth);
400 > #endif
401          for (i = 0, j = 1; j < vismatched; j++)
402                  if (viscmp(&xvi[i],&xvi[j]) > 0)
403                          i = j;
# Line 407 | Line 410 | fprintf(stderr, "Type %s, depth %d\n", vistype[xvi[i].
410                  quiterr("inadequate visuals on this screen");
411                                          /* OK, we'll use it */
412          copystruct(&ourvis, &xvi[i]);
413 < fprintf(stderr, "Selected visual type %s, depth %d\n", vistype[ourvis.class],
414 < ourvis.depth);
413 > #ifdef DEBUG
414 >        fprintf(stderr, "Selected visual type %s, depth %d\n",
415 >                        vistype[ourvis.class], ourvis.depth);
416 > #endif
417 >                                        /* make appropriate adjustments */
418          if (ourvis.class == GrayScale || ourvis.class == StaticGray)
419                  greyscale = 1;
420 <        if (1<<ourvis.depth < maxcolors)
421 <                maxcolors = 1<<ourvis.depth;
420 >        if (ourvis.depth <= 8 && ourvis.colormap_size < maxcolors)
421 >                maxcolors = ourvis.colormap_size;
422          if (maxcolors > 4)
423                  maxcolors -= 2;
424 +        if (ourvis.class == StaticGray) {
425 +                ourblack = 0;
426 +                ourwhite = 255;
427 +        } else if (ourvis.class == PseudoColor) {
428 +                ourblack = BlackPixel(thedisplay,ourscreen);
429 +                ourwhite = WhitePixel(thedisplay,ourscreen);
430 +        } else {
431 +                ourblack = 0;
432 +                ourwhite = ~0;
433 +        }
434          XFree((char *)xvi);
435   }
436  
# Line 450 | Line 466 | getras()                               /* get raster file */
466                                  xmax, ymax, 8);
467                  if (ourras == NULL)
468                          goto fail;
469 <                if (greyscale)
470 <                        biq(dither,maxcolors,1,ourmap);
471 <                else
472 <                        ciq(dither,maxcolors,1,ourmap);
473 <                if (init_rcolors(ourras, ourmap[0], ourmap[1], ourmap[2]) == 0)
474 <                        goto fail;
469 >                if (ourvis.class == StaticGray)
470 >                        getgrey();
471 >                else {
472 >                        if (greyscale)
473 >                                biq(dither,maxcolors,1,ourmap);
474 >                        else
475 >                                ciq(dither,maxcolors,1,ourmap);
476 >                        if (init_rcolors(ourras, ourmap[0],
477 >                                        ourmap[1], ourmap[2]) == 0)
478 >                                goto fail;
479 >                }
480          }
481 <        return;
481 >                return;
482   fail:
483          quiterr("could not create raster image");
484   }
# Line 488 | Line 509 | getevent()                             /* process the next event */
509                          make_rpixmap(ourras, wind);
510                  break;
511          case UnmapNotify:
512 <                unmap_rcolors(ourras);
512 >                if (!fast)
513 >                        unmap_rcolors(ourras);
514                  break;
515          case Expose:
516                  redraw(e.e.x, e.e.y, e.e.width, e.e.height);
# Line 844 | Line 866 | getfull()                      /* get full (24-bit) data */
866   }
867  
868  
869 + getgrey()                       /* get greyscale data */
870 + {
871 +        int     y;
872 +        register unsigned char  *dp;
873 +        register int    x;
874 +                                        /* set gamma correction */
875 +        setcolrgam(gamcor);
876 +                                        /* read and convert file */
877 +        dp = ourdata;
878 +        for (y = 0; y < ymax; y++) {
879 +                if (getscan(y) < 0)
880 +                        quiterr("seek error in getfull");
881 +                if (scale)
882 +                        shiftcolrs(scanline, xmax, scale);
883 +                colrs_gambs(scanline, xmax);
884 +                add2icon(y, scanline);
885 +                if (ourvis.colormap_size < 256)
886 +                        for (x = 0; x < xmax; x++)
887 +                                *dp++ = ((long)normbright(scanline[x]) *
888 +                                        ourvis.colormap_size + 128) >> 8;
889 +                else
890 +                        for (x = 0; x < xmax; x++)
891 +                                *dp++ = normbright(scanline[x]);
892 +        }
893 + }
894 +
895 +
896   scale_rcolors(xr, sf)                   /* scale color map */
897   register XRASTER        *xr;
898   double  sf;
# Line 935 | Line 984 | colormap  map;
984   picwritecm(map)                 /* handled elsewhere */
985   colormap  map;
986   {
987 < #ifdef DEBUG
987 > #if 0
988          register int i;
989  
990          for (i = 0; i < 256; i++)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines