/[rdesktop]/sourceforge.net/trunk/rdesktop/xwin.c
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /sourceforge.net/trunk/rdesktop/xwin.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 182 by astrand, Tue Sep 17 16:55:43 2002 UTC revision 185 by n-ki, Wed Sep 18 12:13:08 2002 UTC
# Line 59  static Pixmap backstore; Line 59  static Pixmap backstore;
59  }  }
60    
61  /* colour maps */  /* colour maps */
 static BOOL owncolmap;  
62  static Colormap xcolmap;  static Colormap xcolmap;
63  static uint32 *colmap;  static uint32 *colmap;
64    
# Line 71  static XIC IC = NULL; Line 70  static XIC IC = NULL;
70  /* toggle fullscreen globals */  /* toggle fullscreen globals */
71  static unsigned long input_mask;  static unsigned long input_mask;
72    
73  #define TRANSLATE(col)          ( owncolmap ? col : translate_colour(colmap[col]) )  #define SET_FOREGROUND(col)     XSetForeground(display, gc, translate_colour(colmap[col]));
74  #define SET_FOREGROUND(col)     XSetForeground(display, gc, TRANSLATE(col));  #define SET_BACKGROUND(col)     XSetBackground(display, gc, translate_colour(colmap[col]));
 #define SET_BACKGROUND(col)     XSetBackground(display, gc, TRANSLATE(col));  
75    
76  static int rop2_map[] = {  static int rop2_map[] = {
77          GXclear,                /* 0 */          GXclear,                /* 0 */
# Line 333  ui_init() Line 331  ui_init()
331                  return False;                  return False;
332          }          }
333    
334          if (depth <= 8)          xcolmap = DefaultColormapOfScreen(screen);
                 owncolmap = True;  
         else  
                 xcolmap = DefaultColormapOfScreen(screen);  
335    
336          if (DoesBackingStore(screen) == NotUseful)          if (DoesBackingStore(screen) == NotUseful)
337                  ownbackstore = True;                  ownbackstore = True;
# Line 637  ui_create_bitmap(int width, int height, Line 632  ui_create_bitmap(int width, int height,
632          Pixmap bitmap;          Pixmap bitmap;
633          uint8 *tdata;          uint8 *tdata;
634    
635          tdata = (owncolmap ? data : translate_image(width, height, data));          tdata = translate_image(width, height, data);
636          bitmap = XCreatePixmap(display, wnd, width, height, depth);          bitmap = XCreatePixmap(display, wnd, width, height, depth);
637          image = XCreateImage(display, visual, depth, ZPixmap, 0,          image = XCreateImage(display, visual, depth, ZPixmap, 0,
638                               (char *) tdata, width, height, 8, 0);                               (char *) tdata, width, height, 8, 0);
# Line 645  ui_create_bitmap(int width, int height, Line 640  ui_create_bitmap(int width, int height,
640          XPutImage(display, bitmap, gc, image, 0, 0, 0, 0, width, height);          XPutImage(display, bitmap, gc, image, 0, 0, 0, 0, width, height);
641    
642          XFree(image);          XFree(image);
643          if (!owncolmap)          xfree(tdata);
                 xfree(tdata);  
644          return (HBITMAP) bitmap;          return (HBITMAP) bitmap;
645  }  }
646    
# Line 656  ui_paint_bitmap(int x, int y, int cx, in Line 650  ui_paint_bitmap(int x, int y, int cx, in
650          XImage *image;          XImage *image;
651          uint8 *tdata;          uint8 *tdata;
652    
653          tdata = (owncolmap ? data : translate_image(width, height, data));          tdata = translate_image(width, height, data);
654          image = XCreateImage(display, visual, depth, ZPixmap, 0,          image = XCreateImage(display, visual, depth, ZPixmap, 0,
655                               (char *) tdata, width, height, 8, 0);                               (char *) tdata, width, height, 8, 0);
656    
# Line 671  ui_paint_bitmap(int x, int y, int cx, in Line 665  ui_paint_bitmap(int x, int y, int cx, in
665          }          }
666    
667          XFree(image);          XFree(image);
668          if (!owncolmap)          xfree(tdata);
                 xfree(tdata);  
669  }  }
670    
671  void  void
# Line 807  ui_create_colourmap(COLOURMAP * colours) Line 800  ui_create_colourmap(COLOURMAP * colours)
800  {  {
801          COLOURENTRY *entry;          COLOURENTRY *entry;
802          int i, ncolours = colours->ncolours;          int i, ncolours = colours->ncolours;
803            uint32 *map = xmalloc(sizeof(*colmap) * ncolours);
804            XColor xentry;
805            XColor xc_cache[256];
806            uint32 colour;
807            int colLookup = 256;
808            for (i = 0; i < ncolours; i++)
809            {
810                    entry = &colours->colours[i];
811                    MAKE_XCOLOR(&xentry, entry);
812    
813                    if (XAllocColor(display, xcolmap, &xentry) == 0)
814                    {
815                            /* Allocation failed, find closest match. */
816                            int j = 256;
817                            int nMinDist = 3 * 256 * 256;
818                            long nDist = nMinDist;
819    
820                            /* only get the colors once */
821                            while( colLookup-- ){
822                                    xc_cache[colLookup].pixel = colLookup;
823                                    xc_cache[colLookup].red = xc_cache[colLookup].green = xc_cache[colLookup].blue = 0;
824                                    xc_cache[colLookup].flags = 0;
825                                    XQueryColor(display, DefaultColormap(display, DefaultScreen(display)), &xc_cache[colLookup]);
826                            }
827                            colLookup = 0;
828    
829          if (owncolmap)                          /* approximate the pixel */
830          {                          while( j-- ){
831                  XColor *xcolours, *xentry;                                  if( xc_cache[j].flags ){
832                  Colormap map;                                          nDist =
833                                            ((long) (xc_cache[j].red >> 8) - (long) (xentry.red >> 8)) *
834                  xcolours = xmalloc(sizeof(XColor) * ncolours);                                          ((long) (xc_cache[j].red >> 8) - (long) (xentry.red >> 8)) +
835                  for (i = 0; i < ncolours; i++)                                          ((long) (xc_cache[j].green >> 8) - (long) (xentry.green >> 8)) *
836                  {                                          ((long) (xc_cache[j].green >> 8) - (long) (xentry.green >> 8)) +
837                          entry = &colours->colours[i];                                          ((long) (xc_cache[j].blue >> 8) - (long) (xentry.blue >> 8)) *
838                          xentry = &xcolours[i];                                          ((long) (xc_cache[j].blue >> 8) - (long) (xentry.blue >> 8));
839                          xentry->pixel = i;                                  }
840                          MAKE_XCOLOR(xentry, entry);                                  if( nDist < nMinDist ){
841                                            nMinDist = nDist;
842                                            xentry.pixel = j;
843                                    }
844                            }
845                  }                  }
846                    colour = xentry.pixel;
847    
848                  map = XCreateColormap(display, wnd, visual, AllocAll);                  /* update our cache */
849                  XStoreColors(display, map, xcolours, ncolours);                  if( xentry.pixel < 256 ){
850                            xc_cache[xentry.pixel].red = xentry.red;
851                            xc_cache[xentry.pixel].green = xentry.green;
852                            xc_cache[xentry.pixel].blue = xentry.blue;
853    
                 xfree(xcolours);  
                 return (HCOLOURMAP) map;  
         }  
         else  
         {  
                 uint32 *map = xmalloc(sizeof(*colmap) * ncolours);  
                 XColor xentry;  
                 uint32 colour;  
   
                 for (i = 0; i < ncolours; i++)  
                 {  
                         entry = &colours->colours[i];  
                         MAKE_XCOLOR(&xentry, entry);  
   
                         if (XAllocColor(display, xcolmap, &xentry) != 0)  
                                 colour = xentry.pixel;  
                         else  
                                 colour = WhitePixelOfScreen(screen);  
   
                         /* byte swap here to make translate_image faster */  
                         map[i] = translate_colour(colour);  
854                  }                  }
855    
856                  return map;  
857                    /* byte swap here to make translate_image faster */
858                    map[i] = translate_colour(colour);
859          }          }
860    
861            return map;
862  }  }
863    
864  void  void
865  ui_destroy_colourmap(HCOLOURMAP map)  ui_destroy_colourmap(HCOLOURMAP map)
866  {  {
867          if (owncolmap)          xfree(map);
                 XFreeColormap(display, (Colormap) map);  
         else  
                 xfree(map);  
868  }  }
869    
870  void  void
871  ui_set_colourmap(HCOLOURMAP map)  ui_set_colourmap(HCOLOURMAP map)
872  {  {
873          if (owncolmap)          colmap = map;
                 XSetWindowColormap(display, wnd, (Colormap) map);  
         else  
                 colmap = map;  
874  }  }
875    
876  void  void

Legend:
Removed from v.182  
changed lines
  Added in v.185

  ViewVC Help
Powered by ViewVC 1.1.26