Some warnings fixed, one useless VERSION warning removed (winelib).
[wine/multimedia.git] / objects / bitmap.c
blobbb55e284c45365684143c58651450d33fa4aedd0
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 "monitor.h"
19 #include "wine/winuser16.h"
21 /***********************************************************************
22 * BITMAP_GetPadding
24 * Return number of bytes to pad a scanline of 16-bit aligned Windows DDB data.
26 INT32 BITMAP_GetPadding( int bmWidth, int bpp )
28 INT32 pad;
30 switch (bpp)
32 case 1:
33 pad = ((bmWidth-1) & 8) ? 0 : 1;
34 break;
36 case 8:
37 pad = (2 - (bmWidth & 1)) & 1;
38 break;
40 case 24:
41 pad = (bmWidth*3) & 1;
42 break;
44 case 32:
45 case 16:
46 case 15:
47 pad = 0; /* we have 16bit alignment already */
48 break;
50 case 4:
51 if (!(bmWidth & 3)) pad = 0;
52 else pad = ((4 - (bmWidth & 3)) + 1) / 2;
53 break;
55 default:
56 WARN(bitmap,"Unknown depth %d, please report.\n", bpp );
57 return -1;
59 return pad;
62 /***********************************************************************
63 * BITMAP_GetWidthBytes
65 * Return number of bytes taken by a scanline of 16-bit aligned Windows DDB
66 * data.
68 INT32 BITMAP_GetWidthBytes( INT32 bmWidth, INT32 bpp )
70 switch(bpp)
72 case 1:
73 return 2 * ((bmWidth+15) >> 4);
75 case 24:
76 bmWidth *= 3; /* fall through */
77 case 8:
78 return bmWidth + (bmWidth & 1);
80 case 32:
81 return bmWidth * 4;
83 case 16:
84 case 15:
85 return bmWidth * 2;
87 case 4:
88 return 2 * ((bmWidth+3) >> 2);
90 default:
91 WARN(bitmap,"Unknown depth %d, please report.\n", bpp );
93 return -1;
96 /***********************************************************************
97 * CreateUserBitmap16 (GDI.407)
99 HBITMAP16 WINAPI CreateUserBitmap16( INT16 width, INT16 height, UINT16 planes,
100 UINT16 bpp, LPCVOID bits )
102 return CreateBitmap16( width, height, planes, bpp, bits );
105 /***********************************************************************
106 * CreateUserDiscardableBitmap16 (GDI.409)
108 HBITMAP16 WINAPI CreateUserDiscardableBitmap16( WORD dummy,
109 INT16 width, INT16 height )
111 return CreateUserBitmap16( width, height, 1, MONITOR_GetDepth(&MONITOR_PrimaryMonitor), NULL );
115 /***********************************************************************
116 * CreateBitmap16 (GDI.48)
118 HBITMAP16 WINAPI CreateBitmap16( INT16 width, INT16 height, UINT16 planes,
119 UINT16 bpp, LPCVOID bits )
121 return CreateBitmap32( width, height, planes, bpp, bits );
125 /******************************************************************************
126 * CreateBitmap32 [GDI32.25] Creates a bitmap with the specified info
128 * PARAMS
129 * width [I] bitmap width
130 * height [I] bitmap height
131 * planes [I] Number of color planes
132 * bpp [I] Number of bits to identify a color
133 * bits [I] Pointer to array containing color data
135 * RETURNS
136 * Success: Handle to bitmap
137 * Failure: 0
139 HBITMAP32 WINAPI CreateBitmap32( INT32 width, INT32 height, UINT32 planes,
140 UINT32 bpp, LPCVOID bits )
142 BITMAPOBJ *bmp;
143 HBITMAP32 hbitmap;
145 planes = (BYTE)planes;
146 bpp = (BYTE)bpp;
149 /* Check parameters */
150 if (!height || !width) return 0;
151 if (planes != 1) {
152 FIXME(bitmap, "planes = %d\n", planes);
153 return 0;
155 if (height < 0) height = -height;
156 if (width < 0) width = -width;
158 /* Create the BITMAPOBJ */
159 hbitmap = GDI_AllocObject( sizeof(BITMAPOBJ), BITMAP_MAGIC );
160 if (!hbitmap) return 0;
162 TRACE(bitmap, "%dx%d, %d colors returning %08x\n", width, height,
163 1 << (planes*bpp), hbitmap);
165 bmp = (BITMAPOBJ *) GDI_HEAP_LOCK( hbitmap );
167 bmp->size.cx = 0;
168 bmp->size.cy = 0;
169 bmp->bitmap.bmType = 0;
170 bmp->bitmap.bmWidth = width;
171 bmp->bitmap.bmHeight = height;
172 bmp->bitmap.bmPlanes = planes;
173 bmp->bitmap.bmBitsPixel = bpp;
174 bmp->bitmap.bmWidthBytes = BITMAP_GetWidthBytes( width, bpp );
175 bmp->bitmap.bmBits = NULL;
177 bmp->DDBitmap = NULL;
178 bmp->dib = NULL;
180 if (bits) /* Set bitmap bits */
181 SetBitmapBits32( hbitmap, height * bmp->bitmap.bmWidthBytes,
182 bits );
183 GDI_HEAP_UNLOCK( hbitmap );
184 return hbitmap;
188 /***********************************************************************
189 * CreateCompatibleBitmap16 (GDI.51)
191 HBITMAP16 WINAPI CreateCompatibleBitmap16(HDC16 hdc, INT16 width, INT16 height)
193 return CreateCompatibleBitmap32( hdc, width, height );
197 /******************************************************************************
198 * CreateCompatibleBitmap32 [GDI32.30] Creates a bitmap compatible with the DC
200 * PARAMS
201 * hdc [I] Handle to device context
202 * width [I] Width of bitmap
203 * height [I] Height of bitmap
205 * RETURNS
206 * Success: Handle to bitmap
207 * Failure: 0
209 HBITMAP32 WINAPI CreateCompatibleBitmap32( HDC32 hdc, INT32 width, INT32 height)
211 HBITMAP32 hbmpRet = 0;
212 DC *dc;
214 TRACE(bitmap, "(%04x,%d,%d) = \n", hdc, width, height );
215 if (!(dc = DC_GetDCPtr( hdc ))) return 0;
216 if ((width >= 0x10000) || (height >= 0x10000)) {
217 FIXME(bitmap,"got bad width %d or height %d, please look for reason\n",
218 width, height );
219 } else {
220 hbmpRet = CreateBitmap32( width, height, 1, dc->w.bitsPerPixel, NULL );
221 if(dc->funcs->pCreateBitmap)
222 dc->funcs->pCreateBitmap( hbmpRet );
224 TRACE(bitmap,"\t\t%04x\n", hbmpRet);
225 GDI_HEAP_UNLOCK(hdc);
226 return hbmpRet;
230 /***********************************************************************
231 * CreateBitmapIndirect16 (GDI.49)
233 HBITMAP16 WINAPI CreateBitmapIndirect16( const BITMAP16 * bmp )
235 return CreateBitmap16( bmp->bmWidth, bmp->bmHeight, bmp->bmPlanes,
236 bmp->bmBitsPixel, PTR_SEG_TO_LIN( bmp->bmBits ) );
240 /******************************************************************************
241 * CreateBitmapIndirect32 [GDI32.26] Creates a bitmap with the specifies info
243 * RETURNS
244 * Success: Handle to bitmap
245 * Failure: NULL
247 HBITMAP32 WINAPI CreateBitmapIndirect32(
248 const BITMAP32 * bmp) /* [in] Pointer to the bitmap data */
250 return CreateBitmap32( bmp->bmWidth, bmp->bmHeight, bmp->bmPlanes,
251 bmp->bmBitsPixel, bmp->bmBits );
255 /***********************************************************************
256 * GetBitmapBits16 (GDI.74)
258 LONG WINAPI GetBitmapBits16( HBITMAP16 hbitmap, LONG count, LPVOID buffer )
260 return GetBitmapBits32( hbitmap, count, buffer );
264 /***********************************************************************
265 * GetBitmapBits32 [GDI32.143] Copies bitmap bits of bitmap to buffer
267 * RETURNS
268 * Success: Number of bytes copied
269 * Failure: 0
271 LONG WINAPI GetBitmapBits32(
272 HBITMAP32 hbitmap, /* [in] Handle to bitmap */
273 LONG count, /* [in] Number of bytes to copy */
274 LPVOID bits) /* [out] Pointer to buffer to receive bits */
276 BITMAPOBJ *bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC );
277 LONG height, ret;
279 if (!bmp) return 0;
281 if (count < 0) {
282 WARN(bitmap, "(%ld): Negative number of bytes passed???\n", count );
283 count = -count;
286 /* Only get entire lines */
287 height = count / bmp->bitmap.bmWidthBytes;
288 if (height > bmp->bitmap.bmHeight) height = bmp->bitmap.bmHeight;
289 count = height * bmp->bitmap.bmWidthBytes;
290 if (count == 0)
292 WARN(bitmap, "Less then one entire line requested\n");
293 GDI_HEAP_UNLOCK( hbitmap );
294 return 0;
298 TRACE(bitmap, "(%08x, %ld, %p) %dx%d %d colors fetched height: %ld\n",
299 hbitmap, count, bits, bmp->bitmap.bmWidth, bmp->bitmap.bmHeight,
300 1 << bmp->bitmap.bmBitsPixel, height );
302 if(bmp->DDBitmap) {
304 TRACE(bitmap, "Calling device specific BitmapBits\n");
305 if(bmp->DDBitmap->funcs->pBitmapBits)
306 ret = bmp->DDBitmap->funcs->pBitmapBits(hbitmap, bits, count,
307 DDB_GET);
308 else {
309 ERR(bitmap, "BitmapBits == NULL??\n");
310 ret = 0;
313 } else {
315 if(!bmp->bitmap.bmBits) {
316 WARN(bitmap, "Bitmap is empty\n");
317 ret = 0;
318 } else {
319 memcpy(bits, bmp->bitmap.bmBits, count);
320 ret = count;
325 GDI_HEAP_UNLOCK( hbitmap );
326 return ret;
330 /***********************************************************************
331 * SetBitmapBits16 (GDI.106)
333 LONG WINAPI SetBitmapBits16( HBITMAP16 hbitmap, LONG count, LPCVOID buffer )
335 return SetBitmapBits32( hbitmap, count, buffer );
339 /******************************************************************************
340 * SetBitmapBits32 [GDI32.303] Sets bits of color data for a bitmap
342 * RETURNS
343 * Success: Number of bytes used in setting the bitmap bits
344 * Failure: 0
346 LONG WINAPI SetBitmapBits32(
347 HBITMAP32 hbitmap, /* [in] Handle to bitmap */
348 LONG count, /* [in] Number of bytes in bitmap array */
349 LPCVOID bits) /* [in] Address of array with bitmap bits */
351 BITMAPOBJ *bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC );
352 LONG height, ret;
354 if (!bmp) return 0;
356 if (count < 0) {
357 WARN(bitmap, "(%ld): Negative number of bytes passed???\n", count );
358 count = -count;
361 /* Only get entire lines */
362 height = count / bmp->bitmap.bmWidthBytes;
363 if (height > bmp->bitmap.bmHeight) height = bmp->bitmap.bmHeight;
364 count = height * bmp->bitmap.bmWidthBytes;
366 TRACE(bitmap, "(%08x, %ld, %p) %dx%d %d colors fetched height: %ld\n",
367 hbitmap, count, bits, bmp->bitmap.bmWidth, bmp->bitmap.bmHeight,
368 1 << bmp->bitmap.bmBitsPixel, height );
370 if(bmp->DDBitmap) {
372 TRACE(bitmap, "Calling device specific BitmapBits\n");
373 if(bmp->DDBitmap->funcs->pBitmapBits)
374 ret = bmp->DDBitmap->funcs->pBitmapBits(hbitmap, (void *) bits,
375 count, DDB_SET);
376 else {
377 ERR(bitmap, "BitmapBits == NULL??\n");
378 ret = 0;
381 } else {
383 if(!bmp->bitmap.bmBits) /* Alloc enough for entire bitmap */
384 bmp->bitmap.bmBits = HeapAlloc( GetProcessHeap(), 0, count );
385 if(!bmp->bitmap.bmBits) {
386 WARN(bitmap, "Unable to allocate bit buffer\n");
387 ret = 0;
388 } else {
389 memcpy(bmp->bitmap.bmBits, bits, count);
390 ret = count;
394 GDI_HEAP_UNLOCK( hbitmap );
395 return ret;
398 /***********************************************************************
399 * LoadImage16 [USER.389]
402 HANDLE16 WINAPI LoadImage16( HINSTANCE16 hinst, LPCSTR name, UINT16 type,
403 INT16 desiredx, INT16 desiredy, UINT16 loadflags)
405 if (HIWORD(name)) {
406 TRACE(resource,"(0x%04x,%s,%d,%d,%d,0x%08x)\n",
407 hinst,(char *)PTR_SEG_TO_LIN(name),type,desiredx,desiredy,loadflags);
408 } else {
409 TRACE(resource,"LoadImage16(0x%04x,%p,%d,%d,%d,0x%08x)\n",
410 hinst,name,type,desiredx,desiredy,loadflags);
412 switch (type) {
413 case IMAGE_BITMAP:
414 return LoadBitmap16(hinst,(SEGPTR)name);
415 case IMAGE_ICON:
416 return LoadIcon16(hinst,(SEGPTR)name);
417 case IMAGE_CURSOR:
418 return LoadCursor16(hinst,(SEGPTR)name);
420 return 0;
424 /**********************************************************************
425 * LoadImage32A (USER32.365)
427 * FIXME: implementation lacks some features, see LR_ defines in windows.h
430 HANDLE32 WINAPI LoadImage32A( HINSTANCE32 hinst, LPCSTR name, UINT32 type,
431 INT32 desiredx, INT32 desiredy, UINT32 loadflags)
433 HANDLE32 res;
434 LPWSTR u_name;
436 if (HIWORD(name)) u_name = HEAP_strdupAtoW(GetProcessHeap(), 0, name);
437 else u_name=(LPWSTR)name;
438 res = LoadImage32W(hinst, u_name, type, desiredx, desiredy, loadflags);
439 if (HIWORD(name)) HeapFree(GetProcessHeap(), 0, u_name);
440 return res;
444 /******************************************************************************
445 * LoadImage32W [USER32.366] Loads an icon, cursor, or bitmap
447 * PARAMS
448 * hinst [I] Handle of instance that contains image
449 * name [I] Name of image
450 * type [I] Type of image
451 * desiredx [I] Desired width
452 * desiredy [I] Desired height
453 * loadflags [I] Load flags
455 * RETURNS
456 * Success: Handle to newly loaded image
457 * Failure: NULL
459 * FIXME: Implementation lacks some features, see LR_ defines in windows.h
461 HANDLE32 WINAPI LoadImage32W( HINSTANCE32 hinst, LPCWSTR name, UINT32 type,
462 INT32 desiredx, INT32 desiredy, UINT32 loadflags )
464 if (HIWORD(name)) {
465 TRACE(resource,"(0x%04x,%p,%d,%d,%d,0x%08x)\n",
466 hinst,name,type,desiredx,desiredy,loadflags);
467 } else {
468 TRACE(resource,"(0x%04x,%p,%d,%d,%d,0x%08x)\n",
469 hinst,name,type,desiredx,desiredy,loadflags);
471 if (loadflags & LR_DEFAULTSIZE) {
472 if (type == IMAGE_ICON) {
473 if (!desiredx) desiredx = SYSMETRICS_CXICON;
474 if (!desiredy) desiredy = SYSMETRICS_CYICON;
475 } else if (type == IMAGE_CURSOR) {
476 if (!desiredx) desiredx = SYSMETRICS_CXCURSOR;
477 if (!desiredy) desiredy = SYSMETRICS_CYCURSOR;
480 if (loadflags & LR_LOADFROMFILE) loadflags &= ~LR_SHARED;
481 switch (type) {
482 case IMAGE_BITMAP:
483 return BITMAP_LoadBitmap32W(hinst, name, loadflags);
485 case IMAGE_ICON:
487 HDC32 hdc = GetDC32(0);
488 UINT32 palEnts = GetSystemPaletteEntries32(hdc, 0, 0, NULL);
489 ReleaseDC32(0, hdc);
491 return CURSORICON_Load32(hinst, name, desiredx, desiredy,
492 MIN(16, palEnts), FALSE, loadflags);
495 case IMAGE_CURSOR:
496 return CURSORICON_Load32(hinst, name, desiredx, desiredy,
497 1, TRUE, loadflags);
499 return 0;
503 /**********************************************************************
504 * BITMAP_CopyBitmap
507 HBITMAP32 BITMAP_CopyBitmap(HBITMAP32 hbitmap)
509 BITMAPOBJ *bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC );
510 HBITMAP32 res = 0;
511 BITMAP32 bm;
513 if(!bmp) return 0;
515 bm = bmp->bitmap;
516 bm.bmBits = NULL;
517 res = CreateBitmapIndirect32(&bm);
519 if(res) {
520 char *buf = HeapAlloc( GetProcessHeap(), 0, bm.bmWidthBytes *
521 bm.bmHeight );
522 GetBitmapBits32 (hbitmap, bm.bmWidthBytes * bm.bmHeight, buf);
523 SetBitmapBits32 (res, bm.bmWidthBytes * bm.bmHeight, buf);
524 HeapFree( GetProcessHeap(), 0, buf );
527 GDI_HEAP_UNLOCK( hbitmap );
528 return res;
531 /******************************************************************************
532 * CopyImage16 [USER.390] Creates new image and copies attributes to it
535 HICON16 WINAPI CopyImage16( HANDLE16 hnd, UINT16 type, INT16 desiredx,
536 INT16 desiredy, UINT16 flags )
538 return (HICON16)CopyImage32((HANDLE32)hnd, (UINT32)type, (INT32)desiredx,
539 (INT32)desiredy, (UINT32)flags);
542 /******************************************************************************
543 * CopyImage32 [USER32.61] Creates new image and copies attributes to it
545 * PARAMS
546 * hnd [I] Handle to image to copy
547 * type [I] Type of image to copy
548 * desiredx [I] Desired width of new image
549 * desiredy [I] Desired height of new image
550 * flags [I] Copy flags
552 * RETURNS
553 * Success: Handle to newly created image
554 * Failure: NULL
556 * FIXME: implementation still lacks nearly all features, see LR_*
557 * defines in windows.h
559 HICON32 WINAPI CopyImage32( HANDLE32 hnd, UINT32 type, INT32 desiredx,
560 INT32 desiredy, UINT32 flags )
562 switch (type)
564 case IMAGE_BITMAP:
565 return BITMAP_CopyBitmap(hnd);
566 case IMAGE_ICON:
567 return CopyIcon32(hnd);
568 case IMAGE_CURSOR:
569 return CopyCursor32(hnd);
571 return 0;
574 /**********************************************************************
575 * LoadBitmap16 (USER.175)
577 * NOTES
578 * Can this call LoadBitmap32?
580 HBITMAP16 WINAPI LoadBitmap16( HINSTANCE16 instance, SEGPTR name )
582 HBITMAP32 hbitmap = 0;
583 HDC32 hdc;
584 HRSRC16 hRsrc;
585 HGLOBAL16 handle;
586 BITMAPINFO *info;
588 if (HIWORD(name))
590 char *str = (char *)PTR_SEG_TO_LIN( name );
591 TRACE(bitmap, "(%04x,'%s')\n", instance, str );
592 if (str[0] == '#') name = (SEGPTR)(DWORD)(WORD)atoi( str + 1 );
594 else
595 TRACE(bitmap, "(%04x,%04x)\n",
596 instance, LOWORD(name) );
598 if (!instance) /* OEM bitmap */
600 HDC32 hdc;
601 DC *dc;
603 if (HIWORD((int)name)) return 0;
604 hdc = CreateDC32A( "DISPLAY", NULL, NULL, NULL );
605 dc = DC_GetDCPtr( hdc );
606 if(dc->funcs->pLoadOEMResource)
607 hbitmap = dc->funcs->pLoadOEMResource( LOWORD((int)name),
608 OEM_BITMAP );
609 GDI_HEAP_UNLOCK( hdc );
610 DeleteDC32( hdc );
611 return hbitmap;
614 if (!(hRsrc = FindResource16( instance, name, RT_BITMAP16 ))) return 0;
615 if (!(handle = LoadResource16( instance, hRsrc ))) return 0;
617 info = (BITMAPINFO *)LockResource16( handle );
618 if ((hdc = GetDC32(0)) != 0)
620 char *bits = (char *)info + DIB_BitmapInfoSize( info, DIB_RGB_COLORS );
621 hbitmap = CreateDIBitmap32( hdc, &info->bmiHeader, CBM_INIT,
622 bits, info, DIB_RGB_COLORS );
623 ReleaseDC32( 0, hdc );
625 FreeResource16( handle );
626 return hbitmap;
630 /**********************************************************************
631 * BITMAP_LoadBitmap32W
633 HBITMAP32 BITMAP_LoadBitmap32W(HINSTANCE32 instance,LPCWSTR name,
634 UINT32 loadflags)
636 HBITMAP32 hbitmap = 0;
637 HDC32 hdc;
638 HRSRC32 hRsrc;
639 HGLOBAL32 handle;
640 char *ptr = NULL;
641 BITMAPINFO *info, *fix_info=NULL;
642 HGLOBAL32 hFix;
643 int size;
645 if (!(loadflags & LR_LOADFROMFILE)) {
646 if (!instance) /* OEM bitmap */
648 HDC32 hdc;
649 DC *dc;
651 if (HIWORD((int)name)) return 0;
652 hdc = CreateDC32A( "DISPLAY", NULL, NULL, NULL );
653 dc = DC_GetDCPtr( hdc );
654 if(dc->funcs->pLoadOEMResource)
655 hbitmap = dc->funcs->pLoadOEMResource( LOWORD((int)name),
656 OEM_BITMAP );
657 GDI_HEAP_UNLOCK( hdc );
658 DeleteDC32( hdc );
659 return hbitmap;
662 if (!(hRsrc = FindResource32W( instance, name, RT_BITMAP32W ))) return 0;
663 if (!(handle = LoadResource32( instance, hRsrc ))) return 0;
665 if ((info = (BITMAPINFO *)LockResource32( handle )) == NULL) return 0;
667 else
669 if (!(ptr = (char *)VIRTUAL_MapFileW( name ))) return 0;
670 info = (BITMAPINFO *)(ptr + sizeof(BITMAPFILEHEADER));
672 size = DIB_BitmapInfoSize(info, DIB_RGB_COLORS);
673 if ((hFix = GlobalAlloc32(0, size))) fix_info=GlobalLock32(hFix);
674 if (fix_info) {
675 BYTE pix;
677 memcpy(fix_info, info, size);
678 pix = *((LPBYTE)info+DIB_BitmapInfoSize(info, DIB_RGB_COLORS));
679 DIB_FixColorsToLoadflags(fix_info, loadflags, pix);
680 if ((hdc = GetDC32(0)) != 0) {
681 if (loadflags & LR_CREATEDIBSECTION)
682 hbitmap = CreateDIBSection32(hdc, fix_info, DIB_RGB_COLORS, NULL, 0, 0);
683 else {
684 char *bits = (char *)info + size;;
685 hbitmap = CreateDIBitmap32( hdc, &fix_info->bmiHeader, CBM_INIT,
686 bits, fix_info, DIB_RGB_COLORS );
688 ReleaseDC32( 0, hdc );
690 GlobalUnlock32(hFix);
691 GlobalFree32(hFix);
693 if (loadflags & LR_LOADFROMFILE) UnmapViewOfFile( ptr );
694 return hbitmap;
698 /******************************************************************************
699 * LoadBitmap32W [USER32.358] Loads bitmap from the executable file
701 * RETURNS
702 * Success: Handle to specified bitmap
703 * Failure: NULL
705 HBITMAP32 WINAPI LoadBitmap32W(
706 HINSTANCE32 instance, /* [in] Handle to application instance */
707 LPCWSTR name) /* [in] Address of bitmap resource name */
709 return BITMAP_LoadBitmap32W(instance, name, 0);
713 /**********************************************************************
714 * LoadBitmap32A (USER32.357)
716 HBITMAP32 WINAPI LoadBitmap32A( HINSTANCE32 instance, LPCSTR name )
718 HBITMAP32 res;
719 if (!HIWORD(name)) res = LoadBitmap32W( instance, (LPWSTR)name );
720 else
722 LPWSTR uni = HEAP_strdupAtoW( GetProcessHeap(), 0, name );
723 res = LoadBitmap32W( instance, uni );
724 HeapFree( GetProcessHeap(), 0, uni );
726 return res;
730 /***********************************************************************
731 * BITMAP_DeleteObject
733 BOOL32 BITMAP_DeleteObject( HBITMAP16 hbitmap, BITMAPOBJ * bmp )
735 if( bmp->DDBitmap ) {
736 if( bmp->DDBitmap->funcs->pDeleteObject )
737 bmp->DDBitmap->funcs->pDeleteObject( hbitmap );
740 if( bmp->bitmap.bmBits )
741 HeapFree( GetProcessHeap(), 0, bmp->bitmap.bmBits );
743 DIB_DeleteDIBSection( bmp );
745 return GDI_FreeObject( hbitmap );
749 /***********************************************************************
750 * BITMAP_GetObject16
752 INT16 BITMAP_GetObject16( BITMAPOBJ * bmp, INT16 count, LPVOID buffer )
754 if (bmp->dib)
756 if ( count <= sizeof(BITMAP16) )
758 BITMAP32 *bmp32 = &bmp->dib->dibSection.dsBm;
759 BITMAP16 bmp16;
760 bmp16.bmType = bmp32->bmType;
761 bmp16.bmWidth = bmp32->bmWidth;
762 bmp16.bmHeight = bmp32->bmHeight;
763 bmp16.bmWidthBytes = bmp32->bmWidthBytes;
764 bmp16.bmPlanes = bmp32->bmPlanes;
765 bmp16.bmBitsPixel = bmp32->bmBitsPixel;
766 bmp16.bmBits = (SEGPTR)0;
767 memcpy( buffer, &bmp16, count );
768 return count;
770 else
772 FIXME(bitmap, "not implemented for DIBs: count %d\n", count);
773 return 0;
776 else
778 BITMAP16 bmp16;
779 bmp16.bmType = bmp->bitmap.bmType;
780 bmp16.bmWidth = bmp->bitmap.bmWidth;
781 bmp16.bmHeight = bmp->bitmap.bmHeight;
782 bmp16.bmWidthBytes = bmp->bitmap.bmWidthBytes;
783 bmp16.bmPlanes = bmp->bitmap.bmPlanes;
784 bmp16.bmBitsPixel = bmp->bitmap.bmBitsPixel;
785 bmp16.bmBits = (SEGPTR)0;
786 if (count > sizeof(bmp16)) count = sizeof(bmp16);
787 memcpy( buffer, &bmp16, count );
788 return count;
793 /***********************************************************************
794 * BITMAP_GetObject32
796 INT32 BITMAP_GetObject32( BITMAPOBJ * bmp, INT32 count, LPVOID buffer )
798 if (bmp->dib)
800 if (count < sizeof(DIBSECTION))
802 if (count > sizeof(BITMAP32)) count = sizeof(BITMAP32);
804 else
806 if (count > sizeof(DIBSECTION)) count = sizeof(DIBSECTION);
809 memcpy( buffer, &bmp->dib->dibSection, count );
810 return count;
812 else
814 if (count > sizeof(BITMAP32)) count = sizeof(BITMAP32);
815 memcpy( buffer, &bmp->bitmap, count );
816 return count;
821 /***********************************************************************
822 * CreateDiscardableBitmap16 (GDI.156)
824 HBITMAP16 WINAPI CreateDiscardableBitmap16( HDC16 hdc, INT16 width,
825 INT16 height )
827 return CreateCompatibleBitmap16( hdc, width, height );
831 /******************************************************************************
832 * CreateDiscardableBitmap32 [GDI32.38] Creates a discardable bitmap
834 * RETURNS
835 * Success: Handle to bitmap
836 * Failure: NULL
838 HBITMAP32 WINAPI CreateDiscardableBitmap32(
839 HDC32 hdc, /* [in] Handle to device context */
840 INT32 width, /* [in] Bitmap width */
841 INT32 height) /* [in] Bitmap height */
843 return CreateCompatibleBitmap32( hdc, width, height );
847 /***********************************************************************
848 * GetBitmapDimensionEx16 (GDI.468)
850 * NOTES
851 * Can this call GetBitmapDimensionEx32?
853 BOOL16 WINAPI GetBitmapDimensionEx16( HBITMAP16 hbitmap, LPSIZE16 size )
855 BITMAPOBJ * bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC );
856 if (!bmp) return FALSE;
857 CONV_SIZE32TO16( &bmp->size, size );
858 GDI_HEAP_UNLOCK( hbitmap );
859 return TRUE;
863 /******************************************************************************
864 * GetBitmapDimensionEx32 [GDI32.144] Retrieves dimensions of a bitmap
866 * RETURNS
867 * Success: TRUE
868 * Failure: FALSE
870 BOOL32 WINAPI GetBitmapDimensionEx32(
871 HBITMAP32 hbitmap, /* [in] Handle to bitmap */
872 LPSIZE32 size) /* [out] Address of struct receiving dimensions */
874 BITMAPOBJ * bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC );
875 if (!bmp) return FALSE;
876 *size = bmp->size;
877 GDI_HEAP_UNLOCK( hbitmap );
878 return TRUE;
882 /***********************************************************************
883 * GetBitmapDimension (GDI.162)
885 DWORD WINAPI GetBitmapDimension( HBITMAP16 hbitmap )
887 SIZE16 size;
888 if (!GetBitmapDimensionEx16( hbitmap, &size )) return 0;
889 return MAKELONG( size.cx, size.cy );
893 /***********************************************************************
894 * SetBitmapDimensionEx16 (GDI.478)
896 BOOL16 WINAPI SetBitmapDimensionEx16( HBITMAP16 hbitmap, INT16 x, INT16 y,
897 LPSIZE16 prevSize )
899 BITMAPOBJ * bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC );
900 if (!bmp) return FALSE;
901 if (prevSize) CONV_SIZE32TO16( &bmp->size, prevSize );
902 bmp->size.cx = x;
903 bmp->size.cy = y;
904 GDI_HEAP_UNLOCK( hbitmap );
905 return TRUE;
909 /******************************************************************************
910 * SetBitmapDimensionEx32 [GDI32.304] Assignes dimensions to a bitmap
912 * RETURNS
913 * Success: TRUE
914 * Failure: FALSE
916 BOOL32 WINAPI SetBitmapDimensionEx32(
917 HBITMAP32 hbitmap, /* [in] Handle to bitmap */
918 INT32 x, /* [in] Bitmap width */
919 INT32 y, /* [in] Bitmap height */
920 LPSIZE32 prevSize) /* [out] Address of structure for orig dims */
922 BITMAPOBJ * bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC );
923 if (!bmp) return FALSE;
924 if (prevSize) *prevSize = bmp->size;
925 bmp->size.cx = x;
926 bmp->size.cy = y;
927 GDI_HEAP_UNLOCK( hbitmap );
928 return TRUE;
932 /***********************************************************************
933 * SetBitmapDimension (GDI.163)
935 DWORD WINAPI SetBitmapDimension( HBITMAP16 hbitmap, INT16 x, INT16 y )
937 SIZE16 size;
938 if (!SetBitmapDimensionEx16( hbitmap, x, y, &size )) return 0;
939 return MAKELONG( size.cx, size.cy );