In CreateDIBSection, the offset into the file mapping does not have to

be a multiple of the memory allocation granularity.
oldstable
James Abbatiello 2001-02-12 19:40:28 +00:00 committed by Alexandre Julliard
parent e19c60ab25
commit c559f3fc69
2 changed files with 23 additions and 4 deletions

View File

@ -3793,6 +3793,7 @@ HBITMAP X11DRV_DIB_CreateDIBSection(
BITMAPINFOHEADER *bi = &bmi->bmiHeader;
INT effHeight, totalSize;
BITMAP bm;
LPVOID mapBits = NULL;
TRACE("format (%ld,%ld), planes %d, bpp %d, size %ld, colors %ld (%s)\n",
bi->biWidth, bi->biHeight, bi->biPlanes, bi->biBitCount,
@ -3814,8 +3815,21 @@ HBITMAP X11DRV_DIB_CreateDIBSection(
? bi->biSizeImage : bm.bmWidthBytes * effHeight;
if (section)
bm.bmBits = MapViewOfFile(section, FILE_MAP_ALL_ACCESS,
0L, offset, totalSize);
{
SYSTEM_INFO SystemInfo;
DWORD mapOffset;
INT mapSize;
GetSystemInfo( &SystemInfo );
mapOffset = offset - (offset % SystemInfo.dwAllocationGranularity);
mapSize = totalSize + (offset - mapOffset);
mapBits = MapViewOfFile( section,
FILE_MAP_ALL_ACCESS,
0L,
mapOffset,
mapSize );
bm.bmBits = (char *)mapBits + (offset - mapOffset);
}
else if (ovr_pitch && offset)
bm.bmBits = (LPVOID) offset;
else {
@ -3916,7 +3930,7 @@ HBITMAP X11DRV_DIB_CreateDIBSection(
if (bm.bmBits)
{
if (section)
UnmapViewOfFile(bm.bmBits), bm.bmBits = NULL;
UnmapViewOfFile(mapBits), bm.bmBits = NULL;
else if (!offset)
VirtualFree(bm.bmBits, 0L, MEM_RELEASE), bm.bmBits = NULL;
}

View File

@ -930,7 +930,12 @@ void DIB_DeleteDIBSection( BITMAPOBJ *bmp )
if (dib->dsBm.bmBits)
{
if (dib->dshSection)
UnmapViewOfFile(dib->dsBm.bmBits);
{
SYSTEM_INFO SystemInfo;
GetSystemInfo( &SystemInfo );
UnmapViewOfFile( (char *)dib->dsBm.bmBits -
(dib->dsOffset % SystemInfo.dwAllocationGranularity) );
}
else if (!dib->dsOffset)
VirtualFree(dib->dsBm.bmBits, 0L, MEM_RELEASE );
}