bitmap.c 25.5 KB
Newer Older
Alexandre Julliard's avatar
Alexandre Julliard committed
1 2 3 4
/*
 * GDI bitmap objects
 *
 * Copyright 1993 Alexandre Julliard
5
 *           1998 Huw D M Davies
Alexandre Julliard's avatar
Alexandre Julliard committed
6
 */
Alexandre Julliard's avatar
Alexandre Julliard committed
7

Alexandre Julliard's avatar
Alexandre Julliard committed
8
#include <stdlib.h>
Alexandre Julliard's avatar
Alexandre Julliard committed
9
#include <string.h>
10 11

#include "wine/winbase16.h"
Alexandre Julliard's avatar
Alexandre Julliard committed
12
#include "gdi.h"
Alexandre Julliard's avatar
Alexandre Julliard committed
13
#include "dc.h"
Alexandre Julliard's avatar
Alexandre Julliard committed
14
#include "bitmap.h"
Alexandre Julliard's avatar
Alexandre Julliard committed
15
#include "heap.h"
16 17 18
#include "global.h"
#include "sysmetrics.h"
#include "cursoricon.h"
19
#include "debug.h"
20 21
#include "monitor.h"
#include "wine/winuser16.h"
Alexandre Julliard's avatar
Alexandre Julliard committed
22

Alexandre Julliard's avatar
Alexandre Julliard committed
23
/***********************************************************************
Huw D M Davies's avatar
Huw D M Davies committed
24
 *           BITMAP_GetPadding
Alexandre Julliard's avatar
Alexandre Julliard committed
25 26 27
 *
 * Return number of bytes to pad a scanline of 16-bit aligned Windows DDB data.
 */
28
INT BITMAP_GetPadding( int bmWidth, int bpp )
Alexandre Julliard's avatar
Alexandre Julliard committed
29
{
30
    INT pad;
Alexandre Julliard's avatar
Alexandre Julliard committed
31 32 33 34

    switch (bpp) 
    {
    case 1:
Huw D M Davies's avatar
Huw D M Davies committed
35
        pad = ((bmWidth-1) & 8) ? 0 : 1;
Alexandre Julliard's avatar
Alexandre Julliard committed
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
	break;

    case 8:
	pad = (2 - (bmWidth & 1)) & 1;
	break;

    case 24:
	pad = (bmWidth*3) & 1;
	break;

    case 32:
    case 16:
    case 15:
	pad = 0; /* we have 16bit alignment already */
	break;

    case 4:
	if (!(bmWidth & 3)) pad = 0;
	else pad = ((4 - (bmWidth & 3)) + 1) / 2;
	break;

    default:
Alexandre Julliard's avatar
Alexandre Julliard committed
58
	WARN(bitmap,"Unknown depth %d, please report.\n", bpp );
Alexandre Julliard's avatar
Alexandre Julliard committed
59 60 61 62 63 64
        return -1;
    }
    return pad;
}

/***********************************************************************
Huw D M Davies's avatar
Huw D M Davies committed
65
 *           BITMAP_GetWidthBytes
Alexandre Julliard's avatar
Alexandre Julliard committed
66
 *
Huw D M Davies's avatar
Huw D M Davies committed
67 68
 * Return number of bytes taken by a scanline of 16-bit aligned Windows DDB
 * data.
Alexandre Julliard's avatar
Alexandre Julliard committed
69
 */
70
INT BITMAP_GetWidthBytes( INT bmWidth, INT bpp )
Alexandre Julliard's avatar
Alexandre Julliard committed
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
{
    switch(bpp)
    {
    case 1:
	return 2 * ((bmWidth+15) >> 4);

    case 24:
	bmWidth *= 3; /* fall through */
    case 8:
	return bmWidth + (bmWidth & 1);

    case 32:
	return bmWidth * 4;

    case 16:
    case 15:
	return bmWidth * 2;

    case 4:
	return 2 * ((bmWidth+3) >> 2);

    default:
Alexandre Julliard's avatar
Alexandre Julliard committed
93
	WARN(bitmap,"Unknown depth %d, please report.\n", bpp );
Alexandre Julliard's avatar
Alexandre Julliard committed
94 95 96
    }
    return -1;
}
Alexandre Julliard's avatar
Alexandre Julliard committed
97

98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
/***********************************************************************
 *           CreateUserBitmap16    (GDI.407)
 */
HBITMAP16 WINAPI CreateUserBitmap16( INT16 width, INT16 height, UINT16 planes,
                                     UINT16 bpp, LPCVOID bits )
{
    return CreateBitmap16( width, height, planes, bpp, bits );
}

/***********************************************************************
 *           CreateUserDiscardableBitmap16    (GDI.409)
 */
HBITMAP16 WINAPI CreateUserDiscardableBitmap16( WORD dummy, 
                                                INT16 width, INT16 height )
{
113
    return CreateUserBitmap16( width, height, 1, MONITOR_GetDepth(&MONITOR_PrimaryMonitor), NULL );
114 115 116
}


Alexandre Julliard's avatar
Alexandre Julliard committed
117
/***********************************************************************
Alexandre Julliard's avatar
Alexandre Julliard committed
118
 *           CreateBitmap16    (GDI.48)
Alexandre Julliard's avatar
Alexandre Julliard committed
119
 */
Alexandre Julliard's avatar
Alexandre Julliard committed
120 121
HBITMAP16 WINAPI CreateBitmap16( INT16 width, INT16 height, UINT16 planes,
                                 UINT16 bpp, LPCVOID bits )
Alexandre Julliard's avatar
Alexandre Julliard committed
122
{
123
    return CreateBitmap( width, height, planes, bpp, bits );
Alexandre Julliard's avatar
Alexandre Julliard committed
124 125 126
}


Alexandre Julliard's avatar
Alexandre Julliard committed
127 128 129 130 131 132 133 134 135 136 137 138
/******************************************************************************
 * CreateBitmap32 [GDI32.25]  Creates a bitmap with the specified info
 *
 * PARAMS
 *    width  [I] bitmap width
 *    height [I] bitmap height
 *    planes [I] Number of color planes
 *    bpp    [I] Number of bits to identify a color
 *    bits   [I] Pointer to array containing color data
 *
 * RETURNS
 *    Success: Handle to bitmap
139
 *    Failure: 0
Alexandre Julliard's avatar
Alexandre Julliard committed
140
 */
141 142
HBITMAP WINAPI CreateBitmap( INT width, INT height, UINT planes,
                                 UINT bpp, LPCVOID bits )
Alexandre Julliard's avatar
Alexandre Julliard committed
143
{
144
    BITMAPOBJ *bmp;
145
    HBITMAP hbitmap;
Alexandre Julliard's avatar
Alexandre Julliard committed
146

Alexandre Julliard's avatar
Alexandre Julliard committed
147 148 149
    planes = (BYTE)planes;
    bpp    = (BYTE)bpp;

Alexandre Julliard's avatar
Alexandre Julliard committed
150

Alexandre Julliard's avatar
Alexandre Julliard committed
151
      /* Check parameters */
152 153 154 155 156
    if (!height || !width) return 0;
    if (planes != 1) {
        FIXME(bitmap, "planes = %d\n", planes);
	return 0;
    }
Alexandre Julliard's avatar
Alexandre Julliard committed
157 158
    if (height < 0) height = -height;
    if (width < 0) width = -width;
Alexandre Julliard's avatar
Alexandre Julliard committed
159

Alexandre Julliard's avatar
Alexandre Julliard committed
160
      /* Create the BITMAPOBJ */
Alexandre Julliard's avatar
Alexandre Julliard committed
161 162
    hbitmap = GDI_AllocObject( sizeof(BITMAPOBJ), BITMAP_MAGIC );
    if (!hbitmap) return 0;
163 164 165 166 167 168 169 170 171

    TRACE(bitmap, "%dx%d, %d colors returning %08x\n", width, height,
	  1 << (planes*bpp), hbitmap);

    bmp = (BITMAPOBJ *) GDI_HEAP_LOCK( hbitmap );

    bmp->size.cx = 0;
    bmp->size.cy = 0;
    bmp->bitmap.bmType = 0;
Huw D M Davies's avatar
Huw D M Davies committed
172 173 174 175 176
    bmp->bitmap.bmWidth = width;
    bmp->bitmap.bmHeight = height;
    bmp->bitmap.bmPlanes = planes;
    bmp->bitmap.bmBitsPixel = bpp;
    bmp->bitmap.bmWidthBytes = BITMAP_GetWidthBytes( width, bpp );
177 178 179 180 181 182
    bmp->bitmap.bmBits = NULL;

    bmp->DDBitmap = NULL;
    bmp->dib = NULL;

    if (bits) /* Set bitmap bits */
183
	SetBitmapBits( hbitmap, height * bmp->bitmap.bmWidthBytes,
Alexandre Julliard's avatar
Alexandre Julliard committed
184
                         bits );
Alexandre Julliard's avatar
Alexandre Julliard committed
185
    GDI_HEAP_UNLOCK( hbitmap );
Alexandre Julliard's avatar
Alexandre Julliard committed
186 187 188 189
    return hbitmap;
}


Alexandre Julliard's avatar
Alexandre Julliard committed
190
/***********************************************************************
Alexandre Julliard's avatar
Alexandre Julliard committed
191 192
 *           CreateCompatibleBitmap16    (GDI.51)
 */
Alexandre Julliard's avatar
Alexandre Julliard committed
193
HBITMAP16 WINAPI CreateCompatibleBitmap16(HDC16 hdc, INT16 width, INT16 height)
Alexandre Julliard's avatar
Alexandre Julliard committed
194
{
195
    return CreateCompatibleBitmap( hdc, width, height );
Alexandre Julliard's avatar
Alexandre Julliard committed
196 197 198
}


Alexandre Julliard's avatar
Alexandre Julliard committed
199 200 201 202 203 204 205 206 207 208
/******************************************************************************
 * CreateCompatibleBitmap32 [GDI32.30]  Creates a bitmap compatible with the DC
 *
 * PARAMS
 *    hdc    [I] Handle to device context
 *    width  [I] Width of bitmap
 *    height [I] Height of bitmap
 *
 * RETURNS
 *    Success: Handle to bitmap
209
 *    Failure: 0
Alexandre Julliard's avatar
Alexandre Julliard committed
210
 */
211
HBITMAP WINAPI CreateCompatibleBitmap( HDC hdc, INT width, INT height)
Alexandre Julliard's avatar
Alexandre Julliard committed
212
{
213
    HBITMAP hbmpRet = 0;
Alexandre Julliard's avatar
Alexandre Julliard committed
214 215
    DC *dc;

216
    TRACE(bitmap, "(%04x,%d,%d) = \n", hdc, width, height );
Alexandre Julliard's avatar
Alexandre Julliard committed
217
    if (!(dc = DC_GetDCPtr( hdc ))) return 0;
218
    if ((width >= 0x10000) || (height >= 0x10000)) {
219 220
	FIXME(bitmap,"got bad width %d or height %d, please look for reason\n",
	      width, height );
221
    } else {
222
        hbmpRet = CreateBitmap( width, height, 1, dc->w.bitsPerPixel, NULL );
223 224
	if(dc->funcs->pCreateBitmap)
	    dc->funcs->pCreateBitmap( hbmpRet );
225 226
    }
    TRACE(bitmap,"\t\t%04x\n", hbmpRet);
227
    GDI_HEAP_UNLOCK(hdc);
Alexandre Julliard's avatar
Alexandre Julliard committed
228
    return hbmpRet;
Alexandre Julliard's avatar
Alexandre Julliard committed
229 230 231 232
}


/***********************************************************************
Alexandre Julliard's avatar
Alexandre Julliard committed
233
 *           CreateBitmapIndirect16    (GDI.49)
Alexandre Julliard's avatar
Alexandre Julliard committed
234
 */
Alexandre Julliard's avatar
Alexandre Julliard committed
235
HBITMAP16 WINAPI CreateBitmapIndirect16( const BITMAP16 * bmp )
Alexandre Julliard's avatar
Alexandre Julliard committed
236
{
Alexandre Julliard's avatar
Alexandre Julliard committed
237 238
    return CreateBitmap16( bmp->bmWidth, bmp->bmHeight, bmp->bmPlanes,
                           bmp->bmBitsPixel, PTR_SEG_TO_LIN( bmp->bmBits ) );
Alexandre Julliard's avatar
Alexandre Julliard committed
239 240 241
}


Alexandre Julliard's avatar
Alexandre Julliard committed
242 243 244 245 246 247
/******************************************************************************
 * CreateBitmapIndirect32 [GDI32.26]  Creates a bitmap with the specifies info
 *
 * RETURNS
 *    Success: Handle to bitmap
 *    Failure: NULL
Alexandre Julliard's avatar
Alexandre Julliard committed
248
 */
249 250
HBITMAP WINAPI CreateBitmapIndirect(
    const BITMAP * bmp) /* [in] Pointer to the bitmap data */
Alexandre Julliard's avatar
Alexandre Julliard committed
251
{
252
    return CreateBitmap( bmp->bmWidth, bmp->bmHeight, bmp->bmPlanes,
Alexandre Julliard's avatar
Alexandre Julliard committed
253 254 255 256 257 258 259
                           bmp->bmBitsPixel, bmp->bmBits );
}


/***********************************************************************
 *           GetBitmapBits16    (GDI.74)
 */
Alexandre Julliard's avatar
Alexandre Julliard committed
260
LONG WINAPI GetBitmapBits16( HBITMAP16 hbitmap, LONG count, LPVOID buffer )
Alexandre Julliard's avatar
Alexandre Julliard committed
261
{
262
    return GetBitmapBits( hbitmap, count, buffer );
Alexandre Julliard's avatar
Alexandre Julliard committed
263 264 265 266
}


/***********************************************************************
Alexandre Julliard's avatar
Alexandre Julliard committed
267 268 269 270 271
 * GetBitmapBits32 [GDI32.143]  Copies bitmap bits of bitmap to buffer
 * 
 * RETURNS
 *    Success: Number of bytes copied
 *    Failure: 0
Alexandre Julliard's avatar
Alexandre Julliard committed
272
 */
273 274
LONG WINAPI GetBitmapBits(
    HBITMAP hbitmap, /* [in]  Handle to bitmap */
Alexandre Julliard's avatar
Alexandre Julliard committed
275
    LONG count,        /* [in]  Number of bytes to copy */
276
    LPVOID bits)       /* [out] Pointer to buffer to receive bits */
Alexandre Julliard's avatar
Alexandre Julliard committed
277
{
278 279
    BITMAPOBJ *bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC );
    LONG height, ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
280
    
281 282
    if (!bmp) return 0;

Alexandre Julliard's avatar
Alexandre Julliard committed
283
    if (count < 0) {
Alexandre Julliard's avatar
Alexandre Julliard committed
284
	WARN(bitmap, "(%ld): Negative number of bytes passed???\n", count );
Alexandre Julliard's avatar
Alexandre Julliard committed
285 286
	count = -count;
    }
Alexandre Julliard's avatar
Alexandre Julliard committed
287

288
    /* Only get entire lines */
Alexandre Julliard's avatar
Alexandre Julliard committed
289 290
    height = count / bmp->bitmap.bmWidthBytes;
    if (height > bmp->bitmap.bmHeight) height = bmp->bitmap.bmHeight;
291
    count = height * bmp->bitmap.bmWidthBytes;
292 293 294 295 296 297 298
    if (count == 0)
      {
	WARN(bitmap, "Less then one entire line requested\n");
	GDI_HEAP_UNLOCK( hbitmap );
	return 0;
      }

Alexandre Julliard's avatar
Alexandre Julliard committed
299

300 301 302
    TRACE(bitmap, "(%08x, %ld, %p) %dx%d %d colors fetched height: %ld\n",
	    hbitmap, count, bits, bmp->bitmap.bmWidth, bmp->bitmap.bmHeight,
	    1 << bmp->bitmap.bmBitsPixel, height );
Alexandre Julliard's avatar
Alexandre Julliard committed
303

304
    if(bmp->DDBitmap) { 
Alexandre Julliard's avatar
Alexandre Julliard committed
305

306 307 308 309 310 311 312 313
        TRACE(bitmap, "Calling device specific BitmapBits\n");
	if(bmp->DDBitmap->funcs->pBitmapBits)
	    ret = bmp->DDBitmap->funcs->pBitmapBits(hbitmap, bits, count,
						    DDB_GET);
	else {
	    ERR(bitmap, "BitmapBits == NULL??\n");
	    ret = 0;
	}	
Alexandre Julliard's avatar
Alexandre Julliard committed
314

315
    } else {
Alexandre Julliard's avatar
Alexandre Julliard committed
316

317 318 319 320 321 322
        if(!bmp->bitmap.bmBits) {
	    WARN(bitmap, "Bitmap is empty\n");
	    ret = 0;
	} else {
	    memcpy(bits, bmp->bitmap.bmBits, count);
	    ret = count;
Alexandre Julliard's avatar
Alexandre Julliard committed
323
	}
Alexandre Julliard's avatar
Alexandre Julliard committed
324

Alexandre Julliard's avatar
Alexandre Julliard committed
325
    }
Alexandre Julliard's avatar
Alexandre Julliard committed
326

Alexandre Julliard's avatar
Alexandre Julliard committed
327
    GDI_HEAP_UNLOCK( hbitmap );
328
    return ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
329 330 331 332
}


/***********************************************************************
Alexandre Julliard's avatar
Alexandre Julliard committed
333 334
 *           SetBitmapBits16    (GDI.106)
 */
Alexandre Julliard's avatar
Alexandre Julliard committed
335
LONG WINAPI SetBitmapBits16( HBITMAP16 hbitmap, LONG count, LPCVOID buffer )
Alexandre Julliard's avatar
Alexandre Julliard committed
336
{
337
    return SetBitmapBits( hbitmap, count, buffer );
Alexandre Julliard's avatar
Alexandre Julliard committed
338 339 340
}


Alexandre Julliard's avatar
Alexandre Julliard committed
341 342 343 344 345 346
/******************************************************************************
 * SetBitmapBits32 [GDI32.303]  Sets bits of color data for a bitmap
 *
 * RETURNS
 *    Success: Number of bytes used in setting the bitmap bits
 *    Failure: 0
Alexandre Julliard's avatar
Alexandre Julliard committed
347
 */
348 349
LONG WINAPI SetBitmapBits(
    HBITMAP hbitmap, /* [in] Handle to bitmap */
Alexandre Julliard's avatar
Alexandre Julliard committed
350
    LONG count,        /* [in] Number of bytes in bitmap array */
351
    LPCVOID bits)      /* [in] Address of array with bitmap bits */
Alexandre Julliard's avatar
Alexandre Julliard committed
352
{
353 354
    BITMAPOBJ *bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC );
    LONG height, ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
355
    
356 357
    if (!bmp) return 0;

Alexandre Julliard's avatar
Alexandre Julliard committed
358
    if (count < 0) {
Alexandre Julliard's avatar
Alexandre Julliard committed
359
	WARN(bitmap, "(%ld): Negative number of bytes passed???\n", count );
Alexandre Julliard's avatar
Alexandre Julliard committed
360 361
	count = -count;
    }
Alexandre Julliard's avatar
Alexandre Julliard committed
362

363
    /* Only get entire lines */
Alexandre Julliard's avatar
Alexandre Julliard committed
364 365
    height = count / bmp->bitmap.bmWidthBytes;
    if (height > bmp->bitmap.bmHeight) height = bmp->bitmap.bmHeight;
366
    count = height * bmp->bitmap.bmWidthBytes;
Alexandre Julliard's avatar
Alexandre Julliard committed
367

368 369 370
    TRACE(bitmap, "(%08x, %ld, %p) %dx%d %d colors fetched height: %ld\n",
	    hbitmap, count, bits, bmp->bitmap.bmWidth, bmp->bitmap.bmHeight,
	    1 << bmp->bitmap.bmBitsPixel, height );
Alexandre Julliard's avatar
Alexandre Julliard committed
371

372
    if(bmp->DDBitmap) {
Alexandre Julliard's avatar
Alexandre Julliard committed
373

374 375 376 377 378 379 380 381 382 383
        TRACE(bitmap, "Calling device specific BitmapBits\n");
	if(bmp->DDBitmap->funcs->pBitmapBits)
	    ret = bmp->DDBitmap->funcs->pBitmapBits(hbitmap, (void *) bits,
						    count, DDB_SET);
	else {
	    ERR(bitmap, "BitmapBits == NULL??\n");
	    ret = 0;
	}
	
    } else {
Alexandre Julliard's avatar
Alexandre Julliard committed
384

385 386 387 388 389 390 391 392 393
        if(!bmp->bitmap.bmBits) /* Alloc enough for entire bitmap */
	    bmp->bitmap.bmBits = HeapAlloc( GetProcessHeap(), 0, count );
	if(!bmp->bitmap.bmBits) {
	    WARN(bitmap, "Unable to allocate bit buffer\n");
	    ret = 0;
	} else {
	    memcpy(bmp->bitmap.bmBits, bits, count);
	    ret = count;
	}
Alexandre Julliard's avatar
Alexandre Julliard committed
394 395
    }

Alexandre Julliard's avatar
Alexandre Julliard committed
396
    GDI_HEAP_UNLOCK( hbitmap );
397
    return ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
398 399
}

Alexandre Julliard's avatar
Alexandre Julliard committed
400 401 402 403
/***********************************************************************
 * LoadImage16 [USER.389]
 *
 */
Alexandre Julliard's avatar
Alexandre Julliard committed
404 405 406 407
HANDLE16 WINAPI LoadImage16( HINSTANCE16 hinst, LPCSTR name, UINT16 type,
                             INT16 desiredx, INT16 desiredy, UINT16 loadflags)
{
	if (HIWORD(name)) {
Alexandre Julliard's avatar
Alexandre Julliard committed
408 409
	    TRACE(resource,"(0x%04x,%s,%d,%d,%d,0x%08x)\n",
                hinst,(char *)PTR_SEG_TO_LIN(name),type,desiredx,desiredy,loadflags);
Alexandre Julliard's avatar
Alexandre Julliard committed
410
	} else {
Alexandre Julliard's avatar
Alexandre Julliard committed
411 412
	    TRACE(resource,"LoadImage16(0x%04x,%p,%d,%d,%d,0x%08x)\n",
                hinst,name,type,desiredx,desiredy,loadflags);
Alexandre Julliard's avatar
Alexandre Julliard committed
413 414 415
	}
	switch (type) {
	case IMAGE_BITMAP:
Alexandre Julliard's avatar
Alexandre Julliard committed
416
		return LoadBitmap16(hinst,(SEGPTR)name);
Alexandre Julliard's avatar
Alexandre Julliard committed
417
	case IMAGE_ICON:
Alexandre Julliard's avatar
Alexandre Julliard committed
418
		return LoadIcon16(hinst,(SEGPTR)name);
Alexandre Julliard's avatar
Alexandre Julliard committed
419
	case IMAGE_CURSOR:
Alexandre Julliard's avatar
Alexandre Julliard committed
420
		return LoadCursor16(hinst,(SEGPTR)name);
Alexandre Julliard's avatar
Alexandre Julliard committed
421 422 423 424
	}
	return 0;
	
}
Alexandre Julliard's avatar
Alexandre Julliard committed
425

Alexandre Julliard's avatar
Alexandre Julliard committed
426
/**********************************************************************
Alexandre Julliard's avatar
Alexandre Julliard committed
427
 *	    LoadImage32A    (USER32.365)
Alexandre Julliard's avatar
Alexandre Julliard committed
428
 * 
429
 * FIXME: implementation lacks some features, see LR_ defines in windows.h
Alexandre Julliard's avatar
Alexandre Julliard committed
430 431
 */

432 433
HANDLE WINAPI LoadImageA( HINSTANCE hinst, LPCSTR name, UINT type,
                              INT desiredx, INT desiredy, UINT loadflags)
Alexandre Julliard's avatar
Alexandre Julliard committed
434
{
435
    HANDLE res;
436
    LPWSTR u_name;
Alexandre Julliard's avatar
Alexandre Julliard committed
437

438 439
    if (HIWORD(name)) u_name = HEAP_strdupAtoW(GetProcessHeap(), 0, name);
    else u_name=(LPWSTR)name;
440
    res = LoadImageW(hinst, u_name, type, desiredx, desiredy, loadflags);
441 442 443
    if (HIWORD(name)) HeapFree(GetProcessHeap(), 0, u_name);
    return res;
}
Alexandre Julliard's avatar
Alexandre Julliard committed
444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460


/******************************************************************************
 * LoadImage32W [USER32.366]  Loads an icon, cursor, or bitmap
 *
 * PARAMS
 *    hinst     [I] Handle of instance that contains image
 *    name      [I] Name of image
 *    type      [I] Type of image
 *    desiredx  [I] Desired width
 *    desiredy  [I] Desired height
 *    loadflags [I] Load flags
 *
 * RETURNS
 *    Success: Handle to newly loaded image
 *    Failure: NULL
 *
461
 * FIXME: Implementation lacks some features, see LR_ defines in windows.h
Alexandre Julliard's avatar
Alexandre Julliard committed
462
 */
463 464
HANDLE WINAPI LoadImageW( HINSTANCE hinst, LPCWSTR name, UINT type,
                INT desiredx, INT desiredy, UINT loadflags )
Alexandre Julliard's avatar
Alexandre Julliard committed
465
{
466 467 468 469 470 471 472 473 474 475 476 477 478 479
    if (HIWORD(name)) {
        TRACE(resource,"(0x%04x,%p,%d,%d,%d,0x%08x)\n",
	      hinst,name,type,desiredx,desiredy,loadflags);
    } else {
        TRACE(resource,"(0x%04x,%p,%d,%d,%d,0x%08x)\n",
	      hinst,name,type,desiredx,desiredy,loadflags);
    }
    if (loadflags & LR_DEFAULTSIZE) {
        if (type == IMAGE_ICON) {
	    if (!desiredx) desiredx = SYSMETRICS_CXICON;
	    if (!desiredy) desiredy = SYSMETRICS_CYICON;
	} else if (type == IMAGE_CURSOR) {
            if (!desiredx) desiredx = SYSMETRICS_CXCURSOR;
	    if (!desiredy) desiredy = SYSMETRICS_CYCURSOR;
Alexandre Julliard's avatar
Alexandre Julliard committed
480
	}
481
    }
482
    if (loadflags & LR_LOADFROMFILE) loadflags &= ~LR_SHARED;
Alexandre Julliard's avatar
Alexandre Julliard committed
483
    switch (type) {
484
    case IMAGE_BITMAP:
485
        return BITMAP_LoadBitmapW(hinst, name, loadflags);
486 487 488

    case IMAGE_ICON:
        {
489 490 491
	HDC hdc = GetDC(0);
	UINT palEnts = GetSystemPaletteEntries(hdc, 0, 0, NULL);
	ReleaseDC(0, hdc);
492

493
	return CURSORICON_Load(hinst, name, desiredx, desiredy,
494 495 496 497
				 MIN(16, palEnts), FALSE, loadflags);
	}

    case IMAGE_CURSOR:
498
        return CURSORICON_Load(hinst, name, desiredx, desiredy,
499
				 1, TRUE, loadflags);
Alexandre Julliard's avatar
Alexandre Julliard committed
500
    }
501
    return 0;
Alexandre Julliard's avatar
Alexandre Julliard committed
502 503
}

Alexandre Julliard's avatar
Alexandre Julliard committed
504

Alexandre Julliard's avatar
Alexandre Julliard committed
505
/**********************************************************************
506
 *		BITMAP_CopyBitmap
Alexandre Julliard's avatar
Alexandre Julliard committed
507
 *
Alexandre Julliard's avatar
Alexandre Julliard committed
508
 */
509
HBITMAP BITMAP_CopyBitmap(HBITMAP hbitmap)
Alexandre Julliard's avatar
Alexandre Julliard committed
510
{
511
    BITMAPOBJ *bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC );
512 513
    HBITMAP res = 0;
    BITMAP bm;
Alexandre Julliard's avatar
Alexandre Julliard committed
514

515 516 517 518
    if(!bmp) return 0;

    bm = bmp->bitmap;
    bm.bmBits = NULL;
519
    res = CreateBitmapIndirect(&bm);
520 521 522 523

    if(res) {
        char *buf = HeapAlloc( GetProcessHeap(), 0, bm.bmWidthBytes *
			       bm.bmHeight );
524 525
        GetBitmapBits (hbitmap, bm.bmWidthBytes * bm.bmHeight, buf);
	SetBitmapBits (res, bm.bmWidthBytes * bm.bmHeight, buf);
526
	HeapFree( GetProcessHeap(), 0, buf );
Alexandre Julliard's avatar
Alexandre Julliard committed
527
    }
528 529

    GDI_HEAP_UNLOCK( hbitmap );
Alexandre Julliard's avatar
Alexandre Julliard committed
530 531 532
    return res;
}

533 534 535 536 537 538 539
/******************************************************************************
 * CopyImage16 [USER.390]  Creates new image and copies attributes to it
 *
 */
HICON16 WINAPI CopyImage16( HANDLE16 hnd, UINT16 type, INT16 desiredx,
                             INT16 desiredy, UINT16 flags )
{
540 541
    return (HICON16)CopyImage((HANDLE)hnd, (UINT)type, (INT)desiredx,
                                (INT)desiredy, (UINT)flags);
542
}
Alexandre Julliard's avatar
Alexandre Julliard committed
543 544 545 546 547 548 549 550 551 552 553 554 555 556

/******************************************************************************
 * CopyImage32 [USER32.61]  Creates new image and copies attributes to it
 *
 * PARAMS
 *    hnd      [I] Handle to image to copy
 *    type     [I] Type of image to copy
 *    desiredx [I] Desired width of new image
 *    desiredy [I] Desired height of new image
 *    flags    [I] Copy flags
 *
 * RETURNS
 *    Success: Handle to newly created image
 *    Failure: NULL
Alexandre Julliard's avatar
Alexandre Julliard committed
557 558 559 560
 *
 * FIXME: implementation still lacks nearly all features, see LR_*
 * defines in windows.h
 */
561 562
HICON WINAPI CopyImage( HANDLE hnd, UINT type, INT desiredx,
                             INT desiredy, UINT flags )
Alexandre Julliard's avatar
Alexandre Julliard committed
563 564 565 566
{
    switch (type)
    {
	case IMAGE_BITMAP:
567
		return BITMAP_CopyBitmap(hnd);
Alexandre Julliard's avatar
Alexandre Julliard committed
568
	case IMAGE_ICON:
569
		return CopyIcon(hnd);
Alexandre Julliard's avatar
Alexandre Julliard committed
570
	case IMAGE_CURSOR:
571
		return CopyCursor(hnd);
Alexandre Julliard's avatar
Alexandre Julliard committed
572 573 574 575
    }
    return 0;
}

Alexandre Julliard's avatar
Alexandre Julliard committed
576
/**********************************************************************
Alexandre Julliard's avatar
Alexandre Julliard committed
577
 *	    LoadBitmap16    (USER.175)
Alexandre Julliard's avatar
Alexandre Julliard committed
578 579 580
 *
 * NOTES
 *    Can this call LoadBitmap32?
Alexandre Julliard's avatar
Alexandre Julliard committed
581
 */
Alexandre Julliard's avatar
Alexandre Julliard committed
582
HBITMAP16 WINAPI LoadBitmap16( HINSTANCE16 instance, SEGPTR name )
Alexandre Julliard's avatar
Alexandre Julliard committed
583
{
584 585
    HBITMAP hbitmap = 0;
    HDC hdc;
Alexandre Julliard's avatar
Alexandre Julliard committed
586 587
    HRSRC16 hRsrc;
    HGLOBAL16 handle;
Alexandre Julliard's avatar
Alexandre Julliard committed
588
    BITMAPINFO *info;
Alexandre Julliard's avatar
Alexandre Julliard committed
589 590 591 592

    if (HIWORD(name))
    {
        char *str = (char *)PTR_SEG_TO_LIN( name );
Alexandre Julliard's avatar
Alexandre Julliard committed
593
        TRACE(bitmap, "(%04x,'%s')\n", instance, str );
Alexandre Julliard's avatar
Alexandre Julliard committed
594
        if (str[0] == '#') name = (SEGPTR)(DWORD)(WORD)atoi( str + 1 );
Alexandre Julliard's avatar
Alexandre Julliard committed
595 596
    }
    else
Alexandre Julliard's avatar
Alexandre Julliard committed
597
        TRACE(bitmap, "(%04x,%04x)\n",
Alexandre Julliard's avatar
Alexandre Julliard committed
598
                        instance, LOWORD(name) );
Alexandre Julliard's avatar
Alexandre Julliard committed
599 600 601

    if (!instance)  /* OEM bitmap */
    {
602
        HDC hdc;
603 604
	DC *dc;

Alexandre Julliard's avatar
Alexandre Julliard committed
605
        if (HIWORD((int)name)) return 0;
606
	hdc = CreateDCA( "DISPLAY", NULL, NULL, NULL );
607 608 609 610 611
	dc = DC_GetDCPtr( hdc );
	if(dc->funcs->pLoadOEMResource)
	  hbitmap = dc->funcs->pLoadOEMResource( LOWORD((int)name),
						 OEM_BITMAP );
	GDI_HEAP_UNLOCK( hdc );
612
	DeleteDC( hdc );
613
	return hbitmap;
Alexandre Julliard's avatar
Alexandre Julliard committed
614 615
    }

Alexandre Julliard's avatar
Alexandre Julliard committed
616
    if (!(hRsrc = FindResource16( instance, name, RT_BITMAP16 ))) return 0;
Alexandre Julliard's avatar
Alexandre Julliard committed
617
    if (!(handle = LoadResource16( instance, hRsrc ))) return 0;
Alexandre Julliard's avatar
Alexandre Julliard committed
618

Alexandre Julliard's avatar
Alexandre Julliard committed
619
    info = (BITMAPINFO *)LockResource16( handle );
620
    if ((hdc = GetDC(0)) != 0)
Alexandre Julliard's avatar
Alexandre Julliard committed
621
    {
Alexandre Julliard's avatar
Alexandre Julliard committed
622
        char *bits = (char *)info + DIB_BitmapInfoSize( info, DIB_RGB_COLORS );
623
        hbitmap = CreateDIBitmap( hdc, &info->bmiHeader, CBM_INIT,
Alexandre Julliard's avatar
Alexandre Julliard committed
624
                                    bits, info, DIB_RGB_COLORS );
625
        ReleaseDC( 0, hdc );
Alexandre Julliard's avatar
Alexandre Julliard committed
626
    }
Alexandre Julliard's avatar
Alexandre Julliard committed
627
    FreeResource16( handle );
Alexandre Julliard's avatar
Alexandre Julliard committed
628 629 630
    return hbitmap;
}

Alexandre Julliard's avatar
Alexandre Julliard committed
631

Huw D M Davies's avatar
Huw D M Davies committed
632 633 634
/**********************************************************************
 *       BITMAP_LoadBitmap32W
 */
635 636
HBITMAP BITMAP_LoadBitmapW(HINSTANCE instance,LPCWSTR name, 
			       UINT loadflags)
Alexandre Julliard's avatar
Alexandre Julliard committed
637
{
638 639 640 641
    HBITMAP hbitmap = 0;
    HDC hdc;
    HRSRC hRsrc;
    HGLOBAL handle;
642 643
    char *ptr = NULL;
    BITMAPINFO *info, *fix_info=NULL;
644
    HGLOBAL hFix;
645
    int size;
Alexandre Julliard's avatar
Alexandre Julliard committed
646

647 648 649
    if (!(loadflags & LR_LOADFROMFILE)) {
      if (!instance)  /* OEM bitmap */
      {
650
          HDC hdc;
651 652 653
	  DC *dc;

	  if (HIWORD((int)name)) return 0;
654
	  hdc = CreateDCA( "DISPLAY", NULL, NULL, NULL );
655 656 657 658 659
	  dc = DC_GetDCPtr( hdc );
	  if(dc->funcs->pLoadOEMResource)
	      hbitmap = dc->funcs->pLoadOEMResource( LOWORD((int)name), 
						     OEM_BITMAP );
	  GDI_HEAP_UNLOCK( hdc );
660
	  DeleteDC( hdc );
661
	  return hbitmap;
662
      }
Alexandre Julliard's avatar
Alexandre Julliard committed
663

664 665
      if (!(hRsrc = FindResourceW( instance, name, RT_BITMAPW ))) return 0;
      if (!(handle = LoadResource( instance, hRsrc ))) return 0;
Alexandre Julliard's avatar
Alexandre Julliard committed
666

667
      if ((info = (BITMAPINFO *)LockResource( handle )) == NULL) return 0;
668 669
    }
    else
Alexandre Julliard's avatar
Alexandre Julliard committed
670
    {
671 672 673 674
        if (!(ptr = (char *)VIRTUAL_MapFileW( name ))) return 0;
        info = (BITMAPINFO *)(ptr + sizeof(BITMAPFILEHEADER));
    }
    size = DIB_BitmapInfoSize(info, DIB_RGB_COLORS);
675
    if ((hFix = GlobalAlloc(0, size))) fix_info=GlobalLock(hFix);
676 677 678 679 680 681
    if (fix_info) {
      BYTE pix;

      memcpy(fix_info, info, size);
      pix = *((LPBYTE)info+DIB_BitmapInfoSize(info, DIB_RGB_COLORS));
      DIB_FixColorsToLoadflags(fix_info, loadflags, pix);
682
      if ((hdc = GetDC(0)) != 0) {
683
	if (loadflags & LR_CREATEDIBSECTION)
684
	  hbitmap = CreateDIBSection(hdc, fix_info, DIB_RGB_COLORS, NULL, 0, 0);
685 686
        else {
          char *bits = (char *)info + size;;
687
          hbitmap = CreateDIBitmap( hdc, &fix_info->bmiHeader, CBM_INIT,
688 689
                                      bits, fix_info, DIB_RGB_COLORS );
	}
690
        ReleaseDC( 0, hdc );
691
      }
692 693
      GlobalUnlock(hFix);
      GlobalFree(hFix);
Alexandre Julliard's avatar
Alexandre Julliard committed
694
    }
695
    if (loadflags & LR_LOADFROMFILE) UnmapViewOfFile( ptr );
Alexandre Julliard's avatar
Alexandre Julliard committed
696 697
    return hbitmap;
}
Huw D M Davies's avatar
Huw D M Davies committed
698 699


700 701 702 703 704 705 706
/******************************************************************************
 * LoadBitmap32W [USER32.358]  Loads bitmap from the executable file
 *
 * RETURNS
 *    Success: Handle to specified bitmap
 *    Failure: NULL
 */
707 708
HBITMAP WINAPI LoadBitmapW(
    HINSTANCE instance, /* [in] Handle to application instance */
709 710
    LPCWSTR name)         /* [in] Address of bitmap resource name */
{
711
    return BITMAP_LoadBitmapW(instance, name, 0);
712
}
Alexandre Julliard's avatar
Alexandre Julliard committed
713 714 715


/**********************************************************************
Alexandre Julliard's avatar
Alexandre Julliard committed
716
 *	    LoadBitmap32A   (USER32.357)
Alexandre Julliard's avatar
Alexandre Julliard committed
717
 */
718
HBITMAP WINAPI LoadBitmapA( HINSTANCE instance, LPCSTR name )
Alexandre Julliard's avatar
Alexandre Julliard committed
719
{
720 721
    HBITMAP res;
    if (!HIWORD(name)) res = LoadBitmapW( instance, (LPWSTR)name );
Alexandre Julliard's avatar
Alexandre Julliard committed
722 723
    else
    {
Alexandre Julliard's avatar
Alexandre Julliard committed
724
        LPWSTR uni = HEAP_strdupAtoW( GetProcessHeap(), 0, name );
725
        res = LoadBitmapW( instance, uni );
Alexandre Julliard's avatar
Alexandre Julliard committed
726
        HeapFree( GetProcessHeap(), 0, uni );
Alexandre Julliard's avatar
Alexandre Julliard committed
727 728 729 730
    }
    return res;
}

Alexandre Julliard's avatar
Alexandre Julliard committed
731

Alexandre Julliard's avatar
Alexandre Julliard committed
732
/***********************************************************************
Alexandre Julliard's avatar
Alexandre Julliard committed
733
 *           BITMAP_DeleteObject
Alexandre Julliard's avatar
Alexandre Julliard committed
734
 */
735
BOOL BITMAP_DeleteObject( HBITMAP16 hbitmap, BITMAPOBJ * bmp )
Alexandre Julliard's avatar
Alexandre Julliard committed
736
{
737 738 739 740
    if( bmp->DDBitmap ) {
        if( bmp->DDBitmap->funcs->pDeleteObject )
	    bmp->DDBitmap->funcs->pDeleteObject( hbitmap );
    }
Alexandre Julliard's avatar
Alexandre Julliard committed
741 742

    if( bmp->bitmap.bmBits )
743
        HeapFree( GetProcessHeap(), 0, bmp->bitmap.bmBits );
Alexandre Julliard's avatar
Alexandre Julliard committed
744

Alexandre Julliard's avatar
Alexandre Julliard committed
745
    DIB_DeleteDIBSection( bmp );
Alexandre Julliard's avatar
Alexandre Julliard committed
746

Alexandre Julliard's avatar
Alexandre Julliard committed
747 748 749 750 751
    return GDI_FreeObject( hbitmap );
}

	
/***********************************************************************
Alexandre Julliard's avatar
Alexandre Julliard committed
752
 *           BITMAP_GetObject16
Alexandre Julliard's avatar
Alexandre Julliard committed
753
 */
Alexandre Julliard's avatar
Alexandre Julliard committed
754
INT16 BITMAP_GetObject16( BITMAPOBJ * bmp, INT16 count, LPVOID buffer )
Alexandre Julliard's avatar
Alexandre Julliard committed
755
{
Alexandre Julliard's avatar
Alexandre Julliard committed
756
    if (bmp->dib)
Alexandre Julliard's avatar
Alexandre Julliard committed
757
    {
Alexandre Julliard's avatar
Alexandre Julliard committed
758 759
        if ( count <= sizeof(BITMAP16) )
        {
760
            BITMAP *bmp32 = &bmp->dib->dibSection.dsBm;
Alexandre Julliard's avatar
Alexandre Julliard committed
761 762 763 764 765 766 767
	    BITMAP16 bmp16;
	    bmp16.bmType       = bmp32->bmType;
	    bmp16.bmWidth      = bmp32->bmWidth;
	    bmp16.bmHeight     = bmp32->bmHeight;
	    bmp16.bmWidthBytes = bmp32->bmWidthBytes;
	    bmp16.bmPlanes     = bmp32->bmPlanes;
	    bmp16.bmBitsPixel  = bmp32->bmBitsPixel;
768
	    bmp16.bmBits       = (SEGPTR)0;
Alexandre Julliard's avatar
Alexandre Julliard committed
769 770 771 772 773 774 775 776
	    memcpy( buffer, &bmp16, count );
	    return count;
        }
        else
        {
	    FIXME(bitmap, "not implemented for DIBs: count %d\n", count);
	    return 0;
        }
Alexandre Julliard's avatar
Alexandre Julliard committed
777 778 779
    }
    else
    {
780 781 782 783 784 785 786 787 788 789
	BITMAP16 bmp16;
	bmp16.bmType       = bmp->bitmap.bmType;
	bmp16.bmWidth      = bmp->bitmap.bmWidth;
	bmp16.bmHeight     = bmp->bitmap.bmHeight;
	bmp16.bmWidthBytes = bmp->bitmap.bmWidthBytes;
	bmp16.bmPlanes     = bmp->bitmap.bmPlanes;
	bmp16.bmBitsPixel  = bmp->bitmap.bmBitsPixel;
	bmp16.bmBits       = (SEGPTR)0;
	if (count > sizeof(bmp16)) count = sizeof(bmp16);
	memcpy( buffer, &bmp16, count );
Alexandre Julliard's avatar
Alexandre Julliard committed
790 791
	return count;
    }
Alexandre Julliard's avatar
Alexandre Julliard committed
792 793 794
}
    

Alexandre Julliard's avatar
Alexandre Julliard committed
795 796 797
/***********************************************************************
 *           BITMAP_GetObject32
 */
798
INT BITMAP_GetObject( BITMAPOBJ * bmp, INT count, LPVOID buffer )
Alexandre Julliard's avatar
Alexandre Julliard committed
799
{
Alexandre Julliard's avatar
Alexandre Julliard committed
800
    if (bmp->dib)
Alexandre Julliard's avatar
Alexandre Julliard committed
801 802 803
    {
	if (count < sizeof(DIBSECTION))
	{
804
	    if (count > sizeof(BITMAP)) count = sizeof(BITMAP);
Alexandre Julliard's avatar
Alexandre Julliard committed
805 806 807 808 809 810
	}
	else
	{
	    if (count > sizeof(DIBSECTION)) count = sizeof(DIBSECTION);
	}

Alexandre Julliard's avatar
Alexandre Julliard committed
811
	memcpy( buffer, &bmp->dib->dibSection, count );
Alexandre Julliard's avatar
Alexandre Julliard committed
812 813 814 815
	return count;
    }
    else
    {
816
	if (count > sizeof(BITMAP)) count = sizeof(BITMAP);
817
	memcpy( buffer, &bmp->bitmap, count );
Alexandre Julliard's avatar
Alexandre Julliard committed
818 819
	return count;
    }
Alexandre Julliard's avatar
Alexandre Julliard committed
820 821 822
}
    

Alexandre Julliard's avatar
Alexandre Julliard committed
823
/***********************************************************************
Alexandre Julliard's avatar
Alexandre Julliard committed
824 825
 *           CreateDiscardableBitmap16    (GDI.156)
 */
Alexandre Julliard's avatar
Alexandre Julliard committed
826 827
HBITMAP16 WINAPI CreateDiscardableBitmap16( HDC16 hdc, INT16 width,
                                            INT16 height )
Alexandre Julliard's avatar
Alexandre Julliard committed
828 829 830 831 832
{
    return CreateCompatibleBitmap16( hdc, width, height );
}


Alexandre Julliard's avatar
Alexandre Julliard committed
833 834 835 836 837 838
/******************************************************************************
 * CreateDiscardableBitmap32 [GDI32.38]  Creates a discardable bitmap
 *
 * RETURNS
 *    Success: Handle to bitmap
 *    Failure: NULL
Alexandre Julliard's avatar
Alexandre Julliard committed
839
 */
840 841 842 843
HBITMAP WINAPI CreateDiscardableBitmap(
    HDC hdc,    /* [in] Handle to device context */
    INT width,  /* [in] Bitmap width */
    INT height) /* [in] Bitmap height */
Alexandre Julliard's avatar
Alexandre Julliard committed
844
{
845
    return CreateCompatibleBitmap( hdc, width, height );
Alexandre Julliard's avatar
Alexandre Julliard committed
846
}
Alexandre Julliard's avatar
Alexandre Julliard committed
847

Alexandre Julliard's avatar
Alexandre Julliard committed
848

Alexandre Julliard's avatar
Alexandre Julliard committed
849
/***********************************************************************
Alexandre Julliard's avatar
Alexandre Julliard committed
850
 *           GetBitmapDimensionEx16    (GDI.468)
Alexandre Julliard's avatar
Alexandre Julliard committed
851 852 853
 *
 * NOTES
 *    Can this call GetBitmapDimensionEx32?
Alexandre Julliard's avatar
Alexandre Julliard committed
854
 */
Alexandre Julliard's avatar
Alexandre Julliard committed
855
BOOL16 WINAPI GetBitmapDimensionEx16( HBITMAP16 hbitmap, LPSIZE16 size )
Alexandre Julliard's avatar
Alexandre Julliard committed
856 857 858
{
    BITMAPOBJ * bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC );
    if (!bmp) return FALSE;
859
    CONV_SIZE32TO16( &bmp->size, size );
Alexandre Julliard's avatar
Alexandre Julliard committed
860
    GDI_HEAP_UNLOCK( hbitmap );
Alexandre Julliard's avatar
Alexandre Julliard committed
861 862 863 864
    return TRUE;
}


Alexandre Julliard's avatar
Alexandre Julliard committed
865 866 867 868 869 870
/******************************************************************************
 * GetBitmapDimensionEx32 [GDI32.144]  Retrieves dimensions of a bitmap
 *
 * RETURNS
 *    Success: TRUE
 *    Failure: FALSE
Alexandre Julliard's avatar
Alexandre Julliard committed
871
 */
872 873 874
BOOL WINAPI GetBitmapDimensionEx(
    HBITMAP hbitmap, /* [in]  Handle to bitmap */
    LPSIZE size)     /* [out] Address of struct receiving dimensions */
Alexandre Julliard's avatar
Alexandre Julliard committed
875 876 877
{
    BITMAPOBJ * bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC );
    if (!bmp) return FALSE;
878
    *size = bmp->size;
Alexandre Julliard's avatar
Alexandre Julliard committed
879
    GDI_HEAP_UNLOCK( hbitmap );
Alexandre Julliard's avatar
Alexandre Julliard committed
880 881 882 883
    return TRUE;
}


Alexandre Julliard's avatar
Alexandre Julliard committed
884 885 886
/***********************************************************************
 *           GetBitmapDimension    (GDI.162)
 */
887
DWORD WINAPI GetBitmapDimension16( HBITMAP16 hbitmap )
Alexandre Julliard's avatar
Alexandre Julliard committed
888
{
Alexandre Julliard's avatar
Alexandre Julliard committed
889 890 891
    SIZE16 size;
    if (!GetBitmapDimensionEx16( hbitmap, &size )) return 0;
    return MAKELONG( size.cx, size.cy );
Alexandre Julliard's avatar
Alexandre Julliard committed
892 893
}

Alexandre Julliard's avatar
Alexandre Julliard committed
894

Alexandre Julliard's avatar
Alexandre Julliard committed
895
/***********************************************************************
Alexandre Julliard's avatar
Alexandre Julliard committed
896
 *           SetBitmapDimensionEx16    (GDI.478)
Alexandre Julliard's avatar
Alexandre Julliard committed
897
 */
Alexandre Julliard's avatar
Alexandre Julliard committed
898 899
BOOL16 WINAPI SetBitmapDimensionEx16( HBITMAP16 hbitmap, INT16 x, INT16 y,
                                      LPSIZE16 prevSize )
Alexandre Julliard's avatar
Alexandre Julliard committed
900 901 902
{
    BITMAPOBJ * bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC );
    if (!bmp) return FALSE;
903
    if (prevSize) CONV_SIZE32TO16( &bmp->size, prevSize );
Alexandre Julliard's avatar
Alexandre Julliard committed
904 905
    bmp->size.cx = x;
    bmp->size.cy = y;
Alexandre Julliard's avatar
Alexandre Julliard committed
906
    GDI_HEAP_UNLOCK( hbitmap );
Alexandre Julliard's avatar
Alexandre Julliard committed
907 908 909 910
    return TRUE;
}


Alexandre Julliard's avatar
Alexandre Julliard committed
911 912 913 914 915 916 917
/******************************************************************************
 * SetBitmapDimensionEx32 [GDI32.304]  Assignes dimensions to a bitmap
 *
 * RETURNS
 *    Success: TRUE
 *    Failure: FALSE
 */
918 919 920 921 922
BOOL WINAPI SetBitmapDimensionEx(
    HBITMAP hbitmap, /* [in]  Handle to bitmap */
    INT x,           /* [in]  Bitmap width */
    INT y,           /* [in]  Bitmap height */
    LPSIZE prevSize) /* [out] Address of structure for orig dims */
Alexandre Julliard's avatar
Alexandre Julliard committed
923 924 925
{
    BITMAPOBJ * bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC );
    if (!bmp) return FALSE;
926 927 928
    if (prevSize) *prevSize = bmp->size;
    bmp->size.cx = x;
    bmp->size.cy = y;
Alexandre Julliard's avatar
Alexandre Julliard committed
929
    GDI_HEAP_UNLOCK( hbitmap );
Alexandre Julliard's avatar
Alexandre Julliard committed
930 931 932 933
    return TRUE;
}


Alexandre Julliard's avatar
Alexandre Julliard committed
934 935 936
/***********************************************************************
 *           SetBitmapDimension    (GDI.163)
 */
937
DWORD WINAPI SetBitmapDimension16( HBITMAP16 hbitmap, INT16 x, INT16 y )
Alexandre Julliard's avatar
Alexandre Julliard committed
938
{
Alexandre Julliard's avatar
Alexandre Julliard committed
939 940 941
    SIZE16 size;
    if (!SetBitmapDimensionEx16( hbitmap, x, y, &size )) return 0;
    return MAKELONG( size.cx, size.cy );
Alexandre Julliard's avatar
Alexandre Julliard committed
942
}
Alexandre Julliard's avatar
Alexandre Julliard committed
943