~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Wine Cross Reference
wine/dlls/gdi32/bitmap.c

Version: ~ [ wine-1.1.33 ] ~ [ wine-1.1.32 ] ~ [ wine-1.1.31 ] ~ [ wine-1.1.30 ] ~ [ wine-1.1.29 ] ~ [ wine-1.1.28 ] ~ [ wine-1.1.27 ] ~ [ wine-1.1.26 ] ~ [ wine-1.1.25 ] ~ [ wine-1.1.24 ] ~ [ wine-1.1.23 ] ~ [ wine-1.1.22 ] ~ [ wine-1.1.21 ] ~ [ wine-1.1.20 ] ~ [ wine-1.1.19 ] ~ [ wine-1.1.18 ] ~ [ wine-1.1.17 ] ~ [ wine-1.1.16 ] ~ [ wine-1.1.15 ] ~ [ wine-1.1.14 ] ~ [ wine-1.1.13 ] ~ [ wine-1.1.12 ] ~ [ wine-1.1.11 ] ~ [ wine-1.1.10 ] ~ [ wine-1.1.9 ] ~ [ wine-1.1.8 ] ~ [ wine-1.1.7 ] ~ [ wine-1.0.1 ] ~ [ wine-1.1.6 ] ~ [ wine-1.1.5 ] ~ [ wine-1.1.4 ] ~ [ wine-1.1.3 ] ~ [ wine-1.1.2 ] ~ [ wine-1.1.1 ] ~ [ wine-1.1.0 ] ~ [ wine-1.0 ] ~

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

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.