libfreerdp-codec: add new freerdp_image_copy function with detailed parameters

This commit is contained in:
Marc-André Moreau 2014-02-28 21:51:29 -05:00
parent 004ad2123e
commit c697941de2
3 changed files with 273 additions and 5 deletions

View File

@ -23,19 +23,115 @@
#include <freerdp/api.h>
#include <freerdp/freerdp.h>
#define FREERDP_PIXEL_FORMAT_TYPE_A 0
#define FREERDP_PIXEL_FORMAT_TYPE_ARGB 1
#define FREERDP_PIXEL_FORMAT_TYPE_ABGR 2
#define FREERDP_PIXEL_FORMAT_TYPE_BGRA 3
#define FREERDP_PIXEL_FORMAT_TYPE_RGBA 4
#define FREERDP_PIXEL_FLIP_NONE 0
#define FREERDP_PIXEL_FLIP_VERTICAL 1
#define FREERDP_PIXEL_FLIP_HORIZONTAL 2
#define FREERDP_PIXEL_FORMAT(_bpp, _type, _flip) \
((_bpp << 24) | (_type << 16) | (_flip << 8))
#define FREERDP_PIXEL_FORMAT(_bpp, _type, _a, _r, _g, _b) \
((_bpp << 24) | (_type << 16) | (_a << 12) | (_r << 8) | (_g << 4) | (_b))
#define FREERDP_PIXEL_FORMAT_BPP(_format) (((_format) >> 24) & 0xFF)
#define FREERDP_PIXEL_FORMAT_FLIP(_format) (((_format) >> 30) & 0x02)
#define FREERDP_PIXEL_FORMAT_BPP(_format) (((_format) >> 24) & 0x3F)
#define FREERDP_PIXEL_FORMAT_TYPE(_format) (((_format) >> 16) & 0xFF)
#define FREERDP_PIXEL_FORMAT_FLIP(_format) (((_format) >> 8) & 0xFF)
#define FREERDP_PIXEL_FORMAT_A(_format) (((_format) >> 12) & 0x0F)
#define FREERDP_PIXEL_FORMAT_R(_format) (((_format) >> 8) & 0x0F)
#define FREERDP_PIXEL_FORMAT_G(_format) (((_format) >> 4) & 0x0F)
#define FREERDP_PIXEL_FORMAT_B(_format) (((_format) ) & 0x0F)
#define FREERDP_PIXEL_FORMAT_RGB(_format) (((_format) ) & 0xFFF)
#define FREERDP_PIXEL_FORMAT_VIS(_format) (((_format) ) & 0xFFFF)
#define FREERDP_PIXEL_FORMAT_DEPTH(_format) \
(FREERDP_PIXEL_FORMAT_A(_format) + \
FREERDP_PIXEL_FORMAT_R(_format) + \
FREERDP_PIXEL_FORMAT_G(_format) + \
FREERDP_PIXEL_FORMAT_B(_format))
/* 32bpp formats */
#define PIXEL_FORMAT_A8R8G8B8 FREERDP_PIXEL_FORMAT(32, FREERDP_PIXEL_FORMAT_TYPE_ARGB, 8, 8, 8, 8)
#define PIXEL_FORMAT_ARGB32 PIXEL_FORMAT_A8R8G8B8
#define PIXEL_FORMAT_X8R8G8B8 FREERDP_PIXEL_FORMAT(32, FREERDP_PIXEL_FORMAT_TYPE_ARGB, 0, 8, 8, 8)
#define PIXEL_FORMAT_XRGB32 PIXEL_FORMAT_X8R8G8B8
#define PIXEL_FORMAT_RGB32 PIXEL_FORMAT_XRGB32
#define PIXEL_FORMAT_A8B8G8R8 FREERDP_PIXEL_FORMAT(32, FREERDP_PIXEL_FORMAT_TYPE_ABGR, 8, 8, 8, 8)
#define PIXEL_FORMAT_ABGR32 PIXEL_FORMAT_A8B8G8R8
#define PIXEL_FORMAT_X8B8G8R8 FREERDP_PIXEL_FORMAT(32, FREERDP_PIXEL_FORMAT_TYPE_ABGR, 0, 8, 8, 8)
#define PIXEL_FORMAT_XBGR32 PIXEL_FORMAT_X8B8G8R8
#define PIXEL_FORMAT_BGR32 PIXEL_FORMAT_XBGR32
#define PIXEL_FORMAT_B8G8R8A8 FREERDP_PIXEL_FORMAT(32, FREERDP_PIXEL_FORMAT_TYPE_BGRA, 8, 8, 8, 8)
#define PIXEL_FORMAT_BGRA32 PIXEL_FORMAT_B8G8R8A8
#define PIXEL_FORMAT_B8G8R8X8 FREERDP_PIXEL_FORMAT(32, FREERDP_PIXEL_FORMAT_TYPE_BGRA, 0, 8, 8, 8)
#define PIXEL_FORMAT_BGRX32 PIXEL_FORMAT_B8G8R8X8
#define PIXEL_FORMAT_R8G8B8A8 FREERDP_PIXEL_FORMAT(32, FREERDP_PIXEL_FORMAT_TYPE_RGBA, 8, 8, 8, 8)
#define PIXEL_FORMAT_RGBA32 PIXEL_FORMAT_R8G8B8A8
#define PIXEL_FORMAT_R8G8B8X8 FREERDP_PIXEL_FORMAT(32, FREERDP_PIXEL_FORMAT_TYPE_RGBA, 0, 8, 8, 8)
#define PIXEL_FORMAT_RGBX32 PIXEL_FORMAT_R8G8B8X8
/* 24bpp formats */
#define PIXEL_FORMAT_R8G8B8 FREERDP_PIXEL_FORMAT(24, FREERDP_PIXEL_FORMAT_TYPE_ARGB, 0, 8, 8, 8)
#define PIXEL_FORMAT_RGB24 PIXEL_FORMAT_R8G8B8
#define PIXEL_FORMAT_B8G8R8 FREERDP_PIXEL_FORMAT(24, FREERDP_PIXEL_FORMAT_TYPE_ABGR, 0, 8, 8, 8)
#define PIXEL_FORMAT_BGR24 PIXEL_FORMAT_B8G8R8
/* 16bpp formats */
#define PIXEL_FORMAT_R5G6B5 FREERDP_PIXEL_FORMAT(16, FREERDP_PIXEL_FORMAT_TYPE_ARGB, 0, 5, 6, 5)
#define PIXEL_FORMAT_RGB565 PIXEL_FORMAT_R5G6B5
#define PIXEL_FORMAT_RGB16 PIXEL_FORMAT_R5G6B5
#define PIXEL_FORMAT_B5G6R5 FREERDP_PIXEL_FORMAT(16, FREERDP_PIXEL_FORMAT_TYPE_ABGR, 0, 5, 6, 5)
#define PIXEL_FORMAT_BGR565 PIXEL_FORMAT_B5G6R5
#define PIXEL_FORMAT_BGR16 PIXEL_FORMAT_B5G6R5
#define PIXEL_FORMAT_A1R5G5B5 FREERDP_PIXEL_FORMAT(16, FREERDP_PIXEL_FORMAT_TYPE_ARGB, 1, 5, 5, 5)
#define PIXEL_FORMAT_ARGB555 PIXEL_FORMAT_A1R5G5B5
#define PIXEL_FORMAT_ARGB15 PIXEL_FORMAT_A1R5G5B5
#define PIXEL_FORMAT_X1R5G5B5 FREERDP_PIXEL_FORMAT(16, FREERDP_PIXEL_FORMAT_TYPE_ARGB, 0, 5, 5, 5)
#define PIXEL_FORMAT_XRGB555 PIXEL_FORMAT_X1R5G5B5
#define PIXEL_FORMAT_RGB555 PIXEL_FORMAT_X1R5G5B5
#define PIXEL_FORMAT_RGB15 PIXEL_FORMAT_X1R5G5B5
#define PIXEL_FORMAT_A1B5G5R5 FREERDP_PIXEL_FORMAT(16, FREERDP_PIXEL_FORMAT_TYPE_ABGR, 1, 5, 5, 5)
#define PIXEL_FORMAT_ABGR555 PIXEL_FORMAT_A1B5G5R5
#define PIXEL_FORMAT_ABGR15 PIXEL_FORMAT_A1B5G5R5
#define PIXEL_FORMAT_X1B5G5R5 FREERDP_PIXEL_FORMAT(16, FREERDP_PIXEL_FORMAT_TYPE_ABGR, 0, 5, 5, 5)
#define PIXEL_FORMAT_XBGR555 PIXEL_FORMAT_X1B5G5R5
#define PIXEL_FORMAT_BGR555 PIXEL_FORMAT_X1B5G5R5
#define PIXEL_FORMAT_BGR15 PIXEL_FORMAT_X1B5G5R5
/* 8bpp formats */
#define PIXEL_FORMAT_A8 FREERDP_PIXEL_FORMAT(8, FREERDP_PIXEL_FORMAT_TYPE_A, 8, 0, 0, 0)
#define PIXEL_FORMAT_8BPP PIXEL_FORMAT_A8
#define PIXEL_FORMAT_256 PIXEL_FORMAT_A8
/* 4 bpp formats */
#define PIXEL_FORMAT_A4 FREERDP_PIXEL_FORMAT(4, FREERDP_PIXEL_FORMAT_TYPE_A, 4, 0, 0, 0)
#define PIXEL_FORMAT_4BPP PIXEL_FORMAT_A4
/* 1bpp formats */
#define PIXEL_FORMAT_A1 FREERDP_PIXEL_FORMAT(1, FREERDP_PIXEL_FORMAT_TYPE_A, 1, 0, 0, 0)
#define PIXEL_FORMAT_1BPP PIXEL_FORMAT_A1
#define PIXEL_FORMAT_MONO PIXEL_FORMAT_A1
#ifdef __cplusplus
extern "C" {
@ -274,6 +370,9 @@ FREERDP_API UINT32 freerdp_color_convert_var_bgr(UINT32 srcColor, int srcBpp, in
FREERDP_API HCLRCONV freerdp_clrconv_new(UINT32 flags);
FREERDP_API void freerdp_clrconv_free(HCLRCONV clrconv);
FREERDP_API int freerdp_image_copy(BYTE* pDstData, DWORD dwDstFormat, int nDstStep, int nXDst, int nYDst,
int nWidth, int nHeight, BYTE* pSrcData, DWORD dwSrcFormat, int nSrcStep, int nXSrc, int nYSrc);
#ifdef __cplusplus
}
#endif

View File

@ -1171,3 +1171,172 @@ void freerdp_clrconv_free(HCLRCONV clrconv)
free(clrconv);
}
}
int freerdp_image_copy(BYTE* pDstData, DWORD dwDstFormat, int nDstStep, int nXDst, int nYDst,
int nWidth, int nHeight, BYTE* pSrcData, DWORD dwSrcFormat, int nSrcStep, int nXSrc, int nYSrc)
{
int i, j;
BYTE a, r, g, b;
int srcBitsPerPixel;
int srcBytesPerPixel;
int dstBitsPerPixel;
int dstBytesPerPixel;
srcBitsPerPixel = FREERDP_PIXEL_FORMAT_DEPTH(dwSrcFormat);
srcBytesPerPixel = (FREERDP_PIXEL_FORMAT_BPP(dwSrcFormat) / 8);
dstBitsPerPixel = FREERDP_PIXEL_FORMAT_DEPTH(dwDstFormat);
dstBytesPerPixel = (FREERDP_PIXEL_FORMAT_BPP(dwDstFormat) / 8);
if (srcBytesPerPixel == 4)
{
if (nSrcStep < 0)
nSrcStep = srcBytesPerPixel * nWidth;
if (srcBitsPerPixel == 24)
{
if (dstBytesPerPixel == 4)
{
if (dstBitsPerPixel == 32)
{
UINT32* pSrcPixel;
UINT32* pDstPixel;
if (nDstStep < 0)
nDstStep = dstBytesPerPixel * nWidth;
pSrcPixel = (UINT32*) &pSrcData[(nYSrc * nSrcStep) + (nXSrc * srcBytesPerPixel)];
pDstPixel = (UINT32*) &pDstData[(nYDst * nDstStep) + (nXDst * dstBytesPerPixel)];
for (i = 0; i < nHeight; i++)
{
for (j = 0; j < nWidth; j++)
{
GetARGB32(a, r, g, b, *pSrcPixel);
*pDstPixel = ARGB32(a, r, g, b);
pSrcPixel++;
pDstPixel++;
}
pSrcPixel = (UINT32*) &((BYTE*) pSrcPixel)[(nSrcStep - (nWidth * srcBytesPerPixel))];
pDstPixel = (UINT32*) &((BYTE*) pDstPixel)[(nDstStep - (nWidth * dstBytesPerPixel))];
}
}
else if (dstBitsPerPixel == 24)
{
UINT32* pSrcPixel;
UINT32* pDstPixel;
if (nDstStep < 0)
nDstStep = dstBytesPerPixel * nWidth;
pSrcPixel = (UINT32*) &pSrcData[(nYSrc * nSrcStep) + (nXSrc * srcBytesPerPixel)];
pDstPixel = (UINT32*) &pDstData[(nYDst * nDstStep) + (nXDst * dstBytesPerPixel)];
for (i = 0; i < nHeight; i++)
{
for (j = 0; j < nWidth; j++)
{
GetRGB32(r, g, b, *pSrcPixel);
*pDstPixel = RGB32(r, g, b);
pSrcPixel++;
pDstPixel++;
}
pSrcPixel = (UINT32*) &((BYTE*) pSrcPixel)[(nSrcStep - (nWidth * srcBytesPerPixel))];
pDstPixel = (UINT32*) &((BYTE*) pDstPixel)[(nDstStep - (nWidth * dstBytesPerPixel))];
}
}
}
else if (dstBytesPerPixel == 3)
{
UINT32* pSrcPixel;
BYTE* pDstPixel;
if (nDstStep < 0)
nDstStep = dstBytesPerPixel * nWidth;
pSrcPixel = (UINT32*) &pSrcData[(nYSrc * nSrcStep) + (nXSrc * srcBytesPerPixel)];
pDstPixel = (BYTE*) &pDstData[(nYDst * nDstStep) + (nXDst * dstBytesPerPixel)];
for (i = 0; i < nHeight; i++)
{
for (j = 0; j < nWidth; j++)
{
GetRGB32(r, g, b, *pSrcPixel);
*(pDstPixel++) = r;
*(pDstPixel++) = g;
*(pDstPixel++) = b;
pSrcPixel++;
}
pSrcPixel = (UINT32*) &((BYTE*) pSrcPixel)[(nSrcStep - (nWidth * srcBytesPerPixel))];
pDstPixel = (BYTE*) &((BYTE*) pDstPixel)[(nDstStep - (nWidth * dstBytesPerPixel))];
}
}
else if (dstBytesPerPixel == 2)
{
if (dstBitsPerPixel == 16)
{
UINT32* pSrcPixel;
UINT16* pDstPixel;
if (nDstStep < 0)
nDstStep = dstBytesPerPixel * nWidth;
pSrcPixel = (UINT32*) &pSrcData[(nYSrc * nSrcStep) + (nXSrc * srcBytesPerPixel)];
pDstPixel = (UINT16*) &pDstData[(nYDst * nDstStep) + (nXDst * dstBytesPerPixel)];
for (i = 0; i < nHeight; i++)
{
for (j = 0; j < nWidth; j++)
{
GetRGB32(r, g, b, *pSrcPixel);
RGB_888_565(r, g, b);
*pDstPixel = RGB565(r, g, b);
pSrcPixel++;
pDstPixel++;
}
pSrcPixel = (UINT32*) &((BYTE*) pSrcPixel)[(nSrcStep - (nWidth * srcBytesPerPixel))];
pDstPixel = (UINT16*) &((BYTE*) pDstPixel)[(nDstStep - (nWidth * dstBytesPerPixel))];
}
}
else if (dstBitsPerPixel == 15)
{
UINT32* pSrcPixel;
UINT16* pDstPixel;
if (nDstStep < 0)
nDstStep = dstBytesPerPixel * nWidth;
pSrcPixel = (UINT32*) &pSrcData[(nYSrc * nSrcStep) + (nXSrc * srcBytesPerPixel)];
pDstPixel = (UINT16*) &pDstData[(nYDst * nDstStep) + (nXDst * dstBytesPerPixel)];
for (i = 0; i < nHeight; i++)
{
for (j = 0; j < nWidth; j++)
{
GetRGB32(r, g, b, *pSrcPixel);
RGB_888_555(r, g, b);
*pDstPixel = RGB555(r, g, b);
pSrcPixel++;
pDstPixel++;
}
pSrcPixel = (UINT32*) &((BYTE*) pSrcPixel)[(nSrcStep - (nWidth * srcBytesPerPixel))];
pDstPixel = (UINT16*) &((BYTE*) pDstPixel)[(nDstStep - (nWidth * dstBytesPerPixel))];
}
}
}
}
}
return 0;
}

View File

@ -3120,7 +3120,7 @@ int TestFreeRDPCodecPlanar(int argc, char* argv[])
srcBitmap32 = freerdp_image_convert(srcBitmap16, NULL, 32, 32, 16, 32, clrconv);
format = FREERDP_PIXEL_FORMAT(32, FREERDP_PIXEL_FORMAT_TYPE_ARGB, FREERDP_PIXEL_FLIP_NONE);
format = PIXEL_FORMAT_ARGB32;
#if 0
freerdp_bitmap_compress_planar(planar, srcBitmap32, format, 32, 32, 32 * 4, NULL, &dstSize);