From 0acc54a4f7b9a61e4362b20feb30e4db19ab6f4f Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Thu, 19 Jan 2017 16:40:58 +0100 Subject: [PATCH 1/5] Fixed scanline for RFX. --- client/X11/xf_gdi.c | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/client/X11/xf_gdi.c b/client/X11/xf_gdi.c index 07b365026..d7e972a69 100644 --- a/client/X11/xf_gdi.c +++ b/client/X11/xf_gdi.c @@ -972,7 +972,7 @@ static BOOL xf_gdi_surface_update_frame(xfContext* xfc, UINT16 tx, UINT16 ty, static BOOL xf_gdi_update_screen(xfContext* xfc, const SURFACE_BITS_COMMAND* cmd, - const BYTE* pSrcData) + const BYTE* pSrcData, UINT32 scanline) { BOOL ret = FALSE; XImage* image; @@ -983,7 +983,8 @@ static BOOL xf_gdi_update_screen(xfContext* xfc, XSetFunction(xfc->display, xfc->gc, GXcopy); XSetFillStyle(xfc->display, xfc->gc, FillSolid); image = XCreateImage(xfc->display, xfc->visual, xfc->depth, ZPixmap, 0, - (char*) pSrcData, cmd->width, cmd->height, xfc->scanline_pad, 0); + (char*) pSrcData, cmd->width, cmd->height, + xfc->scanline_pad, scanline); if (image) { @@ -1005,14 +1006,12 @@ static BOOL xf_gdi_surface_bits(rdpContext* context, xfContext* xfc = (xfContext*) context; BOOL ret = FALSE; DWORD format; - DWORD stride; rdpGdi* gdi; if (!context || !cmd || !context->gdi) return FALSE; gdi = context->gdi; - stride = cmd->width * GetBytesPerPixel(gdi->dstFormat); xf_lock_x11(xfc, FALSE); switch (cmd->codecID) @@ -1020,18 +1019,16 @@ static BOOL xf_gdi_surface_bits(rdpContext* context, case RDP_CODEC_ID_REMOTEFX: if (!rfx_process_message(context->codecs->rfx, cmd->bitmapData, cmd->bitmapDataLength, 0, 0, - gdi->primary_buffer, gdi->dstFormat, stride, + gdi->primary_buffer, gdi->dstFormat, gdi->stride, gdi->height, NULL)) goto fail; break; case RDP_CODEC_ID_NSCODEC: - format = gdi->dstFormat; - if (!nsc_process_message(context->codecs->nsc, cmd->bpp, cmd->width, cmd->height, cmd->bitmapData, cmd->bitmapDataLength, - gdi->primary_buffer, format, stride, + gdi->primary_buffer, gdi->dstFormat, gdi->stride, 0, 0, cmd->width, cmd->height, FREERDP_FLIP_VERTICAL)) goto fail; @@ -1041,10 +1038,10 @@ static BOOL xf_gdi_surface_bits(rdpContext* context, pSrcData = cmd->bitmapData; format = gdi_get_pixel_format(cmd->bpp); - if (!freerdp_image_copy(gdi->primary_buffer, gdi->dstFormat, stride, - 0, 0, - cmd->width, cmd->height, pSrcData, - format, 0, 0, 0, &xfc->context.gdi->palette, FREERDP_FLIP_VERTICAL)) + if (!freerdp_image_copy(gdi->primary_buffer, gdi->dstFormat, gdi->stride, + 0, 0, cmd->width, cmd->height, + pSrcData, format, 0, 0, 0, + &xfc->context.gdi->palette, FREERDP_FLIP_VERTICAL)) goto fail; break; @@ -1055,7 +1052,7 @@ static BOOL xf_gdi_surface_bits(rdpContext* context, goto fail; } - ret = xf_gdi_update_screen(xfc, cmd, gdi->primary_buffer); + ret = xf_gdi_update_screen(xfc, cmd, gdi->primary_buffer, gdi->stride); fail: xf_unlock_x11(xfc, FALSE); return ret; From 6188a12b37704f1bf2ffe8df8001490957d46c64 Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Thu, 19 Jan 2017 17:13:07 +0100 Subject: [PATCH 2/5] Fixed planar with if local framebuffer is 16bpp --- libfreerdp/codec/planar.c | 76 ++++++++++++++++++++++++++++----------- 1 file changed, 55 insertions(+), 21 deletions(-) diff --git a/libfreerdp/codec/planar.c b/libfreerdp/codec/planar.c index d67ad2643..07af15d48 100644 --- a/libfreerdp/codec/planar.c +++ b/libfreerdp/codec/planar.c @@ -223,12 +223,57 @@ static INLINE INT32 planar_decompress_plane_rle(const BYTE* pSrcData, UINT32 Src return (INT32)(srcp - pSrcData); } +static INLINE BOOL writeLine(BYTE** ppRgba, UINT32 DstFormat, UINT32 width, const BYTE** ppR, + const BYTE** ppG, const BYTE** ppB, const BYTE** ppA) +{ + UINT32 x; + + if (!ppRgba || !ppR || !ppG || !ppB) + return FALSE; + + switch (DstFormat) + { + case PIXEL_FORMAT_BGRA32: + for (x = 0; x < width; x++) + { + *(*ppRgba)++ = *(*ppB)++; + *(*ppRgba)++ = *(*ppG)++; + *(*ppRgba)++ = *(*ppR)++; + *(*ppRgba)++ = *(*ppA)++; + } + + return TRUE; + + case PIXEL_FORMAT_BGRX32: + for (x = 0; x < width; x++) + { + *(*ppRgba)++ = *(*ppB)++; + *(*ppRgba)++ = *(*ppG)++; + *(*ppRgba)++ = *(*ppR)++; + *(*ppRgba)++ = *(*ppA)++; + } + + return TRUE; + + default: + for (x = 0; x < width; x++) + { + BYTE alpha = (ppA) ? *(*ppA)++ : 0xFF; + UINT32 color = GetColor(DstFormat, *(*ppR)++, *(*ppG)++, *(*ppB)++, alpha); + WriteColor(*ppRgba, DstFormat, color); + *ppRgba += GetBytesPerPixel(DstFormat); + } + + return TRUE; + } +} + static INLINE BOOL planar_decompress_planes_raw(const BYTE* pSrcData[4], BYTE* pDstData, UINT32 DstFormat, UINT32 nDstStep, UINT32 nXDst, UINT32 nYDst, UINT32 nWidth, UINT32 nHeight, BOOL alpha, BOOL vFlip) { - INT32 x, y; + INT32 y; INT32 beg, end, inc; const BYTE* pR = pSrcData[0]; const BYTE* pG = pSrcData[1]; @@ -255,12 +300,8 @@ static INLINE BOOL planar_decompress_planes_raw(const BYTE* pSrcData[4], BYTE* pRGB = &pDstData[((nYDst + y) * nDstStep) + (nXDst * GetBytesPerPixel( DstFormat))]; - for (x = 0; x < nWidth; x++) - { - UINT32 color = GetColor(DstFormat, *pR++, *pG++, *pB++, *pA++); - WriteColor(pRGB, DstFormat, color); - pRGB += GetBytesPerPixel(DstFormat); - } + if (!writeLine(&pRGB, DstFormat, nWidth, &pR, &pG, &pB, &pA)) + return FALSE; } } else @@ -270,12 +311,8 @@ static INLINE BOOL planar_decompress_planes_raw(const BYTE* pSrcData[4], BYTE* pRGB = &pDstData[((nYDst + y) * nDstStep) + (nXDst * GetBytesPerPixel( DstFormat))]; - for (x = 0; x < nWidth; x++) - { - UINT32 color = GetColor(DstFormat, *pR++, *pG++, *pB++, 0xFF); - WriteColor(pRGB, DstFormat, color); - pRGB += GetBytesPerPixel(DstFormat); - } + if (!writeLine(&pRGB, DstFormat, nWidth, &pR, &pG, &pB, &pA)) + return FALSE; } } @@ -304,15 +341,11 @@ BOOL planar_decompress(BITMAP_PLANAR_CONTEXT* planar, UINT32 rawWidths[4]; UINT32 rawHeights[4]; BYTE FormatHeader; - UINT32 dstBitsPerPixel; - UINT32 dstBytesPerPixel; - const BYTE* planes[4]; UINT32 UncompressedSize; + const BYTE* planes[4]; const UINT32 w = MIN(nSrcWidth, nDstWidth); const UINT32 h = MIN(nSrcHeight, nDstHeight); const primitives_t* prims = primitives_get(); - dstBitsPerPixel = GetBitsPerPixel(DstFormat); - dstBytesPerPixel = GetBytesPerPixel(DstFormat); if (nDstStep <= 0) nDstStep = nDstWidth * GetBytesPerPixel(DstFormat); @@ -470,13 +503,14 @@ BOOL planar_decompress(BITMAP_PLANAR_CONTEXT* planar, || (nSrcHeight != nDstHeight)) { pTempData = planar->pTempData; + nTempStep = planar->nTempStep; } if (!rle) /* RAW */ { if (alpha) { - if (!planar_decompress_planes_raw(planes, pTempData, TempFormat, nDstStep, + if (!planar_decompress_planes_raw(planes, pTempData, TempFormat, nTempStep, nXDst, nYDst, nSrcWidth, nSrcHeight, alpha, vFlip)) return FALSE; @@ -484,7 +518,7 @@ BOOL planar_decompress(BITMAP_PLANAR_CONTEXT* planar, } else /* NoAlpha */ { - if (!planar_decompress_planes_raw(planes, pTempData, TempFormat, nDstStep, + if (!planar_decompress_planes_raw(planes, pTempData, TempFormat, nTempStep, nXDst, nYDst, nSrcWidth, nSrcHeight, alpha, vFlip)) return FALSE; @@ -573,7 +607,7 @@ BOOL planar_decompress(BITMAP_PLANAR_CONTEXT* planar, { BYTE* pTempData = planar->pTempData; UINT32 nTempStep = planar->nTempStep; - UINT32 TempFormat = PIXEL_FORMAT_RGBA32; + UINT32 TempFormat = PIXEL_FORMAT_BGRA32; if (!pTempData) return FALSE; From b32c241b9fe415908cefa837a91a985409fb5771 Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Thu, 19 Jan 2017 17:14:16 +0100 Subject: [PATCH 3/5] Fixed color format selection for 16bpp --- client/X11/xf_graphics.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/client/X11/xf_graphics.c b/client/X11/xf_graphics.c index 2cfd6e1aa..fa6b40262 100644 --- a/client/X11/xf_graphics.c +++ b/client/X11/xf_graphics.c @@ -71,7 +71,6 @@ static BOOL xf_Bitmap_New(rdpContext* context, rdpBitmap* bitmap) BYTE* data; Pixmap pixmap; XImage* image; - UINT32 SrcFormat; rdpGdi* gdi; xfContext* xfc = (xfContext*) context; gdi = context->gdi; @@ -93,10 +92,9 @@ static BOOL xf_Bitmap_New(rdpContext* context, rdpBitmap* bitmap) return FALSE; } - SrcFormat = bitmap->format; freerdp_image_copy(data, gdi->dstFormat, 0, 0, 0, bitmap->width, bitmap->height, - bitmap->data, SrcFormat, + bitmap->data, bitmap->format, 0, 0, 0, &context->gdi->palette, FREERDP_FLIP_NONE); _aligned_free(bitmap->data); bitmap->data = data; @@ -490,7 +488,7 @@ BOOL xf_register_graphics(rdpGraphics* graphics) UINT32 xf_get_local_color_format(xfContext* xfc, BOOL aligned) { UINT32 DstFormat; - BOOL invert = !(aligned ^ xfc->invert); + BOOL invert = xfc->invert; if (!xfc) return 0; @@ -505,9 +503,9 @@ UINT32 xf_get_local_color_format(xfContext* xfc, BOOL aligned) DstFormat = (!invert) ? PIXEL_FORMAT_RGB24 : PIXEL_FORMAT_BGR24; } else if (xfc->depth == 16) - DstFormat = (!invert) ? PIXEL_FORMAT_RGB16 : PIXEL_FORMAT_BGR16; + DstFormat = PIXEL_FORMAT_RGB16; else if (xfc->depth == 15) - DstFormat = (!invert) ? PIXEL_FORMAT_RGB16 : PIXEL_FORMAT_BGR16; + DstFormat = PIXEL_FORMAT_RGB15; else DstFormat = (!invert) ? PIXEL_FORMAT_RGBX32 : PIXEL_FORMAT_BGRX32; From 6ceb57440242164a07db18988f8999343afbd72d Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Thu, 19 Jan 2017 17:16:25 +0100 Subject: [PATCH 4/5] Fixed staging surface scanline. --- client/X11/xf_gfx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/X11/xf_gfx.c b/client/X11/xf_gfx.c index 8f2be9b17..9b229055d 100644 --- a/client/X11/xf_gfx.c +++ b/client/X11/xf_gfx.c @@ -275,7 +275,7 @@ static UINT xf_CreateSurface(RdpgfxClientContext* context, surface->image = XCreateImage(xfc->display, xfc->visual, xfc->depth, ZPixmap, 0, (char*) surface->stage, surface->gdi.width, surface->gdi.height, - xfc->scanline_pad, surface->gdi.scanline); + xfc->scanline_pad, surface->stageScanline); } surface->gdi.outputMapped = FALSE; From 00c32f62d3845234f300d140ab5b987c3c1e1c9f Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Mon, 23 Jan 2017 09:26:56 +0100 Subject: [PATCH 5/5] Fixed alpha channel for color formats without. --- libfreerdp/codec/planar.c | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/libfreerdp/codec/planar.c b/libfreerdp/codec/planar.c index 07af15d48..585634b3d 100644 --- a/libfreerdp/codec/planar.c +++ b/libfreerdp/codec/planar.c @@ -250,18 +250,32 @@ static INLINE BOOL writeLine(BYTE** ppRgba, UINT32 DstFormat, UINT32 width, cons *(*ppRgba)++ = *(*ppB)++; *(*ppRgba)++ = *(*ppG)++; *(*ppRgba)++ = *(*ppR)++; - *(*ppRgba)++ = *(*ppA)++; + *(*ppRgba)++ = 0xFF; } return TRUE; default: - for (x = 0; x < width; x++) + if (ppA) { - BYTE alpha = (ppA) ? *(*ppA)++ : 0xFF; - UINT32 color = GetColor(DstFormat, *(*ppR)++, *(*ppG)++, *(*ppB)++, alpha); - WriteColor(*ppRgba, DstFormat, color); - *ppRgba += GetBytesPerPixel(DstFormat); + for (x = 0; x < width; x++) + { + BYTE alpha = *(*ppA)++; + UINT32 color = GetColor(DstFormat, *(*ppR)++, *(*ppG)++, *(*ppB)++, alpha); + WriteColor(*ppRgba, DstFormat, color); + *ppRgba += GetBytesPerPixel(DstFormat); + } + } + else + { + const BYTE alpha = 0xFF; + + for (x = 0; x < width; x++) + { + UINT32 color = GetColor(DstFormat, *(*ppR)++, *(*ppG)++, *(*ppB)++, alpha); + WriteColor(*ppRgba, DstFormat, color); + *ppRgba += GetBytesPerPixel(DstFormat); + } } return TRUE;