Bug : 1452 : patch from w3seek, some xlate obj fixes for indexed palettes, should fix a hack introduced in r21292

svn path=/trunk/; revision=21794
This commit is contained in:
Magnus Olsen 2006-05-04 05:23:54 +00:00
parent 6da2349338
commit bb9e90f468
2 changed files with 33 additions and 32 deletions

View file

@ -158,9 +158,6 @@ typedef struct _XLATEGDI {
INT GreenShift;
INT BlueShift;
// };
// struct { /* For Table Translations */
ULONG *translationTable;
// };
// struct { /* For Color -> Mono Translations */
ULONG BackgroundColor;
// };

View file

@ -181,6 +181,7 @@ IntEngCreateXlate(USHORT DestPalType, USHORT SourcePalType,
XlateObj->iSrcType = SourcePalType;
XlateObj->iDstType = DestPalType;
XlateObj->flXlate = 0;
XlateObj->cEntries = 0;
/* Store handles of palettes in internal Xlate GDI object (or NULLs) */
XlateGDI->SourcePal = PaletteSource;
@ -237,34 +238,34 @@ IntEngCreateXlate(USHORT DestPalType, USHORT SourcePalType,
/* Indexed -> Indexed */
if (SourcePalType == PAL_INDEXED && DestPalType == PAL_INDEXED)
{
XlateGDI->translationTable =
EngAllocMem(0, sizeof(ULONG) * SourcePalGDI->NumColors, 0);
XlateObj->cEntries = SourcePalGDI->NumColors;
XlateObj->pulXlate =
EngAllocMem(0, sizeof(ULONG) * XlateObj->cEntries, 0);
XlateObj->flXlate |= XO_TRIVIAL;
for (i = 0; i < SourcePalGDI->NumColors; i++)
for (i = 0; i < XlateObj->cEntries; i++)
{
XlateGDI->translationTable[i] = ClosestColorMatch(
XlateObj->pulXlate[i] = ClosestColorMatch(
XlateGDI, SourcePalGDI->IndexedColors + i,
DestPalGDI->IndexedColors, DestPalGDI->NumColors);
if (XlateGDI->translationTable[i] != i)
DestPalGDI->IndexedColors, XlateObj->cEntries);
if (XlateObj->pulXlate[i] != i)
XlateObj->flXlate &= ~XO_TRIVIAL;
}
XlateObj->flXlate |= XO_TABLE;
XlateObj->pulXlate = XlateGDI->translationTable;
goto end;
}
/* Indexed -> Bitfields/RGB/BGR */
if (SourcePalType == PAL_INDEXED)
{
XlateGDI->translationTable =
EngAllocMem(0, sizeof(ULONG) * SourcePalGDI->NumColors, 0);
for (i = 0; i < SourcePalGDI->NumColors; i++)
XlateGDI->translationTable[i] =
XlateObj->cEntries = SourcePalGDI->NumColors;
XlateObj->pulXlate =
EngAllocMem(0, sizeof(ULONG) * XlateObj->cEntries, 0);
for (i = 0; i < XlateObj->cEntries; i++)
XlateObj->pulXlate[i] =
ShiftAndMask(XlateGDI, *((ULONG *)&SourcePalGDI->IndexedColors[i]));
XlateObj->flXlate |= XO_TABLE;
XlateObj->pulXlate = XlateGDI->translationTable;
goto end;
}
@ -313,6 +314,7 @@ IntEngCreateMonoXlate(
XlateGDI->SourcePal = PaletteSource;
XlateObj->flXlate = XO_TO_MONO;
XlateObj->cEntries = 1;
XlateObj->pulXlate = &XlateGDI->BackgroundColor;
switch (SourcePalType)
{
@ -368,16 +370,15 @@ IntEngCreateSrcMonoXlate(HPALETTE PaletteDest,
}
XlateObj = GDIToObj(XlateGDI, XLATE);
XlateGDI->translationTable = EngAllocMem(0, sizeof(ULONG) * 2, 0);
if (XlateGDI->translationTable == NULL)
XlateObj->cEntries = 2;
XlateObj->pulXlate = EngAllocMem(0, sizeof(ULONG) * XlateObj->cEntries, 0);
if (XlateObj->pulXlate == NULL)
{
PALETTE_UnlockPalette(DestPalGDI);
EngFreeMem(XlateGDI);
return NULL;
}
XlateObj->pulXlate = XlateGDI->translationTable;
XlateObj->iSrcType = PAL_INDEXED;
XlateObj->iDstType = DestPalGDI->Mode;
@ -394,19 +395,19 @@ IntEngCreateSrcMonoXlate(HPALETTE PaletteDest,
XlateGDI->GreenShift = CalculateShift(RGB(0x00, 0xFF, 0x00)) - CalculateShift(XlateGDI->GreenMask);
XlateGDI->BlueShift = CalculateShift(RGB(0x00, 0x00, 0xFF)) - CalculateShift(XlateGDI->BlueMask);
XlateGDI->translationTable[0] = ShiftAndMask(XlateGDI, BackgroundColor);
XlateGDI->translationTable[1] = ShiftAndMask(XlateGDI, ForegroundColor);
XlateObj->pulXlate[0] = ShiftAndMask(XlateGDI, BackgroundColor);
XlateObj->pulXlate[1] = ShiftAndMask(XlateGDI, ForegroundColor);
if (XlateObj->iDstType == PAL_INDEXED)
{
XlateGDI->translationTable[0] =
XlateObj->pulXlate[0] =
ClosestColorMatch(XlateGDI,
(LPPALETTEENTRY)&XlateGDI->translationTable[0],
(LPPALETTEENTRY)&XlateObj->pulXlate[0],
DestPalGDI->IndexedColors,
DestPalGDI->NumColors);
XlateGDI->translationTable[1] =
XlateObj->pulXlate[1] =
ClosestColorMatch(XlateGDI,
(LPPALETTEENTRY)&XlateGDI->translationTable[1],
(LPPALETTEENTRY)&XlateObj->pulXlate[1],
DestPalGDI->IndexedColors,
DestPalGDI->NumColors);
}
@ -453,9 +454,9 @@ EngDeleteXlate(XLATEOBJ *XlateObj)
XlateGDI = ObjToGDI(XlateObj, XLATE);
if ((XlateObj->flXlate & XO_TABLE) &&
XlateGDI->translationTable != NULL)
XlateObj->pulXlate != NULL)
{
EngFreeMem(XlateGDI->translationTable);
EngFreeMem(XlateObj->pulXlate);
}
EngFreeMem(XlateGDI);
@ -467,11 +468,9 @@ EngDeleteXlate(XLATEOBJ *XlateObj)
PULONG STDCALL
XLATEOBJ_piVector(XLATEOBJ *XlateObj)
{
XLATEGDI *XlateGDI = ObjToGDI(XlateObj, XLATE);
if (XlateObj->iSrcType == PAL_INDEXED)
{
return XlateGDI->translationTable;
return XlateObj->pulXlate;
}
return NULL;
@ -494,8 +493,13 @@ XLATEOBJ_iXlate(XLATEOBJ *XlateObj, ULONG Color)
if (XlateObj->flXlate & XO_TRIVIAL)
return Color;
if ((XlateObj->flXlate & XO_TABLE))
return XlateObj->pulXlate[Color & 0xff];
if (XlateObj->flXlate & XO_TABLE)
{
if (Color >= XlateObj->cEntries)
Color %= XlateObj->cEntries;
return XlateObj->pulXlate[Color];
}
if (XlateObj->flXlate & XO_TO_MONO)