diff --git a/CMakeLists.txt b/CMakeLists.txt index 31767af1e6abb600fff1e615a83010cbba2a3f66..e706b3a45b5ea9c832ef246941816bd0c9d11c90 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -90,6 +90,7 @@ ENDIF() #OGS_PACKAGING ADD_SUBDIRECTORY( ThirdParty ) INCLUDE_DIRECTORIES( ${CMAKE_SOURCE_DIR}/ThirdParty ) INCLUDE_DIRECTORIES( ${CMAKE_SOURCE_DIR}/ThirdParty/quickcheck ) +INCLUDE_DIRECTORIES( ${CMAKE_BINARY_DIR}/ThirdParty/zlib ) ADD_SUBDIRECTORY( BaseLib ) ADD_SUBDIRECTORY( FemLib ) diff --git a/FileIO/RapidXmlIO/zLibDataCompressor.cpp b/FileIO/RapidXmlIO/zLibDataCompressor.cpp new file mode 100644 index 0000000000000000000000000000000000000000..154634ec5e7efb67c12e62818880cc4fe0f803a2 --- /dev/null +++ b/FileIO/RapidXmlIO/zLibDataCompressor.cpp @@ -0,0 +1,64 @@ +/** + * Copyright (c) 2012, OpenGeoSys Community (http://www.opengeosys.net) + * Distributed under a Modified BSD License. + * See accompanying file LICENSE.txt or + * http://www.opengeosys.net/LICENSE.txt + * + * \file zLibDataCompressor.cpp + * + * Created on 2012-11-26 by Karsten Rink + * Based on the vtkZLibDataCompressor-class in VTK 5.6 + */ + +#include "zLibDataCompressor.h" +#include <cstddef> +#include <iostream> +#include "zlib/zlib.h" + + +unsigned long zLibDataCompressor::CompressBuffer(const unsigned char* uncompressedData, + unsigned long uncompressedSize, + unsigned char* compressedData, + unsigned long compressionSpace) +{ + int CompressionLevel = Z_DEFAULT_COMPRESSION; + unsigned long compressedSize = compressionSpace; + Bytef* cd = reinterpret_cast<Bytef*>(compressedData); + const Bytef* ud = reinterpret_cast<const Bytef*>(uncompressedData); + + // Call zlib's compress function. + if(compress2(cd, &compressedSize, ud, uncompressedSize, CompressionLevel) != Z_OK) + { + std::cout << "Zlib error while compressing data." << std::endl; + return 0; + } + + return compressedSize; +} + +unsigned long zLibDataCompressor::UncompressBuffer(const unsigned char* compressedData, + unsigned long compressedSize, + unsigned char* uncompressedData, + unsigned long uncompressedSize) +{ + unsigned long decSize = uncompressedSize; + Bytef* ud = reinterpret_cast<Bytef*>(uncompressedData); + const Bytef* cd = reinterpret_cast<const Bytef*>(compressedData); + + // Call zlib's uncompress function. + if(uncompress(ud, &decSize, cd, compressedSize) != Z_OK) + { + std::cout << "Zlib error while uncompressing data." << std::endl; + return 0; + } + + // Make sure the output size matched that expected. + if(decSize != uncompressedSize) + { + std::cout << "Decompression produced incorrect size. Expected " + << uncompressedSize << " and got " << decSize << std::endl; + return 0; + } + + return decSize; +} diff --git a/FileIO/RapidXmlIO/zLibDataCompressor.h b/FileIO/RapidXmlIO/zLibDataCompressor.h new file mode 100644 index 0000000000000000000000000000000000000000..e6cc033bc91486682560070be9c0026cd900edef --- /dev/null +++ b/FileIO/RapidXmlIO/zLibDataCompressor.h @@ -0,0 +1,39 @@ +/** + * Copyright (c) 2012, OpenGeoSys Community (http://www.opengeosys.net) + * Distributed under a Modified BSD License. + * See accompanying file LICENSE.txt or + * http://www.opengeosys.net/LICENSE.txt + * + * \file zLibDataCompressor.h + * + * Created on 2012-11-26 by Karsten Rink + * Based on the vtkZLibDataCompressor-class in VTK 5.6 + */ + +#ifndef ZLIBDATACOMPRESSOR_H +#define ZLIBDATACOMPRESSOR_H + + + +class zLibDataCompressor +{ +public: + unsigned long GetMaximumCompressionSpace(unsigned long size); + + // Compression method required by vtkDataCompressor. + static unsigned long CompressBuffer(const unsigned char* uncompressedData, + unsigned long uncompressedSize, + unsigned char* compressedData, + unsigned long compressionSpace); + + // Decompression method required by vtkDataCompressor. + static unsigned long UncompressBuffer(const unsigned char* compressedData, + unsigned long compressedSize, + unsigned char* uncompressedData, + unsigned long uncompressedSize); +private: + +}; + +#endif //ZLIBDATACOMPRESSOR_H +