More bitmap fixes.

This commit is contained in:
Huw D M Davies 1998-11-01 16:35:42 +00:00 committed by Alexandre Julliard
parent 463b713dfd
commit 82617362a5
5 changed files with 48 additions and 73 deletions

View file

@ -17,13 +17,6 @@
#include "xmalloc.h" #include "xmalloc.h"
#include "x11drv.h" #include "x11drv.h"
#ifdef PRELIMINARY_WING16_SUPPORT
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#endif
/* GCs used for B&W and color bitmap operations */ /* GCs used for B&W and color bitmap operations */
GC BITMAP_monoGC = 0, BITMAP_colorGC = 0; GC BITMAP_monoGC = 0, BITMAP_colorGC = 0;
@ -186,11 +179,14 @@ BOOL32 X11DRV_CreateBitmap( HBITMAP32 hbitmap )
/* Check parameters */ /* Check parameters */
if (bmp->bitmap.bmPlanes != 1) return 0; if (bmp->bitmap.bmPlanes != 1) return 0;
if ((bmp->bitmap.bmBitsPixel != 1) && if ((bmp->bitmap.bmBitsPixel != 1) &&
(bmp->bitmap.bmBitsPixel != screenDepth)) { (bmp->bitmap.bmBitsPixel != screenDepth)) {
GDI_HEAP_UNLOCK( hbitmap ); GDI_HEAP_UNLOCK( hbitmap );
return FALSE; return FALSE;
} }
TRACE(x11drv, "(%08x) %dx%d %d bpp\n", hbitmap, bmp->bitmap.bmWidth,
bmp->bitmap.bmHeight, bmp->bitmap.bmBitsPixel);
pbitmap = X11DRV_AllocBitmap( bmp ); pbitmap = X11DRV_AllocBitmap( bmp );
if(!pbitmap) return FALSE; if(!pbitmap) return FALSE;
@ -243,7 +239,9 @@ static LONG X11DRV_GetBitmapBits(BITMAPOBJ *bmp, void *buffer, LONG count)
LPBYTE tbuf; LPBYTE tbuf;
int h, w, pad; int h, w, pad;
pad = BITMAP_GetBitsPadding(bmp->bitmap.bmWidth, bmp->bitmap.bmBitsPixel); TRACE(x11drv, "(bmp=%p, buffer=%p, count=%lx)\n", bmp, buffer, count);
pad = BITMAP_GetPadding(bmp->bitmap.bmWidth, bmp->bitmap.bmBitsPixel);
if (pad == -1) if (pad == -1)
return 0; return 0;
@ -364,30 +362,25 @@ static LONG X11DRV_SetBitmapBits(BITMAPOBJ *bmp, void *bits, LONG count)
struct XPutImage_descr descr; struct XPutImage_descr descr;
LONG height; LONG height;
XImage *image; XImage *image;
LPBYTE sbuf, tmpbuffer; LPBYTE sbuf;
int w, h, pad, widthbytes; int w, h, pad;
TRACE(x11drv, "(bmp=%p, bits=%p, count=%lx)\n", bmp, bits, count); TRACE(x11drv, "(bmp=%p, bits=%p, count=%lx)\n", bmp, bits, count);
pad = BITMAP_GetBitsPadding(bmp->bitmap.bmWidth, bmp->bitmap.bmBitsPixel); pad = BITMAP_GetPadding(bmp->bitmap.bmWidth, bmp->bitmap.bmBitsPixel);
if (pad == -1) if (pad == -1)
return 0; return 0;
sbuf = (LPBYTE)bits; sbuf = (LPBYTE)bits;
widthbytes = (((bmp->bitmap.bmWidth * bmp->bitmap.bmBitsPixel) + 31) / height = count / bmp->bitmap.bmWidthBytes;
32) * 4;
height = count / bmp->bitmap.bmWidthBytes;
tmpbuffer = (LPBYTE)xmalloc(widthbytes*height);
TRACE(x11drv, "h=%ld, w=%d, wb=%d\n", height, bmp->bitmap.bmWidth,
widthbytes);
EnterCriticalSection( &X11DRV_CritSection ); EnterCriticalSection( &X11DRV_CritSection );
image = XCreateImage( display, DefaultVisualOfScreen(screen), image = XCreateImage( display, DefaultVisualOfScreen(screen),
bmp->bitmap.bmBitsPixel, ZPixmap, 0, tmpbuffer, bmp->bitmap.bmBitsPixel, ZPixmap, 0, NULL,
bmp->bitmap.bmWidth,height,32,widthbytes ); bmp->bitmap.bmWidth, height, 32, 0 );
image->data = (LPBYTE)xmalloc(image->bytes_per_line * height);
/* copy 16 bit padded image buffer with real bitsperpixel to XImage */ /* copy 16 bit padded image buffer with real bitsperpixel to XImage */
sbuf = (LPBYTE)bits; sbuf = (LPBYTE)bits;
@ -466,8 +459,9 @@ static LONG X11DRV_SetBitmapBits(BITMAPOBJ *bmp, void *bits, LONG count)
descr.image = image; descr.image = image;
descr.width = bmp->bitmap.bmWidth; descr.width = bmp->bitmap.bmWidth;
descr.height = height; descr.height = height;
CALL_LARGE_STACK( XPutImage_wrapper, &descr ); CALL_LARGE_STACK( XPutImage_wrapper, &descr );
XDestroyImage( image ); /* frees tmpbuffer too */ XDestroyImage( image ); /* frees image->data too */
LeaveCriticalSection( &X11DRV_CritSection ); LeaveCriticalSection( &X11DRV_CritSection );
return count; return count;
@ -505,28 +499,8 @@ BOOL32 X11DRV_BITMAP_DeleteObject( HBITMAP32 hbitmap, BITMAPOBJ * bmp )
{ {
X11DRV_PHYSBITMAP *pbitmap = bmp->DDBitmap->physBitmap; X11DRV_PHYSBITMAP *pbitmap = bmp->DDBitmap->physBitmap;
#ifdef PRELIMINARY_WING16_SUPPORT
if( bmp->bitmap.bmBits )
TSXShmDetach( display, (XShmSegmentInfo*)bmp->bitmap.bmBits );
#endif
TSXFreePixmap( display, pbitmap->pixmap ); TSXFreePixmap( display, pbitmap->pixmap );
#ifdef PRELIMINARY_WING16_SUPPORT
if( bmp->bitmap.bmBits )
{
__ShmBitmapCtl* p = (__ShmBitmapCtl*)bmp->bitmap.bmBits;
WORD sel = HIWORD(p->bits);
unsigned long l, limit = GetSelectorLimit(sel);
for( l = 0; l < limit; l += 0x10000, sel += __AHINCR )
FreeSelector(sel);
shmctl(p->si.shmid, IPC_RMID, NULL);
shmdt(p->si.shmaddr); /* already marked for destruction */
}
#endif
HeapFree( GetProcessHeap(), 0, bmp->DDBitmap->physBitmap ); HeapFree( GetProcessHeap(), 0, bmp->DDBitmap->physBitmap );
HeapFree( GetProcessHeap(), 0, bmp->DDBitmap ); HeapFree( GetProcessHeap(), 0, bmp->DDBitmap );
bmp->DDBitmap = NULL; bmp->DDBitmap = NULL;

View file

@ -53,16 +53,12 @@ typedef struct tagBITMAPOBJ
} BITMAPOBJ; } BITMAPOBJ;
#define BITMAP_WIDTH_BYTES(width,bpp) \
(((bpp) == 24) ? (width) * 4 : ( ((bpp) == 15) ? (width) * 2 : \
((width) * (bpp) + 15) / 16 * 2 ))
/* objects/bitmap.c */ /* objects/bitmap.c */
extern INT16 BITMAP_GetObject16( BITMAPOBJ * bmp, INT16 count, LPVOID buffer ); extern INT16 BITMAP_GetObject16( BITMAPOBJ * bmp, INT16 count, LPVOID buffer );
extern INT32 BITMAP_GetObject32( BITMAPOBJ * bmp, INT32 count, LPVOID buffer ); extern INT32 BITMAP_GetObject32( BITMAPOBJ * bmp, INT32 count, LPVOID buffer );
extern BOOL32 BITMAP_DeleteObject( HBITMAP16 hbitmap, BITMAPOBJ * bitmap ); extern BOOL32 BITMAP_DeleteObject( HBITMAP16 hbitmap, BITMAPOBJ * bitmap );
extern INT32 BITMAP_GetBitsPadding( int width, int depth ); extern INT32 BITMAP_GetPadding( INT32 width, INT32 depth );
extern INT32 BITMAP_GetBitsWidth( int width, int depth ); extern INT32 BITMAP_GetWidthBytes( INT32 width, INT32 depth );
extern HBITMAP32 BITMAP_LoadBitmap32W(HINSTANCE32 instance,LPCWSTR name, extern HBITMAP32 BITMAP_LoadBitmap32W(HINSTANCE32 instance,LPCWSTR name,
UINT32 loadflags); UINT32 loadflags);
extern HBITMAP32 BITMAP_CopyBitmap( HBITMAP32 hbitmap ); extern HBITMAP32 BITMAP_CopyBitmap( HBITMAP32 hbitmap );

View file

@ -19,19 +19,18 @@
/*********************************************************************** /***********************************************************************
* BITMAP_GetBitsPadding * BITMAP_GetPadding
* *
* Return number of bytes to pad a scanline of 16-bit aligned Windows DDB data. * Return number of bytes to pad a scanline of 16-bit aligned Windows DDB data.
*/ */
INT32 BITMAP_GetBitsPadding( int bmWidth, int bpp ) INT32 BITMAP_GetPadding( int bmWidth, int bpp )
{ {
INT32 pad; INT32 pad;
switch (bpp) switch (bpp)
{ {
case 1: case 1:
if (!(bmWidth & 15)) pad = 0; pad = ((bmWidth-1) & 8) ? 0 : 1;
else pad = ((16 - (bmWidth & 15)) + 7) / 8;
break; break;
case 8: case 8:
@ -61,11 +60,12 @@ INT32 BITMAP_GetBitsPadding( int bmWidth, int bpp )
} }
/*********************************************************************** /***********************************************************************
* BITMAP_GetBitsWidth * BITMAP_GetWidthBytes
* *
* Return number of bytes taken by a scanline of 16-bit aligned Windows DDB data. * Return number of bytes taken by a scanline of 16-bit aligned Windows DDB
* data.
*/ */
INT32 BITMAP_GetBitsWidth( int bmWidth, int bpp ) INT32 BITMAP_GetWidthBytes( INT32 bmWidth, INT32 bpp )
{ {
switch(bpp) switch(bpp)
{ {
@ -167,11 +167,11 @@ HBITMAP32 WINAPI CreateBitmap32( INT32 width, INT32 height, UINT32 planes,
bmp->size.cx = 0; bmp->size.cx = 0;
bmp->size.cy = 0; bmp->size.cy = 0;
bmp->bitmap.bmType = 0; bmp->bitmap.bmType = 0;
bmp->bitmap.bmWidth = (INT16)width; bmp->bitmap.bmWidth = width;
bmp->bitmap.bmHeight = (INT16)height; bmp->bitmap.bmHeight = height;
bmp->bitmap.bmPlanes = (BYTE)planes; bmp->bitmap.bmPlanes = planes;
bmp->bitmap.bmBitsPixel = (BYTE)bpp; bmp->bitmap.bmBitsPixel = bpp;
bmp->bitmap.bmWidthBytes = (INT16)BITMAP_WIDTH_BYTES( width, bpp ); bmp->bitmap.bmWidthBytes = BITMAP_GetWidthBytes( width, bpp );
bmp->bitmap.bmBits = NULL; bmp->bitmap.bmBits = NULL;
bmp->DDBitmap = NULL; bmp->DDBitmap = NULL;
@ -594,8 +594,11 @@ HBITMAP16 WINAPI LoadBitmap16( HINSTANCE16 instance, SEGPTR name )
} }
HBITMAP32 BITMAP_LoadBitmap32W(HINSTANCE32 instance,LPCWSTR name, /**********************************************************************
UINT32 loadflags) * BITMAP_LoadBitmap32W
*/
HBITMAP32 BITMAP_LoadBitmap32W(HINSTANCE32 instance,LPCWSTR name,
UINT32 loadflags)
{ {
HBITMAP32 hbitmap = 0; HBITMAP32 hbitmap = 0;
HDC32 hdc; HDC32 hdc;
@ -647,6 +650,8 @@ HBITMAP32 BITMAP_LoadBitmap32W(HINSTANCE32 instance,LPCWSTR name,
if (loadflags & LR_LOADFROMFILE) UnmapViewOfFile( ptr ); if (loadflags & LR_LOADFROMFILE) UnmapViewOfFile( ptr );
return hbitmap; return hbitmap;
} }
/****************************************************************************** /******************************************************************************
* LoadBitmap32W [USER32.358] Loads bitmap from the executable file * LoadBitmap32W [USER32.358] Loads bitmap from the executable file
* *

View file

@ -754,8 +754,8 @@ HCURSOR16 CURSORICON_IconToCursor(HICON16 hIcon, BOOL32 bSemiTransparent)
TRACE(icon, "[%04x] %ix%i %ibpp (bogus %ibps)\n", TRACE(icon, "[%04x] %ix%i %ibpp (bogus %ibps)\n",
hIcon, pIcon->nWidth, pIcon->nHeight, pIcon->bBitsPerPixel, pIcon->nWidthBytes ); hIcon, pIcon->nWidth, pIcon->nHeight, pIcon->bBitsPerPixel, pIcon->nWidthBytes );
xor_width = BITMAP_GetBitsWidth( pIcon->nWidth, bpp ); xor_width = BITMAP_GetWidthBytes( pIcon->nWidth, bpp );
and_width = BITMAP_GetBitsWidth( pIcon->nWidth, 1 ); and_width = BITMAP_GetWidthBytes( pIcon->nWidth, 1 );
psPtr = (BYTE *)(pIcon + 1) + pIcon->nHeight * and_width; psPtr = (BYTE *)(pIcon + 1) + pIcon->nHeight * and_width;
memset(pXorBits, 0, 128); memset(pXorBits, 0, 128);
@ -923,9 +923,9 @@ HGLOBAL16 WINAPI CreateCursorIconIndirect( HINSTANCE16 hInstance,
hInstance = GetExePtr( hInstance ); /* Make it a module handle */ hInstance = GetExePtr( hInstance ); /* Make it a module handle */
if (!lpXORbits || !lpANDbits || info->bPlanes != 1) return 0; if (!lpXORbits || !lpANDbits || info->bPlanes != 1) return 0;
info->nWidthBytes = BITMAP_WIDTH_BYTES(info->nWidth,info->bBitsPerPixel); info->nWidthBytes = BITMAP_GetWidthBytes(info->nWidth,info->bBitsPerPixel);
sizeXor = info->nHeight * info->nWidthBytes; sizeXor = info->nHeight * info->nWidthBytes;
sizeAnd = info->nHeight * BITMAP_WIDTH_BYTES( info->nWidth, 1 ); sizeAnd = info->nHeight * BITMAP_GetWidthBytes( info->nWidth, 1 );
if (!(handle = GlobalAlloc16( GMEM_MOVEABLE, if (!(handle = GlobalAlloc16( GMEM_MOVEABLE,
sizeof(CURSORICONINFO) + sizeXor + sizeAnd))) sizeof(CURSORICONINFO) + sizeXor + sizeAnd)))
return 0; return 0;
@ -1057,7 +1057,7 @@ BOOL32 WINAPI DrawIcon32( HDC32 hdc, INT32 x, INT32 y, HICON32 hIcon )
(char *)(ptr+1) ); (char *)(ptr+1) );
hXorBits = CreateBitmap32( ptr->nWidth, ptr->nHeight, ptr->bPlanes, hXorBits = CreateBitmap32( ptr->nWidth, ptr->nHeight, ptr->bPlanes,
ptr->bBitsPerPixel, (char *)(ptr + 1) ptr->bBitsPerPixel, (char *)(ptr + 1)
+ ptr->nHeight * BITMAP_WIDTH_BYTES(ptr->nWidth,1) ); + ptr->nHeight * BITMAP_GetWidthBytes(ptr->nWidth,1) );
oldFg = SetTextColor32( hdc, RGB(0,0,0) ); oldFg = SetTextColor32( hdc, RGB(0,0,0) );
oldBg = SetBkColor32( hdc, RGB(255,255,255) ); oldBg = SetBkColor32( hdc, RGB(255,255,255) );
@ -1090,7 +1090,7 @@ DWORD WINAPI DumpIcon( SEGPTR pInfo, WORD *lpLen,
if (!info) return 0; if (!info) return 0;
sizeXor = info->nHeight * info->nWidthBytes; sizeXor = info->nHeight * info->nWidthBytes;
sizeAnd = info->nHeight * BITMAP_WIDTH_BYTES( info->nWidth, 1 ); sizeAnd = info->nHeight * BITMAP_GetWidthBytes( info->nWidth, 1 );
if (lpAndBits) *lpAndBits = pInfo + sizeof(CURSORICONINFO); if (lpAndBits) *lpAndBits = pInfo + sizeof(CURSORICONINFO);
if (lpXorBits) *lpXorBits = pInfo + sizeof(CURSORICONINFO) + sizeAnd; if (lpXorBits) *lpXorBits = pInfo + sizeof(CURSORICONINFO) + sizeAnd;
if (lpLen) *lpLen = sizeof(CURSORICONINFO) + sizeAnd + sizeXor; if (lpLen) *lpLen = sizeof(CURSORICONINFO) + sizeAnd + sizeXor;
@ -1674,8 +1674,7 @@ BOOL32 WINAPI GetIconInfo(HICON32 hIcon,LPICONINFO iconinfo) {
ciconinfo->bPlanes, ciconinfo->bBitsPerPixel, ciconinfo->bPlanes, ciconinfo->bBitsPerPixel,
(char *)(ciconinfo + 1) (char *)(ciconinfo + 1)
+ ciconinfo->nHeight * + ciconinfo->nHeight *
BITMAP_GetBitsWidth (ciconinfo->nWidth,1) ); BITMAP_GetWidthBytes (ciconinfo->nWidth,1) );
// BITMAP_WIDTH_BYTES(ciconinfo->nWidth,1) );
iconinfo->hbmMask = CreateBitmap32 ( ciconinfo->nWidth, ciconinfo->nHeight, iconinfo->hbmMask = CreateBitmap32 ( ciconinfo->nWidth, ciconinfo->nHeight,
1, 1, (char *)(ciconinfo + 1)); 1, 1, (char *)(ciconinfo + 1));
@ -1819,7 +1818,7 @@ BOOL32 WINAPI DrawIconEx32( HDC32 hdc, INT32 x0, INT32 y0, HICON32 hIcon,
ptr->bPlanes, ptr->bBitsPerPixel, ptr->bPlanes, ptr->bBitsPerPixel,
(char *)(ptr + 1) (char *)(ptr + 1)
+ ptr->nHeight * + ptr->nHeight *
BITMAP_WIDTH_BYTES(ptr->nWidth,1) ); BITMAP_GetWidthBytes(ptr->nWidth,1) );
hAndBits = CreateBitmap32 ( ptr->nWidth, ptr->nHeight, hAndBits = CreateBitmap32 ( ptr->nWidth, ptr->nHeight,
1, 1, (char *)(ptr+1) ); 1, 1, (char *)(ptr+1) );
oldFg = SetTextColor32( hdc, RGB(0,0,0) ); oldFg = SetTextColor32( hdc, RGB(0,0,0) );

View file

@ -332,7 +332,7 @@ static HBITMAP16 OBM_MakeBitmap( WORD width, WORD height,
bmpObjPtr->bitmap.bmType = 0; bmpObjPtr->bitmap.bmType = 0;
bmpObjPtr->bitmap.bmWidth = width; bmpObjPtr->bitmap.bmWidth = width;
bmpObjPtr->bitmap.bmHeight = height; bmpObjPtr->bitmap.bmHeight = height;
bmpObjPtr->bitmap.bmWidthBytes = BITMAP_WIDTH_BYTES( width, bpp ); bmpObjPtr->bitmap.bmWidthBytes = BITMAP_GetWidthBytes( width, bpp );
bmpObjPtr->bitmap.bmPlanes = 1; bmpObjPtr->bitmap.bmPlanes = 1;
bmpObjPtr->bitmap.bmBitsPixel = bpp; bmpObjPtr->bitmap.bmBitsPixel = bpp;
bmpObjPtr->bitmap.bmBits = NULL; bmpObjPtr->bitmap.bmBits = NULL;
@ -476,7 +476,8 @@ HGLOBAL16 OBM_LoadCursorIcon( WORD id, BOOL32 fCursor )
bmpXor = (BITMAPOBJ *) GDI_GetObjPtr( descr.bitmap, BITMAP_MAGIC ); bmpXor = (BITMAPOBJ *) GDI_GetObjPtr( descr.bitmap, BITMAP_MAGIC );
bmpAnd = (BITMAPOBJ *) GDI_GetObjPtr( descr.mask, BITMAP_MAGIC ); bmpAnd = (BITMAPOBJ *) GDI_GetObjPtr( descr.mask, BITMAP_MAGIC );
sizeXor = bmpXor->bitmap.bmHeight * bmpXor->bitmap.bmWidthBytes; sizeXor = bmpXor->bitmap.bmHeight * bmpXor->bitmap.bmWidthBytes;
sizeAnd = bmpXor->bitmap.bmHeight * BITMAP_WIDTH_BYTES( bmpXor->bitmap.bmWidth, 1 ); sizeAnd = bmpXor->bitmap.bmHeight *
BITMAP_GetWidthBytes( bmpXor->bitmap.bmWidth, 1 );
if (!(handle = GlobalAlloc16( GMEM_MOVEABLE, if (!(handle = GlobalAlloc16( GMEM_MOVEABLE,
sizeof(CURSORICONINFO) + sizeXor + sizeAnd))) sizeof(CURSORICONINFO) + sizeXor + sizeAnd)))