Alexandre Julliard | 349a953 | 1997-02-02 19:01:52 +0000 | [diff] [blame] | 1 | /* |
Huw D M Davies | 87f87bf | 1998-10-28 09:53:53 +0000 | [diff] [blame] | 2 | * X11DRV bitmap objects |
Alexandre Julliard | 349a953 | 1997-02-02 19:01:52 +0000 | [diff] [blame] | 3 | * |
| 4 | * Copyright 1993 Alexandre Julliard |
Noel Borthwick | d05b7be | 1999-09-20 15:42:47 +0000 | [diff] [blame] | 5 | * 1999 Noel Borthwick |
Alexandre Julliard | 349a953 | 1997-02-02 19:01:52 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
Patrik Stridvall | ab121e7 | 1999-02-04 11:11:01 +0000 | [diff] [blame] | 8 | #include "config.h" |
| 9 | |
Alexandre Julliard | 60ce85c | 1998-02-01 18:33:27 +0000 | [diff] [blame] | 10 | #include "ts_xlib.h" |
| 11 | #include "ts_xutil.h" |
Patrik Stridvall | ab121e7 | 1999-02-04 11:11:01 +0000 | [diff] [blame] | 12 | |
| 13 | #include <stdio.h> |
| 14 | #include <stdlib.h> |
Alexandre Julliard | 349a953 | 1997-02-02 19:01:52 +0000 | [diff] [blame] | 15 | #include "gdi.h" |
| 16 | #include "callback.h" |
| 17 | #include "dc.h" |
| 18 | #include "bitmap.h" |
| 19 | #include "heap.h" |
Alexandre Julliard | 61fece0 | 1999-06-26 19:09:08 +0000 | [diff] [blame] | 20 | #include "debugtools.h" |
Patrik Stridvall | ab121e7 | 1999-02-04 11:11:01 +0000 | [diff] [blame] | 21 | #include "local.h" |
Huw D M Davies | 87f87bf | 1998-10-28 09:53:53 +0000 | [diff] [blame] | 22 | #include "x11drv.h" |
Jeremy White | d3e22d9 | 2000-02-10 19:03:02 +0000 | [diff] [blame] | 23 | #include "wingdi.h" |
| 24 | #include "windef.h" |
Patrik Stridvall | ab121e7 | 1999-02-04 11:11:01 +0000 | [diff] [blame] | 25 | #include "wine/winuser16.h" |
Huw D M Davies | 87f87bf | 1998-10-28 09:53:53 +0000 | [diff] [blame] | 26 | |
Alexandre Julliard | 9383eb9 | 2000-03-25 14:05:06 +0000 | [diff] [blame] | 27 | DEFAULT_DEBUG_CHANNEL(x11drv); |
Patrik Stridvall | b4b9fae | 1999-04-19 14:56:29 +0000 | [diff] [blame] | 28 | |
Huw D M Davies | 87f87bf | 1998-10-28 09:53:53 +0000 | [diff] [blame] | 29 | /* GCs used for B&W and color bitmap operations */ |
| 30 | GC BITMAP_monoGC = 0, BITMAP_colorGC = 0; |
| 31 | |
| 32 | |
Alexandre Julliard | 349a953 | 1997-02-02 19:01:52 +0000 | [diff] [blame] | 33 | /*********************************************************************** |
| 34 | * X11DRV_BITMAP_Init |
| 35 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 36 | BOOL X11DRV_BITMAP_Init(void) |
Alexandre Julliard | 349a953 | 1997-02-02 19:01:52 +0000 | [diff] [blame] | 37 | { |
| 38 | Pixmap tmpPixmap; |
| 39 | |
| 40 | /* Create the necessary GCs */ |
| 41 | |
Patrik Stridvall | ab121e7 | 1999-02-04 11:11:01 +0000 | [diff] [blame] | 42 | if ((tmpPixmap = TSXCreatePixmap(display, |
| 43 | X11DRV_GetXRootWindow(), |
| 44 | 1, 1, |
| 45 | 1))) |
Alexandre Julliard | 349a953 | 1997-02-02 19:01:52 +0000 | [diff] [blame] | 46 | { |
Alexandre Julliard | 60ce85c | 1998-02-01 18:33:27 +0000 | [diff] [blame] | 47 | BITMAP_monoGC = TSXCreateGC( display, tmpPixmap, 0, NULL ); |
| 48 | TSXSetGraphicsExposures( display, BITMAP_monoGC, False ); |
| 49 | TSXFreePixmap( display, tmpPixmap ); |
Alexandre Julliard | 349a953 | 1997-02-02 19:01:52 +0000 | [diff] [blame] | 50 | } |
| 51 | |
Alexandre Julliard | 9383eb9 | 2000-03-25 14:05:06 +0000 | [diff] [blame] | 52 | if (X11DRV_GetDepth() != 1) |
Alexandre Julliard | 349a953 | 1997-02-02 19:01:52 +0000 | [diff] [blame] | 53 | { |
Alexandre Julliard | 9383eb9 | 2000-03-25 14:05:06 +0000 | [diff] [blame] | 54 | if ((tmpPixmap = TSXCreatePixmap(display, X11DRV_GetXRootWindow(), |
| 55 | 1, 1, X11DRV_GetDepth()))) |
Alexandre Julliard | 349a953 | 1997-02-02 19:01:52 +0000 | [diff] [blame] | 56 | { |
Alexandre Julliard | 60ce85c | 1998-02-01 18:33:27 +0000 | [diff] [blame] | 57 | BITMAP_colorGC = TSXCreateGC( display, tmpPixmap, 0, NULL ); |
| 58 | TSXSetGraphicsExposures( display, BITMAP_colorGC, False ); |
| 59 | TSXFreePixmap( display, tmpPixmap ); |
Alexandre Julliard | 349a953 | 1997-02-02 19:01:52 +0000 | [diff] [blame] | 60 | } |
| 61 | } |
| 62 | return TRUE; |
| 63 | } |
| 64 | |
| 65 | /*********************************************************************** |
| 66 | * X11DRV_BITMAP_SelectObject |
| 67 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 68 | HBITMAP X11DRV_BITMAP_SelectObject( DC * dc, HBITMAP hbitmap, |
Alexandre Julliard | 349a953 | 1997-02-02 19:01:52 +0000 | [diff] [blame] | 69 | BITMAPOBJ * bmp ) |
| 70 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 71 | HRGN hrgn; |
| 72 | HBITMAP prevHandle = dc->w.hBitmap; |
Huw D M Davies | 9c68faa | 1998-11-25 12:36:03 +0000 | [diff] [blame] | 73 | X11DRV_PDEVICE *physDev = (X11DRV_PDEVICE *)dc->physDev; |
| 74 | |
Huw D M Davies | 87f87bf | 1998-10-28 09:53:53 +0000 | [diff] [blame] | 75 | |
Alexandre Julliard | 349a953 | 1997-02-02 19:01:52 +0000 | [diff] [blame] | 76 | if (!(dc->w.flags & DC_MEMORY)) return 0; |
| 77 | |
Alexandre Julliard | a08e2cf | 2000-03-28 13:37:50 +0000 | [diff] [blame] | 78 | if(!bmp->physBitmap) |
Huw D M Davies | 87f87bf | 1998-10-28 09:53:53 +0000 | [diff] [blame] | 79 | if(!X11DRV_CreateBitmap(hbitmap)) |
| 80 | return 0; |
| 81 | |
Alexandre Julliard | a08e2cf | 2000-03-28 13:37:50 +0000 | [diff] [blame] | 82 | if(bmp->funcs != dc->funcs) { |
Alexandre Julliard | 61fece0 | 1999-06-26 19:09:08 +0000 | [diff] [blame] | 83 | WARN("Trying to select non-X11 DDB into an X11 dc\n"); |
Huw D M Davies | 87f87bf | 1998-10-28 09:53:53 +0000 | [diff] [blame] | 84 | return 0; |
| 85 | } |
| 86 | |
Ulrich Weigand | 27bb362 | 1998-10-14 18:06:44 +0000 | [diff] [blame] | 87 | dc->w.totalExtent.left = 0; |
| 88 | dc->w.totalExtent.top = 0; |
| 89 | dc->w.totalExtent.right = bmp->bitmap.bmWidth; |
| 90 | dc->w.totalExtent.bottom = bmp->bitmap.bmHeight; |
| 91 | |
Alexandre Julliard | 349a953 | 1997-02-02 19:01:52 +0000 | [diff] [blame] | 92 | if (dc->w.hVisRgn) |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 93 | SetRectRgn( dc->w.hVisRgn, 0, 0, |
Alexandre Julliard | 2197901 | 1997-03-05 08:22:35 +0000 | [diff] [blame] | 94 | bmp->bitmap.bmWidth, bmp->bitmap.bmHeight ); |
Alexandre Julliard | 349a953 | 1997-02-02 19:01:52 +0000 | [diff] [blame] | 95 | else |
| 96 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 97 | hrgn = CreateRectRgn(0, 0, bmp->bitmap.bmWidth, bmp->bitmap.bmHeight); |
Alexandre Julliard | 349a953 | 1997-02-02 19:01:52 +0000 | [diff] [blame] | 98 | if (!hrgn) return 0; |
| 99 | dc->w.hVisRgn = hrgn; |
| 100 | } |
| 101 | |
Alexandre Julliard | a08e2cf | 2000-03-28 13:37:50 +0000 | [diff] [blame] | 102 | physDev->drawable = (Pixmap)bmp->physBitmap; |
Huw D M Davies | 9c68faa | 1998-11-25 12:36:03 +0000 | [diff] [blame] | 103 | dc->w.hBitmap = hbitmap; |
Alexandre Julliard | 349a953 | 1997-02-02 19:01:52 +0000 | [diff] [blame] | 104 | |
| 105 | /* Change GC depth if needed */ |
| 106 | |
| 107 | if (dc->w.bitsPerPixel != bmp->bitmap.bmBitsPixel) |
| 108 | { |
Huw D M Davies | 9c68faa | 1998-11-25 12:36:03 +0000 | [diff] [blame] | 109 | TSXFreeGC( display, physDev->gc ); |
| 110 | physDev->gc = TSXCreateGC( display, physDev->drawable, 0, NULL ); |
Ulrich Weigand | 9cfeb5b | 1999-03-10 13:26:09 +0000 | [diff] [blame] | 111 | TSXSetGraphicsExposures( display, physDev->gc, False ); |
Alexandre Julliard | 349a953 | 1997-02-02 19:01:52 +0000 | [diff] [blame] | 112 | dc->w.bitsPerPixel = bmp->bitmap.bmBitsPixel; |
| 113 | DC_InitDC( dc ); |
| 114 | } |
| 115 | else CLIPPING_UpdateGCRegion( dc ); /* Just update GC clip region */ |
| 116 | return prevHandle; |
| 117 | } |
Huw D M Davies | 87f87bf | 1998-10-28 09:53:53 +0000 | [diff] [blame] | 118 | |
| 119 | |
| 120 | /*********************************************************************** |
| 121 | * XPutImage_wrapper |
| 122 | * |
| 123 | * Wrapper to call XPutImage with CALL_LARGE_STACK. |
| 124 | */ |
| 125 | |
| 126 | struct XPutImage_descr |
| 127 | { |
| 128 | BITMAPOBJ *bmp; |
| 129 | XImage *image; |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 130 | INT width; |
| 131 | INT height; |
Huw D M Davies | 87f87bf | 1998-10-28 09:53:53 +0000 | [diff] [blame] | 132 | }; |
| 133 | |
| 134 | static int XPutImage_wrapper( const struct XPutImage_descr *descr ) |
| 135 | { |
Alexandre Julliard | a08e2cf | 2000-03-28 13:37:50 +0000 | [diff] [blame] | 136 | return XPutImage( display, (Pixmap)descr->bmp->physBitmap, BITMAP_GC(descr->bmp), |
| 137 | descr->image, 0, 0, 0, 0, descr->width, descr->height ); |
Huw D M Davies | 87f87bf | 1998-10-28 09:53:53 +0000 | [diff] [blame] | 138 | } |
| 139 | |
| 140 | |
| 141 | /**************************************************************************** |
| 142 | * |
| 143 | * X11DRV_CreateBitmap |
| 144 | * |
| 145 | * Create a device dependent X11 bitmap |
| 146 | * |
| 147 | * Returns TRUE on success else FALSE |
| 148 | * |
| 149 | */ |
| 150 | |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 151 | BOOL X11DRV_CreateBitmap( HBITMAP hbitmap ) |
Huw D M Davies | 87f87bf | 1998-10-28 09:53:53 +0000 | [diff] [blame] | 152 | { |
Huw D M Davies | 87f87bf | 1998-10-28 09:53:53 +0000 | [diff] [blame] | 153 | BITMAPOBJ *bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC ); |
| 154 | |
| 155 | if(!bmp) { |
Alexandre Julliard | 61fece0 | 1999-06-26 19:09:08 +0000 | [diff] [blame] | 156 | WARN("Bad bitmap handle %08x\n", hbitmap); |
Huw D M Davies | 87f87bf | 1998-10-28 09:53:53 +0000 | [diff] [blame] | 157 | return FALSE; |
| 158 | } |
| 159 | |
| 160 | /* Check parameters */ |
| 161 | if (bmp->bitmap.bmPlanes != 1) return 0; |
| 162 | if ((bmp->bitmap.bmBitsPixel != 1) && |
Alexandre Julliard | 9383eb9 | 2000-03-25 14:05:06 +0000 | [diff] [blame] | 163 | (bmp->bitmap.bmBitsPixel != X11DRV_GetDepth())) |
| 164 | { |
Alexandre Julliard | 61fece0 | 1999-06-26 19:09:08 +0000 | [diff] [blame] | 165 | ERR("Trying to make bitmap with planes=%d, bpp=%d\n", |
Huw D M Davies | 9c68faa | 1998-11-25 12:36:03 +0000 | [diff] [blame] | 166 | bmp->bitmap.bmPlanes, bmp->bitmap.bmBitsPixel); |
Huw D M Davies | 87f87bf | 1998-10-28 09:53:53 +0000 | [diff] [blame] | 167 | GDI_HEAP_UNLOCK( hbitmap ); |
| 168 | return FALSE; |
| 169 | } |
| 170 | |
Alexandre Julliard | 61fece0 | 1999-06-26 19:09:08 +0000 | [diff] [blame] | 171 | TRACE("(%08x) %dx%d %d bpp\n", hbitmap, bmp->bitmap.bmWidth, |
Huw D M Davies | 8261736 | 1998-11-01 16:35:42 +0000 | [diff] [blame] | 172 | bmp->bitmap.bmHeight, bmp->bitmap.bmBitsPixel); |
| 173 | |
Huw D M Davies | 87f87bf | 1998-10-28 09:53:53 +0000 | [diff] [blame] | 174 | /* Create the pixmap */ |
Alexandre Julliard | a08e2cf | 2000-03-28 13:37:50 +0000 | [diff] [blame] | 175 | if (!(bmp->physBitmap = (void *)TSXCreatePixmap(display, X11DRV_GetXRootWindow(), |
| 176 | bmp->bitmap.bmWidth, bmp->bitmap.bmHeight, |
| 177 | bmp->bitmap.bmBitsPixel))) |
| 178 | { |
Alexandre Julliard | 61fece0 | 1999-06-26 19:09:08 +0000 | [diff] [blame] | 179 | WARN("Can't create Pixmap\n"); |
Huw D M Davies | 87f87bf | 1998-10-28 09:53:53 +0000 | [diff] [blame] | 180 | GDI_HEAP_UNLOCK( hbitmap ); |
| 181 | return FALSE; |
| 182 | } |
Alexandre Julliard | a08e2cf | 2000-03-28 13:37:50 +0000 | [diff] [blame] | 183 | bmp->funcs = &X11DRV_DC_Funcs; |
Huw D M Davies | 87f87bf | 1998-10-28 09:53:53 +0000 | [diff] [blame] | 184 | |
| 185 | if (bmp->bitmap.bmBits) /* Set bitmap bits */ |
| 186 | X11DRV_BitmapBits( hbitmap, bmp->bitmap.bmBits, |
| 187 | bmp->bitmap.bmHeight * bmp->bitmap.bmWidthBytes, |
| 188 | DDB_SET ); |
| 189 | |
| 190 | GDI_HEAP_UNLOCK( hbitmap ); |
| 191 | return TRUE; |
| 192 | } |
| 193 | |
| 194 | |
| 195 | /*********************************************************************** |
| 196 | * X11DRV_BITMAP_GetXImage |
| 197 | * |
| 198 | * Get an X image for a bitmap. For use with CALL_LARGE_STACK. |
| 199 | */ |
| 200 | XImage *X11DRV_BITMAP_GetXImage( const BITMAPOBJ *bmp ) |
| 201 | { |
Alexandre Julliard | a08e2cf | 2000-03-28 13:37:50 +0000 | [diff] [blame] | 202 | return XGetImage( display, (Pixmap)bmp->physBitmap, |
Huw D M Davies | 87f87bf | 1998-10-28 09:53:53 +0000 | [diff] [blame] | 203 | 0, 0, bmp->bitmap.bmWidth, bmp->bitmap.bmHeight, |
| 204 | AllPlanes, ZPixmap ); |
| 205 | } |
| 206 | |
| 207 | |
| 208 | /*********************************************************************** |
| 209 | * X11DRV_GetBitmapBits |
| 210 | * |
| 211 | * RETURNS |
| 212 | * Success: Number of bytes copied |
| 213 | * Failure: 0 |
| 214 | */ |
| 215 | static LONG X11DRV_GetBitmapBits(BITMAPOBJ *bmp, void *buffer, LONG count) |
| 216 | { |
| 217 | LONG old_height, height; |
| 218 | XImage *image; |
Huw D M Davies | e42ee26 | 1999-03-27 15:59:12 +0000 | [diff] [blame] | 219 | LPBYTE tbuf, startline; |
| 220 | int h, w; |
Huw D M Davies | 87f87bf | 1998-10-28 09:53:53 +0000 | [diff] [blame] | 221 | |
Alexandre Julliard | 61fece0 | 1999-06-26 19:09:08 +0000 | [diff] [blame] | 222 | TRACE("(bmp=%p, buffer=%p, count=0x%lx)\n", bmp, buffer, count); |
Huw D M Davies | 8261736 | 1998-11-01 16:35:42 +0000 | [diff] [blame] | 223 | |
Huw D M Davies | 87f87bf | 1998-10-28 09:53:53 +0000 | [diff] [blame] | 224 | EnterCriticalSection( &X11DRV_CritSection ); |
| 225 | |
| 226 | /* Hack: change the bitmap height temporarily to avoid */ |
| 227 | /* getting unnecessary bitmap rows. */ |
| 228 | |
| 229 | old_height = bmp->bitmap.bmHeight; |
| 230 | height = bmp->bitmap.bmHeight = count / bmp->bitmap.bmWidthBytes; |
| 231 | |
| 232 | image = (XImage *)CALL_LARGE_STACK( X11DRV_BITMAP_GetXImage, bmp ); |
| 233 | |
| 234 | bmp->bitmap.bmHeight = old_height; |
| 235 | |
| 236 | /* copy XImage to 16 bit padded image buffer with real bitsperpixel */ |
| 237 | |
Huw D M Davies | e42ee26 | 1999-03-27 15:59:12 +0000 | [diff] [blame] | 238 | startline = buffer; |
Huw D M Davies | 87f87bf | 1998-10-28 09:53:53 +0000 | [diff] [blame] | 239 | switch (bmp->bitmap.bmBitsPixel) |
| 240 | { |
| 241 | case 1: |
| 242 | for (h=0;h<height;h++) |
| 243 | { |
Huw D M Davies | e42ee26 | 1999-03-27 15:59:12 +0000 | [diff] [blame] | 244 | tbuf = startline; |
Huw D M Davies | 87f87bf | 1998-10-28 09:53:53 +0000 | [diff] [blame] | 245 | *tbuf = 0; |
| 246 | for (w=0;w<bmp->bitmap.bmWidth;w++) |
| 247 | { |
| 248 | if ((w%8) == 0) |
| 249 | *tbuf = 0; |
| 250 | *tbuf |= XGetPixel(image,w,h)<<(7-(w&7)); |
| 251 | if ((w&7) == 7) ++tbuf; |
| 252 | } |
Huw D M Davies | e42ee26 | 1999-03-27 15:59:12 +0000 | [diff] [blame] | 253 | startline += bmp->bitmap.bmWidthBytes; |
Huw D M Davies | 87f87bf | 1998-10-28 09:53:53 +0000 | [diff] [blame] | 254 | } |
| 255 | break; |
| 256 | case 4: |
| 257 | for (h=0;h<height;h++) |
| 258 | { |
Huw D M Davies | e42ee26 | 1999-03-27 15:59:12 +0000 | [diff] [blame] | 259 | tbuf = startline; |
Huw D M Davies | 87f87bf | 1998-10-28 09:53:53 +0000 | [diff] [blame] | 260 | for (w=0;w<bmp->bitmap.bmWidth;w++) |
| 261 | { |
| 262 | if (!(w & 1)) *tbuf = XGetPixel( image, w, h) << 4; |
| 263 | else *tbuf++ |= XGetPixel( image, w, h) & 0x0f; |
| 264 | } |
Huw D M Davies | e42ee26 | 1999-03-27 15:59:12 +0000 | [diff] [blame] | 265 | startline += bmp->bitmap.bmWidthBytes; |
Huw D M Davies | 87f87bf | 1998-10-28 09:53:53 +0000 | [diff] [blame] | 266 | } |
| 267 | break; |
| 268 | case 8: |
| 269 | for (h=0;h<height;h++) |
| 270 | { |
Huw D M Davies | e42ee26 | 1999-03-27 15:59:12 +0000 | [diff] [blame] | 271 | tbuf = startline; |
Huw D M Davies | 87f87bf | 1998-10-28 09:53:53 +0000 | [diff] [blame] | 272 | for (w=0;w<bmp->bitmap.bmWidth;w++) |
| 273 | *tbuf++ = XGetPixel(image,w,h); |
Huw D M Davies | e42ee26 | 1999-03-27 15:59:12 +0000 | [diff] [blame] | 274 | startline += bmp->bitmap.bmWidthBytes; |
Huw D M Davies | 87f87bf | 1998-10-28 09:53:53 +0000 | [diff] [blame] | 275 | } |
| 276 | break; |
| 277 | case 15: |
| 278 | case 16: |
| 279 | for (h=0;h<height;h++) |
| 280 | { |
Huw D M Davies | e42ee26 | 1999-03-27 15:59:12 +0000 | [diff] [blame] | 281 | tbuf = startline; |
Huw D M Davies | 87f87bf | 1998-10-28 09:53:53 +0000 | [diff] [blame] | 282 | for (w=0;w<bmp->bitmap.bmWidth;w++) |
| 283 | { |
| 284 | long pixel = XGetPixel(image,w,h); |
| 285 | |
| 286 | *tbuf++ = pixel & 0xff; |
| 287 | *tbuf++ = (pixel>>8) & 0xff; |
| 288 | } |
Huw D M Davies | e42ee26 | 1999-03-27 15:59:12 +0000 | [diff] [blame] | 289 | startline += bmp->bitmap.bmWidthBytes; |
Huw D M Davies | 87f87bf | 1998-10-28 09:53:53 +0000 | [diff] [blame] | 290 | } |
| 291 | break; |
| 292 | case 24: |
| 293 | for (h=0;h<height;h++) |
| 294 | { |
Huw D M Davies | e42ee26 | 1999-03-27 15:59:12 +0000 | [diff] [blame] | 295 | tbuf = startline; |
Huw D M Davies | 87f87bf | 1998-10-28 09:53:53 +0000 | [diff] [blame] | 296 | for (w=0;w<bmp->bitmap.bmWidth;w++) |
| 297 | { |
| 298 | long pixel = XGetPixel(image,w,h); |
| 299 | |
| 300 | *tbuf++ = pixel & 0xff; |
| 301 | *tbuf++ = (pixel>> 8) & 0xff; |
| 302 | *tbuf++ = (pixel>>16) & 0xff; |
| 303 | } |
Huw D M Davies | e42ee26 | 1999-03-27 15:59:12 +0000 | [diff] [blame] | 304 | startline += bmp->bitmap.bmWidthBytes; |
Huw D M Davies | 87f87bf | 1998-10-28 09:53:53 +0000 | [diff] [blame] | 305 | } |
| 306 | break; |
| 307 | |
| 308 | case 32: |
| 309 | for (h=0;h<height;h++) |
| 310 | { |
Huw D M Davies | e42ee26 | 1999-03-27 15:59:12 +0000 | [diff] [blame] | 311 | tbuf = startline; |
Huw D M Davies | 87f87bf | 1998-10-28 09:53:53 +0000 | [diff] [blame] | 312 | for (w=0;w<bmp->bitmap.bmWidth;w++) |
| 313 | { |
| 314 | long pixel = XGetPixel(image,w,h); |
| 315 | |
| 316 | *tbuf++ = pixel & 0xff; |
| 317 | *tbuf++ = (pixel>> 8) & 0xff; |
| 318 | *tbuf++ = (pixel>>16) & 0xff; |
| 319 | *tbuf++ = (pixel>>24) & 0xff; |
| 320 | } |
Huw D M Davies | e42ee26 | 1999-03-27 15:59:12 +0000 | [diff] [blame] | 321 | startline += bmp->bitmap.bmWidthBytes; |
Huw D M Davies | 87f87bf | 1998-10-28 09:53:53 +0000 | [diff] [blame] | 322 | } |
| 323 | break; |
| 324 | default: |
Alexandre Julliard | 61fece0 | 1999-06-26 19:09:08 +0000 | [diff] [blame] | 325 | FIXME("Unhandled bits:%d\n", bmp->bitmap.bmBitsPixel); |
Huw D M Davies | 87f87bf | 1998-10-28 09:53:53 +0000 | [diff] [blame] | 326 | } |
| 327 | XDestroyImage( image ); |
| 328 | LeaveCriticalSection( &X11DRV_CritSection ); |
| 329 | |
| 330 | return count; |
| 331 | } |
| 332 | |
| 333 | |
| 334 | |
| 335 | /****************************************************************************** |
| 336 | * X11DRV_SetBitmapBits |
| 337 | * |
| 338 | * RETURNS |
| 339 | * Success: Number of bytes used in setting the bitmap bits |
| 340 | * Failure: 0 |
| 341 | */ |
| 342 | static LONG X11DRV_SetBitmapBits(BITMAPOBJ *bmp, void *bits, LONG count) |
| 343 | { |
| 344 | struct XPutImage_descr descr; |
| 345 | LONG height; |
| 346 | XImage *image; |
Huw D M Davies | e42ee26 | 1999-03-27 15:59:12 +0000 | [diff] [blame] | 347 | LPBYTE sbuf, startline; |
| 348 | int w, h; |
Huw D M Davies | 84dd9fe | 1998-11-01 15:13:53 +0000 | [diff] [blame] | 349 | |
Alexandre Julliard | 61fece0 | 1999-06-26 19:09:08 +0000 | [diff] [blame] | 350 | TRACE("(bmp=%p, bits=%p, count=0x%lx)\n", bmp, bits, count); |
Huw D M Davies | 87f87bf | 1998-10-28 09:53:53 +0000 | [diff] [blame] | 351 | |
Huw D M Davies | 8261736 | 1998-11-01 16:35:42 +0000 | [diff] [blame] | 352 | height = count / bmp->bitmap.bmWidthBytes; |
Huw D M Davies | 84dd9fe | 1998-11-01 15:13:53 +0000 | [diff] [blame] | 353 | |
Huw D M Davies | 87f87bf | 1998-10-28 09:53:53 +0000 | [diff] [blame] | 354 | EnterCriticalSection( &X11DRV_CritSection ); |
Alexandre Julliard | 9383eb9 | 2000-03-25 14:05:06 +0000 | [diff] [blame] | 355 | image = XCreateImage( display, X11DRV_GetVisual(), bmp->bitmap.bmBitsPixel, ZPixmap, 0, NULL, |
Huw D M Davies | 8261736 | 1998-11-01 16:35:42 +0000 | [diff] [blame] | 356 | bmp->bitmap.bmWidth, height, 32, 0 ); |
Dimitrie O. Paun | a20b792 | 2000-04-09 18:41:15 +0000 | [diff] [blame] | 357 | if (!(image->data = (LPBYTE)malloc(image->bytes_per_line * height))) |
| 358 | { |
| 359 | WARN("No memory to create image data.\n"); |
| 360 | XDestroyImage( image ); |
| 361 | LeaveCriticalSection( &X11DRV_CritSection ); |
| 362 | return 0; |
| 363 | } |
Huw D M Davies | 87f87bf | 1998-10-28 09:53:53 +0000 | [diff] [blame] | 364 | |
| 365 | /* copy 16 bit padded image buffer with real bitsperpixel to XImage */ |
Huw D M Davies | e42ee26 | 1999-03-27 15:59:12 +0000 | [diff] [blame] | 366 | |
| 367 | startline = bits; |
| 368 | |
Huw D M Davies | 87f87bf | 1998-10-28 09:53:53 +0000 | [diff] [blame] | 369 | switch (bmp->bitmap.bmBitsPixel) |
| 370 | { |
| 371 | case 1: |
| 372 | for (h=0;h<height;h++) |
| 373 | { |
Huw D M Davies | e42ee26 | 1999-03-27 15:59:12 +0000 | [diff] [blame] | 374 | sbuf = startline; |
Huw D M Davies | 87f87bf | 1998-10-28 09:53:53 +0000 | [diff] [blame] | 375 | for (w=0;w<bmp->bitmap.bmWidth;w++) |
| 376 | { |
| 377 | XPutPixel(image,w,h,(sbuf[0]>>(7-(w&7))) & 1); |
| 378 | if ((w&7) == 7) |
| 379 | sbuf++; |
| 380 | } |
Huw D M Davies | e42ee26 | 1999-03-27 15:59:12 +0000 | [diff] [blame] | 381 | startline += bmp->bitmap.bmWidthBytes; |
Huw D M Davies | 87f87bf | 1998-10-28 09:53:53 +0000 | [diff] [blame] | 382 | } |
| 383 | break; |
| 384 | case 4: |
| 385 | for (h=0;h<height;h++) |
| 386 | { |
Huw D M Davies | e42ee26 | 1999-03-27 15:59:12 +0000 | [diff] [blame] | 387 | sbuf = startline; |
Huw D M Davies | 87f87bf | 1998-10-28 09:53:53 +0000 | [diff] [blame] | 388 | for (w=0;w<bmp->bitmap.bmWidth;w++) |
| 389 | { |
| 390 | if (!(w & 1)) XPutPixel( image, w, h, *sbuf >> 4 ); |
| 391 | else XPutPixel( image, w, h, *sbuf++ & 0xf ); |
| 392 | } |
Huw D M Davies | e42ee26 | 1999-03-27 15:59:12 +0000 | [diff] [blame] | 393 | startline += bmp->bitmap.bmWidthBytes; |
Huw D M Davies | 87f87bf | 1998-10-28 09:53:53 +0000 | [diff] [blame] | 394 | } |
| 395 | break; |
| 396 | case 8: |
| 397 | for (h=0;h<height;h++) |
| 398 | { |
Huw D M Davies | e42ee26 | 1999-03-27 15:59:12 +0000 | [diff] [blame] | 399 | sbuf = startline; |
Huw D M Davies | 87f87bf | 1998-10-28 09:53:53 +0000 | [diff] [blame] | 400 | for (w=0;w<bmp->bitmap.bmWidth;w++) |
| 401 | XPutPixel(image,w,h,*sbuf++); |
Huw D M Davies | e42ee26 | 1999-03-27 15:59:12 +0000 | [diff] [blame] | 402 | startline += bmp->bitmap.bmWidthBytes; |
Huw D M Davies | 87f87bf | 1998-10-28 09:53:53 +0000 | [diff] [blame] | 403 | } |
| 404 | break; |
| 405 | case 15: |
| 406 | case 16: |
| 407 | for (h=0;h<height;h++) |
| 408 | { |
Huw D M Davies | e42ee26 | 1999-03-27 15:59:12 +0000 | [diff] [blame] | 409 | sbuf = startline; |
Huw D M Davies | 87f87bf | 1998-10-28 09:53:53 +0000 | [diff] [blame] | 410 | for (w=0;w<bmp->bitmap.bmWidth;w++) |
| 411 | { |
| 412 | XPutPixel(image,w,h,sbuf[1]*256+sbuf[0]); |
| 413 | sbuf+=2; |
| 414 | } |
Huw D M Davies | e42ee26 | 1999-03-27 15:59:12 +0000 | [diff] [blame] | 415 | startline += bmp->bitmap.bmWidthBytes; |
Huw D M Davies | 87f87bf | 1998-10-28 09:53:53 +0000 | [diff] [blame] | 416 | } |
| 417 | break; |
Huw D M Davies | e42ee26 | 1999-03-27 15:59:12 +0000 | [diff] [blame] | 418 | case 24: |
Huw D M Davies | 87f87bf | 1998-10-28 09:53:53 +0000 | [diff] [blame] | 419 | for (h=0;h<height;h++) |
| 420 | { |
Huw D M Davies | e42ee26 | 1999-03-27 15:59:12 +0000 | [diff] [blame] | 421 | sbuf = startline; |
Huw D M Davies | 87f87bf | 1998-10-28 09:53:53 +0000 | [diff] [blame] | 422 | for (w=0;w<bmp->bitmap.bmWidth;w++) |
| 423 | { |
| 424 | XPutPixel(image,w,h,(sbuf[2]<<16)+(sbuf[1]<<8)+sbuf[0]); |
| 425 | sbuf += 3; |
| 426 | } |
Huw D M Davies | e42ee26 | 1999-03-27 15:59:12 +0000 | [diff] [blame] | 427 | startline += bmp->bitmap.bmWidthBytes; |
Huw D M Davies | 87f87bf | 1998-10-28 09:53:53 +0000 | [diff] [blame] | 428 | } |
| 429 | break; |
| 430 | case 32: |
| 431 | for (h=0;h<height;h++) |
| 432 | { |
Huw D M Davies | e42ee26 | 1999-03-27 15:59:12 +0000 | [diff] [blame] | 433 | sbuf = startline; |
Huw D M Davies | 87f87bf | 1998-10-28 09:53:53 +0000 | [diff] [blame] | 434 | for (w=0;w<bmp->bitmap.bmWidth;w++) |
| 435 | { |
| 436 | XPutPixel(image,w,h,(sbuf[3]<<24)+(sbuf[2]<<16)+(sbuf[1]<<8)+sbuf[0]); |
| 437 | sbuf += 4; |
| 438 | } |
Huw D M Davies | e42ee26 | 1999-03-27 15:59:12 +0000 | [diff] [blame] | 439 | startline += bmp->bitmap.bmWidthBytes; |
Huw D M Davies | 87f87bf | 1998-10-28 09:53:53 +0000 | [diff] [blame] | 440 | } |
| 441 | break; |
| 442 | default: |
Alexandre Julliard | 61fece0 | 1999-06-26 19:09:08 +0000 | [diff] [blame] | 443 | FIXME("Unhandled bits:%d\n", bmp->bitmap.bmBitsPixel); |
Huw D M Davies | 87f87bf | 1998-10-28 09:53:53 +0000 | [diff] [blame] | 444 | |
| 445 | } |
| 446 | |
| 447 | descr.bmp = bmp; |
| 448 | descr.image = image; |
| 449 | descr.width = bmp->bitmap.bmWidth; |
| 450 | descr.height = height; |
Huw D M Davies | 8261736 | 1998-11-01 16:35:42 +0000 | [diff] [blame] | 451 | |
Huw D M Davies | 87f87bf | 1998-10-28 09:53:53 +0000 | [diff] [blame] | 452 | CALL_LARGE_STACK( XPutImage_wrapper, &descr ); |
Huw D M Davies | 8261736 | 1998-11-01 16:35:42 +0000 | [diff] [blame] | 453 | XDestroyImage( image ); /* frees image->data too */ |
Huw D M Davies | 87f87bf | 1998-10-28 09:53:53 +0000 | [diff] [blame] | 454 | LeaveCriticalSection( &X11DRV_CritSection ); |
| 455 | |
| 456 | return count; |
| 457 | } |
| 458 | |
| 459 | /*********************************************************************** |
| 460 | * X11DRV_BitmapBits |
| 461 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 462 | LONG X11DRV_BitmapBits(HBITMAP hbitmap, void *bits, LONG count, WORD flags) |
Huw D M Davies | 87f87bf | 1998-10-28 09:53:53 +0000 | [diff] [blame] | 463 | { |
| 464 | BITMAPOBJ *bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC ); |
| 465 | LONG ret; |
| 466 | if(!bmp) { |
Alexandre Julliard | 61fece0 | 1999-06-26 19:09:08 +0000 | [diff] [blame] | 467 | WARN("Bad bitmap handle %08x\n", hbitmap); |
Huw D M Davies | 87f87bf | 1998-10-28 09:53:53 +0000 | [diff] [blame] | 468 | return FALSE; |
| 469 | } |
| 470 | |
| 471 | if(flags == DDB_GET) |
| 472 | ret = X11DRV_GetBitmapBits(bmp, bits, count); |
| 473 | else if(flags == DDB_SET) |
| 474 | ret = X11DRV_SetBitmapBits(bmp, bits, count); |
| 475 | else { |
Alexandre Julliard | 61fece0 | 1999-06-26 19:09:08 +0000 | [diff] [blame] | 476 | ERR("Unknown flags value %d\n", flags); |
Huw D M Davies | 87f87bf | 1998-10-28 09:53:53 +0000 | [diff] [blame] | 477 | ret = 0; |
| 478 | } |
| 479 | |
| 480 | GDI_HEAP_UNLOCK( hbitmap ); |
| 481 | return ret; |
| 482 | } |
| 483 | |
| 484 | /*********************************************************************** |
| 485 | * X11DRV_BITMAP_DeleteObject |
| 486 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 487 | BOOL X11DRV_BITMAP_DeleteObject( HBITMAP hbitmap, BITMAPOBJ * bmp ) |
Huw D M Davies | 87f87bf | 1998-10-28 09:53:53 +0000 | [diff] [blame] | 488 | { |
Alexandre Julliard | a08e2cf | 2000-03-28 13:37:50 +0000 | [diff] [blame] | 489 | TSXFreePixmap( display, (Pixmap)bmp->physBitmap ); |
| 490 | bmp->physBitmap = NULL; |
| 491 | bmp->funcs = NULL; |
Huw D M Davies | 87f87bf | 1998-10-28 09:53:53 +0000 | [diff] [blame] | 492 | return TRUE; |
| 493 | } |
Patrik Stridvall | ab121e7 | 1999-02-04 11:11:01 +0000 | [diff] [blame] | 494 | |
Noel Borthwick | d05b7be | 1999-09-20 15:42:47 +0000 | [diff] [blame] | 495 | /************************************************************************** |
| 496 | * X11DRV_BITMAP_CreateBitmapHeaderFromPixmap |
| 497 | * |
| 498 | * Allocates an HBITMAP which references the Pixmap passed in. |
| 499 | * Note: This function makes the bitmap an owner of the Pixmap so subsequently |
| 500 | * calling DeleteObject on this will free the Pixmap as well. |
| 501 | */ |
| 502 | HBITMAP X11DRV_BITMAP_CreateBitmapHeaderFromPixmap(Pixmap pixmap) |
| 503 | { |
| 504 | HBITMAP hBmp = 0; |
| 505 | BITMAPOBJ *pBmp = NULL; |
Noel Borthwick | d05b7be | 1999-09-20 15:42:47 +0000 | [diff] [blame] | 506 | Window root; |
| 507 | int x,y; /* Unused */ |
| 508 | unsigned border_width; /* Unused */ |
| 509 | unsigned int depth, width, height; |
| 510 | |
| 511 | /* Get the Pixmap dimensions and bit depth */ |
| 512 | if ( 0 == TSXGetGeometry(display, pixmap, &root, &x, &y, &width, &height, |
| 513 | &border_width, &depth) ) |
| 514 | goto END; |
| 515 | |
| 516 | TRACE("\tPixmap properties: width=%d, height=%d, depth=%d\n", |
| 517 | width, height, depth); |
| 518 | |
| 519 | /* |
| 520 | * Create an HBITMAP with the same dimensions and BPP as the pixmap, |
| 521 | * and make it a container for the pixmap passed. |
| 522 | */ |
| 523 | hBmp = CreateBitmap( width, height, 1, depth, NULL ); |
| 524 | |
Noel Borthwick | d05b7be | 1999-09-20 15:42:47 +0000 | [diff] [blame] | 525 | pBmp = (BITMAPOBJ *)GDI_GetObjPtr( hBmp, BITMAP_MAGIC ); |
Noel Borthwick | d05b7be | 1999-09-20 15:42:47 +0000 | [diff] [blame] | 526 | |
Alexandre Julliard | a08e2cf | 2000-03-28 13:37:50 +0000 | [diff] [blame] | 527 | pBmp->funcs = &X11DRV_DC_Funcs; |
| 528 | pBmp->physBitmap = (void *)pixmap; |
Noel Borthwick | d05b7be | 1999-09-20 15:42:47 +0000 | [diff] [blame] | 529 | |
| 530 | END: |
| 531 | TRACE("\tReturning HBITMAP %x\n", hBmp); |
| 532 | return hBmp; |
| 533 | } |
| 534 | |
| 535 | |
| 536 | /************************************************************************** |
| 537 | * X11DRV_BITMAP_CreateBitmapFromPixmap |
| 538 | * |
| 539 | * Allocates an HBITMAP and copies the Pixmap data into it. |
| 540 | * If bDeletePixmap is TRUE, the Pixmap passed in is deleted after the conversion. |
| 541 | */ |
| 542 | HBITMAP X11DRV_BITMAP_CreateBitmapFromPixmap(Pixmap pixmap, BOOL bDeletePixmap) |
| 543 | { |
| 544 | HBITMAP hBmp = 0, hBmpCopy = 0; |
| 545 | BITMAPOBJ *pBmp = NULL; |
| 546 | unsigned int width, height; |
| 547 | |
| 548 | /* Allocate an HBITMAP which references the Pixmap passed to us */ |
| 549 | hBmp = X11DRV_BITMAP_CreateBitmapHeaderFromPixmap(pixmap); |
| 550 | if (!hBmp) |
| 551 | { |
| 552 | TRACE("\tCould not create bitmap header for Pixmap\n"); |
| 553 | goto END; |
| 554 | } |
| 555 | |
| 556 | /* Get the bitmap dimensions */ |
| 557 | width = pBmp->bitmap.bmWidth; |
| 558 | height = pBmp->bitmap.bmHeight; |
| 559 | |
| 560 | hBmpCopy = CopyImage(hBmp, IMAGE_BITMAP, width, height, LR_CREATEDIBSECTION); |
| 561 | |
| 562 | /* We can now get rid of the HBITMAP wrapper we created earlier. |
| 563 | * Note: Simply calling DeleteObject will free the embedded Pixmap as well. |
| 564 | */ |
| 565 | if (!bDeletePixmap) |
| 566 | { |
Alexandre Julliard | a08e2cf | 2000-03-28 13:37:50 +0000 | [diff] [blame] | 567 | /* Manually clear the bitmap internals to prevent the Pixmap |
Noel Borthwick | d05b7be | 1999-09-20 15:42:47 +0000 | [diff] [blame] | 568 | * from being deleted by DeleteObject. |
| 569 | */ |
Alexandre Julliard | a08e2cf | 2000-03-28 13:37:50 +0000 | [diff] [blame] | 570 | pBmp->physBitmap = NULL; |
| 571 | pBmp->funcs = NULL; |
Noel Borthwick | d05b7be | 1999-09-20 15:42:47 +0000 | [diff] [blame] | 572 | } |
| 573 | DeleteObject(hBmp); |
| 574 | |
| 575 | END: |
| 576 | TRACE("\tReturning HBITMAP %x\n", hBmpCopy); |
| 577 | return hBmpCopy; |
| 578 | } |
| 579 | |
| 580 | |
| 581 | /************************************************************************** |
| 582 | * X11DRV_BITMAP_CreatePixmapFromBitmap |
| 583 | * |
| 584 | * Creates a Pixmap from a bitmap |
| 585 | */ |
| 586 | Pixmap X11DRV_BITMAP_CreatePixmapFromBitmap( HBITMAP hBmp, HDC hdc ) |
| 587 | { |
Eric Pouech | 12222f0 | 2000-04-29 14:29:41 +0000 | [diff] [blame] | 588 | HGLOBAL hPackedDIB = 0; |
| 589 | Pixmap pixmap = 0; |
Noel Borthwick | d05b7be | 1999-09-20 15:42:47 +0000 | [diff] [blame] | 590 | |
| 591 | /* |
| 592 | * Create a packed DIB from the bitmap passed to us. |
| 593 | * A packed DIB contains a BITMAPINFO structure followed immediately by |
| 594 | * an optional color palette and the pixel data. |
| 595 | */ |
| 596 | hPackedDIB = DIB_CreateDIBFromBitmap(hdc, hBmp); |
| 597 | |
| 598 | /* Create a Pixmap from the packed DIB */ |
| 599 | pixmap = X11DRV_DIB_CreatePixmapFromDIB( hPackedDIB, hdc ); |
| 600 | |
| 601 | /* Free the temporary packed DIB */ |
| 602 | GlobalFree(hPackedDIB); |
| 603 | |
| 604 | return pixmap; |
| 605 | } |
| 606 | |
| 607 | |
Alex Korobka | 44a1b59 | 1999-04-01 12:03:52 +0000 | [diff] [blame] | 608 | /*********************************************************************** |
| 609 | * X11DRV_BITMAP_Pixmap |
| 610 | * |
| 611 | * This function exists solely for x11 driver of the window system. |
| 612 | */ |
Alexandre Julliard | a08e2cf | 2000-03-28 13:37:50 +0000 | [diff] [blame] | 613 | Pixmap X11DRV_BITMAP_Pixmap(HBITMAP hbitmap) |
Alex Korobka | 44a1b59 | 1999-04-01 12:03:52 +0000 | [diff] [blame] | 614 | { |
| 615 | BITMAPOBJ *bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC ); |
Alexandre Julliard | a08e2cf | 2000-03-28 13:37:50 +0000 | [diff] [blame] | 616 | return (Pixmap)bmp->physBitmap; |
Alex Korobka | 44a1b59 | 1999-04-01 12:03:52 +0000 | [diff] [blame] | 617 | } |
| 618 | |