Fixed implicit type warning.
[wine/multimedia.git] / objects / bitmap.c
blobc4f702991572d47f97592ef78d62efd8aeb445cf
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 "debugtools.h"
20 #include "monitor.h"
21 #include "wine/winuser16.h"
23 DECLARE_DEBUG_CHANNEL(bitmap)
24 DECLARE_DEBUG_CHANNEL(resource)
26 BITMAP_DRIVER *BITMAP_Driver = NULL;
29 /***********************************************************************
30 * BITMAP_GetWidthBytes
32 * Return number of bytes taken by a scanline of 16-bit aligned Windows DDB
33 * data.
35 INT BITMAP_GetWidthBytes( INT bmWidth, INT bpp )
37 switch(bpp)
39 case 1:
40 return 2 * ((bmWidth+15) >> 4);
42 case 24:
43 bmWidth *= 3; /* fall through */
44 case 8:
45 return bmWidth + (bmWidth & 1);
47 case 32:
48 return bmWidth * 4;
50 case 16:
51 case 15:
52 return bmWidth * 2;
54 case 4:
55 return 2 * ((bmWidth+3) >> 2);
57 default:
58 WARN_(bitmap)("Unknown depth %d, please report.\n", bpp );
60 return -1;
63 /***********************************************************************
64 * CreateUserBitmap16 (GDI.407)
66 HBITMAP16 WINAPI CreateUserBitmap16( INT16 width, INT16 height, UINT16 planes,
67 UINT16 bpp, LPCVOID bits )
69 return CreateBitmap16( width, height, planes, bpp, bits );
72 /***********************************************************************
73 * CreateUserDiscardableBitmap16 (GDI.409)
75 HBITMAP16 WINAPI CreateUserDiscardableBitmap16( WORD dummy,
76 INT16 width, INT16 height )
78 return CreateUserBitmap16( width, height, 1, MONITOR_GetDepth(&MONITOR_PrimaryMonitor), NULL );
82 /***********************************************************************
83 * CreateBitmap16 (GDI.48)
85 HBITMAP16 WINAPI CreateBitmap16( INT16 width, INT16 height, UINT16 planes,
86 UINT16 bpp, LPCVOID bits )
88 return CreateBitmap( width, height, planes, bpp, bits );
92 /******************************************************************************
93 * CreateBitmap32 [GDI32.25] Creates a bitmap with the specified info
95 * PARAMS
96 * width [I] bitmap width
97 * height [I] bitmap height
98 * planes [I] Number of color planes
99 * bpp [I] Number of bits to identify a color
100 * bits [I] Pointer to array containing color data
102 * RETURNS
103 * Success: Handle to bitmap
104 * Failure: 0
106 HBITMAP WINAPI CreateBitmap( INT width, INT height, UINT planes,
107 UINT bpp, LPCVOID bits )
109 BITMAPOBJ *bmp;
110 HBITMAP hbitmap;
112 planes = (BYTE)planes;
113 bpp = (BYTE)bpp;
116 /* Check parameters */
117 if (!height || !width) return 0;
118 if (planes != 1) {
119 FIXME_(bitmap)("planes = %d\n", planes);
120 return 0;
122 if (height < 0) height = -height;
123 if (width < 0) width = -width;
125 /* Create the BITMAPOBJ */
126 hbitmap = GDI_AllocObject( sizeof(BITMAPOBJ), BITMAP_MAGIC );
127 if (!hbitmap) return 0;
129 TRACE_(bitmap)("%dx%d, %d colors returning %08x\n", width, height,
130 1 << (planes*bpp), hbitmap);
132 bmp = (BITMAPOBJ *) GDI_HEAP_LOCK( hbitmap );
134 bmp->size.cx = 0;
135 bmp->size.cy = 0;
136 bmp->bitmap.bmType = 0;
137 bmp->bitmap.bmWidth = width;
138 bmp->bitmap.bmHeight = height;
139 bmp->bitmap.bmPlanes = planes;
140 bmp->bitmap.bmBitsPixel = bpp;
141 bmp->bitmap.bmWidthBytes = BITMAP_GetWidthBytes( width, bpp );
142 bmp->bitmap.bmBits = NULL;
144 bmp->DDBitmap = NULL;
145 bmp->dib = NULL;
147 if (bits) /* Set bitmap bits */
148 SetBitmapBits( hbitmap, height * bmp->bitmap.bmWidthBytes,
149 bits );
150 GDI_HEAP_UNLOCK( hbitmap );
151 return hbitmap;
155 /***********************************************************************
156 * CreateCompatibleBitmap16 (GDI.51)
158 HBITMAP16 WINAPI CreateCompatibleBitmap16(HDC16 hdc, INT16 width, INT16 height)
160 return CreateCompatibleBitmap( hdc, width, height );
164 /******************************************************************************
165 * CreateCompatibleBitmap32 [GDI32.30] Creates a bitmap compatible with the DC
167 * PARAMS
168 * hdc [I] Handle to device context
169 * width [I] Width of bitmap
170 * height [I] Height of bitmap
172 * RETURNS
173 * Success: Handle to bitmap
174 * Failure: 0
176 HBITMAP WINAPI CreateCompatibleBitmap( HDC hdc, INT width, INT height)
178 HBITMAP hbmpRet = 0;
179 DC *dc;
181 TRACE_(bitmap)("(%04x,%d,%d) = \n", hdc, width, height );
182 if (!(dc = DC_GetDCPtr( hdc ))) return 0;
183 if ((width >= 0x10000) || (height >= 0x10000)) {
184 FIXME_(bitmap)("got bad width %d or height %d, please look for reason\n",
185 width, height );
186 } else {
187 hbmpRet = CreateBitmap( width, height, 1, dc->w.bitsPerPixel, NULL );
188 if(dc->funcs->pCreateBitmap)
189 dc->funcs->pCreateBitmap( hbmpRet );
191 TRACE_(bitmap)("\t\t%04x\n", hbmpRet);
192 GDI_HEAP_UNLOCK(hdc);
193 return hbmpRet;
197 /***********************************************************************
198 * CreateBitmapIndirect16 (GDI.49)
200 HBITMAP16 WINAPI CreateBitmapIndirect16( const BITMAP16 * bmp )
202 return CreateBitmap16( bmp->bmWidth, bmp->bmHeight, bmp->bmPlanes,
203 bmp->bmBitsPixel, PTR_SEG_TO_LIN( bmp->bmBits ) );
207 /******************************************************************************
208 * CreateBitmapIndirect32 [GDI32.26] Creates a bitmap with the specifies info
210 * RETURNS
211 * Success: Handle to bitmap
212 * Failure: NULL
214 HBITMAP WINAPI CreateBitmapIndirect(
215 const BITMAP * bmp) /* [in] Pointer to the bitmap data */
217 return CreateBitmap( bmp->bmWidth, bmp->bmHeight, bmp->bmPlanes,
218 bmp->bmBitsPixel, bmp->bmBits );
222 /***********************************************************************
223 * GetBitmapBits16 (GDI.74)
225 LONG WINAPI GetBitmapBits16( HBITMAP16 hbitmap, LONG count, LPVOID buffer )
227 return GetBitmapBits( hbitmap, count, buffer );
231 /***********************************************************************
232 * GetBitmapBits32 [GDI32.143] Copies bitmap bits of bitmap to buffer
234 * RETURNS
235 * Success: Number of bytes copied
236 * Failure: 0
238 LONG WINAPI GetBitmapBits(
239 HBITMAP hbitmap, /* [in] Handle to bitmap */
240 LONG count, /* [in] Number of bytes to copy */
241 LPVOID bits) /* [out] Pointer to buffer to receive bits */
243 BITMAPOBJ *bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC );
244 LONG height, ret;
246 if (!bmp) return 0;
248 if (count < 0) {
249 WARN_(bitmap)("(%ld): Negative number of bytes passed???\n", count );
250 count = -count;
253 /* Only get entire lines */
254 height = count / bmp->bitmap.bmWidthBytes;
255 if (height > bmp->bitmap.bmHeight) height = bmp->bitmap.bmHeight;
256 count = height * bmp->bitmap.bmWidthBytes;
257 if (count == 0)
259 WARN_(bitmap)("Less then one entire line requested\n");
260 GDI_HEAP_UNLOCK( hbitmap );
261 return 0;
265 TRACE_(bitmap)("(%08x, %ld, %p) %dx%d %d colors fetched height: %ld\n",
266 hbitmap, count, bits, bmp->bitmap.bmWidth, bmp->bitmap.bmHeight,
267 1 << bmp->bitmap.bmBitsPixel, height );
269 if(bmp->DDBitmap) {
271 TRACE_(bitmap)("Calling device specific BitmapBits\n");
272 if(bmp->DDBitmap->funcs->pBitmapBits)
273 ret = bmp->DDBitmap->funcs->pBitmapBits(hbitmap, bits, count,
274 DDB_GET);
275 else {
276 ERR_(bitmap)("BitmapBits == NULL??\n");
277 ret = 0;
280 } else {
282 if(!bmp->bitmap.bmBits) {
283 WARN_(bitmap)("Bitmap is empty\n");
284 ret = 0;
285 } else {
286 memcpy(bits, bmp->bitmap.bmBits, count);
287 ret = count;
292 GDI_HEAP_UNLOCK( hbitmap );
293 return ret;
297 /***********************************************************************
298 * SetBitmapBits16 (GDI.106)
300 LONG WINAPI SetBitmapBits16( HBITMAP16 hbitmap, LONG count, LPCVOID buffer )
302 return SetBitmapBits( hbitmap, count, buffer );
306 /******************************************************************************
307 * SetBitmapBits32 [GDI32.303] Sets bits of color data for a bitmap
309 * RETURNS
310 * Success: Number of bytes used in setting the bitmap bits
311 * Failure: 0
313 LONG WINAPI SetBitmapBits(
314 HBITMAP hbitmap, /* [in] Handle to bitmap */
315 LONG count, /* [in] Number of bytes in bitmap array */
316 LPCVOID bits) /* [in] Address of array with bitmap bits */
318 BITMAPOBJ *bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC );
319 LONG height, ret;
321 if (!bmp) return 0;
323 if (count < 0) {
324 WARN_(bitmap)("(%ld): Negative number of bytes passed???\n", count );
325 count = -count;
328 /* Only get entire lines */
329 height = count / bmp->bitmap.bmWidthBytes;
330 if (height > bmp->bitmap.bmHeight) height = bmp->bitmap.bmHeight;
331 count = height * bmp->bitmap.bmWidthBytes;
333 TRACE_(bitmap)("(%08x, %ld, %p) %dx%d %d colors fetched height: %ld\n",
334 hbitmap, count, bits, bmp->bitmap.bmWidth, bmp->bitmap.bmHeight,
335 1 << bmp->bitmap.bmBitsPixel, height );
337 if(bmp->DDBitmap) {
339 TRACE_(bitmap)("Calling device specific BitmapBits\n");
340 if(bmp->DDBitmap->funcs->pBitmapBits)
341 ret = bmp->DDBitmap->funcs->pBitmapBits(hbitmap, (void *) bits,
342 count, DDB_SET);
343 else {
344 ERR_(bitmap)("BitmapBits == NULL??\n");
345 ret = 0;
348 } else {
350 if(!bmp->bitmap.bmBits) /* Alloc enough for entire bitmap */
351 bmp->bitmap.bmBits = HeapAlloc( GetProcessHeap(), 0, count );
352 if(!bmp->bitmap.bmBits) {
353 WARN_(bitmap)("Unable to allocate bit buffer\n");
354 ret = 0;
355 } else {
356 memcpy(bmp->bitmap.bmBits, bits, count);
357 ret = count;
361 GDI_HEAP_UNLOCK( hbitmap );
362 return ret;
365 /***********************************************************************
366 * LoadImage16 [USER.389]
369 HANDLE16 WINAPI LoadImage16( HINSTANCE16 hinst, LPCSTR name, UINT16 type,
370 INT16 desiredx, INT16 desiredy, UINT16 loadflags)
372 LPCSTR nameStr = HIWORD(name)? PTR_SEG_TO_LIN(name) : (LPCSTR)name;
373 return LoadImageA( hinst, nameStr, type,
374 desiredx, desiredy, loadflags );
377 /**********************************************************************
378 * LoadImageA (USER32.365)
380 * FIXME: implementation lacks some features, see LR_ defines in windows.h
383 HANDLE WINAPI LoadImageA( HINSTANCE hinst, LPCSTR name, UINT type,
384 INT desiredx, INT desiredy, UINT loadflags)
386 HANDLE res;
387 LPWSTR u_name;
389 if (HIWORD(name)) u_name = HEAP_strdupAtoW(GetProcessHeap(), 0, name);
390 else u_name=(LPWSTR)name;
391 res = LoadImageW(hinst, u_name, type, desiredx, desiredy, loadflags);
392 if (HIWORD(name)) HeapFree(GetProcessHeap(), 0, u_name);
393 return res;
397 /******************************************************************************
398 * LoadImageW [USER32.366] Loads an icon, cursor, or bitmap
400 * PARAMS
401 * hinst [I] Handle of instance that contains image
402 * name [I] Name of image
403 * type [I] Type of image
404 * desiredx [I] Desired width
405 * desiredy [I] Desired height
406 * loadflags [I] Load flags
408 * RETURNS
409 * Success: Handle to newly loaded image
410 * Failure: NULL
412 * FIXME: Implementation lacks some features, see LR_ defines in windows.h
414 HANDLE WINAPI LoadImageW( HINSTANCE hinst, LPCWSTR name, UINT type,
415 INT desiredx, INT desiredy, UINT loadflags )
417 if (HIWORD(name)) {
418 TRACE_(resource)("(0x%04x,%p,%d,%d,%d,0x%08x)\n",
419 hinst,name,type,desiredx,desiredy,loadflags);
420 } else {
421 TRACE_(resource)("(0x%04x,%p,%d,%d,%d,0x%08x)\n",
422 hinst,name,type,desiredx,desiredy,loadflags);
424 if (loadflags & LR_DEFAULTSIZE) {
425 if (type == IMAGE_ICON) {
426 if (!desiredx) desiredx = SYSMETRICS_CXICON;
427 if (!desiredy) desiredy = SYSMETRICS_CYICON;
428 } else if (type == IMAGE_CURSOR) {
429 if (!desiredx) desiredx = SYSMETRICS_CXCURSOR;
430 if (!desiredy) desiredy = SYSMETRICS_CYCURSOR;
433 if (loadflags & LR_LOADFROMFILE) loadflags &= ~LR_SHARED;
434 switch (type) {
435 case IMAGE_BITMAP:
436 return BITMAP_Load( hinst, name, loadflags );
438 case IMAGE_ICON:
440 HDC hdc = GetDC(0);
441 UINT palEnts = GetSystemPaletteEntries(hdc, 0, 0, NULL);
442 if (palEnts == 0)
443 palEnts = 256;
444 ReleaseDC(0, hdc);
446 return CURSORICON_Load(hinst, name, desiredx, desiredy,
447 palEnts, FALSE, loadflags);
450 case IMAGE_CURSOR:
451 return CURSORICON_Load(hinst, name, desiredx, desiredy,
452 1, TRUE, loadflags);
454 return 0;
458 /**********************************************************************
459 * BITMAP_CopyBitmap
462 HBITMAP BITMAP_CopyBitmap(HBITMAP hbitmap)
464 BITMAPOBJ *bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC );
465 HBITMAP res = 0;
466 BITMAP bm;
468 if(!bmp) return 0;
470 bm = bmp->bitmap;
471 bm.bmBits = NULL;
472 res = CreateBitmapIndirect(&bm);
474 if(res) {
475 char *buf = HeapAlloc( GetProcessHeap(), 0, bm.bmWidthBytes *
476 bm.bmHeight );
477 GetBitmapBits (hbitmap, bm.bmWidthBytes * bm.bmHeight, buf);
478 SetBitmapBits (res, bm.bmWidthBytes * bm.bmHeight, buf);
479 HeapFree( GetProcessHeap(), 0, buf );
482 GDI_HEAP_UNLOCK( hbitmap );
483 return res;
486 /******************************************************************************
487 * CopyImage16 [USER.390] Creates new image and copies attributes to it
490 HICON16 WINAPI CopyImage16( HANDLE16 hnd, UINT16 type, INT16 desiredx,
491 INT16 desiredy, UINT16 flags )
493 return (HICON16)CopyImage((HANDLE)hnd, (UINT)type, (INT)desiredx,
494 (INT)desiredy, (UINT)flags);
497 /******************************************************************************
498 * CopyImage32 [USER32.61] Creates new image and copies attributes to it
500 * PARAMS
501 * hnd [I] Handle to image to copy
502 * type [I] Type of image to copy
503 * desiredx [I] Desired width of new image
504 * desiredy [I] Desired height of new image
505 * flags [I] Copy flags
507 * RETURNS
508 * Success: Handle to newly created image
509 * Failure: NULL
511 * FIXME: implementation still lacks nearly all features, see LR_*
512 * defines in windows.h
514 HICON WINAPI CopyImage( HANDLE hnd, UINT type, INT desiredx,
515 INT desiredy, UINT flags )
517 switch (type)
519 case IMAGE_BITMAP:
520 return BITMAP_CopyBitmap(hnd);
521 case IMAGE_ICON:
522 return CopyIcon(hnd);
523 case IMAGE_CURSOR:
524 return CopyCursor(hnd);
526 return 0;
529 /**********************************************************************
530 * BITMAP_Load
532 HBITMAP BITMAP_Load( HINSTANCE instance,LPCWSTR name, UINT loadflags )
534 HBITMAP hbitmap = 0;
535 HDC hdc;
536 HRSRC hRsrc;
537 HGLOBAL handle;
538 char *ptr = NULL;
539 BITMAPINFO *info, *fix_info=NULL;
540 HGLOBAL hFix;
541 int size;
543 if (!(loadflags & LR_LOADFROMFILE)) {
544 if (!instance) /* OEM bitmap */
546 HDC hdc;
547 DC *dc;
549 if (HIWORD((int)name)) return 0;
550 hdc = CreateDCA( "DISPLAY", NULL, NULL, NULL );
551 dc = DC_GetDCPtr( hdc );
552 if(dc->funcs->pLoadOEMResource)
553 hbitmap = dc->funcs->pLoadOEMResource( LOWORD((int)name),
554 OEM_BITMAP );
555 GDI_HEAP_UNLOCK( hdc );
556 DeleteDC( hdc );
557 return hbitmap;
560 if (!(hRsrc = FindResourceW( instance, name, RT_BITMAPW ))) return 0;
561 if (!(handle = LoadResource( instance, hRsrc ))) return 0;
563 if ((info = (BITMAPINFO *)LockResource( handle )) == NULL) return 0;
565 else
567 if (!(ptr = (char *)VIRTUAL_MapFileW( name ))) return 0;
568 info = (BITMAPINFO *)(ptr + sizeof(BITMAPFILEHEADER));
570 size = DIB_BitmapInfoSize(info, DIB_RGB_COLORS);
571 if ((hFix = GlobalAlloc(0, size))) fix_info=GlobalLock(hFix);
572 if (fix_info) {
573 BYTE pix;
575 memcpy(fix_info, info, size);
576 pix = *((LPBYTE)info+DIB_BitmapInfoSize(info, DIB_RGB_COLORS));
577 DIB_FixColorsToLoadflags(fix_info, loadflags, pix);
578 if ((hdc = GetDC(0)) != 0) {
579 char *bits = (char *)info + size;
580 if (loadflags & LR_CREATEDIBSECTION) {
581 DIBSECTION dib;
582 hbitmap = CreateDIBSection(hdc, fix_info, DIB_RGB_COLORS, NULL, 0, 0);
583 GetObjectA(hbitmap, sizeof(DIBSECTION), &dib);
584 SetDIBits(hdc, hbitmap, 0, dib.dsBm.bmHeight, bits, info,
585 DIB_RGB_COLORS);
587 else {
588 hbitmap = CreateDIBitmap( hdc, &fix_info->bmiHeader, CBM_INIT,
589 bits, fix_info, DIB_RGB_COLORS );
591 ReleaseDC( 0, hdc );
593 GlobalUnlock(hFix);
594 GlobalFree(hFix);
596 if (loadflags & LR_LOADFROMFILE) UnmapViewOfFile( ptr );
597 return hbitmap;
601 /******************************************************************************
602 * LoadBitmapW [USER32.358] Loads bitmap from the executable file
604 * RETURNS
605 * Success: Handle to specified bitmap
606 * Failure: NULL
608 HBITMAP WINAPI LoadBitmapW(
609 HINSTANCE instance, /* [in] Handle to application instance */
610 LPCWSTR name) /* [in] Address of bitmap resource name */
612 return LoadImageW( instance, name, IMAGE_BITMAP, 0, 0, 0 );
615 /**********************************************************************
616 * LoadBitmapA (USER32.357)
618 HBITMAP WINAPI LoadBitmapA( HINSTANCE instance, LPCSTR name )
620 return LoadImageA( instance, name, IMAGE_BITMAP, 0, 0, 0 );
623 /**********************************************************************
624 * LoadBitmap16 (USER.175)
626 HBITMAP16 WINAPI LoadBitmap16( HINSTANCE16 instance, SEGPTR name )
628 LPCSTR nameStr = HIWORD(name)? PTR_SEG_TO_LIN(name) : (LPCSTR)name;
629 return LoadBitmapA( instance, nameStr );
634 /***********************************************************************
635 * BITMAP_DeleteObject
637 BOOL BITMAP_DeleteObject( HBITMAP16 hbitmap, BITMAPOBJ * bmp )
639 if( bmp->DDBitmap ) {
640 if( bmp->DDBitmap->funcs->pDeleteObject )
641 bmp->DDBitmap->funcs->pDeleteObject( hbitmap );
644 if( bmp->bitmap.bmBits )
645 HeapFree( GetProcessHeap(), 0, bmp->bitmap.bmBits );
647 DIB_DeleteDIBSection( bmp );
649 return GDI_FreeObject( hbitmap );
653 /***********************************************************************
654 * BITMAP_GetObject16
656 INT16 BITMAP_GetObject16( BITMAPOBJ * bmp, INT16 count, LPVOID buffer )
658 if (bmp->dib)
660 if ( count <= sizeof(BITMAP16) )
662 BITMAP *bmp32 = &bmp->dib->dsBm;
663 BITMAP16 bmp16;
664 bmp16.bmType = bmp32->bmType;
665 bmp16.bmWidth = bmp32->bmWidth;
666 bmp16.bmHeight = bmp32->bmHeight;
667 bmp16.bmWidthBytes = bmp32->bmWidthBytes;
668 bmp16.bmPlanes = bmp32->bmPlanes;
669 bmp16.bmBitsPixel = bmp32->bmBitsPixel;
670 bmp16.bmBits = (SEGPTR)0;
671 memcpy( buffer, &bmp16, count );
672 return count;
674 else
676 FIXME_(bitmap)("not implemented for DIBs: count %d\n", count);
677 return 0;
680 else
682 BITMAP16 bmp16;
683 bmp16.bmType = bmp->bitmap.bmType;
684 bmp16.bmWidth = bmp->bitmap.bmWidth;
685 bmp16.bmHeight = bmp->bitmap.bmHeight;
686 bmp16.bmWidthBytes = bmp->bitmap.bmWidthBytes;
687 bmp16.bmPlanes = bmp->bitmap.bmPlanes;
688 bmp16.bmBitsPixel = bmp->bitmap.bmBitsPixel;
689 bmp16.bmBits = (SEGPTR)0;
690 if (count > sizeof(bmp16)) count = sizeof(bmp16);
691 memcpy( buffer, &bmp16, count );
692 return count;
697 /***********************************************************************
698 * BITMAP_GetObject32
700 INT BITMAP_GetObject( BITMAPOBJ * bmp, INT count, LPVOID buffer )
702 if (bmp->dib)
704 if (count < sizeof(DIBSECTION))
706 if (count > sizeof(BITMAP)) count = sizeof(BITMAP);
708 else
710 if (count > sizeof(DIBSECTION)) count = sizeof(DIBSECTION);
713 memcpy( buffer, bmp->dib, count );
714 return count;
716 else
718 if (count > sizeof(BITMAP)) count = sizeof(BITMAP);
719 memcpy( buffer, &bmp->bitmap, count );
720 return count;
725 /***********************************************************************
726 * CreateDiscardableBitmap16 (GDI.156)
728 HBITMAP16 WINAPI CreateDiscardableBitmap16( HDC16 hdc, INT16 width,
729 INT16 height )
731 return CreateCompatibleBitmap16( hdc, width, height );
735 /******************************************************************************
736 * CreateDiscardableBitmap32 [GDI32.38] Creates a discardable bitmap
738 * RETURNS
739 * Success: Handle to bitmap
740 * Failure: NULL
742 HBITMAP WINAPI CreateDiscardableBitmap(
743 HDC hdc, /* [in] Handle to device context */
744 INT width, /* [in] Bitmap width */
745 INT height) /* [in] Bitmap height */
747 return CreateCompatibleBitmap( hdc, width, height );
751 /***********************************************************************
752 * GetBitmapDimensionEx16 (GDI.468)
754 * NOTES
755 * Can this call GetBitmapDimensionEx32?
757 BOOL16 WINAPI GetBitmapDimensionEx16( HBITMAP16 hbitmap, LPSIZE16 size )
759 BITMAPOBJ * bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC );
760 if (!bmp) return FALSE;
761 CONV_SIZE32TO16( &bmp->size, size );
762 GDI_HEAP_UNLOCK( hbitmap );
763 return TRUE;
767 /******************************************************************************
768 * GetBitmapDimensionEx32 [GDI32.144] Retrieves dimensions of a bitmap
770 * RETURNS
771 * Success: TRUE
772 * Failure: FALSE
774 BOOL WINAPI GetBitmapDimensionEx(
775 HBITMAP hbitmap, /* [in] Handle to bitmap */
776 LPSIZE size) /* [out] Address of struct receiving dimensions */
778 BITMAPOBJ * bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC );
779 if (!bmp) return FALSE;
780 *size = bmp->size;
781 GDI_HEAP_UNLOCK( hbitmap );
782 return TRUE;
786 /***********************************************************************
787 * GetBitmapDimension (GDI.162)
789 DWORD WINAPI GetBitmapDimension16( HBITMAP16 hbitmap )
791 SIZE16 size;
792 if (!GetBitmapDimensionEx16( hbitmap, &size )) return 0;
793 return MAKELONG( size.cx, size.cy );
797 /***********************************************************************
798 * SetBitmapDimensionEx16 (GDI.478)
800 BOOL16 WINAPI SetBitmapDimensionEx16( HBITMAP16 hbitmap, INT16 x, INT16 y,
801 LPSIZE16 prevSize )
803 BITMAPOBJ * bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC );
804 if (!bmp) return FALSE;
805 if (prevSize) CONV_SIZE32TO16( &bmp->size, prevSize );
806 bmp->size.cx = x;
807 bmp->size.cy = y;
808 GDI_HEAP_UNLOCK( hbitmap );
809 return TRUE;
813 /******************************************************************************
814 * SetBitmapDimensionEx32 [GDI32.304] Assignes dimensions to a bitmap
816 * RETURNS
817 * Success: TRUE
818 * Failure: FALSE
820 BOOL WINAPI SetBitmapDimensionEx(
821 HBITMAP hbitmap, /* [in] Handle to bitmap */
822 INT x, /* [in] Bitmap width */
823 INT y, /* [in] Bitmap height */
824 LPSIZE prevSize) /* [out] Address of structure for orig dims */
826 BITMAPOBJ * bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC );
827 if (!bmp) return FALSE;
828 if (prevSize) *prevSize = bmp->size;
829 bmp->size.cx = x;
830 bmp->size.cy = y;
831 GDI_HEAP_UNLOCK( hbitmap );
832 return TRUE;
836 /***********************************************************************
837 * SetBitmapDimension (GDI.163)
839 DWORD WINAPI SetBitmapDimension16( HBITMAP16 hbitmap, INT16 x, INT16 y )
841 SIZE16 size;
842 if (!SetBitmapDimensionEx16( hbitmap, x, y, &size )) return 0;
843 return MAKELONG( size.cx, size.cy );