Ensure that the bitmap is properly initialized when created with the
[wine/testsucceed.git] / objects / bitmap.c
blobe0cf1d1a9f9129d081b280872e44d64b575eb1e3
1 /*
2 * GDI bitmap objects
4 * Copyright 1993 Alexandre Julliard
5 * 1998 Huw D M Davies
6 */
8 #include <stdlib.h>
9 #include <string.h>
11 #include "wine/winbase16.h"
12 #include "gdi.h"
13 #include "dc.h"
14 #include "bitmap.h"
15 #include "heap.h"
16 #include "global.h"
17 #include "sysmetrics.h"
18 #include "cursoricon.h"
19 #include "debug.h"
20 #include "monitor.h"
21 #include "wine/winuser16.h"
23 BITMAP_DRIVER *BITMAP_Driver = NULL;
26 /***********************************************************************
27 * BITMAP_GetWidthBytes
29 * Return number of bytes taken by a scanline of 16-bit aligned Windows DDB
30 * data.
32 INT BITMAP_GetWidthBytes( INT bmWidth, INT bpp )
34 switch(bpp)
36 case 1:
37 return 2 * ((bmWidth+15) >> 4);
39 case 24:
40 bmWidth *= 3; /* fall through */
41 case 8:
42 return bmWidth + (bmWidth & 1);
44 case 32:
45 return bmWidth * 4;
47 case 16:
48 case 15:
49 return bmWidth * 2;
51 case 4:
52 return 2 * ((bmWidth+3) >> 2);
54 default:
55 WARN(bitmap,"Unknown depth %d, please report.\n", bpp );
57 return -1;
60 /***********************************************************************
61 * CreateUserBitmap16 (GDI.407)
63 HBITMAP16 WINAPI CreateUserBitmap16( INT16 width, INT16 height, UINT16 planes,
64 UINT16 bpp, LPCVOID bits )
66 return CreateBitmap16( width, height, planes, bpp, bits );
69 /***********************************************************************
70 * CreateUserDiscardableBitmap16 (GDI.409)
72 HBITMAP16 WINAPI CreateUserDiscardableBitmap16( WORD dummy,
73 INT16 width, INT16 height )
75 return CreateUserBitmap16( width, height, 1, MONITOR_GetDepth(&MONITOR_PrimaryMonitor), NULL );
79 /***********************************************************************
80 * CreateBitmap16 (GDI.48)
82 HBITMAP16 WINAPI CreateBitmap16( INT16 width, INT16 height, UINT16 planes,
83 UINT16 bpp, LPCVOID bits )
85 return CreateBitmap( width, height, planes, bpp, bits );
89 /******************************************************************************
90 * CreateBitmap32 [GDI32.25] Creates a bitmap with the specified info
92 * PARAMS
93 * width [I] bitmap width
94 * height [I] bitmap height
95 * planes [I] Number of color planes
96 * bpp [I] Number of bits to identify a color
97 * bits [I] Pointer to array containing color data
99 * RETURNS
100 * Success: Handle to bitmap
101 * Failure: 0
103 HBITMAP WINAPI CreateBitmap( INT width, INT height, UINT planes,
104 UINT bpp, LPCVOID bits )
106 BITMAPOBJ *bmp;
107 HBITMAP hbitmap;
109 planes = (BYTE)planes;
110 bpp = (BYTE)bpp;
113 /* Check parameters */
114 if (!height || !width) return 0;
115 if (planes != 1) {
116 FIXME(bitmap, "planes = %d\n", planes);
117 return 0;
119 if (height < 0) height = -height;
120 if (width < 0) width = -width;
122 /* Create the BITMAPOBJ */
123 hbitmap = GDI_AllocObject( sizeof(BITMAPOBJ), BITMAP_MAGIC );
124 if (!hbitmap) return 0;
126 TRACE(bitmap, "%dx%d, %d colors returning %08x\n", width, height,
127 1 << (planes*bpp), hbitmap);
129 bmp = (BITMAPOBJ *) GDI_HEAP_LOCK( hbitmap );
131 bmp->size.cx = 0;
132 bmp->size.cy = 0;
133 bmp->bitmap.bmType = 0;
134 bmp->bitmap.bmWidth = width;
135 bmp->bitmap.bmHeight = height;
136 bmp->bitmap.bmPlanes = planes;
137 bmp->bitmap.bmBitsPixel = bpp;
138 bmp->bitmap.bmWidthBytes = BITMAP_GetWidthBytes( width, bpp );
139 bmp->bitmap.bmBits = NULL;
141 bmp->DDBitmap = NULL;
142 bmp->dib = NULL;
144 if (bits) /* Set bitmap bits */
145 SetBitmapBits( hbitmap, height * bmp->bitmap.bmWidthBytes,
146 bits );
147 GDI_HEAP_UNLOCK( hbitmap );
148 return hbitmap;
152 /***********************************************************************
153 * CreateCompatibleBitmap16 (GDI.51)
155 HBITMAP16 WINAPI CreateCompatibleBitmap16(HDC16 hdc, INT16 width, INT16 height)
157 return CreateCompatibleBitmap( hdc, width, height );
161 /******************************************************************************
162 * CreateCompatibleBitmap32 [GDI32.30] Creates a bitmap compatible with the DC
164 * PARAMS
165 * hdc [I] Handle to device context
166 * width [I] Width of bitmap
167 * height [I] Height of bitmap
169 * RETURNS
170 * Success: Handle to bitmap
171 * Failure: 0
173 HBITMAP WINAPI CreateCompatibleBitmap( HDC hdc, INT width, INT height)
175 HBITMAP hbmpRet = 0;
176 DC *dc;
178 TRACE(bitmap, "(%04x,%d,%d) = \n", hdc, width, height );
179 if (!(dc = DC_GetDCPtr( hdc ))) return 0;
180 if ((width >= 0x10000) || (height >= 0x10000)) {
181 FIXME(bitmap,"got bad width %d or height %d, please look for reason\n",
182 width, height );
183 } else {
184 hbmpRet = CreateBitmap( width, height, 1, dc->w.bitsPerPixel, NULL );
185 if(dc->funcs->pCreateBitmap)
186 dc->funcs->pCreateBitmap( hbmpRet );
188 TRACE(bitmap,"\t\t%04x\n", hbmpRet);
189 GDI_HEAP_UNLOCK(hdc);
190 return hbmpRet;
194 /***********************************************************************
195 * CreateBitmapIndirect16 (GDI.49)
197 HBITMAP16 WINAPI CreateBitmapIndirect16( const BITMAP16 * bmp )
199 return CreateBitmap16( bmp->bmWidth, bmp->bmHeight, bmp->bmPlanes,
200 bmp->bmBitsPixel, PTR_SEG_TO_LIN( bmp->bmBits ) );
204 /******************************************************************************
205 * CreateBitmapIndirect32 [GDI32.26] Creates a bitmap with the specifies info
207 * RETURNS
208 * Success: Handle to bitmap
209 * Failure: NULL
211 HBITMAP WINAPI CreateBitmapIndirect(
212 const BITMAP * bmp) /* [in] Pointer to the bitmap data */
214 return CreateBitmap( bmp->bmWidth, bmp->bmHeight, bmp->bmPlanes,
215 bmp->bmBitsPixel, bmp->bmBits );
219 /***********************************************************************
220 * GetBitmapBits16 (GDI.74)
222 LONG WINAPI GetBitmapBits16( HBITMAP16 hbitmap, LONG count, LPVOID buffer )
224 return GetBitmapBits( hbitmap, count, buffer );
228 /***********************************************************************
229 * GetBitmapBits32 [GDI32.143] Copies bitmap bits of bitmap to buffer
231 * RETURNS
232 * Success: Number of bytes copied
233 * Failure: 0
235 LONG WINAPI GetBitmapBits(
236 HBITMAP hbitmap, /* [in] Handle to bitmap */
237 LONG count, /* [in] Number of bytes to copy */
238 LPVOID bits) /* [out] Pointer to buffer to receive bits */
240 BITMAPOBJ *bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC );
241 LONG height, ret;
243 if (!bmp) return 0;
245 if (count < 0) {
246 WARN(bitmap, "(%ld): Negative number of bytes passed???\n", count );
247 count = -count;
250 /* Only get entire lines */
251 height = count / bmp->bitmap.bmWidthBytes;
252 if (height > bmp->bitmap.bmHeight) height = bmp->bitmap.bmHeight;
253 count = height * bmp->bitmap.bmWidthBytes;
254 if (count == 0)
256 WARN(bitmap, "Less then one entire line requested\n");
257 GDI_HEAP_UNLOCK( hbitmap );
258 return 0;
262 TRACE(bitmap, "(%08x, %ld, %p) %dx%d %d colors fetched height: %ld\n",
263 hbitmap, count, bits, bmp->bitmap.bmWidth, bmp->bitmap.bmHeight,
264 1 << bmp->bitmap.bmBitsPixel, height );
266 if(bmp->DDBitmap) {
268 TRACE(bitmap, "Calling device specific BitmapBits\n");
269 if(bmp->DDBitmap->funcs->pBitmapBits)
270 ret = bmp->DDBitmap->funcs->pBitmapBits(hbitmap, bits, count,
271 DDB_GET);
272 else {
273 ERR(bitmap, "BitmapBits == NULL??\n");
274 ret = 0;
277 } else {
279 if(!bmp->bitmap.bmBits) {
280 WARN(bitmap, "Bitmap is empty\n");
281 ret = 0;
282 } else {
283 memcpy(bits, bmp->bitmap.bmBits, count);
284 ret = count;
289 GDI_HEAP_UNLOCK( hbitmap );
290 return ret;
294 /***********************************************************************
295 * SetBitmapBits16 (GDI.106)
297 LONG WINAPI SetBitmapBits16( HBITMAP16 hbitmap, LONG count, LPCVOID buffer )
299 return SetBitmapBits( hbitmap, count, buffer );
303 /******************************************************************************
304 * SetBitmapBits32 [GDI32.303] Sets bits of color data for a bitmap
306 * RETURNS
307 * Success: Number of bytes used in setting the bitmap bits
308 * Failure: 0
310 LONG WINAPI SetBitmapBits(
311 HBITMAP hbitmap, /* [in] Handle to bitmap */
312 LONG count, /* [in] Number of bytes in bitmap array */
313 LPCVOID bits) /* [in] Address of array with bitmap bits */
315 BITMAPOBJ *bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC );
316 LONG height, ret;
318 if (!bmp) return 0;
320 if (count < 0) {
321 WARN(bitmap, "(%ld): Negative number of bytes passed???\n", count );
322 count = -count;
325 /* Only get entire lines */
326 height = count / bmp->bitmap.bmWidthBytes;
327 if (height > bmp->bitmap.bmHeight) height = bmp->bitmap.bmHeight;
328 count = height * bmp->bitmap.bmWidthBytes;
330 TRACE(bitmap, "(%08x, %ld, %p) %dx%d %d colors fetched height: %ld\n",
331 hbitmap, count, bits, bmp->bitmap.bmWidth, bmp->bitmap.bmHeight,
332 1 << bmp->bitmap.bmBitsPixel, height );
334 if(bmp->DDBitmap) {
336 TRACE(bitmap, "Calling device specific BitmapBits\n");
337 if(bmp->DDBitmap->funcs->pBitmapBits)
338 ret = bmp->DDBitmap->funcs->pBitmapBits(hbitmap, (void *) bits,
339 count, DDB_SET);
340 else {
341 ERR(bitmap, "BitmapBits == NULL??\n");
342 ret = 0;
345 } else {
347 if(!bmp->bitmap.bmBits) /* Alloc enough for entire bitmap */
348 bmp->bitmap.bmBits = HeapAlloc( GetProcessHeap(), 0, count );
349 if(!bmp->bitmap.bmBits) {
350 WARN(bitmap, "Unable to allocate bit buffer\n");
351 ret = 0;
352 } else {
353 memcpy(bmp->bitmap.bmBits, bits, count);
354 ret = count;
358 GDI_HEAP_UNLOCK( hbitmap );
359 return ret;
362 /***********************************************************************
363 * LoadImage16 [USER.389]
366 HANDLE16 WINAPI LoadImage16( HINSTANCE16 hinst, LPCSTR name, UINT16 type,
367 INT16 desiredx, INT16 desiredy, UINT16 loadflags)
369 LPCSTR nameStr = HIWORD(name)? PTR_SEG_TO_LIN(name) : (LPCSTR)name;
370 return LoadImageA( hinst, nameStr, type,
371 desiredx, desiredy, loadflags );
374 /**********************************************************************
375 * LoadImageA (USER32.365)
377 * FIXME: implementation lacks some features, see LR_ defines in windows.h
380 HANDLE WINAPI LoadImageA( HINSTANCE hinst, LPCSTR name, UINT type,
381 INT desiredx, INT desiredy, UINT loadflags)
383 HANDLE res;
384 LPWSTR u_name;
386 if (HIWORD(name)) u_name = HEAP_strdupAtoW(GetProcessHeap(), 0, name);
387 else u_name=(LPWSTR)name;
388 res = LoadImageW(hinst, u_name, type, desiredx, desiredy, loadflags);
389 if (HIWORD(name)) HeapFree(GetProcessHeap(), 0, u_name);
390 return res;
394 /******************************************************************************
395 * LoadImageW [USER32.366] Loads an icon, cursor, or bitmap
397 * PARAMS
398 * hinst [I] Handle of instance that contains image
399 * name [I] Name of image
400 * type [I] Type of image
401 * desiredx [I] Desired width
402 * desiredy [I] Desired height
403 * loadflags [I] Load flags
405 * RETURNS
406 * Success: Handle to newly loaded image
407 * Failure: NULL
409 * FIXME: Implementation lacks some features, see LR_ defines in windows.h
411 HANDLE WINAPI LoadImageW( HINSTANCE hinst, LPCWSTR name, UINT type,
412 INT desiredx, INT desiredy, UINT loadflags )
414 if (HIWORD(name)) {
415 TRACE(resource,"(0x%04x,%p,%d,%d,%d,0x%08x)\n",
416 hinst,name,type,desiredx,desiredy,loadflags);
417 } else {
418 TRACE(resource,"(0x%04x,%p,%d,%d,%d,0x%08x)\n",
419 hinst,name,type,desiredx,desiredy,loadflags);
421 if (loadflags & LR_DEFAULTSIZE) {
422 if (type == IMAGE_ICON) {
423 if (!desiredx) desiredx = SYSMETRICS_CXICON;
424 if (!desiredy) desiredy = SYSMETRICS_CYICON;
425 } else if (type == IMAGE_CURSOR) {
426 if (!desiredx) desiredx = SYSMETRICS_CXCURSOR;
427 if (!desiredy) desiredy = SYSMETRICS_CYCURSOR;
430 if (loadflags & LR_LOADFROMFILE) loadflags &= ~LR_SHARED;
431 switch (type) {
432 case IMAGE_BITMAP:
433 return BITMAP_Load( hinst, name, loadflags );
435 case IMAGE_ICON:
437 HDC hdc = GetDC(0);
438 UINT palEnts = GetSystemPaletteEntries(hdc, 0, 0, NULL);
439 ReleaseDC(0, hdc);
441 return CURSORICON_Load(hinst, name, desiredx, desiredy,
442 MIN(16, palEnts), FALSE, loadflags);
445 case IMAGE_CURSOR:
446 return CURSORICON_Load(hinst, name, desiredx, desiredy,
447 1, TRUE, loadflags);
449 return 0;
453 /**********************************************************************
454 * BITMAP_CopyBitmap
457 HBITMAP BITMAP_CopyBitmap(HBITMAP hbitmap)
459 BITMAPOBJ *bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC );
460 HBITMAP res = 0;
461 BITMAP bm;
463 if(!bmp) return 0;
465 bm = bmp->bitmap;
466 bm.bmBits = NULL;
467 res = CreateBitmapIndirect(&bm);
469 if(res) {
470 char *buf = HeapAlloc( GetProcessHeap(), 0, bm.bmWidthBytes *
471 bm.bmHeight );
472 GetBitmapBits (hbitmap, bm.bmWidthBytes * bm.bmHeight, buf);
473 SetBitmapBits (res, bm.bmWidthBytes * bm.bmHeight, buf);
474 HeapFree( GetProcessHeap(), 0, buf );
477 GDI_HEAP_UNLOCK( hbitmap );
478 return res;
481 /******************************************************************************
482 * CopyImage16 [USER.390] Creates new image and copies attributes to it
485 HICON16 WINAPI CopyImage16( HANDLE16 hnd, UINT16 type, INT16 desiredx,
486 INT16 desiredy, UINT16 flags )
488 return (HICON16)CopyImage((HANDLE)hnd, (UINT)type, (INT)desiredx,
489 (INT)desiredy, (UINT)flags);
492 /******************************************************************************
493 * CopyImage32 [USER32.61] Creates new image and copies attributes to it
495 * PARAMS
496 * hnd [I] Handle to image to copy
497 * type [I] Type of image to copy
498 * desiredx [I] Desired width of new image
499 * desiredy [I] Desired height of new image
500 * flags [I] Copy flags
502 * RETURNS
503 * Success: Handle to newly created image
504 * Failure: NULL
506 * FIXME: implementation still lacks nearly all features, see LR_*
507 * defines in windows.h
509 HICON WINAPI CopyImage( HANDLE hnd, UINT type, INT desiredx,
510 INT desiredy, UINT flags )
512 switch (type)
514 case IMAGE_BITMAP:
515 return BITMAP_CopyBitmap(hnd);
516 case IMAGE_ICON:
517 return CopyIcon(hnd);
518 case IMAGE_CURSOR:
519 return CopyCursor(hnd);
521 return 0;
524 /**********************************************************************
525 * BITMAP_Load
527 HBITMAP BITMAP_Load( HINSTANCE instance,LPCWSTR name, UINT loadflags )
529 HBITMAP hbitmap = 0;
530 HDC hdc;
531 HRSRC hRsrc;
532 HGLOBAL handle;
533 char *ptr = NULL;
534 BITMAPINFO *info, *fix_info=NULL;
535 HGLOBAL hFix;
536 int size;
538 if (!(loadflags & LR_LOADFROMFILE)) {
539 if (!instance) /* OEM bitmap */
541 HDC hdc;
542 DC *dc;
544 if (HIWORD((int)name)) return 0;
545 hdc = CreateDCA( "DISPLAY", NULL, NULL, NULL );
546 dc = DC_GetDCPtr( hdc );
547 if(dc->funcs->pLoadOEMResource)
548 hbitmap = dc->funcs->pLoadOEMResource( LOWORD((int)name),
549 OEM_BITMAP );
550 GDI_HEAP_UNLOCK( hdc );
551 DeleteDC( hdc );
552 return hbitmap;
555 if (!(hRsrc = FindResourceW( instance, name, RT_BITMAPW ))) return 0;
556 if (!(handle = LoadResource( instance, hRsrc ))) return 0;
558 if ((info = (BITMAPINFO *)LockResource( handle )) == NULL) return 0;
560 else
562 if (!(ptr = (char *)VIRTUAL_MapFileW( name ))) return 0;
563 info = (BITMAPINFO *)(ptr + sizeof(BITMAPFILEHEADER));
565 size = DIB_BitmapInfoSize(info, DIB_RGB_COLORS);
566 if ((hFix = GlobalAlloc(0, size))) fix_info=GlobalLock(hFix);
567 if (fix_info) {
568 BYTE pix;
570 memcpy(fix_info, info, size);
571 pix = *((LPBYTE)info+DIB_BitmapInfoSize(info, DIB_RGB_COLORS));
572 DIB_FixColorsToLoadflags(fix_info, loadflags, pix);
573 if ((hdc = GetDC(0)) != 0) {
574 char *bits = (char *)info + size;
575 if (loadflags & LR_CREATEDIBSECTION) {
576 DIBSECTION dib;
577 hbitmap = CreateDIBSection(hdc, fix_info, DIB_RGB_COLORS, NULL, 0, 0);
578 GetObjectA(hbitmap, sizeof(DIBSECTION), &dib);
579 SetDIBits(hdc, hbitmap, 0, dib.dsBm.bmHeight, bits, info,
580 DIB_RGB_COLORS);
582 else {
583 hbitmap = CreateDIBitmap( hdc, &fix_info->bmiHeader, CBM_INIT,
584 bits, fix_info, DIB_RGB_COLORS );
586 ReleaseDC( 0, hdc );
588 GlobalUnlock(hFix);
589 GlobalFree(hFix);
591 if (loadflags & LR_LOADFROMFILE) UnmapViewOfFile( ptr );
592 return hbitmap;
596 /******************************************************************************
597 * LoadBitmapW [USER32.358] Loads bitmap from the executable file
599 * RETURNS
600 * Success: Handle to specified bitmap
601 * Failure: NULL
603 HBITMAP WINAPI LoadBitmapW(
604 HINSTANCE instance, /* [in] Handle to application instance */
605 LPCWSTR name) /* [in] Address of bitmap resource name */
607 return LoadImageW( instance, name, IMAGE_BITMAP, 0, 0, 0 );
610 /**********************************************************************
611 * LoadBitmapA (USER32.357)
613 HBITMAP WINAPI LoadBitmapA( HINSTANCE instance, LPCSTR name )
615 return LoadImageA( instance, name, IMAGE_BITMAP, 0, 0, 0 );
618 /**********************************************************************
619 * LoadBitmap16 (USER.175)
621 HBITMAP16 WINAPI LoadBitmap16( HINSTANCE16 instance, SEGPTR name )
623 LPCSTR nameStr = HIWORD(name)? PTR_SEG_TO_LIN(name) : (LPCSTR)name;
624 return LoadBitmapA( instance, nameStr );
629 /***********************************************************************
630 * BITMAP_DeleteObject
632 BOOL BITMAP_DeleteObject( HBITMAP16 hbitmap, BITMAPOBJ * bmp )
634 if( bmp->DDBitmap ) {
635 if( bmp->DDBitmap->funcs->pDeleteObject )
636 bmp->DDBitmap->funcs->pDeleteObject( hbitmap );
639 if( bmp->bitmap.bmBits )
640 HeapFree( GetProcessHeap(), 0, bmp->bitmap.bmBits );
642 DIB_DeleteDIBSection( bmp );
644 return GDI_FreeObject( hbitmap );
648 /***********************************************************************
649 * BITMAP_GetObject16
651 INT16 BITMAP_GetObject16( BITMAPOBJ * bmp, INT16 count, LPVOID buffer )
653 if (bmp->dib)
655 if ( count <= sizeof(BITMAP16) )
657 BITMAP *bmp32 = &bmp->dib->dsBm;
658 BITMAP16 bmp16;
659 bmp16.bmType = bmp32->bmType;
660 bmp16.bmWidth = bmp32->bmWidth;
661 bmp16.bmHeight = bmp32->bmHeight;
662 bmp16.bmWidthBytes = bmp32->bmWidthBytes;
663 bmp16.bmPlanes = bmp32->bmPlanes;
664 bmp16.bmBitsPixel = bmp32->bmBitsPixel;
665 bmp16.bmBits = (SEGPTR)0;
666 memcpy( buffer, &bmp16, count );
667 return count;
669 else
671 FIXME(bitmap, "not implemented for DIBs: count %d\n", count);
672 return 0;
675 else
677 BITMAP16 bmp16;
678 bmp16.bmType = bmp->bitmap.bmType;
679 bmp16.bmWidth = bmp->bitmap.bmWidth;
680 bmp16.bmHeight = bmp->bitmap.bmHeight;
681 bmp16.bmWidthBytes = bmp->bitmap.bmWidthBytes;
682 bmp16.bmPlanes = bmp->bitmap.bmPlanes;
683 bmp16.bmBitsPixel = bmp->bitmap.bmBitsPixel;
684 bmp16.bmBits = (SEGPTR)0;
685 if (count > sizeof(bmp16)) count = sizeof(bmp16);
686 memcpy( buffer, &bmp16, count );
687 return count;
692 /***********************************************************************
693 * BITMAP_GetObject32
695 INT BITMAP_GetObject( BITMAPOBJ * bmp, INT count, LPVOID buffer )
697 if (bmp->dib)
699 if (count < sizeof(DIBSECTION))
701 if (count > sizeof(BITMAP)) count = sizeof(BITMAP);
703 else
705 if (count > sizeof(DIBSECTION)) count = sizeof(DIBSECTION);
708 memcpy( buffer, bmp->dib, count );
709 return count;
711 else
713 if (count > sizeof(BITMAP)) count = sizeof(BITMAP);
714 memcpy( buffer, &bmp->bitmap, count );
715 return count;
720 /***********************************************************************
721 * CreateDiscardableBitmap16 (GDI.156)
723 HBITMAP16 WINAPI CreateDiscardableBitmap16( HDC16 hdc, INT16 width,
724 INT16 height )
726 return CreateCompatibleBitmap16( hdc, width, height );
730 /******************************************************************************
731 * CreateDiscardableBitmap32 [GDI32.38] Creates a discardable bitmap
733 * RETURNS
734 * Success: Handle to bitmap
735 * Failure: NULL
737 HBITMAP WINAPI CreateDiscardableBitmap(
738 HDC hdc, /* [in] Handle to device context */
739 INT width, /* [in] Bitmap width */
740 INT height) /* [in] Bitmap height */
742 return CreateCompatibleBitmap( hdc, width, height );
746 /***********************************************************************
747 * GetBitmapDimensionEx16 (GDI.468)
749 * NOTES
750 * Can this call GetBitmapDimensionEx32?
752 BOOL16 WINAPI GetBitmapDimensionEx16( HBITMAP16 hbitmap, LPSIZE16 size )
754 BITMAPOBJ * bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC );
755 if (!bmp) return FALSE;
756 CONV_SIZE32TO16( &bmp->size, size );
757 GDI_HEAP_UNLOCK( hbitmap );
758 return TRUE;
762 /******************************************************************************
763 * GetBitmapDimensionEx32 [GDI32.144] Retrieves dimensions of a bitmap
765 * RETURNS
766 * Success: TRUE
767 * Failure: FALSE
769 BOOL WINAPI GetBitmapDimensionEx(
770 HBITMAP hbitmap, /* [in] Handle to bitmap */
771 LPSIZE size) /* [out] Address of struct receiving dimensions */
773 BITMAPOBJ * bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC );
774 if (!bmp) return FALSE;
775 *size = bmp->size;
776 GDI_HEAP_UNLOCK( hbitmap );
777 return TRUE;
781 /***********************************************************************
782 * GetBitmapDimension (GDI.162)
784 DWORD WINAPI GetBitmapDimension16( HBITMAP16 hbitmap )
786 SIZE16 size;
787 if (!GetBitmapDimensionEx16( hbitmap, &size )) return 0;
788 return MAKELONG( size.cx, size.cy );
792 /***********************************************************************
793 * SetBitmapDimensionEx16 (GDI.478)
795 BOOL16 WINAPI SetBitmapDimensionEx16( HBITMAP16 hbitmap, INT16 x, INT16 y,
796 LPSIZE16 prevSize )
798 BITMAPOBJ * bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC );
799 if (!bmp) return FALSE;
800 if (prevSize) CONV_SIZE32TO16( &bmp->size, prevSize );
801 bmp->size.cx = x;
802 bmp->size.cy = y;
803 GDI_HEAP_UNLOCK( hbitmap );
804 return TRUE;
808 /******************************************************************************
809 * SetBitmapDimensionEx32 [GDI32.304] Assignes dimensions to a bitmap
811 * RETURNS
812 * Success: TRUE
813 * Failure: FALSE
815 BOOL WINAPI SetBitmapDimensionEx(
816 HBITMAP hbitmap, /* [in] Handle to bitmap */
817 INT x, /* [in] Bitmap width */
818 INT y, /* [in] Bitmap height */
819 LPSIZE prevSize) /* [out] Address of structure for orig dims */
821 BITMAPOBJ * bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC );
822 if (!bmp) return FALSE;
823 if (prevSize) *prevSize = bmp->size;
824 bmp->size.cx = x;
825 bmp->size.cy = y;
826 GDI_HEAP_UNLOCK( hbitmap );
827 return TRUE;
831 /***********************************************************************
832 * SetBitmapDimension (GDI.163)
834 DWORD WINAPI SetBitmapDimension16( HBITMAP16 hbitmap, INT16 x, INT16 y )
836 SIZE16 size;
837 if (!SetBitmapDimensionEx16( hbitmap, x, y, &size )) return 0;
838 return MAKELONG( size.cx, size.cy );