Added registry support to the server.
[wine.git] / objects / bitmap.c
blobc658ca538ddacc957ab0ce927b61f8efeef56e03
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 /* MS doc says if width or height is 0, return 1-by-1 pixel, monochrome bitmap */
187 if (!width || !height)
188 hbmpRet = CreateBitmap( 1, 1, 1, 1, NULL );
189 else
190 hbmpRet = CreateBitmap( width, height, 1, dc->w.bitsPerPixel, NULL );
191 if(dc->funcs->pCreateBitmap)
192 dc->funcs->pCreateBitmap( hbmpRet );
194 TRACE_(bitmap)("\t\t%04x\n", hbmpRet);
195 GDI_HEAP_UNLOCK(hdc);
196 return hbmpRet;
200 /***********************************************************************
201 * CreateBitmapIndirect16 (GDI.49)
203 HBITMAP16 WINAPI CreateBitmapIndirect16( const BITMAP16 * bmp )
205 return CreateBitmap16( bmp->bmWidth, bmp->bmHeight, bmp->bmPlanes,
206 bmp->bmBitsPixel, PTR_SEG_TO_LIN( bmp->bmBits ) );
210 /******************************************************************************
211 * CreateBitmapIndirect32 [GDI32.26] Creates a bitmap with the specifies info
213 * RETURNS
214 * Success: Handle to bitmap
215 * Failure: NULL
217 HBITMAP WINAPI CreateBitmapIndirect(
218 const BITMAP * bmp) /* [in] Pointer to the bitmap data */
220 return CreateBitmap( bmp->bmWidth, bmp->bmHeight, bmp->bmPlanes,
221 bmp->bmBitsPixel, bmp->bmBits );
225 /***********************************************************************
226 * GetBitmapBits16 (GDI.74)
228 LONG WINAPI GetBitmapBits16( HBITMAP16 hbitmap, LONG count, LPVOID buffer )
230 return GetBitmapBits( hbitmap, count, buffer );
234 /***********************************************************************
235 * GetBitmapBits32 [GDI32.143] Copies bitmap bits of bitmap to buffer
237 * RETURNS
238 * Success: Number of bytes copied
239 * Failure: 0
241 LONG WINAPI GetBitmapBits(
242 HBITMAP hbitmap, /* [in] Handle to bitmap */
243 LONG count, /* [in] Number of bytes to copy */
244 LPVOID bits) /* [out] Pointer to buffer to receive bits */
246 BITMAPOBJ *bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC );
247 LONG height, ret;
249 if (!bmp) return 0;
251 /* If the bits vector is null, the function should return the read size */
252 if(bits == NULL)
253 return bmp->bitmap.bmWidthBytes * bmp->bitmap.bmHeight;
255 if (count < 0) {
256 WARN_(bitmap)("(%ld): Negative number of bytes passed???\n", count );
257 count = -count;
260 /* Only get entire lines */
261 height = count / bmp->bitmap.bmWidthBytes;
262 if (height > bmp->bitmap.bmHeight) height = bmp->bitmap.bmHeight;
263 count = height * bmp->bitmap.bmWidthBytes;
264 if (count == 0)
266 WARN_(bitmap)("Less then one entire line requested\n");
267 GDI_HEAP_UNLOCK( hbitmap );
268 return 0;
272 TRACE_(bitmap)("(%08x, %ld, %p) %dx%d %d colors fetched height: %ld\n",
273 hbitmap, count, bits, bmp->bitmap.bmWidth, bmp->bitmap.bmHeight,
274 1 << bmp->bitmap.bmBitsPixel, height );
276 if(bmp->DDBitmap) {
278 TRACE_(bitmap)("Calling device specific BitmapBits\n");
279 if(bmp->DDBitmap->funcs->pBitmapBits)
280 ret = bmp->DDBitmap->funcs->pBitmapBits(hbitmap, bits, count,
281 DDB_GET);
282 else {
283 ERR_(bitmap)("BitmapBits == NULL??\n");
284 ret = 0;
287 } else {
289 if(!bmp->bitmap.bmBits) {
290 WARN_(bitmap)("Bitmap is empty\n");
291 ret = 0;
292 } else {
293 memcpy(bits, bmp->bitmap.bmBits, count);
294 ret = count;
299 GDI_HEAP_UNLOCK( hbitmap );
300 return ret;
304 /***********************************************************************
305 * SetBitmapBits16 (GDI.106)
307 LONG WINAPI SetBitmapBits16( HBITMAP16 hbitmap, LONG count, LPCVOID buffer )
309 return SetBitmapBits( hbitmap, count, buffer );
313 /******************************************************************************
314 * SetBitmapBits32 [GDI32.303] Sets bits of color data for a bitmap
316 * RETURNS
317 * Success: Number of bytes used in setting the bitmap bits
318 * Failure: 0
320 LONG WINAPI SetBitmapBits(
321 HBITMAP hbitmap, /* [in] Handle to bitmap */
322 LONG count, /* [in] Number of bytes in bitmap array */
323 LPCVOID bits) /* [in] Address of array with bitmap bits */
325 BITMAPOBJ *bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC );
326 LONG height, ret;
328 if ((!bmp) || (!bits))
329 return 0;
331 if (count < 0) {
332 WARN_(bitmap)("(%ld): Negative number of bytes passed???\n", count );
333 count = -count;
336 /* Only get entire lines */
337 height = count / bmp->bitmap.bmWidthBytes;
338 if (height > bmp->bitmap.bmHeight) height = bmp->bitmap.bmHeight;
339 count = height * bmp->bitmap.bmWidthBytes;
341 TRACE_(bitmap)("(%08x, %ld, %p) %dx%d %d colors fetched height: %ld\n",
342 hbitmap, count, bits, bmp->bitmap.bmWidth, bmp->bitmap.bmHeight,
343 1 << bmp->bitmap.bmBitsPixel, height );
345 if(bmp->DDBitmap) {
347 TRACE_(bitmap)("Calling device specific BitmapBits\n");
348 if(bmp->DDBitmap->funcs->pBitmapBits)
349 ret = bmp->DDBitmap->funcs->pBitmapBits(hbitmap, (void *) bits,
350 count, DDB_SET);
351 else {
352 ERR_(bitmap)("BitmapBits == NULL??\n");
353 ret = 0;
356 } else {
358 if(!bmp->bitmap.bmBits) /* Alloc enough for entire bitmap */
359 bmp->bitmap.bmBits = HeapAlloc( GetProcessHeap(), 0, count );
360 if(!bmp->bitmap.bmBits) {
361 WARN_(bitmap)("Unable to allocate bit buffer\n");
362 ret = 0;
363 } else {
364 memcpy(bmp->bitmap.bmBits, bits, count);
365 ret = count;
369 GDI_HEAP_UNLOCK( hbitmap );
370 return ret;
373 /***********************************************************************
374 * LoadImage16 [USER.389]
377 HANDLE16 WINAPI LoadImage16( HINSTANCE16 hinst, LPCSTR name, UINT16 type,
378 INT16 desiredx, INT16 desiredy, UINT16 loadflags)
380 LPCSTR nameStr = HIWORD(name)? PTR_SEG_TO_LIN(name) : (LPCSTR)name;
381 return LoadImageA( hinst, nameStr, type,
382 desiredx, desiredy, loadflags );
385 /**********************************************************************
386 * LoadImageA (USER32.365)
388 * FIXME: implementation lacks some features, see LR_ defines in windows.h
391 HANDLE WINAPI LoadImageA( HINSTANCE hinst, LPCSTR name, UINT type,
392 INT desiredx, INT desiredy, UINT loadflags)
394 HANDLE res;
395 LPWSTR u_name;
397 if (HIWORD(name)) u_name = HEAP_strdupAtoW(GetProcessHeap(), 0, name);
398 else u_name=(LPWSTR)name;
399 res = LoadImageW(hinst, u_name, type, desiredx, desiredy, loadflags);
400 if (HIWORD(name)) HeapFree(GetProcessHeap(), 0, u_name);
401 return res;
405 /******************************************************************************
406 * LoadImageW [USER32.366] Loads an icon, cursor, or bitmap
408 * PARAMS
409 * hinst [I] Handle of instance that contains image
410 * name [I] Name of image
411 * type [I] Type of image
412 * desiredx [I] Desired width
413 * desiredy [I] Desired height
414 * loadflags [I] Load flags
416 * RETURNS
417 * Success: Handle to newly loaded image
418 * Failure: NULL
420 * FIXME: Implementation lacks some features, see LR_ defines in windows.h
422 HANDLE WINAPI LoadImageW( HINSTANCE hinst, LPCWSTR name, UINT type,
423 INT desiredx, INT desiredy, UINT loadflags )
425 if (HIWORD(name)) {
426 TRACE_(resource)("(0x%04x,%p,%d,%d,%d,0x%08x)\n",
427 hinst,name,type,desiredx,desiredy,loadflags);
428 } else {
429 TRACE_(resource)("(0x%04x,%p,%d,%d,%d,0x%08x)\n",
430 hinst,name,type,desiredx,desiredy,loadflags);
432 if (loadflags & LR_DEFAULTSIZE) {
433 if (type == IMAGE_ICON) {
434 if (!desiredx) desiredx = GetSystemMetrics(SM_CXICON);
435 if (!desiredy) desiredy = GetSystemMetrics(SM_CYICON);
436 } else if (type == IMAGE_CURSOR) {
437 if (!desiredx) desiredx = GetSystemMetrics(SM_CXCURSOR);
438 if (!desiredy) desiredy = GetSystemMetrics(SM_CYCURSOR);
441 if (loadflags & LR_LOADFROMFILE) loadflags &= ~LR_SHARED;
442 switch (type) {
443 case IMAGE_BITMAP:
444 return BITMAP_Load( hinst, name, loadflags );
446 case IMAGE_ICON:
448 HDC hdc = GetDC(0);
449 UINT palEnts = GetSystemPaletteEntries(hdc, 0, 0, NULL);
450 if (palEnts == 0)
451 palEnts = 256;
452 ReleaseDC(0, hdc);
454 return CURSORICON_Load(hinst, name, desiredx, desiredy,
455 palEnts, FALSE, loadflags);
458 case IMAGE_CURSOR:
459 return CURSORICON_Load(hinst, name, desiredx, desiredy,
460 1, TRUE, loadflags);
462 return 0;
466 /**********************************************************************
467 * BITMAP_CopyBitmap
470 HBITMAP BITMAP_CopyBitmap(HBITMAP hbitmap)
472 BITMAPOBJ *bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC );
473 HBITMAP res = 0;
474 BITMAP bm;
476 if(!bmp) return 0;
478 bm = bmp->bitmap;
479 bm.bmBits = NULL;
480 res = CreateBitmapIndirect(&bm);
482 if(res) {
483 char *buf = HeapAlloc( GetProcessHeap(), 0, bm.bmWidthBytes *
484 bm.bmHeight );
485 GetBitmapBits (hbitmap, bm.bmWidthBytes * bm.bmHeight, buf);
486 SetBitmapBits (res, bm.bmWidthBytes * bm.bmHeight, buf);
487 HeapFree( GetProcessHeap(), 0, buf );
490 GDI_HEAP_UNLOCK( hbitmap );
491 return res;
494 /******************************************************************************
495 * CopyImage16 [USER.390] Creates new image and copies attributes to it
498 HICON16 WINAPI CopyImage16( HANDLE16 hnd, UINT16 type, INT16 desiredx,
499 INT16 desiredy, UINT16 flags )
501 return (HICON16)CopyImage((HANDLE)hnd, (UINT)type, (INT)desiredx,
502 (INT)desiredy, (UINT)flags);
505 /******************************************************************************
506 * CopyImage32 [USER32.61] Creates new image and copies attributes to it
508 * PARAMS
509 * hnd [I] Handle to image to copy
510 * type [I] Type of image to copy
511 * desiredx [I] Desired width of new image
512 * desiredy [I] Desired height of new image
513 * flags [I] Copy flags
515 * RETURNS
516 * Success: Handle to newly created image
517 * Failure: NULL
519 * FIXME: implementation still lacks nearly all features, see LR_*
520 * defines in windows.h
522 HICON WINAPI CopyImage( HANDLE hnd, UINT type, INT desiredx,
523 INT desiredy, UINT flags )
525 switch (type)
527 case IMAGE_BITMAP:
528 return BITMAP_CopyBitmap(hnd);
529 case IMAGE_ICON:
530 return CURSORICON_ExtCopy(hnd,type, desiredx, desiredy, flags);
531 case IMAGE_CURSOR:
532 /* Should call CURSORICON_ExtCopy but more testing
533 * needs to be done before we change this
535 return CopyCursor(hnd);
537 return 0;
540 /**********************************************************************
541 * BITMAP_Load
543 HBITMAP BITMAP_Load( HINSTANCE instance,LPCWSTR name, UINT loadflags )
545 HBITMAP hbitmap = 0;
546 HDC hdc;
547 HRSRC hRsrc;
548 HGLOBAL handle;
549 char *ptr = NULL;
550 BITMAPINFO *info, *fix_info=NULL;
551 HGLOBAL hFix;
552 int size;
554 if (!(loadflags & LR_LOADFROMFILE)) {
555 if (!instance) /* OEM bitmap */
557 HDC hdc;
558 DC *dc;
560 if (HIWORD((int)name)) return 0;
561 hdc = CreateDCA( "DISPLAY", NULL, NULL, NULL );
562 dc = DC_GetDCPtr( hdc );
563 if(dc->funcs->pLoadOEMResource)
564 hbitmap = dc->funcs->pLoadOEMResource( LOWORD((int)name),
565 OEM_BITMAP );
566 GDI_HEAP_UNLOCK( hdc );
567 DeleteDC( hdc );
568 return hbitmap;
571 if (!(hRsrc = FindResourceW( instance, name, RT_BITMAPW ))) return 0;
572 if (!(handle = LoadResource( instance, hRsrc ))) return 0;
574 if ((info = (BITMAPINFO *)LockResource( handle )) == NULL) return 0;
576 else
578 if (!(ptr = (char *)VIRTUAL_MapFileW( name ))) return 0;
579 info = (BITMAPINFO *)(ptr + sizeof(BITMAPFILEHEADER));
581 size = DIB_BitmapInfoSize(info, DIB_RGB_COLORS);
582 if ((hFix = GlobalAlloc(0, size))) fix_info=GlobalLock(hFix);
583 if (fix_info) {
584 BYTE pix;
586 memcpy(fix_info, info, size);
587 pix = *((LPBYTE)info+DIB_BitmapInfoSize(info, DIB_RGB_COLORS));
588 DIB_FixColorsToLoadflags(fix_info, loadflags, pix);
589 if ((hdc = GetDC(0)) != 0) {
590 char *bits = (char *)info + size;
591 if (loadflags & LR_CREATEDIBSECTION) {
592 DIBSECTION dib;
593 hbitmap = CreateDIBSection(hdc, fix_info, DIB_RGB_COLORS, NULL, 0, 0);
594 GetObjectA(hbitmap, sizeof(DIBSECTION), &dib);
595 SetDIBits(hdc, hbitmap, 0, dib.dsBm.bmHeight, bits, info,
596 DIB_RGB_COLORS);
598 else {
599 hbitmap = CreateDIBitmap( hdc, &fix_info->bmiHeader, CBM_INIT,
600 bits, fix_info, DIB_RGB_COLORS );
602 ReleaseDC( 0, hdc );
604 GlobalUnlock(hFix);
605 GlobalFree(hFix);
607 if (loadflags & LR_LOADFROMFILE) UnmapViewOfFile( ptr );
608 return hbitmap;
612 /******************************************************************************
613 * LoadBitmapW [USER32.358] Loads bitmap from the executable file
615 * RETURNS
616 * Success: Handle to specified bitmap
617 * Failure: NULL
619 HBITMAP WINAPI LoadBitmapW(
620 HINSTANCE instance, /* [in] Handle to application instance */
621 LPCWSTR name) /* [in] Address of bitmap resource name */
623 return LoadImageW( instance, name, IMAGE_BITMAP, 0, 0, 0 );
626 /**********************************************************************
627 * LoadBitmapA (USER32.357)
629 HBITMAP WINAPI LoadBitmapA( HINSTANCE instance, LPCSTR name )
631 return LoadImageA( instance, name, IMAGE_BITMAP, 0, 0, 0 );
634 /**********************************************************************
635 * LoadBitmap16 (USER.175)
637 HBITMAP16 WINAPI LoadBitmap16( HINSTANCE16 instance, SEGPTR name )
639 LPCSTR nameStr = HIWORD(name)? PTR_SEG_TO_LIN(name) : (LPCSTR)name;
640 return LoadBitmapA( instance, nameStr );
645 /***********************************************************************
646 * BITMAP_DeleteObject
648 BOOL BITMAP_DeleteObject( HBITMAP16 hbitmap, BITMAPOBJ * bmp )
650 if( bmp->DDBitmap ) {
651 if( bmp->DDBitmap->funcs->pDeleteObject )
652 bmp->DDBitmap->funcs->pDeleteObject( hbitmap );
655 if( bmp->bitmap.bmBits )
656 HeapFree( GetProcessHeap(), 0, bmp->bitmap.bmBits );
658 DIB_DeleteDIBSection( bmp );
660 return GDI_FreeObject( hbitmap );
664 /***********************************************************************
665 * BITMAP_GetObject16
667 INT16 BITMAP_GetObject16( BITMAPOBJ * bmp, INT16 count, LPVOID buffer )
669 if (bmp->dib)
671 if ( count <= sizeof(BITMAP16) )
673 BITMAP *bmp32 = &bmp->dib->dsBm;
674 BITMAP16 bmp16;
675 bmp16.bmType = bmp32->bmType;
676 bmp16.bmWidth = bmp32->bmWidth;
677 bmp16.bmHeight = bmp32->bmHeight;
678 bmp16.bmWidthBytes = bmp32->bmWidthBytes;
679 bmp16.bmPlanes = bmp32->bmPlanes;
680 bmp16.bmBitsPixel = bmp32->bmBitsPixel;
681 bmp16.bmBits = (SEGPTR)0;
682 memcpy( buffer, &bmp16, count );
683 return count;
685 else
687 FIXME_(bitmap)("not implemented for DIBs: count %d\n", count);
688 return 0;
691 else
693 BITMAP16 bmp16;
694 bmp16.bmType = bmp->bitmap.bmType;
695 bmp16.bmWidth = bmp->bitmap.bmWidth;
696 bmp16.bmHeight = bmp->bitmap.bmHeight;
697 bmp16.bmWidthBytes = bmp->bitmap.bmWidthBytes;
698 bmp16.bmPlanes = bmp->bitmap.bmPlanes;
699 bmp16.bmBitsPixel = bmp->bitmap.bmBitsPixel;
700 bmp16.bmBits = (SEGPTR)0;
701 if (count > sizeof(bmp16)) count = sizeof(bmp16);
702 memcpy( buffer, &bmp16, count );
703 return count;
708 /***********************************************************************
709 * BITMAP_GetObject32
711 INT BITMAP_GetObject( BITMAPOBJ * bmp, INT count, LPVOID buffer )
713 if (bmp->dib)
715 if (count < sizeof(DIBSECTION))
717 if (count > sizeof(BITMAP)) count = sizeof(BITMAP);
719 else
721 if (count > sizeof(DIBSECTION)) count = sizeof(DIBSECTION);
724 memcpy( buffer, bmp->dib, count );
725 return count;
727 else
729 if (count > sizeof(BITMAP)) count = sizeof(BITMAP);
730 memcpy( buffer, &bmp->bitmap, count );
731 return count;
736 /***********************************************************************
737 * CreateDiscardableBitmap16 (GDI.156)
739 HBITMAP16 WINAPI CreateDiscardableBitmap16( HDC16 hdc, INT16 width,
740 INT16 height )
742 return CreateCompatibleBitmap16( hdc, width, height );
746 /******************************************************************************
747 * CreateDiscardableBitmap32 [GDI32.38] Creates a discardable bitmap
749 * RETURNS
750 * Success: Handle to bitmap
751 * Failure: NULL
753 HBITMAP WINAPI CreateDiscardableBitmap(
754 HDC hdc, /* [in] Handle to device context */
755 INT width, /* [in] Bitmap width */
756 INT height) /* [in] Bitmap height */
758 return CreateCompatibleBitmap( hdc, width, height );
762 /***********************************************************************
763 * GetBitmapDimensionEx16 (GDI.468)
765 * NOTES
766 * Can this call GetBitmapDimensionEx32?
768 BOOL16 WINAPI GetBitmapDimensionEx16( HBITMAP16 hbitmap, LPSIZE16 size )
770 BITMAPOBJ * bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC );
771 if (!bmp) return FALSE;
772 CONV_SIZE32TO16( &bmp->size, size );
773 GDI_HEAP_UNLOCK( hbitmap );
774 return TRUE;
778 /******************************************************************************
779 * GetBitmapDimensionEx32 [GDI32.144] Retrieves dimensions of a bitmap
781 * RETURNS
782 * Success: TRUE
783 * Failure: FALSE
785 BOOL WINAPI GetBitmapDimensionEx(
786 HBITMAP hbitmap, /* [in] Handle to bitmap */
787 LPSIZE size) /* [out] Address of struct receiving dimensions */
789 BITMAPOBJ * bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC );
790 if (!bmp) return FALSE;
791 *size = bmp->size;
792 GDI_HEAP_UNLOCK( hbitmap );
793 return TRUE;
797 /***********************************************************************
798 * GetBitmapDimension (GDI.162)
800 DWORD WINAPI GetBitmapDimension16( HBITMAP16 hbitmap )
802 SIZE16 size;
803 if (!GetBitmapDimensionEx16( hbitmap, &size )) return 0;
804 return MAKELONG( size.cx, size.cy );
808 /***********************************************************************
809 * SetBitmapDimensionEx16 (GDI.478)
811 BOOL16 WINAPI SetBitmapDimensionEx16( HBITMAP16 hbitmap, INT16 x, INT16 y,
812 LPSIZE16 prevSize )
814 BITMAPOBJ * bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC );
815 if (!bmp) return FALSE;
816 if (prevSize) CONV_SIZE32TO16( &bmp->size, prevSize );
817 bmp->size.cx = x;
818 bmp->size.cy = y;
819 GDI_HEAP_UNLOCK( hbitmap );
820 return TRUE;
824 /******************************************************************************
825 * SetBitmapDimensionEx32 [GDI32.304] Assignes dimensions to a bitmap
827 * RETURNS
828 * Success: TRUE
829 * Failure: FALSE
831 BOOL WINAPI SetBitmapDimensionEx(
832 HBITMAP hbitmap, /* [in] Handle to bitmap */
833 INT x, /* [in] Bitmap width */
834 INT y, /* [in] Bitmap height */
835 LPSIZE prevSize) /* [out] Address of structure for orig dims */
837 BITMAPOBJ * bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC );
838 if (!bmp) return FALSE;
839 if (prevSize) *prevSize = bmp->size;
840 bmp->size.cx = x;
841 bmp->size.cy = y;
842 GDI_HEAP_UNLOCK( hbitmap );
843 return TRUE;
847 /***********************************************************************
848 * SetBitmapDimension (GDI.163)
850 DWORD WINAPI SetBitmapDimension16( HBITMAP16 hbitmap, INT16 x, INT16 y )
852 SIZE16 size;
853 if (!SetBitmapDimensionEx16( hbitmap, x, y, &size )) return 0;
854 return MAKELONG( size.cx, size.cy );