Release 970824
[wine/multimedia.git] / objects / bitmap.c
blob6fe7a98539b4cbaaa76efb22dfe91acb3c272c24
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 );
53 /***********************************************************************
54 * CreateBitmap16 (GDI.48)
56 HBITMAP16 WINAPI CreateBitmap16( INT16 width, INT16 height, UINT16 planes,
57 UINT16 bpp, LPCVOID bits )
59 return CreateBitmap32( width, height, planes, bpp, bits );
63 /***********************************************************************
64 * CreateBitmap32 (GDI32.25)
66 HBITMAP32 WINAPI CreateBitmap32( INT32 width, INT32 height, UINT32 planes,
67 UINT32 bpp, LPCVOID bits )
69 BITMAPOBJ * bmpObjPtr;
70 HBITMAP32 hbitmap;
72 planes = (BYTE)planes;
73 bpp = (BYTE)bpp;
75 dprintf_gdi( stddeb, "CreateBitmap: %dx%d, %d colors\n",
76 width, height, 1 << (planes*bpp) );
78 /* Check parameters */
79 if (!height || !width || planes != 1) return 0;
80 if ((bpp != 1) && (bpp != screenDepth)) return 0;
81 if (height < 0) height = -height;
82 if (width < 0) width = -width;
84 /* Create the BITMAPOBJ */
85 hbitmap = GDI_AllocObject( sizeof(BITMAPOBJ), BITMAP_MAGIC );
86 if (!hbitmap) return 0;
87 bmpObjPtr = (BITMAPOBJ *) GDI_HEAP_LOCK( hbitmap );
89 bmpObjPtr->size.cx = 0;
90 bmpObjPtr->size.cy = 0;
91 bmpObjPtr->bitmap.bmType = 0;
92 bmpObjPtr->bitmap.bmWidth = (INT16)width;
93 bmpObjPtr->bitmap.bmHeight = (INT16)height;
94 bmpObjPtr->bitmap.bmPlanes = (BYTE)planes;
95 bmpObjPtr->bitmap.bmBitsPixel = (BYTE)bpp;
96 bmpObjPtr->bitmap.bmWidthBytes = (INT16)BITMAP_WIDTH_BYTES( width, bpp );
97 bmpObjPtr->bitmap.bmBits = NULL;
99 /* Create the pixmap */
100 bmpObjPtr->pixmap = XCreatePixmap(display, rootWindow, width, height, bpp);
101 if (!bmpObjPtr->pixmap)
103 GDI_HEAP_FREE( hbitmap );
104 hbitmap = 0;
106 else if (bits) /* Set bitmap bits */
107 SetBitmapBits32( hbitmap, height * bmpObjPtr->bitmap.bmWidthBytes,
108 bits );
109 GDI_HEAP_UNLOCK( hbitmap );
110 return hbitmap;
114 /***********************************************************************
115 * CreateCompatibleBitmap16 (GDI.51)
117 HBITMAP16 WINAPI CreateCompatibleBitmap16(HDC16 hdc, INT16 width, INT16 height)
119 return CreateCompatibleBitmap32( hdc, width, height );
123 /***********************************************************************
124 * CreateCompatibleBitmap32 (GDI32.30)
126 HBITMAP32 WINAPI CreateCompatibleBitmap32(HDC32 hdc, INT32 width, INT32 height)
128 HBITMAP32 hbmpRet = 0;
129 DC *dc;
131 dprintf_gdi( stddeb, "CreateCompatibleBitmap(%04x,%d,%d) = \n",
132 hdc, width, height );
133 if (!(dc = DC_GetDCPtr( hdc ))) return 0;
134 hbmpRet = CreateBitmap32( width, height, 1, dc->w.bitsPerPixel, NULL );
135 dprintf_gdi(stddeb,"\t\t%04x\n", hbmpRet);
136 return hbmpRet;
140 /***********************************************************************
141 * CreateBitmapIndirect16 (GDI.49)
143 HBITMAP16 WINAPI CreateBitmapIndirect16( const BITMAP16 * bmp )
145 return CreateBitmap16( bmp->bmWidth, bmp->bmHeight, bmp->bmPlanes,
146 bmp->bmBitsPixel, PTR_SEG_TO_LIN( bmp->bmBits ) );
150 /***********************************************************************
151 * CreateBitmapIndirect32 (GDI32.26)
153 HBITMAP32 WINAPI CreateBitmapIndirect32( const BITMAP32 * bmp )
155 return CreateBitmap32( bmp->bmWidth, bmp->bmHeight, bmp->bmPlanes,
156 bmp->bmBitsPixel, bmp->bmBits );
160 /***********************************************************************
161 * BITMAP_GetXImage
163 * Get an X image for a bitmap. For use with CALL_LARGE_STACK.
165 XImage *BITMAP_GetXImage( const BITMAPOBJ *bmp )
167 return XGetImage( display, bmp->pixmap, 0, 0, bmp->bitmap.bmWidth,
168 bmp->bitmap.bmHeight, AllPlanes, ZPixmap );
172 /***********************************************************************
173 * GetBitmapBits16 (GDI.74)
175 LONG WINAPI GetBitmapBits16( HBITMAP16 hbitmap, LONG count, LPVOID buffer )
177 return GetBitmapBits32( hbitmap, count, buffer );
181 /***********************************************************************
182 * GetBitmapBits32 (GDI32.143)
184 LONG WINAPI GetBitmapBits32( HBITMAP32 hbitmap, LONG count, LPVOID buffer )
186 BITMAPOBJ * bmp;
187 LONG height, old_height;
188 XImage * image;
189 LPBYTE tbuf;
190 int h,w,pad;
192 /* KLUDGE! */
193 if (count < 0) {
194 fprintf(stderr, "Negative number of bytes (%ld) passed to GetBitmapBits???\n", count );
195 count = -count;
197 bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC );
198 if (!bmp) return 0;
200 /* Only get entire lines */
201 height = count / bmp->bitmap.bmWidthBytes;
202 if (height > bmp->bitmap.bmHeight) height = bmp->bitmap.bmHeight;
203 dprintf_bitmap(stddeb, "GetBitmapBits: %dx%d %d colors %p fetched height: %ld\n",
204 bmp->bitmap.bmWidth, bmp->bitmap.bmHeight,
205 1 << bmp->bitmap.bmBitsPixel, buffer, height );
206 if (!height)
208 GDI_HEAP_UNLOCK( hbitmap );
209 return 0;
212 switch (bmp->bitmap.bmBitsPixel) {
213 case 1:
214 if (!(bmp->bitmap.bmWidth & 15))
215 pad = 0;
216 else
217 pad = ((16 - (bmp->bitmap.bmWidth & 15)) + 7) / 8;
218 break;
219 case 4:
220 if (!(bmp->bitmap.bmWidth & 3))
221 pad = 0;
222 else
223 pad = ((4 - (bmp->bitmap.bmWidth & 3)) + 1) / 2;
224 break;
225 case 8:
226 pad = (2 - (bmp->bitmap.bmWidth & 1)) & 1;
227 break;
228 case 15:
229 case 16:
230 pad = 0; /* we have 16bit alignment already */
231 break;
232 case 24:
233 pad = (bmp->bitmap.bmWidth*3) & 1;
234 break;
235 default:
236 fprintf(stderr,"GetBitMapBits32: unknown depth %d, please report.\n",
237 bmp->bitmap.bmBitsPixel
239 GDI_HEAP_UNLOCK( hbitmap );
240 return 0;
243 /* Hack: change the bitmap height temporarily to avoid */
244 /* getting unnecessary bitmap rows. */
245 old_height = bmp->bitmap.bmHeight;
246 bmp->bitmap.bmHeight = height;
247 image = (XImage *)CALL_LARGE_STACK( BITMAP_GetXImage, bmp );
248 bmp->bitmap.bmHeight = old_height;
250 /* copy XImage to 16 bit padded image buffer with real bitsperpixel */
252 tbuf = buffer;
253 switch (bmp->bitmap.bmBitsPixel)
255 case 1:
256 for (h=0;h<height;h++)
258 *tbuf = 0;
259 for (w=0;w<bmp->bitmap.bmWidth;w++)
261 if ((w%8) == 0)
262 *tbuf = 0;
263 *tbuf |= XGetPixel(image,w,h)<<(7-(w&7));
264 if ((w&7) == 7) ++tbuf;
266 tbuf += pad;
268 break;
269 case 4:
270 for (h=0;h<height;h++)
272 for (w=0;w<bmp->bitmap.bmWidth;w++)
274 if (!(w & 1)) *tbuf = XGetPixel( image, w, h) << 4;
275 else *tbuf++ |= XGetPixel( image, w, h) & 0x0f;
277 tbuf += pad;
279 break;
280 case 8:
281 for (h=0;h<height;h++)
283 for (w=0;w<bmp->bitmap.bmWidth;w++)
284 *tbuf++ = XGetPixel(image,w,h);
285 tbuf += pad;
287 break;
288 case 15:
289 case 16:
290 for (h=0;h<height;h++)
292 for (w=0;w<bmp->bitmap.bmWidth;w++)
294 long pixel = XGetPixel(image,w,h);
296 *tbuf++ = pixel & 0xff;
297 *tbuf++ = (pixel>>8) & 0xff;
300 break;
301 case 24:
302 for (h=0;h<height;h++)
304 for (w=0;w<bmp->bitmap.bmWidth;w++)
306 long pixel = XGetPixel(image,w,h);
308 *tbuf++ = pixel & 0xff;
309 *tbuf++ = (pixel>> 8) & 0xff;
310 *tbuf++ = (pixel>>16) & 0xff;
312 tbuf += pad;
315 XDestroyImage( image );
316 GDI_HEAP_UNLOCK( hbitmap );
317 return height * bmp->bitmap.bmWidthBytes;
321 /***********************************************************************
322 * SetBitmapBits16 (GDI.106)
324 LONG WINAPI SetBitmapBits16( HBITMAP16 hbitmap, LONG count, LPCVOID buffer )
326 return SetBitmapBits32( hbitmap, count, buffer );
330 /***********************************************************************
331 * SetBitmapBits32 (GDI32.303)
333 LONG WINAPI SetBitmapBits32( HBITMAP32 hbitmap, LONG count, LPCVOID buffer )
335 struct XPutImage_descr descr;
336 BITMAPOBJ * bmp;
337 LONG height;
338 XImage * image;
339 LPBYTE sbuf,tmpbuffer;
340 int w,h,pad,widthbytes;
342 /* KLUDGE! */
343 if (count < 0) {
344 fprintf(stderr, "Negative number of bytes (%ld) passed to SetBitmapBits???\n", count );
345 count = -count;
347 bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC );
348 if (!bmp) return 0;
350 dprintf_bitmap(stddeb, "SetBitmapBits: %dx%d %d colors %p\n",
351 bmp->bitmap.bmWidth, bmp->bitmap.bmHeight,
352 1 << bmp->bitmap.bmBitsPixel, buffer );
354 /* Only set entire lines */
355 height = count / bmp->bitmap.bmWidthBytes;
356 if (height > bmp->bitmap.bmHeight) height = bmp->bitmap.bmHeight;
357 if (!height)
359 GDI_HEAP_UNLOCK( hbitmap );
360 return 0;
363 switch (bmp->bitmap.bmBitsPixel) {
364 case 1:
365 if (!(bmp->bitmap.bmWidth & 15))
366 pad = 0;
367 else
368 pad = ((16 - (bmp->bitmap.bmWidth & 15)) + 7) / 8;
369 break;
370 case 4:
371 if (!(bmp->bitmap.bmWidth & 3))
372 pad = 0;
373 else
374 pad = ((4 - (bmp->bitmap.bmWidth & 3)) + 1) / 2;
375 break;
376 case 8:
377 pad = (2 - (bmp->bitmap.bmWidth & 1)) & 1;
378 break;
379 case 15:
380 case 16:
381 pad = 0; /* we have 16bit alignment already */
382 break;
383 case 24:
384 pad = (bmp->bitmap.bmWidth*3) & 1;
385 break;
386 default:
387 fprintf(stderr,"SetBitMapBits32: unknown depth %d, please report.\n",
388 bmp->bitmap.bmBitsPixel
390 return 0;
392 sbuf = (LPBYTE)buffer;
394 widthbytes = DIB_GetXImageWidthBytes(bmp->bitmap.bmWidth,bmp->bitmap.bmBitsPixel);
395 tmpbuffer = (LPBYTE)xmalloc(widthbytes*height);
396 image = XCreateImage( display, DefaultVisualOfScreen(screen),
397 bmp->bitmap.bmBitsPixel, ZPixmap, 0, tmpbuffer,
398 bmp->bitmap.bmWidth,height,32,widthbytes
401 /* copy 16 bit padded image buffer with real bitsperpixel to XImage */
402 sbuf = (LPBYTE)buffer;
403 switch (bmp->bitmap.bmBitsPixel)
405 case 1:
406 for (h=0;h<height;h++)
408 for (w=0;w<bmp->bitmap.bmWidth;w++)
410 XPutPixel(image,w,h,(sbuf[0]>>(7-(w&7))) & 1);
411 if ((w&7) == 7)
412 sbuf++;
414 sbuf += pad;
416 break;
417 case 4:
418 for (h=0;h<height;h++)
420 for (w=0;w<bmp->bitmap.bmWidth;w++)
422 if (!(w & 1)) XPutPixel( image, w, h, *sbuf >> 4 );
423 else XPutPixel( image, w, h, *sbuf++ & 0xf );
425 sbuf += pad;
427 break;
428 case 8:
429 for (h=0;h<height;h++)
431 for (w=0;w<bmp->bitmap.bmWidth;w++)
432 XPutPixel(image,w,h,*sbuf++);
433 sbuf += pad;
435 break;
436 case 15:
437 case 16:
438 for (h=0;h<height;h++)
440 for (w=0;w<bmp->bitmap.bmWidth;w++)
442 XPutPixel(image,w,h,sbuf[1]*256+sbuf[0]);
443 sbuf+=2;
446 break;
447 case 24:
448 for (h=0;h<height;h++)
450 for (w=0;w<bmp->bitmap.bmWidth;w++)
452 XPutPixel(image,w,h,(sbuf[2]<<16)+(sbuf[1]<<8)+sbuf[0]);
453 sbuf += 3;
455 sbuf += pad;
457 break;
460 descr.bmp = bmp;
461 descr.image = image;
462 descr.width = bmp->bitmap.bmWidth;
463 descr.height = height;
464 CALL_LARGE_STACK( XPutImage_wrapper, &descr );
466 XDestroyImage( image ); /* frees tmpbuffer too */
467 GDI_HEAP_UNLOCK( hbitmap );
468 return height * bmp->bitmap.bmWidthBytes;
471 /**********************************************************************
472 * LoadImageA (USER32.364)
473 * FIXME: implementation still lacks nearly all features, see LR_*
474 * defines in windows.h
477 HANDLE32 WINAPI LoadImage32A( HINSTANCE32 hinst, LPCSTR name, UINT32 type,
478 INT32 desiredx, INT32 desiredy, UINT32 loadflags)
480 if (HIWORD(name)) {
481 dprintf_resource(stddeb,"LoadImage32A(0x%04x,%s,%d,%d,%d,0x%08x)\n",
482 hinst,name,type,desiredx,desiredy,loadflags
484 } else {
485 dprintf_resource(stddeb,"LoadImage32A(0x%04x,%p,%d,%d,%d,0x%08x)\n",
486 hinst,name,type,desiredx,desiredy,loadflags
489 switch (type) {
490 case IMAGE_BITMAP:
491 return LoadBitmap32A(hinst,name);
492 case IMAGE_ICON:
493 return LoadIcon32A(hinst,name);
494 case IMAGE_CURSOR:
495 return LoadCursor32A(hinst,name);
497 return 0;
500 /**********************************************************************
501 * CopyImage32 (USER32.60)
503 * FIXME: implementation still lacks nearly all features, see LR_*
504 * defines in windows.h
506 HANDLE32 WINAPI CopyImage32( HANDLE32 hnd, UINT32 type, INT32 desiredx,
507 INT32 desiredy, UINT32 flags )
509 switch (type)
511 case IMAGE_BITMAP:
512 return hnd; /* FIXME ... need to copy here */
513 case IMAGE_ICON:
514 return CopyIcon32(hnd);
515 case IMAGE_CURSOR:
516 return CopyCursor32(hnd);
518 return 0;
522 /**********************************************************************
523 * LoadBitmap16 (USER.175)
525 HBITMAP16 WINAPI LoadBitmap16( HINSTANCE16 instance, SEGPTR name )
527 HBITMAP32 hbitmap = 0;
528 HDC32 hdc;
529 HRSRC16 hRsrc;
530 HGLOBAL16 handle;
531 BITMAPINFO *info;
533 if (HIWORD(name))
535 char *str = (char *)PTR_SEG_TO_LIN( name );
536 dprintf_bitmap( stddeb, "LoadBitmap16(%04x,'%s')\n", instance, str );
537 if (str[0] == '#') name = (SEGPTR)(DWORD)(WORD)atoi( str + 1 );
539 else
540 dprintf_bitmap( stddeb, "LoadBitmap16(%04x,%04x)\n",
541 instance, LOWORD(name) );
543 if (!instance) /* OEM bitmap */
545 if (HIWORD((int)name)) return 0;
546 return OBM_LoadBitmap( LOWORD((int)name) );
549 if (!(hRsrc = FindResource16( instance, name, RT_BITMAP ))) return 0;
550 if (!(handle = LoadResource16( instance, hRsrc ))) return 0;
552 info = (BITMAPINFO *)LockResource16( handle );
553 if ((hdc = GetDC32(0)) != 0)
555 char *bits = (char *)info + DIB_BitmapInfoSize( info, DIB_RGB_COLORS );
556 hbitmap = CreateDIBitmap32( hdc, &info->bmiHeader, CBM_INIT,
557 bits, info, DIB_RGB_COLORS );
558 ReleaseDC32( 0, hdc );
560 FreeResource16( handle );
561 return hbitmap;
564 /**********************************************************************
565 * LoadBitmap32W (USER32.357)
567 HBITMAP32 WINAPI LoadBitmap32W( HINSTANCE32 instance, LPCWSTR name )
569 HBITMAP32 hbitmap = 0;
570 HDC32 hdc;
571 HRSRC32 hRsrc;
572 HGLOBAL32 handle;
573 BITMAPINFO *info;
575 if (!instance) /* OEM bitmap */
577 if (HIWORD((int)name)) return 0;
578 return OBM_LoadBitmap( LOWORD((int)name) );
581 if (!(hRsrc = FindResource32W( instance, name,
582 (LPWSTR)RT_BITMAP ))) return 0;
583 if (!(handle = LoadResource32( instance, hRsrc ))) return 0;
585 info = (BITMAPINFO *)LockResource32( handle );
586 if ((hdc = GetDC32(0)) != 0)
588 char *bits = (char *)info + DIB_BitmapInfoSize( info, DIB_RGB_COLORS );
589 hbitmap = CreateDIBitmap32( hdc, &info->bmiHeader, CBM_INIT,
590 bits, info, DIB_RGB_COLORS );
591 ReleaseDC32( 0, hdc );
593 return hbitmap;
597 /**********************************************************************
598 * LoadBitmap32A (USER32.356)
600 HBITMAP32 WINAPI LoadBitmap32A( HINSTANCE32 instance, LPCSTR name )
602 HBITMAP32 res;
603 if (!HIWORD(name)) res = LoadBitmap32W( instance, (LPWSTR)name );
604 else
606 LPWSTR uni = HEAP_strdupAtoW( GetProcessHeap(), 0, name );
607 res = LoadBitmap32W( instance, uni );
608 HeapFree( GetProcessHeap(), 0, uni );
610 return res;
614 /***********************************************************************
615 * BITMAP_DeleteObject
617 BOOL32 BITMAP_DeleteObject( HBITMAP16 hbitmap, BITMAPOBJ * bmp )
619 #ifdef PRELIMINARY_WING16_SUPPORT
620 if( bmp->bitmap.bmBits )
621 XShmDetach( display, (XShmSegmentInfo*)bmp->bitmap.bmBits );
622 #endif
624 XFreePixmap( display, bmp->pixmap );
625 #ifdef PRELIMINARY_WING16_SUPPORT
626 if( bmp->bitmap.bmBits )
628 __ShmBitmapCtl* p = (__ShmBitmapCtl*)bmp->bitmap.bmBits;
629 WORD sel = HIWORD(p->bits);
630 unsigned long l, limit = GetSelectorLimit(sel);
632 for( l = 0; l < limit; l += 0x10000, sel += __AHINCR )
633 FreeSelector(sel);
634 shmctl(p->si.shmid, IPC_RMID, NULL);
635 shmdt(p->si.shmaddr); /* already marked for destruction */
637 #endif
638 return GDI_FreeObject( hbitmap );
642 /***********************************************************************
643 * BITMAP_GetObject16
645 INT16 BITMAP_GetObject16( BITMAPOBJ * bmp, INT16 count, LPVOID buffer )
647 if (count > sizeof(bmp->bitmap)) count = sizeof(bmp->bitmap);
648 memcpy( buffer, &bmp->bitmap, count );
649 return count;
653 /***********************************************************************
654 * BITMAP_GetObject32
656 INT32 BITMAP_GetObject32( BITMAPOBJ * bmp, INT32 count, LPVOID buffer )
658 BITMAP32 bmp32;
659 bmp32.bmType = bmp->bitmap.bmType;
660 bmp32.bmWidth = bmp->bitmap.bmWidth;
661 bmp32.bmHeight = bmp->bitmap.bmHeight;
662 bmp32.bmWidthBytes = bmp->bitmap.bmWidthBytes;
663 bmp32.bmPlanes = bmp->bitmap.bmPlanes;
664 bmp32.bmBitsPixel = bmp->bitmap.bmBitsPixel;
665 bmp32.bmBits = NULL;
666 if (count > sizeof(bmp32)) count = sizeof(bmp32);
667 memcpy( buffer, &bmp32, count );
668 return count;
673 /***********************************************************************
674 * CreateDiscardableBitmap16 (GDI.156)
676 HBITMAP16 WINAPI CreateDiscardableBitmap16( HDC16 hdc, INT16 width,
677 INT16 height )
679 return CreateCompatibleBitmap16( hdc, width, height );
683 /***********************************************************************
684 * CreateDiscardableBitmap32 (GDI32.38)
686 HBITMAP32 WINAPI CreateDiscardableBitmap32( HDC32 hdc, INT32 width,
687 INT32 height )
689 return CreateCompatibleBitmap32( hdc, width, height );
693 /***********************************************************************
694 * GetBitmapDimensionEx16 (GDI.468)
696 BOOL16 WINAPI GetBitmapDimensionEx16( HBITMAP16 hbitmap, LPSIZE16 size )
698 BITMAPOBJ * bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC );
699 if (!bmp) return FALSE;
700 *size = bmp->size;
701 GDI_HEAP_UNLOCK( hbitmap );
702 return TRUE;
706 /***********************************************************************
707 * GetBitmapDimensionEx32 (GDI32.144)
709 BOOL32 WINAPI GetBitmapDimensionEx32( HBITMAP32 hbitmap, LPSIZE32 size )
711 BITMAPOBJ * bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC );
712 if (!bmp) return FALSE;
713 size->cx = (INT32)bmp->size.cx;
714 size->cy = (INT32)bmp->size.cy;
715 GDI_HEAP_UNLOCK( hbitmap );
716 return TRUE;
720 /***********************************************************************
721 * GetBitmapDimension (GDI.162)
723 DWORD WINAPI GetBitmapDimension( HBITMAP16 hbitmap )
725 SIZE16 size;
726 if (!GetBitmapDimensionEx16( hbitmap, &size )) return 0;
727 return MAKELONG( size.cx, size.cy );
731 /***********************************************************************
732 * SetBitmapDimensionEx16 (GDI.478)
734 BOOL16 WINAPI SetBitmapDimensionEx16( HBITMAP16 hbitmap, INT16 x, INT16 y,
735 LPSIZE16 prevSize )
737 BITMAPOBJ * bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC );
738 if (!bmp) return FALSE;
739 if (prevSize) *prevSize = bmp->size;
740 bmp->size.cx = x;
741 bmp->size.cy = y;
742 GDI_HEAP_UNLOCK( hbitmap );
743 return TRUE;
747 /***********************************************************************
748 * SetBitmapDimensionEx32 (GDI32.304)
750 BOOL32 WINAPI SetBitmapDimensionEx32( HBITMAP32 hbitmap, INT32 x, INT32 y,
751 LPSIZE32 prevSize )
753 BITMAPOBJ * bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC );
754 if (!bmp) return FALSE;
755 if (prevSize) CONV_SIZE16TO32( &bmp->size, prevSize );
756 bmp->size.cx = (INT16)x;
757 bmp->size.cy = (INT16)y;
758 GDI_HEAP_UNLOCK( hbitmap );
759 return TRUE;
763 /***********************************************************************
764 * SetBitmapDimension (GDI.163)
766 DWORD WINAPI SetBitmapDimension( HBITMAP16 hbitmap, INT16 x, INT16 y )
768 SIZE16 size;
769 if (!SetBitmapDimensionEx16( hbitmap, x, y, &size )) return 0;
770 return MAKELONG( size.cx, size.cy );