API Documentation
Loading...
Searching...
No Matches
Compressor.h
Go to the documentation of this file.
1#pragma once
2#include <NDEVR/Buffer.h>
3#include <NDEVR/Dictionary.h>
4#include <NDEVR/String.h>
5#include <NDEVR/Pointer.h>
6#define NDEVR_SUPPORTS_ZFP 0
7namespace NDEVR
8{
9 class File;
10 struct Module;
11 /**--------------------------------------------------------------------------------------------------
12 \brief Logical information about the type of compression implemented or requested
13
14 **/
34
35 /**--------------------------------------------------------------------------------------------------
36 \brief Contains information for referencing compressed strings.
37
38 Typically these are combined into a larger buffer so this object will store the beginnning and end
39 of that buffer
40 **/
46
47 /**--------------------------------------------------------------------------------------------------
48 \brief A container for storing compressed data, typically used for File IO operations.
49 Responsible for storing the data associated with the compression.
50 **/
65 /**--------------------------------------------------------------------------------------------------
66 \brief Class which is designed to compress objects for writing to file. Typically objects are added
67 then the compressor is run compressing all data at once.
68 **/
70 {
71 public:
72 template<class t_type>
73 static CompressionMode PickCompressionMode(CompressionMode compression_mode = e_default_compression)
74 {
75 if (compression_mode == e_best_compression || compression_mode == e_default_compression)
76 {
78 compression_mode = e_string_reference;
79#if NDEVR_SUPPORTS_ZFP
81 {
83 {
84 case 0:
85 case 1:
86 if (sizeof(t_type) == 4)
88 else if (sizeof(t_type) == 8)
90 break;
91 case 2:
92 if (sizeof(t_type) / 2 == 4)
94 else if (sizeof(t_type) / 2 == 8)
96 break;
97 case 3:
98 if (sizeof(t_type) / 3 == 4)
100 else if (sizeof(t_type) / 3 == 8)
101 compression_mode = e_floating_point_compression_3_fltp08;
102 break;
103 case 4:
104 if (sizeof(t_type) / 4 == 4)
105 compression_mode = e_floating_point_compression_4_fltp04;
106 else if (sizeof(t_type) / 4 == 8)
107 compression_mode = e_floating_point_compression_4_fltp08;
108 break;
109 }
110 }
111#endif
112 }
113 return compression_mode;
114 }
115
116 template<class t_type, class t_index_type, class t_memory_allocator, class t_memory_manager>
117 static typename std::enable_if<!ObjectInfo<t_type>::Buffer>::type Compress(BinaryCompressionObject& object, Buffer<uint01>& compression_data, const Buffer<t_type, t_index_type, t_memory_allocator, t_memory_manager>& data)
118 {
119 object.buffer_size = data.size();
120 if (object.buffer_size != 0)
121 {
122 object.compression_mode = Compressor::PickCompressionMode<t_type>(object.compression_mode);
123 object.uncompressed_data = (uint01*)data.ptr();
124 object.uncompressed_size = data.memSize();
125 switch (object.compression_mode)
126 {
128 compression_data.setSize(sizeof(Bounds<1, uint04>));
129 object.compressed_size = sizeof(Bounds<1, uint04>);
130 break;
132 compression_data.clear();
133 object.compressed_size = 0;
134 break;
135 default:
136 compression_data.setSize(data.memSize());
137 object.compressed_size = data.memSize();
138 break;
139 }
140 object.compressed_data = compression_data.begin();
141 CompressData(object);
142 if(object.compression_mode != e_string_reference)
143 compression_data.setSize(cast<t_index_type>(object.compressed_size));
144
145 }
146 else
147 {
148 compression_data.clear();
149 }
150 }
151
152 template<class t_index_type, class t_memory_allocator, class t_memory_manager>
154 {
155 Buffer<uint04> locations;
156 locations.setSize(data.size());
157 for (uint04 i = 0; i < data.size(); i++)
158 {
159 CompressedStringInfo info = AddString(object, data[i]);
160 locations[i] = info.index;
161 }
162 Compress(object, compression_data, locations);
163 }
164
165 template<class t_type, class t_index_type, class t_memory_allocator, class t_memory_manager>
166 static typename std::enable_if<ObjectInfo<t_type>::Buffer>::type Compress(BinaryCompressionObject& object, Buffer<uint01>& compression_data, const Buffer<t_type, t_index_type, t_memory_allocator, t_memory_manager>& data)
167 {
168 Buffer<uint01> temp_compress;
169 Buffer<uint04> sizes;
170 sizes.setSize(data.size());
171 Buffer<decltype(t_type::Type())> combined_data;
172 for (uint04 i = 0; i < data.size(); i++)
173 {
174 sizes[i] = data[i].size();
175 combined_data.addAll(data[i]);
176 }
177 compression_data.clear();
179 *sub_obj = object;
180 object.compression_link = sub_obj;
181
182 Compress(*sub_obj, temp_compress, sizes);
183 compression_data += temp_compress;
184
185 Compress(object, temp_compress, combined_data);
186 compression_data += temp_compress;
187 sub_obj->compressed_data = compression_data.begin();
188 object.compressed_data = compression_data.begin(cast<t_index_type>(sub_obj->compressed_size));
189 }
190
194 static sint04 ZLibDecompress(const uint01* compressed, uint01* uncompressed, size_t compressed_size, size_t& decompressed_size);
195 static sint04 ZLibCompress(uint01* compressed, const uint01* uncompressed, size_t& compressed_size, size_t decompressed_size);
196 static sint04 ZLibDecompressFile(File src, File output_dir);
198 static char* GetString(BinaryCompressionObject& data, const Bounds<1, uint04>& bounds);
199 static char* GetString(BinaryCompressionObject& data, uint04 index);
201 };
202}
#define NDEVR_BASE_API
Definition DLLInfo.h:57
A specification of upper and lower bounds in N-dimensions.
Definition Bounds.hpp:52
The equivelent of std::vector but with a bit more control. The basic array unit of the library.
Definition Buffer.hpp:56
constexpr t_index_type size() const
Definition Buffer.hpp:823
decltype(auto) ptr()
Definition Buffer.hpp:387
void setSize(t_index_type new_size)
Definition Buffer.hpp:803
decltype(auto) begin()
Definition Buffer.hpp:402
t_index_type memSize() const
Definition Buffer.hpp:397
void clear()
Definition Buffer.hpp:422
Class which is designed to compress objects for writing to file. Typically objects are added then the...
Definition Compressor.h:70
static sint04 ZLibCompress(uint01 *compressed, const uint01 *uncompressed, size_t &compressed_size, size_t decompressed_size)
static void DecompressData(BinaryCompressionObject &data)
static Module ZLibModule()
static CompressedStringInfo AddString(BinaryCompressionObject &data, const String &string)
static sint04 ZLibDecompressFile(File src, File output_dir)
static uint04 GetStringLength(BinaryCompressionObject &data, uint04 index)
static void CompressData(BinaryCompressionObject &data)
static char * GetString(BinaryCompressionObject &data, uint04 index)
static char * GetString(BinaryCompressionObject &data, const Bounds< 1, uint04 > &bounds)
static std::enable_if< ObjectInfo< t_type >::Buffer >::type Compress(BinaryCompressionObject &object, Buffer< uint01 > &compression_data, const Buffer< t_type, t_index_type, t_memory_allocator, t_memory_manager > &data)
Definition Compressor.h:166
static CompressionMode PickCompressionMode(CompressionMode compression_mode=e_default_compression)
Definition Compressor.h:73
static std::enable_if<!ObjectInfo< t_type >::Buffer >::type Compress(BinaryCompressionObject &object, Buffer< uint01 > &compression_data, const Buffer< t_type, t_index_type, t_memory_allocator, t_memory_manager > &data)
Definition Compressor.h:117
static void CompressString(BinaryCompressionObject &object, Buffer< uint01 > &compression_data, const Buffer< String, t_index_type, t_memory_allocator, t_memory_manager > &data)
Definition Compressor.h:153
static sint04 ZLibDecompress(const uint01 *compressed, uint01 *uncompressed, size_t compressed_size, size_t &decompressed_size)
A hash-based key-value store, useful for quick associative lookups. Key features include:
Definition Dictionary.h:61
Provides a modifiable pointer that has shared ownership of a dynamically allocated object.
Definition Pointer.hpp:320
Logic for reading or writing to a file as well as navigating filesystems.
Definition File.h:48
The core String class for the NDEVR API.
Definition String.h:69
Definition ACIColor.h:37
int32_t sint04
-Defines an alias representing a 4 byte, signed integer. -Can represent exact integer values -2147483...
Definition BaseValues.hpp:64
uint8_t uint01
-Defines an alias representing a 1 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:80
CompressionMode
Logical information about the type of compression implemented or requested.
Definition Compressor.h:16
@ e_best_compression
Definition Compressor.h:22
@ e_floating_point_compression_1_fltp04
Definition Compressor.h:23
@ e_floating_point_compression_2_fltp04
Definition Compressor.h:24
@ e_default_compression
Definition Compressor.h:18
@ e_floating_point_compression_4_fltp08
Definition Compressor.h:30
@ e_floating_point_compression_3_fltp08
Definition Compressor.h:29
@ e_no_compression
Definition Compressor.h:17
@ e_floating_point_compression_2_fltp08
Definition Compressor.h:28
@ e_string_compression
Definition Compressor.h:20
@ e_floating_point_compression_4_fltp04
Definition Compressor.h:26
@ e_compression_count
Definition Compressor.h:32
@ e_floating_point_compression_1_fltp08
Definition Compressor.h:27
@ e_floating_point_compression_3_fltp04
Definition Compressor.h:25
@ e_best_speed
Definition Compressor.h:19
@ e_floating_point_compression
Definition Compressor.h:21
@ e_string_reference
Definition Compressor.h:31
uint64_t uint08
-Defines an alias representing an 8 byte, unsigned integer
Definition BaseValues.hpp:106
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:96
A container for storing compressed data, typically used for File IO operations. Responsible for stori...
Definition Compressor.h:52
uint01 * compressed_data
Definition Compressor.h:56
uint08 compressed_size
Definition Compressor.h:57
Buffer< Bounds< 1, uint04 > > * m_string_size_info
Definition Compressor.h:61
uint01 * uncompressed_data
Definition Compressor.h:54
Dictionary< String, uint04 > * m_string_reference
Definition Compressor.h:60
uint08 uncompressed_size
Definition Compressor.h:55
String * m_strings
Definition Compressor.h:62
CompressionMode compression_mode
Definition Compressor.h:53
DynamicPointer< BinaryCompressionObject > compression_link
Definition Compressor.h:63
uint08 buffer_size
Definition Compressor.h:58
Contains information for referencing compressed strings.
Definition Compressor.h:42
Bounds< 1, uint04 > bounds
Definition Compressor.h:44
uint04 index
Definition Compressor.h:43
Base class for extensions, typically added as external DLL's that can modify or enhance the behavior ...
Definition ModuleManager.h:59
Information about the object.
Definition ObjectInfo.h:54