Fixes for upside-down DIBs.

This commit is contained in:
Huw D M Davies 1999-04-18 12:07:00 +00:00 committed by Alexandre Julliard
parent 251ed43b98
commit 608629bc13
6 changed files with 42 additions and 26 deletions

View file

@ -74,7 +74,7 @@ static BOOL MFDRV_CreatePatternBrush(DC *dc, HBRUSH16 hBrush,
return FALSE;
}
bmSize = bm.bmHeight * DIB_GetDIBWidthBytes(bm.bmWidth, 1);
bmSize = DIB_GetDIBImageBytes(bm.bmWidth, bm.bmHeight, 1);
len = sizeof(METARECORD) + sizeof(WORD) + sizeof(BITMAPINFO) +
sizeof(RGBQUAD) + bmSize;
@ -106,9 +106,9 @@ static BOOL MFDRV_CreatePatternBrush(DC *dc, HBRUSH16 hBrush,
if (info->bmiHeader.biCompression)
bmSize = info->bmiHeader.biSizeImage;
else
bmSize = DIB_GetDIBWidthBytes(info->bmiHeader.biWidth,
info->bmiHeader.biBitCount)
* info->bmiHeader.biHeight;
bmSize = DIB_GetDIBImageBytes(info->bmiHeader.biWidth,
info->bmiHeader.biHeight,
info->bmiHeader.biBitCount);
biSize = DIB_BitmapInfoSize(info, LOWORD(logbrush->lbColor));
len = sizeof(METARECORD) + biSize + bmSize + 2;
mr = HeapAlloc(SystemHeap, HEAP_ZERO_MEMORY, len);

View file

@ -1880,9 +1880,10 @@ INT X11DRV_DIB_GetDIBits(
LeaveCriticalSection( &X11DRV_CritSection );
if(info->bmiHeader.biSizeImage == 0) /* Fill in biSizeImage */
info->bmiHeader.biSizeImage = info->bmiHeader.biHeight *
DIB_GetDIBWidthBytes( info->bmiHeader.biWidth,
info->bmiHeader.biBitCount );
info->bmiHeader.biSizeImage = DIB_GetDIBImageBytes(
info->bmiHeader.biWidth,
info->bmiHeader.biHeight,
info->bmiHeader.biBitCount );
if(bbits - (BYTE *)bits > info->bmiHeader.biSizeImage)
ERR(bitmap, "Buffer overrun. Please investigate.\n");

View file

@ -55,6 +55,7 @@ extern HBITMAP BITMAP_CopyBitmap( HBITMAP hbitmap );
/* objects/dib.c */
extern int DIB_GetDIBWidthBytes( int width, int depth );
extern int DIB_GetDIBImageBytes( int width, int height, int depth );
extern int DIB_BitmapInfoSize( BITMAPINFO * info, WORD coloruse );
extern int DIB_GetBitmapInfo( const BITMAPINFOHEADER *header, DWORD *width,
int *height, WORD *bpp, WORD *compr );

View file

@ -114,9 +114,9 @@ HBRUSH16 WINAPI CreateDIBPatternBrush16( HGLOBAL16 hbitmap, UINT16 coloruse )
if (info->bmiHeader.biCompression)
size = info->bmiHeader.biSizeImage;
else
size = DIB_GetDIBWidthBytes(info->bmiHeader.biWidth,
info->bmiHeader.biBitCount) *
info->bmiHeader.biHeight;
size = DIB_GetDIBImageBytes(info->bmiHeader.biWidth,
info->bmiHeader.biHeight,
info->bmiHeader.biBitCount);
size += DIB_BitmapInfoSize( info, coloruse );
if (!(logbrush.lbHatch = (INT16)GlobalAlloc16( GMEM_MOVEABLE, size )))
@ -164,9 +164,9 @@ HBRUSH WINAPI CreateDIBPatternBrush(
if (info->bmiHeader.biCompression)
size = info->bmiHeader.biSizeImage;
else
size = DIB_GetDIBWidthBytes(info->bmiHeader.biWidth,
info->bmiHeader.biBitCount) *
info->bmiHeader.biHeight;
size = DIB_GetDIBImageBytes(info->bmiHeader.biWidth,
info->bmiHeader.biHeight,
info->bmiHeader.biBitCount);
size += DIB_BitmapInfoSize( info, coloruse );
if (!(logbrush.lbHatch = (INT)GlobalAlloc16( GMEM_MOVEABLE, size )))
@ -204,7 +204,8 @@ HBRUSH WINAPI CreateDIBPatternBrushPt(
BITMAPINFO *newInfo;
INT size;
TRACE(gdi, "%p\n", info );
TRACE(gdi, "%p %ldx%ld %dbpp\n", info, info->bmiHeader.biWidth,
info->bmiHeader.biHeight, info->bmiHeader.biBitCount);
/* Make a copy of the bitmap */
@ -212,9 +213,9 @@ HBRUSH WINAPI CreateDIBPatternBrushPt(
if (info->bmiHeader.biCompression)
size = info->bmiHeader.biSizeImage;
else
size = DIB_GetDIBWidthBytes(info->bmiHeader.biWidth,
info->bmiHeader.biBitCount) *
info->bmiHeader.biHeight;
size = DIB_GetDIBImageBytes(info->bmiHeader.biWidth,
info->bmiHeader.biHeight,
info->bmiHeader.biBitCount);
size += DIB_BitmapInfoSize( info, coloruse );
if (!(logbrush.lbHatch = (INT)GlobalAlloc16( GMEM_MOVEABLE, size )))

View file

@ -524,9 +524,10 @@ static HGLOBAL16 CURSORICON_CreateFromResource( HINSTANCE16 hInstance, HGLOBAL16
CBM_INIT, (char*)bmi + size, pInfo, DIB_RGB_COLORS );
if( hXorBits )
{
char* bits = (char *)bmi + size + bmi->bmiHeader.biHeight *
DIB_GetDIBWidthBytes(bmi->bmiHeader.biWidth,
bmi->bmiHeader.biBitCount) / 2;
char* bits = (char *)bmi + size +
DIB_GetDIBImageBytes(bmi->bmiHeader.biWidth,
bmi->bmiHeader.biHeight,
bmi->bmiHeader.biBitCount) / 2;
pInfo->bmiHeader.biBitCount = 1;
if (pInfo->bmiHeader.biSize == sizeof(BITMAPINFOHEADER))

View file

@ -40,6 +40,16 @@ int DIB_GetDIBWidthBytes( int width, int depth )
return 4 * words;
}
/***********************************************************************
* DIB_GetDIBImageBytes
*
* Return the number of bytes used to hold the image in a DIB bitmap.
*/
int DIB_GetDIBImageBytes( int width, int height, int depth )
{
return DIB_GetDIBWidthBytes( width, depth ) * abs( height );
}
/***********************************************************************
* DIB_BitmapInfoSize
@ -537,16 +547,18 @@ INT WINAPI GetDIBits(
info->bmiHeader.biHeight = bmp->bitmap.bmHeight;
info->bmiHeader.biPlanes = 1;
info->bmiHeader.biBitCount = bmp->bitmap.bmBitsPixel;
info->bmiHeader.biSizeImage = bmp->bitmap.bmHeight *
DIB_GetDIBWidthBytes( bmp->bitmap.bmWidth,
bmp->bitmap.bmBitsPixel );
info->bmiHeader.biSizeImage =
DIB_GetDIBImageBytes( bmp->bitmap.bmWidth,
bmp->bitmap.bmHeight,
bmp->bitmap.bmBitsPixel );
info->bmiHeader.biCompression = 0;
}
else
{
info->bmiHeader.biSizeImage = info->bmiHeader.biHeight *
DIB_GetDIBWidthBytes( info->bmiHeader.biWidth,
info->bmiHeader.biBitCount );
info->bmiHeader.biSizeImage = DIB_GetDIBImageBytes(
info->bmiHeader.biWidth,
info->bmiHeader.biHeight,
info->bmiHeader.biBitCount );
}
}