Release 971012
[wine/multimedia.git] / objects / bitmap.c
blob18df9836c66e27c7e87aba28dc1c24c825258033
1 /*
2 * GDI bitmap objects
4 * Copyright 1993 Alexandre Julliard
5 */
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <string.h>
10 #include <X11/Xlib.h>
11 #include <X11/Xutil.h>
12 #include "gdi.h"
13 #include "callback.h"
14 #include "dc.h"
15 #include "bitmap.h"
16 #include "heap.h"
17 #include "stddebug.h"
18 #include "debug.h"
20 #ifdef PRELIMINARY_WING16_SUPPORT
21 #include <sys/types.h>
22 #include <sys/ipc.h>
23 #include <sys/shm.h>
24 #endif
26 /* GCs used for B&W and color bitmap operations */
27 GC BITMAP_monoGC = 0, BITMAP_colorGC = 0;
29 extern void CLIPPING_UpdateGCRegion( DC * dc ); /* objects/clipping.c */
32 /***********************************************************************
33 * XPutImage_wrapper
35 * Wrapper to call XPutImage with CALL_LARGE_STACK.
38 struct XPutImage_descr
40 BITMAPOBJ *bmp;
41 XImage *image;
42 INT32 width;
43 INT32 height;
46 static int XPutImage_wrapper( const struct XPutImage_descr *descr )
48 return XPutImage( display, descr->bmp->pixmap, BITMAP_GC(descr->bmp),
49 descr->image, 0, 0, 0, 0, descr->width, descr->height );
52 /***********************************************************************
53 * BITMAP_GetBitsPadding
55 * Return number of bytes to pad a scanline of 16-bit aligned Windows DDB data.
57 INT32 BITMAP_GetBitsPadding( int bmWidth, int bpp )
59 INT32 pad;
61 switch (bpp)
63 case 1:
64 if (!(bmWidth & 15)) pad = 0;
65 else pad = ((16 - (bmWidth & 15)) + 7) / 8;
66 break;
68 case 8:
69 pad = (2 - (bmWidth & 1)) & 1;
70 break;
72 case 24:
73 pad = (bmWidth*3) & 1;
74 break;
76 case 32:
77 case 16:
78 case 15:
79 pad = 0; /* we have 16bit alignment already */
80 break;
82 case 4:
83 if (!(bmWidth & 3)) pad = 0;
84 else pad = ((4 - (bmWidth & 3)) + 1) / 2;
85 break;
87 default:
88 fprintf(stderr,"GetBitsPadding: unknown depth %d, please report.\n", bpp );
89 return -1;
91 return pad;
94 /***********************************************************************
95 * BITMAP_GetBitsWidth
97 * Return number of bytes taken by a scanline of 16-bit aligned Windows DDB data.
99 INT32 BITMAP_GetBitsWidth( int bmWidth, int bpp )
101 switch(bpp)
103 case 1:
104 return 2 * ((bmWidth+15) >> 4);
106 case 24:
107 bmWidth *= 3; /* fall through */
108 case 8:
109 return bmWidth + (bmWidth & 1);
111 case 32:
112 return bmWidth * 4;
114 case 16:
115 case 15:
116 return bmWidth * 2;
118 case 4:
119 return 2 * ((bmWidth+3) >> 2);
121 default:
122 fprintf(stderr,"GetBitsPadding: unknown depth %d, please report.\n", bpp );
124 return -1;
127 /***********************************************************************
128 * CreateBitmap16 (GDI.48)
130 HBITMAP16 WINAPI CreateBitmap16( INT16 width, INT16 height, UINT16 planes,
131 UINT16 bpp, LPCVOID bits )
133 return CreateBitmap32( width, height, planes, bpp, bits );
137 /***********************************************************************
138 * CreateBitmap32 (GDI32.25)
140 HBITMAP32 WINAPI CreateBitmap32( INT32 width, INT32 height, UINT32 planes,
141 UINT32 bpp, LPCVOID bits )
143 BITMAPOBJ * bmpObjPtr;
144 HBITMAP32 hbitmap;
146 planes = (BYTE)planes;
147 bpp = (BYTE)bpp;
149 dprintf_gdi( stddeb, "CreateBitmap: %dx%d, %d colors\n",
150 width, height, 1 << (planes*bpp) );
152 /* Check parameters */
153 if (!height || !width || planes != 1) return 0;
154 if ((bpp != 1) && (bpp != screenDepth)) return 0;
155 if (height < 0) height = -height;
156 if (width < 0) width = -width;
158 /* Create the BITMAPOBJ */
159 hbitmap = GDI_AllocObject( sizeof(BITMAPOBJ), BITMAP_MAGIC );
160 if (!hbitmap) return 0;
161 bmpObjPtr = (BITMAPOBJ *) GDI_HEAP_LOCK( hbitmap );
163 bmpObjPtr->size.cx = 0;
164 bmpObjPtr->size.cy = 0;
165 bmpObjPtr->bitmap.bmType = 0;
166 bmpObjPtr->bitmap.bmWidth = (INT16)width;
167 bmpObjPtr->bitmap.bmHeight = (INT16)height;
168 bmpObjPtr->bitmap.bmPlanes = (BYTE)planes;
169 bmpObjPtr->bitmap.bmBitsPixel = (BYTE)bpp;
170 bmpObjPtr->bitmap.bmWidthBytes = (INT16)BITMAP_WIDTH_BYTES( width, bpp );
171 bmpObjPtr->bitmap.bmBits = NULL;
173 /* Create the pixmap */
174 bmpObjPtr->pixmap = XCreatePixmap(display, rootWindow, width, height, bpp);
175 if (!bmpObjPtr->pixmap)
177 GDI_HEAP_FREE( hbitmap );
178 hbitmap = 0;
180 else if (bits) /* Set bitmap bits */
181 SetBitmapBits32( hbitmap, height * bmpObjPtr->bitmap.bmWidthBytes,
182 bits );
183 GDI_HEAP_UNLOCK( hbitmap );
184 return hbitmap;
188 /***********************************************************************
189 * CreateCompatibleBitmap16 (GDI.51)
191 HBITMAP16 WINAPI CreateCompatibleBitmap16(HDC16 hdc, INT16 width, INT16 height)
193 return CreateCompatibleBitmap32( hdc, width, height );
197 /***********************************************************************
198 * CreateCompatibleBitmap32 (GDI32.30)
200 HBITMAP32 WINAPI CreateCompatibleBitmap32(HDC32 hdc, INT32 width, INT32 height)
202 HBITMAP32 hbmpRet = 0;
203 DC *dc;
205 dprintf_gdi( stddeb, "CreateCompatibleBitmap(%04x,%d,%d) = \n",
206 hdc, width, height );
207 if (!(dc = DC_GetDCPtr( hdc ))) return 0;
208 hbmpRet = CreateBitmap32( width, height, 1, dc->w.bitsPerPixel, NULL );
209 dprintf_gdi(stddeb,"\t\t%04x\n", hbmpRet);
210 return hbmpRet;
214 /***********************************************************************
215 * CreateBitmapIndirect16 (GDI.49)
217 HBITMAP16 WINAPI CreateBitmapIndirect16( const BITMAP16 * bmp )
219 return CreateBitmap16( bmp->bmWidth, bmp->bmHeight, bmp->bmPlanes,
220 bmp->bmBitsPixel, PTR_SEG_TO_LIN( bmp->bmBits ) );
224 /***********************************************************************
225 * CreateBitmapIndirect32 (GDI32.26)
227 HBITMAP32 WINAPI CreateBitmapIndirect32( const BITMAP32 * bmp )
229 return CreateBitmap32( bmp->bmWidth, bmp->bmHeight, bmp->bmPlanes,
230 bmp->bmBitsPixel, bmp->bmBits );
234 /***********************************************************************
235 * BITMAP_GetXImage
237 * Get an X image for a bitmap. For use with CALL_LARGE_STACK.
239 XImage *BITMAP_GetXImage( const BITMAPOBJ *bmp )
241 return XGetImage( display, bmp->pixmap, 0, 0, bmp->bitmap.bmWidth,
242 bmp->bitmap.bmHeight, AllPlanes, ZPixmap );
246 /***********************************************************************
247 * GetBitmapBits16 (GDI.74)
249 LONG WINAPI GetBitmapBits16( HBITMAP16 hbitmap, LONG count, LPVOID buffer )
251 return GetBitmapBits32( hbitmap, count, buffer );
255 /***********************************************************************
256 * GetBitmapBits32 (GDI32.143)
258 LONG WINAPI GetBitmapBits32( HBITMAP32 hbitmap, LONG count, LPVOID buffer )
260 BITMAPOBJ * bmp;
261 LONG height, old_height;
262 XImage * image;
263 LPBYTE tbuf;
264 int h,w,pad;
266 /* KLUDGE! */
267 if (count < 0) {
268 fprintf(stderr, "Negative number of bytes (%ld) passed to GetBitmapBits???\n", count );
269 count = -count;
271 bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC );
272 if (!bmp) return 0;
274 /* Only get entire lines */
275 height = count / bmp->bitmap.bmWidthBytes;
276 if (height > bmp->bitmap.bmHeight) height = bmp->bitmap.bmHeight;
278 dprintf_bitmap(stddeb, "GetBitmapBits: %dx%d %d colors %p fetched height: %ld\n",
279 bmp->bitmap.bmWidth, bmp->bitmap.bmHeight,
280 1 << bmp->bitmap.bmBitsPixel, buffer, height );
282 pad = BITMAP_GetBitsPadding( bmp->bitmap.bmWidth, bmp->bitmap.bmBitsPixel );
284 if (!height || (pad == -1))
286 GDI_HEAP_UNLOCK( hbitmap );
287 return 0;
290 /* Hack: change the bitmap height temporarily to avoid */
291 /* getting unnecessary bitmap rows. */
292 old_height = bmp->bitmap.bmHeight;
293 bmp->bitmap.bmHeight = height;
294 image = (XImage *)CALL_LARGE_STACK( BITMAP_GetXImage, bmp );
295 bmp->bitmap.bmHeight = old_height;
297 /* copy XImage to 16 bit padded image buffer with real bitsperpixel */
299 tbuf = buffer;
300 switch (bmp->bitmap.bmBitsPixel)
302 case 1:
303 for (h=0;h<height;h++)
305 *tbuf = 0;
306 for (w=0;w<bmp->bitmap.bmWidth;w++)
308 if ((w%8) == 0)
309 *tbuf = 0;
310 *tbuf |= XGetPixel(image,w,h)<<(7-(w&7));
311 if ((w&7) == 7) ++tbuf;
313 tbuf += pad;
315 break;
316 case 4:
317 for (h=0;h<height;h++)
319 for (w=0;w<bmp->bitmap.bmWidth;w++)
321 if (!(w & 1)) *tbuf = XGetPixel( image, w, h) << 4;
322 else *tbuf++ |= XGetPixel( image, w, h) & 0x0f;
324 tbuf += pad;
326 break;
327 case 8:
328 for (h=0;h<height;h++)
330 for (w=0;w<bmp->bitmap.bmWidth;w++)
331 *tbuf++ = XGetPixel(image,w,h);
332 tbuf += pad;
334 break;
335 case 15:
336 case 16:
337 for (h=0;h<height;h++)
339 for (w=0;w<bmp->bitmap.bmWidth;w++)
341 long pixel = XGetPixel(image,w,h);
343 *tbuf++ = pixel & 0xff;
344 *tbuf++ = (pixel>>8) & 0xff;
347 break;
348 case 24:
349 for (h=0;h<height;h++)
351 for (w=0;w<bmp->bitmap.bmWidth;w++)
353 long pixel = XGetPixel(image,w,h);
355 *tbuf++ = pixel & 0xff;
356 *tbuf++ = (pixel>> 8) & 0xff;
357 *tbuf++ = (pixel>>16) & 0xff;
359 tbuf += pad;
362 XDestroyImage( image );
363 GDI_HEAP_UNLOCK( hbitmap );
364 return height * bmp->bitmap.bmWidthBytes;
368 /***********************************************************************
369 * SetBitmapBits16 (GDI.106)
371 LONG WINAPI SetBitmapBits16( HBITMAP16 hbitmap, LONG count, LPCVOID buffer )
373 return SetBitmapBits32( hbitmap, count, buffer );
377 /***********************************************************************
378 * SetBitmapBits32 (GDI32.303)
380 LONG WINAPI SetBitmapBits32( HBITMAP32 hbitmap, LONG count, LPCVOID buffer )
382 struct XPutImage_descr descr;
383 BITMAPOBJ * bmp;
384 LONG height;
385 XImage * image;
386 LPBYTE sbuf,tmpbuffer;
387 int w,h,pad,widthbytes;
389 /* KLUDGE! */
390 if (count < 0) {
391 fprintf(stderr, "Negative number of bytes (%ld) passed to SetBitmapBits???\n", count );
392 count = -count;
394 bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC );
395 if (!bmp) return 0;
397 dprintf_bitmap(stddeb, "SetBitmapBits: %dx%d %d colors %p\n",
398 bmp->bitmap.bmWidth, bmp->bitmap.bmHeight,
399 1 << bmp->bitmap.bmBitsPixel, buffer );
401 /* Only set entire lines */
402 height = count / bmp->bitmap.bmWidthBytes;
403 if (height > bmp->bitmap.bmHeight) height = bmp->bitmap.bmHeight;
405 pad = BITMAP_GetBitsPadding( bmp->bitmap.bmWidth, bmp->bitmap.bmBitsPixel );
407 if (!height || (pad == -1))
409 GDI_HEAP_UNLOCK( hbitmap );
410 return 0;
413 sbuf = (LPBYTE)buffer;
415 widthbytes = DIB_GetXImageWidthBytes(bmp->bitmap.bmWidth,bmp->bitmap.bmBitsPixel);
416 tmpbuffer = (LPBYTE)xmalloc(widthbytes*height);
417 image = XCreateImage( display, DefaultVisualOfScreen(screen),
418 bmp->bitmap.bmBitsPixel, ZPixmap, 0, tmpbuffer,
419 bmp->bitmap.bmWidth,height,32,widthbytes
422 /* copy 16 bit padded image buffer with real bitsperpixel to XImage */
423 sbuf = (LPBYTE)buffer;
424 switch (bmp->bitmap.bmBitsPixel)
426 case 1:
427 for (h=0;h<height;h++)
429 for (w=0;w<bmp->bitmap.bmWidth;w++)
431 XPutPixel(image,w,h,(sbuf[0]>>(7-(w&7))) & 1);
432 if ((w&7) == 7)
433 sbuf++;
435 sbuf += pad;
437 break;
438 case 4:
439 for (h=0;h<height;h++)
441 for (w=0;w<bmp->bitmap.bmWidth;w++)
443 if (!(w & 1)) XPutPixel( image, w, h, *sbuf >> 4 );
444 else XPutPixel( image, w, h, *sbuf++ & 0xf );
446 sbuf += pad;
448 break;
449 case 8:
450 for (h=0;h<height;h++)
452 for (w=0;w<bmp->bitmap.bmWidth;w++)
453 XPutPixel(image,w,h,*sbuf++);
454 sbuf += pad;
456 break;
457 case 15:
458 case 16:
459 for (h=0;h<height;h++)
461 for (w=0;w<bmp->bitmap.bmWidth;w++)
463 XPutPixel(image,w,h,sbuf[1]*256+sbuf[0]);
464 sbuf+=2;
467 break;
468 case 24:
469 for (h=0;h<height;h++)
471 for (w=0;w<bmp->bitmap.bmWidth;w++)
473 XPutPixel(image,w,h,(sbuf[2]<<16)+(sbuf[1]<<8)+sbuf[0]);
474 sbuf += 3;
476 sbuf += pad;
478 break;
481 descr.bmp = bmp;
482 descr.image = image;
483 descr.width = bmp->bitmap.bmWidth;
484 descr.height = height;
485 CALL_LARGE_STACK( XPutImage_wrapper, &descr );
487 XDestroyImage( image ); /* frees tmpbuffer too */
488 GDI_HEAP_UNLOCK( hbitmap );
489 return height * bmp->bitmap.bmWidthBytes;
492 /**********************************************************************
493 * LoadImageA (USER32.364)
494 * FIXME: implementation still lacks nearly all features, see LR_*
495 * defines in windows.h
498 HANDLE32 WINAPI LoadImage32A( HINSTANCE32 hinst, LPCSTR name, UINT32 type,
499 INT32 desiredx, INT32 desiredy, UINT32 loadflags)
501 if (HIWORD(name)) {
502 dprintf_resource(stddeb,"LoadImage32A(0x%04x,%s,%d,%d,%d,0x%08x)\n",
503 hinst,name,type,desiredx,desiredy,loadflags
505 } else {
506 dprintf_resource(stddeb,"LoadImage32A(0x%04x,%p,%d,%d,%d,0x%08x)\n",
507 hinst,name,type,desiredx,desiredy,loadflags
510 switch (type) {
511 case IMAGE_BITMAP:
512 return LoadBitmap32A(hinst,name);
513 case IMAGE_ICON:
514 return LoadIcon32A(hinst,name);
515 case IMAGE_CURSOR:
516 return LoadCursor32A(hinst,name);
518 return 0;
521 HANDLE32 WINAPI LoadImage32W( HINSTANCE32 hinst, LPCWSTR name, UINT32 type,
522 INT32 desiredx, INT32 desiredy, UINT32 loadflags)
524 if (HIWORD(name)) {
525 dprintf_resource(stddeb,"LoadImage32W(0x%04x,%p,%d,%d,%d,0x%08x)\n",
526 hinst,name,type,desiredx,desiredy,loadflags
528 } else {
529 dprintf_resource(stddeb,"LoadImage32W(0x%04x,%p,%d,%d,%d,0x%08x)\n",
530 hinst,name,type,desiredx,desiredy,loadflags
533 switch (type) {
534 case IMAGE_BITMAP:
535 return LoadBitmap32W(hinst,name);
536 case IMAGE_ICON:
537 return LoadIcon32W(hinst,name);
538 case IMAGE_CURSOR:
539 return LoadCursor32W(hinst,name);
541 return 0;
544 /**********************************************************************
545 * CopyImage32 (USER32.60)
547 * FIXME: implementation still lacks nearly all features, see LR_*
548 * defines in windows.h
550 HANDLE32 WINAPI CopyImage32( HANDLE32 hnd, UINT32 type, INT32 desiredx,
551 INT32 desiredy, UINT32 flags )
553 switch (type)
555 case IMAGE_BITMAP:
556 return hnd; /* FIXME ... need to copy here */
557 case IMAGE_ICON:
558 return CopyIcon32(hnd);
559 case IMAGE_CURSOR:
560 return CopyCursor32(hnd);
562 return 0;
566 /**********************************************************************
567 * LoadBitmap16 (USER.175)
569 HBITMAP16 WINAPI LoadBitmap16( HINSTANCE16 instance, SEGPTR name )
571 HBITMAP32 hbitmap = 0;
572 HDC32 hdc;
573 HRSRC16 hRsrc;
574 HGLOBAL16 handle;
575 BITMAPINFO *info;
577 if (HIWORD(name))
579 char *str = (char *)PTR_SEG_TO_LIN( name );
580 dprintf_bitmap( stddeb, "LoadBitmap16(%04x,'%s')\n", instance, str );
581 if (str[0] == '#') name = (SEGPTR)(DWORD)(WORD)atoi( str + 1 );
583 else
584 dprintf_bitmap( stddeb, "LoadBitmap16(%04x,%04x)\n",
585 instance, LOWORD(name) );
587 if (!instance) /* OEM bitmap */
589 if (HIWORD((int)name)) return 0;
590 return OBM_LoadBitmap( LOWORD((int)name) );
593 if (!(hRsrc = FindResource16( instance, name, RT_BITMAP ))) return 0;
594 if (!(handle = LoadResource16( instance, hRsrc ))) return 0;
596 info = (BITMAPINFO *)LockResource16( handle );
597 if ((hdc = GetDC32(0)) != 0)
599 char *bits = (char *)info + DIB_BitmapInfoSize( info, DIB_RGB_COLORS );
600 hbitmap = CreateDIBitmap32( hdc, &info->bmiHeader, CBM_INIT,
601 bits, info, DIB_RGB_COLORS );
602 ReleaseDC32( 0, hdc );
604 FreeResource16( handle );
605 return hbitmap;
608 /**********************************************************************
609 * LoadBitmap32W (USER32.357)
611 HBITMAP32 WINAPI LoadBitmap32W( HINSTANCE32 instance, LPCWSTR name )
613 HBITMAP32 hbitmap = 0;
614 HDC32 hdc;
615 HRSRC32 hRsrc;
616 HGLOBAL32 handle;
617 BITMAPINFO *info;
619 if (!instance) /* OEM bitmap */
621 if (HIWORD((int)name)) return 0;
622 return OBM_LoadBitmap( LOWORD((int)name) );
625 if (!(hRsrc = FindResource32W( instance, name,
626 (LPWSTR)RT_BITMAP ))) return 0;
627 if (!(handle = LoadResource32( instance, hRsrc ))) return 0;
629 info = (BITMAPINFO *)LockResource32( handle );
630 if ((hdc = GetDC32(0)) != 0)
632 char *bits = (char *)info + DIB_BitmapInfoSize( info, DIB_RGB_COLORS );
633 hbitmap = CreateDIBitmap32( hdc, &info->bmiHeader, CBM_INIT,
634 bits, info, DIB_RGB_COLORS );
635 ReleaseDC32( 0, hdc );
637 return hbitmap;
641 /**********************************************************************
642 * LoadBitmap32A (USER32.356)
644 HBITMAP32 WINAPI LoadBitmap32A( HINSTANCE32 instance, LPCSTR name )
646 HBITMAP32 res;
647 if (!HIWORD(name)) res = LoadBitmap32W( instance, (LPWSTR)name );
648 else
650 LPWSTR uni = HEAP_strdupAtoW( GetProcessHeap(), 0, name );
651 res = LoadBitmap32W( instance, uni );
652 HeapFree( GetProcessHeap(), 0, uni );
654 return res;
658 /***********************************************************************
659 * BITMAP_DeleteObject
661 BOOL32 BITMAP_DeleteObject( HBITMAP16 hbitmap, BITMAPOBJ * bmp )
663 #ifdef PRELIMINARY_WING16_SUPPORT
664 if( bmp->bitmap.bmBits )
665 XShmDetach( display, (XShmSegmentInfo*)bmp->bitmap.bmBits );
666 #endif
668 XFreePixmap( display, bmp->pixmap );
669 #ifdef PRELIMINARY_WING16_SUPPORT
670 if( bmp->bitmap.bmBits )
672 __ShmBitmapCtl* p = (__ShmBitmapCtl*)bmp->bitmap.bmBits;
673 WORD sel = HIWORD(p->bits);
674 unsigned long l, limit = GetSelectorLimit(sel);
676 for( l = 0; l < limit; l += 0x10000, sel += __AHINCR )
677 FreeSelector(sel);
678 shmctl(p->si.shmid, IPC_RMID, NULL);
679 shmdt(p->si.shmaddr); /* already marked for destruction */
681 #endif
682 return GDI_FreeObject( hbitmap );
686 /***********************************************************************
687 * BITMAP_GetObject16
689 INT16 BITMAP_GetObject16( BITMAPOBJ * bmp, INT16 count, LPVOID buffer )
691 if (count > sizeof(bmp->bitmap)) count = sizeof(bmp->bitmap);
692 memcpy( buffer, &bmp->bitmap, count );
693 return count;
697 /***********************************************************************
698 * BITMAP_GetObject32
700 INT32 BITMAP_GetObject32( BITMAPOBJ * bmp, INT32 count, LPVOID buffer )
702 BITMAP32 bmp32;
703 bmp32.bmType = bmp->bitmap.bmType;
704 bmp32.bmWidth = bmp->bitmap.bmWidth;
705 bmp32.bmHeight = bmp->bitmap.bmHeight;
706 bmp32.bmWidthBytes = bmp->bitmap.bmWidthBytes;
707 bmp32.bmPlanes = bmp->bitmap.bmPlanes;
708 bmp32.bmBitsPixel = bmp->bitmap.bmBitsPixel;
709 bmp32.bmBits = NULL;
710 if (count > sizeof(bmp32)) count = sizeof(bmp32);
711 memcpy( buffer, &bmp32, count );
712 return count;
717 /***********************************************************************
718 * CreateDiscardableBitmap16 (GDI.156)
720 HBITMAP16 WINAPI CreateDiscardableBitmap16( HDC16 hdc, INT16 width,
721 INT16 height )
723 return CreateCompatibleBitmap16( hdc, width, height );
727 /***********************************************************************
728 * CreateDiscardableBitmap32 (GDI32.38)
730 HBITMAP32 WINAPI CreateDiscardableBitmap32( HDC32 hdc, INT32 width,
731 INT32 height )
733 return CreateCompatibleBitmap32( hdc, width, height );
737 /***********************************************************************
738 * GetBitmapDimensionEx16 (GDI.468)
740 BOOL16 WINAPI GetBitmapDimensionEx16( HBITMAP16 hbitmap, LPSIZE16 size )
742 BITMAPOBJ * bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC );
743 if (!bmp) return FALSE;
744 *size = bmp->size;
745 GDI_HEAP_UNLOCK( hbitmap );
746 return TRUE;
750 /***********************************************************************
751 * GetBitmapDimensionEx32 (GDI32.144)
753 BOOL32 WINAPI GetBitmapDimensionEx32( HBITMAP32 hbitmap, LPSIZE32 size )
755 BITMAPOBJ * bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC );
756 if (!bmp) return FALSE;
757 size->cx = (INT32)bmp->size.cx;
758 size->cy = (INT32)bmp->size.cy;
759 GDI_HEAP_UNLOCK( hbitmap );
760 return TRUE;
764 /***********************************************************************
765 * GetBitmapDimension (GDI.162)
767 DWORD WINAPI GetBitmapDimension( HBITMAP16 hbitmap )
769 SIZE16 size;
770 if (!GetBitmapDimensionEx16( hbitmap, &size )) return 0;
771 return MAKELONG( size.cx, size.cy );
775 /***********************************************************************
776 * SetBitmapDimensionEx16 (GDI.478)
778 BOOL16 WINAPI SetBitmapDimensionEx16( HBITMAP16 hbitmap, INT16 x, INT16 y,
779 LPSIZE16 prevSize )
781 BITMAPOBJ * bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC );
782 if (!bmp) return FALSE;
783 if (prevSize) *prevSize = bmp->size;
784 bmp->size.cx = x;
785 bmp->size.cy = y;
786 GDI_HEAP_UNLOCK( hbitmap );
787 return TRUE;
791 /***********************************************************************
792 * SetBitmapDimensionEx32 (GDI32.304)
794 BOOL32 WINAPI SetBitmapDimensionEx32( HBITMAP32 hbitmap, INT32 x, INT32 y,
795 LPSIZE32 prevSize )
797 BITMAPOBJ * bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC );
798 if (!bmp) return FALSE;
799 if (prevSize) CONV_SIZE16TO32( &bmp->size, prevSize );
800 bmp->size.cx = (INT16)x;
801 bmp->size.cy = (INT16)y;
802 GDI_HEAP_UNLOCK( hbitmap );
803 return TRUE;
807 /***********************************************************************
808 * SetBitmapDimension (GDI.163)
810 DWORD WINAPI SetBitmapDimension( HBITMAP16 hbitmap, INT16 x, INT16 y )
812 SIZE16 size;
813 if (!SetBitmapDimensionEx16( hbitmap, x, y, &size )) return 0;
814 return MAKELONG( size.cx, size.cy );