void wf_Bitmap_Decompress(wfContext* wfc, rdpBitmap* bitmap, BYTE* data, int width, int height, int bpp, int length, BOOL compressed, int codecId) { int status; UINT16 size; BYTE* pSrcData; BYTE* pDstData; UINT32 SrcSize; UINT32 SrcFormat; UINT32 bytesPerPixel; bytesPerPixel = (bpp + 7) / 8; size = width * height * 4; if (!bitmap->data) bitmap->data = (BYTE*) _aligned_malloc(size, 16); else bitmap->data = (BYTE*) _aligned_realloc(bitmap->data, size, 16); pSrcData = data; SrcSize = (UINT32) length; pDstData = bitmap->data; if (compressed) { if (bpp < 32) { if (!freerdp_client_codecs_prepare(wfc->codecs, FREERDP_CODEC_INTERLEAVED)) return; status = interleaved_decompress(wfc->codecs->interleaved, pSrcData, SrcSize, bpp, &pDstData, PIXEL_FORMAT_XRGB32, width * 4, 0, 0, width, height, NULL); } else { if (!freerdp_client_codecs_prepare(wfc->codecs, FREERDP_CODEC_PLANAR)) return; status = planar_decompress(wfc->codecs->planar, pSrcData, SrcSize, &pDstData, PIXEL_FORMAT_XRGB32, width * 4, 0, 0, width, height, TRUE); } if (status < 0) { WLog_ERR(TAG, "Bitmap Decompression Failed"); return; } } else { SrcFormat = gdi_get_pixel_format(bpp, TRUE); status = freerdp_image_copy(pDstData, PIXEL_FORMAT_XRGB32, width * 4, 0, 0, width, height, pSrcData, SrcFormat, width * bytesPerPixel, 0, 0, NULL); } bitmap->compressed = FALSE; bitmap->length = size; bitmap->bpp = 32; }
BOOL gdi_Bitmap_Decompress(rdpContext* context, rdpBitmap* bitmap, BYTE* data, int width, int height, int bpp, int length, BOOL compressed, int codecId) { int status; UINT16 size; BYTE* pSrcData; BYTE* pDstData; UINT32 SrcSize; UINT32 SrcFormat; UINT32 bytesPerPixel; rdpGdi* gdi = context->gdi; bytesPerPixel = (bpp + 7) / 8; size = width * height * 4; bitmap->data = (BYTE*) _aligned_malloc(size, 16); pSrcData = data; SrcSize = (UINT32) length; pDstData = bitmap->data; if (compressed) { if (bpp < 32) { if (!freerdp_client_codecs_prepare(gdi->codecs, FREERDP_CODEC_INTERLEAVED)) return FALSE; status = interleaved_decompress(gdi->codecs->interleaved, pSrcData, SrcSize, bpp, &pDstData, gdi->format, -1, 0, 0, width, height, gdi->palette); } else { if (!freerdp_client_codecs_prepare(gdi->codecs, FREERDP_CODEC_PLANAR)) return FALSE; status = planar_decompress(gdi->codecs->planar, pSrcData, SrcSize, &pDstData, gdi->format, -1, 0, 0, width, height, TRUE); } if (status < 0) { WLog_ERR(TAG, "Bitmap Decompression Failed"); return FALSE; } } else { SrcFormat = gdi_get_pixel_format(bpp, TRUE); status = freerdp_image_copy(pDstData, gdi->format, -1, 0, 0, width, height, pSrcData, SrcFormat, -1, 0, 0, gdi->palette); } bitmap->compressed = FALSE; bitmap->length = size; bitmap->bpp = gdi->dstBpp; return TRUE; }
static BOOL gdi_Bitmap_Decompress(rdpContext* context, rdpBitmap* bitmap, const BYTE* pSrcData, UINT32 DstWidth, UINT32 DstHeight, UINT32 bpp, UINT32 length, BOOL compressed, UINT32 codecId) { UINT32 SrcSize = length; UINT32 SrcFormat; UINT32 bytesPerPixel; rdpGdi* gdi = context->gdi; bitmap->compressed = FALSE; bitmap->format = gdi->dstFormat; bitmap->length = DstWidth * DstHeight * GetBytesPerPixel(bitmap->format); bytesPerPixel = GetBytesPerPixel(bpp); bitmap->data = (BYTE*) _aligned_malloc(bitmap->length, 16); if (!bitmap->data) return FALSE; if (compressed) { if (bpp < 32) { if (!interleaved_decompress(context->codecs->interleaved, pSrcData, SrcSize, DstWidth, DstHeight, bpp, bitmap->data, bitmap->format, 0, 0, 0, DstWidth, DstHeight, &gdi->palette)) return FALSE; } else { if (!planar_decompress(context->codecs->planar, pSrcData, SrcSize, DstWidth, DstHeight, bitmap->data, bitmap->format, 0, 0, 0, DstWidth, DstHeight, TRUE)) return FALSE; } } else { SrcFormat = gdi_get_pixel_format(bpp); if (!freerdp_image_copy(bitmap->data, bitmap->format, 0, 0, 0, DstWidth, DstHeight, pSrcData, SrcFormat, 0, 0, 0, &gdi->palette, FREERDP_FLIP_VERTICAL)) return FALSE; } return TRUE; }
void guac_rdp_bitmap_decompress(rdpContext* context, rdpBitmap* bitmap, UINT8* data, int width, int height, int bpp, int length, BOOL compressed) { #else void guac_rdp_bitmap_decompress(rdpContext* context, rdpBitmap* bitmap, UINT8* data, int width, int height, int bpp, int length, BOOL compressed, int codec_id) { #endif int size = width * height * 4; #ifdef FREERDP_BITMAP_REQUIRES_ALIGNED_MALLOC bitmap->data = (UINT8*) _aligned_malloc(size, 16); #else bitmap->data = (UINT8*) malloc(size); #endif if (compressed) { #ifdef HAVE_RDPCONTEXT_CODECS rdpCodecs* codecs = context->codecs; UINT32* palette = ((rdp_freerdp_context*) context)->palette; /* Decode as interleaved if less than 32 bits per pixel */ if (bpp < 32) { freerdp_client_codecs_prepare(codecs, FREERDP_CODEC_INTERLEAVED); interleaved_decompress(codecs->interleaved, data, length, bpp, &(bitmap->data), PIXEL_FORMAT_XRGB32, -1, 0, 0, width, height, (BYTE*) palette); } /* Otherwise, decode as planar */ else { freerdp_client_codecs_prepare(codecs, FREERDP_CODEC_PLANAR); planar_decompress(codecs->planar, data, length, &(bitmap->data), PIXEL_FORMAT_XRGB32, -1, 0, 0, width, height, TRUE); } bitmap->bpp = 32; #else bitmap_decompress(data, bitmap->data, width, height, length, bpp, bpp); bitmap->bpp = bpp; #endif } else { freerdp_image_flip(data, bitmap->data, width, height, bpp); bitmap->bpp = bpp; } bitmap->compressed = FALSE; bitmap->length = size; }
static void gdi_bitmap_update(rdpContext* context, BITMAP_UPDATE* bitmapUpdate) { int status; int nXDst; int nYDst; int nXSrc; int nYSrc; int nWidth; int nHeight; int nSrcStep; int nDstStep; UINT32 index; BYTE* pSrcData; BYTE* pDstData; UINT32 SrcSize; BOOL compressed; UINT32 SrcFormat; UINT32 bitsPerPixel; BITMAP_DATA* bitmap; rdpGdi* gdi = context->gdi; rdpCodecs* codecs = context->codecs; for (index = 0; index < bitmapUpdate->number; index++) { bitmap = &(bitmapUpdate->rectangles[index]); nXSrc = 0; nYSrc = 0; nXDst = bitmap->destLeft; nYDst = bitmap->destTop; nWidth = bitmap->width; nHeight = bitmap->height; pSrcData = bitmap->bitmapDataStream; SrcSize = bitmap->bitmapLength; compressed = bitmap->compressed; bitsPerPixel = bitmap->bitsPerPixel; if (gdi->bitmap_size < (nWidth * nHeight * 4)) { gdi->bitmap_size = nWidth * nHeight * 4; gdi->bitmap_buffer = (BYTE*) _aligned_realloc(gdi->bitmap_buffer, gdi->bitmap_size, 16); if (!gdi->bitmap_buffer) return; } if (compressed) { pDstData = gdi->bitmap_buffer; if (bitsPerPixel < 32) { freerdp_client_codecs_prepare(codecs, FREERDP_CODEC_INTERLEAVED); status = interleaved_decompress(codecs->interleaved, pSrcData, SrcSize, bitsPerPixel, &pDstData, gdi->format, -1, 0, 0, nWidth, nHeight, gdi->palette); } else { freerdp_client_codecs_prepare(codecs, FREERDP_CODEC_PLANAR); status = planar_decompress(codecs->planar, pSrcData, SrcSize, &pDstData, gdi->format, -1, 0, 0, nWidth, nHeight, TRUE); } if (status < 0) { WLog_ERR(TAG, "bitmap decompression failure"); return; } pSrcData = gdi->bitmap_buffer; } else { pDstData = gdi->bitmap_buffer; SrcFormat = gdi_get_pixel_format(bitsPerPixel, TRUE); status = freerdp_image_copy(pDstData, gdi->format, -1, 0, 0, nWidth, nHeight, pSrcData, SrcFormat, -1, 0, 0, gdi->palette); pSrcData = gdi->bitmap_buffer; } nSrcStep = nWidth * gdi->bytesPerPixel; pDstData = gdi->primary_buffer; nDstStep = gdi->width * gdi->bytesPerPixel; nWidth = bitmap->destRight - bitmap->destLeft + 1; /* clip width */ nHeight = bitmap->destBottom - bitmap->destTop + 1; /* clip height */ status = freerdp_image_copy(pDstData, gdi->format, nDstStep, nXDst, nYDst, nWidth, nHeight, pSrcData, gdi->format, nSrcStep, nXSrc, nYSrc, gdi->palette); gdi_InvalidateRegion(gdi->primary->hdc, nXDst, nYDst, nWidth, nHeight); } }
void xf_gdi_bitmap_update(rdpContext* context, BITMAP_UPDATE* bitmapUpdate) { int status; int nXDst; int nYDst; int nXSrc; int nYSrc; int nWidth; int nHeight; UINT32 index; XImage* image; BYTE* pSrcData; BYTE* pDstData; UINT32 SrcSize; BOOL compressed; UINT32 SrcFormat; UINT32 bitsPerPixel; UINT32 bytesPerPixel; BITMAP_DATA* bitmap; rdpCodecs* codecs = context->codecs; xfContext* xfc = (xfContext*) context; for (index = 0; index < bitmapUpdate->number; index++) { bitmap = &(bitmapUpdate->rectangles[index]); nXSrc = 0; nYSrc = 0; nXDst = bitmap->destLeft; nYDst = bitmap->destTop; nWidth = bitmap->width; nHeight = bitmap->height; pSrcData = bitmap->bitmapDataStream; SrcSize = bitmap->bitmapLength; compressed = bitmap->compressed; bitsPerPixel = bitmap->bitsPerPixel; bytesPerPixel = (bitsPerPixel + 7) / 8; SrcFormat = gdi_get_pixel_format(bitsPerPixel, TRUE); if (xfc->bitmap_size < (nWidth * nHeight * 4)) { xfc->bitmap_size = nWidth * nHeight * 4; xfc->bitmap_buffer = (BYTE*) _aligned_realloc(xfc->bitmap_buffer, xfc->bitmap_size, 16); if (!xfc->bitmap_buffer) return; } if (compressed) { pDstData = xfc->bitmap_buffer; if (bitsPerPixel < 32) { freerdp_client_codecs_prepare(codecs, FREERDP_CODEC_INTERLEAVED); status = interleaved_decompress(codecs->interleaved, pSrcData, SrcSize, bitsPerPixel, &pDstData, xfc->format, -1, 0, 0, nWidth, nHeight, xfc->palette); } else { freerdp_client_codecs_prepare(codecs, FREERDP_CODEC_PLANAR); status = planar_decompress(codecs->planar, pSrcData, SrcSize, &pDstData, xfc->format, -1, 0, 0, nWidth, nHeight, TRUE); } if (status < 0) { WLog_ERR(TAG, "bitmap decompression failure"); return; } pSrcData = xfc->bitmap_buffer; } else { pDstData = xfc->bitmap_buffer; status = freerdp_image_copy(pDstData, xfc->format, -1, 0, 0, nWidth, nHeight, pSrcData, SrcFormat, -1, 0, 0, xfc->palette); pSrcData = xfc->bitmap_buffer; } xf_lock_x11(xfc, FALSE); XSetFunction(xfc->display, xfc->gc, GXcopy); image = XCreateImage(xfc->display, xfc->visual, xfc->depth, ZPixmap, 0, (char*) pSrcData, nWidth, nHeight, xfc->scanline_pad, 0); nWidth = bitmap->destRight - bitmap->destLeft + 1; /* clip width */ nHeight = bitmap->destBottom - bitmap->destTop + 1; /* clip height */ XPutImage(xfc->display, xfc->primary, xfc->gc, image, 0, 0, nXDst, nYDst, nWidth, nHeight); XFree(image); gdi_InvalidateRegion(xfc->hdc, nXDst, nYDst, nWidth, nHeight); xf_unlock_x11(xfc, FALSE); } }
void guac_rdp_bitmap_decompress(rdpContext* context, rdpBitmap* bitmap, UINT8* data, int width, int height, int bpp, int length, BOOL compressed) { #else void guac_rdp_bitmap_decompress(rdpContext* context, rdpBitmap* bitmap, UINT8* data, int width, int height, int bpp, int length, BOOL compressed, int codec_id) { #endif int size = width * height * 4; #ifdef FREERDP_BITMAP_REQUIRES_ALIGNED_MALLOC /* Free pre-existing data, if any (might be reused) */ if (bitmap->data != NULL) _aligned_free(bitmap->data); /* Allocate new data */ bitmap->data = (UINT8*) _aligned_malloc(size, 16); #else /* Free pre-existing data, if any (might be reused) */ free(bitmap->data); /* Allocate new data */ bitmap->data = (UINT8*) malloc(size); #endif if (compressed) { #ifdef HAVE_RDPCONTEXT_CODECS rdpCodecs* codecs = context->codecs; /* Decode as interleaved if less than 32 bits per pixel */ if (bpp < 32) { freerdp_client_codecs_prepare(codecs, FREERDP_CODEC_INTERLEAVED); #ifdef INTERLEAVED_DECOMPRESS_TAKES_PALETTE interleaved_decompress(codecs->interleaved, data, length, bpp, &(bitmap->data), PIXEL_FORMAT_XRGB32, -1, 0, 0, width, height, (BYTE*) ((rdp_freerdp_context*) context)->palette); bitmap->bpp = 32; #else interleaved_decompress(codecs->interleaved, data, length, bpp, &(bitmap->data), PIXEL_FORMAT_XRGB32, -1, 0, 0, width, height); bitmap->bpp = bpp; #endif } /* Otherwise, decode as planar */ else { freerdp_client_codecs_prepare(codecs, FREERDP_CODEC_PLANAR); #ifdef PLANAR_DECOMPRESS_CAN_FLIP planar_decompress(codecs->planar, data, length, &(bitmap->data), PIXEL_FORMAT_XRGB32, -1, 0, 0, width, height, TRUE); bitmap->bpp = 32; #else planar_decompress(codecs->planar, data, length, &(bitmap->data), PIXEL_FORMAT_XRGB32, -1, 0, 0, width, height); bitmap->bpp = bpp; #endif } #else bitmap_decompress(data, bitmap->data, width, height, length, bpp, bpp); bitmap->bpp = bpp; #endif } else { freerdp_image_flip(data, bitmap->data, width, height, bpp); bitmap->bpp = bpp; } bitmap->compressed = FALSE; bitmap->length = size; }