Cache the calculated color

In desktop area, the next color has high odds to be the same of previous color.
If we cache the value, it can be reused by the next pixel avoiding recalculation.
This optimization can halve the function's processing.
This commit is contained in:
Raul Fernandes 2020-04-10 21:35:39 -03:00 committed by akallabeth
parent 9e1b2eb42e
commit 971be4fe9b

View File

@ -651,15 +651,26 @@ BOOL freerdp_image_copy(BYTE* pDstData, DWORD DstFormat, UINT32 nDstStep, UINT32
const BYTE* srcLine = &pSrcData[(y + nYSrc) * nSrcStep * srcVMultiplier + srcVOffset];
BYTE* dstLine = &pDstData[(y + nYDst) * nDstStep * dstVMultiplier + dstVOffset];
for (x = 0; x < nWidth; x++)
UINT32 color = ReadColor(&srcLine[nXSrc * srcByte], SrcFormat);
UINT32 oldColor = color;
UINT32 dstColor = FreeRDPConvertColor(color, SrcFormat, DstFormat, palette);
WriteColor(&dstLine[nXDst * dstByte], DstFormat, dstColor);
for (x = 1; x < nWidth; x++)
{
UINT32 dstColor;
UINT32 color = ReadColor(&srcLine[(x + nXSrc) * srcByte], SrcFormat);
color = ReadColor(&srcLine[(x + nXSrc) * srcByte], SrcFormat);
if (color == oldColor)
{
WriteColor(&dstLine[(x + nXDst) * dstByte], DstFormat, dstColor);
}
else
{
oldColor = color;
dstColor = FreeRDPConvertColor(color, SrcFormat, DstFormat, palette);
WriteColor(&dstLine[(x + nXDst) * dstByte], DstFormat, dstColor);
}
}
}
}
return TRUE;
}