blob: f6734f286fd8e4c0baa0dc5bb8721e8f5fdafb96 [file] [log] [blame]
Alexandre Julliard401710d1993-09-04 10:09:32 +00001/*
2 * GDI bitmap objects
3 *
4 * Copyright 1993 Alexandre Julliard
Huw D M Davies87f87bf1998-10-28 09:53:53 +00005 * 1998 Huw D M Davies
Alexandre Julliarda2f2e011995-06-06 16:40:35 +00006 */
Alexandre Julliardd90840e1996-06-11 16:02:08 +00007
Alexandre Julliard8d24ae61994-04-05 21:42:43 +00008#include <stdlib.h>
Alexandre Julliard84c70f51997-05-09 08:40:27 +00009#include <string.h>
Marcus Meissner317af321999-02-17 13:51:06 +000010
11#include "wine/winbase16.h"
Alexandre Julliard401710d1993-09-04 10:09:32 +000012#include "gdi.h"
Alexandre Julliard8d24ae61994-04-05 21:42:43 +000013#include "bitmap.h"
Alexandre Julliard18f92e71996-07-17 20:02:21 +000014#include "heap.h"
Alexandre Julliard06c275a1999-05-02 14:32:27 +000015#include "debugtools.h"
Patrik Stridvall8d8703c1999-02-04 14:05:38 +000016#include "wine/winuser16.h"
Alexandre Julliard670cdc41997-08-24 16:00:30 +000017
Alexandre Julliard946a4442000-07-30 13:50:27 +000018DEFAULT_DEBUG_CHANNEL(bitmap);
Patrik Stridvallb4b9fae1999-04-19 14:56:29 +000019
Patrik Stridvallb87fe2e1999-04-01 08:16:08 +000020BITMAP_DRIVER *BITMAP_Driver = NULL;
21
Alexandre Julliard77b99181997-09-14 17:17:23 +000022
23/***********************************************************************
Huw D M Davies82617361998-11-01 16:35:42 +000024 * BITMAP_GetWidthBytes
Alexandre Julliard77b99181997-09-14 17:17:23 +000025 *
Huw D M Davies82617361998-11-01 16:35:42 +000026 * Return number of bytes taken by a scanline of 16-bit aligned Windows DDB
27 * data.
Alexandre Julliard77b99181997-09-14 17:17:23 +000028 */
Alexandre Julliarda3960291999-02-26 11:11:13 +000029INT BITMAP_GetWidthBytes( INT bmWidth, INT bpp )
Alexandre Julliard77b99181997-09-14 17:17:23 +000030{
31 switch(bpp)
32 {
33 case 1:
34 return 2 * ((bmWidth+15) >> 4);
35
36 case 24:
37 bmWidth *= 3; /* fall through */
38 case 8:
39 return bmWidth + (bmWidth & 1);
40
41 case 32:
42 return bmWidth * 4;
43
44 case 16:
45 case 15:
46 return bmWidth * 2;
47
48 case 4:
49 return 2 * ((bmWidth+3) >> 2);
50
51 default:
Dimitrie O. Paundd03cc11999-12-08 03:56:23 +000052 WARN("Unknown depth %d, please report.\n", bpp );
Alexandre Julliard77b99181997-09-14 17:17:23 +000053 }
54 return -1;
55}
Alexandre Julliard670cdc41997-08-24 16:00:30 +000056
57/***********************************************************************
Ulrich Weigand71f7a461998-10-11 19:13:52 +000058 * CreateUserBitmap16 (GDI.407)
59 */
60HBITMAP16 WINAPI CreateUserBitmap16( INT16 width, INT16 height, UINT16 planes,
61 UINT16 bpp, LPCVOID bits )
62{
63 return CreateBitmap16( width, height, planes, bpp, bits );
64}
65
66/***********************************************************************
67 * CreateUserDiscardableBitmap16 (GDI.409)
68 */
69HBITMAP16 WINAPI CreateUserDiscardableBitmap16( WORD dummy,
70 INT16 width, INT16 height )
71{
Alexandre Julliard946a4442000-07-30 13:50:27 +000072 HDC hdc = CreateDCA( "DISPLAY", NULL, NULL, NULL );
73 HBITMAP16 ret = CreateCompatibleBitmap16( hdc, width, height );
74 DeleteDC( hdc );
75 return ret;
Ulrich Weigand71f7a461998-10-11 19:13:52 +000076}
77
78
Ulrich Weigand71f7a461998-10-11 19:13:52 +000079/***********************************************************************
Alexandre Julliard21979011997-03-05 08:22:35 +000080 * CreateBitmap16 (GDI.48)
Patrik Stridvalld0a41772001-02-14 23:11:17 +000081 * CreateBitmap16 (DISPLAY.48)
Alexandre Julliard401710d1993-09-04 10:09:32 +000082 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +000083HBITMAP16 WINAPI CreateBitmap16( INT16 width, INT16 height, UINT16 planes,
84 UINT16 bpp, LPCVOID bits )
Alexandre Julliard21979011997-03-05 08:22:35 +000085{
Alexandre Julliarda3960291999-02-26 11:11:13 +000086 return CreateBitmap( width, height, planes, bpp, bits );
Alexandre Julliard21979011997-03-05 08:22:35 +000087}
88
89
Alexandre Julliard46ea8b31998-05-03 19:01:20 +000090/******************************************************************************
Patrik Stridvalld0a41772001-02-14 23:11:17 +000091 * CreateBitmap [GDI32.@] Creates a bitmap with the specified info
Alexandre Julliard46ea8b31998-05-03 19:01:20 +000092 *
93 * PARAMS
94 * width [I] bitmap width
95 * height [I] bitmap height
96 * planes [I] Number of color planes
97 * bpp [I] Number of bits to identify a color
98 * bits [I] Pointer to array containing color data
99 *
100 * RETURNS
101 * Success: Handle to bitmap
Huw D M Davies87f87bf1998-10-28 09:53:53 +0000102 * Failure: 0
Alexandre Julliard21979011997-03-05 08:22:35 +0000103 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000104HBITMAP WINAPI CreateBitmap( INT width, INT height, UINT planes,
105 UINT bpp, LPCVOID bits )
Alexandre Julliard401710d1993-09-04 10:09:32 +0000106{
Huw D M Davies87f87bf1998-10-28 09:53:53 +0000107 BITMAPOBJ *bmp;
Alexandre Julliarda3960291999-02-26 11:11:13 +0000108 HBITMAP hbitmap;
Alexandre Julliarda2f2e011995-06-06 16:40:35 +0000109
Alexandre Julliard7ebe1a41996-12-22 18:27:48 +0000110 planes = (BYTE)planes;
111 bpp = (BYTE)bpp;
112
Alexandre Julliarda2f2e011995-06-06 16:40:35 +0000113
114 /* Check parameters */
Huw D M Davies87f87bf1998-10-28 09:53:53 +0000115 if (!height || !width) return 0;
116 if (planes != 1) {
Dimitrie O. Paundd03cc11999-12-08 03:56:23 +0000117 FIXME("planes = %d\n", planes);
Huw D M Davies87f87bf1998-10-28 09:53:53 +0000118 return 0;
119 }
Alexandre Julliarda2f2e011995-06-06 16:40:35 +0000120 if (height < 0) height = -height;
121 if (width < 0) width = -width;
122
123 /* Create the BITMAPOBJ */
Alexandre Julliard2a2321b2000-08-19 21:38:55 +0000124 if (!(bmp = GDI_AllocObject( sizeof(BITMAPOBJ), BITMAP_MAGIC, &hbitmap ))) return 0;
Alexandre Julliarda2f2e011995-06-06 16:40:35 +0000125
Dimitrie O. Paundd03cc11999-12-08 03:56:23 +0000126 TRACE("%dx%d, %d colors returning %08x\n", width, height,
Huw D M Davies87f87bf1998-10-28 09:53:53 +0000127 1 << (planes*bpp), hbitmap);
Alexandre Julliarda2f2e011995-06-06 16:40:35 +0000128
Huw D M Davies87f87bf1998-10-28 09:53:53 +0000129 bmp->size.cx = 0;
130 bmp->size.cy = 0;
131 bmp->bitmap.bmType = 0;
Huw D M Davies82617361998-11-01 16:35:42 +0000132 bmp->bitmap.bmWidth = width;
133 bmp->bitmap.bmHeight = height;
134 bmp->bitmap.bmPlanes = planes;
135 bmp->bitmap.bmBitsPixel = bpp;
136 bmp->bitmap.bmWidthBytes = BITMAP_GetWidthBytes( width, bpp );
Huw D M Davies87f87bf1998-10-28 09:53:53 +0000137 bmp->bitmap.bmBits = NULL;
138
Alexandre Julliarda08e2cf2000-03-28 13:37:50 +0000139 bmp->funcs = NULL;
140 bmp->physBitmap = NULL;
Huw D M Davies87f87bf1998-10-28 09:53:53 +0000141 bmp->dib = NULL;
142
143 if (bits) /* Set bitmap bits */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000144 SetBitmapBits( hbitmap, height * bmp->bitmap.bmWidthBytes,
Alexandre Julliard21979011997-03-05 08:22:35 +0000145 bits );
Alexandre Julliard2a2321b2000-08-19 21:38:55 +0000146 GDI_ReleaseObj( hbitmap );
Alexandre Julliarda2f2e011995-06-06 16:40:35 +0000147 return hbitmap;
Alexandre Julliard401710d1993-09-04 10:09:32 +0000148}
149
150
151/***********************************************************************
Alexandre Julliard21979011997-03-05 08:22:35 +0000152 * CreateCompatibleBitmap16 (GDI.51)
Alexandre Julliard401710d1993-09-04 10:09:32 +0000153 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000154HBITMAP16 WINAPI CreateCompatibleBitmap16(HDC16 hdc, INT16 width, INT16 height)
Alexandre Julliard401710d1993-09-04 10:09:32 +0000155{
Alexandre Julliarda3960291999-02-26 11:11:13 +0000156 return CreateCompatibleBitmap( hdc, width, height );
Alexandre Julliard21979011997-03-05 08:22:35 +0000157}
158
159
Alexandre Julliard46ea8b31998-05-03 19:01:20 +0000160/******************************************************************************
Patrik Stridvalld0a41772001-02-14 23:11:17 +0000161 * CreateCompatibleBitmap [GDI32.@] Creates a bitmap compatible with the DC
Alexandre Julliard46ea8b31998-05-03 19:01:20 +0000162 *
163 * PARAMS
164 * hdc [I] Handle to device context
165 * width [I] Width of bitmap
166 * height [I] Height of bitmap
167 *
168 * RETURNS
169 * Success: Handle to bitmap
Huw D M Davies87f87bf1998-10-28 09:53:53 +0000170 * Failure: 0
Alexandre Julliard21979011997-03-05 08:22:35 +0000171 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000172HBITMAP WINAPI CreateCompatibleBitmap( HDC hdc, INT width, INT height)
Alexandre Julliard21979011997-03-05 08:22:35 +0000173{
Alexandre Julliarda3960291999-02-26 11:11:13 +0000174 HBITMAP hbmpRet = 0;
Alexandre Julliardd90840e1996-06-11 16:02:08 +0000175 DC *dc;
176
Dimitrie O. Paundd03cc11999-12-08 03:56:23 +0000177 TRACE("(%04x,%d,%d) = \n", hdc, width, height );
Alexandre Julliard21979011997-03-05 08:22:35 +0000178 if (!(dc = DC_GetDCPtr( hdc ))) return 0;
NF Stevens16f0dfb1999-01-01 18:45:03 +0000179 if ((width >= 0x10000) || (height >= 0x10000)) {
Dimitrie O. Paundd03cc11999-12-08 03:56:23 +0000180 FIXME("got bad width %d or height %d, please look for reason\n",
Huw D M Davies87f87bf1998-10-28 09:53:53 +0000181 width, height );
Huw D M Daviesd6a91b71998-12-02 10:29:04 +0000182 } else {
Eric Pouech7990b7c1999-06-07 17:46:39 +0000183 /* MS doc says if width or height is 0, return 1-by-1 pixel, monochrome bitmap */
184 if (!width || !height)
185 hbmpRet = CreateBitmap( 1, 1, 1, 1, NULL );
186 else
Alexandre Julliard2239abb2000-11-05 02:05:07 +0000187 hbmpRet = CreateBitmap( width, height, 1, dc->bitsPerPixel, NULL );
Huw D M Daviesd6a91b71998-12-02 10:29:04 +0000188 if(dc->funcs->pCreateBitmap)
189 dc->funcs->pCreateBitmap( hbmpRet );
Huw D M Davies87f87bf1998-10-28 09:53:53 +0000190 }
Dimitrie O. Paundd03cc11999-12-08 03:56:23 +0000191 TRACE("\t\t%04x\n", hbmpRet);
Alexandre Julliard2a2321b2000-08-19 21:38:55 +0000192 GDI_ReleaseObj(hdc);
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000193 return hbmpRet;
Alexandre Julliard401710d1993-09-04 10:09:32 +0000194}
195
196
197/***********************************************************************
Alexandre Julliardd90840e1996-06-11 16:02:08 +0000198 * CreateBitmapIndirect16 (GDI.49)
Alexandre Julliard401710d1993-09-04 10:09:32 +0000199 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000200HBITMAP16 WINAPI CreateBitmapIndirect16( const BITMAP16 * bmp )
Alexandre Julliard401710d1993-09-04 10:09:32 +0000201{
Alexandre Julliard21979011997-03-05 08:22:35 +0000202 return CreateBitmap16( bmp->bmWidth, bmp->bmHeight, bmp->bmPlanes,
Alexandre Julliard982a2232000-12-13 20:20:09 +0000203 bmp->bmBitsPixel, MapSL( bmp->bmBits ) );
Alexandre Julliard401710d1993-09-04 10:09:32 +0000204}
205
206
Alexandre Julliard46ea8b31998-05-03 19:01:20 +0000207/******************************************************************************
Patrik Stridvalld0a41772001-02-14 23:11:17 +0000208 * CreateBitmapIndirect [GDI32.@] Creates a bitmap with the specifies info
Alexandre Julliard46ea8b31998-05-03 19:01:20 +0000209 *
210 * RETURNS
211 * Success: Handle to bitmap
212 * Failure: NULL
Alexandre Julliard401710d1993-09-04 10:09:32 +0000213 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000214HBITMAP WINAPI CreateBitmapIndirect(
215 const BITMAP * bmp) /* [in] Pointer to the bitmap data */
Alexandre Julliardd90840e1996-06-11 16:02:08 +0000216{
Alexandre Julliarda3960291999-02-26 11:11:13 +0000217 return CreateBitmap( bmp->bmWidth, bmp->bmHeight, bmp->bmPlanes,
Alexandre Julliard21979011997-03-05 08:22:35 +0000218 bmp->bmBitsPixel, bmp->bmBits );
Alexandre Julliardd90840e1996-06-11 16:02:08 +0000219}
220
221
222/***********************************************************************
Alexandre Julliard21979011997-03-05 08:22:35 +0000223 * GetBitmapBits16 (GDI.74)
Alexandre Julliardd90840e1996-06-11 16:02:08 +0000224 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000225LONG WINAPI GetBitmapBits16( HBITMAP16 hbitmap, LONG count, LPVOID buffer )
Alexandre Julliard21979011997-03-05 08:22:35 +0000226{
Alexandre Julliarda3960291999-02-26 11:11:13 +0000227 return GetBitmapBits( hbitmap, count, buffer );
Alexandre Julliard21979011997-03-05 08:22:35 +0000228}
229
230
231/***********************************************************************
Patrik Stridvalld0a41772001-02-14 23:11:17 +0000232 * GetBitmapBits [GDI32.@] Copies bitmap bits of bitmap to buffer
Alexandre Julliard46ea8b31998-05-03 19:01:20 +0000233 *
234 * RETURNS
235 * Success: Number of bytes copied
236 * Failure: 0
Alexandre Julliard21979011997-03-05 08:22:35 +0000237 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000238LONG WINAPI GetBitmapBits(
239 HBITMAP hbitmap, /* [in] Handle to bitmap */
Alexandre Julliard46ea8b31998-05-03 19:01:20 +0000240 LONG count, /* [in] Number of bytes to copy */
Huw D M Davies87f87bf1998-10-28 09:53:53 +0000241 LPVOID bits) /* [out] Pointer to buffer to receive bits */
Alexandre Julliard401710d1993-09-04 10:09:32 +0000242{
Huw D M Davies87f87bf1998-10-28 09:53:53 +0000243 BITMAPOBJ *bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC );
244 LONG height, ret;
Alexandre Julliard8d24ae61994-04-05 21:42:43 +0000245
Huw D M Davies87f87bf1998-10-28 09:53:53 +0000246 if (!bmp) return 0;
Pascal Lessard8903e531999-05-22 10:39:00 +0000247
248 /* If the bits vector is null, the function should return the read size */
249 if(bits == NULL)
Alexandre Julliard2a2321b2000-08-19 21:38:55 +0000250 {
251 ret = bmp->bitmap.bmWidthBytes * bmp->bitmap.bmHeight;
252 goto done;
253 }
Huw D M Davies87f87bf1998-10-28 09:53:53 +0000254
Alexandre Julliardade697e1995-11-26 13:59:11 +0000255 if (count < 0) {
Dimitrie O. Paundd03cc11999-12-08 03:56:23 +0000256 WARN("(%ld): Negative number of bytes passed???\n", count );
Alexandre Julliardade697e1995-11-26 13:59:11 +0000257 count = -count;
258 }
Alexandre Julliard8d24ae61994-04-05 21:42:43 +0000259
Huw D M Davies87f87bf1998-10-28 09:53:53 +0000260 /* Only get entire lines */
Alexandre Julliard8d24ae61994-04-05 21:42:43 +0000261 height = count / bmp->bitmap.bmWidthBytes;
262 if (height > bmp->bitmap.bmHeight) height = bmp->bitmap.bmHeight;
Huw D M Davies87f87bf1998-10-28 09:53:53 +0000263 count = height * bmp->bitmap.bmWidthBytes;
Uwe Bonnes1f43de31998-11-07 12:25:18 +0000264 if (count == 0)
265 {
Francois Gouget05fc3cd2001-01-22 02:22:26 +0000266 WARN("Less than one entire line requested\n");
Alexandre Julliard2a2321b2000-08-19 21:38:55 +0000267 ret = 0;
268 goto done;
Uwe Bonnes1f43de31998-11-07 12:25:18 +0000269 }
270
Alexandre Julliard77b99181997-09-14 17:17:23 +0000271
Dimitrie O. Paundd03cc11999-12-08 03:56:23 +0000272 TRACE("(%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 );
Alexandre Julliard77b99181997-09-14 17:17:23 +0000275
Alexandre Julliarda08e2cf2000-03-28 13:37:50 +0000276 if(bmp->funcs) {
Alexandre Julliard77b99181997-09-14 17:17:23 +0000277
Dimitrie O. Paundd03cc11999-12-08 03:56:23 +0000278 TRACE("Calling device specific BitmapBits\n");
Alexandre Julliarda08e2cf2000-03-28 13:37:50 +0000279 if(bmp->funcs->pBitmapBits)
280 ret = bmp->funcs->pBitmapBits(hbitmap, bits, count, DDB_GET);
Huw D M Davies87f87bf1998-10-28 09:53:53 +0000281 else {
Dimitrie O. Paundd03cc11999-12-08 03:56:23 +0000282 ERR("BitmapBits == NULL??\n");
Huw D M Davies87f87bf1998-10-28 09:53:53 +0000283 ret = 0;
284 }
Alexandre Julliard84c70f51997-05-09 08:40:27 +0000285
Huw D M Davies87f87bf1998-10-28 09:53:53 +0000286 } else {
Alexandre Julliard03468f71998-02-15 19:40:49 +0000287
Huw D M Davies87f87bf1998-10-28 09:53:53 +0000288 if(!bmp->bitmap.bmBits) {
Dimitrie O. Paundd03cc11999-12-08 03:56:23 +0000289 WARN("Bitmap is empty\n");
Huw D M Davies87f87bf1998-10-28 09:53:53 +0000290 ret = 0;
291 } else {
292 memcpy(bits, bmp->bitmap.bmBits, count);
293 ret = count;
Alexandre Julliard84c70f51997-05-09 08:40:27 +0000294 }
Alexandre Julliard85ed45e1998-08-22 19:03:56 +0000295
Alexandre Julliard84c70f51997-05-09 08:40:27 +0000296 }
Alexandre Julliard2a2321b2000-08-19 21:38:55 +0000297 done:
298 GDI_ReleaseObj( hbitmap );
Huw D M Davies87f87bf1998-10-28 09:53:53 +0000299 return ret;
Alexandre Julliard401710d1993-09-04 10:09:32 +0000300}
301
302
303/***********************************************************************
Alexandre Julliard21979011997-03-05 08:22:35 +0000304 * SetBitmapBits16 (GDI.106)
Alexandre Julliard401710d1993-09-04 10:09:32 +0000305 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000306LONG WINAPI SetBitmapBits16( HBITMAP16 hbitmap, LONG count, LPCVOID buffer )
Alexandre Julliard21979011997-03-05 08:22:35 +0000307{
Alexandre Julliarda3960291999-02-26 11:11:13 +0000308 return SetBitmapBits( hbitmap, count, buffer );
Alexandre Julliard21979011997-03-05 08:22:35 +0000309}
310
311
Alexandre Julliard46ea8b31998-05-03 19:01:20 +0000312/******************************************************************************
Patrik Stridvalld0a41772001-02-14 23:11:17 +0000313 * SetBitmapBits [GDI32.@] Sets bits of color data for a bitmap
Alexandre Julliard46ea8b31998-05-03 19:01:20 +0000314 *
315 * RETURNS
316 * Success: Number of bytes used in setting the bitmap bits
317 * Failure: 0
Alexandre Julliard21979011997-03-05 08:22:35 +0000318 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000319LONG WINAPI SetBitmapBits(
320 HBITMAP hbitmap, /* [in] Handle to bitmap */
Alexandre Julliard46ea8b31998-05-03 19:01:20 +0000321 LONG count, /* [in] Number of bytes in bitmap array */
Huw D M Davies87f87bf1998-10-28 09:53:53 +0000322 LPCVOID bits) /* [in] Address of array with bitmap bits */
Alexandre Julliard401710d1993-09-04 10:09:32 +0000323{
Huw D M Davies87f87bf1998-10-28 09:53:53 +0000324 BITMAPOBJ *bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC );
325 LONG height, ret;
Alexandre Julliard8d24ae61994-04-05 21:42:43 +0000326
Pascal Lessard8903e531999-05-22 10:39:00 +0000327 if ((!bmp) || (!bits))
328 return 0;
Huw D M Davies87f87bf1998-10-28 09:53:53 +0000329
Alexandre Julliardade697e1995-11-26 13:59:11 +0000330 if (count < 0) {
Dimitrie O. Paundd03cc11999-12-08 03:56:23 +0000331 WARN("(%ld): Negative number of bytes passed???\n", count );
Alexandre Julliardade697e1995-11-26 13:59:11 +0000332 count = -count;
333 }
Alexandre Julliard8d24ae61994-04-05 21:42:43 +0000334
Huw D M Davies87f87bf1998-10-28 09:53:53 +0000335 /* Only get entire lines */
Alexandre Julliard8d24ae61994-04-05 21:42:43 +0000336 height = count / bmp->bitmap.bmWidthBytes;
337 if (height > bmp->bitmap.bmHeight) height = bmp->bitmap.bmHeight;
Huw D M Davies87f87bf1998-10-28 09:53:53 +0000338 count = height * bmp->bitmap.bmWidthBytes;
Alexandre Julliard77b99181997-09-14 17:17:23 +0000339
Dimitrie O. Paundd03cc11999-12-08 03:56:23 +0000340 TRACE("(%08x, %ld, %p) %dx%d %d colors fetched height: %ld\n",
341 hbitmap, count, bits, bmp->bitmap.bmWidth, bmp->bitmap.bmHeight,
342 1 << bmp->bitmap.bmBitsPixel, height );
Alexandre Julliard77b99181997-09-14 17:17:23 +0000343
Alexandre Julliarda08e2cf2000-03-28 13:37:50 +0000344 if(bmp->funcs) {
Huw D M Davies87f87bf1998-10-28 09:53:53 +0000345
Dimitrie O. Paundd03cc11999-12-08 03:56:23 +0000346 TRACE("Calling device specific BitmapBits\n");
Alexandre Julliarda08e2cf2000-03-28 13:37:50 +0000347 if(bmp->funcs->pBitmapBits)
348 ret = bmp->funcs->pBitmapBits(hbitmap, (void *) bits, count, DDB_SET);
Huw D M Davies87f87bf1998-10-28 09:53:53 +0000349 else {
Dimitrie O. Paundd03cc11999-12-08 03:56:23 +0000350 ERR("BitmapBits == NULL??\n");
Huw D M Davies87f87bf1998-10-28 09:53:53 +0000351 ret = 0;
352 }
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000353
Huw D M Davies87f87bf1998-10-28 09:53:53 +0000354 } else {
Alexandre Julliard84c70f51997-05-09 08:40:27 +0000355
Huw D M Davies87f87bf1998-10-28 09:53:53 +0000356 if(!bmp->bitmap.bmBits) /* Alloc enough for entire bitmap */
357 bmp->bitmap.bmBits = HeapAlloc( GetProcessHeap(), 0, count );
358 if(!bmp->bitmap.bmBits) {
Dimitrie O. Paundd03cc11999-12-08 03:56:23 +0000359 WARN("Unable to allocate bit buffer\n");
Huw D M Davies87f87bf1998-10-28 09:53:53 +0000360 ret = 0;
361 } else {
362 memcpy(bmp->bitmap.bmBits, bits, count);
363 ret = count;
364 }
Alexandre Julliard84c70f51997-05-09 08:40:27 +0000365 }
366
Alexandre Julliard2a2321b2000-08-19 21:38:55 +0000367 GDI_ReleaseObj( hbitmap );
Huw D M Davies87f87bf1998-10-28 09:53:53 +0000368 return ret;
Alexandre Julliard401710d1993-09-04 10:09:32 +0000369}
370
Alexandre Julliard594997c1995-04-30 10:05:20 +0000371/**********************************************************************
Huw D M Davies87f87bf1998-10-28 09:53:53 +0000372 * BITMAP_CopyBitmap
Alexandre Julliard46ea8b31998-05-03 19:01:20 +0000373 *
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +0000374 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000375HBITMAP BITMAP_CopyBitmap(HBITMAP hbitmap)
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +0000376{
Huw D M Davies87f87bf1998-10-28 09:53:53 +0000377 BITMAPOBJ *bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC );
Alexandre Julliarda3960291999-02-26 11:11:13 +0000378 HBITMAP res = 0;
379 BITMAP bm;
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +0000380
Huw D M Davies87f87bf1998-10-28 09:53:53 +0000381 if(!bmp) return 0;
382
383 bm = bmp->bitmap;
384 bm.bmBits = NULL;
Alexandre Julliarda3960291999-02-26 11:11:13 +0000385 res = CreateBitmapIndirect(&bm);
Huw D M Davies87f87bf1998-10-28 09:53:53 +0000386
387 if(res) {
388 char *buf = HeapAlloc( GetProcessHeap(), 0, bm.bmWidthBytes *
389 bm.bmHeight );
Alexandre Julliarda3960291999-02-26 11:11:13 +0000390 GetBitmapBits (hbitmap, bm.bmWidthBytes * bm.bmHeight, buf);
391 SetBitmapBits (res, bm.bmWidthBytes * bm.bmHeight, buf);
Huw D M Davies87f87bf1998-10-28 09:53:53 +0000392 HeapFree( GetProcessHeap(), 0, buf );
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +0000393 }
Huw D M Davies87f87bf1998-10-28 09:53:53 +0000394
Alexandre Julliard2a2321b2000-08-19 21:38:55 +0000395 GDI_ReleaseObj( hbitmap );
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +0000396 return res;
397}
398
Alexandre Julliard401710d1993-09-04 10:09:32 +0000399/***********************************************************************
Alexandre Julliard7cbe6571995-01-09 18:21:16 +0000400 * BITMAP_DeleteObject
Alexandre Julliard401710d1993-09-04 10:09:32 +0000401 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000402BOOL BITMAP_DeleteObject( HBITMAP16 hbitmap, BITMAPOBJ * bmp )
Alexandre Julliard401710d1993-09-04 10:09:32 +0000403{
Alexandre Julliarda08e2cf2000-03-28 13:37:50 +0000404 if (bmp->funcs && bmp->funcs->pDeleteObject)
405 bmp->funcs->pDeleteObject( hbitmap );
Huw D M Davies87f87bf1998-10-28 09:53:53 +0000406
407 if( bmp->bitmap.bmBits )
408 HeapFree( GetProcessHeap(), 0, bmp->bitmap.bmBits );
Alexandre Julliarda845b881998-06-01 10:44:35 +0000409
Alexandre Julliard642d3131998-07-12 19:29:36 +0000410 DIB_DeleteDIBSection( bmp );
Alexandre Julliarda845b881998-06-01 10:44:35 +0000411
Alexandre Julliard2a2321b2000-08-19 21:38:55 +0000412 return GDI_FreeObject( hbitmap, bmp );
Alexandre Julliard401710d1993-09-04 10:09:32 +0000413}
414
415
416/***********************************************************************
Alexandre Julliardd90840e1996-06-11 16:02:08 +0000417 * BITMAP_GetObject16
Alexandre Julliard401710d1993-09-04 10:09:32 +0000418 */
Alexandre Julliardd90840e1996-06-11 16:02:08 +0000419INT16 BITMAP_GetObject16( BITMAPOBJ * bmp, INT16 count, LPVOID buffer )
Alexandre Julliard401710d1993-09-04 10:09:32 +0000420{
Alexandre Julliard642d3131998-07-12 19:29:36 +0000421 if (bmp->dib)
Alexandre Julliarda845b881998-06-01 10:44:35 +0000422 {
Alexandre Julliardd30dfd21998-09-27 18:28:36 +0000423 if ( count <= sizeof(BITMAP16) )
424 {
Patrik Stridvallb87fe2e1999-04-01 08:16:08 +0000425 BITMAP *bmp32 = &bmp->dib->dsBm;
Alexandre Julliardd30dfd21998-09-27 18:28:36 +0000426 BITMAP16 bmp16;
427 bmp16.bmType = bmp32->bmType;
428 bmp16.bmWidth = bmp32->bmWidth;
429 bmp16.bmHeight = bmp32->bmHeight;
430 bmp16.bmWidthBytes = bmp32->bmWidthBytes;
431 bmp16.bmPlanes = bmp32->bmPlanes;
432 bmp16.bmBitsPixel = bmp32->bmBitsPixel;
Huw D M Davies87f87bf1998-10-28 09:53:53 +0000433 bmp16.bmBits = (SEGPTR)0;
Alexandre Julliardd30dfd21998-09-27 18:28:36 +0000434 memcpy( buffer, &bmp16, count );
435 return count;
436 }
437 else
438 {
Dimitrie O. Paundd03cc11999-12-08 03:56:23 +0000439 FIXME("not implemented for DIBs: count %d\n", count);
Alexandre Julliardd30dfd21998-09-27 18:28:36 +0000440 return 0;
441 }
Alexandre Julliarda845b881998-06-01 10:44:35 +0000442 }
443 else
444 {
Huw D M Davies87f87bf1998-10-28 09:53:53 +0000445 BITMAP16 bmp16;
446 bmp16.bmType = bmp->bitmap.bmType;
447 bmp16.bmWidth = bmp->bitmap.bmWidth;
448 bmp16.bmHeight = bmp->bitmap.bmHeight;
449 bmp16.bmWidthBytes = bmp->bitmap.bmWidthBytes;
450 bmp16.bmPlanes = bmp->bitmap.bmPlanes;
451 bmp16.bmBitsPixel = bmp->bitmap.bmBitsPixel;
452 bmp16.bmBits = (SEGPTR)0;
453 if (count > sizeof(bmp16)) count = sizeof(bmp16);
454 memcpy( buffer, &bmp16, count );
Alexandre Julliarda845b881998-06-01 10:44:35 +0000455 return count;
456 }
Alexandre Julliard401710d1993-09-04 10:09:32 +0000457}
Alexandre Julliard401710d1993-09-04 10:09:32 +0000458
Alexandre Julliard401710d1993-09-04 10:09:32 +0000459
460/***********************************************************************
Patrik Stridvall2d6457c2000-03-28 20:22:59 +0000461 * BITMAP_GetObject
Alexandre Julliardd90840e1996-06-11 16:02:08 +0000462 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000463INT BITMAP_GetObject( BITMAPOBJ * bmp, INT count, LPVOID buffer )
Alexandre Julliardd90840e1996-06-11 16:02:08 +0000464{
Alexandre Julliard642d3131998-07-12 19:29:36 +0000465 if (bmp->dib)
Alexandre Julliarda845b881998-06-01 10:44:35 +0000466 {
467 if (count < sizeof(DIBSECTION))
468 {
Alexandre Julliarda3960291999-02-26 11:11:13 +0000469 if (count > sizeof(BITMAP)) count = sizeof(BITMAP);
Alexandre Julliarda845b881998-06-01 10:44:35 +0000470 }
471 else
472 {
473 if (count > sizeof(DIBSECTION)) count = sizeof(DIBSECTION);
474 }
475
Patrik Stridvallb87fe2e1999-04-01 08:16:08 +0000476 memcpy( buffer, bmp->dib, count );
Alexandre Julliarda845b881998-06-01 10:44:35 +0000477 return count;
478 }
479 else
480 {
Alexandre Julliarda3960291999-02-26 11:11:13 +0000481 if (count > sizeof(BITMAP)) count = sizeof(BITMAP);
Huw D M Davies87f87bf1998-10-28 09:53:53 +0000482 memcpy( buffer, &bmp->bitmap, count );
Alexandre Julliarda845b881998-06-01 10:44:35 +0000483 return count;
484 }
Alexandre Julliardd90840e1996-06-11 16:02:08 +0000485}
486
487
Alexandre Julliard36ca1361994-06-02 22:38:20 +0000488/***********************************************************************
Alexandre Julliard21979011997-03-05 08:22:35 +0000489 * CreateDiscardableBitmap16 (GDI.156)
Alexandre Julliard36ca1361994-06-02 22:38:20 +0000490 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000491HBITMAP16 WINAPI CreateDiscardableBitmap16( HDC16 hdc, INT16 width,
492 INT16 height )
Alexandre Julliard36ca1361994-06-02 22:38:20 +0000493{
Alexandre Julliard21979011997-03-05 08:22:35 +0000494 return CreateCompatibleBitmap16( hdc, width, height );
495}
496
497
Alexandre Julliard46ea8b31998-05-03 19:01:20 +0000498/******************************************************************************
Patrik Stridvalld0a41772001-02-14 23:11:17 +0000499 * CreateDiscardableBitmap [GDI32.@] Creates a discardable bitmap
Alexandre Julliard46ea8b31998-05-03 19:01:20 +0000500 *
501 * RETURNS
502 * Success: Handle to bitmap
503 * Failure: NULL
Alexandre Julliard21979011997-03-05 08:22:35 +0000504 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000505HBITMAP WINAPI CreateDiscardableBitmap(
506 HDC hdc, /* [in] Handle to device context */
507 INT width, /* [in] Bitmap width */
508 INT height) /* [in] Bitmap height */
Alexandre Julliard21979011997-03-05 08:22:35 +0000509{
Alexandre Julliarda3960291999-02-26 11:11:13 +0000510 return CreateCompatibleBitmap( hdc, width, height );
Alexandre Julliard36ca1361994-06-02 22:38:20 +0000511}
Alexandre Julliard401710d1993-09-04 10:09:32 +0000512
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000513
Alexandre Julliard401710d1993-09-04 10:09:32 +0000514/***********************************************************************
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000515 * GetBitmapDimensionEx16 (GDI.468)
Alexandre Julliard46ea8b31998-05-03 19:01:20 +0000516 *
517 * NOTES
Patrik Stridvall2d6457c2000-03-28 20:22:59 +0000518 * Can this call GetBitmapDimensionEx?
Alexandre Julliard401710d1993-09-04 10:09:32 +0000519 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000520BOOL16 WINAPI GetBitmapDimensionEx16( HBITMAP16 hbitmap, LPSIZE16 size )
Alexandre Julliard401710d1993-09-04 10:09:32 +0000521{
522 BITMAPOBJ * bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC );
523 if (!bmp) return FALSE;
Alexandre Julliard982a2232000-12-13 20:20:09 +0000524 size->cx = bmp->size.cx;
525 size->cy = bmp->size.cy;
Alexandre Julliard2a2321b2000-08-19 21:38:55 +0000526 GDI_ReleaseObj( hbitmap );
Alexandre Julliard401710d1993-09-04 10:09:32 +0000527 return TRUE;
528}
529
530
Alexandre Julliard46ea8b31998-05-03 19:01:20 +0000531/******************************************************************************
Patrik Stridvalld0a41772001-02-14 23:11:17 +0000532 * GetBitmapDimensionEx [GDI32.@] Retrieves dimensions of a bitmap
Alexandre Julliard46ea8b31998-05-03 19:01:20 +0000533 *
534 * RETURNS
535 * Success: TRUE
536 * Failure: FALSE
Alexandre Julliard401710d1993-09-04 10:09:32 +0000537 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000538BOOL WINAPI GetBitmapDimensionEx(
539 HBITMAP hbitmap, /* [in] Handle to bitmap */
540 LPSIZE size) /* [out] Address of struct receiving dimensions */
Alexandre Julliard401710d1993-09-04 10:09:32 +0000541{
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000542 BITMAPOBJ * bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC );
543 if (!bmp) return FALSE;
Huw D M Davies87f87bf1998-10-28 09:53:53 +0000544 *size = bmp->size;
Alexandre Julliard2a2321b2000-08-19 21:38:55 +0000545 GDI_ReleaseObj( hbitmap );
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000546 return TRUE;
Alexandre Julliard401710d1993-09-04 10:09:32 +0000547}
548
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000549
Alexandre Julliard401710d1993-09-04 10:09:32 +0000550/***********************************************************************
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000551 * GetBitmapDimension (GDI.162)
Alexandre Julliard401710d1993-09-04 10:09:32 +0000552 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000553DWORD WINAPI GetBitmapDimension16( HBITMAP16 hbitmap )
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000554{
555 SIZE16 size;
556 if (!GetBitmapDimensionEx16( hbitmap, &size )) return 0;
557 return MAKELONG( size.cx, size.cy );
558}
559
560
561/***********************************************************************
562 * SetBitmapDimensionEx16 (GDI.478)
563 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000564BOOL16 WINAPI SetBitmapDimensionEx16( HBITMAP16 hbitmap, INT16 x, INT16 y,
565 LPSIZE16 prevSize )
Alexandre Julliard401710d1993-09-04 10:09:32 +0000566{
567 BITMAPOBJ * bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC );
568 if (!bmp) return FALSE;
Alexandre Julliard982a2232000-12-13 20:20:09 +0000569 if (prevSize)
570 {
571 prevSize->cx = bmp->size.cx;
572 prevSize->cy = bmp->size.cy;
573 }
Alexandre Julliard401710d1993-09-04 10:09:32 +0000574 bmp->size.cx = x;
575 bmp->size.cy = y;
Alexandre Julliard2a2321b2000-08-19 21:38:55 +0000576 GDI_ReleaseObj( hbitmap );
Alexandre Julliard401710d1993-09-04 10:09:32 +0000577 return TRUE;
578}
579
580
Alexandre Julliard46ea8b31998-05-03 19:01:20 +0000581/******************************************************************************
Patrik Stridvalld0a41772001-02-14 23:11:17 +0000582 * SetBitmapDimensionEx [GDI32.@] Assignes dimensions to a bitmap
Alexandre Julliard46ea8b31998-05-03 19:01:20 +0000583 *
584 * RETURNS
585 * Success: TRUE
586 * Failure: FALSE
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000587 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000588BOOL WINAPI SetBitmapDimensionEx(
589 HBITMAP hbitmap, /* [in] Handle to bitmap */
590 INT x, /* [in] Bitmap width */
591 INT y, /* [in] Bitmap height */
592 LPSIZE prevSize) /* [out] Address of structure for orig dims */
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000593{
594 BITMAPOBJ * bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC );
595 if (!bmp) return FALSE;
Huw D M Davies87f87bf1998-10-28 09:53:53 +0000596 if (prevSize) *prevSize = bmp->size;
597 bmp->size.cx = x;
598 bmp->size.cy = y;
Alexandre Julliard2a2321b2000-08-19 21:38:55 +0000599 GDI_ReleaseObj( hbitmap );
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000600 return TRUE;
601}
602
603
604/***********************************************************************
Alexandre Julliard401710d1993-09-04 10:09:32 +0000605 * SetBitmapDimension (GDI.163)
606 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000607DWORD WINAPI SetBitmapDimension16( HBITMAP16 hbitmap, INT16 x, INT16 y )
Alexandre Julliard401710d1993-09-04 10:09:32 +0000608{
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000609 SIZE16 size;
610 if (!SetBitmapDimensionEx16( hbitmap, x, y, &size )) return 0;
611 return MAKELONG( size.cx, size.cy );
Alexandre Julliard401710d1993-09-04 10:09:32 +0000612}
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000613