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