libfreerdp-codec: make planar encoder pass compression/decompression tests

This commit is contained in:
Marc-André Moreau
2013-12-20 02:41:25 -05:00
parent 74a3232707
commit 4c6218e594
2 changed files with 66 additions and 44 deletions

View File

@@ -330,6 +330,7 @@ struct _PLANAR_RLE_CONTEXT
BYTE* outPlane;
int outPlaneSize;
int outSegmentSize;
int nRunLengthPrev;
};
typedef struct _PLANAR_RLE_CONTEXT PLANAR_RLE_CONTEXT;
@@ -339,12 +340,12 @@ int freerdp_bitmap_planar_compress_plane_rle_segment(PLANAR_RLE_CONTEXT* rle)
{
int k;
printf("RAW[");
printf("RAW(%d)[", rle->cRawBytes);
for (k = 0; k < rle->cRawBytes; k++)
{
printf("0x%02X%s", rle->rawValues[k],
((k + 1) == rle->cRawBytes) ? "" : ", ");
printf("%02x%s", rle->rawValues[k],
((k + 1) == rle->cRawBytes) ? "" : " ");
}
printf("] RUN[%d]\n", rle->nRunLength);
@@ -416,9 +417,14 @@ int freerdp_bitmap_planar_compress_plane_rle_segment(PLANAR_RLE_CONTEXT* rle)
}
*rle->output = PLANAR_CONTROL_BYTE(2, (rle->nRunLength - 32));
rle->nRunLength -= 32;
rle->output++;
rle->rawValues += (rle->cRawBytes + rle->nRunLength);
rle->output += rle->cRawBytes;
rle->cRawBytes = 0;
rle->nRunLength = 0;
return 0; /* finish */
}
else if (rle->nRunLength > 15)
@@ -432,9 +438,14 @@ int freerdp_bitmap_planar_compress_plane_rle_segment(PLANAR_RLE_CONTEXT* rle)
}
*rle->output = PLANAR_CONTROL_BYTE(1, (rle->nRunLength - 16));
rle->nRunLength -= 16;
rle->output++;
rle->rawValues += (rle->cRawBytes + rle->nRunLength);
rle->output += rle->cRawBytes;
rle->cRawBytes = 0;
rle->nRunLength = 0;
return 0; /* finish */
}
else
@@ -450,7 +461,6 @@ int freerdp_bitmap_planar_compress_plane_rle_segment(PLANAR_RLE_CONTEXT* rle)
*rle->output = PLANAR_CONTROL_BYTE(rle->nRunLength, rle->cRawBytes);
rle->output++;
CopyMemory(rle->output, rle->rawValues, rle->cRawBytes);
rle->rawValues += (rle->cRawBytes + rle->nRunLength);
rle->output += rle->cRawBytes;
@@ -543,32 +553,34 @@ BYTE* freerdp_bitmap_planar_compress_plane_rle(BYTE* inPlane, int width, int hei
rle->rawScanline = &inPlane[i * width];
rle->rawValues = rle->rawScanline;
rle->nRunLengthPrev = 0;
//winpr_HexDump(rle->rawScanline, width);
for (j = 1; j < width; j++)
for (j = 1; j <= width; j++)
{
bSymbolMatch = FALSE;
bSequenceEnd = ((j + 1) == width) ? TRUE : FALSE;
bSequenceEnd = (j == width) ? TRUE : FALSE;
if (rle->rawScanline[j] == rle->rawValues[rle->cRawBytes - 1])
if (!bSequenceEnd)
{
bSymbolMatch = TRUE;
}
else
{
//printf("mismatch: nRunLength: %d cRawBytes: %d\n", rle->nRunLength, rle->cRawBytes);
if (bSequenceEnd)
rle->cRawBytes++;
if (rle->nRunLength < 3)
if (rle->rawScanline[j] == rle->rawValues[rle->cRawBytes - 1])
{
rle->cRawBytes += rle->nRunLength;
rle->nRunLength = 0;
bSymbolMatch = TRUE;
}
else
{
bSequenceEnd = TRUE;
//printf("mismatch: nRunLength: %d cRawBytes: %d\n", rle->nRunLength, rle->cRawBytes);
if (rle->nRunLength < 3)
{
rle->cRawBytes += rle->nRunLength;
rle->nRunLength = 0;
}
else
{
bSequenceEnd = TRUE;
}
}
}
@@ -582,15 +594,30 @@ BYTE* freerdp_bitmap_planar_compress_plane_rle(BYTE* inPlane, int width, int hei
if (bSequenceEnd)
{
int nRunLengthPrev;
if (rle->nRunLength < 3)
{
rle->cRawBytes += rle->nRunLength;
rle->nRunLength = 0;
}
if ((rle->cRawBytes == 1) && (*rle->rawValues == 0))
{
if (!rle->nRunLengthPrev)
{
rle->cRawBytes = 0;
rle->nRunLength++;
}
}
nRunLengthPrev = rle->nRunLength;
if (freerdp_bitmap_planar_compress_plane_rle_segment(rle) < 0)
return NULL;
rle->nRunLengthPrev = nRunLengthPrev;
rle->nRunLength = 0;
rle->cRawBytes = 1;
}
@@ -756,8 +783,8 @@ BYTE* freerdp_bitmap_compress_planar(BITMAP_PLANAR_CONTEXT* context, BYTE* data,
context->rlePlanes[3] = &context->rlePlanesBuffer[offset];
offset += dstSizes[3];
printf("R: [%d/%d] G: [%d/%d] B: [%d/%d]\n",
dstSizes[1], planeSize, dstSizes[2], planeSize, dstSizes[3], planeSize);
//printf("R: [%d/%d] G: [%d/%d] B: [%d/%d]\n",
// dstSizes[1], planeSize, dstSizes[2], planeSize, dstSizes[3], planeSize);
}
}

View File

@@ -2984,7 +2984,7 @@ int test_individual_planes_encoding_rle()
dstSizes[1] = availableSize;
if (!freerdp_bitmap_planar_compress_plane_rle(planar->planes[1], width, height, pOutput, &dstSizes[1]))
if (!freerdp_bitmap_planar_compress_plane_rle(planar->deltaPlanes[1], width, height, pOutput, &dstSizes[1]))
{
printf("failed to encode red plane\n");
return 0;
@@ -2998,7 +2998,7 @@ int test_individual_planes_encoding_rle()
{
printf("RedPlaneRle unexpected size: actual: %d, expected: %d\n",
dstSizes[1], sizeof(TEST_64X64_RED_PLANE_RLE));
//return -1;
return -1;
}
compareSize = (dstSizes[1] > sizeof(TEST_64X64_RED_PLANE_RLE)) ? sizeof(TEST_64X64_RED_PLANE_RLE) : dstSizes[1];
@@ -3008,19 +3008,19 @@ int test_individual_planes_encoding_rle()
printf("RedPlaneRle doesn't match expected output\n");
printf("RedPlaneRle Expected (%d):\n", sizeof(TEST_64X64_RED_PLANE_RLE));
winpr_HexDump((BYTE*) TEST_64X64_RED_PLANE_RLE, sizeof(TEST_64X64_RED_PLANE_RLE));
//winpr_HexDump((BYTE*) TEST_64X64_RED_PLANE_RLE, sizeof(TEST_64X64_RED_PLANE_RLE));
printf("RedPlaneRle Actual (%d):\n", dstSizes[1]);
winpr_HexDump(planar->rlePlanes[1], dstSizes[1]);
//return -1;
return -1;
}
/* Green */
dstSizes[2] = availableSize;
if (!freerdp_bitmap_planar_compress_plane_rle(planar->planes[2], width, height, pOutput, &dstSizes[2]))
if (!freerdp_bitmap_planar_compress_plane_rle(planar->deltaPlanes[2], width, height, pOutput, &dstSizes[2]))
{
printf("failed to encode green plane\n");
return 0;
@@ -3034,7 +3034,7 @@ int test_individual_planes_encoding_rle()
{
printf("GreenPlaneRle unexpected size: actual: %d, expected: %d\n",
dstSizes[1], sizeof(TEST_64X64_GREEN_PLANE_RLE));
//return -1;
return -1;
}
compareSize = (dstSizes[2] > sizeof(TEST_64X64_GREEN_PLANE_RLE)) ? sizeof(TEST_64X64_GREEN_PLANE_RLE) : dstSizes[2];
@@ -3049,14 +3049,14 @@ int test_individual_planes_encoding_rle()
printf("GreenPlaneRle Actual (%d):\n", dstSizes[2]);
winpr_HexDump(planar->rlePlanes[2], dstSizes[2]);
//return -1;
return -1;
}
/* Blue */
dstSizes[3] = availableSize;
if (!freerdp_bitmap_planar_compress_plane_rle(planar->planes[3], width, height, pOutput, &dstSizes[3]))
if (!freerdp_bitmap_planar_compress_plane_rle(planar->deltaPlanes[3], width, height, pOutput, &dstSizes[3]))
{
printf("failed to encode blue plane\n");
return 0;
@@ -3070,7 +3070,7 @@ int test_individual_planes_encoding_rle()
{
printf("BluePlaneRle unexpected size: actual: %d, expected: %d\n",
dstSizes[1], sizeof(TEST_64X64_BLUE_PLANE_RLE));
//return -1;
return -1;
}
compareSize = (dstSizes[3] > sizeof(TEST_64X64_BLUE_PLANE_RLE)) ? sizeof(TEST_64X64_BLUE_PLANE_RLE) : dstSizes[3];
@@ -3085,7 +3085,7 @@ int test_individual_planes_encoding_rle()
printf("BluePlaneRle Actual (%d):\n", dstSizes[3]);
winpr_HexDump(planar->rlePlanes[3], dstSizes[3]);
//return -1;
return -1;
}
freerdp_bitmap_planar_context_free(planar);
@@ -3111,7 +3111,7 @@ int TestFreeRDPCodecPlanar(int argc, char* argv[])
BITMAP_PLANAR_CONTEXT* planar;
planarFlags = PLANAR_FORMAT_HEADER_NA;
//planarFlags |= PLANAR_FORMAT_HEADER_RLE;
planarFlags |= PLANAR_FORMAT_HEADER_RLE;
planar = freerdp_bitmap_planar_context_new(planarFlags, 64, 64);
@@ -3122,7 +3122,6 @@ int TestFreeRDPCodecPlanar(int argc, char* argv[])
format = FREERDP_PIXEL_FORMAT(32, FREERDP_PIXEL_FORMAT_TYPE_ARGB, FREERDP_PIXEL_FLIP_NONE);
#if 1
freerdp_bitmap_compress_planar(planar, srcBitmap32, format, 32, 32, 32 * 4, NULL, &dstSize);
freerdp_bitmap_planar_compress_plane_rle((BYTE*) TEST_RLE_SCANLINE_UNCOMPRESSED, 12, 1, NULL, &dstSize);
@@ -3255,9 +3254,7 @@ int TestFreeRDPCodecPlanar(int argc, char* argv[])
free(compressedBitmap);
free(decompressedBitmap);
}
#endif
#if 1
/* Experimental Case 01 */
width = 64;
@@ -3298,9 +3295,7 @@ int TestFreeRDPCodecPlanar(int argc, char* argv[])
free(compressedBitmap);
free(decompressedBitmap);
#endif
#if 1
/* Experimental Case 02 */
width = 64;
@@ -3341,11 +3336,12 @@ int TestFreeRDPCodecPlanar(int argc, char* argv[])
free(compressedBitmap);
free(decompressedBitmap);
#endif
//test_individual_planes_encoding_rle();
if (test_individual_planes_encoding_rle() < 0)
{
//return -1;
}
#if 1
/* Experimental Case 03 */
width = 64;
@@ -3386,7 +3382,6 @@ int TestFreeRDPCodecPlanar(int argc, char* argv[])
free(compressedBitmap);
free(decompressedBitmap);
#endif
freerdp_clrconv_free(clrconv);
free(srcBitmap32);