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