Release 980215
[wine/multimedia.git] / objects / bitmap.c
blob7d8a36d923b65c4e1039708c22c5d898839ea580
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 "ts_xlib.h"
11 #include "ts_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 /***********************************************************************
30 * XPutImage_wrapper
32 * Wrapper to call XPutImage with CALL_LARGE_STACK.
35 struct XPutImage_descr
37 BITMAPOBJ *bmp;
38 XImage *image;
39 INT32 width;
40 INT32 height;
43 static int XPutImage_wrapper( const struct XPutImage_descr *descr )
45 return XPutImage( display, descr->bmp->pixmap, BITMAP_GC(descr->bmp),
46 descr->image, 0, 0, 0, 0, descr->width, descr->height );
49 /***********************************************************************
50 * BITMAP_GetBitsPadding
52 * Return number of bytes to pad a scanline of 16-bit aligned Windows DDB data.
54 INT32 BITMAP_GetBitsPadding( int bmWidth, int bpp )
56 INT32 pad;
58 switch (bpp)
60 case 1:
61 if (!(bmWidth & 15)) pad = 0;
62 else pad = ((16 - (bmWidth & 15)) + 7) / 8;
63 break;
65 case 8:
66 pad = (2 - (bmWidth & 1)) & 1;
67 break;
69 case 24:
70 pad = (bmWidth*3) & 1;
71 break;
73 case 32:
74 case 16:
75 case 15:
76 pad = 0; /* we have 16bit alignment already */
77 break;
79 case 4:
80 if (!(bmWidth & 3)) pad = 0;
81 else pad = ((4 - (bmWidth & 3)) + 1) / 2;
82 break;
84 default:
85 fprintf(stderr,"GetBitsPadding: unknown depth %d, please report.\n", bpp );
86 return -1;
88 return pad;
91 /***********************************************************************
92 * BITMAP_GetBitsWidth
94 * Return number of bytes taken by a scanline of 16-bit aligned Windows DDB data.
96 INT32 BITMAP_GetBitsWidth( int bmWidth, int bpp )
98 switch(bpp)
100 case 1:
101 return 2 * ((bmWidth+15) >> 4);
103 case 24:
104 bmWidth *= 3; /* fall through */
105 case 8:
106 return bmWidth + (bmWidth & 1);
108 case 32:
109 return bmWidth * 4;
111 case 16:
112 case 15:
113 return bmWidth * 2;
115 case 4:
116 return 2 * ((bmWidth+3) >> 2);
118 default:
119 fprintf(stderr,"GetBitsPadding: unknown depth %d, please report.\n", bpp );
121 return -1;
124 /***********************************************************************
125 * CreateBitmap16 (GDI.48)
127 HBITMAP16 WINAPI CreateBitmap16( INT16 width, INT16 height, UINT16 planes,
128 UINT16 bpp, LPCVOID bits )
130 return CreateBitmap32( width, height, planes, bpp, bits );
134 /***********************************************************************
135 * CreateBitmap32 (GDI32.25)
137 HBITMAP32 WINAPI CreateBitmap32( INT32 width, INT32 height, UINT32 planes,
138 UINT32 bpp, LPCVOID bits )
140 BITMAPOBJ * bmpObjPtr;
141 HBITMAP32 hbitmap;
143 planes = (BYTE)planes;
144 bpp = (BYTE)bpp;
146 dprintf_gdi( stddeb, "CreateBitmap: %dx%d, %d colors\n",
147 width, height, 1 << (planes*bpp) );
149 /* Check parameters */
150 if (!height || !width || planes != 1) return 0;
151 if ((bpp != 1) && (bpp != screenDepth)) return 0;
152 if (height < 0) height = -height;
153 if (width < 0) width = -width;
155 /* Create the BITMAPOBJ */
156 hbitmap = GDI_AllocObject( sizeof(BITMAPOBJ), BITMAP_MAGIC );
157 if (!hbitmap) return 0;
158 bmpObjPtr = (BITMAPOBJ *) GDI_HEAP_LOCK( hbitmap );
160 bmpObjPtr->size.cx = 0;
161 bmpObjPtr->size.cy = 0;
162 bmpObjPtr->bitmap.bmType = 0;
163 bmpObjPtr->bitmap.bmWidth = (INT16)width;
164 bmpObjPtr->bitmap.bmHeight = (INT16)height;
165 bmpObjPtr->bitmap.bmPlanes = (BYTE)planes;
166 bmpObjPtr->bitmap.bmBitsPixel = (BYTE)bpp;
167 bmpObjPtr->bitmap.bmWidthBytes = (INT16)BITMAP_WIDTH_BYTES( width, bpp );
168 bmpObjPtr->bitmap.bmBits = NULL;
170 /* Create the pixmap */
171 bmpObjPtr->pixmap = TSXCreatePixmap(display, rootWindow, width, height, bpp);
172 if (!bmpObjPtr->pixmap)
174 GDI_HEAP_FREE( hbitmap );
175 hbitmap = 0;
177 else if (bits) /* Set bitmap bits */
178 SetBitmapBits32( hbitmap, height * bmpObjPtr->bitmap.bmWidthBytes,
179 bits );
180 GDI_HEAP_UNLOCK( hbitmap );
181 return hbitmap;
185 /***********************************************************************
186 * CreateCompatibleBitmap16 (GDI.51)
188 HBITMAP16 WINAPI CreateCompatibleBitmap16(HDC16 hdc, INT16 width, INT16 height)
190 return CreateCompatibleBitmap32( hdc, width, height );
194 /***********************************************************************
195 * CreateCompatibleBitmap32 (GDI32.30)
197 HBITMAP32 WINAPI CreateCompatibleBitmap32(HDC32 hdc, INT32 width, INT32 height)
199 HBITMAP32 hbmpRet = 0;
200 DC *dc;
202 dprintf_gdi( stddeb, "CreateCompatibleBitmap(%04x,%d,%d) = \n",
203 hdc, width, height );
204 if (!(dc = DC_GetDCPtr( hdc ))) return 0;
205 hbmpRet = CreateBitmap32( width, height, 1, dc->w.bitsPerPixel, NULL );
206 dprintf_gdi(stddeb,"\t\t%04x\n", hbmpRet);
207 return hbmpRet;
211 /***********************************************************************
212 * CreateBitmapIndirect16 (GDI.49)
214 HBITMAP16 WINAPI CreateBitmapIndirect16( const BITMAP16 * bmp )
216 return CreateBitmap16( bmp->bmWidth, bmp->bmHeight, bmp->bmPlanes,
217 bmp->bmBitsPixel, PTR_SEG_TO_LIN( bmp->bmBits ) );
221 /***********************************************************************
222 * CreateBitmapIndirect32 (GDI32.26)
224 HBITMAP32 WINAPI CreateBitmapIndirect32( const BITMAP32 * bmp )
226 return CreateBitmap32( bmp->bmWidth, bmp->bmHeight, bmp->bmPlanes,
227 bmp->bmBitsPixel, bmp->bmBits );
231 /***********************************************************************
232 * BITMAP_GetXImage
234 * Get an X image for a bitmap. For use with CALL_LARGE_STACK.
236 XImage *BITMAP_GetXImage( const BITMAPOBJ *bmp )
238 return XGetImage( display, bmp->pixmap, 0, 0, bmp->bitmap.bmWidth,
239 bmp->bitmap.bmHeight, AllPlanes, ZPixmap );
243 /***********************************************************************
244 * GetBitmapBits16 (GDI.74)
246 LONG WINAPI GetBitmapBits16( HBITMAP16 hbitmap, LONG count, LPVOID buffer )
248 return GetBitmapBits32( hbitmap, count, buffer );
252 /***********************************************************************
253 * GetBitmapBits32 (GDI32.143)
255 LONG WINAPI GetBitmapBits32( HBITMAP32 hbitmap, LONG count, LPVOID buffer )
257 BITMAPOBJ * bmp;
258 LONG height, old_height;
259 XImage * image;
260 LPBYTE tbuf;
261 int h,w,pad;
263 /* KLUDGE! */
264 if (count < 0) {
265 fprintf(stderr, "Negative number of bytes (%ld) passed to GetBitmapBits???\n", count );
266 count = -count;
268 bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC );
269 if (!bmp) return 0;
271 /* Only get entire lines */
272 height = count / bmp->bitmap.bmWidthBytes;
273 if (height > bmp->bitmap.bmHeight) height = bmp->bitmap.bmHeight;
275 dprintf_bitmap(stddeb, "GetBitmapBits: %dx%d %d colors %p fetched height: %ld\n",
276 bmp->bitmap.bmWidth, bmp->bitmap.bmHeight,
277 1 << bmp->bitmap.bmBitsPixel, buffer, height );
279 pad = BITMAP_GetBitsPadding( bmp->bitmap.bmWidth, bmp->bitmap.bmBitsPixel );
281 if (!height || (pad == -1))
283 GDI_HEAP_UNLOCK( hbitmap );
284 return 0;
287 EnterCriticalSection( &X11DRV_CritSection );
289 /* Hack: change the bitmap height temporarily to avoid */
290 /* getting unnecessary bitmap rows. */
291 old_height = bmp->bitmap.bmHeight;
292 bmp->bitmap.bmHeight = height;
293 image = (XImage *)CALL_LARGE_STACK( BITMAP_GetXImage, bmp );
294 bmp->bitmap.bmHeight = old_height;
296 /* copy XImage to 16 bit padded image buffer with real bitsperpixel */
298 tbuf = buffer;
299 switch (bmp->bitmap.bmBitsPixel)
301 case 1:
302 for (h=0;h<height;h++)
304 *tbuf = 0;
305 for (w=0;w<bmp->bitmap.bmWidth;w++)
307 if ((w%8) == 0)
308 *tbuf = 0;
309 *tbuf |= XGetPixel(image,w,h)<<(7-(w&7));
310 if ((w&7) == 7) ++tbuf;
312 tbuf += pad;
314 break;
315 case 4:
316 for (h=0;h<height;h++)
318 for (w=0;w<bmp->bitmap.bmWidth;w++)
320 if (!(w & 1)) *tbuf = XGetPixel( image, w, h) << 4;
321 else *tbuf++ |= XGetPixel( image, w, h) & 0x0f;
323 tbuf += pad;
325 break;
326 case 8:
327 for (h=0;h<height;h++)
329 for (w=0;w<bmp->bitmap.bmWidth;w++)
330 *tbuf++ = XGetPixel(image,w,h);
331 tbuf += pad;
333 break;
334 case 15:
335 case 16:
336 for (h=0;h<height;h++)
338 for (w=0;w<bmp->bitmap.bmWidth;w++)
340 long pixel = XGetPixel(image,w,h);
342 *tbuf++ = pixel & 0xff;
343 *tbuf++ = (pixel>>8) & 0xff;
346 break;
347 case 24:
348 for (h=0;h<height;h++)
350 for (w=0;w<bmp->bitmap.bmWidth;w++)
352 long pixel = XGetPixel(image,w,h);
354 *tbuf++ = pixel & 0xff;
355 *tbuf++ = (pixel>> 8) & 0xff;
356 *tbuf++ = (pixel>>16) & 0xff;
358 tbuf += pad;
361 XDestroyImage( image );
362 LeaveCriticalSection( &X11DRV_CritSection );
364 GDI_HEAP_UNLOCK( hbitmap );
365 return height * bmp->bitmap.bmWidthBytes;
369 /***********************************************************************
370 * SetBitmapBits16 (GDI.106)
372 LONG WINAPI SetBitmapBits16( HBITMAP16 hbitmap, LONG count, LPCVOID buffer )
374 return SetBitmapBits32( hbitmap, count, buffer );
378 /***********************************************************************
379 * SetBitmapBits32 (GDI32.303)
381 LONG WINAPI SetBitmapBits32( HBITMAP32 hbitmap, LONG count, LPCVOID buffer )
383 struct XPutImage_descr descr;
384 BITMAPOBJ * bmp;
385 LONG height;
386 XImage * image;
387 LPBYTE sbuf,tmpbuffer;
388 int w,h,pad,widthbytes;
390 /* KLUDGE! */
391 if (count < 0) {
392 fprintf(stderr, "Negative number of bytes (%ld) passed to SetBitmapBits???\n", count );
393 count = -count;
395 bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC );
396 if (!bmp) return 0;
398 dprintf_bitmap(stddeb, "SetBitmapBits: %dx%d %d colors %p\n",
399 bmp->bitmap.bmWidth, bmp->bitmap.bmHeight,
400 1 << bmp->bitmap.bmBitsPixel, buffer );
402 /* Only set entire lines */
403 height = count / bmp->bitmap.bmWidthBytes;
404 if (height > bmp->bitmap.bmHeight) height = bmp->bitmap.bmHeight;
406 pad = BITMAP_GetBitsPadding( bmp->bitmap.bmWidth, bmp->bitmap.bmBitsPixel );
408 if (!height || (pad == -1))
410 GDI_HEAP_UNLOCK( hbitmap );
411 return 0;
414 sbuf = (LPBYTE)buffer;
416 widthbytes = DIB_GetXImageWidthBytes(bmp->bitmap.bmWidth,bmp->bitmap.bmBitsPixel);
417 tmpbuffer = (LPBYTE)xmalloc(widthbytes*height);
419 EnterCriticalSection( &X11DRV_CritSection );
420 image = XCreateImage( display, DefaultVisualOfScreen(screen),
421 bmp->bitmap.bmBitsPixel, ZPixmap, 0, tmpbuffer,
422 bmp->bitmap.bmWidth,height,32,widthbytes );
424 /* copy 16 bit padded image buffer with real bitsperpixel to XImage */
425 sbuf = (LPBYTE)buffer;
426 switch (bmp->bitmap.bmBitsPixel)
428 case 1:
429 for (h=0;h<height;h++)
431 for (w=0;w<bmp->bitmap.bmWidth;w++)
433 XPutPixel(image,w,h,(sbuf[0]>>(7-(w&7))) & 1);
434 if ((w&7) == 7)
435 sbuf++;
437 sbuf += pad;
439 break;
440 case 4:
441 for (h=0;h<height;h++)
443 for (w=0;w<bmp->bitmap.bmWidth;w++)
445 if (!(w & 1)) XPutPixel( image, w, h, *sbuf >> 4 );
446 else XPutPixel( image, w, h, *sbuf++ & 0xf );
448 sbuf += pad;
450 break;
451 case 8:
452 for (h=0;h<height;h++)
454 for (w=0;w<bmp->bitmap.bmWidth;w++)
455 XPutPixel(image,w,h,*sbuf++);
456 sbuf += pad;
458 break;
459 case 15:
460 case 16:
461 for (h=0;h<height;h++)
463 for (w=0;w<bmp->bitmap.bmWidth;w++)
465 XPutPixel(image,w,h,sbuf[1]*256+sbuf[0]);
466 sbuf+=2;
469 break;
470 case 24:
471 for (h=0;h<height;h++)
473 for (w=0;w<bmp->bitmap.bmWidth;w++)
475 XPutPixel(image,w,h,(sbuf[2]<<16)+(sbuf[1]<<8)+sbuf[0]);
476 sbuf += 3;
478 sbuf += pad;
480 break;
483 descr.bmp = bmp;
484 descr.image = image;
485 descr.width = bmp->bitmap.bmWidth;
486 descr.height = height;
487 CALL_LARGE_STACK( XPutImage_wrapper, &descr );
488 XDestroyImage( image ); /* frees tmpbuffer too */
489 LeaveCriticalSection( &X11DRV_CritSection );
491 GDI_HEAP_UNLOCK( hbitmap );
492 return height * bmp->bitmap.bmWidthBytes;
495 HANDLE16 WINAPI LoadImage16( HINSTANCE16 hinst, LPCSTR name, UINT16 type,
496 INT16 desiredx, INT16 desiredy, UINT16 loadflags)
498 if (HIWORD(name)) {
499 fprintf(stddeb,"LoadImage16(0x%04x,%s,%d,%d,%d,0x%08x)\n",
500 hinst,(char *)PTR_SEG_TO_LIN(name),type,desiredx,desiredy,loadflags
502 } else {
503 fprintf(stddeb,"LoadImage16(0x%04x,%p,%d,%d,%d,0x%08x)\n",
504 hinst,name,type,desiredx,desiredy,loadflags
507 switch (type) {
508 case IMAGE_BITMAP:
509 return LoadBitmap16(hinst,name);
510 case IMAGE_ICON:
511 return LoadIcon16(hinst,name);
512 case IMAGE_CURSOR:
513 return LoadCursor16(hinst,name);
515 return 0;
518 /**********************************************************************
519 * LoadImage32A (USER32.364)
520 * FIXME: implementation still lacks nearly all features, see LR_*
521 * defines in windows.h
524 HANDLE32 WINAPI LoadImage32A( HINSTANCE32 hinst, LPCSTR name, UINT32 type,
525 INT32 desiredx, INT32 desiredy, UINT32 loadflags)
527 if (HIWORD(name)) {
528 dprintf_resource(stddeb,"LoadImage32A(0x%04x,%s,%d,%d,%d,0x%08x)\n",
529 hinst,name,type,desiredx,desiredy,loadflags
531 } else {
532 dprintf_resource(stddeb,"LoadImage32A(0x%04x,%p,%d,%d,%d,0x%08x)\n",
533 hinst,name,type,desiredx,desiredy,loadflags
536 switch (type) {
537 case IMAGE_BITMAP:
538 return LoadBitmap32A(hinst,name);
539 case IMAGE_ICON:
540 return LoadIcon32A(hinst,name);
541 case IMAGE_CURSOR:
542 return LoadCursor32A(hinst,name);
544 return 0;
547 HANDLE32 WINAPI LoadImage32W( HINSTANCE32 hinst, LPCWSTR name, UINT32 type,
548 INT32 desiredx, INT32 desiredy, UINT32 loadflags)
550 if (HIWORD(name)) {
551 dprintf_resource(stddeb,"LoadImage32W(0x%04x,%p,%d,%d,%d,0x%08x)\n",
552 hinst,name,type,desiredx,desiredy,loadflags
554 } else {
555 dprintf_resource(stddeb,"LoadImage32W(0x%04x,%p,%d,%d,%d,0x%08x)\n",
556 hinst,name,type,desiredx,desiredy,loadflags
559 switch (type) {
560 case IMAGE_BITMAP:
561 return LoadBitmap32W(hinst,name);
562 case IMAGE_ICON:
563 return LoadIcon32W(hinst,name);
564 case IMAGE_CURSOR:
565 return LoadCursor32W(hinst,name);
567 return 0;
570 /**********************************************************************
571 * CopyBitmap32 (not an API)
574 HBITMAP32 WINAPI CopyBitmap32 (HBITMAP32 hnd)
576 HBITMAP32 res = 0;
577 BITMAP32 bmp;
579 if (GetObject32A (hnd, sizeof (bmp), &bmp))
581 res = CreateBitmapIndirect32 (&bmp);
582 SetBitmapBits32 (res, bmp.bmWidthBytes * bmp.bmHeight, bmp.bmBits);
584 return res;
587 /**********************************************************************
588 * CopyImage32 (USER32.60)
590 * FIXME: implementation still lacks nearly all features, see LR_*
591 * defines in windows.h
593 HANDLE32 WINAPI CopyImage32( HANDLE32 hnd, UINT32 type, INT32 desiredx,
594 INT32 desiredy, UINT32 flags )
596 switch (type)
598 case IMAGE_BITMAP:
599 return CopyBitmap32(hnd);
600 case IMAGE_ICON:
601 return CopyIcon32(hnd);
602 case IMAGE_CURSOR:
603 return CopyCursor32(hnd);
605 return 0;
609 /**********************************************************************
610 * LoadBitmap16 (USER.175)
612 HBITMAP16 WINAPI LoadBitmap16( HINSTANCE16 instance, SEGPTR name )
614 HBITMAP32 hbitmap = 0;
615 HDC32 hdc;
616 HRSRC16 hRsrc;
617 HGLOBAL16 handle;
618 BITMAPINFO *info;
620 if (HIWORD(name))
622 char *str = (char *)PTR_SEG_TO_LIN( name );
623 dprintf_bitmap( stddeb, "LoadBitmap16(%04x,'%s')\n", instance, str );
624 if (str[0] == '#') name = (SEGPTR)(DWORD)(WORD)atoi( str + 1 );
626 else
627 dprintf_bitmap( stddeb, "LoadBitmap16(%04x,%04x)\n",
628 instance, LOWORD(name) );
630 if (!instance) /* OEM bitmap */
632 if (HIWORD((int)name)) return 0;
633 return OBM_LoadBitmap( LOWORD((int)name) );
636 if (!(hRsrc = FindResource16( instance, name, RT_BITMAP ))) return 0;
637 if (!(handle = LoadResource16( instance, hRsrc ))) return 0;
639 info = (BITMAPINFO *)LockResource16( handle );
640 if ((hdc = GetDC32(0)) != 0)
642 char *bits = (char *)info + DIB_BitmapInfoSize( info, DIB_RGB_COLORS );
643 hbitmap = CreateDIBitmap32( hdc, &info->bmiHeader, CBM_INIT,
644 bits, info, DIB_RGB_COLORS );
645 ReleaseDC32( 0, hdc );
647 FreeResource16( handle );
648 return hbitmap;
651 /**********************************************************************
652 * LoadBitmap32W (USER32.357)
654 HBITMAP32 WINAPI LoadBitmap32W( HINSTANCE32 instance, LPCWSTR name )
656 HBITMAP32 hbitmap = 0;
657 HDC32 hdc;
658 HRSRC32 hRsrc;
659 HGLOBAL32 handle;
660 BITMAPINFO *info;
662 if (!instance) /* OEM bitmap */
664 if (HIWORD((int)name)) return 0;
665 return OBM_LoadBitmap( LOWORD((int)name) );
668 if (!(hRsrc = FindResource32W( instance, name,
669 (LPWSTR)RT_BITMAP ))) return 0;
670 if (!(handle = LoadResource32( instance, hRsrc ))) return 0;
672 info = (BITMAPINFO *)LockResource32( handle );
673 if ((hdc = GetDC32(0)) != 0)
675 char *bits = (char *)info + DIB_BitmapInfoSize( info, DIB_RGB_COLORS );
676 hbitmap = CreateDIBitmap32( hdc, &info->bmiHeader, CBM_INIT,
677 bits, info, DIB_RGB_COLORS );
678 ReleaseDC32( 0, hdc );
680 return hbitmap;
684 /**********************************************************************
685 * LoadBitmap32A (USER32.356)
687 HBITMAP32 WINAPI LoadBitmap32A( HINSTANCE32 instance, LPCSTR name )
689 HBITMAP32 res;
690 if (!HIWORD(name)) res = LoadBitmap32W( instance, (LPWSTR)name );
691 else
693 LPWSTR uni = HEAP_strdupAtoW( GetProcessHeap(), 0, name );
694 res = LoadBitmap32W( instance, uni );
695 HeapFree( GetProcessHeap(), 0, uni );
697 return res;
701 /***********************************************************************
702 * BITMAP_DeleteObject
704 BOOL32 BITMAP_DeleteObject( HBITMAP16 hbitmap, BITMAPOBJ * bmp )
706 #ifdef PRELIMINARY_WING16_SUPPORT
707 if( bmp->bitmap.bmBits )
708 TSXShmDetach( display, (XShmSegmentInfo*)bmp->bitmap.bmBits );
709 #endif
711 TSXFreePixmap( display, bmp->pixmap );
712 #ifdef PRELIMINARY_WING16_SUPPORT
713 if( bmp->bitmap.bmBits )
715 __ShmBitmapCtl* p = (__ShmBitmapCtl*)bmp->bitmap.bmBits;
716 WORD sel = HIWORD(p->bits);
717 unsigned long l, limit = GetSelectorLimit(sel);
719 for( l = 0; l < limit; l += 0x10000, sel += __AHINCR )
720 FreeSelector(sel);
721 shmctl(p->si.shmid, IPC_RMID, NULL);
722 shmdt(p->si.shmaddr); /* already marked for destruction */
724 #endif
725 return GDI_FreeObject( hbitmap );
729 /***********************************************************************
730 * BITMAP_GetObject16
732 INT16 BITMAP_GetObject16( BITMAPOBJ * bmp, INT16 count, LPVOID buffer )
734 if (count > sizeof(bmp->bitmap)) count = sizeof(bmp->bitmap);
735 memcpy( buffer, &bmp->bitmap, count );
736 return count;
740 /***********************************************************************
741 * BITMAP_GetObject32
743 INT32 BITMAP_GetObject32( BITMAPOBJ * bmp, INT32 count, LPVOID buffer )
745 BITMAP32 bmp32;
746 bmp32.bmType = bmp->bitmap.bmType;
747 bmp32.bmWidth = bmp->bitmap.bmWidth;
748 bmp32.bmHeight = bmp->bitmap.bmHeight;
749 bmp32.bmWidthBytes = bmp->bitmap.bmWidthBytes;
750 bmp32.bmPlanes = bmp->bitmap.bmPlanes;
751 bmp32.bmBitsPixel = bmp->bitmap.bmBitsPixel;
752 bmp32.bmBits = NULL;
753 if (count > sizeof(bmp32)) count = sizeof(bmp32);
754 memcpy( buffer, &bmp32, count );
755 return count;
760 /***********************************************************************
761 * CreateDiscardableBitmap16 (GDI.156)
763 HBITMAP16 WINAPI CreateDiscardableBitmap16( HDC16 hdc, INT16 width,
764 INT16 height )
766 return CreateCompatibleBitmap16( hdc, width, height );
770 /***********************************************************************
771 * CreateDiscardableBitmap32 (GDI32.38)
773 HBITMAP32 WINAPI CreateDiscardableBitmap32( HDC32 hdc, INT32 width,
774 INT32 height )
776 return CreateCompatibleBitmap32( hdc, width, height );
780 /***********************************************************************
781 * GetBitmapDimensionEx16 (GDI.468)
783 BOOL16 WINAPI GetBitmapDimensionEx16( HBITMAP16 hbitmap, LPSIZE16 size )
785 BITMAPOBJ * bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC );
786 if (!bmp) return FALSE;
787 *size = bmp->size;
788 GDI_HEAP_UNLOCK( hbitmap );
789 return TRUE;
793 /***********************************************************************
794 * GetBitmapDimensionEx32 (GDI32.144)
796 BOOL32 WINAPI GetBitmapDimensionEx32( HBITMAP32 hbitmap, LPSIZE32 size )
798 BITMAPOBJ * bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC );
799 if (!bmp) return FALSE;
800 size->cx = (INT32)bmp->size.cx;
801 size->cy = (INT32)bmp->size.cy;
802 GDI_HEAP_UNLOCK( hbitmap );
803 return TRUE;
807 /***********************************************************************
808 * GetBitmapDimension (GDI.162)
810 DWORD WINAPI GetBitmapDimension( HBITMAP16 hbitmap )
812 SIZE16 size;
813 if (!GetBitmapDimensionEx16( hbitmap, &size )) return 0;
814 return MAKELONG( size.cx, size.cy );
818 /***********************************************************************
819 * SetBitmapDimensionEx16 (GDI.478)
821 BOOL16 WINAPI SetBitmapDimensionEx16( HBITMAP16 hbitmap, INT16 x, INT16 y,
822 LPSIZE16 prevSize )
824 BITMAPOBJ * bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC );
825 if (!bmp) return FALSE;
826 if (prevSize) *prevSize = bmp->size;
827 bmp->size.cx = x;
828 bmp->size.cy = y;
829 GDI_HEAP_UNLOCK( hbitmap );
830 return TRUE;
834 /***********************************************************************
835 * SetBitmapDimensionEx32 (GDI32.304)
837 BOOL32 WINAPI SetBitmapDimensionEx32( HBITMAP32 hbitmap, INT32 x, INT32 y,
838 LPSIZE32 prevSize )
840 BITMAPOBJ * bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC );
841 if (!bmp) return FALSE;
842 if (prevSize) CONV_SIZE16TO32( &bmp->size, prevSize );
843 bmp->size.cx = (INT16)x;
844 bmp->size.cy = (INT16)y;
845 GDI_HEAP_UNLOCK( hbitmap );
846 return TRUE;
850 /***********************************************************************
851 * SetBitmapDimension (GDI.163)
853 DWORD WINAPI SetBitmapDimension( HBITMAP16 hbitmap, INT16 x, INT16 y )
855 SIZE16 size;
856 if (!SetBitmapDimensionEx16( hbitmap, x, y, &size )) return 0;
857 return MAKELONG( size.cx, size.cy );