/[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 28 by matty, Wed Jun 20 13:54:48 2001 UTC revision 31 by matty, Sat Sep 15 03:16:05 2001 UTC
# Line 1  Line 1 
1  /*  /*
2     rdesktop: A Remote Desktop Protocol client.     rdesktop: A Remote Desktop Protocol client.
3     User interface services - X-Windows     User interface services - X-Windows
4     Copyright (C) Matthew Chapman 1999-2000     Copyright (C) Matthew Chapman 1999-2001
5        
6     This program is free software; you can redistribute it and/or modify     This program is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by     it under the terms of the GNU General Public License as published by
# Line 25  Line 25 
25    
26  extern int width;  extern int width;
27  extern int height;  extern int height;
28  extern BOOL motion;  extern BOOL sendmotion;
 extern BOOL grab_keyboard;  
29  extern BOOL fullscreen;  extern BOOL fullscreen;
 extern int private_colormap;  
30    
 static int bpp;  
 static int depth;  
31  static Display *display;  static Display *display;
32  static Window wnd;  static Window wnd;
33  static GC gc;  static GC gc;
34  static Visual *visual;  static Visual *visual;
35  static uint32 *colmap;  static int depth;
36    static int bpp;
37    
38  #define Ctrans(col) ( private_colormap ? col : colmap[col])  static BOOL ownbackstore;
39    static Pixmap backstore;
40    
41  #define L_ENDIAN  #define FILL_RECTANGLE(x,y,cx,cy)\
42  int screen_msbfirst = 0;  { \
43            XFillRectangle(display, wnd, gc, x, y, cx, cy); \
44            if (ownbackstore) \
45                    XFillRectangle(display, backstore, gc, x, y, cx, cy); \
46    }
47    
48  static uint8 *translate(int width, int height, uint8 *data);  static BOOL owncolmap;
49    static Colormap xcolmap;
50    static uint32 white;
51    static uint32 *colmap;
52    
53    #define TRANSLATE(col)          ( owncolmap ? col : colmap[col] )
54    #define SET_FOREGROUND(col)     XSetForeground(display, gc, TRANSLATE(col));
55    #define SET_BACKGROUND(col)     XSetBackground(display, gc, TRANSLATE(col));
56    
57  static int rop2_map[] = {  static int rop2_map[] = {
58          GXclear,                /* 0 */          GXclear,                /* 0 */
# Line 64  static int rop2_map[] = { Line 73  static int rop2_map[] = {
73          GXset                   /* 1 */          GXset                   /* 1 */
74  };  };
75    
76    #define SET_FUNCTION(rop2)      { if (rop2 != ROP2_COPY) XSetFunction(display, gc, rop2_map[rop2]); }
77    #define RESET_FUNCTION(rop2)    { if (rop2 != ROP2_COPY) XSetFunction(display, gc, GXcopy); }
78    
79    static void
80    translate8(uint8 *data, uint8 *out, uint8 *end)
81    {
82            while (out < end)
83                    *(out++) = (uint8)colmap[*(data++)];
84    }
85    
86  static void  static void
87  xwin_set_function(uint8 rop2)  translate16(uint8 *data, uint16 *out, uint16 *end)
88  {  {
89          static uint8 last_rop2 = ROP2_COPY;          while (out < end)
90                    *(out++) = (uint16)colmap[*(data++)];
91    }
92    
93          if (last_rop2 != rop2)  /* XXX endianness */
94    static void
95    translate24(uint8 *data, uint8 *out, uint8 *end)
96    {
97            uint32 value;
98    
99            while (out < end)
100          {          {
101                  XSetFunction(display, gc, rop2_map[rop2]);                  value = colmap[*(data++)];
102                  last_rop2 = rop2;                  *(out++) = value;
103                    *(out++) = value >> 8;
104                    *(out++) = value >> 16;
105          }          }
106  }  }
107    
108  static void  static void
109  xwin_grab_keyboard()  translate32(uint8 *data, uint32 *out, uint32 *end)
110  {  {
111          XGrabKeyboard(display, wnd, True, GrabModeAsync, GrabModeAsync,          while (out < end)
112                        CurrentTime);                  *(out++) = colmap[*(data++)];
113  }  }
114    
115  static void  static uint8 *
116  xwin_ungrab_keyboard()  translate(int width, int height, uint8 *data)
117  {  {
118          XUngrabKeyboard(display, CurrentTime);          int size = width * height * bpp/8;
119            uint8 *out = xmalloc(size);
120            uint8 *end = out + size;
121    
122            switch (bpp)
123            {
124                    case 8:
125                            translate8(data, out, end);
126                            break;
127    
128                    case 16:
129                            translate16(data, (uint16 *)out, (uint16 *)end);
130                            break;
131    
132                    case 24:
133                            translate24(data, out, end);
134                            break;
135    
136                    case 32:
137                            translate32(data, (uint32 *)out, (uint32 *)end);
138                            break;
139            }
140    
141            return out;
142  }  }
143    
144    #define L_ENDIAN
145    int screen_msbfirst = 0;
146    
147    
148  BOOL  BOOL
149  ui_create_window(char *title)  ui_create_window(char *title)
150  {  {
# Line 97  ui_create_window(char *title) Line 153  ui_create_window(char *title)
153          XSizeHints *sizehints;          XSizeHints *sizehints;
154          unsigned long input_mask;          unsigned long input_mask;
155          XPixmapFormatValues *pfm;          XPixmapFormatValues *pfm;
156          int count;          Screen *screen;
157            int i;
158    
159    
160          display = XOpenDisplay(NULL);          display = XOpenDisplay(NULL);
161          if (display == NULL)          if (display == NULL)
162          {          {
163                  ERROR("Failed to open display\n");                  error("Failed to open display\n");
164                  return False;                  return False;
165          }          }
166    
167          visual = DefaultVisual(display, DefaultScreen(display));          screen = DefaultScreenOfDisplay(display);
168          depth = DefaultDepth(display, DefaultScreen(display));          visual = DefaultVisualOfScreen(screen);
169          pfm = XListPixmapFormats(display, &count);          depth = DefaultDepthOfScreen(screen);
170    
171            pfm = XListPixmapFormats(display, &i);
172          if (pfm != NULL)          if (pfm != NULL)
173          {          {
174                  while (count--)                  /* Use maximum bpp for this depth - this is generally
175                       desirable, e.g. 24 bits->32 bits. */
176                    while (i--)
177                  {                  {
178                          if ((pfm + count)->depth == depth                          if ((pfm[i].depth == depth)
179                              && (pfm + count)->bits_per_pixel > bpp)                              && (pfm[i].bits_per_pixel > bpp))
180                          {                          {
181                                  bpp = (pfm + count)->bits_per_pixel;                                  bpp = pfm[i].bits_per_pixel;
182                          }                          }
183                  }                  }
184                  XFree(pfm);                  XFree(pfm);
# Line 124  ui_create_window(char *title) Line 186  ui_create_window(char *title)
186    
187          if (bpp < 8)          if (bpp < 8)
188          {          {
189                  ERROR("Less than 8 bpp not currently supported.\n");                  error("Less than 8 bpp not currently supported.\n");
190                  XCloseDisplay(display);                  XCloseDisplay(display);
191                  return False;                  return False;
192          }          }
193    
194          width &= ~3; /* make width nicely divisible */          if (depth <= 8)
195                    owncolmap = True;
196            else
197                    xcolmap = DefaultColormapOfScreen(screen);
198    
199            white = WhitePixelOfScreen(screen);
200            attribs.background_pixel = BlackPixelOfScreen(screen);
201            attribs.backing_store = DoesBackingStore(screen);
202    
203          attribs.background_pixel = BlackPixel(display, DefaultScreen(display));          if (attribs.backing_store == NotUseful)
204          attribs.backing_store = Always;                  ownbackstore = True;
205    
206          if (fullscreen)          if (fullscreen)
207          {          {
208                  attribs.override_redirect = True;                  attribs.override_redirect = True;
209                  width = WidthOfScreen(DefaultScreenOfDisplay(display));                  width = WidthOfScreen(screen);
210                  height = HeightOfScreen(DefaultScreenOfDisplay(display));                  height = HeightOfScreen(screen);
                 XSetInputFocus(display, PointerRoot, RevertToPointerRoot,  
                                CurrentTime);  
211          }          }
212          else          else
213          {          {
214                  attribs.override_redirect = False;                  attribs.override_redirect = False;
215          }          }
216    
217          wnd = XCreateWindow(display, DefaultRootWindow(display),          width = (width + 3) & ~3; /* make width a multiple of 32 bits */
218    
219            wnd = XCreateWindow(display, RootWindowOfScreen(screen),
220                              0, 0, width, height, 0, CopyFromParent,                              0, 0, width, height, 0, CopyFromParent,
221                              InputOutput, CopyFromParent,                              InputOutput, CopyFromParent,
222                              CWBackingStore | CWBackPixel | CWOverrideRedirect,                              CWBackingStore | CWBackPixel | CWOverrideRedirect,
# Line 157  ui_create_window(char *title) Line 226  ui_create_window(char *title)
226    
227          classhints = XAllocClassHint();          classhints = XAllocClassHint();
228          if (classhints != NULL)          if (classhints != NULL)
   
229          {          {
230                  classhints->res_name = "rdesktop";                  classhints->res_name = classhints->res_class = "rdesktop";
                 classhints->res_class = "rdesktop";  
231                  XSetClassHint(display, wnd, classhints);                  XSetClassHint(display, wnd, classhints);
232                  XFree(classhints);                  XFree(classhints);
233          }          }
# Line 168  ui_create_window(char *title) Line 235  ui_create_window(char *title)
235          sizehints = XAllocSizeHints();          sizehints = XAllocSizeHints();
236          if (sizehints)          if (sizehints)
237          {          {
238                  sizehints->flags =                  sizehints->flags = PMinSize | PMaxSize;
239                          PPosition | PSize | PMinSize | PMaxSize | PBaseSize;                  sizehints->min_width = sizehints->max_width = width;
240                  sizehints->min_width = width;                  sizehints->min_height = sizehints->max_height = height;
                 sizehints->max_width = width;  
                 sizehints->min_height = height;  
                 sizehints->max_height = height;  
                 sizehints->base_width = width;  
                 sizehints->base_height = height;  
241                  XSetWMNormalHints(display, wnd, sizehints);                  XSetWMNormalHints(display, wnd, sizehints);
242                  XFree(sizehints);                  XFree(sizehints);
243          }          }
244    
245          input_mask = KeyPressMask | KeyReleaseMask;          input_mask = KeyPressMask | KeyReleaseMask
246          input_mask |= ButtonPressMask | ButtonReleaseMask;                          | ButtonPressMask | ButtonReleaseMask
247          if (motion)                          | EnterWindowMask | LeaveWindowMask;
248    
249            if (sendmotion)
250                  input_mask |= PointerMotionMask;                  input_mask |= PointerMotionMask;
251          if (grab_keyboard)  
252                  input_mask |= EnterWindowMask | LeaveWindowMask;          if (ownbackstore)
253                    input_mask |= ExposureMask;
254    
255          XSelectInput(display, wnd, input_mask);          XSelectInput(display, wnd, input_mask);
256          gc = XCreateGC(display, wnd, 0, NULL);          gc = XCreateGC(display, wnd, 0, NULL);
257    
258            if (ownbackstore)
259                    backstore = XCreatePixmap(display, wnd, width, height, depth);
260    
261          XMapWindow(display, wnd);          XMapWindow(display, wnd);
262          return True;          return True;
263  }  }
# Line 197  ui_create_window(char *title) Line 265  ui_create_window(char *title)
265  void  void
266  ui_destroy_window()  ui_destroy_window()
267  {  {
268            if (ownbackstore)
269                    XFreePixmap(display, backstore);
270    
271          XFreeGC(display, gc);          XFreeGC(display, gc);
272          XDestroyWindow(display, wnd);          XDestroyWindow(display, wnd);
273          XCloseDisplay(display);          XCloseDisplay(display);
# Line 206  ui_destroy_window() Line 277  ui_destroy_window()
277  static uint8  static uint8
278  xwin_translate_key(unsigned long key)  xwin_translate_key(unsigned long key)
279  {  {
280          DEBUG("KEY(code=0x%lx)\n", key);          DEBUG(("KEY(code=0x%lx)\n", key));
281    
282          if ((key > 8) && (key <= 0x60))          if ((key > 8) && (key <= 0x60))
283                  return (key - 8);                  return (key - 8);
# Line 338  ui_process_events() Line 409  ui_process_events()
409                                  break;                                  break;
410    
411                          case EnterNotify:                          case EnterNotify:
412                                  if (grab_keyboard)                                  XGrabKeyboard(display, wnd, True, GrabModeAsync,
413                                          xwin_grab_keyboard();                                                GrabModeAsync, CurrentTime);
414                                  break;                                  break;
415    
416                          case LeaveNotify:                          case LeaveNotify:
417                                  if (grab_keyboard)                                  XUngrabKeyboard(display, CurrentTime);
418                                          xwin_ungrab_keyboard();                                  break;
419    
420                            case Expose:
421                                    XCopyArea(display, backstore, wnd, gc,
422                                              event.xexpose.x, event.xexpose.y,
423                                              event.xexpose.width, event.xexpose.height,
424                                              event.xexpose.x, event.xexpose.y);
425                                  break;                                  break;
426                  }                  }
427          }          }
# Line 362  ui_create_bitmap(int width, int height, Line 439  ui_create_bitmap(int width, int height,
439          XImage *image;          XImage *image;
440          Pixmap bitmap;          Pixmap bitmap;
441          uint8 *tdata;          uint8 *tdata;
442          tdata = (private_colormap ? data : translate(width, height, data));  
443            tdata = (owncolmap ? data : translate(width, height, data));
444          bitmap = XCreatePixmap(display, wnd, width, height, depth);          bitmap = XCreatePixmap(display, wnd, width, height, depth);
445          image =          image = XCreateImage(display, visual, depth, ZPixmap,
446                  XCreateImage(display, visual,                               0, tdata, width, height, 8, 0);
                              depth, ZPixmap,  
                              0, tdata, width, height, BitmapPad(display), 0);  
447    
         xwin_set_function(ROP2_COPY);  
448          XPutImage(display, bitmap, gc, image, 0, 0, 0, 0, width, height);          XPutImage(display, bitmap, gc, image, 0, 0, 0, 0, width, height);
449    
450          XFree(image);          XFree(image);
451          if (!private_colormap)          if (!owncolmap)
452                  xfree(tdata);                  xfree(tdata);
453          return (HBITMAP) bitmap;          return (HBITMAP) bitmap;
454  }  }
# Line 383  ui_paint_bitmap(int x, int y, int cx, in Line 458  ui_paint_bitmap(int x, int y, int cx, in
458                  int width, int height, uint8 *data)                  int width, int height, uint8 *data)
459  {  {
460          XImage *image;          XImage *image;
461          uint8 *tdata =          uint8 *tdata;
                 (private_colormap ? data : translate(width, height, data));  
         image =  
                 XCreateImage(display, visual, depth, ZPixmap, 0, tdata, width,  
                              height, BitmapPad(display), 0);  
   
         xwin_set_function(ROP2_COPY);  
   
         /* Window */  
         XPutImage(display, wnd, gc, image, 0, 0, x, y, cx, cy);  
         XFree(image);  
         if (!private_colormap)  
                 xfree(tdata);  
 }  
462    
463  void          tdata = (owncolmap ? data : translate(width, height, data));
464  ui_destroy_bitmap(HBITMAP bmp)          image = XCreateImage(display, visual, depth, ZPixmap,
465  {                               0, tdata, width, height, 8, 0);
         XFreePixmap(display, (Pixmap) bmp);  
 }  
466    
467  HCURSOR          if (ownbackstore)
 ui_create_cursor(unsigned int x, unsigned int y, int width,  
                  int height, uint8 *mask, uint8 *data)  
 {  
         XImage *imagecursor;  
         XImage *imagemask;  
         Pixmap maskbitmap, cursorbitmap;  
         Cursor cursor;  
         XColor bg, fg;  
         GC lgc;  
         int i, x1, y1, scanlinelen;  
         uint8 *cdata, *cmask;  
         uint8 c;  
         cdata = (uint8 *) malloc(sizeof(uint8) * width * height);  
         if (!cdata)  
                 return NULL;  
         scanlinelen = (width + 7) >> 3;  
         cmask = (uint8 *) malloc(sizeof(uint8) * scanlinelen * height);  
         if (!cmask)  
468          {          {
469                  free(cdata);                  XPutImage(display, backstore, gc, image, 0, 0, x, y, cx, cy);
470                  return NULL;                  XCopyArea(display, backstore, wnd, gc, x, y, cx, cy, x, y);
         }  
         i = (height - 1) * scanlinelen;  
   
         if (!screen_msbfirst)  
         {  
                 while (i >= 0)  
                 {  
                         for (x1 = 0; x1 < scanlinelen; x1++)  
                         {  
                                 c = *(mask++);  
                                 cmask[i + x1] =  
                                         ((c & 0x1) << 7) | ((c & 0x2) << 5) |  
                                         ((c & 0x4) << 3) | ((c & 0x8) << 1) |  
                                         ((c & 0x10) >> 1) | ((c & 0x20) >> 3)  
                                         | ((c & 0x40) >> 5) | ((c & 0x80) >>  
                                                                7);  
                         }  
                         i -= scanlinelen;  
                 }  
471          }          }
472          else          else
473          {          {
474                  while (i >= 0)                  XPutImage(display, wnd, gc, image, 0, 0, x, y, cx, cy);
                 {  
                         for (x1 = 0; x1 < scanlinelen; x1++)  
                         {  
                                 cmask[i + x1] = *(mask++);  
                         }  
                         i -= scanlinelen;  
                 }  
475          }          }
476    
477            XFree(image);
478          fg.red = 0;          if (!owncolmap)
479          fg.blue = 0;                  xfree(tdata);
         fg.green = 0;  
         fg.flags = DoRed | DoBlue | DoGreen;  
         bg.red = 65535;  
         bg.blue = 65535;  
         bg.green = 65535;  
         bg.flags = DoRed | DoBlue | DoGreen;  
         maskbitmap = XCreatePixmap(display, wnd, width, height, 1);  
         cursorbitmap = XCreatePixmap(display, wnd, width, height, 1);  
         lgc = XCreateGC(display, maskbitmap, 0, NULL);  
         XSetFunction(display, lgc, GXcopy);  
         imagemask =  
                 XCreateImage(display, visual, 1, XYBitmap, 0, cmask, width,  
                              height, 8, 0);  
         imagecursor =  
                 XCreateImage(display, visual, 1, XYBitmap, 0, cdata, width,  
                              height, 8, 0);  
         for (y1 = height - 1; y1 >= 0; y1--)  
                 for (x1 = 0; x1 < width; x1++)  
                 {  
                         if (data[0] >= 0x80 || data[1] >= 0x80  
                             || data[2] >= 0x80)  
                                 if (XGetPixel(imagemask, x1, y1))  
   
                                 {  
                                         XPutPixel(imagecursor, x1, y1, 0);  
                                         XPutPixel(imagemask, x1, y1, 0);        /* mask is blank for text cursor! */  
                                 }  
   
                                 else  
                                         XPutPixel(imagecursor, x1, y1, 1);  
   
                         else  
                                 XPutPixel(imagecursor, x1, y1,  
                                           XGetPixel(imagemask, x1, y1));  
                         data += 3;  
                 }  
         XPutImage(display, maskbitmap, lgc, imagemask, 0, 0, 0, 0, width,  
                   height);  
         XPutImage(display, cursorbitmap, lgc, imagecursor, 0, 0, 0, 0, width,  
                   height); XFree(imagemask);  
         XFree(imagecursor);  
         free(cmask);  
         free(cdata);  
         XFreeGC(display, lgc);  
         cursor =  
                 XCreatePixmapCursor(display, cursorbitmap, maskbitmap, &fg,  
                                     &bg, x, y);  
         XFreePixmap(display, maskbitmap);  
         XFreePixmap(display, cursorbitmap);  
         return (HCURSOR) cursor;  
 }  
   
 void  
 ui_set_cursor(HCURSOR cursor)  
 {  
         XDefineCursor(display, wnd, (Cursor) cursor);  
480  }  }
481    
482  void  void
483  ui_destroy_cursor(HCURSOR cursor)  ui_destroy_bitmap(HBITMAP bmp)
484  {  {
485          XFreeCursor(display, (Cursor) cursor);          XFreePixmap(display, (Pixmap)bmp);
486  }  }
487    
488  HGLYPH  HGLYPH
# Line 544  ui_create_glyph(int width, int height, u Line 504  ui_create_glyph(int width, int height, u
504          image->bitmap_bit_order = MSBFirst;          image->bitmap_bit_order = MSBFirst;
505          XInitImage(image);          XInitImage(image);
506    
         XSetFunction(display, gc, GXcopy);  
507          XPutImage(display, bitmap, gc, image, 0, 0, 0, 0, width, height);          XPutImage(display, bitmap, gc, image, 0, 0, 0, 0, width, height);
508    
509          XFree(image);          XFree(image);
510          XFreeGC(display, gc);          XFreeGC(display, gc);
511            return (HGLYPH)bitmap;
         return (HGLYPH) bitmap;  
512  }  }
513    
514  void  void
515  ui_destroy_glyph(HGLYPH glyph)  ui_destroy_glyph(HGLYPH glyph)
516  {  {
517          XFreePixmap(display, (Pixmap) glyph);          XFreePixmap(display, (Pixmap)glyph);
518  }  }
519    
520  HCOLOURMAP  HCURSOR
521  ui_create_colourmap(COLOURMAP *colours)  ui_create_cursor(unsigned int x, unsigned int y, int width,
522                     int height, uint8 *andmask, uint8 *xormask)
523  {  {
524          if (!private_colormap)          HGLYPH maskglyph, cursorglyph;
525            XColor bg, fg;
526            Cursor xcursor;
527            uint8 *cursor, *pcursor;
528            uint8 *mask, *pmask;
529            uint8 nextbit;
530            int scanline, offset;
531            int i, j;
532    
533            scanline = (width + 7) / 8;
534            offset = scanline * height;
535    
536            cursor = xmalloc(offset);
537            memset(cursor, 0, offset);
538    
539            mask = xmalloc(offset);
540            memset(mask, 0, offset);
541    
542            /* approximate AND and XOR masks with a monochrome X pointer */
543            for (i = 0; i < height; i++)
544          {          {
545                  COLOURENTRY *entry;                  offset -= scanline;
546                  int i, ncolours = colours->ncolours;                  pcursor = &cursor[offset];
547                  uint32 *nc = xmalloc(sizeof(*colmap) * ncolours);                  pmask = &mask[offset];
548                  for (i = 0; i < ncolours; i++)  
549                    for (j = 0; j < scanline; j++)
550                  {                  {
551                          XColor xc;                          for (nextbit = 0x80; nextbit != 0; nextbit >>= 1)
552                          entry = &colours->colours[i];                          {
553                          xc.red = entry->red << 8;                                  if (xormask[0] || xormask[1] || xormask[2])
554                          xc.green = entry->green << 8;                                  {
555                          xc.blue = entry->blue << 8;                                          *pcursor |= (~(*andmask) & nextbit);
556                          XAllocColor(display,                                          *pmask |= nextbit;
557                                      DefaultColormap(display,                                  }
558                                                      DefaultScreen(display)),                                  else
559                                      &xc);                                  {
560                          /* XXX Check return value */                                          *pcursor |= ((*andmask) & nextbit);
561                          nc[i] = xc.pixel;                                          *pmask |= (~(*andmask) & nextbit);
562                                    }
563    
564                                    xormask += 3;
565                            }
566    
567                            andmask++;
568                            pcursor++;
569                            pmask++;
570                  }                  }
                 return nc;  
571          }          }
572          else  
573            fg.red = fg.blue = fg.green = 0xffff;
574            bg.red = bg.blue = bg.green = 0x0000;
575            fg.flags = bg.flags = DoRed | DoBlue | DoGreen;
576    
577            cursorglyph = ui_create_glyph(width, height, cursor);
578            maskglyph = ui_create_glyph(width, height, mask);
579            
580            xcursor = XCreatePixmapCursor(display, (Pixmap)cursorglyph,
581                                    (Pixmap)maskglyph, &fg, &bg, x, y);
582    
583            ui_destroy_glyph(maskglyph);
584            ui_destroy_glyph(cursorglyph);
585            xfree(mask);
586            xfree(cursor);
587            return (HCURSOR)xcursor;
588    }
589    
590    void
591    ui_set_cursor(HCURSOR cursor)
592    {
593            XDefineCursor(display, wnd, (Cursor)cursor);
594    }
595    
596    void
597    ui_destroy_cursor(HCURSOR cursor)
598    {
599            XFreeCursor(display, (Cursor)cursor);
600    }
601    
602    #define MAKE_XCOLOR(xc,c) \
603                    (xc)->red   = ((c)->red   << 8) | (c)->red; \
604                    (xc)->green = ((c)->green << 8) | (c)->green; \
605                    (xc)->blue  = ((c)->blue  << 8) | (c)->blue; \
606                    (xc)->flags = DoRed | DoGreen | DoBlue;
607    
608    HCOLOURMAP
609    ui_create_colourmap(COLOURMAP *colours)
610    {
611            COLOURENTRY *entry;
612            int i, ncolours = colours->ncolours;
613    
614            if (owncolmap)
615          {          {
                 COLOURENTRY *entry;  
616                  XColor *xcolours, *xentry;                  XColor *xcolours, *xentry;
617                  Colormap map;                  Colormap map;
618                  int i, ncolours = colours->ncolours;  
619                  xcolours = xmalloc(sizeof(XColor) * ncolours);                  xcolours = xmalloc(sizeof(XColor) * ncolours);
620                  for (i = 0; i < ncolours; i++)                  for (i = 0; i < ncolours; i++)
621                  {                  {
622                          entry = &colours->colours[i];                          entry = &colours->colours[i];
623                          xentry = &xcolours[i];                          xentry = &xcolours[i];
   
624                          xentry->pixel = i;                          xentry->pixel = i;
625                          xentry->red = entry->red << 8;                          MAKE_XCOLOR(xentry, entry);
                         xentry->blue = entry->blue << 8;  
                         xentry->green = entry->green << 8;  
                         xentry->flags = DoRed | DoBlue | DoGreen;  
626                  }                  }
627    
628                  map = XCreateColormap(display, wnd, visual, AllocAll);                  map = XCreateColormap(display, wnd, visual, AllocAll);
629                  XStoreColors(display, map, xcolours, ncolours);                  XStoreColors(display, map, xcolours, ncolours);
630    
631                  xfree(xcolours);                  xfree(xcolours);
632                  return (HCOLOURMAP) map;                  return (HCOLOURMAP)map;
633            }
634            else
635            {
636                    uint32 *map = xmalloc(sizeof(*colmap) * ncolours);
637                    XColor xentry;
638    
639                    for (i = 0; i < ncolours; i++)
640                    {
641                            entry = &colours->colours[i];
642                            MAKE_XCOLOR(&xentry, entry);
643    
644                            if (XAllocColor(display, xcolmap, &xentry) != 0)
645                                    map[i] = xentry.pixel;
646                            else
647                                    map[i] = white;
648                    }
649    
650                    return map;
651          }          }
652  }  }
653    
654  void  void
655  ui_destroy_colourmap(HCOLOURMAP map)  ui_destroy_colourmap(HCOLOURMAP map)
656  {  {
657          XFreeColormap(display, (Colormap) map);          if (owncolmap)
658                    XFreeColormap(display, (Colormap)map);
659            else
660                    xfree(map);
661  }  }
662    
663  void  void
664  ui_set_colourmap(HCOLOURMAP map)  ui_set_colourmap(HCOLOURMAP map)
665  {  {
666            if (owncolmap)
667          /* XXX, change values of all pixels on the screen if the new colmap                  XSetWindowColormap(display, wnd, (Colormap)map);
          * doesn't have the same values as the old one? */  
         if (!private_colormap)  
                 colmap = map;  
668          else          else
669          {                  colmap = map;
                 XSetWindowColormap(display, wnd, (Colormap) map);  
                 if (fullscreen)  
                         XInstallColormap(display, (Colormap) map);  
         }  
670  }  }
671    
672  void  void
# Line 665  void Line 703  void
703  ui_destblt(uint8 opcode,  ui_destblt(uint8 opcode,
704             /* dest */ int x, int y, int cx, int cy)             /* dest */ int x, int y, int cx, int cy)
705  {  {
706          xwin_set_function(opcode);          SET_FUNCTION(opcode);
707            FILL_RECTANGLE(x, y, cx, cy);
708          XFillRectangle(display, wnd, gc, x, y, cx, cy);          RESET_FUNCTION(opcode);
709  }  }
710    
711  void  void
# Line 675  ui_patblt(uint8 opcode, Line 713  ui_patblt(uint8 opcode,
713            /* dest */ int x, int y, int cx, int cy,            /* dest */ int x, int y, int cx, int cy,
714            /* brush */ BRUSH *brush, int bgcolour, int fgcolour)            /* brush */ BRUSH *brush, int bgcolour, int fgcolour)
715  {  {
         Display *dpy = display;  
716          Pixmap fill;          Pixmap fill;
         uint8 i, ipattern[8];  
717    
718          xwin_set_function(opcode);          SET_FUNCTION(opcode);
719    
720          switch (brush->style)          switch (brush->style)
721          {          {
722                  case 0: /* Solid */                  case 0: /* Solid */
723                          XSetForeground(dpy, gc, Ctrans(fgcolour));                          SET_FOREGROUND(fgcolour);
724                          XFillRectangle(dpy, wnd, gc, x, y, cx, cy);                          FILL_RECTANGLE(x, y, cx, cy);
725                          break;                          break;
726    
727                  case 3: /* Pattern */                  case 3: /* Pattern */
728                          for (i = 0; i != 8; i++)                          fill = (Pixmap)ui_create_glyph(8, 8, brush->pattern);
729                                  ipattern[i] = ~brush->pattern[i];  
730                          fill = (Pixmap) ui_create_glyph(8, 8, ipattern);                          SET_FOREGROUND(bgcolour);
731                            SET_BACKGROUND(fgcolour);
732                          XSetForeground(dpy, gc, Ctrans(fgcolour));                          XSetFillStyle(display, gc, FillOpaqueStippled);
733                          XSetBackground(dpy, gc, Ctrans(bgcolour));                          XSetStipple(display, gc, fill);
734                          XSetFillStyle(dpy, gc, FillOpaqueStippled);                          XSetTSOrigin(display, gc, brush->xorigin, brush->yorigin);
                         XSetStipple(dpy, gc, fill);  
735    
736                          XFillRectangle(dpy, wnd, gc, x, y, cx, cy);                          FILL_RECTANGLE(x, y, cx, cy);
737    
738                          XSetFillStyle(dpy, gc, FillSolid);                          XSetFillStyle(display, gc, FillSolid);
739                          ui_destroy_glyph((HGLYPH) fill);                          ui_destroy_glyph((HGLYPH)fill);
740                          break;                          break;
741    
742                  default:                  default:
743                          NOTIMP("brush %d\n", brush->style);                          unimpl("brush %d\n", brush->style);
744          }          }
745    
746            RESET_FUNCTION(opcode);
747  }  }
748    
749  void  void
# Line 714  ui_screenblt(uint8 opcode, Line 751  ui_screenblt(uint8 opcode,
751               /* dest */ int x, int y, int cx, int cy,               /* dest */ int x, int y, int cx, int cy,
752               /* src */ int srcx, int srcy)               /* src */ int srcx, int srcy)
753  {  {
754          xwin_set_function(opcode);          SET_FUNCTION(opcode);
   
755          XCopyArea(display, wnd, wnd, gc, srcx, srcy, cx, cy, x, y);          XCopyArea(display, wnd, wnd, gc, srcx, srcy, cx, cy, x, y);
756            if (ownbackstore)
757                    XCopyArea(display, backstore, backstore, gc, srcx, srcy,
758                              cx, cy, x, y);
759            RESET_FUNCTION(opcode);
760  }  }
761    
762  void  void
# Line 724  ui_memblt(uint8 opcode, Line 764  ui_memblt(uint8 opcode,
764            /* dest */ int x, int y, int cx, int cy,            /* dest */ int x, int y, int cx, int cy,
765            /* src */ HBITMAP src, int srcx, int srcy)            /* src */ HBITMAP src, int srcx, int srcy)
766  {  {
767          xwin_set_function(opcode);          SET_FUNCTION(opcode);
768            XCopyArea(display, (Pixmap)src, wnd, gc, srcx, srcy, cx, cy, x, y);
769          XCopyArea(display, (Pixmap) src, wnd, gc, srcx, srcy, cx, cy, x, y);          if (ownbackstore)
770                    XCopyArea(display, (Pixmap)src, backstore, gc, srcx, srcy,
771                              cx, cy, x, y);
772            RESET_FUNCTION(opcode);
773  }  }
774    
775  void  void
# Line 754  ui_triblt(uint8 opcode, Line 797  ui_triblt(uint8 opcode,
797                                    brush, bgcolour, fgcolour);                                    brush, bgcolour, fgcolour);
798                          break;                          break;
799    
800                  case 0xc0:                  case 0xc0:      /* PSa */
801                          ui_memblt(ROP2_COPY, x, y, cx, cy, src, srcx, srcy);                          ui_memblt(ROP2_COPY, x, y, cx, cy, src, srcx, srcy);
802                          ui_patblt(ROP2_AND, x, y, cx, cy, brush, bgcolour,                          ui_patblt(ROP2_AND, x, y, cx, cy, brush, bgcolour,
803                                    fgcolour);                                    fgcolour);
804                          break;                          break;
805    
806                  default:                  default:
807                          NOTIMP("triblt 0x%x\n", opcode);                          unimpl("triblt 0x%x\n", opcode);
808                          ui_memblt(ROP2_COPY, x, y, cx, cy, src, srcx, srcy);                          ui_memblt(ROP2_COPY, x, y, cx, cy, src, srcx, srcy);
809          }          }
810  }  }
# Line 771  ui_line(uint8 opcode, Line 814  ui_line(uint8 opcode,
814          /* dest */ int startx, int starty, int endx, int endy,          /* dest */ int startx, int starty, int endx, int endy,
815          /* pen */ PEN *pen)          /* pen */ PEN *pen)
816  {  {
817          xwin_set_function(opcode);          SET_FUNCTION(opcode);
818            SET_FOREGROUND(pen->colour);
         XSetForeground(display, gc, Ctrans(pen->colour));  
819          XDrawLine(display, wnd, gc, startx, starty, endx, endy);          XDrawLine(display, wnd, gc, startx, starty, endx, endy);
820            if (ownbackstore)
821                    XDrawLine(display, backstore, gc, startx, starty, endx, endy);
822            RESET_FUNCTION(opcode);
823  }  }
824    
825  void  void
# Line 782  ui_rect( Line 827  ui_rect(
827                 /* dest */ int x, int y, int cx, int cy,                 /* dest */ int x, int y, int cx, int cy,
828                 /* brush */ int colour)                 /* brush */ int colour)
829  {  {
830          xwin_set_function(ROP2_COPY);          SET_FOREGROUND(colour);
831            FILL_RECTANGLE(x, y, cx, cy);
         XSetForeground(display, gc, Ctrans(colour));  
         XFillRectangle(display, wnd, gc, x, y, cx, cy);  
832  }  }
833    
834  void  void
# Line 794  ui_draw_glyph(int mixmode, Line 837  ui_draw_glyph(int mixmode,
837                /* src */ HGLYPH glyph, int srcx, int srcy, int bgcolour,                /* src */ HGLYPH glyph, int srcx, int srcy, int bgcolour,
838                int fgcolour)                int fgcolour)
839  {  {
840          Pixmap pixmap = (Pixmap) glyph;          SET_FOREGROUND(fgcolour);
841            SET_BACKGROUND(bgcolour);
         xwin_set_function(ROP2_COPY);  
842    
843            XSetFillStyle(display, gc, (mixmode == MIX_TRANSPARENT)
844                          ? FillStippled : FillOpaqueStippled);
845            XSetStipple(display, gc, (Pixmap)glyph);
846            XSetTSOrigin(display, gc, x, y);
847    
848          XSetForeground(display, gc, Ctrans(fgcolour));          FILL_RECTANGLE(x, y, cx, cy);
         switch (mixmode)  
         {  
                 case MIX_TRANSPARENT:  
                         XSetStipple(display, gc, pixmap);  
                         XSetFillStyle(display, gc, FillStippled);  
                         XSetTSOrigin(display, gc, x, y);  
                         XFillRectangle(display, wnd, gc, x, y, cx, cy);  
                         XSetFillStyle(display, gc, FillSolid);  
                         break;  
   
                 case MIX_OPAQUE:  
                         XSetBackground(display, gc, Ctrans(bgcolour));  
 /*      XCopyPlane (display, pixmap, back_pixmap, back_gc, srcx, srcy, cx, cy, x, y, 1); */  
                         XSetStipple(display, gc, pixmap);  
                         XSetFillStyle(display, gc, FillOpaqueStippled);  
                         XSetTSOrigin(display, gc, x, y);  
                         XFillRectangle(display, wnd, gc, x, y, cx, cy);  
                         XSetFillStyle(display, gc, FillSolid);  
                         break;  
849    
850                  default:          XSetFillStyle(display, gc, FillSolid);
                         NOTIMP("mix %d\n", mixmode);  
         }  
851  }  }
852    
853  void  void
# Line 832  ui_draw_text(uint8 font, uint8 flags, in Line 857  ui_draw_text(uint8 font, uint8 flags, in
857               int bgcolour, int fgcolour, uint8 *text, uint8 length)               int bgcolour, int fgcolour, uint8 *text, uint8 length)
858  {  {
859          FONTGLYPH *glyph;          FONTGLYPH *glyph;
860          int i, xyoffset;          int i, offset;
861    
862          xwin_set_function(ROP2_COPY);          SET_FOREGROUND(bgcolour);
         XSetForeground(display, gc, Ctrans(bgcolour));  
863    
864          if (boxcx > 1)          if (boxcx > 1)
865                  XFillRectangle(display, wnd, gc, boxx, boxy, boxcx, boxcy);          {
866                    FILL_RECTANGLE(boxx, boxy, boxcx, boxcy);
867            }
868          else if (mixmode == MIX_OPAQUE)          else if (mixmode == MIX_OPAQUE)
869                  XFillRectangle(display, wnd, gc, clipx, clipy, clipcx, clipcy);          {
870                    FILL_RECTANGLE(clipx, clipy, clipcx, clipcy);
871            }
872    
873          /* Paint text, character by character */          /* Paint text, character by character */
874          for (i = 0; i < length; i++)          for (i = 0; i < length; i++)
# Line 848  ui_draw_text(uint8 font, uint8 flags, in Line 876  ui_draw_text(uint8 font, uint8 flags, in
876                  glyph = cache_get_font(font, text[i]);                  glyph = cache_get_font(font, text[i]);
877    
878                  if (!(flags & TEXT2_IMPLICIT_X))                  if (!(flags & TEXT2_IMPLICIT_X))
   
879                  {                  {
880                          xyoffset = text[++i];                          offset = text[++i];
881                          if ((xyoffset & 0x80))                          if (offset & 0x80)
882                          {                                  offset = ((offset & 0x7f) << 8) | text[++i];
                                 if (flags & 0x04)       /* vertical text */  
                                         y += text[++i] | (text[++i] << 8);  
                                 else  
                                         x += text[++i] | (text[++i] << 8);  
                         }  
                         else  
                         {  
                                 if (flags & 0x04)       /* vertical text */  
                                         y += xyoffset;  
                                 else  
                                         x += xyoffset;  
                         }  
883    
884                            if (flags & TEXT2_VERTICAL)
885                                    y += offset;
886                            else
887                                    x += offset;
888                  }                  }
889    
890                  if (glyph != NULL)                  if (glyph != NULL)
891                  {                  {
892                          ui_draw_glyph(mixmode, x + (short) glyph->offset,                          ui_draw_glyph(mixmode, x + (short) glyph->offset,
# Line 887  ui_desktop_save(uint32 offset, int x, in Line 907  ui_desktop_save(uint32 offset, int x, in
907          Pixmap pix;          Pixmap pix;
908          XImage *image;          XImage *image;
909    
910          pix = XCreatePixmap(display, wnd, cx, cy, depth);          if (ownbackstore)
911          xwin_set_function(ROP2_COPY);          {
912                    image = XGetImage(display, backstore, x, y, cx, cy, AllPlanes,
913          XCopyArea(display, wnd, pix, gc, x, y, cx, cy, 0, 0);                                    ZPixmap);
914          image = XGetImage(display, pix, 0, 0, cx, cy, AllPlanes, ZPixmap);          }
915            else
916            {
917                    pix = XCreatePixmap(display, wnd, cx, cy, depth);
918                    XCopyArea(display, wnd, pix, gc, x, y, cx, cy, 0, 0);
919                    image = XGetImage(display, pix, 0, 0, cx, cy, AllPlanes,
920                                      ZPixmap);
921                    XFreePixmap(display, pix);
922            }
923    
924          offset *= bpp/8;          offset *= bpp/8;
925          cache_put_desktop(offset, cx, cy, image->bytes_per_line,          cache_put_desktop(offset, cx, cy, image->bytes_per_line,
926                            bpp/8, image->data);                            bpp/8, image->data);
927    
928          XDestroyImage(image);          XDestroyImage(image);
         XFreePixmap(display, pix);  
929  }  }
930    
931  void  void
# Line 911  ui_desktop_restore(uint32 offset, int x, Line 938  ui_desktop_restore(uint32 offset, int x,
938          data = cache_get_desktop(offset, cx, cy, bpp/8);          data = cache_get_desktop(offset, cx, cy, bpp/8);
939          if (data == NULL)          if (data == NULL)
940                  return;                  return;
941          image =  
942                  XCreateImage(display, visual,          image = XCreateImage(display, visual, depth, ZPixmap,
                              depth, ZPixmap,  
943                               0, data, cx, cy, BitmapPad(display),                               0, data, cx, cy, BitmapPad(display),
944                               cx * bpp/8);                               cx * bpp/8);
         xwin_set_function(ROP2_COPY);  
         XPutImage(display, wnd, gc, image, 0, 0, x, y, cx, cy);  
         XFree(image);  
 }  
   
 /* unroll defines, used to make the loops a bit more readable... */  
 #define unroll8Expr(uexp) uexp uexp uexp uexp uexp uexp uexp uexp  
 #define unroll8Lefts(uexp) case 7: uexp \  
         case 6: uexp \  
         case 5: uexp \  
         case 4: uexp \  
         case 3: uexp \  
         case 2: uexp \  
         case 1: uexp  
945    
946  static uint8 *          if (ownbackstore)
 translate(int width, int height, uint8 *data)  
 {  
         uint32 i;  
         uint32 size = width * height;  
         uint8 *d2 = xmalloc(size * bpp/8);  
         uint8 *d3 = d2;  
         uint32 pix;  
         i = (size & ~0x7);  
   
         /* XXX: where are the bits swapped??? */  
 #ifdef L_ENDIAN                 /* little-endian */  
         /* big-endian screen */  
         if (screen_msbfirst)  
947          {          {
948                  switch (bpp)                  XPutImage(display, backstore, gc, image, 0, 0, x, y, cx, cy);
949                  {                  XCopyArea(display, backstore, wnd, gc, x, y, cx, cy, x, y);
                         case 32:  
                                 while (i)  
                                 {  
                                         unroll8Expr(pix = colmap[*data++];  
                                                     *d3++ = pix >> 24;  
                                                     *d3++ = pix >> 16;  
                                                     *d3++ = pix >> 8;  
                                                     *d3++ = pix;) i -= 8;  
                                 }  
                                 i = (size & 0x7);  
                                 if (i != 0)  
                                         switch (i)  
                                         {  
                                                         unroll8Lefts(pix =  
                                                                      colmap  
                                                                      [*data++];  
                                                                      *d3++ =  
                                                                      pix >>  
                                                                      24;  
                                                                      *d3++ =  
                                                                      pix >>  
                                                                      16;  
                                                                      *d3++ =  
                                                                      pix >> 8;  
                                                                      *d3++ =  
                                                                      pix;)}  
                                 break;  
                         case 24:  
                                 while (i)  
                                 {  
                                         unroll8Expr(pix = colmap[*data++];  
                                                     *d3++ = pix >> 16;  
                                                     *d3++ = pix >> 8;  
                                                     *d3++ = pix;) i -= 8;  
                                 }  
                                 i = (size & 0x7);  
                                 if (i != 0)  
                                         switch (i)  
                                         {  
                                                         unroll8Lefts(pix =  
                                                                      colmap  
                                                                      [*data++];  
                                                                      *d3++ =  
                                                                      pix >>  
                                                                      16;  
                                                                      *d3++ =  
                                                                      pix >> 8;  
                                                                      *d3++ =  
                                                                      pix;)}  
                                 break;  
                         case 16:  
                                 while (i)  
                                 {  
                                         unroll8Expr(pix = colmap[*data++];  
                                                     *d3++ = pix >> 8;  
                                                     *d3++ = pix;) i -= 8;  
                                 }  
                                 i = (size & 0x7);  
                                 if (i != 0)  
                                         switch (i)  
                                         {  
                                                         unroll8Lefts(pix =  
                                                                      colmap  
                                                                      [*data++];  
                                                                      *d3++ =  
                                                                      pix >> 8;  
                                                                      *d3++ =  
                                                                      pix;)}  
                                 break;  
                         case 8:  
                                 while (i)  
                                 {  
                                         unroll8Expr(pix = colmap[*data++];  
                                                     *d3++ = pix;  
                                                 )i -= 8;  
                                 }  
                                 i = (size & 0x7);  
                                 if (i != 0)  
                                         switch (i)  
                                         {  
                                                         unroll8Lefts(pix =  
                                                                      colmap  
                                                                      [*data++];  
                                                                      *d3++ =  
                                                                      pix;)}  
                                 break;  
                 }  
         }  
         else  
         {                       /* little-endian screen */  
                 switch (bpp)  
                 {  
                         case 32:  
                                 while (i)  
                                 {  
                                         unroll8Expr(*((uint32 *) d3) =  
                                                     colmap[*data++];  
                                                     d3 += sizeof(uint32);  
                                                 )i -= 8;  
                                 }  
                                 i = (size & 0x7);  
                                 if (i != 0)  
                                         switch (i)  
                                         {  
                                                         unroll8Lefts(*  
                                                                      ((uint32  
                                                                        *) d3)  
 = colmap[*data++];  
 d3 += sizeof(uint32);  
                                         )}  
                                 break;  
                         case 24:  
                                 while (i)  
                                 {  
                                         unroll8Expr(pix = colmap[*data++];  
                                                     *d3++ = pix;  
                                                     *d3++ = pix >> 8;  
                                                     *d3++ = pix >> 16;  
                                                 )i -= 8;  
                                 }  
                                 i = (size & 0x7);  
                                 if (i != 0)  
                                         switch (i)  
                                         {  
                                                         unroll8Lefts(pix =  
                                                                      colmap  
                                                                      [*data++];  
                                                                      *d3++ =  
                                                                      pix;  
                                                                      *d3++ =  
                                                                      pix >> 8;  
                                                                      *d3++ =  
                                                                      pix >>  
                                                                      16;)}  
                                 break;  
                         case 16:  
                                 while (i)  
                                 {  
                                         unroll8Expr(pix = colmap[*data++];  
                                                     *d3++ = pix;  
                                                     *d3++ = pix >> 8;  
                                                 )i -= 8;  
                                 }  
                                 i = (size & 0x7);  
                                 if (i != 0)  
                                         switch (i)  
                                         {  
                                                         unroll8Lefts(pix =  
                                                                      colmap  
                                                                      [*data++];  
                                                                      *d3++ =  
                                                                      pix;  
                                                                      *d3++ =  
                                                                      pix >> 8;  
                                         )}  
                                 break;  
                         case 8:  
                                 while (i)  
                                 {  
                                         unroll8Expr(pix = colmap[*data++];  
                                                     *d3++ = pix;  
                                                 )i -= 8;  
                                 }  
                                 i = (size & 0x7);  
                                 if (i != 0)  
                                         switch (i)  
                                         {  
                                                         unroll8Lefts(pix =  
                                                                      colmap  
                                                                      [*data++];  
                                                                      *d3++ =  
                                                                      pix;)}  
                 }  
         }  
   
 #else /* bigendian-compiled */  
         if (screen_msbfirst)  
         {  
                 /* big-endian screen */  
                 switch (bpp)  
                 {  
                         case 32:  
                                 while (i)  
                                 {  
                                         unroll8Expr(*((uint32 *) d3) =  
                                                     colmap[*data++];  
                                                     d3 += sizeof(uint32);  
                                                 )i -= 8;  
                                 }  
                                 i = (size & 0x7);  
                                 if (i != 0)  
                                         switch (i)  
                                         {  
                                                         unroll8Lefts(*  
                                                                      ((uint32  
                                                                        *) d3)  
 = colmap[*data++];  
 d3 += sizeof(uint32);  
                                         )}  
                                 break;  
                         case 24:  
                                 while (i)  
                                 {  
                                         unroll8Expr(pix = colmap[*data++];  
                                                     *d3++ = pix;  
                                                     *d3++ = pix >> 8;  
                                                     *d3++ = pix >> 16;  
                                                 )i -= 8;  
                                 }  
                                 i = (size & 0x7);  
                                 if (i != 0)  
                                         switch (i)  
                                         {  
                                                         unroll8Lefts(pix =  
                                                                      colmap  
                                                                      [*data++];  
                                                                      *d3++ =  
                                                                      pix;  
                                                                      *d3++ =  
                                                                      pix >> 8;  
                                                                      *d3++ =  
                                                                      pix >>  
                                                                      16;)}  
                                 break;  
                         case 16:  
                                 while (i)  
                                 {  
                                         unroll8Expr(pix = colmap[*data++];  
                                                     *d3++ = pix;  
                                                     *d3++ = pix >> 8;  
                                                 )i -= 8;  
                                 }  
                                 i = (size & 0x7);  
                                 if (i != 0)  
                                         switch (i)  
                                         {  
                                                         unroll8Lefts(pix =  
                                                                      colmap  
                                                                      [*data++];  
                                                                      *d3++ =  
                                                                      pix;  
                                                                      *d3++ =  
                                                                      pix >> 8;  
                                         )}  
                                 break;  
                         case 8:  
                                 while (i)  
                                 {  
                                         unroll8Expr(pix = colmap[*data++];  
                                                     *d3++ = pix;  
                                                 )i -= 8;  
                                 }  
                                 i = (size & 0x7);  
                                 if (i != 0)  
                                         switch (i)  
                                         {  
                                                         unroll8Lefts(pix =  
                                                                      colmap  
                                                                      [*data++];  
                                                                      *d3++ =  
                                                                      pix;)}  
                 }  
950          }          }
951          else          else
952          {          {
953                  /* little-endian screen */                  XPutImage(display, wnd, gc, image, 0, 0, x, y, cx, cy);
                 switch (bpp)  
                 {  
                         case 32:  
                                 while (i)  
                                 {  
                                         unroll8Expr(pix = colmap[*data++];  
                                                     *d3++ = pix;  
                                                     *d3++ = pix >> 8;  
                                                     *d3++ = pix >> 16;  
                                                     *d3++ = pix >> 24;  
                                                 )i -= 8;  
                                 }  
                                 i = (size & 0x7);  
                                 if (i != 0)  
                                         switch (i)  
                                         {  
                                                         unroll8Lefts(pix =  
                                                                      colmap  
                                                                      [*data++];  
                                                                      *d3++ =  
                                                                      pix;  
                                                                      *d3++ =  
                                                                      pix >> 8;  
                                                                      *d3++ =  
                                                                      pix >>  
                                                                      16;  
                                                                      *d3++ =  
                                                                      pix >>  
                                                                      24;)}  
                                 break;  
                         case 24:  
                                 while (i)  
                                 {  
                                         unroll8Expr(pix = colmap[*data++];  
                                                     *d3++ = pix;  
                                                     *d3++ = pix >> 8;  
                                                     *d3++ = pix >> 16;  
                                                 )i -= 8;  
                                 }  
                                 i = (size & 0x7);  
                                 if (i != 0)  
                                         switch (i)  
                                         {  
                                                         unroll8Lefts(pix =  
                                                                      colmap  
                                                                      [*data++];  
                                                                      *d3++ =  
                                                                      pix;  
                                                                      *d3++ =  
                                                                      pix >> 8;  
                                                                      *d3++ =  
                                                                      pix >>  
                                                                      16;)}  
                                 break;  
                         case 16:  
                                 while (i)  
                                 {  
                                         unroll8Expr(pix = colmap[*data++];  
                                                     *d3++ = pix;  
                                                     *d3++ = pix >> 8;  
                                                 )i -= 8;  
                                 }  
                                 i = (size & 0x7);  
                                 if (i != 0)  
                                         switch (i)  
                                         {  
                                                         unroll8Lefts(pix =  
                                                                      colmap  
                                                                      [*data++];  
                                                                      *d3++ =  
                                                                      pix;  
                                                                      *d3++ =  
                                                                      pix >> 8;  
                                         )}  
                                 break;  
                         case 8:  
                                 while (i)  
                                 {  
                                         unroll8Expr(pix = colmap[*data++];  
                                                     *d3++ = pix;  
                                                 )i -= 8;  
                                 }  
                                 i = (size & 0x7);  
                                 if (i != 0)  
                                         switch (i)  
                                         {  
                                                         unroll8Lefts(pix =  
                                                                      colmap  
                                                                      [*data++];  
                                                                      *d3++ =  
                                                                      pix;)}  
                 }  
954          }          }
 #endif  
955    
956          return d2;          XFree(image);
957  }  }

Legend:
Removed from v.28  
changed lines
  Added in v.31

  ViewVC Help
Powered by ViewVC 1.1.26