Removed W->A from DEFWND_ImmIsUIMessageW.
[wine] / dlls / gdi / bitmap.c
1 /*
2  * GDI bitmap objects
3  *
4  * Copyright 1993 Alexandre Julliard
5  *           1998 Huw D M Davies
6  *
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.
11  *
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.
16  *
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  */
21
22 #include <stdlib.h>
23 #include <string.h>
24
25 #include "wine/winbase16.h"
26 #include "wine/winuser16.h"
27 #include "gdi.h"
28 #include "gdi_private.h"
29 #include "wine/debug.h"
30
31 WINE_DEFAULT_DEBUG_CHANNEL(bitmap);
32
33
34 static HGDIOBJ BITMAP_SelectObject( HGDIOBJ handle, void *obj, HDC hdc );
35 static INT BITMAP_GetObject16( HGDIOBJ handle, void *obj, INT count, LPVOID buffer );
36 static INT BITMAP_GetObject( HGDIOBJ handle, void *obj, INT count, LPVOID buffer );
37 static BOOL BITMAP_DeleteObject( HGDIOBJ handle, void *obj );
38
39 static const struct gdi_obj_funcs bitmap_funcs =
40 {
41     BITMAP_SelectObject,  /* pSelectObject */
42     BITMAP_GetObject16,   /* pGetObject16 */
43     BITMAP_GetObject,     /* pGetObjectA */
44     BITMAP_GetObject,     /* pGetObjectW */
45     NULL,                 /* pUnrealizeObject */
46     BITMAP_DeleteObject   /* pDeleteObject */
47 };
48
49 /***********************************************************************
50  *           BITMAP_GetWidthBytes
51  *
52  * Return number of bytes taken by a scanline of 16-bit aligned Windows DDB
53  * data.
54  */
55 static INT BITMAP_GetWidthBytes( INT bmWidth, INT bpp )
56 {
57     switch(bpp)
58     {
59     case 1:
60         return 2 * ((bmWidth+15) >> 4);
61
62     case 24:
63         bmWidth *= 3; /* fall through */
64     case 8:
65         return bmWidth + (bmWidth & 1);
66
67     case 32:
68         return bmWidth * 4;
69
70     case 16:
71     case 15:
72         return bmWidth * 2;
73
74     case 4:
75         return 2 * ((bmWidth+3) >> 2);
76
77     default:
78         WARN("Unknown depth %d, please report.\n", bpp );
79     }
80     return -1;
81 }
82
83
84 /******************************************************************************
85  * CreateBitmap [GDI32.@]
86  *
87  * Creates a bitmap with the specified info.
88  *
89  * PARAMS
90  *    width  [I] bitmap width
91  *    height [I] bitmap height
92  *    planes [I] Number of color planes
93  *    bpp    [I] Number of bits to identify a color
94  *    bits   [I] Pointer to array containing color data
95  *
96  * RETURNS
97  *    Success: Handle to bitmap
98  *    Failure: 0
99  */
100 HBITMAP WINAPI CreateBitmap( INT width, INT height, UINT planes,
101                                  UINT bpp, LPCVOID bits )
102 {
103     BITMAPOBJ *bmp;
104     HBITMAP hbitmap;
105
106     planes = (BYTE)planes;
107     bpp    = (BYTE)bpp;
108
109
110       /* Check parameters */
111     if (!height || !width)
112     {
113         height = 1;
114         width  = 1;
115         planes = 1;
116         bpp    = 1;
117     }
118     if (planes != 1) {
119         FIXME("planes = %d\n", planes);
120         return 0;
121     }
122     if (height < 0) height = -height;
123     if (width < 0) width = -width;
124
125       /* Create the BITMAPOBJ */
126     if (!(bmp = GDI_AllocObject( sizeof(BITMAPOBJ), BITMAP_MAGIC,
127                                  (HGDIOBJ *)&hbitmap, &bitmap_funcs )))
128         return 0;
129
130     TRACE("%dx%d, %d colors returning %p\n", width, height, 1 << (planes*bpp), hbitmap);
131
132     bmp->size.cx = 0;
133     bmp->size.cy = 0;
134     bmp->bitmap.bmType = 0;
135     bmp->bitmap.bmWidth = width;
136     bmp->bitmap.bmHeight = height;
137     bmp->bitmap.bmPlanes = planes;
138     bmp->bitmap.bmBitsPixel = bpp;
139     bmp->bitmap.bmWidthBytes = BITMAP_GetWidthBytes( width, bpp );
140     bmp->bitmap.bmBits = NULL;
141
142     bmp->funcs = NULL;
143     bmp->physBitmap = NULL;
144     bmp->dib = NULL;
145     bmp->segptr_bits = 0;
146
147     if (bits) /* Set bitmap bits */
148         SetBitmapBits( hbitmap, height * bmp->bitmap.bmWidthBytes,
149                          bits );
150     GDI_ReleaseObj( hbitmap );
151     return hbitmap;
152 }
153
154
155 /******************************************************************************
156  * CreateCompatibleBitmap [GDI32.@]
157  *
158  * Creates a bitmap compatible with the DC.
159  *
160  * PARAMS
161  *    hdc    [I] Handle to device context
162  *    width  [I] Width of bitmap
163  *    height [I] Height of bitmap
164  *
165  * RETURNS
166  *    Success: Handle to bitmap
167  *    Failure: 0
168  */
169 HBITMAP WINAPI CreateCompatibleBitmap( HDC hdc, INT width, INT height)
170 {
171     HBITMAP hbmpRet = 0;
172     DC *dc;
173
174     TRACE("(%p,%d,%d) = \n", hdc, width, height);
175
176     if ((width >= 0x10000) || (height >= 0x10000))
177     {
178         FIXME("got bad width %d or height %d, please look for reason\n",
179               width, height);
180     }
181     else
182     {
183         if (!(dc = DC_GetDCPtr(hdc))) return 0;
184
185         if (GDIMAGIC( dc->header.wMagic ) != MEMORY_DC_MAGIC)
186         {
187             hbmpRet = CreateBitmap(width, height,
188                                    GetDeviceCaps(hdc, PLANES),
189                                    GetDeviceCaps(hdc, BITSPIXEL),
190                                    NULL);
191         }
192         else  /* Memory DC */
193         {
194             BITMAPOBJ *bmp = GDI_GetObjPtr( dc->hBitmap, BITMAP_MAGIC );
195
196             if (!bmp->dib)
197             {
198                 /* A device-dependent bitmap is selected in the DC */
199                 hbmpRet = CreateBitmap(width, height,
200                                        bmp->bitmap.bmPlanes,
201                                        bmp->bitmap.bmBitsPixel,
202                                        NULL);
203             }
204             else
205             {
206                 /* A DIB section is selected in the DC */
207                 BITMAPINFO *bi;
208                 void *bits;
209
210                 /* Allocate memory for a BITMAPINFOHEADER structure and a
211                    color table. The maximum number of colors in a color table
212                    is 256 which corresponds to a bitmap with depth 8.
213                    Bitmaps with higher depths don't have color tables. */
214                 bi = HeapAlloc(GetProcessHeap(), 0, sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD));
215
216                 if (bi)
217                 {
218                     bi->bmiHeader.biSize          = sizeof(bi->bmiHeader);
219                     bi->bmiHeader.biWidth         = width;
220                     bi->bmiHeader.biHeight        = height;
221                     bi->bmiHeader.biPlanes        = bmp->dib->dsBmih.biPlanes;
222                     bi->bmiHeader.biBitCount      = bmp->dib->dsBmih.biBitCount;
223                     bi->bmiHeader.biCompression   = bmp->dib->dsBmih.biCompression;
224                     bi->bmiHeader.biSizeImage     = 0;
225                     bi->bmiHeader.biXPelsPerMeter = bmp->dib->dsBmih.biXPelsPerMeter;
226                     bi->bmiHeader.biYPelsPerMeter = bmp->dib->dsBmih.biYPelsPerMeter;           
227                     bi->bmiHeader.biClrUsed       = bmp->dib->dsBmih.biClrUsed;
228                     bi->bmiHeader.biClrImportant  = bmp->dib->dsBmih.biClrImportant;
229
230                     if (bi->bmiHeader.biCompression == BI_BITFIELDS)
231                     {
232                         /* Copy the color masks */
233                         CopyMemory(bi->bmiColors, bmp->dib->dsBitfields, 3 * sizeof(DWORD));
234                     }
235                     else if (bi->bmiHeader.biBitCount <= 8)
236                     {
237                         /* Copy the color table */
238                         GetDIBColorTable(hdc, 0, 256, bi->bmiColors);
239                     }
240
241                     hbmpRet = CreateDIBSection(hdc, bi, DIB_RGB_COLORS, &bits, NULL, 0);
242                     HeapFree(GetProcessHeap(), 0, bi);
243                 }
244             }
245             GDI_ReleaseObj(dc->hBitmap);
246         }
247         GDI_ReleaseObj(hdc);
248     }
249
250     TRACE("\t\t%p\n", hbmpRet);
251     return hbmpRet;
252 }
253
254
255 /******************************************************************************
256  * CreateBitmapIndirect [GDI32.@]
257  *
258  * Creates a bitmap with the specifies info.
259  *
260  * RETURNS
261  *    Success: Handle to bitmap
262  *    Failure: NULL
263  */
264 HBITMAP WINAPI CreateBitmapIndirect(
265     const BITMAP * bmp) /* [in] Pointer to the bitmap data */
266 {
267     return CreateBitmap( bmp->bmWidth, bmp->bmHeight, bmp->bmPlanes,
268                            bmp->bmBitsPixel, bmp->bmBits );
269 }
270
271
272 /***********************************************************************
273  * GetBitmapBits [GDI32.@]
274  *
275  * Copies bitmap bits of bitmap to buffer.
276  *
277  * RETURNS
278  *    Success: Number of bytes copied
279  *    Failure: 0
280  */
281 LONG WINAPI GetBitmapBits(
282     HBITMAP hbitmap, /* [in]  Handle to bitmap */
283     LONG count,        /* [in]  Number of bytes to copy */
284     LPVOID bits)       /* [out] Pointer to buffer to receive bits */
285 {
286     BITMAPOBJ *bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC );
287     LONG height, ret;
288
289     if (!bmp) return 0;
290
291     /* If the bits vector is null, the function should return the read size */
292     if(bits == NULL)
293     {
294         ret = bmp->bitmap.bmWidthBytes * bmp->bitmap.bmHeight;
295         goto done;
296     }
297
298     if (count < 0) {
299         WARN("(%ld): Negative number of bytes passed???\n", count );
300         count = -count;
301     }
302
303     /* Only get entire lines */
304     height = count / bmp->bitmap.bmWidthBytes;
305     if (height > bmp->bitmap.bmHeight) height = bmp->bitmap.bmHeight;
306     count = height * bmp->bitmap.bmWidthBytes;
307     if (count == 0)
308       {
309         WARN("Less than one entire line requested\n");
310         ret = 0;
311         goto done;
312       }
313
314
315     TRACE("(%p, %ld, %p) %dx%d %d colors fetched height: %ld\n",
316           hbitmap, count, bits, bmp->bitmap.bmWidth, bmp->bitmap.bmHeight,
317           1 << bmp->bitmap.bmBitsPixel, height );
318
319     if(bmp->funcs && bmp->funcs->pGetBitmapBits)
320     {
321         TRACE("Calling device specific BitmapBits\n");
322         ret = bmp->funcs->pGetBitmapBits(hbitmap, bits, count);
323     } else {
324
325         if(!bmp->bitmap.bmBits) {
326             WARN("Bitmap is empty\n");
327             ret = 0;
328         } else {
329             memcpy(bits, bmp->bitmap.bmBits, count);
330             ret = count;
331         }
332
333     }
334  done:
335     GDI_ReleaseObj( hbitmap );
336     return ret;
337 }
338
339
340 /******************************************************************************
341  * SetBitmapBits [GDI32.@]
342  *
343  * Sets bits of color data for a bitmap.
344  *
345  * RETURNS
346  *    Success: Number of bytes used in setting the bitmap bits
347  *    Failure: 0
348  */
349 LONG WINAPI SetBitmapBits(
350     HBITMAP hbitmap, /* [in] Handle to bitmap */
351     LONG count,        /* [in] Number of bytes in bitmap array */
352     LPCVOID bits)      /* [in] Address of array with bitmap bits */
353 {
354     BITMAPOBJ *bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC );
355     LONG height, ret;
356
357     if ((!bmp) || (!bits))
358         return 0;
359
360     if (count < 0) {
361         WARN("(%ld): Negative number of bytes passed???\n", count );
362         count = -count;
363     }
364
365     /* Only get entire lines */
366     height = count / bmp->bitmap.bmWidthBytes;
367     if (height > bmp->bitmap.bmHeight) height = bmp->bitmap.bmHeight;
368     count = height * bmp->bitmap.bmWidthBytes;
369
370     TRACE("(%p, %ld, %p) %dx%d %d colors fetched height: %ld\n",
371           hbitmap, count, bits, bmp->bitmap.bmWidth, bmp->bitmap.bmHeight,
372           1 << bmp->bitmap.bmBitsPixel, height );
373
374     if(bmp->funcs && bmp->funcs->pSetBitmapBits) {
375
376         TRACE("Calling device specific BitmapBits\n");
377         ret = bmp->funcs->pSetBitmapBits(hbitmap, bits, count);
378     } else {
379
380         if(!bmp->bitmap.bmBits) /* Alloc enough for entire bitmap */
381             bmp->bitmap.bmBits = HeapAlloc( GetProcessHeap(), 0, count );
382         if(!bmp->bitmap.bmBits) {
383             WARN("Unable to allocate bit buffer\n");
384             ret = 0;
385         } else {
386             memcpy(bmp->bitmap.bmBits, bits, count);
387             ret = count;
388         }
389     }
390
391     GDI_ReleaseObj( hbitmap );
392     return ret;
393 }
394
395 /**********************************************************************
396  *              BITMAP_CopyBitmap
397  *
398  */
399 HBITMAP BITMAP_CopyBitmap(HBITMAP hbitmap)
400 {
401     BITMAPOBJ *bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC );
402     HBITMAP res = 0;
403     BITMAP bm;
404
405     if(!bmp) return 0;
406
407     bm = bmp->bitmap;
408     bm.bmBits = NULL;
409     res = CreateBitmapIndirect(&bm);
410
411     if(res) {
412         char *buf = HeapAlloc( GetProcessHeap(), 0, bm.bmWidthBytes *
413                                bm.bmHeight );
414         GetBitmapBits (hbitmap, bm.bmWidthBytes * bm.bmHeight, buf);
415         SetBitmapBits (res, bm.bmWidthBytes * bm.bmHeight, buf);
416         HeapFree( GetProcessHeap(), 0, buf );
417     }
418
419     GDI_ReleaseObj( hbitmap );
420     return res;
421 }
422
423
424 /***********************************************************************
425  *           BITMAP_SetOwnerDC
426  *
427  * Set the type of DC that owns the bitmap. This is used when the
428  * bitmap is selected into a device to initialize the bitmap function
429  * table.
430  */
431 BOOL BITMAP_SetOwnerDC( HBITMAP hbitmap, DC *dc )
432 {
433     BITMAPOBJ *bitmap;
434     BOOL ret;
435
436     /* never set the owner of the stock bitmap since it can be selected in multiple DCs */
437     if (hbitmap == GetStockObject(DEFAULT_BITMAP)) return TRUE;
438
439     if (!(bitmap = GDI_GetObjPtr( hbitmap, BITMAP_MAGIC ))) return FALSE;
440
441     ret = TRUE;
442     if (!bitmap->funcs)  /* not owned by a DC yet */
443     {
444         if (dc->funcs->pCreateBitmap) ret = dc->funcs->pCreateBitmap( dc->physDev, hbitmap );
445         if (ret) bitmap->funcs = dc->funcs;
446     }
447     else if (bitmap->funcs != dc->funcs)
448     {
449         FIXME( "Trying to select bitmap %p in different DC type\n", hbitmap );
450         ret = FALSE;
451     }
452     GDI_ReleaseObj( hbitmap );
453     return ret;
454 }
455
456
457 /***********************************************************************
458  *           BITMAP_SelectObject
459  */
460 static HGDIOBJ BITMAP_SelectObject( HGDIOBJ handle, void *obj, HDC hdc )
461 {
462     HGDIOBJ ret;
463     BITMAPOBJ *bitmap = obj;
464     DC *dc = DC_GetDCPtr( hdc );
465
466     if (!dc) return 0;
467     if (GetObjectType( hdc ) != OBJ_MEMDC)
468     {
469         GDI_ReleaseObj( hdc );
470         return 0;
471     }
472     ret = dc->hBitmap;
473     if (handle == dc->hBitmap) goto done;  /* nothing to do */
474
475     if (bitmap->header.dwCount && (handle != GetStockObject(DEFAULT_BITMAP)))
476     {
477         WARN( "Bitmap already selected in another DC\n" );
478         GDI_ReleaseObj( hdc );
479         return 0;
480     }
481
482     if (!bitmap->funcs && !BITMAP_SetOwnerDC( handle, dc ))
483     {
484         GDI_ReleaseObj( hdc );
485         return 0;
486     }
487
488     if (dc->funcs->pSelectBitmap) handle = dc->funcs->pSelectBitmap( dc->physDev, handle );
489
490     if (handle)
491     {
492         dc->hBitmap = handle;
493         dc->flags &= ~DC_DIRTY;
494         SetRectRgn( dc->hVisRgn, 0, 0, bitmap->bitmap.bmWidth, bitmap->bitmap.bmHeight);
495         DC_InitDC( dc );
496     }
497     else ret = 0;
498
499  done:
500     GDI_ReleaseObj( hdc );
501     return ret;
502 }
503
504
505 /***********************************************************************
506  *           BITMAP_DeleteObject
507  */
508 static BOOL BITMAP_DeleteObject( HGDIOBJ handle, void *obj )
509 {
510     BITMAPOBJ * bmp = obj;
511
512     if (bmp->funcs && bmp->funcs->pDeleteBitmap)
513         bmp->funcs->pDeleteBitmap( handle );
514
515     if( bmp->bitmap.bmBits )
516         HeapFree( GetProcessHeap(), 0, bmp->bitmap.bmBits );
517
518     if (bmp->dib)
519     {
520         DIBSECTION *dib = bmp->dib;
521
522         if (dib->dsBm.bmBits)
523         {
524             if (dib->dshSection)
525             {
526                 SYSTEM_INFO SystemInfo;
527                 GetSystemInfo( &SystemInfo );
528                 UnmapViewOfFile( (char *)dib->dsBm.bmBits -
529                                  (dib->dsOffset % SystemInfo.dwAllocationGranularity) );
530             }
531             else if (!dib->dsOffset)
532                 VirtualFree(dib->dsBm.bmBits, 0L, MEM_RELEASE );
533         }
534         HeapFree(GetProcessHeap(), 0, dib);
535         bmp->dib = NULL;
536         if (bmp->segptr_bits)
537         { /* free its selector array */
538             WORD sel = SELECTOROF(bmp->segptr_bits);
539             WORD count = (GetSelectorLimit16(sel) / 0x10000) + 1;
540             int i;
541
542             for (i = 0; i < count; i++) FreeSelector16(sel + (i << __AHSHIFT));
543         }
544     }
545     return GDI_FreeObject( handle, obj );
546 }
547
548
549 /***********************************************************************
550  *           BITMAP_GetObject16
551  */
552 static INT BITMAP_GetObject16( HGDIOBJ handle, void *obj, INT count, LPVOID buffer )
553 {
554     BITMAPOBJ *bmp = obj;
555
556     if (bmp->dib)
557     {
558         if ( count <= sizeof(BITMAP16) )
559         {
560             BITMAP *bmp32 = &bmp->dib->dsBm;
561             BITMAP16 bmp16;
562             bmp16.bmType       = bmp32->bmType;
563             bmp16.bmWidth      = bmp32->bmWidth;
564             bmp16.bmHeight     = bmp32->bmHeight;
565             bmp16.bmWidthBytes = bmp32->bmWidthBytes;
566             bmp16.bmPlanes     = bmp32->bmPlanes;
567             bmp16.bmBitsPixel  = bmp32->bmBitsPixel;
568             bmp16.bmBits       = (SEGPTR)0;
569             memcpy( buffer, &bmp16, count );
570             return count;
571         }
572         else
573         {
574             FIXME("not implemented for DIBs: count %d\n", count);
575             return 0;
576         }
577     }
578     else
579     {
580         BITMAP16 bmp16;
581         bmp16.bmType       = bmp->bitmap.bmType;
582         bmp16.bmWidth      = bmp->bitmap.bmWidth;
583         bmp16.bmHeight     = bmp->bitmap.bmHeight;
584         bmp16.bmWidthBytes = bmp->bitmap.bmWidthBytes;
585         bmp16.bmPlanes     = bmp->bitmap.bmPlanes;
586         bmp16.bmBitsPixel  = bmp->bitmap.bmBitsPixel;
587         bmp16.bmBits       = (SEGPTR)0;
588         if (count > sizeof(bmp16)) count = sizeof(bmp16);
589         memcpy( buffer, &bmp16, count );
590         return count;
591     }
592 }
593
594
595 /***********************************************************************
596  *           BITMAP_GetObject
597  */
598 static INT BITMAP_GetObject( HGDIOBJ handle, void *obj, INT count, LPVOID buffer )
599 {
600     BITMAPOBJ *bmp = obj;
601
602     if (bmp->dib)
603     {
604         if( !buffer )
605             return sizeof(DIBSECTION);
606         if (count < sizeof(DIBSECTION))
607         {
608             if (count > sizeof(BITMAP)) count = sizeof(BITMAP);
609         }
610         else
611         {
612             if (count > sizeof(DIBSECTION)) count = sizeof(DIBSECTION);
613         }
614
615         memcpy( buffer, bmp->dib, count );
616         return count;
617     }
618     else
619     {
620         if( !buffer )
621             return sizeof(BITMAP);
622         if (count > sizeof(BITMAP)) count = sizeof(BITMAP);
623         memcpy( buffer, &bmp->bitmap, count );
624         return count;
625     }
626 }
627
628
629 /******************************************************************************
630  * CreateDiscardableBitmap [GDI32.@]
631  *
632  * Creates a discardable bitmap.
633  *
634  * RETURNS
635  *    Success: Handle to bitmap
636  *    Failure: NULL
637  */
638 HBITMAP WINAPI CreateDiscardableBitmap(
639     HDC hdc,    /* [in] Handle to device context */
640     INT width,  /* [in] Bitmap width */
641     INT height) /* [in] Bitmap height */
642 {
643     return CreateCompatibleBitmap( hdc, width, height );
644 }
645
646
647 /******************************************************************************
648  * GetBitmapDimensionEx [GDI32.@]
649  *
650  * Retrieves dimensions of a bitmap.
651  *
652  * RETURNS
653  *    Success: TRUE
654  *    Failure: FALSE
655  */
656 BOOL WINAPI GetBitmapDimensionEx(
657     HBITMAP hbitmap, /* [in]  Handle to bitmap */
658     LPSIZE size)     /* [out] Address of struct receiving dimensions */
659 {
660     BITMAPOBJ * bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC );
661     if (!bmp) return FALSE;
662     *size = bmp->size;
663     GDI_ReleaseObj( hbitmap );
664     return TRUE;
665 }
666
667
668 /******************************************************************************
669  * SetBitmapDimensionEx [GDI32.@]
670  *
671  * Assigns dimensions to a bitmap.
672  * MSDN says that this function will fail if hbitmap is a handle created by
673  * CreateDIBSection, but that's not true on Windows 2000.
674  *
675  * RETURNS
676  *    Success: TRUE
677  *    Failure: FALSE
678  */
679 BOOL WINAPI SetBitmapDimensionEx(
680     HBITMAP hbitmap, /* [in]  Handle to bitmap */
681     INT x,           /* [in]  Bitmap width */
682     INT y,           /* [in]  Bitmap height */
683     LPSIZE prevSize) /* [out] Address of structure for orig dims */
684 {
685     BITMAPOBJ * bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC );
686     if (!bmp) return FALSE;
687     if (prevSize) *prevSize = bmp->size;
688     bmp->size.cx = x;
689     bmp->size.cy = y;
690     GDI_ReleaseObj( hbitmap );
691     return TRUE;
692 }