int test_NCrushCompressBells()
{
	int status;
	UINT32 Flags;
	UINT32 SrcSize;
	BYTE* pSrcData;
	UINT32 DstSize;
	BYTE* pDstData;
	UINT32 expectedSize;
	BYTE OutputBuffer[65536];
	NCRUSH_CONTEXT* ncrush;

	ncrush = ncrush_context_new(TRUE);

	SrcSize = sizeof(TEST_BELLS_DATA) - 1;
	pSrcData = (BYTE*) TEST_BELLS_DATA;
	expectedSize = sizeof(TEST_BELLS_NCRUSH) - 1;

	pDstData = OutputBuffer;
	DstSize = sizeof(OutputBuffer);
	ZeroMemory(OutputBuffer, sizeof(OutputBuffer));

	status = ncrush_compress(ncrush, pSrcData, SrcSize, &pDstData, &DstSize, &Flags);

	printf("status: %d Flags: 0x%04X DstSize: %d\n", status, Flags, DstSize);

	if (DstSize != expectedSize)
	{
		printf("NCrushCompressBells: output size mismatch: Actual: %d, Expected: %d\n", DstSize, expectedSize);

		printf("Actual\n");
		BitDump(pDstData, DstSize * 8, 0);

		printf("Expected\n");
		BitDump(TEST_BELLS_NCRUSH, expectedSize * 8, 0);

		return -1;
	}

	if (memcmp(pDstData, TEST_BELLS_NCRUSH, DstSize) != 0)
	{
		printf("NCrushCompressBells: output mismatch\n");

		printf("Actual\n");
		BitDump(pDstData, DstSize * 8, 0);

		printf("Expected\n");
		BitDump(TEST_BELLS_NCRUSH, expectedSize * 8, 0);

		return -1;
	}

	ncrush_context_free(ncrush);

	return 1;
}
static BOOL test_NCrushCompressBells(void)
{
	BOOL rc = FALSE;
	int status;
	UINT32 Flags;
	UINT32 SrcSize;
	BYTE* pSrcData;
	UINT32 DstSize;
	BYTE* pDstData;
	UINT32 expectedSize;
	BYTE OutputBuffer[65536];
	NCRUSH_CONTEXT* ncrush = ncrush_context_new(TRUE);

	if (!ncrush)
		return rc;

	SrcSize = sizeof(TEST_BELLS_DATA) - 1;
	pSrcData = (BYTE*) TEST_BELLS_DATA;
	expectedSize = sizeof(TEST_BELLS_NCRUSH) - 1;
	pDstData = OutputBuffer;
	DstSize = sizeof(OutputBuffer);
	ZeroMemory(OutputBuffer, sizeof(OutputBuffer));
	status = ncrush_compress(ncrush, pSrcData, SrcSize, &pDstData, &DstSize, &Flags);

	if (status < 0)
		goto fail;

	printf("status: %d Flags: 0x%08"PRIX32" DstSize: %"PRIu32"\n", status, Flags, DstSize);

	if (DstSize != expectedSize)
	{
		printf("NCrushCompressBells: output size mismatch: Actual: %"PRIu32", Expected: %"PRIu32"\n",
		       DstSize, expectedSize);
		printf("Actual\n");
		BitDump(__FUNCTION__, WLOG_INFO, pDstData, DstSize * 8, 0);
		printf("Expected\n");
		BitDump(__FUNCTION__, WLOG_INFO, TEST_BELLS_NCRUSH, expectedSize * 8, 0);
		goto fail;
	}

	if (memcmp(pDstData, TEST_BELLS_NCRUSH, DstSize) != 0)
	{
		printf("NCrushCompressBells: output mismatch\n");
		printf("Actual\n");
		BitDump(__FUNCTION__, WLOG_INFO, pDstData, DstSize * 8, 0);
		printf("Expected\n");
		BitDump(__FUNCTION__, WLOG_INFO, TEST_BELLS_NCRUSH, expectedSize * 8, 0);
		goto fail;
	}

	rc = TRUE;
fail:
	ncrush_context_free(ncrush);
	return rc;
}
Exemple #3
0
int bulk_compress(rdpBulk* bulk, BYTE* pSrcData, UINT32 SrcSize, BYTE** ppDstData, UINT32* pDstSize, UINT32* pFlags)
{
    int status = -1;
    rdpMetrics* metrics;
    UINT32 CompressedBytes;
    UINT32 UncompressedBytes;
    double CompressionRatio;
    metrics = bulk->context->metrics;

    if ((SrcSize <= 50) || (SrcSize >= 16384))
    {
        *ppDstData = pSrcData;
        *pDstSize = SrcSize;
        return 0;
    }

    *ppDstData = bulk->OutputBuffer;
    *pDstSize = sizeof(bulk->OutputBuffer);
    bulk_compression_level(bulk);
    bulk_compression_max_size(bulk);

    if ((bulk->CompressionLevel == PACKET_COMPR_TYPE_8K) ||
            (bulk->CompressionLevel == PACKET_COMPR_TYPE_64K))
    {
        mppc_set_compression_level(bulk->mppcSend, bulk->CompressionLevel);
        status = mppc_compress(bulk->mppcSend, pSrcData, SrcSize, ppDstData, pDstSize, pFlags);
    }
    else if (bulk->CompressionLevel == PACKET_COMPR_TYPE_RDP6)
    {
        status = ncrush_compress(bulk->ncrushSend, pSrcData, SrcSize, ppDstData, pDstSize, pFlags);
    }
    else if (bulk->CompressionLevel == PACKET_COMPR_TYPE_RDP61)
    {
        status = xcrush_compress(bulk->xcrushSend, pSrcData, SrcSize, ppDstData, pDstSize, pFlags);
    }
    else
    {
        status = -1;
    }

    if (status >= 0)
    {
        CompressedBytes = *pDstSize;
        UncompressedBytes = SrcSize;
        CompressionRatio = metrics_write_bytes(metrics, UncompressedBytes, CompressedBytes);
#ifdef WITH_BULK_DEBUG
        {
            DEBUG_MSG("Compress Type: %d Flags: %s (0x%04X) Compression Ratio: %f (%d / %d), Total: %f (%u / %u)\n",
                      bulk->CompressionLevel, bulk_get_compression_flags_string(*pFlags), *pFlags,
                      CompressionRatio, CompressedBytes, UncompressedBytes,
                      metrics->TotalCompressionRatio, (UINT32) metrics->TotalCompressedBytes,
                      (UINT32) metrics->TotalUncompressedBytes);
        }
#endif
    }

#if 0

    if (bulk_compress_validate(bulk, pSrcData, SrcSize, ppDstData, pDstSize, pFlags) < 0)
        status = -1;

#endif
    return status;
}
Exemple #4
0
int bulk_compress(rdpBulk* bulk, BYTE* pSrcData, UINT32 SrcSize, BYTE** ppDstData, UINT32* pDstSize, UINT32* pFlags)
{
    int status = -1;
    UINT32 CompressedBytes;
    UINT32 UncompressedBytes;

    if ((SrcSize <= 50) || (SrcSize >= 16384))
    {
        *ppDstData = pSrcData;
        *pDstSize = SrcSize;
        return 0;
    }

    *ppDstData = bulk->OutputBuffer;
    *pDstSize = sizeof(bulk->OutputBuffer);

    bulk_compression_level(bulk);
    bulk_compression_max_size(bulk);

    if (bulk->CompressionLevel < PACKET_COMPR_TYPE_RDP6)
    {
        mppc_set_compression_level(bulk->mppcSend, bulk->CompressionLevel);
        status = mppc_compress(bulk->mppcSend, pSrcData, SrcSize, ppDstData, pDstSize, pFlags);
    }
    else
    {
        status = ncrush_compress(bulk->ncrushSend, pSrcData, SrcSize, ppDstData, pDstSize, pFlags);
    }

    if (status >= 0)
    {
        CompressedBytes = *pDstSize;
        UncompressedBytes = SrcSize;

        bulk->TotalUncompressedBytes += UncompressedBytes;
        bulk->TotalCompressedBytes += CompressedBytes;

#ifdef WITH_BULK_DEBUG
        {
            UINT32 type;
            double CompressionRatio;
            double TotalCompressionRatio;

            type = bulk->CompressionLevel;

            CompressionRatio = ((double) CompressedBytes) / ((double) UncompressedBytes);
            TotalCompressionRatio = ((double) bulk->TotalCompressedBytes) / ((double) bulk->TotalUncompressedBytes);

            printf("Compress Type: %d Flags: %s (0x%04X) Compression Ratio: %f (%d / %d), Total: %f (%d / %d)\n",
                   type, bulk_get_compression_flags_string(*pFlags), *pFlags,
                   CompressionRatio, CompressedBytes, UncompressedBytes,
                   TotalCompressionRatio, bulk->TotalCompressedBytes, bulk->TotalUncompressedBytes);
        }
#endif
    }

#if 0
    if (bulk_compress_validate(bulk, pSrcData, SrcSize, ppDstData, pDstSize, pFlags) < 0)
        status = -1;
#endif

    return status;
}