Added my two new compressor classes - one based on Miniz and the other based on RLE.
This commit is contained in:
@ -336,7 +336,7 @@ namespace PolyVox
|
||||
}
|
||||
|
||||
// Robert Jenkins' 32 bit integer hash function
|
||||
// http://www.concentric.net/~ttwang/tech/inthash.htm
|
||||
// http://www.burtleburtle.net/bob/hash/integer.html
|
||||
template<typename VolumeType>
|
||||
uint32_t AStarPathfinder<VolumeType>::hash( uint32_t a)
|
||||
{
|
||||
|
16
library/PolyVoxCore/include/PolyVoxCore/MinizCompressor.h
Normal file
16
library/PolyVoxCore/include/PolyVoxCore/MinizCompressor.h
Normal file
@ -0,0 +1,16 @@
|
||||
#ifndef __PolyVox_MinizCompressor_H__
|
||||
#define __PolyVox_MinizCompressor_H__
|
||||
|
||||
#include "PolyVoxCore/Impl/TypeDef.h"
|
||||
|
||||
class MinizCompressor
|
||||
{
|
||||
public:
|
||||
MinizCompressor();
|
||||
~MinizCompressor();
|
||||
|
||||
uint32_t compress(void* pSrcData, uint32_t uSrcLength, void* pDstData, uint32_t uDstLength);
|
||||
uint32_t decompress(void* pSrcData, uint32_t uSrcLength, void* pDstData, uint32_t uDstLength);
|
||||
};
|
||||
|
||||
#endif //__PolyVox_MinizCompressor_H__
|
24
library/PolyVoxCore/include/PolyVoxCore/RLECompressor.h
Normal file
24
library/PolyVoxCore/include/PolyVoxCore/RLECompressor.h
Normal file
@ -0,0 +1,24 @@
|
||||
#ifndef __PolyVox_RLECompressor_H__
|
||||
#define __PolyVox_RLECompressor_H__
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
template<typename ValueType, typename LengthType>
|
||||
class RLECompressor
|
||||
{
|
||||
struct Run
|
||||
{
|
||||
ValueType value;
|
||||
LengthType length;
|
||||
};
|
||||
public:
|
||||
RLECompressor();
|
||||
~RLECompressor();
|
||||
|
||||
uint32_t compress(void* pSrcData, uint32_t uSrcLength, void* pDstData, uint32_t uDstLength);
|
||||
uint32_t decompress(void* pSrcData, uint32_t uSrcLength, void* pDstData, uint32_t uDstLength);
|
||||
};
|
||||
|
||||
#include "RLECompressor.inl"
|
||||
|
||||
#endif //__PolyVox_RLECompressor_H__
|
85
library/PolyVoxCore/include/PolyVoxCore/RLECompressor.inl
Normal file
85
library/PolyVoxCore/include/PolyVoxCore/RLECompressor.inl
Normal file
@ -0,0 +1,85 @@
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
|
||||
template<typename ValueType, typename LengthType>
|
||||
RLECompressor<ValueType, LengthType>::RLECompressor()
|
||||
{
|
||||
}
|
||||
|
||||
template<typename ValueType, typename LengthType>
|
||||
RLECompressor<ValueType, LengthType>::~RLECompressor()
|
||||
{
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
uSrcLength /= sizeof(ValueType);
|
||||
uDstLength /= sizeof(Run);
|
||||
|
||||
ValueType* pSrcDataAsInt = reinterpret_cast<ValueType*>(pSrcData);
|
||||
Run* pDstDataAsRun = reinterpret_cast<Run*>(pDstData);
|
||||
|
||||
ValueType* pSrcDataEnd = pSrcDataAsInt + uSrcLength;
|
||||
Run* pDstDataEnd = pDstDataAsRun + uDstLength;
|
||||
|
||||
uint32_t uDstLengthInBytes = 0;
|
||||
|
||||
|
||||
pDstDataAsRun->value = *pSrcDataAsInt;
|
||||
pSrcDataAsInt++;
|
||||
pDstDataAsRun->length = 1;
|
||||
uDstLengthInBytes += sizeof(Run);
|
||||
|
||||
while(pSrcDataAsInt < pSrcDataEnd)
|
||||
{
|
||||
if((*pSrcDataAsInt == pDstDataAsRun->value) && (pDstDataAsRun->length < std::numeric_limits<LengthType>::max()))
|
||||
{
|
||||
pDstDataAsRun->length++;
|
||||
}
|
||||
else
|
||||
{
|
||||
pDstDataAsRun++;
|
||||
assert(pDstDataAsRun < pDstDataEnd);
|
||||
pDstDataAsRun->value = *pSrcDataAsInt;
|
||||
pDstDataAsRun->length = 1;
|
||||
uDstLengthInBytes += sizeof(Run);
|
||||
}
|
||||
|
||||
pSrcDataAsInt++;
|
||||
}
|
||||
|
||||
return uDstLengthInBytes;
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
uSrcLength /= sizeof(Run);
|
||||
uDstLength /= sizeof(ValueType);
|
||||
|
||||
Run* pSrcDataAsRun = reinterpret_cast<Run*>(pSrcData);
|
||||
ValueType* pDstDataAsInt = reinterpret_cast<ValueType*>(pDstData);
|
||||
|
||||
Run* pSrcDataEnd = pSrcDataAsRun + uSrcLength;
|
||||
ValueType* pDstDataEnd = pDstDataAsInt + uDstLength;
|
||||
|
||||
uint32_t uDstLengthInBytes = 0;
|
||||
|
||||
while(pSrcDataAsRun < pSrcDataEnd)
|
||||
{
|
||||
std::fill(pDstDataAsInt, pDstDataAsInt + pSrcDataAsRun->length, pSrcDataAsRun->value);
|
||||
pDstDataAsInt += pSrcDataAsRun->length;
|
||||
|
||||
uDstLengthInBytes += pSrcDataAsRun->length * sizeof(ValueType);
|
||||
|
||||
pSrcDataAsRun++;
|
||||
}
|
||||
|
||||
return uDstLengthInBytes;
|
||||
}
|
||||
|
Reference in New Issue
Block a user