Got rid of THREAD_InitDone.
[wine/multimedia.git] / objects / bitmap.c
blob4f191d080590307f358e3a6f41667feae089e154
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 "cursoricon.h"
18 #include "debugtools.h"
19 #include "monitor.h"
20 #include "wine/winuser16.h"
22 DECLARE_DEBUG_CHANNEL(bitmap)
23 DECLARE_DEBUG_CHANNEL(resource)
25 BITMAP_DRIVER *BITMAP_Driver = NULL;
28 /***********************************************************************
29 * BITMAP_GetWidthBytes
31 * Return number of bytes taken by a scanline of 16-bit aligned Windows DDB
32 * data.
34 INT BITMAP_GetWidthBytes( INT bmWidth, INT bpp )
36 switch(bpp)
38 case 1:
39 return 2 * ((bmWidth+15) >> 4);
41 case 24:
42 bmWidth *= 3; /* fall through */
43 case 8:
44 return bmWidth + (bmWidth & 1);
46 case 32:
47 return bmWidth * 4;
49 case 16:
50 case 15:
51 return bmWidth * 2;
53 case 4:
54 return 2 * ((bmWidth+3) >> 2);
56 default:
57 WARN_(bitmap)("Unknown depth %d, please report.\n", bpp );
59 return -1;
62 /***********************************************************************
63 * CreateUserBitmap16 (GDI.407)
65 HBITMAP16 WINAPI CreateUserBitmap16( INT16 width, INT16 height, UINT16 planes,
66 UINT16 bpp, LPCVOID bits )
68 return CreateBitmap16( width, height, planes, bpp, bits );
71 /***********************************************************************
72 * CreateUserDiscardableBitmap16 (GDI.409)
74 HBITMAP16 WINAPI CreateUserDiscardableBitmap16( WORD dummy,
75 INT16 width, INT16 height )
77 return CreateUserBitmap16( width, height, 1, MONITOR_GetDepth(&MONITOR_PrimaryMonitor), NULL );
81 /***********************************************************************
82 * CreateBitmap16 (GDI.48)
84 HBITMAP16 WINAPI CreateBitmap16( INT16 width, INT16 height, UINT16 planes,
85 UINT16 bpp, LPCVOID bits )
87 return CreateBitmap( width, height, planes, bpp, bits );
91 /******************************************************************************
92 * CreateBitmap32 [GDI32.25] Creates a bitmap with the specified info
94 * PARAMS
95 * width [I] bitmap width
96 * height [I] bitmap height
97 * planes [I] Number of color planes
98 * bpp [I] Number of bits to identify a color
99 * bits [I] Pointer to array containing color data
101 * RETURNS
102 * Success: Handle to bitmap
103 * Failure: 0
105 HBITMAP WINAPI CreateBitmap( INT width, INT height, UINT planes,
106 UINT bpp, LPCVOID bits )
108 BITMAPOBJ *bmp;
109 HBITMAP hbitmap;
111 planes = (BYTE)planes;
112 bpp = (BYTE)bpp;
115 /* Check parameters */
116 if (!height || !width) return 0;
117 if (planes != 1) {
118 FIXME_(bitmap)("planes = %d\n", planes);
119 return 0;
121 if (height < 0) height = -height;
122 if (width < 0) width = -width;
124 /* Create the BITMAPOBJ */
125 hbitmap = GDI_AllocObject( sizeof(BITMAPOBJ), BITMAP_MAGIC );
126 if (!hbitmap) return 0;
128 TRACE_(bitmap)("%dx%d, %d colors returning %08x\n", width, height,
129 1 << (planes*bpp), hbitmap);
131 bmp = (BITMAPOBJ *) GDI_HEAP_LOCK( hbitmap );
133 bmp->size.cx = 0;
134 bmp->size.cy = 0;
135 bmp->bitmap.bmType = 0;
136 bmp->bitmap.bmWidth = width;
137 bmp->bitmap.bmHeight = height;
138 bmp->bitmap.bmPlanes = planes;
139 bmp->bitmap.bmBitsPixel = bpp;
140 bmp->bitmap.bmWidthBytes = BITMAP_GetWidthBytes( width, bpp );
141 bmp->bitmap.bmBits = NULL;
143 bmp->DDBitmap = NULL;
144 bmp->dib = NULL;
146 if (bits) /* Set bitmap bits */
147 SetBitmapBits( hbitmap, height * bmp->bitmap.bmWidthBytes,
148 bits );
149 GDI_HEAP_UNLOCK( hbitmap );
150 return hbitmap;
154 /***********************************************************************
155 * CreateCompatibleBitmap16 (GDI.51)
157 HBITMAP16 WINAPI CreateCompatibleBitmap16(HDC16 hdc, INT16 width, INT16 height)
159 return CreateCompatibleBitmap( hdc, width, height );
163 /******************************************************************************
164 * CreateCompatibleBitmap32 [GDI32.30] Creates a bitmap compatible with the DC
166 * PARAMS
167 * hdc [I] Handle to device context
168 * width [I] Width of bitmap
169 * height [I] Height of bitmap
171 * RETURNS
172 * Success: Handle to bitmap
173 * Failure: 0
175 HBITMAP WINAPI CreateCompatibleBitmap( HDC hdc, INT width, INT height)
177 HBITMAP hbmpRet = 0;
178 DC *dc;
180 TRACE_(bitmap)("(%04x,%d,%d) = \n", hdc, width, height );
181 if (!(dc = DC_GetDCPtr( hdc ))) return 0;
182 if ((width >= 0x10000) || (height >= 0x10000)) {
183 FIXME_(bitmap)("got bad width %d or height %d, please look for reason\n",
184 width, height );
185 } else {
186 hbmpRet = CreateBitmap( width, height, 1, dc->w.bitsPerPixel, NULL );
187 if(dc->funcs->pCreateBitmap)
188 dc->funcs->pCreateBitmap( hbmpRet );
190 TRACE_(bitmap)("\t\t%04x\n", hbmpRet);
191 GDI_HEAP_UNLOCK(hdc);
192 return hbmpRet;
196 /***********************************************************************
197 * CreateBitmapIndirect16 (GDI.49)
199 HBITMAP16 WINAPI CreateBitmapIndirect16( const BITMAP16 * bmp )
201 return CreateBitmap16( bmp->bmWidth, bmp->bmHeight, bmp->bmPlanes,
202 bmp->bmBitsPixel, PTR_SEG_TO_LIN( bmp->bmBits ) );
206 /******************************************************************************
207 * CreateBitmapIndirect32 [GDI32.26] Creates a bitmap with the specifies info
209 * RETURNS
210 * Success: Handle to bitmap
211 * Failure: NULL
213 HBITMAP WINAPI CreateBitmapIndirect(
214 const BITMAP * bmp) /* [in] Pointer to the bitmap data */
216 return CreateBitmap( bmp->bmWidth, bmp->bmHeight, bmp->bmPlanes,
217 bmp->bmBitsPixel, bmp->bmBits );
221 /***********************************************************************
222 * GetBitmapBits16 (GDI.74)
224 LONG WINAPI GetBitmapBits16( HBITMAP16 hbitmap, LONG count, LPVOID buffer )
226 return GetBitmapBits( hbitmap, count, buffer );
230 /***********************************************************************
231 * GetBitmapBits32 [GDI32.143] Copies bitmap bits of bitmap to buffer
233 * RETURNS
234 * Success: Number of bytes copied
235 * Failure: 0
237 LONG WINAPI GetBitmapBits(
238 HBITMAP hbitmap, /* [in] Handle to bitmap */
239 LONG count, /* [in] Number of bytes to copy */
240 LPVOID bits) /* [out] Pointer to buffer to receive bits */
242 BITMAPOBJ *bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC );
243 LONG height, ret;
245 if (!bmp) return 0;
247 /* If the bits vector is null, the function should return the read size */
248 if(bits == NULL)
249 return bmp->bitmap.bmWidthBytes * bmp->bitmap.bmHeight;
251 if (count < 0) {
252 WARN_(bitmap)("(%ld): Negative number of bytes passed???\n", count );
253 count = -count;
256 /* Only get entire lines */
257 height = count / bmp->bitmap.bmWidthBytes;
258 if (height > bmp->bitmap.bmHeight) height = bmp->bitmap.bmHeight;
259 count = height * bmp->bitmap.bmWidthBytes;
260 if (count == 0)
262 WARN_(bitmap)("Less then one entire line requested\n");
263 GDI_HEAP_UNLOCK( hbitmap );
264 return 0;
268 TRACE_(bitmap)("(%08x, %ld, %p) %dx%d %d colors fetched height: %ld\n",
269 hbitmap, count, bits, bmp->bitmap.bmWidth, bmp->bitmap.bmHeight,
270 1 << bmp->bitmap.bmBitsPixel, height );
272 if(bmp->DDBitmap) {
274 TRACE_(bitmap)("Calling device specific BitmapBits\n");
275 if(bmp->DDBitmap->funcs->pBitmapBits)
276 ret = bmp->DDBitmap->funcs->pBitmapBits(hbitmap, bits, count,
277 DDB_GET);
278 else {
279 ERR_(bitmap)("BitmapBits == NULL??\n");
280 ret = 0;
283 } else {
285 if(!bmp->bitmap.bmBits) {
286 WARN_(bitmap)("Bitmap is empty\n");
287 ret = 0;
288 } else {
289 memcpy(bits, bmp->bitmap.bmBits, count);
290 ret = count;
295 GDI_HEAP_UNLOCK( hbitmap );
296 return ret;
300 /***********************************************************************
301 * SetBitmapBits16 (GDI.106)
303 LONG WINAPI SetBitmapBits16( HBITMAP16 hbitmap, LONG count, LPCVOID buffer )
305 return SetBitmapBits( hbitmap, count, buffer );
309 /******************************************************************************
310 * SetBitmapBits32 [GDI32.303] Sets bits of color data for a bitmap
312 * RETURNS
313 * Success: Number of bytes used in setting the bitmap bits
314 * Failure: 0
316 LONG WINAPI SetBitmapBits(
317 HBITMAP hbitmap, /* [in] Handle to bitmap */
318 LONG count, /* [in] Number of bytes in bitmap array */
319 LPCVOID bits) /* [in] Address of array with bitmap bits */
321 BITMAPOBJ *bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC );
322 LONG height, ret;
324 if ((!bmp) || (!bits))
325 return 0;
327 if (count < 0) {
328 WARN_(bitmap)("(%ld): Negative number of bytes passed???\n", count );
329 count = -count;
332 /* Only get entire lines */
333 height = count / bmp->bitmap.bmWidthBytes;
334 if (height > bmp->bitmap.bmHeight) height = bmp->bitmap.bmHeight;
335 count = height * bmp->bitmap.bmWidthBytes;
337 TRACE_(bitmap)("(%08x, %ld, %p) %dx%d %d colors fetched height: %ld\n",
338 hbitmap, count, bits, bmp->bitmap.bmWidth, bmp->bitmap.bmHeight,
339 1 << bmp->bitmap.bmBitsPixel, height );
341 if(bmp->DDBitmap) {
343 TRACE_(bitmap)("Calling device specific BitmapBits\n");
344 if(bmp->DDBitmap->funcs->pBitmapBits)
345 ret = bmp->DDBitmap->funcs->pBitmapBits(hbitmap, (void *) bits,
346 count, DDB_SET);
347 else {
348 ERR_(bitmap)("BitmapBits == NULL??\n");
349 ret = 0;
352 } else {
354 if(!bmp->bitmap.bmBits) /* Alloc enough for entire bitmap */
355 bmp->bitmap.bmBits = HeapAlloc( GetProcessHeap(), 0, count );
356 if(!bmp->bitmap.bmBits) {
357 WARN_(bitmap)("Unable to allocate bit buffer\n");
358 ret = 0;
359 } else {
360 memcpy(bmp->bitmap.bmBits, bits, count);
361 ret = count;
365 GDI_HEAP_UNLOCK( hbitmap );
366 return ret;
369 /***********************************************************************
370 * LoadImage16 [USER.389]
373 HANDLE16 WINAPI LoadImage16( HINSTANCE16 hinst, LPCSTR name, UINT16 type,
374 INT16 desiredx, INT16 desiredy, UINT16 loadflags)
376 LPCSTR nameStr = HIWORD(name)? PTR_SEG_TO_LIN(name) : (LPCSTR)name;
377 return LoadImageA( hinst, nameStr, type,
378 desiredx, desiredy, loadflags );
381 /**********************************************************************
382 * LoadImageA (USER32.365)
384 * FIXME: implementation lacks some features, see LR_ defines in windows.h
387 HANDLE WINAPI LoadImageA( HINSTANCE hinst, LPCSTR name, UINT type,
388 INT desiredx, INT desiredy, UINT loadflags)
390 HANDLE res;
391 LPWSTR u_name;
393 if (HIWORD(name)) u_name = HEAP_strdupAtoW(GetProcessHeap(), 0, name);
394 else u_name=(LPWSTR)name;
395 res = LoadImageW(hinst, u_name, type, desiredx, desiredy, loadflags);
396 if (HIWORD(name)) HeapFree(GetProcessHeap(), 0, u_name);
397 return res;
401 /******************************************************************************
402 * LoadImageW [USER32.366] Loads an icon, cursor, or bitmap
404 * PARAMS
405 * hinst [I] Handle of instance that contains image
406 * name [I] Name of image
407 * type [I] Type of image
408 * desiredx [I] Desired width
409 * desiredy [I] Desired height
410 * loadflags [I] Load flags
412 * RETURNS
413 * Success: Handle to newly loaded image
414 * Failure: NULL
416 * FIXME: Implementation lacks some features, see LR_ defines in windows.h
418 HANDLE WINAPI LoadImageW( HINSTANCE hinst, LPCWSTR name, UINT type,
419 INT desiredx, INT desiredy, UINT loadflags )
421 if (HIWORD(name)) {
422 TRACE_(resource)("(0x%04x,%p,%d,%d,%d,0x%08x)\n",
423 hinst,name,type,desiredx,desiredy,loadflags);
424 } else {
425 TRACE_(resource)("(0x%04x,%p,%d,%d,%d,0x%08x)\n",
426 hinst,name,type,desiredx,desiredy,loadflags);
428 if (loadflags & LR_DEFAULTSIZE) {
429 if (type == IMAGE_ICON) {
430 if (!desiredx) desiredx = GetSystemMetrics(SM_CXICON);
431 if (!desiredy) desiredy = GetSystemMetrics(SM_CYICON);
432 } else if (type == IMAGE_CURSOR) {
433 if (!desiredx) desiredx = GetSystemMetrics(SM_CXCURSOR);
434 if (!desiredy) desiredy = GetSystemMetrics(SM_CYCURSOR);
437 if (loadflags & LR_LOADFROMFILE) loadflags &= ~LR_SHARED;
438 switch (type) {
439 case IMAGE_BITMAP:
440 return BITMAP_Load( hinst, name, loadflags );
442 case IMAGE_ICON:
444 HDC hdc = GetDC(0);
445 UINT palEnts = GetSystemPaletteEntries(hdc, 0, 0, NULL);
446 if (palEnts == 0)
447 palEnts = 256;
448 ReleaseDC(0, hdc);
450 return CURSORICON_Load(hinst, name, desiredx, desiredy,
451 palEnts, FALSE, loadflags);
454 case IMAGE_CURSOR:
455 return CURSORICON_Load(hinst, name, desiredx, desiredy,
456 1, TRUE, loadflags);
458 return 0;
462 /**********************************************************************
463 * BITMAP_CopyBitmap
466 HBITMAP BITMAP_CopyBitmap(HBITMAP hbitmap)
468 BITMAPOBJ *bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC );
469 HBITMAP res = 0;
470 BITMAP bm;
472 if(!bmp) return 0;
474 bm = bmp->bitmap;
475 bm.bmBits = NULL;
476 res = CreateBitmapIndirect(&bm);
478 if(res) {
479 char *buf = HeapAlloc( GetProcessHeap(), 0, bm.bmWidthBytes *
480 bm.bmHeight );
481 GetBitmapBits (hbitmap, bm.bmWidthBytes * bm.bmHeight, buf);
482 SetBitmapBits (res, bm.bmWidthBytes * bm.bmHeight, buf);
483 HeapFree( GetProcessHeap(), 0, buf );
486 GDI_HEAP_UNLOCK( hbitmap );
487 return res;
490 /******************************************************************************
491 * CopyImage16 [USER.390] Creates new image and copies attributes to it
494 HICON16 WINAPI CopyImage16( HANDLE16 hnd, UINT16 type, INT16 desiredx,
495 INT16 desiredy, UINT16 flags )
497 return (HICON16)CopyImage((HANDLE)hnd, (UINT)type, (INT)desiredx,
498 (INT)desiredy, (UINT)flags);
501 /******************************************************************************
502 * CopyImage32 [USER32.61] Creates new image and copies attributes to it
504 * PARAMS
505 * hnd [I] Handle to image to copy
506 * type [I] Type of image to copy
507 * desiredx [I] Desired width of new image
508 * desiredy [I] Desired height of new image
509 * flags [I] Copy flags
511 * RETURNS
512 * Success: Handle to newly created image
513 * Failure: NULL
515 * FIXME: implementation still lacks nearly all features, see LR_*
516 * defines in windows.h
518 HICON WINAPI CopyImage( HANDLE hnd, UINT type, INT desiredx,
519 INT desiredy, UINT flags )
521 switch (type)
523 case IMAGE_BITMAP:
524 return BITMAP_CopyBitmap(hnd);
525 case IMAGE_ICON:
526 return CopyIcon(hnd);
527 case IMAGE_CURSOR:
528 return CopyCursor(hnd);
530 return 0;
533 /**********************************************************************
534 * BITMAP_Load
536 HBITMAP BITMAP_Load( HINSTANCE instance,LPCWSTR name, UINT loadflags )
538 HBITMAP hbitmap = 0;
539 HDC hdc;
540 HRSRC hRsrc;
541 HGLOBAL handle;
542 char *ptr = NULL;
543 BITMAPINFO *info, *fix_info=NULL;
544 HGLOBAL hFix;
545 int size;
547 if (!(loadflags & LR_LOADFROMFILE)) {
548 if (!instance) /* OEM bitmap */
550 HDC hdc;
551 DC *dc;
553 if (HIWORD((int)name)) return 0;
554 hdc = CreateDCA( "DISPLAY", NULL, NULL, NULL );
555 dc = DC_GetDCPtr( hdc );
556 if(dc->funcs->pLoadOEMResource)
557 hbitmap = dc->funcs->pLoadOEMResource( LOWORD((int)name),
558 OEM_BITMAP );
559 GDI_HEAP_UNLOCK( hdc );
560 DeleteDC( hdc );
561 return hbitmap;
564 if (!(hRsrc = FindResourceW( instance, name, RT_BITMAPW ))) return 0;
565 if (!(handle = LoadResource( instance, hRsrc ))) return 0;
567 if ((info = (BITMAPINFO *)LockResource( handle )) == NULL) return 0;
569 else
571 if (!(ptr = (char *)VIRTUAL_MapFileW( name ))) return 0;
572 info = (BITMAPINFO *)(ptr + sizeof(BITMAPFILEHEADER));
574 size = DIB_BitmapInfoSize(info, DIB_RGB_COLORS);
575 if ((hFix = GlobalAlloc(0, size))) fix_info=GlobalLock(hFix);
576 if (fix_info) {
577 BYTE pix;
579 memcpy(fix_info, info, size);
580 pix = *((LPBYTE)info+DIB_BitmapInfoSize(info, DIB_RGB_COLORS));
581 DIB_FixColorsToLoadflags(fix_info, loadflags, pix);
582 if ((hdc = GetDC(0)) != 0) {
583 char *bits = (char *)info + size;
584 if (loadflags & LR_CREATEDIBSECTION) {
585 DIBSECTION dib;
586 hbitmap = CreateDIBSection(hdc, fix_info, DIB_RGB_COLORS, NULL, 0, 0);
587 GetObjectA(hbitmap, sizeof(DIBSECTION), &dib);
588 SetDIBits(hdc, hbitmap, 0, dib.dsBm.bmHeight, bits, info,
589 DIB_RGB_COLORS);
591 else {
592 hbitmap = CreateDIBitmap( hdc, &fix_info->bmiHeader, CBM_INIT,
593 bits, fix_info, DIB_RGB_COLORS );
595 ReleaseDC( 0, hdc );
597 GlobalUnlock(hFix);
598 GlobalFree(hFix);
600 if (loadflags & LR_LOADFROMFILE) UnmapViewOfFile( ptr );
601 return hbitmap;
605 /******************************************************************************
606 * LoadBitmapW [USER32.358] Loads bitmap from the executable file
608 * RETURNS
609 * Success: Handle to specified bitmap
610 * Failure: NULL
612 HBITMAP WINAPI LoadBitmapW(
613 HINSTANCE instance, /* [in] Handle to application instance */
614 LPCWSTR name) /* [in] Address of bitmap resource name */
616 return LoadImageW( instance, name, IMAGE_BITMAP, 0, 0, 0 );
619 /**********************************************************************
620 * LoadBitmapA (USER32.357)
622 HBITMAP WINAPI LoadBitmapA( HINSTANCE instance, LPCSTR name )
624 return LoadImageA( instance, name, IMAGE_BITMAP, 0, 0, 0 );
627 /**********************************************************************
628 * LoadBitmap16 (USER.175)
630 HBITMAP16 WINAPI LoadBitmap16( HINSTANCE16 instance, SEGPTR name )
632 LPCSTR nameStr = HIWORD(name)? PTR_SEG_TO_LIN(name) : (LPCSTR)name;
633 return LoadBitmapA( instance, nameStr );
638 /***********************************************************************
639 * BITMAP_DeleteObject
641 BOOL BITMAP_DeleteObject( HBITMAP16 hbitmap, BITMAPOBJ * bmp )
643 if( bmp->DDBitmap ) {
644 if( bmp->DDBitmap->funcs->pDeleteObject )
645 bmp->DDBitmap->funcs->pDeleteObject( hbitmap );
648 if( bmp->bitmap.bmBits )
649 HeapFree( GetProcessHeap(), 0, bmp->bitmap.bmBits );
651 DIB_DeleteDIBSection( bmp );
653 return GDI_FreeObject( hbitmap );
657 /***********************************************************************
658 * BITMAP_GetObject16
660 INT16 BITMAP_GetObject16( BITMAPOBJ * bmp, INT16 count, LPVOID buffer )
662 if (bmp->dib)
664 if ( count <= sizeof(BITMAP16) )
666 BITMAP *bmp32 = &bmp->dib->dsBm;
667 BITMAP16 bmp16;
668 bmp16.bmType = bmp32->bmType;
669 bmp16.bmWidth = bmp32->bmWidth;
670 bmp16.bmHeight = bmp32->bmHeight;
671 bmp16.bmWidthBytes = bmp32->bmWidthBytes;
672 bmp16.bmPlanes = bmp32->bmPlanes;
673 bmp16.bmBitsPixel = bmp32->bmBitsPixel;
674 bmp16.bmBits = (SEGPTR)0;
675 memcpy( buffer, &bmp16, count );
676 return count;
678 else
680 FIXME_(bitmap)("not implemented for DIBs: count %d\n", count);
681 return 0;
684 else
686 BITMAP16 bmp16;
687 bmp16.bmType = bmp->bitmap.bmType;
688 bmp16.bmWidth = bmp->bitmap.bmWidth;
689 bmp16.bmHeight = bmp->bitmap.bmHeight;
690 bmp16.bmWidthBytes = bmp->bitmap.bmWidthBytes;
691 bmp16.bmPlanes = bmp->bitmap.bmPlanes;
692 bmp16.bmBitsPixel = bmp->bitmap.bmBitsPixel;
693 bmp16.bmBits = (SEGPTR)0;
694 if (count > sizeof(bmp16)) count = sizeof(bmp16);
695 memcpy( buffer, &bmp16, count );
696 return count;
701 /***********************************************************************
702 * BITMAP_GetObject32
704 INT BITMAP_GetObject( BITMAPOBJ * bmp, INT count, LPVOID buffer )
706 if (bmp->dib)
708 if (count < sizeof(DIBSECTION))
710 if (count > sizeof(BITMAP)) count = sizeof(BITMAP);
712 else
714 if (count > sizeof(DIBSECTION)) count = sizeof(DIBSECTION);
717 memcpy( buffer, bmp->dib, count );
718 return count;
720 else
722 if (count > sizeof(BITMAP)) count = sizeof(BITMAP);
723 memcpy( buffer, &bmp->bitmap, count );
724 return count;
729 /***********************************************************************
730 * CreateDiscardableBitmap16 (GDI.156)
732 HBITMAP16 WINAPI CreateDiscardableBitmap16( HDC16 hdc, INT16 width,
733 INT16 height )
735 return CreateCompatibleBitmap16( hdc, width, height );
739 /******************************************************************************
740 * CreateDiscardableBitmap32 [GDI32.38] Creates a discardable bitmap
742 * RETURNS
743 * Success: Handle to bitmap
744 * Failure: NULL
746 HBITMAP WINAPI CreateDiscardableBitmap(
747 HDC hdc, /* [in] Handle to device context */
748 INT width, /* [in] Bitmap width */
749 INT height) /* [in] Bitmap height */
751 return CreateCompatibleBitmap( hdc, width, height );
755 /***********************************************************************
756 * GetBitmapDimensionEx16 (GDI.468)
758 * NOTES
759 * Can this call GetBitmapDimensionEx32?
761 BOOL16 WINAPI GetBitmapDimensionEx16( HBITMAP16 hbitmap, LPSIZE16 size )
763 BITMAPOBJ * bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC );
764 if (!bmp) return FALSE;
765 CONV_SIZE32TO16( &bmp->size, size );
766 GDI_HEAP_UNLOCK( hbitmap );
767 return TRUE;
771 /******************************************************************************
772 * GetBitmapDimensionEx32 [GDI32.144] Retrieves dimensions of a bitmap
774 * RETURNS
775 * Success: TRUE
776 * Failure: FALSE
778 BOOL WINAPI GetBitmapDimensionEx(
779 HBITMAP hbitmap, /* [in] Handle to bitmap */
780 LPSIZE size) /* [out] Address of struct receiving dimensions */
782 BITMAPOBJ * bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC );
783 if (!bmp) return FALSE;
784 *size = bmp->size;
785 GDI_HEAP_UNLOCK( hbitmap );
786 return TRUE;
790 /***********************************************************************
791 * GetBitmapDimension (GDI.162)
793 DWORD WINAPI GetBitmapDimension16( HBITMAP16 hbitmap )
795 SIZE16 size;
796 if (!GetBitmapDimensionEx16( hbitmap, &size )) return 0;
797 return MAKELONG( size.cx, size.cy );
801 /***********************************************************************
802 * SetBitmapDimensionEx16 (GDI.478)
804 BOOL16 WINAPI SetBitmapDimensionEx16( HBITMAP16 hbitmap, INT16 x, INT16 y,
805 LPSIZE16 prevSize )
807 BITMAPOBJ * bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC );
808 if (!bmp) return FALSE;
809 if (prevSize) CONV_SIZE32TO16( &bmp->size, prevSize );
810 bmp->size.cx = x;
811 bmp->size.cy = y;
812 GDI_HEAP_UNLOCK( hbitmap );
813 return TRUE;
817 /******************************************************************************
818 * SetBitmapDimensionEx32 [GDI32.304] Assignes dimensions to a bitmap
820 * RETURNS
821 * Success: TRUE
822 * Failure: FALSE
824 BOOL WINAPI SetBitmapDimensionEx(
825 HBITMAP hbitmap, /* [in] Handle to bitmap */
826 INT x, /* [in] Bitmap width */
827 INT y, /* [in] Bitmap height */
828 LPSIZE prevSize) /* [out] Address of structure for orig dims */
830 BITMAPOBJ * bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC );
831 if (!bmp) return FALSE;
832 if (prevSize) *prevSize = bmp->size;
833 bmp->size.cx = x;
834 bmp->size.cy = y;
835 GDI_HEAP_UNLOCK( hbitmap );
836 return TRUE;
840 /***********************************************************************
841 * SetBitmapDimension (GDI.163)
843 DWORD WINAPI SetBitmapDimension16( HBITMAP16 hbitmap, INT16 x, INT16 y )
845 SIZE16 size;
846 if (!SetBitmapDimensionEx16( hbitmap, x, y, &size )) return 0;
847 return MAKELONG( size.cx, size.cy );