Fixed clear codec.

This commit is contained in:
Armin Novak 2016-04-13 23:06:33 +02:00 committed by Armin Novak
parent 5633f5242a
commit bb92655339
2 changed files with 115 additions and 111 deletions

View File

@ -72,9 +72,9 @@ extern "C" {
FREERDP_API int clear_compress(CLEAR_CONTEXT* clear, BYTE* pSrcData, UINT32 SrcSize, BYTE** ppDstData, UINT32* pDstSize); FREERDP_API int clear_compress(CLEAR_CONTEXT* clear, BYTE* pSrcData, UINT32 SrcSize, BYTE** ppDstData, UINT32* pDstSize);
FREERDP_API INT32 clear_decompress(CLEAR_CONTEXT* clear, const BYTE* pSrcData, FREERDP_API INT32 clear_decompress(CLEAR_CONTEXT* clear, const BYTE* pSrcData,
UINT32 SrcSize, UINT32 SrcSize, UINT32 nWidth, UINT32 nHeight,
BYTE* pDstData, UINT32 DstFormat, UINT32 nDstStep, BYTE* pDstData, UINT32 DstFormat, UINT32 nDstStep,
UINT32 nXDst, UINT32 nYDst, UINT32 nWidth, UINT32 nHeight); UINT32 nXDst, UINT32 nYDst, UINT32 nDstWidth, UINT32 nDstHeight);
FREERDP_API BOOL clear_context_reset(CLEAR_CONTEXT* clear); FREERDP_API BOOL clear_context_reset(CLEAR_CONTEXT* clear);

View File

@ -56,12 +56,17 @@ static BYTE CLEAR_8BIT_MASKS[9] =
}; };
static void convert_color(BYTE* dst, UINT32 nDstStep, UINT32 DstFormat, static void convert_color(BYTE* dst, UINT32 nDstStep, UINT32 DstFormat,
UINT32 nXDst, UINT32 nYDst, UINT32 nXDst, UINT32 nYDst, UINT32 nWidth, UINT32 nHeight,
const BYTE* src, UINT32 nSrcStep, UINT32 SrcFormat, const BYTE* src, UINT32 nSrcStep, UINT32 SrcFormat,
UINT32 nWidth, UINT32 nHeight) UINT32 nDstWidth, UINT32 nDstHeight)
{ {
UINT32 x, y; UINT32 x, y;
if (nWidth + nXDst > nDstWidth)
nWidth = nDstWidth - nXDst;
if (nHeight + nYDst > nDstHeight)
nHeight = nDstHeight - nYDst;
for (y = 0; y < nHeight; y++) for (y = 0; y < nHeight; y++)
{ {
const BYTE* pSrcLine = &src[y * nSrcStep]; const BYTE* pSrcLine = &src[y * nSrcStep];
@ -95,10 +100,10 @@ static BOOL clear_decompress_nscodec(NSC_CONTEXT* nsc, UINT32 width,
static BOOL clear_decompress_subcode_rlex(const BYTE* bitmapData, static BOOL clear_decompress_subcode_rlex(const BYTE* bitmapData,
UINT32 bitmapDataByteCount, UINT32 bitmapDataByteCount,
UINT32 width, UINT32 height, UINT32 width, UINT32 height,
BYTE* tmpBuffer, UINT32 nTmpBufferSize,
BYTE* pDstData, UINT32 DstFormat, UINT32 nDstStep, BYTE* pDstData, UINT32 DstFormat, UINT32 nDstStep,
UINT32 nXDstRel, UINT32 nYDstRel) UINT32 nXDstRel, UINT32 nYDstRel, UINT32 nDstWidth, UINT32 nDstHeight)
{ {
UINT32 x = 0, y = 0;
UINT32 i; UINT32 i;
UINT32 SrcFormat = PIXEL_FORMAT_BGR24; UINT32 SrcFormat = PIXEL_FORMAT_BGR24;
UINT32 pixelCount; UINT32 pixelCount;
@ -118,16 +123,17 @@ static BOOL clear_decompress_subcode_rlex(const BYTE* bitmapData,
bitmapDataOffset = 1 + (paletteCount * 3); bitmapDataOffset = 1 + (paletteCount * 3);
if (paletteCount > 127) if (paletteCount > 127)
return -1047; return FALSE;
for (i = 0; i < paletteCount; i++) for (i = 0; i < paletteCount; i++)
{ {
UINT32 color = GetColor(SrcFormat, UINT32 color = GetColor(
SrcFormat,
pSrcPixel8[2], pSrcPixel8[2],
pSrcPixel8[1], pSrcPixel8[1],
pSrcPixel8[0], pSrcPixel8[0],
0xFF); 0xFF);
palette[i] = color; palette[i] = ConvertColor(color, SrcFormat, DstFormat, NULL);
pSrcPixel8 += GetBytesPerPixel(SrcFormat); pSrcPixel8 += GetBytesPerPixel(SrcFormat);
} }
@ -183,8 +189,15 @@ static BOOL clear_decompress_subcode_rlex(const BYTE* bitmapData,
for (i = 0; i < runLengthFactor; i++) for (i = 0; i < runLengthFactor; i++)
{ {
WriteColor(tmpBuffer, SrcFormat, color); BYTE* pTmpData = &pDstData[(nXDstRel + x) * GetBytesPerPixel(DstFormat) + (nYDstRel + y) * nDstStep];
tmpBuffer += GetBytesPerPixel(SrcFormat); if ((nXDstRel + x < nDstWidth) && (nYDstRel + y < nDstHeight))
WriteColor(pTmpData, DstFormat, color);
if (++x >= width) {
y++;
x = 0;
}
} }
pixelIndex += runLengthFactor; pixelIndex += runLengthFactor;
@ -194,23 +207,25 @@ static BOOL clear_decompress_subcode_rlex(const BYTE* bitmapData,
for (i = 0; i <= suiteDepth; i++) for (i = 0; i <= suiteDepth; i++)
{ {
BYTE* pTmpData = &pDstData[(nXDstRel + x) * GetBytesPerPixel(DstFormat) + (nYDstRel + y) * nDstStep];
UINT32 color = palette[suiteIndex++]; UINT32 color = palette[suiteIndex++];
WriteColor(tmpBuffer, SrcFormat, color); if ((nXDstRel + x < nDstWidth) && (nYDstRel + y < nDstHeight))
tmpBuffer += GetBytesPerPixel(SrcFormat); WriteColor(pTmpData, DstFormat, color);
if (++x >= width) {
y++;
x = 0;
}
} }
pixelIndex += (suiteDepth + 1); pixelIndex += (suiteDepth + 1);
} }
nSrcStep = width * GetBytesPerPixel(SrcFormat); nSrcStep = width * GetBytesPerPixel(DstFormat);
if (pixelIndex != pixelCount) if (pixelIndex != pixelCount)
return -1055; return -1055;
convert_color(pDstData, nDstStep, DstFormat,
nXDstRel, nYDstRel,
tmpBuffer, nSrcStep, SrcFormat,
width, height);
return TRUE; return TRUE;
} }
@ -219,7 +234,7 @@ static BOOL clear_decompress_residual_data(CLEAR_CONTEXT* clear,
UINT32 residualByteCount, UINT32 SrcSize, UINT32 residualByteCount, UINT32 SrcSize,
UINT32 nWidth, UINT32 nHeight, UINT32 nWidth, UINT32 nHeight,
BYTE* pDstData, UINT32 DstFormat, UINT32 nDstStep, BYTE* pDstData, UINT32 DstFormat, UINT32 nDstStep,
UINT32 nXDst, UINT32 nYDst) UINT32 nXDst, UINT32 nYDst, UINT32 nDstWidth, UINT32 nDstHeight)
{ {
UINT32 i; UINT32 i;
UINT32 nSrcStep; UINT32 nSrcStep;
@ -233,15 +248,6 @@ static BOOL clear_decompress_residual_data(CLEAR_CONTEXT* clear,
suboffset = 0; suboffset = 0;
if ((nWidth * nHeight * GetBytesPerPixel(clear->format)) > clear->TempSize)
{
clear->TempSize = (nWidth * nHeight * GetBytesPerPixel(clear->format));
clear->TempBuffer = (BYTE*) realloc(clear->TempBuffer, clear->TempSize);
if (!clear->TempBuffer)
return -1014;
}
pixelIndex = 0; pixelIndex = 0;
pixelCount = nWidth * nHeight; pixelCount = nWidth * nHeight;
dstBuffer = clear->TempBuffer; dstBuffer = clear->TempBuffer;
@ -297,9 +303,9 @@ static BOOL clear_decompress_residual_data(CLEAR_CONTEXT* clear,
return -1019; return -1019;
convert_color(pDstData, nDstStep, DstFormat, convert_color(pDstData, nDstStep, DstFormat,
nXDst, nYDst, nXDst, nYDst, nWidth, nHeight,
clear->TempBuffer, nSrcStep, clear->format, clear->TempBuffer, nSrcStep, clear->format,
nWidth, nHeight); nDstWidth, nDstHeight);
return TRUE; return TRUE;
} }
@ -576,9 +582,9 @@ static BOOL clear_decompress_bands_data(CLEAR_CONTEXT* clear,
} }
INT32 clear_decompress(CLEAR_CONTEXT* clear, const BYTE* pSrcData, INT32 clear_decompress(CLEAR_CONTEXT* clear, const BYTE* pSrcData,
UINT32 SrcSize, UINT32 SrcSize, UINT32 nWidth, UINT32 nHeight,
BYTE* pDstData, UINT32 DstFormat, UINT32 nDstStep, BYTE* pDstData, UINT32 DstFormat, UINT32 nDstStep,
UINT32 nXDst, UINT32 nYDst, UINT32 nWidth, UINT32 nHeight) UINT32 nXDst, UINT32 nYDst, UINT32 nDstWidth, UINT32 nDstHeight)
{ {
BYTE seqNumber; BYTE seqNumber;
BYTE glyphFlags; BYTE glyphFlags;
@ -649,9 +655,9 @@ INT32 clear_decompress(CLEAR_CONTEXT* clear, const BYTE* pSrcData,
nSrcStep = nWidth * GetBytesPerPixel(clear->format); nSrcStep = nWidth * GetBytesPerPixel(clear->format);
convert_color(pDstData, nDstStep, DstFormat, convert_color(pDstData, nDstStep, DstFormat,
nXDst, nYDst, nXDst, nYDst, nWidth, nHeight,
glyphData, nSrcStep, clear->format, glyphData, nSrcStep, clear->format,
nWidth, nHeight); nDstWidth, nDstHeight);
return 1; /* Finish */ return 1; /* Finish */
} }
} }
@ -670,7 +676,8 @@ INT32 clear_decompress(CLEAR_CONTEXT* clear, const BYTE* pSrcData,
if (!clear_decompress_residual_data(clear, if (!clear_decompress_residual_data(clear,
&pSrcData[offset], residualByteCount, &pSrcData[offset], residualByteCount,
SrcSize - offset, nWidth, nHeight, SrcSize - offset, nWidth, nHeight,
pDstData, DstFormat, nDstStep, nXDst, nYDst)) pDstData, DstFormat, nDstStep, nXDst, nYDst,
nDstWidth, nDstHeight))
return -1111; return -1111;
offset += residualByteCount; offset += residualByteCount;
@ -747,16 +754,17 @@ INT32 clear_decompress(CLEAR_CONTEXT* clear, const BYTE* pSrcData,
if (subcodecId == 0) /* Uncompressed */ if (subcodecId == 0) /* Uncompressed */
{ {
UINT32 nSrcStep = width * height * GetBytesPerPixel(PIXEL_FORMAT_BGR24); UINT32 nSrcStep = width * GetBytesPerPixel(PIXEL_FORMAT_BGR24);;
UINT32 nSrcSize = nSrcStep * height;
if (bitmapDataByteCount != nSrcStep) if (bitmapDataByteCount != nSrcSize)
return -1045; return -1045;
convert_color(pDstData, nDstStep, DstFormat, convert_color(pDstData, nDstStep, DstFormat,
nXDstRel, nYDstRel, nXDstRel, nYDstRel, width, height,
bitmapData, nSrcStep, bitmapData, nSrcStep,
PIXEL_FORMAT_BGR24, PIXEL_FORMAT_BGR24,
width, height); nDstWidth, nDstHeight);
} }
else if (subcodecId == 1) /* NSCodec */ else if (subcodecId == 1) /* NSCodec */
{ {
@ -771,9 +779,9 @@ INT32 clear_decompress(CLEAR_CONTEXT* clear, const BYTE* pSrcData,
if (!clear_decompress_subcode_rlex(bitmapData, if (!clear_decompress_subcode_rlex(bitmapData,
bitmapDataByteCount, bitmapDataByteCount,
width, height, width, height,
clear->TempBuffer, clear->TempSize,
pDstData, DstFormat, nDstStep, pDstData, DstFormat, nDstStep,
nXDstRel, nYDstRel)) nXDstRel, nYDstRel,
nDstWidth, nDstHeight))
return -1047; return -1047;
} }
else else
@ -811,9 +819,9 @@ INT32 clear_decompress(CLEAR_CONTEXT* clear, const BYTE* pSrcData,
glyphData = (BYTE*) glyphEntry->pixels; glyphData = (BYTE*) glyphEntry->pixels;
nSrcStep = nWidth * GetBytesPerPixel(clear->format); nSrcStep = nWidth * GetBytesPerPixel(clear->format);
convert_color(pDstData, nDstStep, DstFormat, convert_color(pDstData, nDstStep, DstFormat,
nXDst, nYDst, nXDst, nYDst, nWidth, nHeight,
glyphData, nSrcStep, clear->format, glyphData, nSrcStep, clear->format,
nWidth, nHeight); nDstWidth, nDstHeight);
} }
if (offset != SrcSize) if (offset != SrcSize)
@ -858,13 +866,9 @@ CLEAR_CONTEXT* clear_context_new(BOOL Compressor)
clear->TempSize = 512 * 512 * 4; clear->TempSize = 512 * 512 * 4;
clear->TempBuffer = (BYTE*) malloc(clear->TempSize); clear->TempBuffer = (BYTE*) malloc(clear->TempSize);
if (!clear->TempBuffer)
goto error_temp_buffer;
clear_context_reset(clear); clear_context_reset(clear);
return clear; return clear;
error_temp_buffer:
nsc_context_free(clear->nsc);
error_nsc: error_nsc:
free(clear); free(clear);
return NULL; return NULL;