Implementation of VER.DLL. Thunks up to VERSION.DLL.
[wine/testsucceed.git] / objects / bitmap.c
blob335b449c04d6c06460ef87544cea336eaed5ded2
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>
10 #include "gdi.h"
11 #include "dc.h"
12 #include "bitmap.h"
13 #include "heap.h"
14 #include "global.h"
15 #include "sysmetrics.h"
16 #include "cursoricon.h"
17 #include "debug.h"
18 #include "x11drv.h"
20 /***********************************************************************
21 * BITMAP_GetPadding
23 * Return number of bytes to pad a scanline of 16-bit aligned Windows DDB data.
25 INT32 BITMAP_GetPadding( int bmWidth, int bpp )
27 INT32 pad;
29 switch (bpp)
31 case 1:
32 pad = ((bmWidth-1) & 8) ? 0 : 1;
33 break;
35 case 8:
36 pad = (2 - (bmWidth & 1)) & 1;
37 break;
39 case 24:
40 pad = (bmWidth*3) & 1;
41 break;
43 case 32:
44 case 16:
45 case 15:
46 pad = 0; /* we have 16bit alignment already */
47 break;
49 case 4:
50 if (!(bmWidth & 3)) pad = 0;
51 else pad = ((4 - (bmWidth & 3)) + 1) / 2;
52 break;
54 default:
55 WARN(bitmap,"Unknown depth %d, please report.\n", bpp );
56 return -1;
58 return pad;
61 /***********************************************************************
62 * BITMAP_GetWidthBytes
64 * Return number of bytes taken by a scanline of 16-bit aligned Windows DDB
65 * data.
67 INT32 BITMAP_GetWidthBytes( INT32 bmWidth, INT32 bpp )
69 switch(bpp)
71 case 1:
72 return 2 * ((bmWidth+15) >> 4);
74 case 24:
75 bmWidth *= 3; /* fall through */
76 case 8:
77 return bmWidth + (bmWidth & 1);
79 case 32:
80 return bmWidth * 4;
82 case 16:
83 case 15:
84 return bmWidth * 2;
86 case 4:
87 return 2 * ((bmWidth+3) >> 2);
89 default:
90 WARN(bitmap,"Unknown depth %d, please report.\n", bpp );
92 return -1;
95 /***********************************************************************
96 * CreateUserBitmap16 (GDI.407)
98 HBITMAP16 WINAPI CreateUserBitmap16( INT16 width, INT16 height, UINT16 planes,
99 UINT16 bpp, LPCVOID bits )
101 return CreateBitmap16( width, height, planes, bpp, bits );
104 /***********************************************************************
105 * CreateUserDiscardableBitmap16 (GDI.409)
107 HBITMAP16 WINAPI CreateUserDiscardableBitmap16( WORD dummy,
108 INT16 width, INT16 height )
110 return CreateUserBitmap16( width, height, 1, screenDepth, NULL );
114 /***********************************************************************
115 * CreateBitmap16 (GDI.48)
117 HBITMAP16 WINAPI CreateBitmap16( INT16 width, INT16 height, UINT16 planes,
118 UINT16 bpp, LPCVOID bits )
120 return CreateBitmap32( width, height, planes, bpp, bits );
124 /******************************************************************************
125 * CreateBitmap32 [GDI32.25] Creates a bitmap with the specified info
127 * PARAMS
128 * width [I] bitmap width
129 * height [I] bitmap height
130 * planes [I] Number of color planes
131 * bpp [I] Number of bits to identify a color
132 * bits [I] Pointer to array containing color data
134 * RETURNS
135 * Success: Handle to bitmap
136 * Failure: 0
138 HBITMAP32 WINAPI CreateBitmap32( INT32 width, INT32 height, UINT32 planes,
139 UINT32 bpp, LPCVOID bits )
141 BITMAPOBJ *bmp;
142 HBITMAP32 hbitmap;
144 planes = (BYTE)planes;
145 bpp = (BYTE)bpp;
148 /* Check parameters */
149 if (!height || !width) return 0;
150 if (planes != 1) {
151 FIXME(bitmap, "planes = %d\n", planes);
152 return 0;
154 if (height < 0) height = -height;
155 if (width < 0) width = -width;
157 /* Create the BITMAPOBJ */
158 hbitmap = GDI_AllocObject( sizeof(BITMAPOBJ), BITMAP_MAGIC );
159 if (!hbitmap) return 0;
161 TRACE(bitmap, "%dx%d, %d colors returning %08x\n", width, height,
162 1 << (planes*bpp), hbitmap);
164 bmp = (BITMAPOBJ *) GDI_HEAP_LOCK( hbitmap );
166 bmp->size.cx = 0;
167 bmp->size.cy = 0;
168 bmp->bitmap.bmType = 0;
169 bmp->bitmap.bmWidth = width;
170 bmp->bitmap.bmHeight = height;
171 bmp->bitmap.bmPlanes = planes;
172 bmp->bitmap.bmBitsPixel = bpp;
173 bmp->bitmap.bmWidthBytes = BITMAP_GetWidthBytes( width, bpp );
174 bmp->bitmap.bmBits = NULL;
176 bmp->DDBitmap = NULL;
177 bmp->dib = NULL;
179 if (bits) /* Set bitmap bits */
180 SetBitmapBits32( hbitmap, height * bmp->bitmap.bmWidthBytes,
181 bits );
182 GDI_HEAP_UNLOCK( hbitmap );
183 return hbitmap;
187 /***********************************************************************
188 * CreateCompatibleBitmap16 (GDI.51)
190 HBITMAP16 WINAPI CreateCompatibleBitmap16(HDC16 hdc, INT16 width, INT16 height)
192 return CreateCompatibleBitmap32( hdc, width, height );
196 /******************************************************************************
197 * CreateCompatibleBitmap32 [GDI32.30] Creates a bitmap compatible with the DC
199 * PARAMS
200 * hdc [I] Handle to device context
201 * width [I] Width of bitmap
202 * height [I] Height of bitmap
204 * RETURNS
205 * Success: Handle to bitmap
206 * Failure: 0
208 HBITMAP32 WINAPI CreateCompatibleBitmap32( HDC32 hdc, INT32 width, INT32 height)
210 HBITMAP32 hbmpRet = 0;
211 DC *dc;
213 TRACE(bitmap, "(%04x,%d,%d) = \n", hdc, width, height );
214 if (!(dc = DC_GetDCPtr( hdc ))) return 0;
215 if ((width >= 0x10000) || (height >= 0x10000)) {
216 FIXME(bitmap,"got bad width %d or height %d, please look for reason\n",
217 width, height );
218 } else {
219 hbmpRet = CreateBitmap32( width, height, 1, dc->w.bitsPerPixel, NULL );
220 if(dc->funcs->pCreateBitmap)
221 dc->funcs->pCreateBitmap( hbmpRet );
223 TRACE(bitmap,"\t\t%04x\n", hbmpRet);
224 GDI_HEAP_UNLOCK(hdc);
225 return hbmpRet;
229 /***********************************************************************
230 * CreateBitmapIndirect16 (GDI.49)
232 HBITMAP16 WINAPI CreateBitmapIndirect16( const BITMAP16 * bmp )
234 return CreateBitmap16( bmp->bmWidth, bmp->bmHeight, bmp->bmPlanes,
235 bmp->bmBitsPixel, PTR_SEG_TO_LIN( bmp->bmBits ) );
239 /******************************************************************************
240 * CreateBitmapIndirect32 [GDI32.26] Creates a bitmap with the specifies info
242 * RETURNS
243 * Success: Handle to bitmap
244 * Failure: NULL
246 HBITMAP32 WINAPI CreateBitmapIndirect32(
247 const BITMAP32 * bmp) /* [in] Pointer to the bitmap data */
249 return CreateBitmap32( bmp->bmWidth, bmp->bmHeight, bmp->bmPlanes,
250 bmp->bmBitsPixel, bmp->bmBits );
254 /***********************************************************************
255 * GetBitmapBits16 (GDI.74)
257 LONG WINAPI GetBitmapBits16( HBITMAP16 hbitmap, LONG count, LPVOID buffer )
259 return GetBitmapBits32( hbitmap, count, buffer );
263 /***********************************************************************
264 * GetBitmapBits32 [GDI32.143] Copies bitmap bits of bitmap to buffer
266 * RETURNS
267 * Success: Number of bytes copied
268 * Failure: 0
270 LONG WINAPI GetBitmapBits32(
271 HBITMAP32 hbitmap, /* [in] Handle to bitmap */
272 LONG count, /* [in] Number of bytes to copy */
273 LPVOID bits) /* [out] Pointer to buffer to receive bits */
275 BITMAPOBJ *bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC );
276 LONG height, ret;
278 if (!bmp) return 0;
280 if (count < 0) {
281 WARN(bitmap, "(%ld): Negative number of bytes passed???\n", count );
282 count = -count;
285 /* Only get entire lines */
286 height = count / bmp->bitmap.bmWidthBytes;
287 if (height > bmp->bitmap.bmHeight) height = bmp->bitmap.bmHeight;
288 count = height * bmp->bitmap.bmWidthBytes;
289 if (count == 0)
291 WARN(bitmap, "Less then one entire line requested\n");
292 GDI_HEAP_UNLOCK( hbitmap );
293 return 0;
297 TRACE(bitmap, "(%08x, %ld, %p) %dx%d %d colors fetched height: %ld\n",
298 hbitmap, count, bits, bmp->bitmap.bmWidth, bmp->bitmap.bmHeight,
299 1 << bmp->bitmap.bmBitsPixel, height );
301 if(bmp->DDBitmap) {
303 TRACE(bitmap, "Calling device specific BitmapBits\n");
304 if(bmp->DDBitmap->funcs->pBitmapBits)
305 ret = bmp->DDBitmap->funcs->pBitmapBits(hbitmap, bits, count,
306 DDB_GET);
307 else {
308 ERR(bitmap, "BitmapBits == NULL??\n");
309 ret = 0;
312 } else {
314 if(!bmp->bitmap.bmBits) {
315 WARN(bitmap, "Bitmap is empty\n");
316 ret = 0;
317 } else {
318 memcpy(bits, bmp->bitmap.bmBits, count);
319 ret = count;
324 GDI_HEAP_UNLOCK( hbitmap );
325 return ret;
329 /***********************************************************************
330 * SetBitmapBits16 (GDI.106)
332 LONG WINAPI SetBitmapBits16( HBITMAP16 hbitmap, LONG count, LPCVOID buffer )
334 return SetBitmapBits32( hbitmap, count, buffer );
338 /******************************************************************************
339 * SetBitmapBits32 [GDI32.303] Sets bits of color data for a bitmap
341 * RETURNS
342 * Success: Number of bytes used in setting the bitmap bits
343 * Failure: 0
345 LONG WINAPI SetBitmapBits32(
346 HBITMAP32 hbitmap, /* [in] Handle to bitmap */
347 LONG count, /* [in] Number of bytes in bitmap array */
348 LPCVOID bits) /* [in] Address of array with bitmap bits */
350 BITMAPOBJ *bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC );
351 LONG height, ret;
353 if (!bmp) return 0;
355 if (count < 0) {
356 WARN(bitmap, "(%ld): Negative number of bytes passed???\n", count );
357 count = -count;
360 /* Only get entire lines */
361 height = count / bmp->bitmap.bmWidthBytes;
362 if (height > bmp->bitmap.bmHeight) height = bmp->bitmap.bmHeight;
363 count = height * bmp->bitmap.bmWidthBytes;
365 TRACE(bitmap, "(%08x, %ld, %p) %dx%d %d colors fetched height: %ld\n",
366 hbitmap, count, bits, bmp->bitmap.bmWidth, bmp->bitmap.bmHeight,
367 1 << bmp->bitmap.bmBitsPixel, height );
369 if(bmp->DDBitmap) {
371 TRACE(bitmap, "Calling device specific BitmapBits\n");
372 if(bmp->DDBitmap->funcs->pBitmapBits)
373 ret = bmp->DDBitmap->funcs->pBitmapBits(hbitmap, (void *) bits,
374 count, DDB_SET);
375 else {
376 ERR(bitmap, "BitmapBits == NULL??\n");
377 ret = 0;
380 } else {
382 if(!bmp->bitmap.bmBits) /* Alloc enough for entire bitmap */
383 bmp->bitmap.bmBits = HeapAlloc( GetProcessHeap(), 0, count );
384 if(!bmp->bitmap.bmBits) {
385 WARN(bitmap, "Unable to allocate bit buffer\n");
386 ret = 0;
387 } else {
388 memcpy(bmp->bitmap.bmBits, bits, count);
389 ret = count;
393 GDI_HEAP_UNLOCK( hbitmap );
394 return ret;
397 /***********************************************************************
398 * LoadImage16 [USER.389]
401 HANDLE16 WINAPI LoadImage16( HINSTANCE16 hinst, LPCSTR name, UINT16 type,
402 INT16 desiredx, INT16 desiredy, UINT16 loadflags)
404 if (HIWORD(name)) {
405 TRACE(resource,"(0x%04x,%s,%d,%d,%d,0x%08x)\n",
406 hinst,(char *)PTR_SEG_TO_LIN(name),type,desiredx,desiredy,loadflags);
407 } else {
408 TRACE(resource,"LoadImage16(0x%04x,%p,%d,%d,%d,0x%08x)\n",
409 hinst,name,type,desiredx,desiredy,loadflags);
411 switch (type) {
412 case IMAGE_BITMAP:
413 return LoadBitmap16(hinst,(SEGPTR)name);
414 case IMAGE_ICON:
415 return LoadIcon16(hinst,(SEGPTR)name);
416 case IMAGE_CURSOR:
417 return LoadCursor16(hinst,(SEGPTR)name);
419 return 0;
423 /**********************************************************************
424 * LoadImage32A (USER32.365)
426 * FIXME: implementation lacks some features, see LR_ defines in windows.h
429 HANDLE32 WINAPI LoadImage32A( HINSTANCE32 hinst, LPCSTR name, UINT32 type,
430 INT32 desiredx, INT32 desiredy, UINT32 loadflags)
432 HANDLE32 res;
433 LPWSTR u_name;
435 if (HIWORD(name)) u_name = HEAP_strdupAtoW(GetProcessHeap(), 0, name);
436 else u_name=(LPWSTR)name;
437 res = LoadImage32W(hinst, u_name, type, desiredx, desiredy, loadflags);
438 if (HIWORD(name)) HeapFree(GetProcessHeap(), 0, u_name);
439 return res;
443 /******************************************************************************
444 * LoadImage32W [USER32.366] Loads an icon, cursor, or bitmap
446 * PARAMS
447 * hinst [I] Handle of instance that contains image
448 * name [I] Name of image
449 * type [I] Type of image
450 * desiredx [I] Desired width
451 * desiredy [I] Desired height
452 * loadflags [I] Load flags
454 * RETURNS
455 * Success: Handle to newly loaded image
456 * Failure: NULL
458 * FIXME: Implementation lacks some features, see LR_ defines in windows.h
460 HANDLE32 WINAPI LoadImage32W( HINSTANCE32 hinst, LPCWSTR name, UINT32 type,
461 INT32 desiredx, INT32 desiredy, UINT32 loadflags )
463 if (HIWORD(name)) {
464 TRACE(resource,"(0x%04x,%p,%d,%d,%d,0x%08x)\n",
465 hinst,name,type,desiredx,desiredy,loadflags);
466 } else {
467 TRACE(resource,"(0x%04x,%p,%d,%d,%d,0x%08x)\n",
468 hinst,name,type,desiredx,desiredy,loadflags);
470 if (loadflags & LR_DEFAULTSIZE) {
471 if (type == IMAGE_ICON) {
472 if (!desiredx) desiredx = SYSMETRICS_CXICON;
473 if (!desiredy) desiredy = SYSMETRICS_CYICON;
474 } else if (type == IMAGE_CURSOR) {
475 if (!desiredx) desiredx = SYSMETRICS_CXCURSOR;
476 if (!desiredy) desiredy = SYSMETRICS_CYCURSOR;
479 if (loadflags & LR_LOADFROMFILE) loadflags &= ~LR_SHARED;
480 switch (type) {
481 case IMAGE_BITMAP:
482 return BITMAP_LoadBitmap32W(hinst, name, loadflags);
484 case IMAGE_ICON:
486 HDC32 hdc = GetDC32(0);
487 UINT32 palEnts = GetSystemPaletteEntries32(hdc, 0, 0, NULL);
488 ReleaseDC32(0, hdc);
490 return CURSORICON_Load32(hinst, name, desiredx, desiredy,
491 MIN(16, palEnts), FALSE, loadflags);
494 case IMAGE_CURSOR:
495 return CURSORICON_Load32(hinst, name, desiredx, desiredy,
496 1, TRUE, loadflags);
498 return 0;
502 /**********************************************************************
503 * BITMAP_CopyBitmap
506 HBITMAP32 BITMAP_CopyBitmap(HBITMAP32 hbitmap)
508 BITMAPOBJ *bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC );
509 HBITMAP32 res = 0;
510 BITMAP32 bm;
512 if(!bmp) return 0;
514 bm = bmp->bitmap;
515 bm.bmBits = NULL;
516 res = CreateBitmapIndirect32(&bm);
518 if(res) {
519 char *buf = HeapAlloc( GetProcessHeap(), 0, bm.bmWidthBytes *
520 bm.bmHeight );
521 GetBitmapBits32 (hbitmap, bm.bmWidthBytes * bm.bmHeight, buf);
522 SetBitmapBits32 (res, bm.bmWidthBytes * bm.bmHeight, buf);
523 HeapFree( GetProcessHeap(), 0, buf );
526 GDI_HEAP_UNLOCK( hbitmap );
527 return res;
530 /******************************************************************************
531 * CopyImage16 [USER.390] Creates new image and copies attributes to it
534 HICON16 WINAPI CopyImage16( HANDLE16 hnd, UINT16 type, INT16 desiredx,
535 INT16 desiredy, UINT16 flags )
537 return (HICON16)CopyImage32((HANDLE32)hnd, (UINT32)type, (INT32)desiredx,
538 (INT32)desiredy, (UINT32)flags);
541 /******************************************************************************
542 * CopyImage32 [USER32.61] Creates new image and copies attributes to it
544 * PARAMS
545 * hnd [I] Handle to image to copy
546 * type [I] Type of image to copy
547 * desiredx [I] Desired width of new image
548 * desiredy [I] Desired height of new image
549 * flags [I] Copy flags
551 * RETURNS
552 * Success: Handle to newly created image
553 * Failure: NULL
555 * FIXME: implementation still lacks nearly all features, see LR_*
556 * defines in windows.h
558 HICON32 WINAPI CopyImage32( HANDLE32 hnd, UINT32 type, INT32 desiredx,
559 INT32 desiredy, UINT32 flags )
561 switch (type)
563 case IMAGE_BITMAP:
564 return BITMAP_CopyBitmap(hnd);
565 case IMAGE_ICON:
566 return CopyIcon32(hnd);
567 case IMAGE_CURSOR:
568 return CopyCursor32(hnd);
570 return 0;
573 /**********************************************************************
574 * LoadBitmap16 (USER.175)
576 * NOTES
577 * Can this call LoadBitmap32?
579 HBITMAP16 WINAPI LoadBitmap16( HINSTANCE16 instance, SEGPTR name )
581 HBITMAP32 hbitmap = 0;
582 HDC32 hdc;
583 HRSRC16 hRsrc;
584 HGLOBAL16 handle;
585 BITMAPINFO *info;
587 if (HIWORD(name))
589 char *str = (char *)PTR_SEG_TO_LIN( name );
590 TRACE(bitmap, "(%04x,'%s')\n", instance, str );
591 if (str[0] == '#') name = (SEGPTR)(DWORD)(WORD)atoi( str + 1 );
593 else
594 TRACE(bitmap, "(%04x,%04x)\n",
595 instance, LOWORD(name) );
597 if (!instance) /* OEM bitmap */
599 HDC32 hdc;
600 DC *dc;
602 if (HIWORD((int)name)) return 0;
603 hdc = CreateDC32A( "DISPLAY", NULL, NULL, NULL );
604 dc = DC_GetDCPtr( hdc );
605 if(dc->funcs->pLoadOEMResource)
606 hbitmap = dc->funcs->pLoadOEMResource( LOWORD((int)name),
607 OEM_BITMAP );
608 GDI_HEAP_UNLOCK( hdc );
609 DeleteDC32( hdc );
610 return hbitmap;
613 if (!(hRsrc = FindResource16( instance, name, RT_BITMAP16 ))) return 0;
614 if (!(handle = LoadResource16( instance, hRsrc ))) return 0;
616 info = (BITMAPINFO *)LockResource16( handle );
617 if ((hdc = GetDC32(0)) != 0)
619 char *bits = (char *)info + DIB_BitmapInfoSize( info, DIB_RGB_COLORS );
620 hbitmap = CreateDIBitmap32( hdc, &info->bmiHeader, CBM_INIT,
621 bits, info, DIB_RGB_COLORS );
622 ReleaseDC32( 0, hdc );
624 FreeResource16( handle );
625 return hbitmap;
629 /**********************************************************************
630 * BITMAP_LoadBitmap32W
632 HBITMAP32 BITMAP_LoadBitmap32W(HINSTANCE32 instance,LPCWSTR name,
633 UINT32 loadflags)
635 HBITMAP32 hbitmap = 0;
636 HDC32 hdc;
637 HRSRC32 hRsrc;
638 HGLOBAL32 handle;
639 char *ptr = NULL;
640 BITMAPINFO *info, *fix_info=NULL;
641 HGLOBAL32 hFix;
642 int size;
644 if (!(loadflags & LR_LOADFROMFILE)) {
645 if (!instance) /* OEM bitmap */
647 HDC32 hdc;
648 DC *dc;
650 if (HIWORD((int)name)) return 0;
651 hdc = CreateDC32A( "DISPLAY", NULL, NULL, NULL );
652 dc = DC_GetDCPtr( hdc );
653 if(dc->funcs->pLoadOEMResource)
654 hbitmap = dc->funcs->pLoadOEMResource( LOWORD((int)name),
655 OEM_BITMAP );
656 GDI_HEAP_UNLOCK( hdc );
657 DeleteDC32( hdc );
658 return hbitmap;
661 if (!(hRsrc = FindResource32W( instance, name, RT_BITMAP32W ))) return 0;
662 if (!(handle = LoadResource32( instance, hRsrc ))) return 0;
664 if ((info = (BITMAPINFO *)LockResource32( handle )) == NULL) return 0;
666 else
668 if (!(ptr = (char *)VIRTUAL_MapFileW( name ))) return 0;
669 info = (BITMAPINFO *)(ptr + sizeof(BITMAPFILEHEADER));
671 size = DIB_BitmapInfoSize(info, DIB_RGB_COLORS);
672 if ((hFix = GlobalAlloc32(0, size))) fix_info=GlobalLock32(hFix);
673 if (fix_info) {
674 BYTE pix;
676 memcpy(fix_info, info, size);
677 pix = *((LPBYTE)info+DIB_BitmapInfoSize(info, DIB_RGB_COLORS));
678 DIB_FixColorsToLoadflags(fix_info, loadflags, pix);
679 if ((hdc = GetDC32(0)) != 0) {
680 if (loadflags & LR_CREATEDIBSECTION)
681 hbitmap = CreateDIBSection32(hdc, fix_info, DIB_RGB_COLORS, NULL, 0, 0);
682 else {
683 char *bits = (char *)info + size;;
684 hbitmap = CreateDIBitmap32( hdc, &fix_info->bmiHeader, CBM_INIT,
685 bits, fix_info, DIB_RGB_COLORS );
687 ReleaseDC32( 0, hdc );
689 GlobalUnlock32(hFix);
690 GlobalFree32(hFix);
692 if (loadflags & LR_LOADFROMFILE) UnmapViewOfFile( ptr );
693 return hbitmap;
697 /******************************************************************************
698 * LoadBitmap32W [USER32.358] Loads bitmap from the executable file
700 * RETURNS
701 * Success: Handle to specified bitmap
702 * Failure: NULL
704 HBITMAP32 WINAPI LoadBitmap32W(
705 HINSTANCE32 instance, /* [in] Handle to application instance */
706 LPCWSTR name) /* [in] Address of bitmap resource name */
708 return BITMAP_LoadBitmap32W(instance, name, 0);
712 /**********************************************************************
713 * LoadBitmap32A (USER32.357)
715 HBITMAP32 WINAPI LoadBitmap32A( HINSTANCE32 instance, LPCSTR name )
717 HBITMAP32 res;
718 if (!HIWORD(name)) res = LoadBitmap32W( instance, (LPWSTR)name );
719 else
721 LPWSTR uni = HEAP_strdupAtoW( GetProcessHeap(), 0, name );
722 res = LoadBitmap32W( instance, uni );
723 HeapFree( GetProcessHeap(), 0, uni );
725 return res;
729 /***********************************************************************
730 * BITMAP_DeleteObject
732 BOOL32 BITMAP_DeleteObject( HBITMAP16 hbitmap, BITMAPOBJ * bmp )
734 if( bmp->DDBitmap ) {
735 if( bmp->DDBitmap->funcs->pDeleteObject )
736 bmp->DDBitmap->funcs->pDeleteObject( hbitmap );
739 if( bmp->bitmap.bmBits )
740 HeapFree( GetProcessHeap(), 0, bmp->bitmap.bmBits );
742 DIB_DeleteDIBSection( bmp );
744 return GDI_FreeObject( hbitmap );
748 /***********************************************************************
749 * BITMAP_GetObject16
751 INT16 BITMAP_GetObject16( BITMAPOBJ * bmp, INT16 count, LPVOID buffer )
753 if (bmp->dib)
755 if ( count <= sizeof(BITMAP16) )
757 BITMAP32 *bmp32 = &bmp->dib->dibSection.dsBm;
758 BITMAP16 bmp16;
759 bmp16.bmType = bmp32->bmType;
760 bmp16.bmWidth = bmp32->bmWidth;
761 bmp16.bmHeight = bmp32->bmHeight;
762 bmp16.bmWidthBytes = bmp32->bmWidthBytes;
763 bmp16.bmPlanes = bmp32->bmPlanes;
764 bmp16.bmBitsPixel = bmp32->bmBitsPixel;
765 bmp16.bmBits = (SEGPTR)0;
766 memcpy( buffer, &bmp16, count );
767 return count;
769 else
771 FIXME(bitmap, "not implemented for DIBs: count %d\n", count);
772 return 0;
775 else
777 BITMAP16 bmp16;
778 bmp16.bmType = bmp->bitmap.bmType;
779 bmp16.bmWidth = bmp->bitmap.bmWidth;
780 bmp16.bmHeight = bmp->bitmap.bmHeight;
781 bmp16.bmWidthBytes = bmp->bitmap.bmWidthBytes;
782 bmp16.bmPlanes = bmp->bitmap.bmPlanes;
783 bmp16.bmBitsPixel = bmp->bitmap.bmBitsPixel;
784 bmp16.bmBits = (SEGPTR)0;
785 if (count > sizeof(bmp16)) count = sizeof(bmp16);
786 memcpy( buffer, &bmp16, count );
787 return count;
792 /***********************************************************************
793 * BITMAP_GetObject32
795 INT32 BITMAP_GetObject32( BITMAPOBJ * bmp, INT32 count, LPVOID buffer )
797 if (bmp->dib)
799 if (count < sizeof(DIBSECTION))
801 if (count > sizeof(BITMAP32)) count = sizeof(BITMAP32);
803 else
805 if (count > sizeof(DIBSECTION)) count = sizeof(DIBSECTION);
808 memcpy( buffer, &bmp->dib->dibSection, count );
809 return count;
811 else
813 if (count > sizeof(BITMAP32)) count = sizeof(BITMAP32);
814 memcpy( buffer, &bmp->bitmap, count );
815 return count;
820 /***********************************************************************
821 * CreateDiscardableBitmap16 (GDI.156)
823 HBITMAP16 WINAPI CreateDiscardableBitmap16( HDC16 hdc, INT16 width,
824 INT16 height )
826 return CreateCompatibleBitmap16( hdc, width, height );
830 /******************************************************************************
831 * CreateDiscardableBitmap32 [GDI32.38] Creates a discardable bitmap
833 * RETURNS
834 * Success: Handle to bitmap
835 * Failure: NULL
837 HBITMAP32 WINAPI CreateDiscardableBitmap32(
838 HDC32 hdc, /* [in] Handle to device context */
839 INT32 width, /* [in] Bitmap width */
840 INT32 height) /* [in] Bitmap height */
842 return CreateCompatibleBitmap32( hdc, width, height );
846 /***********************************************************************
847 * GetBitmapDimensionEx16 (GDI.468)
849 * NOTES
850 * Can this call GetBitmapDimensionEx32?
852 BOOL16 WINAPI GetBitmapDimensionEx16( HBITMAP16 hbitmap, LPSIZE16 size )
854 BITMAPOBJ * bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC );
855 if (!bmp) return FALSE;
856 CONV_SIZE32TO16( &bmp->size, size );
857 GDI_HEAP_UNLOCK( hbitmap );
858 return TRUE;
862 /******************************************************************************
863 * GetBitmapDimensionEx32 [GDI32.144] Retrieves dimensions of a bitmap
865 * RETURNS
866 * Success: TRUE
867 * Failure: FALSE
869 BOOL32 WINAPI GetBitmapDimensionEx32(
870 HBITMAP32 hbitmap, /* [in] Handle to bitmap */
871 LPSIZE32 size) /* [out] Address of struct receiving dimensions */
873 BITMAPOBJ * bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC );
874 if (!bmp) return FALSE;
875 *size = bmp->size;
876 GDI_HEAP_UNLOCK( hbitmap );
877 return TRUE;
881 /***********************************************************************
882 * GetBitmapDimension (GDI.162)
884 DWORD WINAPI GetBitmapDimension( HBITMAP16 hbitmap )
886 SIZE16 size;
887 if (!GetBitmapDimensionEx16( hbitmap, &size )) return 0;
888 return MAKELONG( size.cx, size.cy );
892 /***********************************************************************
893 * SetBitmapDimensionEx16 (GDI.478)
895 BOOL16 WINAPI SetBitmapDimensionEx16( HBITMAP16 hbitmap, INT16 x, INT16 y,
896 LPSIZE16 prevSize )
898 BITMAPOBJ * bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC );
899 if (!bmp) return FALSE;
900 if (prevSize) CONV_SIZE32TO16( &bmp->size, prevSize );
901 bmp->size.cx = x;
902 bmp->size.cy = y;
903 GDI_HEAP_UNLOCK( hbitmap );
904 return TRUE;
908 /******************************************************************************
909 * SetBitmapDimensionEx32 [GDI32.304] Assignes dimensions to a bitmap
911 * RETURNS
912 * Success: TRUE
913 * Failure: FALSE
915 BOOL32 WINAPI SetBitmapDimensionEx32(
916 HBITMAP32 hbitmap, /* [in] Handle to bitmap */
917 INT32 x, /* [in] Bitmap width */
918 INT32 y, /* [in] Bitmap height */
919 LPSIZE32 prevSize) /* [out] Address of structure for orig dims */
921 BITMAPOBJ * bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC );
922 if (!bmp) return FALSE;
923 if (prevSize) *prevSize = bmp->size;
924 bmp->size.cx = x;
925 bmp->size.cy = y;
926 GDI_HEAP_UNLOCK( hbitmap );
927 return TRUE;
931 /***********************************************************************
932 * SetBitmapDimension (GDI.163)
934 DWORD WINAPI SetBitmapDimension( HBITMAP16 hbitmap, INT16 x, INT16 y )
936 SIZE16 size;
937 if (!SetBitmapDimensionEx16( hbitmap, x, y, &size )) return 0;
938 return MAKELONG( size.cx, size.cy );