Work on compression.

This commit is contained in:
Daviw Williams 2013-01-31 16:56:32 +01:00
parent a81ec68714
commit 46e38c4714
5 changed files with 30 additions and 8 deletions

View File

@ -26,7 +26,7 @@ freely, subject to the following restrictions:
#include "PolyVoxCore/Impl/TypeDef.h"
#include "PolyVoxCore/Compressor.h"
#include "PolyVoxCore/PolyVoxForwardDeclarations.h"
#include "PolyVoxCore/Vector.h"
#include <limits>

View File

@ -24,8 +24,7 @@ freely, subject to the following restrictions:
#include "PolyVoxCore/Impl/ErrorHandling.h"
#include "PolyVoxCore/Impl/Utility.h"
#include "PolyVoxCore/MinizCompressor.h"
#include "PolyVoxCore/RLECompressor.h"
#include "PolyVoxCore/Compressor.h"
#include "PolyVoxCore/Vector.h"
#include "PolyVoxCore/Impl/ErrorHandling.h"

View File

@ -17,7 +17,10 @@ namespace PolyVox
template<typename ValueType, typename LengthType>
uint32_t RLECompressor<ValueType, LengthType>::compress(void* pSrcData, uint32_t uSrcLength, void* pDstData, uint32_t uDstLength)
{
assert(uSrcLength % sizeof(ValueType) == 0);
if(uSrcLength % sizeof(ValueType) != 0)
{
POLYVOX_THROW(std::length_error, "Source length must be a integer multiple of the ValueType size");
}
uSrcLength /= sizeof(ValueType);
uDstLength /= sizeof(Run);
@ -60,7 +63,10 @@ namespace PolyVox
template<typename ValueType, typename LengthType>
uint32_t RLECompressor<ValueType, LengthType>::decompress(void* pSrcData, uint32_t uSrcLength, void* pDstData, uint32_t uDstLength)
{
assert(uSrcLength % sizeof(Run) == 0);
if(uSrcLength % sizeof(Run) != 0)
{
POLYVOX_THROW(std::length_error, "Source length must be a integer multiple of the Run size");
}
uSrcLength /= sizeof(Run);
uDstLength /= sizeof(ValueType);

View File

@ -9,11 +9,16 @@
#define MINIZ_NO_ZLIB_COMPATIBLE_NAMES
//#define MINIZ_NO_MALLOC
#include "PolyVoxCore/Impl/ErrorHandling.h"
// For some unknown reason the miniz library is supplied only as a
// single .c file without a header. Apparently the only way to use
// it is then to #include it directly which is what the examples do.
#include "PolyVoxCore/Impl/miniz.c"
#include <sstream>
using namespace std;
namespace PolyVox
{
MinizCompressor::MinizCompressor()
@ -30,7 +35,12 @@ namespace PolyVox
// Do the compression
int result = mz_compress((unsigned char*)pDstData, &ulDstLength, (const unsigned char*) pSrcData, uSrcLength);
assert(result == MZ_OK);
if(result != MZ_OK)
{
stringstream ss;
ss << "mz_compress() failed with return code '" << result << "'";
POLYVOX_THROW(std::runtime_error, ss.str());
}
// Return the number of bytes written to the output.
return ulDstLength;
@ -41,7 +51,12 @@ namespace PolyVox
mz_ulong ulDstLength = uDstLength;
int result = mz_uncompress((unsigned char*) pDstData, &ulDstLength, (const unsigned char*) pSrcData, uSrcLength);
assert(result == MZ_OK);
if(result != MZ_OK)
{
stringstream ss;
ss << "mz_uncompress() failed with return code '" << result << "'";
POLYVOX_THROW(std::runtime_error, ss.str());
}
return ulDstLength;
}

View File

@ -24,6 +24,7 @@ freely, subject to the following restrictions:
#include "testvolume.h"
#include "PolyVoxCore/LargeVolume.h"
#include "PolyVoxCore/MinizCompressor.h"
#include "PolyVoxCore/RawVolume.h"
#include "PolyVoxCore/RLECompressor.h"
#include "PolyVoxCore/SimpleVolume.h"
@ -270,7 +271,8 @@ TestVolume::TestVolume()
{
Region region(-57, -31, 12, 64, 96, 131); // Deliberatly awkward size
m_pCompressor = new RLECompressor<int32_t, uint16_t>;
//m_pCompressor = new RLECompressor<int32_t, uint16_t>;
m_pCompressor = new MinizCompressor;
//Create the volumes
m_pRawVolume = new RawVolume<int32_t>(region);