4 * Copyright 1993 Alexandre Julliard
18 #include "sysmetrics.h"
19 #include "cursoricon.h"
22 #ifdef PRELIMINARY_WING16_SUPPORT
23 #include <sys/types.h>
28 /* GCs used for B&W and color bitmap operations */
29 GC BITMAP_monoGC
= 0, BITMAP_colorGC
= 0;
31 /***********************************************************************
34 * Wrapper to call XPutImage with CALL_LARGE_STACK.
37 struct XPutImage_descr
45 static int XPutImage_wrapper( const struct XPutImage_descr
*descr
)
47 return XPutImage( display
, descr
->bmp
->pixmap
, BITMAP_GC(descr
->bmp
),
48 descr
->image
, 0, 0, 0, 0, descr
->width
, descr
->height
);
51 /***********************************************************************
52 * BITMAP_GetBitsPadding
54 * Return number of bytes to pad a scanline of 16-bit aligned Windows DDB data.
56 INT32
BITMAP_GetBitsPadding( int bmWidth
, int bpp
)
63 if (!(bmWidth
& 15)) pad
= 0;
64 else pad
= ((16 - (bmWidth
& 15)) + 7) / 8;
68 pad
= (2 - (bmWidth
& 1)) & 1;
72 pad
= (bmWidth
*3) & 1;
78 pad
= 0; /* we have 16bit alignment already */
82 if (!(bmWidth
& 3)) pad
= 0;
83 else pad
= ((4 - (bmWidth
& 3)) + 1) / 2;
87 WARN(bitmap
,"Unknown depth %d, please report.\n", bpp
);
93 /***********************************************************************
96 * Return number of bytes taken by a scanline of 16-bit aligned Windows DDB data.
98 INT32
BITMAP_GetBitsWidth( int bmWidth
, int bpp
)
103 return 2 * ((bmWidth
+15) >> 4);
106 bmWidth
*= 3; /* fall through */
108 return bmWidth
+ (bmWidth
& 1);
118 return 2 * ((bmWidth
+3) >> 2);
121 WARN(bitmap
,"Unknown depth %d, please report.\n", bpp
);
126 /***********************************************************************
127 * CreateUserBitmap16 (GDI.407)
129 HBITMAP16 WINAPI
CreateUserBitmap16( INT16 width
, INT16 height
, UINT16 planes
,
130 UINT16 bpp
, LPCVOID bits
)
132 return CreateBitmap16( width
, height
, planes
, bpp
, bits
);
135 /***********************************************************************
136 * CreateUserDiscardableBitmap16 (GDI.409)
138 HBITMAP16 WINAPI
CreateUserDiscardableBitmap16( WORD dummy
,
139 INT16 width
, INT16 height
)
141 return CreateUserBitmap16( width
, height
, 1, screenDepth
, NULL
);
146 /***********************************************************************
147 * CreateBitmap16 (GDI.48)
149 HBITMAP16 WINAPI
CreateBitmap16( INT16 width
, INT16 height
, UINT16 planes
,
150 UINT16 bpp
, LPCVOID bits
)
152 return CreateBitmap32( width
, height
, planes
, bpp
, bits
);
156 /******************************************************************************
157 * CreateBitmap32 [GDI32.25] Creates a bitmap with the specified info
160 * width [I] bitmap width
161 * height [I] bitmap height
162 * planes [I] Number of color planes
163 * bpp [I] Number of bits to identify a color
164 * bits [I] Pointer to array containing color data
167 * Success: Handle to bitmap
170 HBITMAP32 WINAPI
CreateBitmap32( INT32 width
, INT32 height
, UINT32 planes
,
171 UINT32 bpp
, LPCVOID bits
)
173 BITMAPOBJ
* bmpObjPtr
;
176 planes
= (BYTE
)planes
;
179 TRACE(gdi
, "%dx%d, %d colors\n", width
, height
, 1 << (planes
*bpp
) );
181 /* Check parameters */
182 if (!height
|| !width
|| planes
!= 1) return 0;
183 if ((bpp
!= 1) && (bpp
!= screenDepth
)) return 0;
184 if (height
< 0) height
= -height
;
185 if (width
< 0) width
= -width
;
187 /* Create the BITMAPOBJ */
188 hbitmap
= GDI_AllocObject( sizeof(BITMAPOBJ
), BITMAP_MAGIC
);
189 if (!hbitmap
) return 0;
190 bmpObjPtr
= (BITMAPOBJ
*) GDI_HEAP_LOCK( hbitmap
);
192 bmpObjPtr
->size
.cx
= 0;
193 bmpObjPtr
->size
.cy
= 0;
194 bmpObjPtr
->bitmap
.bmType
= 0;
195 bmpObjPtr
->bitmap
.bmWidth
= (INT16
)width
;
196 bmpObjPtr
->bitmap
.bmHeight
= (INT16
)height
;
197 bmpObjPtr
->bitmap
.bmPlanes
= (BYTE
)planes
;
198 bmpObjPtr
->bitmap
.bmBitsPixel
= (BYTE
)bpp
;
199 bmpObjPtr
->bitmap
.bmWidthBytes
= (INT16
)BITMAP_WIDTH_BYTES( width
, bpp
);
200 bmpObjPtr
->bitmap
.bmBits
= 0;
202 bmpObjPtr
->dib
= NULL
;
204 /* Create the pixmap */
205 bmpObjPtr
->pixmap
= TSXCreatePixmap(display
, rootWindow
, width
, height
, bpp
);
206 if (!bmpObjPtr
->pixmap
)
208 GDI_HEAP_FREE( hbitmap
);
211 else if (bits
) /* Set bitmap bits */
212 SetBitmapBits32( hbitmap
, height
* bmpObjPtr
->bitmap
.bmWidthBytes
,
214 GDI_HEAP_UNLOCK( hbitmap
);
219 /***********************************************************************
220 * CreateCompatibleBitmap16 (GDI.51)
222 HBITMAP16 WINAPI
CreateCompatibleBitmap16(HDC16 hdc
, INT16 width
, INT16 height
)
224 return CreateCompatibleBitmap32( hdc
, width
, height
);
228 /******************************************************************************
229 * CreateCompatibleBitmap32 [GDI32.30] Creates a bitmap compatible with the DC
232 * hdc [I] Handle to device context
233 * width [I] Width of bitmap
234 * height [I] Height of bitmap
237 * Success: Handle to bitmap
240 HBITMAP32 WINAPI
CreateCompatibleBitmap32( HDC32 hdc
, INT32 width
, INT32 height
)
242 HBITMAP32 hbmpRet
= 0;
245 TRACE(gdi
, "(%04x,%d,%d) = \n", hdc
, width
, height
);
246 if (!(dc
= DC_GetDCPtr( hdc
))) return 0;
247 if ((width
>0x1000) || (height
> 0x1000))
249 FIXME(gdi
,"got bad width %d or height %d, please look for reason\n",
253 hbmpRet
= CreateBitmap32( width
, height
, 1, dc
->w
.bitsPerPixel
, NULL
);
254 TRACE(gdi
,"\t\t%04x\n", hbmpRet
);
259 /***********************************************************************
260 * CreateBitmapIndirect16 (GDI.49)
262 HBITMAP16 WINAPI
CreateBitmapIndirect16( const BITMAP16
* bmp
)
264 return CreateBitmap16( bmp
->bmWidth
, bmp
->bmHeight
, bmp
->bmPlanes
,
265 bmp
->bmBitsPixel
, PTR_SEG_TO_LIN( bmp
->bmBits
) );
269 /******************************************************************************
270 * CreateBitmapIndirect32 [GDI32.26] Creates a bitmap with the specifies info
273 * Success: Handle to bitmap
276 HBITMAP32 WINAPI
CreateBitmapIndirect32(
277 const BITMAP32
* bmp
) /* [in] Pointer to the bitmap data */
279 return CreateBitmap32( bmp
->bmWidth
, bmp
->bmHeight
, bmp
->bmPlanes
,
280 bmp
->bmBitsPixel
, bmp
->bmBits
);
284 /***********************************************************************
287 * Get an X image for a bitmap. For use with CALL_LARGE_STACK.
289 XImage
*BITMAP_GetXImage( const BITMAPOBJ
*bmp
)
291 return XGetImage( display
, bmp
->pixmap
, 0, 0, bmp
->bitmap
.bmWidth
,
292 bmp
->bitmap
.bmHeight
, AllPlanes
, ZPixmap
);
296 /***********************************************************************
297 * GetBitmapBits16 (GDI.74)
299 LONG WINAPI
GetBitmapBits16( HBITMAP16 hbitmap
, LONG count
, LPVOID buffer
)
301 return GetBitmapBits32( hbitmap
, count
, buffer
);
305 /***********************************************************************
306 * GetBitmapBits32 [GDI32.143] Copies bitmap bits of bitmap to buffer
309 * Success: Number of bytes copied
312 LONG WINAPI
GetBitmapBits32(
313 HBITMAP32 hbitmap
, /* [in] Handle to bitmap */
314 LONG count
, /* [in] Number of bytes to copy */
315 LPVOID buffer
) /* [out] Pointer to buffer to receive bits */
318 LONG height
, old_height
;
325 WARN(bitmap
, "(%ld): Negative number of bytes passed???\n", count
);
328 bmp
= (BITMAPOBJ
*) GDI_GetObjPtr( hbitmap
, BITMAP_MAGIC
);
331 /* Only get entire lines */
332 height
= count
/ bmp
->bitmap
.bmWidthBytes
;
333 if (height
> bmp
->bitmap
.bmHeight
) height
= bmp
->bitmap
.bmHeight
;
335 TRACE(bitmap
, "%dx%d %d colors %p fetched height: %ld\n",
336 bmp
->bitmap
.bmWidth
, bmp
->bitmap
.bmHeight
,
337 1 << bmp
->bitmap
.bmBitsPixel
, buffer
, height
);
339 pad
= BITMAP_GetBitsPadding( bmp
->bitmap
.bmWidth
, bmp
->bitmap
.bmBitsPixel
);
341 if (!height
|| (pad
== -1))
343 GDI_HEAP_UNLOCK( hbitmap
);
347 EnterCriticalSection( &X11DRV_CritSection
);
349 /* Hack: change the bitmap height temporarily to avoid */
350 /* getting unnecessary bitmap rows. */
351 old_height
= bmp
->bitmap
.bmHeight
;
352 bmp
->bitmap
.bmHeight
= height
;
353 image
= (XImage
*)CALL_LARGE_STACK( BITMAP_GetXImage
, bmp
);
354 bmp
->bitmap
.bmHeight
= old_height
;
356 /* copy XImage to 16 bit padded image buffer with real bitsperpixel */
359 switch (bmp
->bitmap
.bmBitsPixel
)
362 for (h
=0;h
<height
;h
++)
365 for (w
=0;w
<bmp
->bitmap
.bmWidth
;w
++)
369 *tbuf
|= XGetPixel(image
,w
,h
)<<(7-(w
&7));
370 if ((w
&7) == 7) ++tbuf
;
376 for (h
=0;h
<height
;h
++)
378 for (w
=0;w
<bmp
->bitmap
.bmWidth
;w
++)
380 if (!(w
& 1)) *tbuf
= XGetPixel( image
, w
, h
) << 4;
381 else *tbuf
++ |= XGetPixel( image
, w
, h
) & 0x0f;
387 for (h
=0;h
<height
;h
++)
389 for (w
=0;w
<bmp
->bitmap
.bmWidth
;w
++)
390 *tbuf
++ = XGetPixel(image
,w
,h
);
396 for (h
=0;h
<height
;h
++)
398 for (w
=0;w
<bmp
->bitmap
.bmWidth
;w
++)
400 long pixel
= XGetPixel(image
,w
,h
);
402 *tbuf
++ = pixel
& 0xff;
403 *tbuf
++ = (pixel
>>8) & 0xff;
408 for (h
=0;h
<height
;h
++)
410 for (w
=0;w
<bmp
->bitmap
.bmWidth
;w
++)
412 long pixel
= XGetPixel(image
,w
,h
);
414 *tbuf
++ = pixel
& 0xff;
415 *tbuf
++ = (pixel
>> 8) & 0xff;
416 *tbuf
++ = (pixel
>>16) & 0xff;
423 for (h
=0;h
<height
;h
++)
425 for (w
=0;w
<bmp
->bitmap
.bmWidth
;w
++)
427 long pixel
= XGetPixel(image
,w
,h
);
429 *tbuf
++ = pixel
& 0xff;
430 *tbuf
++ = (pixel
>> 8) & 0xff;
431 *tbuf
++ = (pixel
>>16) & 0xff;
432 *tbuf
++ = (pixel
>>24) & 0xff;
438 FIXME(bitmap
, "Unhandled bits:%d\n", bmp
->bitmap
.bmBitsPixel
);
440 XDestroyImage( image
);
441 LeaveCriticalSection( &X11DRV_CritSection
);
443 GDI_HEAP_UNLOCK( hbitmap
);
444 return height
* bmp
->bitmap
.bmWidthBytes
;
448 /***********************************************************************
449 * SetBitmapBits16 (GDI.106)
451 LONG WINAPI
SetBitmapBits16( HBITMAP16 hbitmap
, LONG count
, LPCVOID buffer
)
453 return SetBitmapBits32( hbitmap
, count
, buffer
);
457 /******************************************************************************
458 * SetBitmapBits32 [GDI32.303] Sets bits of color data for a bitmap
461 * Success: Number of bytes used in setting the bitmap bits
464 LONG WINAPI
SetBitmapBits32(
465 HBITMAP32 hbitmap
, /* [in] Handle to bitmap */
466 LONG count
, /* [in] Number of bytes in bitmap array */
467 LPCVOID buffer
) /* [in] Address of array with bitmap bits */
469 struct XPutImage_descr descr
;
473 LPBYTE sbuf
,tmpbuffer
;
474 int w
,h
,pad
,widthbytes
;
478 WARN(bitmap
, "(%ld): Negative number of bytes passed???\n", count
);
481 bmp
= (BITMAPOBJ
*) GDI_GetObjPtr( hbitmap
, BITMAP_MAGIC
);
484 TRACE(bitmap
, "%dx%d %d colors %p\n",
485 bmp
->bitmap
.bmWidth
, bmp
->bitmap
.bmHeight
,
486 1 << bmp
->bitmap
.bmBitsPixel
, buffer
);
488 /* Only set entire lines */
489 height
= count
/ bmp
->bitmap
.bmWidthBytes
;
490 if (height
> bmp
->bitmap
.bmHeight
) height
= bmp
->bitmap
.bmHeight
;
492 pad
= BITMAP_GetBitsPadding( bmp
->bitmap
.bmWidth
, bmp
->bitmap
.bmBitsPixel
);
494 if (!height
|| (pad
== -1))
496 GDI_HEAP_UNLOCK( hbitmap
);
500 sbuf
= (LPBYTE
)buffer
;
502 widthbytes
= DIB_GetXImageWidthBytes(bmp
->bitmap
.bmWidth
,bmp
->bitmap
.bmBitsPixel
);
503 tmpbuffer
= (LPBYTE
)xmalloc(widthbytes
*height
);
505 EnterCriticalSection( &X11DRV_CritSection
);
506 image
= XCreateImage( display
, DefaultVisualOfScreen(screen
),
507 bmp
->bitmap
.bmBitsPixel
, ZPixmap
, 0, tmpbuffer
,
508 bmp
->bitmap
.bmWidth
,height
,32,widthbytes
);
510 /* copy 16 bit padded image buffer with real bitsperpixel to XImage */
511 sbuf
= (LPBYTE
)buffer
;
512 switch (bmp
->bitmap
.bmBitsPixel
)
515 for (h
=0;h
<height
;h
++)
517 for (w
=0;w
<bmp
->bitmap
.bmWidth
;w
++)
519 XPutPixel(image
,w
,h
,(sbuf
[0]>>(7-(w
&7))) & 1);
527 for (h
=0;h
<height
;h
++)
529 for (w
=0;w
<bmp
->bitmap
.bmWidth
;w
++)
531 if (!(w
& 1)) XPutPixel( image
, w
, h
, *sbuf
>> 4 );
532 else XPutPixel( image
, w
, h
, *sbuf
++ & 0xf );
538 for (h
=0;h
<height
;h
++)
540 for (w
=0;w
<bmp
->bitmap
.bmWidth
;w
++)
541 XPutPixel(image
,w
,h
,*sbuf
++);
547 for (h
=0;h
<height
;h
++)
549 for (w
=0;w
<bmp
->bitmap
.bmWidth
;w
++)
551 XPutPixel(image
,w
,h
,sbuf
[1]*256+sbuf
[0]);
557 for (h
=0;h
<height
;h
++)
559 for (w
=0;w
<bmp
->bitmap
.bmWidth
;w
++)
561 XPutPixel(image
,w
,h
,(sbuf
[2]<<16)+(sbuf
[1]<<8)+sbuf
[0]);
568 for (h
=0;h
<height
;h
++)
570 for (w
=0;w
<bmp
->bitmap
.bmWidth
;w
++)
572 XPutPixel(image
,w
,h
,(sbuf
[3]<<24)+(sbuf
[2]<<16)+(sbuf
[1]<<8)+sbuf
[0]);
579 FIXME(bitmap
, "Unhandled bits:%d\n", bmp
->bitmap
.bmBitsPixel
);
585 descr
.width
= bmp
->bitmap
.bmWidth
;
586 descr
.height
= height
;
587 CALL_LARGE_STACK( XPutImage_wrapper
, &descr
);
588 XDestroyImage( image
); /* frees tmpbuffer too */
589 LeaveCriticalSection( &X11DRV_CritSection
);
591 GDI_HEAP_UNLOCK( hbitmap
);
592 return height
* bmp
->bitmap
.bmWidthBytes
;
595 /***********************************************************************
596 * LoadImage16 [USER.389]
599 HANDLE16 WINAPI
LoadImage16( HINSTANCE16 hinst
, LPCSTR name
, UINT16 type
,
600 INT16 desiredx
, INT16 desiredy
, UINT16 loadflags
)
603 TRACE(resource
,"(0x%04x,%s,%d,%d,%d,0x%08x)\n",
604 hinst
,(char *)PTR_SEG_TO_LIN(name
),type
,desiredx
,desiredy
,loadflags
);
606 TRACE(resource
,"LoadImage16(0x%04x,%p,%d,%d,%d,0x%08x)\n",
607 hinst
,name
,type
,desiredx
,desiredy
,loadflags
);
611 return LoadBitmap16(hinst
,(SEGPTR
)name
);
613 return LoadIcon16(hinst
,(SEGPTR
)name
);
615 return LoadCursor16(hinst
,(SEGPTR
)name
);
621 /**********************************************************************
622 * LoadImage32A (USER32.365)
624 * FIXME: implementation lacks some features, see LR_ defines in windows.h
627 HANDLE32 WINAPI
LoadImage32A( HINSTANCE32 hinst
, LPCSTR name
, UINT32 type
,
628 INT32 desiredx
, INT32 desiredy
, UINT32 loadflags
)
633 if (HIWORD(name
)) u_name
= HEAP_strdupAtoW(GetProcessHeap(), 0, name
);
634 else u_name
=(LPWSTR
)name
;
635 res
= LoadImage32W(hinst
, u_name
, type
, desiredx
, desiredy
, loadflags
);
636 if (HIWORD(name
)) HeapFree(GetProcessHeap(), 0, u_name
);
641 /******************************************************************************
642 * LoadImage32W [USER32.366] Loads an icon, cursor, or bitmap
645 * hinst [I] Handle of instance that contains image
646 * name [I] Name of image
647 * type [I] Type of image
648 * desiredx [I] Desired width
649 * desiredy [I] Desired height
650 * loadflags [I] Load flags
653 * Success: Handle to newly loaded image
656 * FIXME: Implementation lacks some features, see LR_ defines in windows.h
658 HANDLE32 WINAPI
LoadImage32W( HINSTANCE32 hinst
, LPCWSTR name
, UINT32 type
,
659 INT32 desiredx
, INT32 desiredy
, UINT32 loadflags
)
662 TRACE(resource
,"(0x%04x,%p,%d,%d,%d,0x%08x)\n",
663 hinst
,name
,type
,desiredx
,desiredy
,loadflags
666 TRACE(resource
,"(0x%04x,%p,%d,%d,%d,0x%08x)\n",
667 hinst
,name
,type
,desiredx
,desiredy
,loadflags
670 if (loadflags
& LR_DEFAULTSIZE
)
671 if (type
== IMAGE_ICON
) {
672 if (!desiredx
) desiredx
= SYSMETRICS_CXICON
;
673 if (!desiredy
) desiredy
= SYSMETRICS_CYICON
;
674 } else if (type
== IMAGE_CURSOR
) {
675 if (!desiredx
) desiredx
= SYSMETRICS_CXCURSOR
;
676 if (!desiredy
) desiredy
= SYSMETRICS_CYCURSOR
;
678 if (loadflags
& LR_LOADFROMFILE
) loadflags
&= ~LR_SHARED
;
681 return BITMAP_LoadBitmap32W(hinst
, name
, loadflags
);
683 return CURSORICON_Load32(hinst
, name
, desiredx
, desiredy
,
684 MIN(16, COLOR_GetSystemPaletteSize()), FALSE
, loadflags
);
686 return CURSORICON_Load32(hinst
, name
, desiredx
, desiredy
, 1, TRUE
,
693 /**********************************************************************
694 * CopyBitmap32 (not an API)
697 * If it is not an API, why is it declared with WINAPI?
700 HBITMAP32 WINAPI
CopyBitmap32 (HBITMAP32 hnd
)
705 if (GetObject32A (hnd
, sizeof (bmp
), &bmp
))
707 res
= CreateBitmapIndirect32 (&bmp
);
708 SetBitmapBits32 (res
, bmp
.bmWidthBytes
* bmp
.bmHeight
, bmp
.bmBits
);
714 /******************************************************************************
715 * CopyImage32 [USER32.61] Creates new image and copies attributes to it
718 * hnd [I] Handle to image to copy
719 * type [I] Type of image to copy
720 * desiredx [I] Desired width of new image
721 * desiredy [I] Desired height of new image
722 * flags [I] Copy flags
725 * Success: Handle to newly created image
728 * FIXME: implementation still lacks nearly all features, see LR_*
729 * defines in windows.h
731 HICON32 WINAPI
CopyImage32( HANDLE32 hnd
, UINT32 type
, INT32 desiredx
,
732 INT32 desiredy
, UINT32 flags
)
737 return CopyBitmap32(hnd
);
739 return CopyIcon32(hnd
);
741 return CopyCursor32(hnd
);
746 /**********************************************************************
747 * LoadBitmap16 (USER.175)
750 * Can this call LoadBitmap32?
752 HBITMAP16 WINAPI
LoadBitmap16( HINSTANCE16 instance
, SEGPTR name
)
754 HBITMAP32 hbitmap
= 0;
762 char *str
= (char *)PTR_SEG_TO_LIN( name
);
763 TRACE(bitmap
, "(%04x,'%s')\n", instance
, str
);
764 if (str
[0] == '#') name
= (SEGPTR
)(DWORD
)(WORD
)atoi( str
+ 1 );
767 TRACE(bitmap
, "(%04x,%04x)\n",
768 instance
, LOWORD(name
) );
770 if (!instance
) /* OEM bitmap */
772 if (HIWORD((int)name
)) return 0;
773 return OBM_LoadBitmap( LOWORD((int)name
) );
776 if (!(hRsrc
= FindResource16( instance
, name
, RT_BITMAP16
))) return 0;
777 if (!(handle
= LoadResource16( instance
, hRsrc
))) return 0;
779 info
= (BITMAPINFO
*)LockResource16( handle
);
780 if ((hdc
= GetDC32(0)) != 0)
782 char *bits
= (char *)info
+ DIB_BitmapInfoSize( info
, DIB_RGB_COLORS
);
783 hbitmap
= CreateDIBitmap32( hdc
, &info
->bmiHeader
, CBM_INIT
,
784 bits
, info
, DIB_RGB_COLORS
);
785 ReleaseDC32( 0, hdc
);
787 FreeResource16( handle
);
792 HBITMAP32
BITMAP_LoadBitmap32W(HINSTANCE32 instance
,LPCWSTR name
,
795 HBITMAP32 hbitmap
= 0;
800 BITMAPINFO
*info
, *fix_info
=NULL
;
804 if (!(loadflags
& LR_LOADFROMFILE
)) {
805 if (!instance
) /* OEM bitmap */
807 if (HIWORD((int)name
)) return 0;
808 return OBM_LoadBitmap( LOWORD((int)name
) );
811 if (!(hRsrc
= FindResource32W( instance
, name
, RT_BITMAP32W
))) return 0;
812 if (!(handle
= LoadResource32( instance
, hRsrc
))) return 0;
814 if ((info
= (BITMAPINFO
*)LockResource32( handle
)) == NULL
) return 0;
818 if (!(ptr
= (char *)VIRTUAL_MapFileW( name
))) return 0;
819 info
= (BITMAPINFO
*)(ptr
+ sizeof(BITMAPFILEHEADER
));
821 size
= DIB_BitmapInfoSize(info
, DIB_RGB_COLORS
);
822 if ((hFix
= GlobalAlloc32(0, size
))) fix_info
=GlobalLock32(hFix
);
826 memcpy(fix_info
, info
, size
);
827 pix
= *((LPBYTE
)info
+DIB_BitmapInfoSize(info
, DIB_RGB_COLORS
));
828 DIB_FixColorsToLoadflags(fix_info
, loadflags
, pix
);
829 if ((hdc
= GetDC32(0)) != 0) {
830 if (loadflags
& LR_CREATEDIBSECTION
)
831 hbitmap
= CreateDIBSection32(hdc
, fix_info
, DIB_RGB_COLORS
, NULL
, 0, 0);
833 char *bits
= (char *)info
+ size
;;
834 hbitmap
= CreateDIBitmap32( hdc
, &fix_info
->bmiHeader
, CBM_INIT
,
835 bits
, fix_info
, DIB_RGB_COLORS
);
837 ReleaseDC32( 0, hdc
);
839 GlobalUnlock32(hFix
);
842 if (loadflags
& LR_LOADFROMFILE
) UnmapViewOfFile( ptr
);
845 /******************************************************************************
846 * LoadBitmap32W [USER32.358] Loads bitmap from the executable file
849 * Success: Handle to specified bitmap
852 HBITMAP32 WINAPI
LoadBitmap32W(
853 HINSTANCE32 instance
, /* [in] Handle to application instance */
854 LPCWSTR name
) /* [in] Address of bitmap resource name */
856 return BITMAP_LoadBitmap32W(instance
, name
, 0);
860 /**********************************************************************
861 * LoadBitmap32A (USER32.357)
863 HBITMAP32 WINAPI
LoadBitmap32A( HINSTANCE32 instance
, LPCSTR name
)
866 if (!HIWORD(name
)) res
= LoadBitmap32W( instance
, (LPWSTR
)name
);
869 LPWSTR uni
= HEAP_strdupAtoW( GetProcessHeap(), 0, name
);
870 res
= LoadBitmap32W( instance
, uni
);
871 HeapFree( GetProcessHeap(), 0, uni
);
877 /***********************************************************************
878 * BITMAP_DeleteObject
880 BOOL32
BITMAP_DeleteObject( HBITMAP16 hbitmap
, BITMAPOBJ
* bmp
)
882 #ifdef PRELIMINARY_WING16_SUPPORT
883 if( bmp
->bitmap
.bmBits
)
884 TSXShmDetach( display
, (XShmSegmentInfo
*)bmp
->bitmap
.bmBits
);
887 TSXFreePixmap( display
, bmp
->pixmap
);
888 #ifdef PRELIMINARY_WING16_SUPPORT
889 if( bmp
->bitmap
.bmBits
)
891 __ShmBitmapCtl
* p
= (__ShmBitmapCtl
*)bmp
->bitmap
.bmBits
;
892 WORD sel
= HIWORD(p
->bits
);
893 unsigned long l
, limit
= GetSelectorLimit(sel
);
895 for( l
= 0; l
< limit
; l
+= 0x10000, sel
+= __AHINCR
)
897 shmctl(p
->si
.shmid
, IPC_RMID
, NULL
);
898 shmdt(p
->si
.shmaddr
); /* already marked for destruction */
902 DIB_DeleteDIBSection( bmp
);
904 return GDI_FreeObject( hbitmap
);
908 /***********************************************************************
911 INT16
BITMAP_GetObject16( BITMAPOBJ
* bmp
, INT16 count
, LPVOID buffer
)
915 if ( count
<= sizeof(BITMAP16
) )
917 BITMAP32
*bmp32
= &bmp
->dib
->dibSection
.dsBm
;
919 bmp16
.bmType
= bmp32
->bmType
;
920 bmp16
.bmWidth
= bmp32
->bmWidth
;
921 bmp16
.bmHeight
= bmp32
->bmHeight
;
922 bmp16
.bmWidthBytes
= bmp32
->bmWidthBytes
;
923 bmp16
.bmPlanes
= bmp32
->bmPlanes
;
924 bmp16
.bmBitsPixel
= bmp32
->bmBitsPixel
;
926 memcpy( buffer
, &bmp16
, count
);
931 FIXME(bitmap
, "not implemented for DIBs: count %d\n", count
);
937 if (count
> sizeof(bmp
->bitmap
)) count
= sizeof(bmp
->bitmap
);
938 memcpy( buffer
, &bmp
->bitmap
, count
);
944 /***********************************************************************
947 INT32
BITMAP_GetObject32( BITMAPOBJ
* bmp
, INT32 count
, LPVOID buffer
)
951 if (count
< sizeof(DIBSECTION
))
953 if (count
> sizeof(BITMAP32
)) count
= sizeof(BITMAP32
);
957 if (count
> sizeof(DIBSECTION
)) count
= sizeof(DIBSECTION
);
960 memcpy( buffer
, &bmp
->dib
->dibSection
, count
);
966 bmp32
.bmType
= bmp
->bitmap
.bmType
;
967 bmp32
.bmWidth
= bmp
->bitmap
.bmWidth
;
968 bmp32
.bmHeight
= bmp
->bitmap
.bmHeight
;
969 bmp32
.bmWidthBytes
= bmp
->bitmap
.bmWidthBytes
;
970 bmp32
.bmPlanes
= bmp
->bitmap
.bmPlanes
;
971 bmp32
.bmBitsPixel
= bmp
->bitmap
.bmBitsPixel
;
973 if (count
> sizeof(bmp32
)) count
= sizeof(bmp32
);
974 memcpy( buffer
, &bmp32
, count
);
980 /***********************************************************************
981 * CreateDiscardableBitmap16 (GDI.156)
983 HBITMAP16 WINAPI
CreateDiscardableBitmap16( HDC16 hdc
, INT16 width
,
986 return CreateCompatibleBitmap16( hdc
, width
, height
);
990 /******************************************************************************
991 * CreateDiscardableBitmap32 [GDI32.38] Creates a discardable bitmap
994 * Success: Handle to bitmap
997 HBITMAP32 WINAPI
CreateDiscardableBitmap32(
998 HDC32 hdc
, /* [in] Handle to device context */
999 INT32 width
, /* [in] Bitmap width */
1000 INT32 height
) /* [in] Bitmap height */
1002 return CreateCompatibleBitmap32( hdc
, width
, height
);
1006 /***********************************************************************
1007 * GetBitmapDimensionEx16 (GDI.468)
1010 * Can this call GetBitmapDimensionEx32?
1012 BOOL16 WINAPI
GetBitmapDimensionEx16( HBITMAP16 hbitmap
, LPSIZE16 size
)
1014 BITMAPOBJ
* bmp
= (BITMAPOBJ
*) GDI_GetObjPtr( hbitmap
, BITMAP_MAGIC
);
1015 if (!bmp
) return FALSE
;
1017 GDI_HEAP_UNLOCK( hbitmap
);
1022 /******************************************************************************
1023 * GetBitmapDimensionEx32 [GDI32.144] Retrieves dimensions of a bitmap
1029 BOOL32 WINAPI
GetBitmapDimensionEx32(
1030 HBITMAP32 hbitmap
, /* [in] Handle to bitmap */
1031 LPSIZE32 size
) /* [out] Address of struct receiving dimensions */
1033 BITMAPOBJ
* bmp
= (BITMAPOBJ
*) GDI_GetObjPtr( hbitmap
, BITMAP_MAGIC
);
1034 if (!bmp
) return FALSE
;
1035 size
->cx
= (INT32
)bmp
->size
.cx
;
1036 size
->cy
= (INT32
)bmp
->size
.cy
;
1037 GDI_HEAP_UNLOCK( hbitmap
);
1042 /***********************************************************************
1043 * GetBitmapDimension (GDI.162)
1045 DWORD WINAPI
GetBitmapDimension( HBITMAP16 hbitmap
)
1048 if (!GetBitmapDimensionEx16( hbitmap
, &size
)) return 0;
1049 return MAKELONG( size
.cx
, size
.cy
);
1053 /***********************************************************************
1054 * SetBitmapDimensionEx16 (GDI.478)
1056 BOOL16 WINAPI
SetBitmapDimensionEx16( HBITMAP16 hbitmap
, INT16 x
, INT16 y
,
1059 BITMAPOBJ
* bmp
= (BITMAPOBJ
*) GDI_GetObjPtr( hbitmap
, BITMAP_MAGIC
);
1060 if (!bmp
) return FALSE
;
1061 if (prevSize
) *prevSize
= bmp
->size
;
1064 GDI_HEAP_UNLOCK( hbitmap
);
1069 /******************************************************************************
1070 * SetBitmapDimensionEx32 [GDI32.304] Assignes dimensions to a bitmap
1076 BOOL32 WINAPI
SetBitmapDimensionEx32(
1077 HBITMAP32 hbitmap
, /* [in] Handle to bitmap */
1078 INT32 x
, /* [in] Bitmap width */
1079 INT32 y
, /* [in] Bitmap height */
1080 LPSIZE32 prevSize
) /* [out] Address of structure for orig dims */
1082 BITMAPOBJ
* bmp
= (BITMAPOBJ
*) GDI_GetObjPtr( hbitmap
, BITMAP_MAGIC
);
1083 if (!bmp
) return FALSE
;
1084 if (prevSize
) CONV_SIZE16TO32( &bmp
->size
, prevSize
);
1085 bmp
->size
.cx
= (INT16
)x
;
1086 bmp
->size
.cy
= (INT16
)y
;
1087 GDI_HEAP_UNLOCK( hbitmap
);
1092 /***********************************************************************
1093 * SetBitmapDimension (GDI.163)
1095 DWORD WINAPI
SetBitmapDimension( HBITMAP16 hbitmap
, INT16 x
, INT16 y
)
1098 if (!SetBitmapDimensionEx16( hbitmap
, x
, y
, &size
)) return 0;
1099 return MAKELONG( size
.cx
, size
.cy
);