4 * Copyright 1993 Alexandre Julliard
18 #ifdef PRELIMINARY_WING16_SUPPORT
19 #include <sys/types.h>
24 /* GCs used for B&W and color bitmap operations */
25 GC BITMAP_monoGC
= 0, BITMAP_colorGC
= 0;
27 /***********************************************************************
30 * Wrapper to call XPutImage with CALL_LARGE_STACK.
33 struct XPutImage_descr
41 static int XPutImage_wrapper( const struct XPutImage_descr
*descr
)
43 return XPutImage( display
, descr
->bmp
->pixmap
, BITMAP_GC(descr
->bmp
),
44 descr
->image
, 0, 0, 0, 0, descr
->width
, descr
->height
);
47 /***********************************************************************
48 * BITMAP_GetBitsPadding
50 * Return number of bytes to pad a scanline of 16-bit aligned Windows DDB data.
52 INT32
BITMAP_GetBitsPadding( int bmWidth
, int bpp
)
59 if (!(bmWidth
& 15)) pad
= 0;
60 else pad
= ((16 - (bmWidth
& 15)) + 7) / 8;
64 pad
= (2 - (bmWidth
& 1)) & 1;
68 pad
= (bmWidth
*3) & 1;
74 pad
= 0; /* we have 16bit alignment already */
78 if (!(bmWidth
& 3)) pad
= 0;
79 else pad
= ((4 - (bmWidth
& 3)) + 1) / 2;
83 WARN(bitmap
,"Unknown depth %d, please report.\n", bpp
);
89 /***********************************************************************
92 * Return number of bytes taken by a scanline of 16-bit aligned Windows DDB data.
94 INT32
BITMAP_GetBitsWidth( int bmWidth
, int bpp
)
99 return 2 * ((bmWidth
+15) >> 4);
102 bmWidth
*= 3; /* fall through */
104 return bmWidth
+ (bmWidth
& 1);
114 return 2 * ((bmWidth
+3) >> 2);
117 WARN(bitmap
,"Unknown depth %d, please report.\n", bpp
);
122 /***********************************************************************
123 * CreateBitmap16 (GDI.48)
125 HBITMAP16 WINAPI
CreateBitmap16( INT16 width
, INT16 height
, UINT16 planes
,
126 UINT16 bpp
, LPCVOID bits
)
128 return CreateBitmap32( width
, height
, planes
, bpp
, bits
);
132 /******************************************************************************
133 * CreateBitmap32 [GDI32.25] Creates a bitmap with the specified info
136 * width [I] bitmap width
137 * height [I] bitmap height
138 * planes [I] Number of color planes
139 * bpp [I] Number of bits to identify a color
140 * bits [I] Pointer to array containing color data
143 * Success: Handle to bitmap
146 HBITMAP32 WINAPI
CreateBitmap32( INT32 width
, INT32 height
, UINT32 planes
,
147 UINT32 bpp
, LPCVOID bits
)
149 BITMAPOBJ
* bmpObjPtr
;
152 planes
= (BYTE
)planes
;
155 TRACE(gdi
, "%dx%d, %d colors\n", width
, height
, 1 << (planes
*bpp
) );
157 /* Check parameters */
158 if (!height
|| !width
|| planes
!= 1) return 0;
159 if ((bpp
!= 1) && (bpp
!= screenDepth
)) return 0;
160 if (height
< 0) height
= -height
;
161 if (width
< 0) width
= -width
;
163 /* Create the BITMAPOBJ */
164 hbitmap
= GDI_AllocObject( sizeof(BITMAPOBJ
), BITMAP_MAGIC
);
165 if (!hbitmap
) return 0;
166 bmpObjPtr
= (BITMAPOBJ
*) GDI_HEAP_LOCK( hbitmap
);
168 bmpObjPtr
->size
.cx
= 0;
169 bmpObjPtr
->size
.cy
= 0;
170 bmpObjPtr
->bitmap
.bmType
= 0;
171 bmpObjPtr
->bitmap
.bmWidth
= (INT16
)width
;
172 bmpObjPtr
->bitmap
.bmHeight
= (INT16
)height
;
173 bmpObjPtr
->bitmap
.bmPlanes
= (BYTE
)planes
;
174 bmpObjPtr
->bitmap
.bmBitsPixel
= (BYTE
)bpp
;
175 bmpObjPtr
->bitmap
.bmWidthBytes
= (INT16
)BITMAP_WIDTH_BYTES( width
, bpp
);
176 bmpObjPtr
->bitmap
.bmBits
= NULL
;
178 bmpObjPtr
->dib
= NULL
;
180 /* Create the pixmap */
181 bmpObjPtr
->pixmap
= TSXCreatePixmap(display
, rootWindow
, width
, height
, bpp
);
182 if (!bmpObjPtr
->pixmap
)
184 GDI_HEAP_FREE( hbitmap
);
187 else if (bits
) /* Set bitmap bits */
188 SetBitmapBits32( hbitmap
, height
* bmpObjPtr
->bitmap
.bmWidthBytes
,
190 GDI_HEAP_UNLOCK( hbitmap
);
195 /***********************************************************************
196 * CreateCompatibleBitmap16 (GDI.51)
198 HBITMAP16 WINAPI
CreateCompatibleBitmap16(HDC16 hdc
, INT16 width
, INT16 height
)
200 return CreateCompatibleBitmap32( hdc
, width
, height
);
204 /******************************************************************************
205 * CreateCompatibleBitmap32 [GDI32.30] Creates a bitmap compatible with the DC
208 * hdc [I] Handle to device context
209 * width [I] Width of bitmap
210 * height [I] Height of bitmap
213 * Success: Handle to bitmap
216 HBITMAP32 WINAPI
CreateCompatibleBitmap32( HDC32 hdc
, INT32 width
, INT32 height
)
218 HBITMAP32 hbmpRet
= 0;
221 TRACE(gdi
, "(%04x,%d,%d) = \n", hdc
, width
, height
);
222 if (!(dc
= DC_GetDCPtr( hdc
))) return 0;
223 if ((width
>0x1000) || (height
> 0x1000))
225 FIXME(gdi
,"got bad width %d or height %d, please look for reason\n",
229 hbmpRet
= CreateBitmap32( width
, height
, 1, dc
->w
.bitsPerPixel
, NULL
);
230 TRACE(gdi
,"\t\t%04x\n", hbmpRet
);
235 /***********************************************************************
236 * CreateBitmapIndirect16 (GDI.49)
238 HBITMAP16 WINAPI
CreateBitmapIndirect16( const BITMAP16
* bmp
)
240 return CreateBitmap16( bmp
->bmWidth
, bmp
->bmHeight
, bmp
->bmPlanes
,
241 bmp
->bmBitsPixel
, PTR_SEG_TO_LIN( bmp
->bmBits
) );
245 /******************************************************************************
246 * CreateBitmapIndirect32 [GDI32.26] Creates a bitmap with the specifies info
249 * Success: Handle to bitmap
252 HBITMAP32 WINAPI
CreateBitmapIndirect32(
253 const BITMAP32
* bmp
) /* [in] Pointer to the bitmap data */
255 return CreateBitmap32( bmp
->bmWidth
, bmp
->bmHeight
, bmp
->bmPlanes
,
256 bmp
->bmBitsPixel
, bmp
->bmBits
);
260 /***********************************************************************
263 * Get an X image for a bitmap. For use with CALL_LARGE_STACK.
265 XImage
*BITMAP_GetXImage( const BITMAPOBJ
*bmp
)
267 return XGetImage( display
, bmp
->pixmap
, 0, 0, bmp
->bitmap
.bmWidth
,
268 bmp
->bitmap
.bmHeight
, AllPlanes
, ZPixmap
);
272 /***********************************************************************
273 * GetBitmapBits16 (GDI.74)
275 LONG WINAPI
GetBitmapBits16( HBITMAP16 hbitmap
, LONG count
, LPVOID buffer
)
277 return GetBitmapBits32( hbitmap
, count
, buffer
);
281 /***********************************************************************
282 * GetBitmapBits32 [GDI32.143] Copies bitmap bits of bitmap to buffer
285 * Success: Number of bytes copied
288 LONG WINAPI
GetBitmapBits32(
289 HBITMAP32 hbitmap
, /* [in] Handle to bitmap */
290 LONG count
, /* [in] Number of bytes to copy */
291 LPVOID buffer
) /* [out] Pointer to buffer to receive bits */
294 LONG height
, old_height
;
301 WARN(bitmap
, "(%ld): Negative number of bytes passed???\n", count
);
304 bmp
= (BITMAPOBJ
*) GDI_GetObjPtr( hbitmap
, BITMAP_MAGIC
);
307 /* Only get entire lines */
308 height
= count
/ bmp
->bitmap
.bmWidthBytes
;
309 if (height
> bmp
->bitmap
.bmHeight
) height
= bmp
->bitmap
.bmHeight
;
311 TRACE(bitmap
, "%dx%d %d colors %p fetched height: %ld\n",
312 bmp
->bitmap
.bmWidth
, bmp
->bitmap
.bmHeight
,
313 1 << bmp
->bitmap
.bmBitsPixel
, buffer
, height
);
315 pad
= BITMAP_GetBitsPadding( bmp
->bitmap
.bmWidth
, bmp
->bitmap
.bmBitsPixel
);
317 if (!height
|| (pad
== -1))
319 GDI_HEAP_UNLOCK( hbitmap
);
323 EnterCriticalSection( &X11DRV_CritSection
);
325 /* Hack: change the bitmap height temporarily to avoid */
326 /* getting unnecessary bitmap rows. */
327 old_height
= bmp
->bitmap
.bmHeight
;
328 bmp
->bitmap
.bmHeight
= height
;
329 image
= (XImage
*)CALL_LARGE_STACK( BITMAP_GetXImage
, bmp
);
330 bmp
->bitmap
.bmHeight
= old_height
;
332 /* copy XImage to 16 bit padded image buffer with real bitsperpixel */
335 switch (bmp
->bitmap
.bmBitsPixel
)
338 for (h
=0;h
<height
;h
++)
341 for (w
=0;w
<bmp
->bitmap
.bmWidth
;w
++)
345 *tbuf
|= XGetPixel(image
,w
,h
)<<(7-(w
&7));
346 if ((w
&7) == 7) ++tbuf
;
352 for (h
=0;h
<height
;h
++)
354 for (w
=0;w
<bmp
->bitmap
.bmWidth
;w
++)
356 if (!(w
& 1)) *tbuf
= XGetPixel( image
, w
, h
) << 4;
357 else *tbuf
++ |= XGetPixel( image
, w
, h
) & 0x0f;
363 for (h
=0;h
<height
;h
++)
365 for (w
=0;w
<bmp
->bitmap
.bmWidth
;w
++)
366 *tbuf
++ = XGetPixel(image
,w
,h
);
372 for (h
=0;h
<height
;h
++)
374 for (w
=0;w
<bmp
->bitmap
.bmWidth
;w
++)
376 long pixel
= XGetPixel(image
,w
,h
);
378 *tbuf
++ = pixel
& 0xff;
379 *tbuf
++ = (pixel
>>8) & 0xff;
384 for (h
=0;h
<height
;h
++)
386 for (w
=0;w
<bmp
->bitmap
.bmWidth
;w
++)
388 long pixel
= XGetPixel(image
,w
,h
);
390 *tbuf
++ = pixel
& 0xff;
391 *tbuf
++ = (pixel
>> 8) & 0xff;
392 *tbuf
++ = (pixel
>>16) & 0xff;
399 for (h
=0;h
<height
;h
++)
401 for (w
=0;w
<bmp
->bitmap
.bmWidth
;w
++)
403 long pixel
= XGetPixel(image
,w
,h
);
405 *tbuf
++ = pixel
& 0xff;
406 *tbuf
++ = (pixel
>> 8) & 0xff;
407 *tbuf
++ = (pixel
>>16) & 0xff;
408 *tbuf
++ = (pixel
>>24) & 0xff;
414 FIXME(bitmap
, "Unhandled bits:%d\n", bmp
->bitmap
.bmBitsPixel
);
416 XDestroyImage( image
);
417 LeaveCriticalSection( &X11DRV_CritSection
);
419 GDI_HEAP_UNLOCK( hbitmap
);
420 return height
* bmp
->bitmap
.bmWidthBytes
;
424 /***********************************************************************
425 * SetBitmapBits16 (GDI.106)
427 LONG WINAPI
SetBitmapBits16( HBITMAP16 hbitmap
, LONG count
, LPCVOID buffer
)
429 return SetBitmapBits32( hbitmap
, count
, buffer
);
433 /******************************************************************************
434 * SetBitmapBits32 [GDI32.303] Sets bits of color data for a bitmap
437 * Success: Number of bytes used in setting the bitmap bits
440 LONG WINAPI
SetBitmapBits32(
441 HBITMAP32 hbitmap
, /* [in] Handle to bitmap */
442 LONG count
, /* [in] Number of bytes in bitmap array */
443 LPCVOID buffer
) /* [in] Address of array with bitmap bits */
445 struct XPutImage_descr descr
;
449 LPBYTE sbuf
,tmpbuffer
;
450 int w
,h
,pad
,widthbytes
;
454 WARN(bitmap
, "(%ld): Negative number of bytes passed???\n", count
);
457 bmp
= (BITMAPOBJ
*) GDI_GetObjPtr( hbitmap
, BITMAP_MAGIC
);
460 TRACE(bitmap
, "%dx%d %d colors %p\n",
461 bmp
->bitmap
.bmWidth
, bmp
->bitmap
.bmHeight
,
462 1 << bmp
->bitmap
.bmBitsPixel
, buffer
);
464 /* Only set entire lines */
465 height
= count
/ bmp
->bitmap
.bmWidthBytes
;
466 if (height
> bmp
->bitmap
.bmHeight
) height
= bmp
->bitmap
.bmHeight
;
468 pad
= BITMAP_GetBitsPadding( bmp
->bitmap
.bmWidth
, bmp
->bitmap
.bmBitsPixel
);
470 if (!height
|| (pad
== -1))
472 GDI_HEAP_UNLOCK( hbitmap
);
476 sbuf
= (LPBYTE
)buffer
;
478 widthbytes
= DIB_GetXImageWidthBytes(bmp
->bitmap
.bmWidth
,bmp
->bitmap
.bmBitsPixel
);
479 tmpbuffer
= (LPBYTE
)xmalloc(widthbytes
*height
);
481 EnterCriticalSection( &X11DRV_CritSection
);
482 image
= XCreateImage( display
, DefaultVisualOfScreen(screen
),
483 bmp
->bitmap
.bmBitsPixel
, ZPixmap
, 0, tmpbuffer
,
484 bmp
->bitmap
.bmWidth
,height
,32,widthbytes
);
486 /* copy 16 bit padded image buffer with real bitsperpixel to XImage */
487 sbuf
= (LPBYTE
)buffer
;
488 switch (bmp
->bitmap
.bmBitsPixel
)
491 for (h
=0;h
<height
;h
++)
493 for (w
=0;w
<bmp
->bitmap
.bmWidth
;w
++)
495 XPutPixel(image
,w
,h
,(sbuf
[0]>>(7-(w
&7))) & 1);
503 for (h
=0;h
<height
;h
++)
505 for (w
=0;w
<bmp
->bitmap
.bmWidth
;w
++)
507 if (!(w
& 1)) XPutPixel( image
, w
, h
, *sbuf
>> 4 );
508 else XPutPixel( image
, w
, h
, *sbuf
++ & 0xf );
514 for (h
=0;h
<height
;h
++)
516 for (w
=0;w
<bmp
->bitmap
.bmWidth
;w
++)
517 XPutPixel(image
,w
,h
,*sbuf
++);
523 for (h
=0;h
<height
;h
++)
525 for (w
=0;w
<bmp
->bitmap
.bmWidth
;w
++)
527 XPutPixel(image
,w
,h
,sbuf
[1]*256+sbuf
[0]);
533 for (h
=0;h
<height
;h
++)
535 for (w
=0;w
<bmp
->bitmap
.bmWidth
;w
++)
537 XPutPixel(image
,w
,h
,(sbuf
[2]<<16)+(sbuf
[1]<<8)+sbuf
[0]);
544 for (h
=0;h
<height
;h
++)
546 for (w
=0;w
<bmp
->bitmap
.bmWidth
;w
++)
548 XPutPixel(image
,w
,h
,(sbuf
[3]<<24)+(sbuf
[2]<<16)+(sbuf
[1]<<8)+sbuf
[0]);
555 FIXME(bitmap
, "Unhandled bits:%d\n", bmp
->bitmap
.bmBitsPixel
);
561 descr
.width
= bmp
->bitmap
.bmWidth
;
562 descr
.height
= height
;
563 CALL_LARGE_STACK( XPutImage_wrapper
, &descr
);
564 XDestroyImage( image
); /* frees tmpbuffer too */
565 LeaveCriticalSection( &X11DRV_CritSection
);
567 GDI_HEAP_UNLOCK( hbitmap
);
568 return height
* bmp
->bitmap
.bmWidthBytes
;
571 /***********************************************************************
572 * LoadImage16 [USER.389]
575 HANDLE16 WINAPI
LoadImage16( HINSTANCE16 hinst
, LPCSTR name
, UINT16 type
,
576 INT16 desiredx
, INT16 desiredy
, UINT16 loadflags
)
579 TRACE(resource
,"(0x%04x,%s,%d,%d,%d,0x%08x)\n",
580 hinst
,(char *)PTR_SEG_TO_LIN(name
),type
,desiredx
,desiredy
,loadflags
);
582 TRACE(resource
,"LoadImage16(0x%04x,%p,%d,%d,%d,0x%08x)\n",
583 hinst
,name
,type
,desiredx
,desiredy
,loadflags
);
587 return LoadBitmap16(hinst
,(SEGPTR
)name
);
589 return LoadIcon16(hinst
,(SEGPTR
)name
);
591 return LoadCursor16(hinst
,(SEGPTR
)name
);
597 /**********************************************************************
598 * LoadImage32A (USER32.365)
600 * FIXME: implementation still lacks nearly all features, see LR_*
601 * defines in windows.h
604 HANDLE32 WINAPI
LoadImage32A( HINSTANCE32 hinst
, LPCSTR name
, UINT32 type
,
605 INT32 desiredx
, INT32 desiredy
, UINT32 loadflags
)
608 TRACE(resource
,"(0x%04x,%s,%d,%d,%d,0x%08x)\n",
609 hinst
,name
,type
,desiredx
,desiredy
,loadflags
612 TRACE(resource
,"(0x%04x,%p,%d,%d,%d,0x%08x)\n",
613 hinst
,name
,type
,desiredx
,desiredy
,loadflags
618 return LoadBitmap32A(hinst
,name
);
620 return LoadIcon32A(hinst
,name
);
622 return LoadCursor32A(hinst
,name
);
627 /**********************************************************************
628 * LoadImage32W (USER32.366)
630 * FIXME: implementation still lacks nearly all features, see LR_*
631 * defines in windows.h
635 /******************************************************************************
636 * LoadImage32W [USER32.366] Loads an icon, cursor, or bitmap
639 * hinst [I] Handle of instance that contains image
640 * name [I] Name of image
641 * type [I] Type of image
642 * desiredx [I] Desired width
643 * desiredy [I] Desired height
644 * loadflags [I] Load flags
647 * Success: Handle to newly loaded image
651 * Implementation still lacks nearly all features, see LR_*
652 * defines in windows.h
654 HANDLE32 WINAPI
LoadImage32W( HINSTANCE32 hinst
, LPCWSTR name
, UINT32 type
,
655 INT32 desiredx
, INT32 desiredy
, UINT32 loadflags
)
658 TRACE(resource
,"(0x%04x,%p,%d,%d,%d,0x%08x)\n",
659 hinst
,name
,type
,desiredx
,desiredy
,loadflags
662 TRACE(resource
,"(0x%04x,%p,%d,%d,%d,0x%08x)\n",
663 hinst
,name
,type
,desiredx
,desiredy
,loadflags
669 return LoadBitmap32W(hinst
,name
);
671 return LoadIcon32W(hinst
,name
);
673 return LoadCursor32W(hinst
,name
);
679 /**********************************************************************
680 * CopyBitmap32 (not an API)
683 * If it is not an API, why is it declared with WINAPI?
686 HBITMAP32 WINAPI
CopyBitmap32 (HBITMAP32 hnd
)
691 if (GetObject32A (hnd
, sizeof (bmp
), &bmp
))
693 res
= CreateBitmapIndirect32 (&bmp
);
694 SetBitmapBits32 (res
, bmp
.bmWidthBytes
* bmp
.bmHeight
, bmp
.bmBits
);
700 /******************************************************************************
701 * CopyImage32 [USER32.61] Creates new image and copies attributes to it
704 * hnd [I] Handle to image to copy
705 * type [I] Type of image to copy
706 * desiredx [I] Desired width of new image
707 * desiredy [I] Desired height of new image
708 * flags [I] Copy flags
711 * Success: Handle to newly created image
714 * FIXME: implementation still lacks nearly all features, see LR_*
715 * defines in windows.h
717 HICON32 WINAPI
CopyImage32( HANDLE32 hnd
, UINT32 type
, INT32 desiredx
,
718 INT32 desiredy
, UINT32 flags
)
723 return CopyBitmap32(hnd
);
725 return CopyIcon32(hnd
);
727 return CopyCursor32(hnd
);
732 /**********************************************************************
733 * LoadBitmap16 (USER.175)
736 * Can this call LoadBitmap32?
738 HBITMAP16 WINAPI
LoadBitmap16( HINSTANCE16 instance
, SEGPTR name
)
740 HBITMAP32 hbitmap
= 0;
748 char *str
= (char *)PTR_SEG_TO_LIN( name
);
749 TRACE(bitmap
, "(%04x,'%s')\n", instance
, str
);
750 if (str
[0] == '#') name
= (SEGPTR
)(DWORD
)(WORD
)atoi( str
+ 1 );
753 TRACE(bitmap
, "(%04x,%04x)\n",
754 instance
, LOWORD(name
) );
756 if (!instance
) /* OEM bitmap */
758 if (HIWORD((int)name
)) return 0;
759 return OBM_LoadBitmap( LOWORD((int)name
) );
762 if (!(hRsrc
= FindResource16( instance
, name
, RT_BITMAP16
))) return 0;
763 if (!(handle
= LoadResource16( instance
, hRsrc
))) return 0;
765 info
= (BITMAPINFO
*)LockResource16( handle
);
766 if ((hdc
= GetDC32(0)) != 0)
768 char *bits
= (char *)info
+ DIB_BitmapInfoSize( info
, DIB_RGB_COLORS
);
769 hbitmap
= CreateDIBitmap32( hdc
, &info
->bmiHeader
, CBM_INIT
,
770 bits
, info
, DIB_RGB_COLORS
);
771 ReleaseDC32( 0, hdc
);
773 FreeResource16( handle
);
778 /******************************************************************************
779 * LoadBitmap32W [USER32.358] Loads bitmap from the executable file
782 * Success: Handle to specified bitmap
785 HBITMAP32 WINAPI
LoadBitmap32W(
786 HINSTANCE32 instance
, /* [in] Handle to application instance */
787 LPCWSTR name
) /* [in] Address of bitmap resource name */
789 HBITMAP32 hbitmap
= 0;
795 if (!instance
) /* OEM bitmap */
797 if (HIWORD((int)name
)) return 0;
798 return OBM_LoadBitmap( LOWORD((int)name
) );
801 if (!(hRsrc
= FindResource32W( instance
, name
, RT_BITMAP32W
))) return 0;
802 if (!(handle
= LoadResource32( instance
, hRsrc
))) return 0;
804 info
= (BITMAPINFO
*)LockResource32( handle
);
805 if ((hdc
= GetDC32(0)) != 0)
807 char *bits
= (char *)info
+ DIB_BitmapInfoSize( info
, DIB_RGB_COLORS
);
808 hbitmap
= CreateDIBitmap32( hdc
, &info
->bmiHeader
, CBM_INIT
,
809 bits
, info
, DIB_RGB_COLORS
);
810 ReleaseDC32( 0, hdc
);
816 /**********************************************************************
817 * LoadBitmap32A (USER32.357)
819 HBITMAP32 WINAPI
LoadBitmap32A( HINSTANCE32 instance
, LPCSTR name
)
822 if (!HIWORD(name
)) res
= LoadBitmap32W( instance
, (LPWSTR
)name
);
825 LPWSTR uni
= HEAP_strdupAtoW( GetProcessHeap(), 0, name
);
826 res
= LoadBitmap32W( instance
, uni
);
827 HeapFree( GetProcessHeap(), 0, uni
);
833 /***********************************************************************
834 * BITMAP_DeleteObject
836 BOOL32
BITMAP_DeleteObject( HBITMAP16 hbitmap
, BITMAPOBJ
* bmp
)
838 #ifdef PRELIMINARY_WING16_SUPPORT
839 if( bmp
->bitmap
.bmBits
)
840 TSXShmDetach( display
, (XShmSegmentInfo
*)bmp
->bitmap
.bmBits
);
843 TSXFreePixmap( display
, bmp
->pixmap
);
844 #ifdef PRELIMINARY_WING16_SUPPORT
845 if( bmp
->bitmap
.bmBits
)
847 __ShmBitmapCtl
* p
= (__ShmBitmapCtl
*)bmp
->bitmap
.bmBits
;
848 WORD sel
= HIWORD(p
->bits
);
849 unsigned long l
, limit
= GetSelectorLimit(sel
);
851 for( l
= 0; l
< limit
; l
+= 0x10000, sel
+= __AHINCR
)
853 shmctl(p
->si
.shmid
, IPC_RMID
, NULL
);
854 shmdt(p
->si
.shmaddr
); /* already marked for destruction */
858 DIB_DeleteDIBSection( bmp
);
860 return GDI_FreeObject( hbitmap
);
864 /***********************************************************************
867 INT16
BITMAP_GetObject16( BITMAPOBJ
* bmp
, INT16 count
, LPVOID buffer
)
871 if ( count
<= sizeof(BITMAP16
) )
873 BITMAP32
*bmp32
= &bmp
->dib
->dibSection
.dsBm
;
875 bmp16
.bmType
= bmp32
->bmType
;
876 bmp16
.bmWidth
= bmp32
->bmWidth
;
877 bmp16
.bmHeight
= bmp32
->bmHeight
;
878 bmp16
.bmWidthBytes
= bmp32
->bmWidthBytes
;
879 bmp16
.bmPlanes
= bmp32
->bmPlanes
;
880 bmp16
.bmBitsPixel
= bmp32
->bmBitsPixel
;
882 memcpy( buffer
, &bmp16
, count
);
887 FIXME(bitmap
, "not implemented for DIBs: count %d\n", count
);
893 if (count
> sizeof(bmp
->bitmap
)) count
= sizeof(bmp
->bitmap
);
894 memcpy( buffer
, &bmp
->bitmap
, count
);
900 /***********************************************************************
903 INT32
BITMAP_GetObject32( BITMAPOBJ
* bmp
, INT32 count
, LPVOID buffer
)
907 if (count
< sizeof(DIBSECTION
))
909 if (count
> sizeof(BITMAP32
)) count
= sizeof(BITMAP32
);
913 if (count
> sizeof(DIBSECTION
)) count
= sizeof(DIBSECTION
);
916 memcpy( buffer
, &bmp
->dib
->dibSection
, count
);
922 bmp32
.bmType
= bmp
->bitmap
.bmType
;
923 bmp32
.bmWidth
= bmp
->bitmap
.bmWidth
;
924 bmp32
.bmHeight
= bmp
->bitmap
.bmHeight
;
925 bmp32
.bmWidthBytes
= bmp
->bitmap
.bmWidthBytes
;
926 bmp32
.bmPlanes
= bmp
->bitmap
.bmPlanes
;
927 bmp32
.bmBitsPixel
= bmp
->bitmap
.bmBitsPixel
;
929 if (count
> sizeof(bmp32
)) count
= sizeof(bmp32
);
930 memcpy( buffer
, &bmp32
, count
);
936 /***********************************************************************
937 * CreateDiscardableBitmap16 (GDI.156)
939 HBITMAP16 WINAPI
CreateDiscardableBitmap16( HDC16 hdc
, INT16 width
,
942 return CreateCompatibleBitmap16( hdc
, width
, height
);
946 /******************************************************************************
947 * CreateDiscardableBitmap32 [GDI32.38] Creates a discardable bitmap
950 * Success: Handle to bitmap
953 HBITMAP32 WINAPI
CreateDiscardableBitmap32(
954 HDC32 hdc
, /* [in] Handle to device context */
955 INT32 width
, /* [in] Bitmap width */
956 INT32 height
) /* [in] Bitmap height */
958 return CreateCompatibleBitmap32( hdc
, width
, height
);
962 /***********************************************************************
963 * GetBitmapDimensionEx16 (GDI.468)
966 * Can this call GetBitmapDimensionEx32?
968 BOOL16 WINAPI
GetBitmapDimensionEx16( HBITMAP16 hbitmap
, LPSIZE16 size
)
970 BITMAPOBJ
* bmp
= (BITMAPOBJ
*) GDI_GetObjPtr( hbitmap
, BITMAP_MAGIC
);
971 if (!bmp
) return FALSE
;
973 GDI_HEAP_UNLOCK( hbitmap
);
978 /******************************************************************************
979 * GetBitmapDimensionEx32 [GDI32.144] Retrieves dimensions of a bitmap
985 BOOL32 WINAPI
GetBitmapDimensionEx32(
986 HBITMAP32 hbitmap
, /* [in] Handle to bitmap */
987 LPSIZE32 size
) /* [out] Address of struct receiving dimensions */
989 BITMAPOBJ
* bmp
= (BITMAPOBJ
*) GDI_GetObjPtr( hbitmap
, BITMAP_MAGIC
);
990 if (!bmp
) return FALSE
;
991 size
->cx
= (INT32
)bmp
->size
.cx
;
992 size
->cy
= (INT32
)bmp
->size
.cy
;
993 GDI_HEAP_UNLOCK( hbitmap
);
998 /***********************************************************************
999 * GetBitmapDimension (GDI.162)
1001 DWORD WINAPI
GetBitmapDimension( HBITMAP16 hbitmap
)
1004 if (!GetBitmapDimensionEx16( hbitmap
, &size
)) return 0;
1005 return MAKELONG( size
.cx
, size
.cy
);
1009 /***********************************************************************
1010 * SetBitmapDimensionEx16 (GDI.478)
1012 BOOL16 WINAPI
SetBitmapDimensionEx16( HBITMAP16 hbitmap
, INT16 x
, INT16 y
,
1015 BITMAPOBJ
* bmp
= (BITMAPOBJ
*) GDI_GetObjPtr( hbitmap
, BITMAP_MAGIC
);
1016 if (!bmp
) return FALSE
;
1017 if (prevSize
) *prevSize
= bmp
->size
;
1020 GDI_HEAP_UNLOCK( hbitmap
);
1025 /******************************************************************************
1026 * SetBitmapDimensionEx32 [GDI32.304] Assignes dimensions to a bitmap
1032 BOOL32 WINAPI
SetBitmapDimensionEx32(
1033 HBITMAP32 hbitmap
, /* [in] Handle to bitmap */
1034 INT32 x
, /* [in] Bitmap width */
1035 INT32 y
, /* [in] Bitmap height */
1036 LPSIZE32 prevSize
) /* [out] Address of structure for orig dims */
1038 BITMAPOBJ
* bmp
= (BITMAPOBJ
*) GDI_GetObjPtr( hbitmap
, BITMAP_MAGIC
);
1039 if (!bmp
) return FALSE
;
1040 if (prevSize
) CONV_SIZE16TO32( &bmp
->size
, prevSize
);
1041 bmp
->size
.cx
= (INT16
)x
;
1042 bmp
->size
.cy
= (INT16
)y
;
1043 GDI_HEAP_UNLOCK( hbitmap
);
1048 /***********************************************************************
1049 * SetBitmapDimension (GDI.163)
1051 DWORD WINAPI
SetBitmapDimension( HBITMAP16 hbitmap
, INT16 x
, INT16 y
)
1054 if (!SetBitmapDimensionEx16( hbitmap
, x
, y
, &size
)) return 0;
1055 return MAKELONG( size
.cx
, size
.cy
);