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;
30
36
52 {
53 public:
54 template<class t_type>
55 static CompressionMode PickCompressionMode(CompressionMode compression_mode = e_default_compression)
56 {
57 if (compression_mode == e_best_compression || compression_mode == e_default_compression)
58 {
60 compression_mode = e_string_reference;
61#if NDEVR_SUPPORTS_ZFP
63 {
65 {
66 case 0:
67 case 1:
68 if (sizeof(t_type) == 4)
70 else if (sizeof(t_type) == 8)
72 break;
73 case 2:
74 if (sizeof(t_type) / 2 == 4)
76 else if (sizeof(t_type) / 2 == 8)
78 break;
79 case 3:
80 if (sizeof(t_type) / 3 == 4)
82 else if (sizeof(t_type) / 3 == 8)
84 break;
85 case 4:
86 if (sizeof(t_type) / 4 == 4)
88 else if (sizeof(t_type) / 4 == 8)
90 break;
91 }
92 }
93#endif
94 //else if (ObjectInfo<t_type>::Float)
95 //compression_mode = e_floating_point_compression;
96 }
97 return compression_mode;
98 }
99
100 template<class t_type, class t_index_type, class t_memory_allocator, class t_memory_manager>
101 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)
102 {
103 object.buffer_size = data.size();
104 if (object.buffer_size != 0)
105 {
106 object.compression_mode = Compressor::PickCompressionMode<t_type>(object.compression_mode);
107 object.uncompressed_data = (uint01*)data.ptr();
108 object.uncompressed_size = data.memSize();
109 switch (object.compression_mode)
110 {
112 compression_data.setSize(sizeof(Bounds<1, uint04>));
113 object.compressed_size = sizeof(Bounds<1, uint04>);
114 break;
116 compression_data.clear();
117 object.compressed_size = 0;
118 break;
119 default:
120 compression_data.setSize(data.memSize());
121 object.compressed_size = data.memSize();
122 break;
123 }
124 object.compressed_data = compression_data.begin();
125 CompressData(object);
126 if(object.compression_mode != e_string_reference)
127 compression_data.setSize(cast<t_index_type>(object.compressed_size));
128
129 }
130 else
131 {
132 compression_data.clear();
133 }
134 }
135
136 template<class t_index_type, class t_memory_allocator, class t_memory_manager>
138 {
139 Buffer<uint04> locations;
140 locations.setSize(data.size());
141 for (uint04 i = 0; i < data.size(); i++)
142 {
143 CompressedStringInfo info = AddString(object, data[i]);
144 locations[i] = info.index;
145 }
146 Compress(object, compression_data, locations);
147 }
148
149 template<class t_type, class t_index_type, class t_memory_allocator, class t_memory_manager>
150 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)
151 {
152 Buffer<uint01> temp_compress;
153 Buffer<uint04> sizes;
154 sizes.setSize(data.size());
155 Buffer<decltype(t_type::Type())> combined_data;
156 for (uint04 i = 0; i < data.size(); i++)
157 {
158 sizes[i] = data[i].size();
159 combined_data.addAll(data[i]);
160 }
161 compression_data.clear();
163 *sub_obj = object;
164 object.compression_link = sub_obj;
165
166 Compress(*sub_obj, temp_compress, sizes);
167 compression_data += temp_compress;
168
169 Compress(object, temp_compress, combined_data);
170 compression_data += temp_compress;
171 sub_obj->compressed_data = compression_data.begin();
172 object.compressed_data = compression_data.begin(cast<t_index_type>(sub_obj->compressed_size));
173 }
174
178 static sint04 ZLibDecompress(const uint01* compressed, uint01* uncompressed, size_t compressed_size, size_t& decompressed_size);
179 static sint04 ZLibCompress(uint01* compressed, const uint01* uncompressed, size_t& compressed_size, size_t decompressed_size);
180 static sint04 ZLibDecompressFile(File src, File output_dir);
182 static char* GetString(BinaryCompressionObject& data, const Bounds<1, uint04>& bounds);
183 static char* GetString(BinaryCompressionObject& data, uint04 index);
185 };
186}
#define NDEVR_BASE_API
Definition DLLInfo.h:78
A specification of upper and lower bounds in N-dimensions.
Definition Bounds.hpp:57
The equivelent of std::vector but with a bit more control. The basic array unit of the library.
Definition Buffer.hpp:64
constexpr t_index_type size() const
Definition Buffer.hpp:1461
decltype(auto) ptr()
Definition Buffer.hpp:489
void setSize(t_index_type new_size)
Definition Buffer.hpp:1413
decltype(auto) begin()
Definition Buffer.hpp:504
t_index_type memSize() const
Definition Buffer.hpp:499
void clear()
Definition Buffer.hpp:572
Definition Compressor.h:52
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:150
static CompressionMode PickCompressionMode(CompressionMode compression_mode=e_default_compression)
Definition Compressor.h:55
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:101
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:137
static sint04 ZLibDecompress(const uint01 *compressed, uint01 *uncompressed, size_t compressed_size, size_t &decompressed_size)
Definition Dictionary.h:48
Definition Pointer.hpp:303
Definition File.h:47
Definition String.h:40
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:76
uint8_t uint01
-Defines an alias representing a 1 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:98
CompressionMode
Definition Compressor.h:12
@ e_best_compression
Definition Compressor.h:18
@ e_floating_point_compression_1_fltp04
Definition Compressor.h:19
@ e_floating_point_compression_2_fltp04
Definition Compressor.h:20
@ e_default_compression
Definition Compressor.h:14
@ e_floating_point_compression_4_fltp08
Definition Compressor.h:26
@ e_floating_point_compression_3_fltp08
Definition Compressor.h:25
@ e_no_compression
Definition Compressor.h:13
@ e_floating_point_compression_2_fltp08
Definition Compressor.h:24
@ e_string_compression
Definition Compressor.h:16
@ e_floating_point_compression_4_fltp04
Definition Compressor.h:22
@ e_compression_count
Definition Compressor.h:28
@ e_floating_point_compression_1_fltp08
Definition Compressor.h:23
@ e_floating_point_compression_3_fltp04
Definition Compressor.h:21
@ e_best_speed
Definition Compressor.h:15
@ e_floating_point_compression
Definition Compressor.h:17
@ e_string_reference
Definition Compressor.h:27
uint64_t uint08
-Defines an alias representing an 8 byte, unsigned integer -Can represent exact integer values 0 thro...
Definition BaseValues.hpp:132
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:120
Definition Compressor.h:38
uint01 * compressed_data
Definition Compressor.h:42
uint08 compressed_size
Definition Compressor.h:43
Buffer< Bounds< 1, uint04 > > * m_string_size_info
Definition Compressor.h:47
uint01 * uncompressed_data
Definition Compressor.h:40
Dictionary< String, uint04 > * m_string_reference
Definition Compressor.h:46
uint08 uncompressed_size
Definition Compressor.h:41
String * m_strings
Definition Compressor.h:48
CompressionMode compression_mode
Definition Compressor.h:39
DynamicPointer< BinaryCompressionObject > compression_link
Definition Compressor.h:49
uint08 buffer_size
Definition Compressor.h:44
Definition Compressor.h:32
Bounds< 1, uint04 > bounds
Definition Compressor.h:34
uint04 index
Definition Compressor.h:33
Definition ModuleManager.h:54
Information about the object.
Definition ObjectInfo.h:56