change default iSmCaptionWidth to 12
[wine/kumbayo.git] / dlls / gdi32 / bitmap.c
blob33555413517d3069cc3e939a018bc5b1c319ff57
1 /*
2 * GDI bitmap objects
4 * Copyright 1993 Alexandre Julliard
5 * 1998 Huw D M Davies
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include <stdarg.h>
23 #include <stdlib.h>
24 #include <string.h>
26 #include "windef.h"
27 #include "winbase.h"
28 #include "wingdi.h"
29 #include "wine/winbase16.h"
30 #include "gdi_private.h"
31 #include "wine/debug.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(bitmap);
36 static HGDIOBJ BITMAP_SelectObject( HGDIOBJ handle, HDC hdc );
37 static INT BITMAP_GetObject16( HGDIOBJ handle, void *obj, INT count, LPVOID buffer );
38 static INT BITMAP_GetObject( HGDIOBJ handle, void *obj, INT count, LPVOID buffer );
39 static BOOL BITMAP_DeleteObject( HGDIOBJ handle, void *obj );
41 static const struct gdi_obj_funcs bitmap_funcs =
43 BITMAP_SelectObject, /* pSelectObject */
44 BITMAP_GetObject16, /* pGetObject16 */
45 BITMAP_GetObject, /* pGetObjectA */
46 BITMAP_GetObject, /* pGetObjectW */
47 NULL, /* pUnrealizeObject */
48 BITMAP_DeleteObject /* pDeleteObject */
51 /***********************************************************************
52 * BITMAP_GetWidthBytes
54 * Return number of bytes taken by a scanline of 16-bit aligned Windows DDB
55 * data.
57 INT BITMAP_GetWidthBytes( INT bmWidth, INT bpp )
59 switch(bpp)
61 case 1:
62 return 2 * ((bmWidth+15) >> 4);
64 case 24:
65 bmWidth *= 3; /* fall through */
66 case 8:
67 return bmWidth + (bmWidth & 1);
69 case 32:
70 return bmWidth * 4;
72 case 16:
73 case 15:
74 return bmWidth * 2;
76 case 4:
77 return 2 * ((bmWidth+3) >> 2);
79 default:
80 WARN("Unknown depth %d, please report.\n", bpp );
82 return -1;
86 /******************************************************************************
87 * CreateBitmap [GDI32.@]
89 * Creates a bitmap with the specified info.
91 * PARAMS
92 * width [I] bitmap width
93 * height [I] bitmap height
94 * planes [I] Number of color planes
95 * bpp [I] Number of bits to identify a color
96 * bits [I] Pointer to array containing color data
98 * RETURNS
99 * Success: Handle to bitmap
100 * Failure: 0
102 HBITMAP WINAPI CreateBitmap( INT width, INT height, UINT planes,
103 UINT bpp, LPCVOID bits )
105 BITMAP bm;
107 bm.bmType = 0;
108 bm.bmWidth = width;
109 bm.bmHeight = height;
110 bm.bmWidthBytes = BITMAP_GetWidthBytes( width, bpp );
111 bm.bmPlanes = planes;
112 bm.bmBitsPixel = bpp;
113 bm.bmBits = (LPVOID)bits;
115 return CreateBitmapIndirect( &bm );
118 /******************************************************************************
119 * CreateCompatibleBitmap [GDI32.@]
121 * Creates a bitmap compatible with the DC.
123 * PARAMS
124 * hdc [I] Handle to device context
125 * width [I] Width of bitmap
126 * height [I] Height of bitmap
128 * RETURNS
129 * Success: Handle to bitmap
130 * Failure: 0
132 HBITMAP WINAPI CreateCompatibleBitmap( HDC hdc, INT width, INT height)
134 HBITMAP hbmpRet = 0;
135 DC *dc;
137 TRACE("(%p,%d,%d) =\n", hdc, width, height);
139 if ((width >= 0x10000) || (height >= 0x10000))
141 FIXME("got bad width %d or height %d, please look for reason\n",
142 width, height);
144 else
146 if (!(dc = DC_GetDCPtr(hdc))) return 0;
148 if (GDIMAGIC( dc->header.wMagic ) != MEMORY_DC_MAGIC)
150 hbmpRet = CreateBitmap(width, height,
151 GetDeviceCaps(hdc, PLANES),
152 GetDeviceCaps(hdc, BITSPIXEL),
153 NULL);
155 else /* Memory DC */
157 BITMAPOBJ *bmp = GDI_GetObjPtr( dc->hBitmap, BITMAP_MAGIC );
159 if (!bmp->dib)
161 /* A device-dependent bitmap is selected in the DC */
162 hbmpRet = CreateBitmap(width, height,
163 bmp->bitmap.bmPlanes,
164 bmp->bitmap.bmBitsPixel,
165 NULL);
167 else
169 /* A DIB section is selected in the DC */
170 BITMAPINFO *bi;
171 void *bits;
173 /* Allocate memory for a BITMAPINFOHEADER structure and a
174 color table. The maximum number of colors in a color table
175 is 256 which corresponds to a bitmap with depth 8.
176 Bitmaps with higher depths don't have color tables. */
177 bi = HeapAlloc(GetProcessHeap(), 0, sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD));
179 if (bi)
181 bi->bmiHeader.biSize = sizeof(bi->bmiHeader);
182 bi->bmiHeader.biWidth = width;
183 bi->bmiHeader.biHeight = height;
184 bi->bmiHeader.biPlanes = bmp->dib->dsBmih.biPlanes;
185 bi->bmiHeader.biBitCount = bmp->dib->dsBmih.biBitCount;
186 bi->bmiHeader.biCompression = bmp->dib->dsBmih.biCompression;
187 bi->bmiHeader.biSizeImage = 0;
188 bi->bmiHeader.biXPelsPerMeter = bmp->dib->dsBmih.biXPelsPerMeter;
189 bi->bmiHeader.biYPelsPerMeter = bmp->dib->dsBmih.biYPelsPerMeter;
190 bi->bmiHeader.biClrUsed = bmp->dib->dsBmih.biClrUsed;
191 bi->bmiHeader.biClrImportant = bmp->dib->dsBmih.biClrImportant;
193 if (bi->bmiHeader.biCompression == BI_BITFIELDS)
195 /* Copy the color masks */
196 CopyMemory(bi->bmiColors, bmp->dib->dsBitfields, 3 * sizeof(DWORD));
198 else if (bi->bmiHeader.biBitCount <= 8)
200 /* Copy the color table */
201 GetDIBColorTable(hdc, 0, 256, bi->bmiColors);
204 hbmpRet = CreateDIBSection(hdc, bi, DIB_RGB_COLORS, &bits, NULL, 0);
205 HeapFree(GetProcessHeap(), 0, bi);
208 GDI_ReleaseObj(dc->hBitmap);
210 DC_ReleaseDCPtr( dc );
213 TRACE("\t\t%p\n", hbmpRet);
214 return hbmpRet;
218 /******************************************************************************
219 * CreateBitmapIndirect [GDI32.@]
221 * Creates a bitmap with the specified info.
223 * PARAMS
224 * bmp [I] Pointer to the bitmap info describing the bitmap
226 * RETURNS
227 * Success: Handle to bitmap
228 * Failure: NULL. Use GetLastError() to determine the cause.
230 * NOTES
231 * If a width or height of 0 are given, a 1x1 monochrome bitmap is returned.
233 HBITMAP WINAPI CreateBitmapIndirect( const BITMAP *bmp )
235 BITMAP bm;
236 BITMAPOBJ *bmpobj;
237 HBITMAP hbitmap;
239 if (!bmp || bmp->bmType)
241 SetLastError( ERROR_INVALID_PARAMETER );
242 return NULL;
245 bm = *bmp;
247 if (!bm.bmWidth || !bm.bmHeight)
249 return GetStockObject( DEFAULT_BITMAP );
251 else
253 if (bm.bmHeight < 0)
254 bm.bmHeight = -bm.bmHeight;
255 if (bm.bmWidth < 0)
256 bm.bmWidth = -bm.bmWidth;
259 if (bm.bmPlanes != 1)
261 FIXME("planes = %d\n", bm.bmPlanes);
262 SetLastError( ERROR_INVALID_PARAMETER );
263 return NULL;
266 /* Windows only uses 1, 4, 8, 16, 24 and 32 bpp */
267 if(bm.bmBitsPixel == 1) bm.bmBitsPixel = 1;
268 else if(bm.bmBitsPixel <= 4) bm.bmBitsPixel = 4;
269 else if(bm.bmBitsPixel <= 8) bm.bmBitsPixel = 8;
270 else if(bm.bmBitsPixel <= 16) bm.bmBitsPixel = 16;
271 else if(bm.bmBitsPixel <= 24) bm.bmBitsPixel = 24;
272 else if(bm.bmBitsPixel <= 32) bm.bmBitsPixel = 32;
273 else {
274 WARN("Invalid bmBitsPixel %d, returning ERROR_INVALID_PARAMETER\n", bm.bmBitsPixel);
275 SetLastError(ERROR_INVALID_PARAMETER);
276 return NULL;
279 /* Windows ignores the provided bm.bmWidthBytes */
280 bm.bmWidthBytes = BITMAP_GetWidthBytes( bm.bmWidth, bm.bmBitsPixel );
282 /* Create the BITMAPOBJ */
283 bmpobj = GDI_AllocObject( sizeof(BITMAPOBJ), BITMAP_MAGIC,
284 (HGDIOBJ *)&hbitmap, &bitmap_funcs );
286 if (!bmpobj)
288 SetLastError( ERROR_NOT_ENOUGH_MEMORY );
289 return NULL;
292 TRACE("%dx%d, %d colors returning %p\n", bm.bmWidth, bm.bmHeight,
293 1 << (bm.bmPlanes * bm.bmBitsPixel), hbitmap);
295 bmpobj->size.cx = 0;
296 bmpobj->size.cy = 0;
297 bmpobj->bitmap = bm;
298 bmpobj->bitmap.bmBits = NULL;
299 bmpobj->funcs = NULL;
300 bmpobj->dib = NULL;
301 bmpobj->segptr_bits = 0;
302 bmpobj->color_table = NULL;
303 bmpobj->nb_colors = 0;
305 if (bm.bmBits)
306 SetBitmapBits( hbitmap, bm.bmHeight * bm.bmWidthBytes, bm.bmBits );
308 GDI_ReleaseObj( hbitmap );
309 return hbitmap;
313 /***********************************************************************
314 * GetBitmapBits [GDI32.@]
316 * Copies bitmap bits of bitmap to buffer.
318 * RETURNS
319 * Success: Number of bytes copied
320 * Failure: 0
322 LONG WINAPI GetBitmapBits(
323 HBITMAP hbitmap, /* [in] Handle to bitmap */
324 LONG count, /* [in] Number of bytes to copy */
325 LPVOID bits) /* [out] Pointer to buffer to receive bits */
327 BITMAPOBJ *bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC );
328 LONG height, ret;
330 if (!bmp) return 0;
332 if (bmp->dib) /* simply copy the bits from the DIB */
334 DIBSECTION *dib = bmp->dib;
335 const char *src = dib->dsBm.bmBits;
336 INT width_bytes = BITMAP_GetWidthBytes(dib->dsBm.bmWidth, dib->dsBm.bmBitsPixel);
337 DWORD max = width_bytes * bmp->bitmap.bmHeight;
339 if (!bits)
341 ret = max;
342 goto done;
345 if (count > max) count = max;
346 ret = count;
348 /* GetBitmapBits returns not 32-bit aligned data */
350 if (bmp->dib->dsBmih.biHeight >= 0) /* not top-down, need to flip contents vertically */
352 src += dib->dsBm.bmWidthBytes * dib->dsBm.bmHeight;
353 while (count > 0)
355 src -= dib->dsBm.bmWidthBytes;
356 memcpy( bits, src, min( count, width_bytes ) );
357 bits = (char *)bits + width_bytes;
358 count -= width_bytes;
361 else
363 while (count > 0)
365 memcpy( bits, src, min( count, width_bytes ) );
366 src += dib->dsBm.bmWidthBytes;
367 bits = (char *)bits + width_bytes;
368 count -= width_bytes;
371 goto done;
374 /* If the bits vector is null, the function should return the read size */
375 if(bits == NULL)
377 ret = bmp->bitmap.bmWidthBytes * bmp->bitmap.bmHeight;
378 goto done;
381 if (count < 0) {
382 WARN("(%d): Negative number of bytes passed???\n", count );
383 count = -count;
386 /* Only get entire lines */
387 height = count / bmp->bitmap.bmWidthBytes;
388 if (height > bmp->bitmap.bmHeight) height = bmp->bitmap.bmHeight;
389 count = height * bmp->bitmap.bmWidthBytes;
390 if (count == 0)
392 WARN("Less than one entire line requested\n");
393 ret = 0;
394 goto done;
398 TRACE("(%p, %d, %p) %dx%d %d colors fetched height: %d\n",
399 hbitmap, count, bits, bmp->bitmap.bmWidth, bmp->bitmap.bmHeight,
400 1 << bmp->bitmap.bmBitsPixel, height );
402 if(bmp->funcs && bmp->funcs->pGetBitmapBits)
404 TRACE("Calling device specific BitmapBits\n");
405 ret = bmp->funcs->pGetBitmapBits(hbitmap, bits, count);
406 } else {
408 if(!bmp->bitmap.bmBits) {
409 TRACE("Bitmap is empty\n");
410 memset(bits, 0, count);
411 ret = count;
412 } else {
413 memcpy(bits, bmp->bitmap.bmBits, count);
414 ret = count;
418 done:
419 GDI_ReleaseObj( hbitmap );
420 return ret;
424 /******************************************************************************
425 * SetBitmapBits [GDI32.@]
427 * Sets bits of color data for a bitmap.
429 * RETURNS
430 * Success: Number of bytes used in setting the bitmap bits
431 * Failure: 0
433 LONG WINAPI SetBitmapBits(
434 HBITMAP hbitmap, /* [in] Handle to bitmap */
435 LONG count, /* [in] Number of bytes in bitmap array */
436 LPCVOID bits) /* [in] Address of array with bitmap bits */
438 BITMAPOBJ *bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC );
439 LONG height, ret;
441 if ((!bmp) || (!bits))
442 return 0;
444 if (count < 0) {
445 WARN("(%d): Negative number of bytes passed???\n", count );
446 count = -count;
449 if (bmp->dib) /* simply copy the bits into the DIB */
451 DIBSECTION *dib = bmp->dib;
452 char *dest = dib->dsBm.bmBits;
453 DWORD max = dib->dsBm.bmWidthBytes * dib->dsBm.bmHeight;
454 if (count > max) count = max;
455 ret = count;
457 if (bmp->dib->dsBmih.biHeight >= 0) /* not top-down, need to flip contents vertically */
459 dest += dib->dsBm.bmWidthBytes * dib->dsBm.bmHeight;
460 while (count > 0)
462 dest -= dib->dsBm.bmWidthBytes;
463 memcpy( dest, bits, min( count, dib->dsBm.bmWidthBytes ) );
464 bits = (const char *)bits + dib->dsBm.bmWidthBytes;
465 count -= dib->dsBm.bmWidthBytes;
468 else memcpy( dest, bits, count );
470 GDI_ReleaseObj( hbitmap );
471 return ret;
474 /* Only get entire lines */
475 height = count / bmp->bitmap.bmWidthBytes;
476 if (height > bmp->bitmap.bmHeight) height = bmp->bitmap.bmHeight;
477 count = height * bmp->bitmap.bmWidthBytes;
479 TRACE("(%p, %d, %p) %dx%d %d colors fetched height: %d\n",
480 hbitmap, count, bits, bmp->bitmap.bmWidth, bmp->bitmap.bmHeight,
481 1 << bmp->bitmap.bmBitsPixel, height );
483 if(bmp->funcs && bmp->funcs->pSetBitmapBits) {
485 TRACE("Calling device specific BitmapBits\n");
486 ret = bmp->funcs->pSetBitmapBits(hbitmap, bits, count);
487 } else {
489 if(!bmp->bitmap.bmBits) /* Alloc enough for entire bitmap */
490 bmp->bitmap.bmBits = HeapAlloc( GetProcessHeap(), 0, count );
491 if(!bmp->bitmap.bmBits) {
492 WARN("Unable to allocate bit buffer\n");
493 ret = 0;
494 } else {
495 memcpy(bmp->bitmap.bmBits, bits, count);
496 ret = count;
500 GDI_ReleaseObj( hbitmap );
501 return ret;
504 /**********************************************************************
505 * BITMAP_CopyBitmap
508 HBITMAP BITMAP_CopyBitmap(HBITMAP hbitmap)
510 BITMAPOBJ *bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC );
511 HBITMAP res = 0;
512 BITMAP bm;
514 if(!bmp) return 0;
516 bm = bmp->bitmap;
517 bm.bmBits = NULL;
518 res = CreateBitmapIndirect(&bm);
520 if(res) {
521 char *buf = HeapAlloc( GetProcessHeap(), 0, bm.bmWidthBytes *
522 bm.bmHeight );
523 GetBitmapBits (hbitmap, bm.bmWidthBytes * bm.bmHeight, buf);
524 SetBitmapBits (res, bm.bmWidthBytes * bm.bmHeight, buf);
525 HeapFree( GetProcessHeap(), 0, buf );
528 GDI_ReleaseObj( hbitmap );
529 return res;
533 /***********************************************************************
534 * BITMAP_SetOwnerDC
536 * Set the type of DC that owns the bitmap. This is used when the
537 * bitmap is selected into a device to initialize the bitmap function
538 * table.
540 BOOL BITMAP_SetOwnerDC( HBITMAP hbitmap, DC *dc )
542 BITMAPOBJ *bitmap;
543 BOOL ret;
545 /* never set the owner of the stock bitmap since it can be selected in multiple DCs */
546 if (hbitmap == GetStockObject(DEFAULT_BITMAP)) return TRUE;
548 if (!(bitmap = GDI_GetObjPtr( hbitmap, BITMAP_MAGIC ))) return FALSE;
550 ret = TRUE;
551 if (!bitmap->funcs) /* not owned by a DC yet */
553 if (dc->funcs->pCreateBitmap) ret = dc->funcs->pCreateBitmap( dc->physDev, hbitmap,
554 bitmap->bitmap.bmBits );
555 if (ret) bitmap->funcs = dc->funcs;
557 else if (bitmap->funcs != dc->funcs)
559 FIXME( "Trying to select bitmap %p in different DC type\n", hbitmap );
560 ret = FALSE;
562 GDI_ReleaseObj( hbitmap );
563 return ret;
567 /***********************************************************************
568 * BITMAP_SelectObject
570 static HGDIOBJ BITMAP_SelectObject( HGDIOBJ handle, HDC hdc )
572 HGDIOBJ ret;
573 BITMAPOBJ *bitmap;
574 DC *dc;
576 if (!(bitmap = GDI_GetObjPtr( handle, BITMAP_MAGIC ))) return 0;
578 if (!(dc = get_dc_ptr( hdc )))
580 GDI_ReleaseObj( handle );
581 return 0;
583 if (GetObjectType( hdc ) != OBJ_MEMDC)
585 ret = 0;
586 goto done;
588 ret = dc->hBitmap;
589 if (handle == dc->hBitmap) goto done; /* nothing to do */
591 if (bitmap->header.dwCount && (handle != GetStockObject(DEFAULT_BITMAP)))
593 WARN( "Bitmap already selected in another DC\n" );
594 ret = 0;
595 goto done;
598 if (!bitmap->funcs && !BITMAP_SetOwnerDC( handle, dc ))
600 ret = 0;
601 goto done;
604 if (dc->funcs->pSelectBitmap) handle = dc->funcs->pSelectBitmap( dc->physDev, handle );
606 if (handle)
608 dc->hBitmap = handle;
609 GDI_inc_ref_count( handle );
610 dc->dirty = 0;
611 SetRectRgn( dc->hVisRgn, 0, 0, bitmap->bitmap.bmWidth, bitmap->bitmap.bmHeight);
612 DC_InitDC( dc );
613 GDI_dec_ref_count( ret );
615 else ret = 0;
617 done:
618 GDI_ReleaseObj( handle );
619 release_dc_ptr( dc );
620 return ret;
624 /***********************************************************************
625 * BITMAP_DeleteObject
627 static BOOL BITMAP_DeleteObject( HGDIOBJ handle, void *obj )
629 BITMAPOBJ * bmp = obj;
631 if (bmp->funcs && bmp->funcs->pDeleteBitmap)
632 bmp->funcs->pDeleteBitmap( handle );
634 HeapFree( GetProcessHeap(), 0, bmp->bitmap.bmBits );
636 if (bmp->dib)
638 DIBSECTION *dib = bmp->dib;
640 if (dib->dsBm.bmBits)
642 if (dib->dshSection)
644 SYSTEM_INFO SystemInfo;
645 GetSystemInfo( &SystemInfo );
646 UnmapViewOfFile( (char *)dib->dsBm.bmBits -
647 (dib->dsOffset % SystemInfo.dwAllocationGranularity) );
649 else if (!dib->dsOffset)
650 VirtualFree(dib->dsBm.bmBits, 0L, MEM_RELEASE );
652 HeapFree(GetProcessHeap(), 0, dib);
653 bmp->dib = NULL;
654 if (bmp->segptr_bits)
655 { /* free its selector array */
656 WORD sel = SELECTOROF(bmp->segptr_bits);
657 WORD count = (GetSelectorLimit16(sel) / 0x10000) + 1;
658 int i;
660 for (i = 0; i < count; i++) FreeSelector16(sel + (i << __AHSHIFT));
662 HeapFree(GetProcessHeap(), 0, bmp->color_table);
664 return GDI_FreeObject( handle, obj );
668 /***********************************************************************
669 * BITMAP_GetObject16
671 static INT BITMAP_GetObject16( HGDIOBJ handle, void *obj, INT count, LPVOID buffer )
673 BITMAPOBJ *bmp = obj;
675 if (bmp->dib)
677 if ( count <= sizeof(BITMAP16) )
679 BITMAP *bmp32 = &bmp->dib->dsBm;
680 BITMAP16 bmp16;
681 bmp16.bmType = bmp32->bmType;
682 bmp16.bmWidth = bmp32->bmWidth;
683 bmp16.bmHeight = bmp32->bmHeight;
684 bmp16.bmWidthBytes = bmp32->bmWidthBytes;
685 bmp16.bmPlanes = bmp32->bmPlanes;
686 bmp16.bmBitsPixel = bmp32->bmBitsPixel;
687 bmp16.bmBits = (SEGPTR)0;
688 memcpy( buffer, &bmp16, count );
689 return count;
691 else
693 FIXME("not implemented for DIBs: count %d\n", count);
694 return 0;
697 else
699 BITMAP16 bmp16;
700 bmp16.bmType = bmp->bitmap.bmType;
701 bmp16.bmWidth = bmp->bitmap.bmWidth;
702 bmp16.bmHeight = bmp->bitmap.bmHeight;
703 bmp16.bmWidthBytes = bmp->bitmap.bmWidthBytes;
704 bmp16.bmPlanes = bmp->bitmap.bmPlanes;
705 bmp16.bmBitsPixel = bmp->bitmap.bmBitsPixel;
706 bmp16.bmBits = (SEGPTR)0;
707 if (count < sizeof(bmp16)) return 0;
708 memcpy( buffer, &bmp16, sizeof(bmp16) );
709 return sizeof(bmp16);
714 /***********************************************************************
715 * BITMAP_GetObject
717 static INT BITMAP_GetObject( HGDIOBJ handle, void *obj, INT count, LPVOID buffer )
719 BITMAPOBJ *bmp = obj;
721 if( !buffer ) return sizeof(BITMAP);
722 if (count < sizeof(BITMAP)) return 0;
724 if (bmp->dib)
726 if (count >= sizeof(DIBSECTION))
728 memcpy( buffer, bmp->dib, sizeof(DIBSECTION) );
729 return sizeof(DIBSECTION);
731 else /* if (count >= sizeof(BITMAP)) */
733 DIBSECTION *dib = bmp->dib;
734 memcpy( buffer, &dib->dsBm, sizeof(BITMAP) );
735 return sizeof(BITMAP);
738 else
740 memcpy( buffer, &bmp->bitmap, sizeof(BITMAP) );
741 ((BITMAP *) buffer)->bmBits = NULL;
742 return sizeof(BITMAP);
747 /******************************************************************************
748 * CreateDiscardableBitmap [GDI32.@]
750 * Creates a discardable bitmap.
752 * RETURNS
753 * Success: Handle to bitmap
754 * Failure: NULL
756 HBITMAP WINAPI CreateDiscardableBitmap(
757 HDC hdc, /* [in] Handle to device context */
758 INT width, /* [in] Bitmap width */
759 INT height) /* [in] Bitmap height */
761 return CreateCompatibleBitmap( hdc, width, height );
765 /******************************************************************************
766 * GetBitmapDimensionEx [GDI32.@]
768 * 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_ReleaseObj( hbitmap );
782 return TRUE;
786 /******************************************************************************
787 * SetBitmapDimensionEx [GDI32.@]
789 * Assigns dimensions to a bitmap.
790 * MSDN says that this function will fail if hbitmap is a handle created by
791 * CreateDIBSection, but that's not true on Windows 2000.
793 * RETURNS
794 * Success: TRUE
795 * Failure: FALSE
797 BOOL WINAPI SetBitmapDimensionEx(
798 HBITMAP hbitmap, /* [in] Handle to bitmap */
799 INT x, /* [in] Bitmap width */
800 INT y, /* [in] Bitmap height */
801 LPSIZE prevSize) /* [out] Address of structure for orig dims */
803 BITMAPOBJ * bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC );
804 if (!bmp) return FALSE;
805 if (prevSize) *prevSize = bmp->size;
806 bmp->size.cx = x;
807 bmp->size.cy = y;
808 GDI_ReleaseObj( hbitmap );
809 return TRUE;