4 * Copyright 1993 Alexandre Julliard
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
29 #include "gdi_private.h"
30 #include "wine/debug.h"
32 WINE_DEFAULT_DEBUG_CHANNEL(bitmap
);
35 static HGDIOBJ
BITMAP_SelectObject( HGDIOBJ handle
, HDC hdc
);
36 static INT
BITMAP_GetObject( HGDIOBJ handle
, INT count
, LPVOID buffer
);
37 static BOOL
BITMAP_DeleteObject( HGDIOBJ handle
);
39 static const struct gdi_obj_funcs bitmap_funcs
=
41 BITMAP_SelectObject
, /* pSelectObject */
42 BITMAP_GetObject
, /* pGetObjectA */
43 BITMAP_GetObject
, /* pGetObjectW */
44 NULL
, /* pUnrealizeObject */
45 BITMAP_DeleteObject
/* pDeleteObject */
49 /***********************************************************************
50 * null driver fallback implementations
53 DWORD
nulldrv_GetImage( PHYSDEV dev
, HBITMAP hbitmap
, BITMAPINFO
*info
,
54 struct gdi_image_bits
*bits
, struct bitblt_coords
*src
)
56 if (!hbitmap
) return ERROR_NOT_SUPPORTED
;
57 return dib_driver
.pGetImage( 0, hbitmap
, info
, bits
, src
);
60 DWORD
nulldrv_PutImage( PHYSDEV dev
, HBITMAP hbitmap
, HRGN clip
, BITMAPINFO
*info
,
61 const struct gdi_image_bits
*bits
, struct bitblt_coords
*src
,
62 struct bitblt_coords
*dst
, DWORD rop
)
64 if (!hbitmap
) return ERROR_SUCCESS
;
65 return dib_driver
.pPutImage( NULL
, hbitmap
, clip
, info
, bits
, src
, dst
, rop
);
68 BOOL
nulldrv_CopyBitmap( HBITMAP src
, HBITMAP dst
)
71 BITMAPOBJ
*src_bmp
= GDI_GetObjPtr( src
, OBJ_BITMAP
);
73 if (!src_bmp
) return FALSE
;
74 if (src_bmp
->dib
.dsBm
.bmBits
)
76 BITMAPOBJ
*dst_bmp
= GDI_GetObjPtr( dst
, OBJ_BITMAP
);
77 int stride
= get_dib_stride( dst_bmp
->dib
.dsBm
.bmWidth
, dst_bmp
->dib
.dsBm
.bmBitsPixel
);
78 dst_bmp
->dib
.dsBm
.bmBits
= HeapAlloc( GetProcessHeap(), 0, dst_bmp
->dib
.dsBm
.bmHeight
* stride
);
79 if (dst_bmp
->dib
.dsBm
.bmBits
)
80 memcpy( dst_bmp
->dib
.dsBm
.bmBits
, src_bmp
->dib
.dsBm
.bmBits
, dst_bmp
->dib
.dsBm
.bmHeight
* stride
);
83 GDI_ReleaseObj( dst
);
85 GDI_ReleaseObj( src
);
90 /******************************************************************************
91 * CreateBitmap [GDI32.@]
93 * Creates a bitmap with the specified info.
96 * width [I] bitmap width
97 * height [I] bitmap height
98 * planes [I] Number of color planes
99 * bpp [I] Number of bits to identify a color
100 * bits [I] Pointer to array containing color data
103 * Success: Handle to bitmap
106 HBITMAP WINAPI
CreateBitmap( INT width
, INT height
, UINT planes
,
107 UINT bpp
, LPCVOID bits
)
113 bm
.bmHeight
= height
;
114 bm
.bmWidthBytes
= get_bitmap_stride( width
, bpp
);
115 bm
.bmPlanes
= planes
;
116 bm
.bmBitsPixel
= bpp
;
117 bm
.bmBits
= (LPVOID
)bits
;
119 return CreateBitmapIndirect( &bm
);
122 /******************************************************************************
123 * CreateCompatibleBitmap [GDI32.@]
125 * Creates a bitmap compatible with the DC.
128 * hdc [I] Handle to device context
129 * width [I] Width of bitmap
130 * height [I] Height of bitmap
133 * Success: Handle to bitmap
136 HBITMAP WINAPI
CreateCompatibleBitmap( HDC hdc
, INT width
, INT height
)
140 TRACE("(%p,%d,%d) =\n", hdc
, width
, height
);
142 if (GetObjectType( hdc
) != OBJ_MEMDC
)
144 hbmpRet
= CreateBitmap(width
, height
,
145 GetDeviceCaps(hdc
, PLANES
),
146 GetDeviceCaps(hdc
, BITSPIXEL
),
152 HBITMAP bitmap
= GetCurrentObject( hdc
, OBJ_BITMAP
);
153 INT size
= GetObjectW( bitmap
, sizeof(dib
), &dib
);
157 if (size
== sizeof(BITMAP
))
159 /* A device-dependent bitmap is selected in the DC */
160 hbmpRet
= CreateBitmap(width
, height
,
162 dib
.dsBm
.bmBitsPixel
,
167 /* A DIB section is selected in the DC */
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
));
179 bi
->bmiHeader
.biSize
= sizeof(bi
->bmiHeader
);
180 bi
->bmiHeader
.biWidth
= width
;
181 bi
->bmiHeader
.biHeight
= height
;
182 bi
->bmiHeader
.biPlanes
= dib
.dsBmih
.biPlanes
;
183 bi
->bmiHeader
.biBitCount
= dib
.dsBmih
.biBitCount
;
184 bi
->bmiHeader
.biCompression
= dib
.dsBmih
.biCompression
;
185 bi
->bmiHeader
.biSizeImage
= 0;
186 bi
->bmiHeader
.biXPelsPerMeter
= dib
.dsBmih
.biXPelsPerMeter
;
187 bi
->bmiHeader
.biYPelsPerMeter
= dib
.dsBmih
.biYPelsPerMeter
;
188 bi
->bmiHeader
.biClrUsed
= dib
.dsBmih
.biClrUsed
;
189 bi
->bmiHeader
.biClrImportant
= dib
.dsBmih
.biClrImportant
;
191 if (bi
->bmiHeader
.biCompression
== BI_BITFIELDS
)
193 /* Copy the color masks */
194 CopyMemory(bi
->bmiColors
, 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
);
208 TRACE("\t\t%p\n", hbmpRet
);
213 /******************************************************************************
214 * CreateBitmapIndirect [GDI32.@]
216 * Creates a bitmap with the specified info.
219 * bmp [I] Pointer to the bitmap info describing the bitmap
222 * Success: Handle to bitmap
223 * Failure: NULL. Use GetLastError() to determine the cause.
226 * If a width or height of 0 are given, a 1x1 monochrome bitmap is returned.
228 HBITMAP WINAPI
CreateBitmapIndirect( const BITMAP
*bmp
)
234 if (!bmp
|| bmp
->bmType
)
236 SetLastError( ERROR_INVALID_PARAMETER
);
240 if (bmp
->bmWidth
> 0x7ffffff || bmp
->bmHeight
> 0x7ffffff)
242 SetLastError( ERROR_INVALID_PARAMETER
);
248 if (!bm
.bmWidth
|| !bm
.bmHeight
)
250 return GetStockObject( DEFAULT_BITMAP
);
255 bm
.bmHeight
= -bm
.bmHeight
;
257 bm
.bmWidth
= -bm
.bmWidth
;
260 if (bm
.bmPlanes
!= 1)
262 FIXME("planes = %d\n", bm
.bmPlanes
);
263 SetLastError( ERROR_INVALID_PARAMETER
);
267 /* Windows only uses 1, 4, 8, 16, 24 and 32 bpp */
268 if(bm
.bmBitsPixel
== 1) bm
.bmBitsPixel
= 1;
269 else if(bm
.bmBitsPixel
<= 4) bm
.bmBitsPixel
= 4;
270 else if(bm
.bmBitsPixel
<= 8) bm
.bmBitsPixel
= 8;
271 else if(bm
.bmBitsPixel
<= 16) bm
.bmBitsPixel
= 16;
272 else if(bm
.bmBitsPixel
<= 24) bm
.bmBitsPixel
= 24;
273 else if(bm
.bmBitsPixel
<= 32) bm
.bmBitsPixel
= 32;
275 WARN("Invalid bmBitsPixel %d, returning ERROR_INVALID_PARAMETER\n", bm
.bmBitsPixel
);
276 SetLastError(ERROR_INVALID_PARAMETER
);
280 /* Windows ignores the provided bm.bmWidthBytes */
281 bm
.bmWidthBytes
= get_bitmap_stride( bm
.bmWidth
, bm
.bmBitsPixel
);
282 /* XP doesn't allow to create bitmaps larger than 128 Mb */
283 if (bm
.bmHeight
> 128 * 1024 * 1024 / bm
.bmWidthBytes
)
285 SetLastError( ERROR_NOT_ENOUGH_MEMORY
);
289 /* Create the BITMAPOBJ */
290 if (!(bmpobj
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*bmpobj
) )))
292 SetLastError( ERROR_NOT_ENOUGH_MEMORY
);
296 bmpobj
->dib
.dsBm
= bm
;
297 bmpobj
->dib
.dsBm
.bmBits
= NULL
;
298 bmpobj
->funcs
= &null_driver
;
300 if (!(hbitmap
= alloc_gdi_handle( &bmpobj
->header
, OBJ_BITMAP
, &bitmap_funcs
)))
302 HeapFree( GetProcessHeap(), 0, bmpobj
);
307 SetBitmapBits( hbitmap
, bm
.bmHeight
* bm
.bmWidthBytes
, bm
.bmBits
);
309 TRACE("%dx%d, bpp %d planes %d: returning %p\n", bm
.bmWidth
, bm
.bmHeight
,
310 bm
.bmBitsPixel
, bm
.bmPlanes
, hbitmap
);
316 /***********************************************************************
317 * GetBitmapBits [GDI32.@]
319 * Copies bitmap bits of bitmap to buffer.
322 * Success: Number of bytes copied
325 LONG WINAPI
GetBitmapBits(
326 HBITMAP hbitmap
, /* [in] Handle to bitmap */
327 LONG count
, /* [in] Number of bytes to copy */
328 LPVOID bits
) /* [out] Pointer to buffer to receive bits */
330 char buffer
[FIELD_OFFSET( BITMAPINFO
, bmiColors
[256] )];
331 BITMAPINFO
*info
= (BITMAPINFO
*)buffer
;
332 struct gdi_image_bits src_bits
;
333 struct bitblt_coords src
;
334 int dst_stride
, max
, ret
;
335 BITMAPOBJ
*bmp
= GDI_GetObjPtr( hbitmap
, OBJ_BITMAP
);
339 dst_stride
= get_bitmap_stride( bmp
->dib
.dsBm
.bmWidth
, bmp
->dib
.dsBm
.bmBitsPixel
);
340 ret
= max
= dst_stride
* bmp
->dib
.dsBm
.bmHeight
;
341 if (!bits
) goto done
;
342 if (count
> max
) count
= max
;
345 src
.visrect
.left
= 0;
346 src
.visrect
.right
= bmp
->dib
.dsBm
.bmWidth
;
348 src
.visrect
.bottom
= (count
+ dst_stride
- 1) / dst_stride
;
350 src
.width
= src
.visrect
.right
- src
.visrect
.left
;
351 src
.height
= src
.visrect
.bottom
- src
.visrect
.top
;
353 if (!bmp
->funcs
->pGetImage( NULL
, hbitmap
, info
, &src_bits
, &src
))
355 const char *src_ptr
= src_bits
.ptr
;
356 int src_stride
= get_dib_stride( info
->bmiHeader
.biWidth
, info
->bmiHeader
.biBitCount
);
358 /* GetBitmapBits returns 16-bit aligned data */
360 if (info
->bmiHeader
.biHeight
> 0)
362 src_ptr
+= (info
->bmiHeader
.biHeight
- 1) * src_stride
;
363 src_stride
= -src_stride
;
365 src_ptr
+= src
.visrect
.top
* src_stride
;
367 if (src_stride
== dst_stride
) memcpy( bits
, src_ptr
, count
);
368 else while (count
> 0)
370 memcpy( bits
, src_ptr
, min( count
, dst_stride
) );
371 src_ptr
+= src_stride
;
372 bits
= (char *)bits
+ dst_stride
;
375 if (src_bits
.free
) src_bits
.free( &src_bits
);
380 GDI_ReleaseObj( hbitmap
);
385 /******************************************************************************
386 * SetBitmapBits [GDI32.@]
388 * Sets bits of color data for a bitmap.
391 * Success: Number of bytes used in setting the bitmap bits
394 LONG WINAPI
SetBitmapBits(
395 HBITMAP hbitmap
, /* [in] Handle to bitmap */
396 LONG count
, /* [in] Number of bytes in bitmap array */
397 LPCVOID bits
) /* [in] Address of array with bitmap bits */
399 char buffer
[FIELD_OFFSET( BITMAPINFO
, bmiColors
[256] )];
400 BITMAPINFO
*info
= (BITMAPINFO
*)buffer
;
403 int i
, src_stride
, dst_stride
;
404 struct bitblt_coords src
, dst
;
405 struct gdi_image_bits src_bits
;
410 bmp
= GDI_GetObjPtr( hbitmap
, OBJ_BITMAP
);
414 WARN("(%d): Negative number of bytes passed???\n", count
);
418 src_stride
= get_bitmap_stride( bmp
->dib
.dsBm
.bmWidth
, bmp
->dib
.dsBm
.bmBitsPixel
);
419 count
= min( count
, src_stride
* bmp
->dib
.dsBm
.bmHeight
);
421 dst_stride
= get_dib_stride( bmp
->dib
.dsBm
.bmWidth
, bmp
->dib
.dsBm
.bmBitsPixel
);
423 src
.visrect
.left
= src
.x
= 0;
424 src
.visrect
.top
= src
.y
= 0;
425 src
.visrect
.right
= src
.width
= bmp
->dib
.dsBm
.bmWidth
;
426 src
.visrect
.bottom
= src
.height
= (count
+ src_stride
- 1 ) / src_stride
;
429 if (count
% src_stride
)
432 int extra_pixels
= ((count
% src_stride
) << 3) / bmp
->dib
.dsBm
.bmBitsPixel
;
434 if ((count
% src_stride
<< 3) % bmp
->dib
.dsBm
.bmBitsPixel
)
435 FIXME( "Unhandled partial pixel\n" );
436 clip
= CreateRectRgn( src
.visrect
.left
, src
.visrect
.top
,
437 src
.visrect
.right
, src
.visrect
.bottom
- 1 );
438 last_row
= CreateRectRgn( src
.visrect
.left
, src
.visrect
.bottom
- 1,
439 src
.visrect
.left
+ extra_pixels
, src
.visrect
.bottom
);
440 CombineRgn( clip
, clip
, last_row
, RGN_OR
);
441 DeleteObject( last_row
);
444 TRACE("(%p, %d, %p) %dx%d %d bpp fetched height: %d\n",
445 hbitmap
, count
, bits
, bmp
->dib
.dsBm
.bmWidth
, bmp
->dib
.dsBm
.bmHeight
,
446 bmp
->dib
.dsBm
.bmBitsPixel
, src
.height
);
448 if (src_stride
== dst_stride
)
450 src_bits
.ptr
= (void *)bits
;
451 src_bits
.is_copy
= FALSE
;
452 src_bits
.free
= NULL
;
456 if (!(src_bits
.ptr
= HeapAlloc( GetProcessHeap(), 0, dst
.height
* dst_stride
)))
458 GDI_ReleaseObj( hbitmap
);
461 src_bits
.is_copy
= TRUE
;
462 src_bits
.free
= free_heap_bits
;
463 for (i
= 0; i
< count
/ src_stride
; i
++)
464 memcpy( (char *)src_bits
.ptr
+ i
* dst_stride
, (char *)bits
+ i
* src_stride
, src_stride
);
465 if (count
% src_stride
)
466 memcpy( (char *)src_bits
.ptr
+ i
* dst_stride
, (char *)bits
+ i
* src_stride
, count
% src_stride
);
469 /* query the color info */
470 info
->bmiHeader
.biSize
= sizeof(info
->bmiHeader
);
471 info
->bmiHeader
.biPlanes
= 1;
472 info
->bmiHeader
.biBitCount
= bmp
->dib
.dsBm
.bmBitsPixel
;
473 info
->bmiHeader
.biCompression
= BI_RGB
;
474 info
->bmiHeader
.biXPelsPerMeter
= 0;
475 info
->bmiHeader
.biYPelsPerMeter
= 0;
476 info
->bmiHeader
.biClrUsed
= 0;
477 info
->bmiHeader
.biClrImportant
= 0;
478 info
->bmiHeader
.biWidth
= 0;
479 info
->bmiHeader
.biHeight
= 0;
480 info
->bmiHeader
.biSizeImage
= 0;
481 err
= bmp
->funcs
->pPutImage( NULL
, hbitmap
, 0, info
, NULL
, NULL
, NULL
, SRCCOPY
);
483 if (!err
|| err
== ERROR_BAD_FORMAT
)
485 info
->bmiHeader
.biWidth
= bmp
->dib
.dsBm
.bmWidth
;
486 info
->bmiHeader
.biHeight
= -dst
.height
;
487 info
->bmiHeader
.biSizeImage
= dst
.height
* dst_stride
;
488 err
= bmp
->funcs
->pPutImage( NULL
, hbitmap
, clip
, info
, &src_bits
, &src
, &dst
, SRCCOPY
);
492 if (clip
) DeleteObject( clip
);
493 if (src_bits
.free
) src_bits
.free( &src_bits
);
494 GDI_ReleaseObj( hbitmap
);
499 static void set_initial_bitmap_bits( HBITMAP hbitmap
, BITMAPOBJ
*bmp
)
501 char src_bmibuf
[FIELD_OFFSET( BITMAPINFO
, bmiColors
[256] )];
502 BITMAPINFO
*src_info
= (BITMAPINFO
*)src_bmibuf
;
503 char dst_bmibuf
[FIELD_OFFSET( BITMAPINFO
, bmiColors
[256] )];
504 BITMAPINFO
*dst_info
= (BITMAPINFO
*)dst_bmibuf
;
506 struct gdi_image_bits bits
;
507 struct bitblt_coords src
, dst
;
509 if (!bmp
->dib
.dsBm
.bmBits
) return;
510 if (bmp
->funcs
->pPutImage
== nulldrv_PutImage
) return;
512 get_ddb_bitmapinfo( bmp
, src_info
);
514 bits
.ptr
= bmp
->dib
.dsBm
.bmBits
;
515 bits
.is_copy
= FALSE
;
521 src
.width
= bmp
->dib
.dsBm
.bmWidth
;
522 src
.height
= bmp
->dib
.dsBm
.bmHeight
;
523 src
.visrect
.left
= 0;
525 src
.visrect
.right
= bmp
->dib
.dsBm
.bmWidth
;
526 src
.visrect
.bottom
= bmp
->dib
.dsBm
.bmHeight
;
529 copy_bitmapinfo( dst_info
, src_info
);
531 err
= bmp
->funcs
->pPutImage( NULL
, hbitmap
, 0, dst_info
, &bits
, &src
, &dst
, 0 );
532 if (err
== ERROR_BAD_FORMAT
)
534 err
= convert_bits( src_info
, &src
, dst_info
, &bits
, FALSE
);
535 if (!err
) err
= bmp
->funcs
->pPutImage( NULL
, hbitmap
, 0, dst_info
, &bits
, &src
, &dst
, 0 );
536 if (bits
.free
) bits
.free( &bits
);
540 /***********************************************************************
543 * Set the type of DC that owns the bitmap. This is used when the
544 * bitmap is selected into a device to initialize the bitmap function
547 static BOOL
BITMAP_SetOwnerDC( HBITMAP hbitmap
, PHYSDEV physdev
)
552 /* never set the owner of the stock bitmap since it can be selected in multiple DCs */
553 if (hbitmap
== GetStockObject(DEFAULT_BITMAP
)) return TRUE
;
555 if (!(bitmap
= GDI_GetObjPtr( hbitmap
, OBJ_BITMAP
))) return FALSE
;
557 if (bitmap
->funcs
!= physdev
->funcs
)
559 /* we can only change from the null driver to some other driver */
560 if (bitmap
->funcs
== &null_driver
)
562 if (physdev
->funcs
->pCreateBitmap
)
564 ret
= physdev
->funcs
->pCreateBitmap( physdev
, hbitmap
);
567 bitmap
->funcs
= physdev
->funcs
;
568 set_initial_bitmap_bits( hbitmap
, bitmap
);
571 else bitmap
->funcs
= &dib_driver
; /* use the DIB driver to emulate DDB support */
575 FIXME( "Trying to select bitmap %p in different DC type\n", hbitmap
);
579 GDI_ReleaseObj( hbitmap
);
584 /***********************************************************************
585 * BITMAP_SelectObject
587 static HGDIOBJ
BITMAP_SelectObject( HGDIOBJ handle
, HDC hdc
)
592 PHYSDEV physdev
= NULL
, old_physdev
= NULL
, pathdev
= NULL
;
594 if (!(dc
= get_dc_ptr( hdc
))) return 0;
596 if (GetObjectType( hdc
) != OBJ_MEMDC
)
602 if (handle
== dc
->hBitmap
) goto done
; /* nothing to do */
604 if (!(bitmap
= GDI_GetObjPtr( handle
, OBJ_BITMAP
)))
610 if (bitmap
->header
.selcount
&& (handle
!= GetStockObject(DEFAULT_BITMAP
)))
612 WARN( "Bitmap already selected in another DC\n" );
613 GDI_ReleaseObj( handle
);
618 if (dc
->physDev
->funcs
== &path_driver
) pathdev
= pop_dc_driver( &dc
->physDev
);
620 old_physdev
= GET_DC_PHYSDEV( dc
, pSelectBitmap
);
621 if(old_physdev
== dc
->dibdrv
)
622 old_physdev
= pop_dc_driver( &dc
->physDev
);
624 physdev
= GET_DC_PHYSDEV( dc
, pSelectBitmap
);
625 if (physdev
->funcs
== &null_driver
)
627 physdev
= dc
->dibdrv
;
628 if (physdev
) push_dc_driver( &dc
->physDev
, physdev
, physdev
->funcs
);
631 if (!dib_driver
.pCreateDC( &dc
->physDev
, NULL
, NULL
, NULL
, NULL
)) goto done
;
632 dc
->dibdrv
= physdev
= dc
->physDev
;
636 if (!BITMAP_SetOwnerDC( handle
, physdev
))
638 GDI_ReleaseObj( handle
);
642 if (!physdev
->funcs
->pSelectBitmap( physdev
, handle
))
644 GDI_ReleaseObj( handle
);
649 dc
->hBitmap
= handle
;
650 GDI_inc_ref_count( handle
);
652 dc
->vis_rect
.left
= 0;
653 dc
->vis_rect
.top
= 0;
654 dc
->vis_rect
.right
= bitmap
->dib
.dsBm
.bmWidth
;
655 dc
->vis_rect
.bottom
= bitmap
->dib
.dsBm
.bmHeight
;
656 GDI_ReleaseObj( handle
);
658 GDI_dec_ref_count( ret
);
664 if (physdev
&& physdev
== dc
->dibdrv
)
665 pop_dc_driver( &dc
->physDev
);
666 if (old_physdev
&& old_physdev
== dc
->dibdrv
)
667 push_dc_driver( &dc
->physDev
, old_physdev
, old_physdev
->funcs
);
669 if (pathdev
) push_dc_driver( &dc
->physDev
, pathdev
, pathdev
->funcs
);
670 release_dc_ptr( dc
);
675 /***********************************************************************
676 * BITMAP_DeleteObject
678 static BOOL
BITMAP_DeleteObject( HGDIOBJ handle
)
680 const struct gdi_dc_funcs
*funcs
;
681 BITMAPOBJ
*bmp
= GDI_GetObjPtr( handle
, OBJ_BITMAP
);
683 if (!bmp
) return FALSE
;
685 GDI_ReleaseObj( handle
);
687 funcs
->pDeleteBitmap( handle
);
689 if (!(bmp
= free_gdi_handle( handle
))) return FALSE
;
691 HeapFree( GetProcessHeap(), 0, bmp
->dib
.dsBm
.bmBits
);
692 return HeapFree( GetProcessHeap(), 0, bmp
);
696 /***********************************************************************
699 static INT
BITMAP_GetObject( HGDIOBJ handle
, INT count
, LPVOID buffer
)
702 BITMAPOBJ
*bmp
= GDI_GetObjPtr( handle
, OBJ_BITMAP
);
706 if (!buffer
) ret
= sizeof(BITMAP
);
707 else if (count
>= sizeof(BITMAP
))
709 BITMAP
*bitmap
= buffer
;
710 *bitmap
= bmp
->dib
.dsBm
;
711 bitmap
->bmBits
= NULL
;
712 ret
= sizeof(BITMAP
);
714 GDI_ReleaseObj( handle
);
719 /******************************************************************************
720 * CreateDiscardableBitmap [GDI32.@]
722 * Creates a discardable bitmap.
725 * Success: Handle to bitmap
728 HBITMAP WINAPI
CreateDiscardableBitmap(
729 HDC hdc
, /* [in] Handle to device context */
730 INT width
, /* [in] Bitmap width */
731 INT height
) /* [in] Bitmap height */
733 return CreateCompatibleBitmap( hdc
, width
, height
);
737 /******************************************************************************
738 * GetBitmapDimensionEx [GDI32.@]
740 * Retrieves dimensions of a bitmap.
746 BOOL WINAPI
GetBitmapDimensionEx(
747 HBITMAP hbitmap
, /* [in] Handle to bitmap */
748 LPSIZE size
) /* [out] Address of struct receiving dimensions */
750 BITMAPOBJ
* bmp
= GDI_GetObjPtr( hbitmap
, OBJ_BITMAP
);
751 if (!bmp
) return FALSE
;
753 GDI_ReleaseObj( hbitmap
);
758 /******************************************************************************
759 * SetBitmapDimensionEx [GDI32.@]
761 * Assigns dimensions to a bitmap.
762 * MSDN says that this function will fail if hbitmap is a handle created by
763 * CreateDIBSection, but that's not true on Windows 2000.
769 BOOL WINAPI
SetBitmapDimensionEx(
770 HBITMAP hbitmap
, /* [in] Handle to bitmap */
771 INT x
, /* [in] Bitmap width */
772 INT y
, /* [in] Bitmap height */
773 LPSIZE prevSize
) /* [out] Address of structure for orig dims */
775 BITMAPOBJ
* bmp
= GDI_GetObjPtr( hbitmap
, OBJ_BITMAP
);
776 if (!bmp
) return FALSE
;
777 if (prevSize
) *prevSize
= bmp
->size
;
780 GDI_ReleaseObj( hbitmap
);