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