From a1cdf78250f065845be7986bd637cb2bcf5facfa Mon Sep 17 00:00:00 2001 From: Daviw Williams Date: Wed, 30 Jan 2013 16:49:06 +0100 Subject: [PATCH] Block now working with new MinizCompressor. Removing some old compression code. --- library/PolyVoxCore/CMakeLists.txt | 2 - .../include/PolyVoxCore/Impl/Block.h | 2 +- .../include/PolyVoxCore/Impl/Block.inl | 35 +++++++++-- .../include/PolyVoxCore/Impl/Compression.h | 38 ----------- .../PolyVoxCore/source/Impl/Compression.cpp | 63 ------------------- 5 files changed, 30 insertions(+), 110 deletions(-) delete mode 100644 library/PolyVoxCore/include/PolyVoxCore/Impl/Compression.h delete mode 100644 library/PolyVoxCore/source/Impl/Compression.cpp diff --git a/library/PolyVoxCore/CMakeLists.txt b/library/PolyVoxCore/CMakeLists.txt index c62d34ff..41d8ad78 100644 --- a/library/PolyVoxCore/CMakeLists.txt +++ b/library/PolyVoxCore/CMakeLists.txt @@ -98,7 +98,6 @@ SET(CORE_INC_FILES ) SET(IMPL_SRC_FILES - source/Impl/Compression.cpp source/Impl/ErrorHandling.cpp source/Impl/MarchingCubesTables.cpp source/Impl/RandomUnitVectors.cpp @@ -113,7 +112,6 @@ SET(IMPL_INC_FILES include/PolyVoxCore/Impl/Block.h include/PolyVoxCore/Impl/Block.inl include/PolyVoxCore/Impl/CompilerCapabilities.h - include/PolyVoxCore/Impl/Compression.h include/PolyVoxCore/Impl/Config.h include/PolyVoxCore/Impl/ErrorHandling.h include/PolyVoxCore/Impl/MarchingCubesTables.h diff --git a/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.h b/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.h index 3c253186..269f0079 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.h @@ -64,7 +64,7 @@ namespace PolyVox void uncompress(void); std::vector< RunlengthEntry > m_vecCompressedData; - uint8_t* m_pCompressedData; + void* m_pCompressedData; uint32_t m_uCompressedDataLength; VoxelType* m_tUncompressedData; uint16_t m_uSideLength; diff --git a/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.inl b/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.inl index 65325b65..8876e1b7 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.inl @@ -21,10 +21,10 @@ freely, subject to the following restrictions: distribution. *******************************************************************************/ -#include "PolyVoxCore/Impl/Compression.h" #include "PolyVoxCore/Impl/ErrorHandling.h" #include "PolyVoxCore/Impl/Utility.h" +#include "PolyVoxCore/MinizCompressor.h" #include "PolyVoxCore/Vector.h" #include "PolyVoxCore/Impl/ErrorHandling.h" @@ -151,14 +151,29 @@ namespace PolyVox //modified then we don't need to redo the compression. if(m_bIsUncompressedDataModified) { - Data src; + void* pSrcData = reinterpret_cast(m_tUncompressedData); + void* pDstData = reinterpret_cast( new uint8_t[1000000] ); + uint32_t uSrcLength = m_uSideLength * m_uSideLength * m_uSideLength * sizeof(VoxelType); + uint32_t uDstLength = 1000000; + + MinizCompressor compressor; + uint32_t uCompressedLength = compressor.compress(pSrcData, uSrcLength, pDstData, uDstLength); + + m_pCompressedData = reinterpret_cast( new uint8_t[uCompressedLength] ); + memcpy(m_pCompressedData, pDstData, uCompressedLength); + 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; + m_uCompressedDataLength = compressedResult.length;*/ /*uint32_t uNoOfVoxels = m_uSideLength * m_uSideLength * m_uSideLength; m_vecCompressedData.clear(); @@ -212,7 +227,15 @@ namespace PolyVox m_tUncompressedData = new VoxelType[m_uSideLength * m_uSideLength * m_uSideLength]; - Data src; + void* pSrcData = reinterpret_cast(m_pCompressedData); + void* pDstData = reinterpret_cast(m_tUncompressedData); + uint32_t uSrcLength = m_uCompressedDataLength; + uint32_t uDstLength = m_uSideLength * m_uSideLength * m_uSideLength * sizeof(VoxelType); + + MinizCompressor compressor; + uint32_t uUncompressedLength = compressor.decompress(pSrcData, uSrcLength, pDstData, uDstLength); + + /*Data src; src.ptr = m_pCompressedData; src.length = m_uCompressedDataLength; @@ -220,9 +243,9 @@ namespace PolyVox dst.ptr = reinterpret_cast(m_tUncompressedData); dst.length = m_uSideLength * m_uSideLength * m_uSideLength * sizeof(VoxelType); - polyvox_decompress(src, dst); + polyvox_decompress(src, dst);*/ - POLYVOX_ASSERT(dst.length == m_uSideLength * m_uSideLength * m_uSideLength * sizeof(VoxelType), "Destination length has changed."); + 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/Impl/Compression.h b/library/PolyVoxCore/include/PolyVoxCore/Impl/Compression.h deleted file mode 100644 index 6c98b4a0..00000000 --- a/library/PolyVoxCore/include/PolyVoxCore/Impl/Compression.h +++ /dev/null @@ -1,38 +0,0 @@ -/******************************************************************************* -Copyright (c) 2005-2009 David Williams - -This software is provided 'as-is', without any express or implied -warranty. In no event will the authors be held liable for any damages -arising from the use of this software. - -Permission is granted to anyone to use this software for any purpose, -including commercial applications, and to alter it and redistribute it -freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - - 3. This notice may not be removed or altered from any source - distribution. -*******************************************************************************/ - -#ifndef __PolyVox_Compression_H__ -#define __PolyVox_Compression_H__ - -#include "PolyVoxCore/Impl/TypeDef.h" - -struct Data -{ - uint8_t* ptr; - unsigned long length; // Think what type this should be. -}; - -Data polyvox_compress(Data src); -void polyvox_decompress(Data src, Data dst); - -#endif //__PolyVox_Compression_H__ \ No newline at end of file diff --git a/library/PolyVoxCore/source/Impl/Compression.cpp b/library/PolyVoxCore/source/Impl/Compression.cpp deleted file mode 100644 index d533b430..00000000 --- a/library/PolyVoxCore/source/Impl/Compression.cpp +++ /dev/null @@ -1,63 +0,0 @@ -#include "PolyVoxCore/Impl/Compression.h" -#include "PolyVoxCore/Impl/ErrorHandling.h" - -// The miniz library is supplied only as a single .c file without a header. -// Apparently the only way to use it would then be to #include it directly -// which is what the examples do. -#include "PolyVoxCore/Impl/miniz.c" - -Data polyvox_compress(Data src) -{ - POLYVOX_ASSERT(src.ptr != 0, "Source data cannot be null"); - - unsigned char* buffer; - mz_ulong compressedDataLength = compressBound(src.length); - buffer = new unsigned char[compressedDataLength]; - - int iCompressionResult = compress(buffer, &compressedDataLength, static_cast(src.ptr), src.length); - - // Debug more checking - POLYVOX_ASSERT(iCompressionResult == Z_OK, "Data compression failed."); - - // Release mode checking - if (iCompressionResult != Z_OK) - { - delete[] buffer; - POLYVOX_THROW(std::runtime_error, "Data compression failed."); - } - - Data dst; - dst.length = compressedDataLength; - dst.ptr = new uint8_t[dst.length]; - - memcpy(dst.ptr, buffer, compressedDataLength); - - delete[] buffer; - - return dst; -} - -void polyvox_decompress(Data src, Data dst) -{ - /*unsigned char* buffer; - mz_ulong uncompressedDataLength = 1000000; - buffer = new unsigned char[uncompressedDataLength];*/ - - int iUncompressionResult = uncompress(dst.ptr, &dst.length, src.ptr, src.length); - - if (iUncompressionResult != Z_OK) - { - //delete[] buffer; - POLYVOX_THROW(std::runtime_error, "Data decompression failed."); - } - - /*Data dst; - dst.length = uncompressedDataLength; - dst.ptr = new uint8_t[dst.length]; - - memcpy(dst.ptr, buffer, uncompressedDataLength); - - delete[] buffer;*/ - - //return dst; -} \ No newline at end of file