From 924744c5e633aaaf62d61bfd20cbea105b2ea230 Mon Sep 17 00:00:00 2001 From: Daviw Williams Date: Wed, 30 Jan 2013 16:58:13 +0100 Subject: [PATCH] Looks like RLECompressor works as well. --- .../include/PolyVoxCore/Impl/Block.inl | 64 ++----------------- .../include/PolyVoxCore/RLECompressor.h | 2 +- .../include/PolyVoxCore/RLECompressor.inl | 3 +- 3 files changed, 8 insertions(+), 61 deletions(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.inl b/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.inl index 8876e1b7..5cdeb34c 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.inl @@ -25,6 +25,7 @@ freely, subject to the following restrictions: #include "PolyVoxCore/Impl/Utility.h" #include "PolyVoxCore/MinizCompressor.h" +#include "PolyVoxCore/RLECompressor.h" #include "PolyVoxCore/Vector.h" #include "PolyVoxCore/Impl/ErrorHandling.h" @@ -156,7 +157,8 @@ namespace PolyVox uint32_t uSrcLength = m_uSideLength * m_uSideLength * m_uSideLength * sizeof(VoxelType); uint32_t uDstLength = 1000000; - MinizCompressor compressor; + //MinizCompressor compressor; + RLECompressor compressor; uint32_t uCompressedLength = compressor.compress(pSrcData, uSrcLength, pDstData, uDstLength); m_pCompressedData = reinterpret_cast( new uint8_t[uCompressedLength] ); @@ -164,45 +166,6 @@ namespace PolyVox m_uCompressedDataLength = uCompressedLength; delete pDstData; - - - /*Data src; - src.ptr = reinterpret_cast(m_tUncompressedData); - src.length = m_uSideLength * m_uSideLength * m_uSideLength * sizeof(VoxelType); - - Data compressedResult = polyvox_compress(src); - - m_pCompressedData = compressedResult.ptr; - m_uCompressedDataLength = compressedResult.length;*/ - - /*uint32_t uNoOfVoxels = m_uSideLength * m_uSideLength * m_uSideLength; - m_vecCompressedData.clear(); - - RunlengthEntry entry; - entry.length = 1; - entry.value = m_tUncompressedData[0]; - - for(uint32_t ct = 1; ct < uNoOfVoxels; ++ct) - { - VoxelType value = m_tUncompressedData[ct]; - if((value == entry.value) && (entry.length < entry.maxRunlength())) - { - entry.length++; - } - else - { - m_vecCompressedData.push_back(entry); - entry.value = value; - entry.length = 1; - } - } - - m_vecCompressedData.push_back(entry); - - //Shrink the vectors to their contents (maybe slow?): - //http://stackoverflow.com/questions/1111078/reduce-the-capacity-of-an-stl-vector - //C++0x may have a shrink_to_fit() function? - std::vector< RunlengthEntry >(m_vecCompressedData).swap(m_vecCompressedData);*/ } //Flag the uncompressed data as no longer being used. @@ -216,14 +179,6 @@ namespace PolyVox { POLYVOX_ASSERT(m_bIsCompressed == true, "Attempted to uncompress block which is not flagged as compressed."); POLYVOX_ASSERT(m_tUncompressedData == 0, "Uncompressed data already exists."); - /*m_tUncompressedData = new VoxelType[m_uSideLength * m_uSideLength * m_uSideLength]; - - VoxelType* pUncompressedData = m_tUncompressedData; - for(uint32_t ct = 0; ct < m_vecCompressedData.size(); ++ct) - { - std::fill(pUncompressedData, pUncompressedData + m_vecCompressedData[ct].length, m_vecCompressedData[ct].value); - pUncompressedData += m_vecCompressedData[ct].length; - }*/ m_tUncompressedData = new VoxelType[m_uSideLength * m_uSideLength * m_uSideLength]; @@ -232,19 +187,10 @@ namespace PolyVox uint32_t uSrcLength = m_uCompressedDataLength; uint32_t uDstLength = m_uSideLength * m_uSideLength * m_uSideLength * sizeof(VoxelType); - MinizCompressor compressor; + //MinizCompressor compressor; + RLECompressor compressor; uint32_t uUncompressedLength = compressor.decompress(pSrcData, uSrcLength, pDstData, uDstLength); - /*Data src; - src.ptr = m_pCompressedData; - src.length = m_uCompressedDataLength; - - Data dst; - dst.ptr = reinterpret_cast(m_tUncompressedData); - dst.length = m_uSideLength * m_uSideLength * m_uSideLength * sizeof(VoxelType); - - polyvox_decompress(src, dst);*/ - POLYVOX_ASSERT(uUncompressedLength == m_uSideLength * m_uSideLength * m_uSideLength * sizeof(VoxelType), "Destination length has changed."); //m_tUncompressedData = reinterpret_cast(uncompressedResult.ptr); diff --git a/library/PolyVoxCore/include/PolyVoxCore/RLECompressor.h b/library/PolyVoxCore/include/PolyVoxCore/RLECompressor.h index c2611eb2..8540b5ac 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/RLECompressor.h +++ b/library/PolyVoxCore/include/PolyVoxCore/RLECompressor.h @@ -1,7 +1,7 @@ #ifndef __PolyVox_RLECompressor_H__ #define __PolyVox_RLECompressor_H__ -#include +#include "PolyVoxCore/Impl/TypeDef.h" template class RLECompressor diff --git a/library/PolyVoxCore/include/PolyVoxCore/RLECompressor.inl b/library/PolyVoxCore/include/PolyVoxCore/RLECompressor.inl index 8b897f6c..167206c6 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/RLECompressor.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/RLECompressor.inl @@ -1,5 +1,6 @@ #include #include +#include template RLECompressor::RLECompressor() @@ -35,7 +36,7 @@ uint32_t RLECompressor::compress(void* pSrcData, uint32_t while(pSrcDataAsInt < pSrcDataEnd) { - if((*pSrcDataAsInt == pDstDataAsRun->value) && (pDstDataAsRun->length < std::numeric_limits::max())) + if((*pSrcDataAsInt == pDstDataAsRun->value) && (pDstDataAsRun->length < (std::numeric_limits::max)())) { pDstDataAsRun->length++; }