Reverted accidental changes to tests.

Updated comments in compression code.
This commit is contained in:
Daviw Williams 2013-02-25 17:06:12 +01:00
parent c42270f165
commit 62370868c8
3 changed files with 18 additions and 11 deletions

View File

@ -27,13 +27,15 @@ namespace PolyVox
MinizCompressor::MinizCompressor(int iCompressionLevel)
:m_pDeflator(0)
{
// Create and store the deflator.
tdefl_compressor* pDeflator = new tdefl_compressor;
m_pDeflator = reinterpret_cast<void*>(pDeflator);
// The number of dictionary probes to use at each compression level (0-10). 0=implies fastest/minimal possible probing.
// The discontinuity is unsettling but may be explained by the 'iCompressionLevel <= 3' check later?
static const mz_uint s_tdefl_num_probes[11] = { 0, 1, 6, 32, 16, 32, 128, 256, 512, 768, 1500 };
// create tdefl() compatible flags (we have to compose the low-level flags ourselves, or use tdefl_create_comp_flags_from_zip_params() but that means MINIZ_NO_ZLIB_APIS can't be defined).
// Create tdefl() compatible flags (we have to compose the low-level flags ourselves, or use tdefl_create_comp_flags_from_zip_params() but that means MINIZ_NO_ZLIB_APIS can't be defined).
m_uCompressionFlags = TDEFL_WRITE_ZLIB_HEADER | s_tdefl_num_probes[MZ_MIN(10, iCompressionLevel)] | ((iCompressionLevel <= 3) ? TDEFL_GREEDY_PARSING_FLAG : 0);
if (!iCompressionLevel)
{
@ -43,6 +45,7 @@ namespace PolyVox
MinizCompressor::~MinizCompressor()
{
// Delete the deflator
tdefl_compressor* pDeflator = reinterpret_cast<tdefl_compressor*>(m_pDeflator);
delete pDeflator;
}
@ -57,10 +60,9 @@ namespace PolyVox
return MZ_MAX(128 + (source_len * 110) / 100, 128 + source_len + ((source_len / (31 * 1024)) + 1) * 5);
}
// The behaviour of this function should be the same as the commented out version above (except that it requires the destination to be a power of two),
// but it's implemented using the lower level API which does not conflict with zlib or perform any memory allocations.
uint32_t MinizCompressor::compress(void* pSrcData, uint32_t uSrcLength, void* pDstData, uint32_t uDstLength)
{
//Get the deflator
tdefl_compressor* pDeflator = reinterpret_cast<tdefl_compressor*>(m_pDeflator);
// It seems we have to reinitialise the deflator for each fresh dataset (it's probably intended for streaming, which we're not doing here)
@ -72,12 +74,14 @@ namespace PolyVox
POLYVOX_THROW(std::runtime_error, ss.str());
}
// Change the type to avoid compiler warnings
size_t ulSrcLength = uSrcLength;
size_t ulDstLength = uDstLength;
// Compress as much of the input as possible (or all of it) to the output buffer.
status = tdefl_compress(pDeflator, pSrcData, &ulSrcLength, pDstData, &ulDstLength, TDEFL_FINISH);
//Check whther the compression was successful.
if (status != TDEFL_STATUS_DONE)
{
stringstream ss;
@ -85,11 +89,10 @@ namespace PolyVox
POLYVOX_THROW(std::runtime_error, ss.str());
}
// The compression modifies 'ulDstLength' to hold the new length.
return ulDstLength;
}
// The behaviour of this function should be the same as the commented out version above (except that it requires the destination to be a power of two),
// but it's implemented using the lower level API which does not conflict with zlib or perform any memory allocations.
uint32_t MinizCompressor::decompress(void* pSrcData, uint32_t uSrcLength, void* pDstData, uint32_t uDstLength)
{
// I don't know exactly why this limitation exists but it's an implementation detail of miniz. It shouldn't matter for our purposes
@ -102,9 +105,11 @@ namespace PolyVox
POLYVOX_THROW(std::invalid_argument, "Miniz decompressor requires the destination buffer to have a size which is a power of two.");
}
// Change the type to avoid compiler warnings
size_t ulSrcLength = uSrcLength;
size_t ulDstLength = uDstLength;
// Create and initialise the decompressor (I believe this is much small than the compressor).
tinfl_decompressor inflator;
tinfl_init(&inflator);
@ -112,6 +117,7 @@ namespace PolyVox
// different locations within it. In our scenario it's only called once so the start and the location are the same (both pDstData).
tinfl_status status = tinfl_decompress(&inflator, (const mz_uint8 *)pSrcData, &ulSrcLength, (mz_uint8 *)pDstData, (mz_uint8 *)pDstData, &ulDstLength, TINFL_FLAG_PARSE_ZLIB_HEADER);
//Check whther the decompression was successful.
if (status != TINFL_STATUS_DONE)
{
stringstream ss;
@ -119,6 +125,7 @@ namespace PolyVox
POLYVOX_THROW(std::runtime_error, ss.str());
}
// The decompression modifies 'ulDstLength' to hold the new length.
return ulDstLength;
}
}

View File

@ -312,7 +312,7 @@ TestVolume::~TestVolume()
* RawVolume Tests
*/
/*void TestVolume::testRawVolumeDirectAccessAllInternalForwards()
void TestVolume::testRawVolumeDirectAccessAllInternalForwards()
{
int32_t result = 0;
@ -398,13 +398,13 @@ void TestVolume::testRawVolumeSamplersWithExternalBackwards()
result = testSamplersWithWrappingBackwards(m_pRawVolume, -1, -3, -2, 2, 5, 4);
}
QCOMPARE(result, static_cast<int32_t>(-769775893));
}*/
}
/*
* SimpleVolume Tests
*/
/*void TestVolume::testSimpleVolumeDirectAccessAllInternalForwards()
void TestVolume::testSimpleVolumeDirectAccessAllInternalForwards()
{
int32_t result = 0;
QBENCHMARK
@ -482,7 +482,7 @@ void TestVolume::testSimpleVolumeSamplersWithExternalBackwards()
result = testSamplersWithWrappingBackwards(m_pSimpleVolume, -1, -3, -2, 2, 5, 4);
}
QCOMPARE(result, static_cast<int32_t>(-769775893));
}*/
}
/*
* LargeVolume Tests

View File

@ -37,7 +37,7 @@ public:
~TestVolume();
private slots:
/*void testRawVolumeDirectAccessAllInternalForwards();
void testRawVolumeDirectAccessAllInternalForwards();
void testRawVolumeSamplersAllInternalForwards();
void testRawVolumeDirectAccessWithExternalForwards();
void testRawVolumeSamplersWithExternalForwards();
@ -53,7 +53,7 @@ private slots:
void testSimpleVolumeDirectAccessAllInternalBackwards();
void testSimpleVolumeSamplersAllInternalBackwards();
void testSimpleVolumeDirectAccessWithExternalBackwards();
void testSimpleVolumeSamplersWithExternalBackwards();*/
void testSimpleVolumeSamplersWithExternalBackwards();
void testLargeVolumeDirectAccessAllInternalForwards();
void testLargeVolumeSamplersAllInternalForwards();