From e42ee26d9a40139847b1bf48b50dfc977e2754b9 Mon Sep 17 00:00:00 2001 From: Huw D M Davies Date: Sat, 27 Mar 1999 15:59:12 +0000 Subject: [PATCH] Fixed {S|G}etBitmapBits in x11drv. Removed BITMAP_GetPadding. --- graphics/x11drv/bitmap.c | 62 ++++++++++++++++++++++++++---------------------- include/bitmap.h | 1 - objects/bitmap.c | 40 ------------------------------- 3 files changed, 33 insertions(+), 70 deletions(-) diff --git a/graphics/x11drv/bitmap.c b/graphics/x11drv/bitmap.c index c5323b8301e..ea677d0c1a8 100644 --- a/graphics/x11drv/bitmap.c +++ b/graphics/x11drv/bitmap.c @@ -254,16 +254,11 @@ static LONG X11DRV_GetBitmapBits(BITMAPOBJ *bmp, void *buffer, LONG count) { LONG old_height, height; XImage *image; - LPBYTE tbuf; - int h, w, pad; + LPBYTE tbuf, startline; + int h, w; TRACE(x11drv, "(bmp=%p, buffer=%p, count=0x%lx)\n", bmp, buffer, count); - pad = BITMAP_GetPadding(bmp->bitmap.bmWidth, bmp->bitmap.bmBitsPixel); - - if (pad == -1) - return 0; - EnterCriticalSection( &X11DRV_CritSection ); /* Hack: change the bitmap height temporarily to avoid */ @@ -278,12 +273,13 @@ static LONG X11DRV_GetBitmapBits(BITMAPOBJ *bmp, void *buffer, LONG count) /* copy XImage to 16 bit padded image buffer with real bitsperpixel */ - tbuf = buffer; + startline = buffer; switch (bmp->bitmap.bmBitsPixel) { case 1: for (h=0;hbitmap.bmWidth;w++) { @@ -292,32 +288,35 @@ static LONG X11DRV_GetBitmapBits(BITMAPOBJ *bmp, void *buffer, LONG count) *tbuf |= XGetPixel(image,w,h)<<(7-(w&7)); if ((w&7) == 7) ++tbuf; } - tbuf += pad; + startline += bmp->bitmap.bmWidthBytes; } break; case 4: for (h=0;hbitmap.bmWidth;w++) { if (!(w & 1)) *tbuf = XGetPixel( image, w, h) << 4; else *tbuf++ |= XGetPixel( image, w, h) & 0x0f; } - tbuf += pad; + startline += bmp->bitmap.bmWidthBytes; } break; case 8: for (h=0;hbitmap.bmWidth;w++) *tbuf++ = XGetPixel(image,w,h); - tbuf += pad; + startline += bmp->bitmap.bmWidthBytes; } break; case 15: case 16: for (h=0;hbitmap.bmWidth;w++) { long pixel = XGetPixel(image,w,h); @@ -325,11 +324,13 @@ static LONG X11DRV_GetBitmapBits(BITMAPOBJ *bmp, void *buffer, LONG count) *tbuf++ = pixel & 0xff; *tbuf++ = (pixel>>8) & 0xff; } + startline += bmp->bitmap.bmWidthBytes; } break; case 24: for (h=0;hbitmap.bmWidth;w++) { long pixel = XGetPixel(image,w,h); @@ -338,13 +339,14 @@ static LONG X11DRV_GetBitmapBits(BITMAPOBJ *bmp, void *buffer, LONG count) *tbuf++ = (pixel>> 8) & 0xff; *tbuf++ = (pixel>>16) & 0xff; } - tbuf += pad; + startline += bmp->bitmap.bmWidthBytes; } break; case 32: for (h=0;hbitmap.bmWidth;w++) { long pixel = XGetPixel(image,w,h); @@ -354,7 +356,7 @@ static LONG X11DRV_GetBitmapBits(BITMAPOBJ *bmp, void *buffer, LONG count) *tbuf++ = (pixel>>16) & 0xff; *tbuf++ = (pixel>>24) & 0xff; } - tbuf += pad; + startline += bmp->bitmap.bmWidthBytes; } break; default: @@ -380,18 +382,11 @@ static LONG X11DRV_SetBitmapBits(BITMAPOBJ *bmp, void *bits, LONG count) struct XPutImage_descr descr; LONG height; XImage *image; - LPBYTE sbuf; - int w, h, pad; + LPBYTE sbuf, startline; + int w, h; TRACE(x11drv, "(bmp=%p, bits=%p, count=0x%lx)\n", bmp, bits, count); - pad = BITMAP_GetPadding(bmp->bitmap.bmWidth, bmp->bitmap.bmBitsPixel); - - if (pad == -1) - return 0; - - sbuf = (LPBYTE)bits; - height = count / bmp->bitmap.bmWidthBytes; EnterCriticalSection( &X11DRV_CritSection ); @@ -401,71 +396,80 @@ static LONG X11DRV_SetBitmapBits(BITMAPOBJ *bmp, void *bits, LONG count) image->data = (LPBYTE)xmalloc(image->bytes_per_line * height); /* copy 16 bit padded image buffer with real bitsperpixel to XImage */ - sbuf = (LPBYTE)bits; + + startline = bits; + switch (bmp->bitmap.bmBitsPixel) { case 1: for (h=0;hbitmap.bmWidth;w++) { XPutPixel(image,w,h,(sbuf[0]>>(7-(w&7))) & 1); if ((w&7) == 7) sbuf++; } - sbuf += pad; + startline += bmp->bitmap.bmWidthBytes; } break; case 4: for (h=0;hbitmap.bmWidth;w++) { if (!(w & 1)) XPutPixel( image, w, h, *sbuf >> 4 ); else XPutPixel( image, w, h, *sbuf++ & 0xf ); } - sbuf += pad; + startline += bmp->bitmap.bmWidthBytes; } break; case 8: for (h=0;hbitmap.bmWidth;w++) XPutPixel(image,w,h,*sbuf++); - sbuf += pad; + startline += bmp->bitmap.bmWidthBytes; } break; case 15: case 16: for (h=0;hbitmap.bmWidth;w++) { XPutPixel(image,w,h,sbuf[1]*256+sbuf[0]); sbuf+=2; } + startline += bmp->bitmap.bmWidthBytes; } break; - case 24: + case 24: for (h=0;hbitmap.bmWidth;w++) { XPutPixel(image,w,h,(sbuf[2]<<16)+(sbuf[1]<<8)+sbuf[0]); sbuf += 3; } - sbuf += pad; + startline += bmp->bitmap.bmWidthBytes; } break; case 32: for (h=0;hbitmap.bmWidth;w++) { XPutPixel(image,w,h,(sbuf[3]<<24)+(sbuf[2]<<16)+(sbuf[1]<<8)+sbuf[0]); sbuf += 4; } - sbuf += pad; + startline += bmp->bitmap.bmWidthBytes; } break; default: diff --git a/include/bitmap.h b/include/bitmap.h index 35b58ea43eb..27f0b5c3f06 100644 --- a/include/bitmap.h +++ b/include/bitmap.h @@ -62,7 +62,6 @@ typedef struct tagBITMAPOBJ extern INT16 BITMAP_GetObject16( BITMAPOBJ * bmp, INT16 count, LPVOID buffer ); extern INT BITMAP_GetObject( BITMAPOBJ * bmp, INT count, LPVOID buffer ); extern BOOL BITMAP_DeleteObject( HBITMAP16 hbitmap, BITMAPOBJ * bitmap ); -extern INT BITMAP_GetPadding( INT width, INT depth ); extern INT BITMAP_GetWidthBytes( INT width, INT depth ); extern HBITMAP BITMAP_LoadBitmapW(HINSTANCE instance,LPCWSTR name, UINT loadflags); diff --git a/objects/bitmap.c b/objects/bitmap.c index 05094eba679..bb38dd3eee0 100644 --- a/objects/bitmap.c +++ b/objects/bitmap.c @@ -20,46 +20,6 @@ #include "monitor.h" #include "wine/winuser16.h" -/*********************************************************************** - * BITMAP_GetPadding - * - * Return number of bytes to pad a scanline of 16-bit aligned Windows DDB data. - */ -INT BITMAP_GetPadding( int bmWidth, int bpp ) -{ - INT pad; - - switch (bpp) - { - case 1: - pad = ((bmWidth-1) & 8) ? 0 : 1; - break; - - case 8: - pad = (2 - (bmWidth & 1)) & 1; - break; - - case 24: - pad = (bmWidth*3) & 1; - break; - - case 32: - case 16: - case 15: - pad = 0; /* we have 16bit alignment already */ - break; - - case 4: - if (!(bmWidth & 3)) pad = 0; - else pad = ((4 - (bmWidth & 3)) + 1) / 2; - break; - - default: - WARN(bitmap,"Unknown depth %d, please report.\n", bpp ); - return -1; - } - return pad; -} /*********************************************************************** * BITMAP_GetWidthBytes -- 2.11.4.GIT