From 57b0e4d01008474b5beaa9fb058bc6e0f823f0c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Moreau?= Date: Thu, 19 Jun 2014 13:08:07 -0400 Subject: [PATCH] libfreerdp-codec: handle flipping in planar decompression --- client/X11/xf_gfx.c | 2 +- libfreerdp/codec/bitmap_decode.c | 2 +- libfreerdp/codec/planar.c | 60 ++++++++++++++++++++++++-------- 3 files changed, 48 insertions(+), 16 deletions(-) diff --git a/client/X11/xf_gfx.c b/client/X11/xf_gfx.c index 98b4bb437..c4336a6fd 100644 --- a/client/X11/xf_gfx.c +++ b/client/X11/xf_gfx.c @@ -307,7 +307,7 @@ int xf_SurfaceCommand_Planar(xfContext* xfc, RdpgfxClientContext* context, RDPGF PIXEL_FORMAT_XRGB32, cmd->width * 4, 0, 0, cmd->width, cmd->height); freerdp_image_copy(surface->data, PIXEL_FORMAT_XRGB32, surface->scanline, cmd->left, cmd->top, - cmd->width, cmd->height, DstData, PIXEL_FORMAT_XRGB32_VF, cmd->width * 4, 0, 0); + cmd->width, cmd->height, DstData, PIXEL_FORMAT_XRGB32, cmd->width * 4, 0, 0); free(DstData); diff --git a/libfreerdp/codec/bitmap_decode.c b/libfreerdp/codec/bitmap_decode.c index 74ae94a74..c5232d988 100644 --- a/libfreerdp/codec/bitmap_decode.c +++ b/libfreerdp/codec/bitmap_decode.c @@ -276,7 +276,7 @@ BOOL bitmap_decompress(BYTE* srcData, BYTE* dstData, int width, int height, int pDstData = dstData; status = planar_decompress(NULL, srcData, size, &pDstData, - PIXEL_FORMAT_XRGB32, width * 4, 0, 0, width, height); + PIXEL_FORMAT_XRGB32_VF, width * 4, 0, 0, width, height); if (status < 0) return FALSE; diff --git a/libfreerdp/codec/planar.c b/libfreerdp/codec/planar.c index 9b57f33cb..15ac70f9f 100644 --- a/libfreerdp/codec/planar.c +++ b/libfreerdp/codec/planar.c @@ -29,7 +29,7 @@ #include "planar.h" static int planar_decompress_plane_rle(BYTE* pSrcData, UINT32 SrcSize, BYTE* pDstData, - int nDstStep, int nXDst, int nYDst, int nWidth, int nHeight, int nChannel) + int nDstStep, int nXDst, int nYDst, int nWidth, int nHeight, int nChannel, BOOL vFlip) { int x, y; BYTE* srcp; @@ -38,6 +38,7 @@ static int planar_decompress_plane_rle(BYTE* pSrcData, UINT32 SrcSize, BYTE* pDs int cRawBytes; int nRunLength; int deltaValue; + int beg, end, inc; BYTE controlByte; BYTE* currentScanline; BYTE* previousScanline; @@ -46,10 +47,24 @@ static int planar_decompress_plane_rle(BYTE* pSrcData, UINT32 SrcSize, BYTE* pDs dstp = pDstData; previousScanline = NULL; - for (y = 0; y < nHeight; y++) + if (vFlip) { + beg = nHeight - 1; + end = -1; + inc = -1; + } + else + { + beg = 0; + end = nHeight; + inc = 1; + } + + for (y = beg; y != end; y += inc) + { + dstp = &pDstData[(y * nDstStep) + nChannel]; + pixel = 0; - dstp = &pDstData[((nHeight - y - 1) * nDstStep) + nChannel]; currentScanline = dstp; for (x = 0; x < nWidth; ) @@ -152,15 +167,29 @@ static int planar_decompress_plane_rle(BYTE* pSrcData, UINT32 SrcSize, BYTE* pDs } static int planar_decompress_plane_raw(BYTE* pSrcData, UINT32 SrcSize, BYTE* pDstData, - int nDstStep, int nXDst, int nYDst, int nWidth, int nHeight, int nChannel) + int nDstStep, int nXDst, int nYDst, int nWidth, int nHeight, int nChannel, BOOL vFlip) { int x, y; + int beg, end, inc; BYTE* dstp = NULL; BYTE* srcp = pSrcData; - for (y = 0; y < nHeight; y++) + if (vFlip) { - dstp = &pDstData[((nHeight - y - 1) * nDstStep) + nChannel]; + beg = nHeight - 1; + end = -1; + inc = -1; + } + else + { + beg = 0; + end = nHeight; + inc = 1; + } + + for (y = beg; y != end; y += inc) + { + dstp = &pDstData[(y * nDstStep) + nChannel]; for (x = 0; x < nWidth; x++) { @@ -178,6 +207,7 @@ int planar_decompress(BITMAP_PLANAR_CONTEXT* planar, BYTE* pSrcData, UINT32 SrcS { int status; BYTE* srcp; + BOOL vFlip; BYTE FormatHeader; BYTE* pDstData = NULL; UINT32 UncompressedSize; @@ -185,6 +215,8 @@ int planar_decompress(BITMAP_PLANAR_CONTEXT* planar, BYTE* pSrcData, UINT32 SrcS if ((nWidth * nHeight) <= 0) return -1; + vFlip = FREERDP_PIXEL_FORMAT_FLIP(DstFormat) ? TRUE : FALSE; + srcp = pSrcData; UncompressedSize = nWidth * nHeight * 4; @@ -210,7 +242,7 @@ int planar_decompress(BITMAP_PLANAR_CONTEXT* planar, BYTE* pSrcData, UINT32 SrcS if (FormatHeader & PLANAR_FORMAT_HEADER_RLE) { status = planar_decompress_plane_rle(srcp, SrcSize - (srcp - pSrcData), - pDstData, nDstStep, nXDst, nYDst, nWidth, nHeight, 3); + pDstData, nDstStep, nXDst, nYDst, nWidth, nHeight, 3, vFlip); if (status < 0) return -1; @@ -220,7 +252,7 @@ int planar_decompress(BITMAP_PLANAR_CONTEXT* planar, BYTE* pSrcData, UINT32 SrcS else { status = planar_decompress_plane_raw(srcp, SrcSize - (srcp - pSrcData), - pDstData, nDstStep, nXDst, nYDst, nWidth, nHeight, 3); + pDstData, nDstStep, nXDst, nYDst, nWidth, nHeight, 3, vFlip); if (status < 0) return -1; @@ -234,7 +266,7 @@ int planar_decompress(BITMAP_PLANAR_CONTEXT* planar, BYTE* pSrcData, UINT32 SrcS /* LumaOrRedPlane */ status = planar_decompress_plane_rle(srcp, SrcSize - (srcp - pSrcData), - pDstData, nDstStep, nXDst, nYDst, nWidth, nHeight, 2); + pDstData, nDstStep, nXDst, nYDst, nWidth, nHeight, 2, vFlip); if (status < 0) return -1; @@ -244,7 +276,7 @@ int planar_decompress(BITMAP_PLANAR_CONTEXT* planar, BYTE* pSrcData, UINT32 SrcS /* OrangeChromaOrGreenPlane */ status = planar_decompress_plane_rle(srcp, SrcSize - (srcp - pSrcData), - pDstData, nDstStep, nXDst, nYDst, nWidth, nHeight, 1); + pDstData, nDstStep, nXDst, nYDst, nWidth, nHeight, 1, vFlip); if (status < 0) return -1; @@ -254,7 +286,7 @@ int planar_decompress(BITMAP_PLANAR_CONTEXT* planar, BYTE* pSrcData, UINT32 SrcS /* GreenChromeOrBluePlane */ status = planar_decompress_plane_rle(srcp, SrcSize - (srcp - pSrcData), - pDstData, nDstStep, nXDst, nYDst, nWidth, nHeight, 0); + pDstData, nDstStep, nXDst, nYDst, nWidth, nHeight, 0, vFlip); if (status < 0) return -1; @@ -266,7 +298,7 @@ int planar_decompress(BITMAP_PLANAR_CONTEXT* planar, BYTE* pSrcData, UINT32 SrcS /* LumaOrRedPlane */ status = planar_decompress_plane_raw(srcp, SrcSize - (srcp - pSrcData), - pDstData, nDstStep, nXDst, nYDst, nWidth, nHeight, 2); + pDstData, nDstStep, nXDst, nYDst, nWidth, nHeight, 2, vFlip); if (status < 0) return -1; @@ -276,7 +308,7 @@ int planar_decompress(BITMAP_PLANAR_CONTEXT* planar, BYTE* pSrcData, UINT32 SrcS /* OrangeChromaOrGreenPlane */ status = planar_decompress_plane_raw(srcp, SrcSize - (srcp - pSrcData), - pDstData, nDstStep, nXDst, nYDst, nWidth, nHeight, 1); + pDstData, nDstStep, nXDst, nYDst, nWidth, nHeight, 1, vFlip); if (status < 0) return -1; @@ -286,7 +318,7 @@ int planar_decompress(BITMAP_PLANAR_CONTEXT* planar, BYTE* pSrcData, UINT32 SrcS /* GreenChromeOrBluePlane */ status = planar_decompress_plane_raw(srcp, SrcSize - (srcp - pSrcData), - pDstData, nDstStep, nXDst, nYDst, nWidth, nHeight, 0); + pDstData, nDstStep, nXDst, nYDst, nWidth, nHeight, 0, vFlip); if (status < 0) return -1;