Release 971221
[wine.git] / objects / bitmap.c
blob4092719c410d431d43d0a598e40b81decbf2b315
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 HANDLE16 WINAPI LoadImage16( HINSTANCE16 hinst, LPCSTR name, UINT16 type,
493 INT16 desiredx, INT16 desiredy, UINT16 loadflags)
495 if (HIWORD(name)) {
496 fprintf(stddeb,"LoadImage16(0x%04x,%s,%d,%d,%d,0x%08x)\n",
497 hinst,(char *)PTR_SEG_TO_LIN(name),type,desiredx,desiredy,loadflags
499 } else {
500 fprintf(stddeb,"LoadImage16(0x%04x,%p,%d,%d,%d,0x%08x)\n",
501 hinst,name,type,desiredx,desiredy,loadflags
504 switch (type) {
505 case IMAGE_BITMAP:
506 return LoadBitmap16(hinst,name);
507 case IMAGE_ICON:
508 return LoadIcon16(hinst,name);
509 case IMAGE_CURSOR:
510 return LoadCursor16(hinst,name);
512 return 0;
515 /**********************************************************************
516 * LoadImageA (USER32.364)
517 * FIXME: implementation still lacks nearly all features, see LR_*
518 * defines in windows.h
521 HANDLE32 WINAPI LoadImage32A( HINSTANCE32 hinst, LPCSTR name, UINT32 type,
522 INT32 desiredx, INT32 desiredy, UINT32 loadflags)
524 if (HIWORD(name)) {
525 dprintf_resource(stddeb,"LoadImage32A(0x%04x,%s,%d,%d,%d,0x%08x)\n",
526 hinst,name,type,desiredx,desiredy,loadflags
528 } else {
529 dprintf_resource(stddeb,"LoadImage32A(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 LoadBitmap32A(hinst,name);
536 case IMAGE_ICON:
537 return LoadIcon32A(hinst,name);
538 case IMAGE_CURSOR:
539 return LoadCursor32A(hinst,name);
541 return 0;
544 HANDLE32 WINAPI LoadImage32W( HINSTANCE32 hinst, LPCWSTR name, UINT32 type,
545 INT32 desiredx, INT32 desiredy, UINT32 loadflags)
547 if (HIWORD(name)) {
548 dprintf_resource(stddeb,"LoadImage32W(0x%04x,%p,%d,%d,%d,0x%08x)\n",
549 hinst,name,type,desiredx,desiredy,loadflags
551 } else {
552 dprintf_resource(stddeb,"LoadImage32W(0x%04x,%p,%d,%d,%d,0x%08x)\n",
553 hinst,name,type,desiredx,desiredy,loadflags
556 switch (type) {
557 case IMAGE_BITMAP:
558 return LoadBitmap32W(hinst,name);
559 case IMAGE_ICON:
560 return LoadIcon32W(hinst,name);
561 case IMAGE_CURSOR:
562 return LoadCursor32W(hinst,name);
564 return 0;
567 /**********************************************************************
568 * CopyBitmap32 (not an API)
571 HBITMAP32 WINAPI CopyBitmap32 (HBITMAP32 hnd)
573 HBITMAP32 res = 0;
574 BITMAP32 bmp;
576 if (GetObject32A (hnd, sizeof (bmp), &bmp))
578 res = CreateBitmapIndirect32 (&bmp);
579 SetBitmapBits32 (res, bmp.bmWidthBytes * bmp.bmHeight, bmp.bmBits);
581 return res;
584 /**********************************************************************
585 * CopyImage32 (USER32.60)
587 * FIXME: implementation still lacks nearly all features, see LR_*
588 * defines in windows.h
590 HANDLE32 WINAPI CopyImage32( HANDLE32 hnd, UINT32 type, INT32 desiredx,
591 INT32 desiredy, UINT32 flags )
593 switch (type)
595 case IMAGE_BITMAP:
596 return CopyBitmap32(hnd);
597 case IMAGE_ICON:
598 return CopyIcon32(hnd);
599 case IMAGE_CURSOR:
600 return CopyCursor32(hnd);
602 return 0;
606 /**********************************************************************
607 * LoadBitmap16 (USER.175)
609 HBITMAP16 WINAPI LoadBitmap16( HINSTANCE16 instance, SEGPTR name )
611 HBITMAP32 hbitmap = 0;
612 HDC32 hdc;
613 HRSRC16 hRsrc;
614 HGLOBAL16 handle;
615 BITMAPINFO *info;
617 if (HIWORD(name))
619 char *str = (char *)PTR_SEG_TO_LIN( name );
620 dprintf_bitmap( stddeb, "LoadBitmap16(%04x,'%s')\n", instance, str );
621 if (str[0] == '#') name = (SEGPTR)(DWORD)(WORD)atoi( str + 1 );
623 else
624 dprintf_bitmap( stddeb, "LoadBitmap16(%04x,%04x)\n",
625 instance, LOWORD(name) );
627 if (!instance) /* OEM bitmap */
629 if (HIWORD((int)name)) return 0;
630 return OBM_LoadBitmap( LOWORD((int)name) );
633 if (!(hRsrc = FindResource16( instance, name, RT_BITMAP ))) return 0;
634 if (!(handle = LoadResource16( instance, hRsrc ))) return 0;
636 info = (BITMAPINFO *)LockResource16( handle );
637 if ((hdc = GetDC32(0)) != 0)
639 char *bits = (char *)info + DIB_BitmapInfoSize( info, DIB_RGB_COLORS );
640 hbitmap = CreateDIBitmap32( hdc, &info->bmiHeader, CBM_INIT,
641 bits, info, DIB_RGB_COLORS );
642 ReleaseDC32( 0, hdc );
644 FreeResource16( handle );
645 return hbitmap;
648 /**********************************************************************
649 * LoadBitmap32W (USER32.357)
651 HBITMAP32 WINAPI LoadBitmap32W( HINSTANCE32 instance, LPCWSTR name )
653 HBITMAP32 hbitmap = 0;
654 HDC32 hdc;
655 HRSRC32 hRsrc;
656 HGLOBAL32 handle;
657 BITMAPINFO *info;
659 if (!instance) /* OEM bitmap */
661 if (HIWORD((int)name)) return 0;
662 return OBM_LoadBitmap( LOWORD((int)name) );
665 if (!(hRsrc = FindResource32W( instance, name,
666 (LPWSTR)RT_BITMAP ))) return 0;
667 if (!(handle = LoadResource32( instance, hRsrc ))) return 0;
669 info = (BITMAPINFO *)LockResource32( handle );
670 if ((hdc = GetDC32(0)) != 0)
672 char *bits = (char *)info + DIB_BitmapInfoSize( info, DIB_RGB_COLORS );
673 hbitmap = CreateDIBitmap32( hdc, &info->bmiHeader, CBM_INIT,
674 bits, info, DIB_RGB_COLORS );
675 ReleaseDC32( 0, hdc );
677 return hbitmap;
681 /**********************************************************************
682 * LoadBitmap32A (USER32.356)
684 HBITMAP32 WINAPI LoadBitmap32A( HINSTANCE32 instance, LPCSTR name )
686 HBITMAP32 res;
687 if (!HIWORD(name)) res = LoadBitmap32W( instance, (LPWSTR)name );
688 else
690 LPWSTR uni = HEAP_strdupAtoW( GetProcessHeap(), 0, name );
691 res = LoadBitmap32W( instance, uni );
692 HeapFree( GetProcessHeap(), 0, uni );
694 return res;
698 /***********************************************************************
699 * BITMAP_DeleteObject
701 BOOL32 BITMAP_DeleteObject( HBITMAP16 hbitmap, BITMAPOBJ * bmp )
703 #ifdef PRELIMINARY_WING16_SUPPORT
704 if( bmp->bitmap.bmBits )
705 XShmDetach( display, (XShmSegmentInfo*)bmp->bitmap.bmBits );
706 #endif
708 XFreePixmap( display, bmp->pixmap );
709 #ifdef PRELIMINARY_WING16_SUPPORT
710 if( bmp->bitmap.bmBits )
712 __ShmBitmapCtl* p = (__ShmBitmapCtl*)bmp->bitmap.bmBits;
713 WORD sel = HIWORD(p->bits);
714 unsigned long l, limit = GetSelectorLimit(sel);
716 for( l = 0; l < limit; l += 0x10000, sel += __AHINCR )
717 FreeSelector(sel);
718 shmctl(p->si.shmid, IPC_RMID, NULL);
719 shmdt(p->si.shmaddr); /* already marked for destruction */
721 #endif
722 return GDI_FreeObject( hbitmap );
726 /***********************************************************************
727 * BITMAP_GetObject16
729 INT16 BITMAP_GetObject16( BITMAPOBJ * bmp, INT16 count, LPVOID buffer )
731 if (count > sizeof(bmp->bitmap)) count = sizeof(bmp->bitmap);
732 memcpy( buffer, &bmp->bitmap, count );
733 return count;
737 /***********************************************************************
738 * BITMAP_GetObject32
740 INT32 BITMAP_GetObject32( BITMAPOBJ * bmp, INT32 count, LPVOID buffer )
742 BITMAP32 bmp32;
743 bmp32.bmType = bmp->bitmap.bmType;
744 bmp32.bmWidth = bmp->bitmap.bmWidth;
745 bmp32.bmHeight = bmp->bitmap.bmHeight;
746 bmp32.bmWidthBytes = bmp->bitmap.bmWidthBytes;
747 bmp32.bmPlanes = bmp->bitmap.bmPlanes;
748 bmp32.bmBitsPixel = bmp->bitmap.bmBitsPixel;
749 bmp32.bmBits = NULL;
750 if (count > sizeof(bmp32)) count = sizeof(bmp32);
751 memcpy( buffer, &bmp32, count );
752 return count;
757 /***********************************************************************
758 * CreateDiscardableBitmap16 (GDI.156)
760 HBITMAP16 WINAPI CreateDiscardableBitmap16( HDC16 hdc, INT16 width,
761 INT16 height )
763 return CreateCompatibleBitmap16( hdc, width, height );
767 /***********************************************************************
768 * CreateDiscardableBitmap32 (GDI32.38)
770 HBITMAP32 WINAPI CreateDiscardableBitmap32( HDC32 hdc, INT32 width,
771 INT32 height )
773 return CreateCompatibleBitmap32( hdc, width, height );
777 /***********************************************************************
778 * GetBitmapDimensionEx16 (GDI.468)
780 BOOL16 WINAPI GetBitmapDimensionEx16( HBITMAP16 hbitmap, LPSIZE16 size )
782 BITMAPOBJ * bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC );
783 if (!bmp) return FALSE;
784 *size = bmp->size;
785 GDI_HEAP_UNLOCK( hbitmap );
786 return TRUE;
790 /***********************************************************************
791 * GetBitmapDimensionEx32 (GDI32.144)
793 BOOL32 WINAPI GetBitmapDimensionEx32( HBITMAP32 hbitmap, LPSIZE32 size )
795 BITMAPOBJ * bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC );
796 if (!bmp) return FALSE;
797 size->cx = (INT32)bmp->size.cx;
798 size->cy = (INT32)bmp->size.cy;
799 GDI_HEAP_UNLOCK( hbitmap );
800 return TRUE;
804 /***********************************************************************
805 * GetBitmapDimension (GDI.162)
807 DWORD WINAPI GetBitmapDimension( HBITMAP16 hbitmap )
809 SIZE16 size;
810 if (!GetBitmapDimensionEx16( hbitmap, &size )) return 0;
811 return MAKELONG( size.cx, size.cy );
815 /***********************************************************************
816 * SetBitmapDimensionEx16 (GDI.478)
818 BOOL16 WINAPI SetBitmapDimensionEx16( HBITMAP16 hbitmap, INT16 x, INT16 y,
819 LPSIZE16 prevSize )
821 BITMAPOBJ * bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC );
822 if (!bmp) return FALSE;
823 if (prevSize) *prevSize = bmp->size;
824 bmp->size.cx = x;
825 bmp->size.cy = y;
826 GDI_HEAP_UNLOCK( hbitmap );
827 return TRUE;
831 /***********************************************************************
832 * SetBitmapDimensionEx32 (GDI32.304)
834 BOOL32 WINAPI SetBitmapDimensionEx32( HBITMAP32 hbitmap, INT32 x, INT32 y,
835 LPSIZE32 prevSize )
837 BITMAPOBJ * bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC );
838 if (!bmp) return FALSE;
839 if (prevSize) CONV_SIZE16TO32( &bmp->size, prevSize );
840 bmp->size.cx = (INT16)x;
841 bmp->size.cy = (INT16)y;
842 GDI_HEAP_UNLOCK( hbitmap );
843 return TRUE;
847 /***********************************************************************
848 * SetBitmapDimension (GDI.163)
850 DWORD WINAPI SetBitmapDimension( HBITMAP16 hbitmap, INT16 x, INT16 y )
852 SIZE16 size;
853 if (!SetBitmapDimensionEx16( hbitmap, x, y, &size )) return 0;
854 return MAKELONG( size.cx, size.cy );