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.9 by greg, Sat May 30 09:33:01 1992 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1991 Regents of the University of California */
1 > /* Copyright (c) 1992 Regents of the University of California */
2  
3   #ifndef lint
4   static char SCCSid[] = "$SunId$ LBL";
# 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=0, ourwhite=1;  /* 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 242 | Line 240 | init()                 /* get data and open window */
240                          CWBackPixel|CWBorderPixel|CWColormap, &ourwinattr);
241          if (wind == 0)
242                  quiterr("cannot create window");
243 +        XFreeColormap(thedisplay, ourwinattr.colormap);
244          width = xmax;
245          height = ymax;
246          ourgc = XCreateGC(thedisplay, wind, 0, 0);
247 <        XSetState(thedisplay, ourgc, BlackPixel(thedisplay,ourscreen),
249 <                        WhitePixel(thedisplay,ourscreen), GXcopy, AllPlanes);
247 >        XSetState(thedisplay, ourgc, ourblack, ourwhite, GXcopy, AllPlanes);
248          revgc = XCreateGC(thedisplay, wind, 0, 0);
249          XSetFunction(thedisplay, revgc, GXinvert);
250          fontid = XLoadFont(thedisplay, FONTNAME);
# Line 362 | Line 360 | register XVisualInfo   *v1, *v2;
360  
361   getbestvis()                    /* get the best visual for this screen */
362   {
363 + #ifdef DEBUG
364   static char  vistype[][12] = {
365                  "StaticGray",
366                  "GrayScale",
# Line 370 | Line 369 | static char  vistype[][12] = {
369                  "TrueColor",
370                  "DirectColor"
371   };
372 + #endif
373          static int      rankings[3][6] = {
374                  {TrueColor,DirectColor,PseudoColor,GrayScale,StaticGray,-1},
375 <                {PseudoColor,GrayScale,-1},
376 <                {PseudoColor,GrayScale,-1}
375 >                {PseudoColor,GrayScale,StaticGray,-1},
376 >                {PseudoColor,GrayScale,StaticGray,-1}
377          };
378          XVisualInfo     *xvi;
379          int     vismatched;
# Line 393 | Line 393 | static char  vistype[][12] = {
393          xvi = XGetVisualInfo(thedisplay,VisualScreenMask,&ourvis,&vismatched);
394          if (xvi == NULL)
395                  quiterr("no visuals for this screen!");
396 < for (i = 0; i < vismatched; i++)
397 < fprintf(stderr, "Type %s, depth %d\n", vistype[xvi[i].class], xvi[i].depth);
396 > #ifdef DEBUG
397 >        fprintf(stderr, "Supported visuals:\n");
398 >        for (i = 0; i < vismatched; i++)
399 >                fprintf(stderr, "\ttype %s, depth %d\n",
400 >                                vistype[xvi[i].class], xvi[i].depth);
401 > #endif
402          for (i = 0, j = 1; j < vismatched; j++)
403                  if (viscmp(&xvi[i],&xvi[j]) > 0)
404                          i = j;
# Line 407 | Line 411 | fprintf(stderr, "Type %s, depth %d\n", vistype[xvi[i].
411                  quiterr("inadequate visuals on this screen");
412                                          /* OK, we'll use it */
413          copystruct(&ourvis, &xvi[i]);
414 < fprintf(stderr, "Selected visual type %s, depth %d\n", vistype[ourvis.class],
415 < ourvis.depth);
414 > #ifdef DEBUG
415 >        fprintf(stderr, "Selected visual type %s, depth %d\n",
416 >                        vistype[ourvis.class], ourvis.depth);
417 > #endif
418 >                                        /* make appropriate adjustments */
419          if (ourvis.class == GrayScale || ourvis.class == StaticGray)
420                  greyscale = 1;
421 <        if (1<<ourvis.depth < maxcolors)
422 <                maxcolors = 1<<ourvis.depth;
421 >        if (ourvis.depth <= 8 && ourvis.colormap_size < maxcolors)
422 >                maxcolors = ourvis.colormap_size;
423          if (maxcolors > 4)
424                  maxcolors -= 2;
425 +        if (ourvis.class == StaticGray) {
426 +                ourblack = 0;
427 +                ourwhite = 255;
428 +        } else if (ourvis.class == PseudoColor) {
429 +                ourblack = BlackPixel(thedisplay,ourscreen);
430 +                ourwhite = WhitePixel(thedisplay,ourscreen);
431 +                if ((ourblack|ourwhite) & ~255L) {
432 +                        ourblack = 0;
433 +                        ourwhite = 1;
434 +                }
435 +        } else {
436 +                ourblack = 0;
437 +                ourwhite = ourvis.red_mask|ourvis.green_mask|ourvis.blue_mask;
438 +        }
439          XFree((char *)xvi);
440   }
441  
# Line 450 | Line 471 | getras()                               /* get raster file */
471                                  xmax, ymax, 8);
472                  if (ourras == NULL)
473                          goto fail;
474 <                if (greyscale)
475 <                        biq(dither,maxcolors,1,ourmap);
476 <                else
477 <                        ciq(dither,maxcolors,1,ourmap);
478 <                if (init_rcolors(ourras, ourmap[0], ourmap[1], ourmap[2]) == 0)
479 <                        goto fail;
474 >                if (ourvis.class == StaticGray)
475 >                        getgrey();
476 >                else {
477 >                        if (greyscale)
478 >                                biq(dither,maxcolors,1,ourmap);
479 >                        else
480 >                                ciq(dither,maxcolors,1,ourmap);
481 >                        if (init_rcolors(ourras, ourmap[0],
482 >                                        ourmap[1], ourmap[2]) == 0)
483 >                                goto fail;
484 >                }
485          }
486 <        return;
486 >                return;
487   fail:
488          quiterr("could not create raster image");
489   }
# Line 488 | Line 514 | getevent()                             /* process the next event */
514                          make_rpixmap(ourras, wind);
515                  break;
516          case UnmapNotify:
517 <                unmap_rcolors(ourras);
517 >                if (!fast)
518 >                        unmap_rcolors(ourras);
519                  break;
520          case Expose:
521                  redraw(e.e.x, e.e.y, e.e.width, e.e.height);
# Line 844 | Line 871 | getfull()                      /* get full (24-bit) data */
871   }
872  
873  
874 + getgrey()                       /* get greyscale data */
875 + {
876 +        int     y;
877 +        register unsigned char  *dp;
878 +        register int    x;
879 +                                        /* set gamma correction */
880 +        setcolrgam(gamcor);
881 +                                        /* read and convert file */
882 +        dp = ourdata;
883 +        for (y = 0; y < ymax; y++) {
884 +                if (getscan(y) < 0)
885 +                        quiterr("seek error in getfull");
886 +                if (scale)
887 +                        shiftcolrs(scanline, xmax, scale);
888 +                colrs_gambs(scanline, xmax);
889 +                add2icon(y, scanline);
890 +                if (ourvis.colormap_size < 256)
891 +                        for (x = 0; x < xmax; x++)
892 +                                *dp++ = ((long)normbright(scanline[x]) *
893 +                                        ourvis.colormap_size + 128) >> 8;
894 +                else
895 +                        for (x = 0; x < xmax; x++)
896 +                                *dp++ = normbright(scanline[x]);
897 +        }
898 + }
899 +
900 +
901   scale_rcolors(xr, sf)                   /* scale color map */
902   register XRASTER        *xr;
903   double  sf;
# Line 935 | Line 989 | colormap  map;
989   picwritecm(map)                 /* handled elsewhere */
990   colormap  map;
991   {
992 < #ifdef DEBUG
992 > #if 0
993          register int i;
994  
995          for (i = 0; i < 256; i++)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines