blob: 484a7b690600ccc1b7d6ee0842e58d30e4c32159 [file] [log] [blame]
Alexandre Julliard349a9531997-02-02 19:01:52 +00001/*
Huw D M Davies87f87bf1998-10-28 09:53:53 +00002 * X11DRV bitmap objects
Alexandre Julliard349a9531997-02-02 19:01:52 +00003 *
4 * Copyright 1993 Alexandre Julliard
Noel Borthwickd05b7be1999-09-20 15:42:47 +00005 * 1999 Noel Borthwick
Alexandre Julliard349a9531997-02-02 19:01:52 +00006 */
7
Patrik Stridvallab121e71999-02-04 11:11:01 +00008#include "config.h"
9
Alexandre Julliard60ce85c1998-02-01 18:33:27 +000010#include "ts_xlib.h"
11#include "ts_xutil.h"
Patrik Stridvallab121e71999-02-04 11:11:01 +000012
13#include <stdio.h>
14#include <stdlib.h>
Alexandre Julliard349a9531997-02-02 19:01:52 +000015#include "gdi.h"
16#include "callback.h"
17#include "dc.h"
18#include "bitmap.h"
19#include "heap.h"
Alexandre Julliard61fece01999-06-26 19:09:08 +000020#include "debugtools.h"
Patrik Stridvallab121e71999-02-04 11:11:01 +000021#include "local.h"
Huw D M Davies87f87bf1998-10-28 09:53:53 +000022#include "x11drv.h"
Jeremy Whited3e22d92000-02-10 19:03:02 +000023#include "wingdi.h"
24#include "windef.h"
Patrik Stridvallab121e71999-02-04 11:11:01 +000025#include "wine/winuser16.h"
Huw D M Davies87f87bf1998-10-28 09:53:53 +000026
Alexandre Julliard9383eb92000-03-25 14:05:06 +000027DEFAULT_DEBUG_CHANNEL(x11drv);
Patrik Stridvallb4b9fae1999-04-19 14:56:29 +000028
Huw D M Davies87f87bf1998-10-28 09:53:53 +000029 /* GCs used for B&W and color bitmap operations */
30GC BITMAP_monoGC = 0, BITMAP_colorGC = 0;
31
32
Alexandre Julliard349a9531997-02-02 19:01:52 +000033/***********************************************************************
34 * X11DRV_BITMAP_Init
35 */
Alexandre Julliarda3960291999-02-26 11:11:13 +000036BOOL X11DRV_BITMAP_Init(void)
Alexandre Julliard349a9531997-02-02 19:01:52 +000037{
38 Pixmap tmpPixmap;
39
40 /* Create the necessary GCs */
41
Patrik Stridvallab121e71999-02-04 11:11:01 +000042 if ((tmpPixmap = TSXCreatePixmap(display,
43 X11DRV_GetXRootWindow(),
44 1, 1,
45 1)))
Alexandre Julliard349a9531997-02-02 19:01:52 +000046 {
Alexandre Julliard60ce85c1998-02-01 18:33:27 +000047 BITMAP_monoGC = TSXCreateGC( display, tmpPixmap, 0, NULL );
48 TSXSetGraphicsExposures( display, BITMAP_monoGC, False );
49 TSXFreePixmap( display, tmpPixmap );
Alexandre Julliard349a9531997-02-02 19:01:52 +000050 }
51
Alexandre Julliard9383eb92000-03-25 14:05:06 +000052 if (X11DRV_GetDepth() != 1)
Alexandre Julliard349a9531997-02-02 19:01:52 +000053 {
Alexandre Julliard9383eb92000-03-25 14:05:06 +000054 if ((tmpPixmap = TSXCreatePixmap(display, X11DRV_GetXRootWindow(),
55 1, 1, X11DRV_GetDepth())))
Alexandre Julliard349a9531997-02-02 19:01:52 +000056 {
Alexandre Julliard60ce85c1998-02-01 18:33:27 +000057 BITMAP_colorGC = TSXCreateGC( display, tmpPixmap, 0, NULL );
58 TSXSetGraphicsExposures( display, BITMAP_colorGC, False );
59 TSXFreePixmap( display, tmpPixmap );
Alexandre Julliard349a9531997-02-02 19:01:52 +000060 }
61 }
62 return TRUE;
63}
64
65/***********************************************************************
66 * X11DRV_BITMAP_SelectObject
67 */
Alexandre Julliarda3960291999-02-26 11:11:13 +000068HBITMAP X11DRV_BITMAP_SelectObject( DC * dc, HBITMAP hbitmap,
Alexandre Julliard349a9531997-02-02 19:01:52 +000069 BITMAPOBJ * bmp )
70{
Alexandre Julliarda3960291999-02-26 11:11:13 +000071 HRGN hrgn;
72 HBITMAP prevHandle = dc->w.hBitmap;
Huw D M Davies9c68faa1998-11-25 12:36:03 +000073 X11DRV_PDEVICE *physDev = (X11DRV_PDEVICE *)dc->physDev;
74
Huw D M Davies87f87bf1998-10-28 09:53:53 +000075
Alexandre Julliard349a9531997-02-02 19:01:52 +000076 if (!(dc->w.flags & DC_MEMORY)) return 0;
77
Alexandre Julliarda08e2cf2000-03-28 13:37:50 +000078 if(!bmp->physBitmap)
Huw D M Davies87f87bf1998-10-28 09:53:53 +000079 if(!X11DRV_CreateBitmap(hbitmap))
80 return 0;
81
Alexandre Julliarda08e2cf2000-03-28 13:37:50 +000082 if(bmp->funcs != dc->funcs) {
Alexandre Julliard61fece01999-06-26 19:09:08 +000083 WARN("Trying to select non-X11 DDB into an X11 dc\n");
Huw D M Davies87f87bf1998-10-28 09:53:53 +000084 return 0;
85 }
86
Ulrich Weigand27bb3621998-10-14 18:06:44 +000087 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 Julliard349a9531997-02-02 19:01:52 +000092 if (dc->w.hVisRgn)
Alexandre Julliarda3960291999-02-26 11:11:13 +000093 SetRectRgn( dc->w.hVisRgn, 0, 0,
Alexandre Julliard21979011997-03-05 08:22:35 +000094 bmp->bitmap.bmWidth, bmp->bitmap.bmHeight );
Alexandre Julliard349a9531997-02-02 19:01:52 +000095 else
96 {
Alexandre Julliarda3960291999-02-26 11:11:13 +000097 hrgn = CreateRectRgn(0, 0, bmp->bitmap.bmWidth, bmp->bitmap.bmHeight);
Alexandre Julliard349a9531997-02-02 19:01:52 +000098 if (!hrgn) return 0;
99 dc->w.hVisRgn = hrgn;
100 }
101
Alexandre Julliarda08e2cf2000-03-28 13:37:50 +0000102 physDev->drawable = (Pixmap)bmp->physBitmap;
Huw D M Davies9c68faa1998-11-25 12:36:03 +0000103 dc->w.hBitmap = hbitmap;
Alexandre Julliard349a9531997-02-02 19:01:52 +0000104
105 /* Change GC depth if needed */
106
107 if (dc->w.bitsPerPixel != bmp->bitmap.bmBitsPixel)
108 {
Huw D M Davies9c68faa1998-11-25 12:36:03 +0000109 TSXFreeGC( display, physDev->gc );
110 physDev->gc = TSXCreateGC( display, physDev->drawable, 0, NULL );
Ulrich Weigand9cfeb5b1999-03-10 13:26:09 +0000111 TSXSetGraphicsExposures( display, physDev->gc, False );
Alexandre Julliard349a9531997-02-02 19:01:52 +0000112 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 Davies87f87bf1998-10-28 09:53:53 +0000118
119
120/***********************************************************************
121 * XPutImage_wrapper
122 *
123 * Wrapper to call XPutImage with CALL_LARGE_STACK.
124 */
125
126struct XPutImage_descr
127{
128 BITMAPOBJ *bmp;
129 XImage *image;
Alexandre Julliarda3960291999-02-26 11:11:13 +0000130 INT width;
131 INT height;
Huw D M Davies87f87bf1998-10-28 09:53:53 +0000132};
133
134static int XPutImage_wrapper( const struct XPutImage_descr *descr )
135{
Alexandre Julliarda08e2cf2000-03-28 13:37:50 +0000136 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 Davies87f87bf1998-10-28 09:53:53 +0000138}
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 Julliarda3960291999-02-26 11:11:13 +0000151BOOL X11DRV_CreateBitmap( HBITMAP hbitmap )
Huw D M Davies87f87bf1998-10-28 09:53:53 +0000152{
Huw D M Davies87f87bf1998-10-28 09:53:53 +0000153 BITMAPOBJ *bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC );
154
155 if(!bmp) {
Alexandre Julliard61fece01999-06-26 19:09:08 +0000156 WARN("Bad bitmap handle %08x\n", hbitmap);
Huw D M Davies87f87bf1998-10-28 09:53:53 +0000157 return FALSE;
158 }
159
160 /* Check parameters */
161 if (bmp->bitmap.bmPlanes != 1) return 0;
162 if ((bmp->bitmap.bmBitsPixel != 1) &&
Alexandre Julliard9383eb92000-03-25 14:05:06 +0000163 (bmp->bitmap.bmBitsPixel != X11DRV_GetDepth()))
164 {
Alexandre Julliard61fece01999-06-26 19:09:08 +0000165 ERR("Trying to make bitmap with planes=%d, bpp=%d\n",
Huw D M Davies9c68faa1998-11-25 12:36:03 +0000166 bmp->bitmap.bmPlanes, bmp->bitmap.bmBitsPixel);
Huw D M Davies87f87bf1998-10-28 09:53:53 +0000167 GDI_HEAP_UNLOCK( hbitmap );
168 return FALSE;
169 }
170
Alexandre Julliard61fece01999-06-26 19:09:08 +0000171 TRACE("(%08x) %dx%d %d bpp\n", hbitmap, bmp->bitmap.bmWidth,
Huw D M Davies82617361998-11-01 16:35:42 +0000172 bmp->bitmap.bmHeight, bmp->bitmap.bmBitsPixel);
173
Huw D M Davies87f87bf1998-10-28 09:53:53 +0000174 /* Create the pixmap */
Alexandre Julliarda08e2cf2000-03-28 13:37:50 +0000175 if (!(bmp->physBitmap = (void *)TSXCreatePixmap(display, X11DRV_GetXRootWindow(),
176 bmp->bitmap.bmWidth, bmp->bitmap.bmHeight,
177 bmp->bitmap.bmBitsPixel)))
178 {
Alexandre Julliard61fece01999-06-26 19:09:08 +0000179 WARN("Can't create Pixmap\n");
Huw D M Davies87f87bf1998-10-28 09:53:53 +0000180 GDI_HEAP_UNLOCK( hbitmap );
181 return FALSE;
182 }
Alexandre Julliarda08e2cf2000-03-28 13:37:50 +0000183 bmp->funcs = &X11DRV_DC_Funcs;
Huw D M Davies87f87bf1998-10-28 09:53:53 +0000184
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 */
200XImage *X11DRV_BITMAP_GetXImage( const BITMAPOBJ *bmp )
201{
Alexandre Julliarda08e2cf2000-03-28 13:37:50 +0000202 return XGetImage( display, (Pixmap)bmp->physBitmap,
Huw D M Davies87f87bf1998-10-28 09:53:53 +0000203 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 */
215static LONG X11DRV_GetBitmapBits(BITMAPOBJ *bmp, void *buffer, LONG count)
216{
217 LONG old_height, height;
218 XImage *image;
Huw D M Daviese42ee261999-03-27 15:59:12 +0000219 LPBYTE tbuf, startline;
220 int h, w;
Huw D M Davies87f87bf1998-10-28 09:53:53 +0000221
Alexandre Julliard61fece01999-06-26 19:09:08 +0000222 TRACE("(bmp=%p, buffer=%p, count=0x%lx)\n", bmp, buffer, count);
Huw D M Davies82617361998-11-01 16:35:42 +0000223
Huw D M Davies87f87bf1998-10-28 09:53:53 +0000224 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 Daviese42ee261999-03-27 15:59:12 +0000238 startline = buffer;
Huw D M Davies87f87bf1998-10-28 09:53:53 +0000239 switch (bmp->bitmap.bmBitsPixel)
240 {
241 case 1:
242 for (h=0;h<height;h++)
243 {
Huw D M Daviese42ee261999-03-27 15:59:12 +0000244 tbuf = startline;
Huw D M Davies87f87bf1998-10-28 09:53:53 +0000245 *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 Daviese42ee261999-03-27 15:59:12 +0000253 startline += bmp->bitmap.bmWidthBytes;
Huw D M Davies87f87bf1998-10-28 09:53:53 +0000254 }
255 break;
256 case 4:
257 for (h=0;h<height;h++)
258 {
Huw D M Daviese42ee261999-03-27 15:59:12 +0000259 tbuf = startline;
Huw D M Davies87f87bf1998-10-28 09:53:53 +0000260 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 Daviese42ee261999-03-27 15:59:12 +0000265 startline += bmp->bitmap.bmWidthBytes;
Huw D M Davies87f87bf1998-10-28 09:53:53 +0000266 }
267 break;
268 case 8:
269 for (h=0;h<height;h++)
270 {
Huw D M Daviese42ee261999-03-27 15:59:12 +0000271 tbuf = startline;
Huw D M Davies87f87bf1998-10-28 09:53:53 +0000272 for (w=0;w<bmp->bitmap.bmWidth;w++)
273 *tbuf++ = XGetPixel(image,w,h);
Huw D M Daviese42ee261999-03-27 15:59:12 +0000274 startline += bmp->bitmap.bmWidthBytes;
Huw D M Davies87f87bf1998-10-28 09:53:53 +0000275 }
276 break;
277 case 15:
278 case 16:
279 for (h=0;h<height;h++)
280 {
Huw D M Daviese42ee261999-03-27 15:59:12 +0000281 tbuf = startline;
Huw D M Davies87f87bf1998-10-28 09:53:53 +0000282 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 Daviese42ee261999-03-27 15:59:12 +0000289 startline += bmp->bitmap.bmWidthBytes;
Huw D M Davies87f87bf1998-10-28 09:53:53 +0000290 }
291 break;
292 case 24:
293 for (h=0;h<height;h++)
294 {
Huw D M Daviese42ee261999-03-27 15:59:12 +0000295 tbuf = startline;
Huw D M Davies87f87bf1998-10-28 09:53:53 +0000296 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 Daviese42ee261999-03-27 15:59:12 +0000304 startline += bmp->bitmap.bmWidthBytes;
Huw D M Davies87f87bf1998-10-28 09:53:53 +0000305 }
306 break;
307
308 case 32:
309 for (h=0;h<height;h++)
310 {
Huw D M Daviese42ee261999-03-27 15:59:12 +0000311 tbuf = startline;
Huw D M Davies87f87bf1998-10-28 09:53:53 +0000312 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 Daviese42ee261999-03-27 15:59:12 +0000321 startline += bmp->bitmap.bmWidthBytes;
Huw D M Davies87f87bf1998-10-28 09:53:53 +0000322 }
323 break;
324 default:
Alexandre Julliard61fece01999-06-26 19:09:08 +0000325 FIXME("Unhandled bits:%d\n", bmp->bitmap.bmBitsPixel);
Huw D M Davies87f87bf1998-10-28 09:53:53 +0000326 }
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 */
342static LONG X11DRV_SetBitmapBits(BITMAPOBJ *bmp, void *bits, LONG count)
343{
344 struct XPutImage_descr descr;
345 LONG height;
346 XImage *image;
Huw D M Daviese42ee261999-03-27 15:59:12 +0000347 LPBYTE sbuf, startline;
348 int w, h;
Huw D M Davies84dd9fe1998-11-01 15:13:53 +0000349
Alexandre Julliard61fece01999-06-26 19:09:08 +0000350 TRACE("(bmp=%p, bits=%p, count=0x%lx)\n", bmp, bits, count);
Huw D M Davies87f87bf1998-10-28 09:53:53 +0000351
Huw D M Davies82617361998-11-01 16:35:42 +0000352 height = count / bmp->bitmap.bmWidthBytes;
Huw D M Davies84dd9fe1998-11-01 15:13:53 +0000353
Huw D M Davies87f87bf1998-10-28 09:53:53 +0000354 EnterCriticalSection( &X11DRV_CritSection );
Alexandre Julliard9383eb92000-03-25 14:05:06 +0000355 image = XCreateImage( display, X11DRV_GetVisual(), bmp->bitmap.bmBitsPixel, ZPixmap, 0, NULL,
Huw D M Davies82617361998-11-01 16:35:42 +0000356 bmp->bitmap.bmWidth, height, 32, 0 );
Dimitrie O. Pauna20b7922000-04-09 18:41:15 +0000357 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 Davies87f87bf1998-10-28 09:53:53 +0000364
365 /* copy 16 bit padded image buffer with real bitsperpixel to XImage */
Huw D M Daviese42ee261999-03-27 15:59:12 +0000366
367 startline = bits;
368
Huw D M Davies87f87bf1998-10-28 09:53:53 +0000369 switch (bmp->bitmap.bmBitsPixel)
370 {
371 case 1:
372 for (h=0;h<height;h++)
373 {
Huw D M Daviese42ee261999-03-27 15:59:12 +0000374 sbuf = startline;
Huw D M Davies87f87bf1998-10-28 09:53:53 +0000375 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 Daviese42ee261999-03-27 15:59:12 +0000381 startline += bmp->bitmap.bmWidthBytes;
Huw D M Davies87f87bf1998-10-28 09:53:53 +0000382 }
383 break;
384 case 4:
385 for (h=0;h<height;h++)
386 {
Huw D M Daviese42ee261999-03-27 15:59:12 +0000387 sbuf = startline;
Huw D M Davies87f87bf1998-10-28 09:53:53 +0000388 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 Daviese42ee261999-03-27 15:59:12 +0000393 startline += bmp->bitmap.bmWidthBytes;
Huw D M Davies87f87bf1998-10-28 09:53:53 +0000394 }
395 break;
396 case 8:
397 for (h=0;h<height;h++)
398 {
Huw D M Daviese42ee261999-03-27 15:59:12 +0000399 sbuf = startline;
Huw D M Davies87f87bf1998-10-28 09:53:53 +0000400 for (w=0;w<bmp->bitmap.bmWidth;w++)
401 XPutPixel(image,w,h,*sbuf++);
Huw D M Daviese42ee261999-03-27 15:59:12 +0000402 startline += bmp->bitmap.bmWidthBytes;
Huw D M Davies87f87bf1998-10-28 09:53:53 +0000403 }
404 break;
405 case 15:
406 case 16:
407 for (h=0;h<height;h++)
408 {
Huw D M Daviese42ee261999-03-27 15:59:12 +0000409 sbuf = startline;
Huw D M Davies87f87bf1998-10-28 09:53:53 +0000410 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 Daviese42ee261999-03-27 15:59:12 +0000415 startline += bmp->bitmap.bmWidthBytes;
Huw D M Davies87f87bf1998-10-28 09:53:53 +0000416 }
417 break;
Huw D M Daviese42ee261999-03-27 15:59:12 +0000418 case 24:
Huw D M Davies87f87bf1998-10-28 09:53:53 +0000419 for (h=0;h<height;h++)
420 {
Huw D M Daviese42ee261999-03-27 15:59:12 +0000421 sbuf = startline;
Huw D M Davies87f87bf1998-10-28 09:53:53 +0000422 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 Daviese42ee261999-03-27 15:59:12 +0000427 startline += bmp->bitmap.bmWidthBytes;
Huw D M Davies87f87bf1998-10-28 09:53:53 +0000428 }
429 break;
430 case 32:
431 for (h=0;h<height;h++)
432 {
Huw D M Daviese42ee261999-03-27 15:59:12 +0000433 sbuf = startline;
Huw D M Davies87f87bf1998-10-28 09:53:53 +0000434 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 Daviese42ee261999-03-27 15:59:12 +0000439 startline += bmp->bitmap.bmWidthBytes;
Huw D M Davies87f87bf1998-10-28 09:53:53 +0000440 }
441 break;
442 default:
Alexandre Julliard61fece01999-06-26 19:09:08 +0000443 FIXME("Unhandled bits:%d\n", bmp->bitmap.bmBitsPixel);
Huw D M Davies87f87bf1998-10-28 09:53:53 +0000444
445 }
446
447 descr.bmp = bmp;
448 descr.image = image;
449 descr.width = bmp->bitmap.bmWidth;
450 descr.height = height;
Huw D M Davies82617361998-11-01 16:35:42 +0000451
Huw D M Davies87f87bf1998-10-28 09:53:53 +0000452 CALL_LARGE_STACK( XPutImage_wrapper, &descr );
Huw D M Davies82617361998-11-01 16:35:42 +0000453 XDestroyImage( image ); /* frees image->data too */
Huw D M Davies87f87bf1998-10-28 09:53:53 +0000454 LeaveCriticalSection( &X11DRV_CritSection );
455
456 return count;
457}
458
459/***********************************************************************
460 * X11DRV_BitmapBits
461 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000462LONG X11DRV_BitmapBits(HBITMAP hbitmap, void *bits, LONG count, WORD flags)
Huw D M Davies87f87bf1998-10-28 09:53:53 +0000463{
464 BITMAPOBJ *bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC );
465 LONG ret;
466 if(!bmp) {
Alexandre Julliard61fece01999-06-26 19:09:08 +0000467 WARN("Bad bitmap handle %08x\n", hbitmap);
Huw D M Davies87f87bf1998-10-28 09:53:53 +0000468 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 Julliard61fece01999-06-26 19:09:08 +0000476 ERR("Unknown flags value %d\n", flags);
Huw D M Davies87f87bf1998-10-28 09:53:53 +0000477 ret = 0;
478 }
479
480 GDI_HEAP_UNLOCK( hbitmap );
481 return ret;
482}
483
484/***********************************************************************
485 * X11DRV_BITMAP_DeleteObject
486 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000487BOOL X11DRV_BITMAP_DeleteObject( HBITMAP hbitmap, BITMAPOBJ * bmp )
Huw D M Davies87f87bf1998-10-28 09:53:53 +0000488{
Alexandre Julliarda08e2cf2000-03-28 13:37:50 +0000489 TSXFreePixmap( display, (Pixmap)bmp->physBitmap );
490 bmp->physBitmap = NULL;
491 bmp->funcs = NULL;
Huw D M Davies87f87bf1998-10-28 09:53:53 +0000492 return TRUE;
493}
Patrik Stridvallab121e71999-02-04 11:11:01 +0000494
Noel Borthwickd05b7be1999-09-20 15:42:47 +0000495/**************************************************************************
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 */
502HBITMAP X11DRV_BITMAP_CreateBitmapHeaderFromPixmap(Pixmap pixmap)
503{
504 HBITMAP hBmp = 0;
505 BITMAPOBJ *pBmp = NULL;
Noel Borthwickd05b7be1999-09-20 15:42:47 +0000506 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 Borthwickd05b7be1999-09-20 15:42:47 +0000525 pBmp = (BITMAPOBJ *)GDI_GetObjPtr( hBmp, BITMAP_MAGIC );
Noel Borthwickd05b7be1999-09-20 15:42:47 +0000526
Alexandre Julliarda08e2cf2000-03-28 13:37:50 +0000527 pBmp->funcs = &X11DRV_DC_Funcs;
528 pBmp->physBitmap = (void *)pixmap;
Noel Borthwickd05b7be1999-09-20 15:42:47 +0000529
530END:
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 */
542HBITMAP 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 Julliarda08e2cf2000-03-28 13:37:50 +0000567 /* Manually clear the bitmap internals to prevent the Pixmap
Noel Borthwickd05b7be1999-09-20 15:42:47 +0000568 * from being deleted by DeleteObject.
569 */
Alexandre Julliarda08e2cf2000-03-28 13:37:50 +0000570 pBmp->physBitmap = NULL;
571 pBmp->funcs = NULL;
Noel Borthwickd05b7be1999-09-20 15:42:47 +0000572 }
573 DeleteObject(hBmp);
574
575END:
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 */
586Pixmap X11DRV_BITMAP_CreatePixmapFromBitmap( HBITMAP hBmp, HDC hdc )
587{
Eric Pouech12222f02000-04-29 14:29:41 +0000588 HGLOBAL hPackedDIB = 0;
589 Pixmap pixmap = 0;
Noel Borthwickd05b7be1999-09-20 15:42:47 +0000590
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 Korobka44a1b591999-04-01 12:03:52 +0000608/***********************************************************************
609 * X11DRV_BITMAP_Pixmap
610 *
611 * This function exists solely for x11 driver of the window system.
612 */
Alexandre Julliarda08e2cf2000-03-28 13:37:50 +0000613Pixmap X11DRV_BITMAP_Pixmap(HBITMAP hbitmap)
Alex Korobka44a1b591999-04-01 12:03:52 +0000614{
615 BITMAPOBJ *bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC );
Alexandre Julliarda08e2cf2000-03-28 13:37:50 +0000616 return (Pixmap)bmp->physBitmap;
Alex Korobka44a1b591999-04-01 12:03:52 +0000617}
618