lz32: Remove dead code from the LZOpenFileW test.
[wine.git] / dlls / gdi / bitmap.c
blob3caa55f593d29b077fcfcd41b3e391e3c7f63644
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 <stdlib.h>
23 #include <string.h>
25 #include "wine/winbase16.h"
26 #include "wine/wingdi16.h"
27 #include "gdi.h"
28 #include "gdi_private.h"
29 #include "wine/debug.h"
31 WINE_DEFAULT_DEBUG_CHANNEL(bitmap);
34 static HGDIOBJ BITMAP_SelectObject( HGDIOBJ handle, void *obj, HDC hdc );
35 static INT BITMAP_GetObject16( HGDIOBJ handle, void *obj, INT count, LPVOID buffer );
36 static INT BITMAP_GetObject( HGDIOBJ handle, void *obj, INT count, LPVOID buffer );
37 static BOOL BITMAP_DeleteObject( HGDIOBJ handle, void *obj );
39 static const struct gdi_obj_funcs bitmap_funcs =
41 BITMAP_SelectObject, /* pSelectObject */
42 BITMAP_GetObject16, /* pGetObject16 */
43 BITMAP_GetObject, /* pGetObjectA */
44 BITMAP_GetObject, /* pGetObjectW */
45 NULL, /* pUnrealizeObject */
46 BITMAP_DeleteObject /* pDeleteObject */
49 /***********************************************************************
50 * BITMAP_GetWidthBytes
52 * Return number of bytes taken by a scanline of 16-bit aligned Windows DDB
53 * data.
55 INT BITMAP_GetWidthBytes( INT bmWidth, INT bpp )
57 switch(bpp)
59 case 1:
60 return 2 * ((bmWidth+15) >> 4);
62 case 24:
63 bmWidth *= 3; /* fall through */
64 case 8:
65 return bmWidth + (bmWidth & 1);
67 case 32:
68 return bmWidth * 4;
70 case 16:
71 case 15:
72 return bmWidth * 2;
74 case 4:
75 return 2 * ((bmWidth+3) >> 2);
77 default:
78 WARN("Unknown depth %d, please report.\n", bpp );
80 return -1;
84 /******************************************************************************
85 * CreateBitmap [GDI32.@]
87 * Creates a bitmap with the specified info.
89 * PARAMS
90 * width [I] bitmap width
91 * height [I] bitmap height
92 * planes [I] Number of color planes
93 * bpp [I] Number of bits to identify a color
94 * bits [I] Pointer to array containing color data
96 * RETURNS
97 * Success: Handle to bitmap
98 * Failure: 0
100 HBITMAP WINAPI CreateBitmap( INT width, INT height, UINT planes,
101 UINT bpp, LPCVOID bits )
103 BITMAP bm;
105 bm.bmType = 0;
106 bm.bmWidth = width;
107 bm.bmHeight = height;
108 bm.bmWidthBytes = BITMAP_GetWidthBytes( width, bpp );
109 bm.bmPlanes = planes;
110 bm.bmBitsPixel = bpp;
111 bm.bmBits = (LPVOID)bits;
113 return CreateBitmapIndirect( &bm );
116 /******************************************************************************
117 * CreateCompatibleBitmap [GDI32.@]
119 * Creates a bitmap compatible with the DC.
121 * PARAMS
122 * hdc [I] Handle to device context
123 * width [I] Width of bitmap
124 * height [I] Height of bitmap
126 * RETURNS
127 * Success: Handle to bitmap
128 * Failure: 0
130 HBITMAP WINAPI CreateCompatibleBitmap( HDC hdc, INT width, INT height)
132 HBITMAP hbmpRet = 0;
133 DC *dc;
135 TRACE("(%p,%d,%d) =\n", hdc, width, height);
137 if ((width >= 0x10000) || (height >= 0x10000))
139 FIXME("got bad width %d or height %d, please look for reason\n",
140 width, height);
142 else
144 if (!(dc = DC_GetDCPtr(hdc))) return 0;
146 if (GDIMAGIC( dc->header.wMagic ) != MEMORY_DC_MAGIC)
148 hbmpRet = CreateBitmap(width, height,
149 GetDeviceCaps(hdc, PLANES),
150 GetDeviceCaps(hdc, BITSPIXEL),
151 NULL);
153 else /* Memory DC */
155 BITMAPOBJ *bmp = GDI_GetObjPtr( dc->hBitmap, BITMAP_MAGIC );
157 if (!bmp->dib)
159 /* A device-dependent bitmap is selected in the DC */
160 hbmpRet = CreateBitmap(width, height,
161 bmp->bitmap.bmPlanes,
162 bmp->bitmap.bmBitsPixel,
163 NULL);
165 else
167 /* A DIB section is selected in the DC */
168 BITMAPINFO *bi;
169 void *bits;
171 /* Allocate memory for a BITMAPINFOHEADER structure and a
172 color table. The maximum number of colors in a color table
173 is 256 which corresponds to a bitmap with depth 8.
174 Bitmaps with higher depths don't have color tables. */
175 bi = HeapAlloc(GetProcessHeap(), 0, sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD));
177 if (bi)
179 bi->bmiHeader.biSize = sizeof(bi->bmiHeader);
180 bi->bmiHeader.biWidth = width;
181 bi->bmiHeader.biHeight = height;
182 bi->bmiHeader.biPlanes = bmp->dib->dsBmih.biPlanes;
183 bi->bmiHeader.biBitCount = bmp->dib->dsBmih.biBitCount;
184 bi->bmiHeader.biCompression = bmp->dib->dsBmih.biCompression;
185 bi->bmiHeader.biSizeImage = 0;
186 bi->bmiHeader.biXPelsPerMeter = bmp->dib->dsBmih.biXPelsPerMeter;
187 bi->bmiHeader.biYPelsPerMeter = bmp->dib->dsBmih.biYPelsPerMeter;
188 bi->bmiHeader.biClrUsed = bmp->dib->dsBmih.biClrUsed;
189 bi->bmiHeader.biClrImportant = bmp->dib->dsBmih.biClrImportant;
191 if (bi->bmiHeader.biCompression == BI_BITFIELDS)
193 /* Copy the color masks */
194 CopyMemory(bi->bmiColors, bmp->dib->dsBitfields, 3 * sizeof(DWORD));
196 else if (bi->bmiHeader.biBitCount <= 8)
198 /* Copy the color table */
199 GetDIBColorTable(hdc, 0, 256, bi->bmiColors);
202 hbmpRet = CreateDIBSection(hdc, bi, DIB_RGB_COLORS, &bits, NULL, 0);
203 HeapFree(GetProcessHeap(), 0, bi);
206 GDI_ReleaseObj(dc->hBitmap);
208 GDI_ReleaseObj(hdc);
211 TRACE("\t\t%p\n", hbmpRet);
212 return hbmpRet;
216 /******************************************************************************
217 * CreateBitmapIndirect [GDI32.@]
219 * Creates a bitmap with the specified info.
221 * PARAMS
222 * bmp [I] Pointer to the bitmap info describing the bitmap
224 * RETURNS
225 * Success: Handle to bitmap
226 * Failure: NULL. Use GetLastError() to determine the cause.
228 * NOTES
229 * If a width or height of 0 are given, a 1x1 monochrome bitmap is returned.
231 HBITMAP WINAPI CreateBitmapIndirect( const BITMAP *bmp )
233 BITMAP bm;
234 BITMAPOBJ *bmpobj;
235 HBITMAP hbitmap;
237 if (!bmp || bmp->bmType || bmp->bmPlanes != 1)
239 if (bmp && bmp->bmPlanes != 1)
240 FIXME("planes = %d\n", bmp->bmPlanes);
241 SetLastError( ERROR_INVALID_PARAMETER );
242 return NULL;
245 bm = *bmp;
247 if (!bm.bmWidth || !bm.bmHeight)
249 bm.bmWidth = bm.bmHeight = 1;
250 bm.bmPlanes = bm.bmBitsPixel = 1;
251 bm.bmWidthBytes = 2;
252 bm.bmBits = NULL;
254 else
256 if (bm.bmHeight < 0)
257 bm.bmHeight = -bm.bmHeight;
258 if (bm.bmWidth < 0)
259 bm.bmWidth = -bm.bmWidth;
262 /* Create the BITMAPOBJ */
263 bmpobj = GDI_AllocObject( sizeof(BITMAPOBJ), BITMAP_MAGIC,
264 (HGDIOBJ *)&hbitmap, &bitmap_funcs );
266 if (!bmpobj)
268 SetLastError( ERROR_NOT_ENOUGH_MEMORY );
269 return NULL;
272 TRACE("%dx%d, %d colors returning %p\n", bm.bmWidth, bm.bmHeight,
273 1 << (bm.bmPlanes * bm.bmBitsPixel), hbitmap);
275 bmpobj->size.cx = 0;
276 bmpobj->size.cy = 0;
277 bmpobj->bitmap = bm;
278 bmpobj->bitmap.bmBits = NULL;
279 bmpobj->funcs = NULL;
280 bmpobj->dib = NULL;
281 bmpobj->segptr_bits = 0;
283 if (bm.bmBits)
284 SetBitmapBits( hbitmap, bm.bmHeight * bm.bmWidthBytes, bm.bmBits );
286 GDI_ReleaseObj( hbitmap );
287 return hbitmap;
291 /***********************************************************************
292 * GetBitmapBits [GDI32.@]
294 * Copies bitmap bits of bitmap to buffer.
296 * RETURNS
297 * Success: Number of bytes copied
298 * Failure: 0
300 LONG WINAPI GetBitmapBits(
301 HBITMAP hbitmap, /* [in] Handle to bitmap */
302 LONG count, /* [in] Number of bytes to copy */
303 LPVOID bits) /* [out] Pointer to buffer to receive bits */
305 BITMAPOBJ *bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC );
306 LONG height, ret;
308 if (!bmp) return 0;
310 if (bmp->dib) /* simply copy the bits from the DIB */
312 DIBSECTION *dib = bmp->dib;
313 const char *src = dib->dsBm.bmBits;
314 INT width_bytes = BITMAP_GetWidthBytes(dib->dsBm.bmWidth, dib->dsBm.bmBitsPixel);
315 DWORD max = width_bytes * bmp->bitmap.bmHeight;
317 if (!bits)
319 ret = max;
320 goto done;
323 if (count > max) count = max;
324 ret = count;
326 /* GetBitmapBits returns not 32-bit aligned data */
328 if (bmp->dib->dsBmih.biHeight >= 0) /* not top-down, need to flip contents vertically */
330 src += dib->dsBm.bmWidthBytes * dib->dsBm.bmHeight;
331 while (count > 0)
333 src -= dib->dsBm.bmWidthBytes;
334 memcpy( bits, src, min( count, width_bytes ) );
335 bits = (char *)bits + width_bytes;
336 count -= width_bytes;
339 else
341 while (count > 0)
343 memcpy( bits, src, min( count, width_bytes ) );
344 src += dib->dsBm.bmWidthBytes;
345 bits = (char *)bits + width_bytes;
346 count -= width_bytes;
349 goto done;
352 /* If the bits vector is null, the function should return the read size */
353 if(bits == NULL)
355 ret = bmp->bitmap.bmWidthBytes * bmp->bitmap.bmHeight;
356 goto done;
359 if (count < 0) {
360 WARN("(%ld): Negative number of bytes passed???\n", count );
361 count = -count;
364 /* Only get entire lines */
365 height = count / bmp->bitmap.bmWidthBytes;
366 if (height > bmp->bitmap.bmHeight) height = bmp->bitmap.bmHeight;
367 count = height * bmp->bitmap.bmWidthBytes;
368 if (count == 0)
370 WARN("Less than one entire line requested\n");
371 ret = 0;
372 goto done;
376 TRACE("(%p, %ld, %p) %dx%d %d colors fetched height: %ld\n",
377 hbitmap, count, bits, bmp->bitmap.bmWidth, bmp->bitmap.bmHeight,
378 1 << bmp->bitmap.bmBitsPixel, height );
380 if(bmp->funcs && bmp->funcs->pGetBitmapBits)
382 TRACE("Calling device specific BitmapBits\n");
383 ret = bmp->funcs->pGetBitmapBits(hbitmap, bits, count);
384 } else {
386 if(!bmp->bitmap.bmBits) {
387 TRACE("Bitmap is empty\n");
388 memset(bits, 0, count);
389 ret = count;
390 } else {
391 memcpy(bits, bmp->bitmap.bmBits, count);
392 ret = count;
396 done:
397 GDI_ReleaseObj( hbitmap );
398 return ret;
402 /******************************************************************************
403 * SetBitmapBits [GDI32.@]
405 * Sets bits of color data for a bitmap.
407 * RETURNS
408 * Success: Number of bytes used in setting the bitmap bits
409 * Failure: 0
411 LONG WINAPI SetBitmapBits(
412 HBITMAP hbitmap, /* [in] Handle to bitmap */
413 LONG count, /* [in] Number of bytes in bitmap array */
414 LPCVOID bits) /* [in] Address of array with bitmap bits */
416 BITMAPOBJ *bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC );
417 LONG height, ret;
419 if ((!bmp) || (!bits))
420 return 0;
422 if (count < 0) {
423 WARN("(%ld): Negative number of bytes passed???\n", count );
424 count = -count;
427 if (bmp->dib) /* simply copy the bits into the DIB */
429 DIBSECTION *dib = bmp->dib;
430 char *dest = dib->dsBm.bmBits;
431 DWORD max = dib->dsBm.bmWidthBytes * dib->dsBm.bmHeight;
432 if (count > max) count = max;
433 ret = count;
435 if (bmp->dib->dsBmih.biHeight >= 0) /* not top-down, need to flip contents vertically */
437 dest += dib->dsBm.bmWidthBytes * dib->dsBm.bmHeight;
438 while (count > 0)
440 dest -= dib->dsBm.bmWidthBytes;
441 memcpy( dest, bits, min( count, dib->dsBm.bmWidthBytes ) );
442 bits = (char *)bits + dib->dsBm.bmWidthBytes;
443 count -= dib->dsBm.bmWidthBytes;
446 else memcpy( dest, bits, count );
448 GDI_ReleaseObj( hbitmap );
449 return ret;
452 /* Only get entire lines */
453 height = count / bmp->bitmap.bmWidthBytes;
454 if (height > bmp->bitmap.bmHeight) height = bmp->bitmap.bmHeight;
455 count = height * bmp->bitmap.bmWidthBytes;
457 TRACE("(%p, %ld, %p) %dx%d %d colors fetched height: %ld\n",
458 hbitmap, count, bits, bmp->bitmap.bmWidth, bmp->bitmap.bmHeight,
459 1 << bmp->bitmap.bmBitsPixel, height );
461 if(bmp->funcs && bmp->funcs->pSetBitmapBits) {
463 TRACE("Calling device specific BitmapBits\n");
464 ret = bmp->funcs->pSetBitmapBits(hbitmap, bits, count);
465 } else {
467 if(!bmp->bitmap.bmBits) /* Alloc enough for entire bitmap */
468 bmp->bitmap.bmBits = HeapAlloc( GetProcessHeap(), 0, count );
469 if(!bmp->bitmap.bmBits) {
470 WARN("Unable to allocate bit buffer\n");
471 ret = 0;
472 } else {
473 memcpy(bmp->bitmap.bmBits, bits, count);
474 ret = count;
478 GDI_ReleaseObj( hbitmap );
479 return ret;
482 /**********************************************************************
483 * BITMAP_CopyBitmap
486 HBITMAP BITMAP_CopyBitmap(HBITMAP hbitmap)
488 BITMAPOBJ *bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC );
489 HBITMAP res = 0;
490 BITMAP bm;
492 if(!bmp) return 0;
494 bm = bmp->bitmap;
495 bm.bmBits = NULL;
496 res = CreateBitmapIndirect(&bm);
498 if(res) {
499 char *buf = HeapAlloc( GetProcessHeap(), 0, bm.bmWidthBytes *
500 bm.bmHeight );
501 GetBitmapBits (hbitmap, bm.bmWidthBytes * bm.bmHeight, buf);
502 SetBitmapBits (res, bm.bmWidthBytes * bm.bmHeight, buf);
503 HeapFree( GetProcessHeap(), 0, buf );
506 GDI_ReleaseObj( hbitmap );
507 return res;
511 /***********************************************************************
512 * BITMAP_SetOwnerDC
514 * Set the type of DC that owns the bitmap. This is used when the
515 * bitmap is selected into a device to initialize the bitmap function
516 * table.
518 BOOL BITMAP_SetOwnerDC( HBITMAP hbitmap, DC *dc )
520 BITMAPOBJ *bitmap;
521 BOOL ret;
523 /* never set the owner of the stock bitmap since it can be selected in multiple DCs */
524 if (hbitmap == GetStockObject(DEFAULT_BITMAP)) return TRUE;
526 if (!(bitmap = GDI_GetObjPtr( hbitmap, BITMAP_MAGIC ))) return FALSE;
528 ret = TRUE;
529 if (!bitmap->funcs) /* not owned by a DC yet */
531 if (dc->funcs->pCreateBitmap) ret = dc->funcs->pCreateBitmap( dc->physDev, hbitmap,
532 bitmap->bitmap.bmBits );
533 if (ret) bitmap->funcs = dc->funcs;
535 else if (bitmap->funcs != dc->funcs)
537 FIXME( "Trying to select bitmap %p in different DC type\n", hbitmap );
538 ret = FALSE;
540 GDI_ReleaseObj( hbitmap );
541 return ret;
545 /***********************************************************************
546 * BITMAP_SelectObject
548 static HGDIOBJ BITMAP_SelectObject( HGDIOBJ handle, void *obj, HDC hdc )
550 HGDIOBJ ret;
551 BITMAPOBJ *bitmap = obj;
552 DC *dc = DC_GetDCPtr( hdc );
554 if (!dc) return 0;
555 if (GetObjectType( hdc ) != OBJ_MEMDC)
557 GDI_ReleaseObj( hdc );
558 return 0;
560 ret = dc->hBitmap;
561 if (handle == dc->hBitmap) goto done; /* nothing to do */
563 if (bitmap->header.dwCount && (handle != GetStockObject(DEFAULT_BITMAP)))
565 WARN( "Bitmap already selected in another DC\n" );
566 GDI_ReleaseObj( hdc );
567 return 0;
570 if (!bitmap->funcs && !BITMAP_SetOwnerDC( handle, dc ))
572 GDI_ReleaseObj( hdc );
573 return 0;
576 if (dc->funcs->pSelectBitmap) handle = dc->funcs->pSelectBitmap( dc->physDev, handle );
578 if (handle)
580 dc->hBitmap = handle;
581 dc->flags &= ~DC_DIRTY;
582 SetRectRgn( dc->hVisRgn, 0, 0, bitmap->bitmap.bmWidth, bitmap->bitmap.bmHeight);
583 DC_InitDC( dc );
585 else ret = 0;
587 done:
588 GDI_ReleaseObj( hdc );
589 return ret;
593 /***********************************************************************
594 * BITMAP_DeleteObject
596 static BOOL BITMAP_DeleteObject( HGDIOBJ handle, void *obj )
598 BITMAPOBJ * bmp = obj;
600 if (bmp->funcs && bmp->funcs->pDeleteBitmap)
601 bmp->funcs->pDeleteBitmap( handle );
603 HeapFree( GetProcessHeap(), 0, bmp->bitmap.bmBits );
605 if (bmp->dib)
607 DIBSECTION *dib = bmp->dib;
609 if (dib->dsBm.bmBits)
611 if (dib->dshSection)
613 SYSTEM_INFO SystemInfo;
614 GetSystemInfo( &SystemInfo );
615 UnmapViewOfFile( (char *)dib->dsBm.bmBits -
616 (dib->dsOffset % SystemInfo.dwAllocationGranularity) );
618 else if (!dib->dsOffset)
619 VirtualFree(dib->dsBm.bmBits, 0L, MEM_RELEASE );
621 HeapFree(GetProcessHeap(), 0, dib);
622 bmp->dib = NULL;
623 if (bmp->segptr_bits)
624 { /* free its selector array */
625 WORD sel = SELECTOROF(bmp->segptr_bits);
626 WORD count = (GetSelectorLimit16(sel) / 0x10000) + 1;
627 int i;
629 for (i = 0; i < count; i++) FreeSelector16(sel + (i << __AHSHIFT));
632 return GDI_FreeObject( handle, obj );
636 /***********************************************************************
637 * BITMAP_GetObject16
639 static INT BITMAP_GetObject16( HGDIOBJ handle, void *obj, INT count, LPVOID buffer )
641 BITMAPOBJ *bmp = obj;
643 if (bmp->dib)
645 if ( count <= sizeof(BITMAP16) )
647 BITMAP *bmp32 = &bmp->dib->dsBm;
648 BITMAP16 bmp16;
649 bmp16.bmType = bmp32->bmType;
650 bmp16.bmWidth = bmp32->bmWidth;
651 bmp16.bmHeight = bmp32->bmHeight;
652 bmp16.bmWidthBytes = bmp32->bmWidthBytes;
653 bmp16.bmPlanes = bmp32->bmPlanes;
654 bmp16.bmBitsPixel = bmp32->bmBitsPixel;
655 bmp16.bmBits = (SEGPTR)0;
656 memcpy( buffer, &bmp16, count );
657 return count;
659 else
661 FIXME("not implemented for DIBs: count %d\n", count);
662 return 0;
665 else
667 BITMAP16 bmp16;
668 bmp16.bmType = bmp->bitmap.bmType;
669 bmp16.bmWidth = bmp->bitmap.bmWidth;
670 bmp16.bmHeight = bmp->bitmap.bmHeight;
671 bmp16.bmWidthBytes = bmp->bitmap.bmWidthBytes;
672 bmp16.bmPlanes = bmp->bitmap.bmPlanes;
673 bmp16.bmBitsPixel = bmp->bitmap.bmBitsPixel;
674 bmp16.bmBits = (SEGPTR)0;
675 if (count < sizeof(bmp16)) return 0;
676 memcpy( buffer, &bmp16, sizeof(bmp16) );
677 return sizeof(bmp16);
682 /***********************************************************************
683 * BITMAP_GetObject
685 static INT BITMAP_GetObject( HGDIOBJ handle, void *obj, INT count, LPVOID buffer )
687 BITMAPOBJ *bmp = obj;
689 if( !buffer ) return sizeof(BITMAP);
690 if (count < sizeof(BITMAP)) return 0;
692 if (bmp->dib)
694 if (count >= sizeof(DIBSECTION))
696 memcpy( buffer, bmp->dib, sizeof(DIBSECTION) );
697 return sizeof(DIBSECTION);
699 else /* if (count >= sizeof(BITMAP)) */
701 DIBSECTION *dib = bmp->dib;
702 memcpy( buffer, &dib->dsBm, sizeof(BITMAP) );
703 return sizeof(BITMAP);
706 else
708 memcpy( buffer, &bmp->bitmap, sizeof(BITMAP) );
709 ((BITMAP *) buffer)->bmBits = NULL;
710 return sizeof(BITMAP);
715 /******************************************************************************
716 * CreateDiscardableBitmap [GDI32.@]
718 * Creates a discardable bitmap.
720 * RETURNS
721 * Success: Handle to bitmap
722 * Failure: NULL
724 HBITMAP WINAPI CreateDiscardableBitmap(
725 HDC hdc, /* [in] Handle to device context */
726 INT width, /* [in] Bitmap width */
727 INT height) /* [in] Bitmap height */
729 return CreateCompatibleBitmap( hdc, width, height );
733 /******************************************************************************
734 * GetBitmapDimensionEx [GDI32.@]
736 * Retrieves dimensions of a bitmap.
738 * RETURNS
739 * Success: TRUE
740 * Failure: FALSE
742 BOOL WINAPI GetBitmapDimensionEx(
743 HBITMAP hbitmap, /* [in] Handle to bitmap */
744 LPSIZE size) /* [out] Address of struct receiving dimensions */
746 BITMAPOBJ * bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC );
747 if (!bmp) return FALSE;
748 *size = bmp->size;
749 GDI_ReleaseObj( hbitmap );
750 return TRUE;
754 /******************************************************************************
755 * SetBitmapDimensionEx [GDI32.@]
757 * Assigns dimensions to a bitmap.
758 * MSDN says that this function will fail if hbitmap is a handle created by
759 * CreateDIBSection, but that's not true on Windows 2000.
761 * RETURNS
762 * Success: TRUE
763 * Failure: FALSE
765 BOOL WINAPI SetBitmapDimensionEx(
766 HBITMAP hbitmap, /* [in] Handle to bitmap */
767 INT x, /* [in] Bitmap width */
768 INT y, /* [in] Bitmap height */
769 LPSIZE prevSize) /* [out] Address of structure for orig dims */
771 BITMAPOBJ * bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC );
772 if (!bmp) return FALSE;
773 if (prevSize) *prevSize = bmp->size;
774 bmp->size.cx = x;
775 bmp->size.cy = y;
776 GDI_ReleaseObj( hbitmap );
777 return TRUE;