From 0e94ac663d5c709e46e1a398b6cb43454d5c047f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Moreau?= Date: Mon, 16 Mar 2015 14:01:43 -0400 Subject: [PATCH] libfreerdp-codec: add support for 16 color palette image copy --- libfreerdp/codec/color.c | 68 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/libfreerdp/codec/color.c b/libfreerdp/codec/color.c index 490dff714..01ea26ad0 100644 --- a/libfreerdp/codec/color.c +++ b/libfreerdp/codec/color.c @@ -1720,6 +1720,74 @@ int freerdp_image1_copy(BYTE* pDstData, DWORD DstFormat, int nDstStep, int nXDst int freerdp_image4_copy(BYTE* pDstData, DWORD DstFormat, int nDstStep, int nXDst, int nYDst, int nWidth, int nHeight, BYTE* pSrcData, DWORD SrcFormat, int nSrcStep, int nXSrc, int nYSrc, BYTE* palette) { + int x, y; + int nSrcPad; + int nDstPad; + int nAlignedWidth; + int dstBitsPerPixel; + int dstBytesPerPixel; + BOOL vFlip = FALSE; + BOOL invert = FALSE; + + dstBitsPerPixel = FREERDP_PIXEL_FORMAT_DEPTH(DstFormat); + dstBytesPerPixel = (FREERDP_PIXEL_FORMAT_BPP(DstFormat) / 8); + + nAlignedWidth = nWidth + (nWidth % 2); + + if (nSrcStep < 0) + nSrcStep = nAlignedWidth / 2; + + if (nDstStep < 0) + nDstStep = dstBytesPerPixel * nWidth; + + nSrcPad = (nSrcStep - (nAlignedWidth / 2)); + nDstPad = (nDstStep - (nWidth * dstBytesPerPixel)); + + if (FREERDP_PIXEL_FORMAT_IS_ABGR(DstFormat)) + invert = TRUE; + + if (FREERDP_PIXEL_FORMAT_FLIP(DstFormat) == FREERDP_PIXEL_FLIP_VERTICAL) + vFlip = TRUE; + + if (dstBytesPerPixel == 4) + { + BYTE* pSrcPixel; + UINT32* pDstPixel; + UINT32* values = (UINT32*) palette; + + if (!invert) + { + if (!vFlip) + { + pSrcPixel = &pSrcData[nYSrc * nSrcStep]; + pDstPixel = (UINT32*) &pDstData[(nYDst * nDstStep) + (nXDst * 4)]; + + for (y = 0; y < nHeight; y++) + { + for (x = 0; x < nWidth / 2; x++) + { + pDstPixel[0] = values[*pSrcPixel >> 4]; + pDstPixel[1] = values[*pSrcPixel & 0xF]; + pDstPixel += 2; + pSrcPixel++; + } + + if (nWidth % 2) + { + pDstPixel[0] = values[*pSrcPixel >> 4]; + pDstPixel++; + pSrcPixel++; + } + + pSrcPixel += nSrcPad; + pDstPixel = (UINT32*) &((BYTE*) pDstPixel)[nDstPad]; + } + } + } + + return 1; + } + return 1; }