mirror of
https://github.com/reactos/reactos.git
synced 2024-12-28 10:04:49 +00:00
Fix some bugs in DIB mapping code to prevent instant system crashes.
svn path=/trunk/; revision=16737
This commit is contained in:
parent
11c02111f0
commit
e0cd2dc6bf
1 changed files with 32 additions and 10 deletions
|
@ -175,7 +175,7 @@ IntSetDIBits(
|
||||||
RECTL DestRect;
|
RECTL DestRect;
|
||||||
XLATEOBJ *XlateObj;
|
XLATEOBJ *XlateObj;
|
||||||
PPALGDI hDCPalette;
|
PPALGDI hDCPalette;
|
||||||
//RGBQUAD *lpRGB;
|
//RGBQUAD *lpRGB;
|
||||||
HPALETTE DDB_Palette, DIB_Palette;
|
HPALETTE DDB_Palette, DIB_Palette;
|
||||||
ULONG DDB_Palette_Type, DIB_Palette_Type;
|
ULONG DDB_Palette_Type, DIB_Palette_Type;
|
||||||
INT DIBWidth;
|
INT DIBWidth;
|
||||||
|
@ -190,7 +190,7 @@ IntSetDIBits(
|
||||||
//if (ColorUse == DIB_PAL_COLORS)
|
//if (ColorUse == DIB_PAL_COLORS)
|
||||||
// lpRGB = DIB_MapPaletteColors(hDC, bmi);
|
// lpRGB = DIB_MapPaletteColors(hDC, bmi);
|
||||||
//else
|
//else
|
||||||
// lpRGB = &bmi->bmiColors[0];
|
// lpRGB = &bmi->bmiColors;
|
||||||
|
|
||||||
DestSurf = &bitmap->SurfObj;
|
DestSurf = &bitmap->SurfObj;
|
||||||
|
|
||||||
|
@ -810,6 +810,7 @@ DIB_CreateDIBSection(
|
||||||
UINT Entries = 0;
|
UINT Entries = 0;
|
||||||
BITMAP bm;
|
BITMAP bm;
|
||||||
SIZEL Size;
|
SIZEL Size;
|
||||||
|
RGBQUAD *lpRGB;
|
||||||
|
|
||||||
DPRINT("format (%ld,%ld), planes %d, bpp %d, size %ld, colors %ld (%s)\n",
|
DPRINT("format (%ld,%ld), planes %d, bpp %d, size %ld, colors %ld (%s)\n",
|
||||||
bi->biWidth, bi->biHeight, bi->biPlanes, bi->biBitCount,
|
bi->biWidth, bi->biHeight, bi->biPlanes, bi->biBitCount,
|
||||||
|
@ -846,7 +847,9 @@ DIB_CreateDIBSection(
|
||||||
}
|
}
|
||||||
|
|
||||||
if(usage == DIB_PAL_COLORS)
|
if(usage == DIB_PAL_COLORS)
|
||||||
memcpy(bmi->bmiColors, (UINT *)DIB_MapPaletteColors(dc, bmi), sizeof(UINT *));
|
lpRGB = DIB_MapPaletteColors(dc, bmi);
|
||||||
|
else
|
||||||
|
lpRGB = bmi->bmiColors;
|
||||||
|
|
||||||
// Allocate Memory for DIB and fill structure
|
// Allocate Memory for DIB and fill structure
|
||||||
if (bm.bmBits)
|
if (bm.bmBits)
|
||||||
|
@ -869,9 +872,9 @@ DIB_CreateDIBSection(
|
||||||
else switch(bi->biBitCount)
|
else switch(bi->biBitCount)
|
||||||
{
|
{
|
||||||
case 16:
|
case 16:
|
||||||
dib->dsBitfields[0] = (bi->biCompression == BI_BITFIELDS) ? *(DWORD *)bmi->bmiColors : 0x7c00;
|
dib->dsBitfields[0] = (bi->biCompression == BI_BITFIELDS) ? *(DWORD *)lpRGB : 0x7c00;
|
||||||
dib->dsBitfields[1] = (bi->biCompression == BI_BITFIELDS) ? *((DWORD *)bmi->bmiColors + 1) : 0x03e0;
|
dib->dsBitfields[1] = (bi->biCompression == BI_BITFIELDS) ? *((DWORD *)lpRGB + 1) : 0x03e0;
|
||||||
dib->dsBitfields[2] = (bi->biCompression == BI_BITFIELDS) ? *((DWORD *)bmi->bmiColors + 2) : 0x001f; break;
|
dib->dsBitfields[2] = (bi->biCompression == BI_BITFIELDS) ? *((DWORD *)lpRGB + 2) : 0x001f; break;
|
||||||
|
|
||||||
case 24:
|
case 24:
|
||||||
dib->dsBitfields[0] = 0xff0000;
|
dib->dsBitfields[0] = 0xff0000;
|
||||||
|
@ -880,9 +883,9 @@ DIB_CreateDIBSection(
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 32:
|
case 32:
|
||||||
dib->dsBitfields[0] = (bi->biCompression == BI_BITFIELDS) ? *(DWORD *)bmi->bmiColors : 0xff0000;
|
dib->dsBitfields[0] = (bi->biCompression == BI_BITFIELDS) ? *(DWORD *)lpRGB : 0xff0000;
|
||||||
dib->dsBitfields[1] = (bi->biCompression == BI_BITFIELDS) ? *((DWORD *)bmi->bmiColors + 1) : 0x00ff00;
|
dib->dsBitfields[1] = (bi->biCompression == BI_BITFIELDS) ? *((DWORD *)lpRGB + 1) : 0x00ff00;
|
||||||
dib->dsBitfields[2] = (bi->biCompression == BI_BITFIELDS) ? *((DWORD *)bmi->bmiColors + 2) : 0x0000ff;
|
dib->dsBitfields[2] = (bi->biCompression == BI_BITFIELDS) ? *((DWORD *)lpRGB + 2) : 0x0000ff;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
dib->dshSection = section;
|
dib->dshSection = section;
|
||||||
|
@ -901,12 +904,20 @@ DIB_CreateDIBSection(
|
||||||
bm.bmBits);
|
bm.bmBits);
|
||||||
if (! res)
|
if (! res)
|
||||||
{
|
{
|
||||||
|
if (lpRGB != bmi->bmiColors)
|
||||||
|
{
|
||||||
|
ExFreePool(lpRGB);
|
||||||
|
}
|
||||||
SetLastWin32Error(ERROR_NO_SYSTEM_RESOURCES);
|
SetLastWin32Error(ERROR_NO_SYSTEM_RESOURCES);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
bmp = BITMAPOBJ_LockBitmap(res);
|
bmp = BITMAPOBJ_LockBitmap(res);
|
||||||
if (NULL == bmp)
|
if (NULL == bmp)
|
||||||
{
|
{
|
||||||
|
if (lpRGB != bmi->bmiColors)
|
||||||
|
{
|
||||||
|
ExFreePool(lpRGB);
|
||||||
|
}
|
||||||
SetLastWin32Error(ERROR_INVALID_HANDLE);
|
SetLastWin32Error(ERROR_INVALID_HANDLE);
|
||||||
NtGdiDeleteObject(bmp);
|
NtGdiDeleteObject(bmp);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -921,7 +932,7 @@ DIB_CreateDIBSection(
|
||||||
if(bi->biBitCount == 8) { Entries = 256; }
|
if(bi->biBitCount == 8) { Entries = 256; }
|
||||||
|
|
||||||
if (Entries)
|
if (Entries)
|
||||||
bmp->hDIBPalette = PALETTE_AllocPaletteIndexedRGB(Entries, bmi->bmiColors);
|
bmp->hDIBPalette = PALETTE_AllocPaletteIndexedRGB(Entries, lpRGB);
|
||||||
else
|
else
|
||||||
bmp->hDIBPalette = PALETTE_AllocPalette(PAL_BITFIELDS, 0, NULL,
|
bmp->hDIBPalette = PALETTE_AllocPalette(PAL_BITFIELDS, 0, NULL,
|
||||||
dib->dsBitfields[0],
|
dib->dsBitfields[0],
|
||||||
|
@ -946,6 +957,11 @@ DIB_CreateDIBSection(
|
||||||
if (res) { BITMAPOBJ_FreeBitmap(res); res = 0; }
|
if (res) { BITMAPOBJ_FreeBitmap(res); res = 0; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (lpRGB != bmi->bmiColors)
|
||||||
|
{
|
||||||
|
ExFreePool(lpRGB);
|
||||||
|
}
|
||||||
|
|
||||||
if (bmp)
|
if (bmp)
|
||||||
{
|
{
|
||||||
BITMAPOBJ_UnlockBitmap(bmp);
|
BITMAPOBJ_UnlockBitmap(bmp);
|
||||||
|
@ -1097,6 +1113,12 @@ DIB_MapPaletteColors(PDC dc, CONST BITMAPINFO* lpbmi)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (palGDI->Mode != PAL_INDEXED)
|
||||||
|
{
|
||||||
|
PALETTE_UnlockPalette(palGDI);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
nNumColors = 1 << lpbmi->bmiHeader.biBitCount;
|
nNumColors = 1 << lpbmi->bmiHeader.biBitCount;
|
||||||
if (lpbmi->bmiHeader.biClrUsed)
|
if (lpbmi->bmiHeader.biClrUsed)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue