20 #ifndef vtkX3DExporterFIWriterHelper_h 21 #define vtkX3DExporterFIWriterHelper_h 27 #define EXPONENT_MASK_32 0x7f800000 28 #define MANTISSA_MASK_32 0x007fffff 31 #define max(a,b) (((a) > (b)) ? (a) : (b)) 47 assert(writer->CurrentBytePos == 2);
51 writer->PutBits(
"11");
53 writer->PutBits(7-1, 8);
57 for (
size_t i = 0; i <
size; i++)
63 if (v.
ui == 0x80000000)
73 bytes.append(byte, 4);
82 assert(writer->CurrentBytePos == 2);
86 writer->PutBits(
"11");
88 writer->PutBits(4-1, 8);
90 for(
size_t i = 0; i <
size; i++)
93 int f = ReverseBytes(&v);
94 char *p = reinterpret_cast <
char*> (&
f);
103 assert(writer->CurrentBytePos == 2);
107 writer->PutBits(
"00");
116 int length =
static_cast<int>(value.length());
120 writer->PutBits(length - 1, 3);
122 else if (length <= 264)
124 writer->PutBits(
"1000");
125 writer->PutBits(length - 9, 8);
129 writer->PutBits(
"1100");
130 writer->PutBits(length - 265, 32);
132 writer->PutBytes(value.c_str(),
length);
141 assert(writer->CurrentBytePos == 2);
146 writer->PutBits(value - 1, 5);
148 else if (value <= 2080)
150 writer->PutBits(
"100");
151 writer->PutBits(value - 33, 11);
153 else if (value < 526368)
155 writer->PutBits(
"101");
156 writer->PutBits(value - 2081, 19);
160 writer->PutBits(
"1100000000");
161 writer->PutBits(value - 526369, 20);
170 assert(writer->CurrentBytePos == 1);
174 writer->PutBits(
"0");
175 writer->PutBits(value - 1, 6);
177 else if (value <= 8256)
179 writer->PutBits(
"10");
180 writer->PutBits(value - 65, 13);
184 writer->PutBits(
"110");
185 writer->PutBits(value - 8257, 20);
191 static bool firstTime =
true;
195 writer->PutBits(
"1001000000001010");
201 writer->PutBits(
"10100000");
207 static int ReverseBytes(
int* x) {
209 int part1 = (*x) & 0xFF;
210 int part2 = ((*x) >> 8) & 0xFF;
211 int part3 = ((*x) >> 16) & 0xFF;
212 int part4 = ((*x) >> 24) & 0xFF;
213 return (part1 << 24) | ( part2 << 16) | (part3 << 8) | part4;
229 assert(writer->CurrentBytePos == 2);
233 writer->PutBits(
"11");
235 writer->PutBits(34-1, 8);
240 int f;
unsigned char *p;
241 std::vector<unsigned char> deltas;
246 for(i = 0; i <
size; i++)
248 int v = 1 + (value[i]);
249 int *vp =
reinterpret_cast<int*
>(&v);
250 f = vtkX3DExporterFIWriterHelper::ReverseBytes(vp);
251 p = reinterpret_cast <
unsigned char*> (&
f);
252 deltas.push_back(p[0]);
253 deltas.push_back(p[1]);
254 deltas.push_back(p[2]);
255 deltas.push_back(p[3]);
261 for (i = 0; i < 20; i++)
265 span =
static_cast<char>(i) + 1;
271 for(i = 0; i < static_cast<size_t>(span); i++)
273 int v = 1 + value[i];
274 int *vp =
reinterpret_cast<int*
>(&v);
275 f = vtkX3DExporterFIWriterHelper::ReverseBytes(vp);
277 p = reinterpret_cast <
unsigned char*> (&
f);
278 deltas.push_back(p[0]);
279 deltas.push_back(p[1]);
280 deltas.push_back(p[2]);
281 deltas.push_back(p[3]);
283 for(i = span; i <
size; i++)
285 int v = 1 + (value[i] - value[i-span]);
286 f = vtkX3DExporterFIWriterHelper::ReverseBytes(&v);
288 p = reinterpret_cast <
unsigned char*> (&
f);
289 deltas.push_back(p[0]);
290 deltas.push_back(p[1]);
291 deltas.push_back(p[2]);
292 deltas.push_back(p[3]);
296 size_t bufferSize = deltas.size() +
static_cast<unsigned int>(ceil(deltas.size()*0.001)) + 12;
297 unsigned char* buffer =
new unsigned char[bufferSize];
298 size_t newSize = compressor->
Compress(&deltas[0],static_cast<unsigned long>(deltas.size()), buffer, static_cast<unsigned long>(bufferSize));
301 int size32 =
static_cast<int>(
size);
302 int size32_reversed = vtkX3DExporterFIWriterHelper::ReverseBytes(&size32);
303 char *s = reinterpret_cast <
char*> (&size32_reversed);
305 bytes.append(&span, 1);
307 for (i = 0; i < newSize; i++)
309 unsigned char c = buffer[i];
324 assert(writer->CurrentBytePos == 2);
328 writer->PutBits(
"11");
330 writer->PutBits(34, 8);
332 unsigned char* bytes =
new unsigned char[size*4];
333 unsigned char* bytepos = bytes;
337 const double* vd =
value;
338 for (i = 0; i <
size; i++)
340 union float_to_unsigned_int_to_bytes
346 float_to_unsigned_int_to_bytes v;
350 if (v.ui == 0x80000000)
355 *bytepos++ = v.ub[3];
356 *bytepos++ = v.ub[2];
357 *bytepos++ = v.ub[1];
358 *bytepos++ = v.ub[0];
364 size_t bufferSize = (size * 4) + static_cast<size_t>(ceil((size * 4)*0.001)) + 12;
365 unsigned char* buffer =
new unsigned char[bufferSize];
366 size_t newSize = compressor->
Compress(bytes,
367 static_cast<unsigned long>(size * 4), buffer,
368 static_cast<unsigned long>(bufferSize));
372 bytesCompressed +=
static_cast<char>(8);
374 bytesCompressed +=
static_cast<char>(23);
376 int length =
static_cast<int>(size*4);
377 int length_reversed = vtkX3DExporterFIWriterHelper::ReverseBytes(&length);
378 s = reinterpret_cast <
char*> (&length_reversed);
379 bytesCompressed.append(s, 4);
382 int numFloats =
static_cast<int>(
size);
383 int numFloats_reversed = vtkX3DExporterFIWriterHelper::ReverseBytes(&numFloats);
384 s = reinterpret_cast <
char*> (&numFloats_reversed);
385 bytesCompressed.append(s, 4);
387 for (i = 0; i < newSize; i++)
389 unsigned char c = buffer[i];
390 bytesCompressed += c;
static void EncodeNonEmptyByteString5(vtkX3DExporterFIByteWriter *writer, const std::string &value)
static void EncodeIntegerDeltaZ(vtkX3DExporterFIByteWriter *writer, T *value, size_t size, vtkZLibDataCompressor *compressor, bool image=false)
static void EncodeCharacterString3(vtkX3DExporterFIByteWriter *writer, const std::string &value)
static void EncodeInteger2(vtkX3DExporterFIByteWriter *writer, unsigned int value)
Data compression using zlib.
size_t Compress(unsigned char const *uncompressedData, size_t uncompressedSize, unsigned char *compressedData, size_t compressionSpace)
Compress the given input data buffer into the given output buffer.
static void EncodeInteger3(vtkX3DExporterFIByteWriter *writer, unsigned int value)
void SetCompressionLevel(int compressionLevel) override
Get/Set the compression level.
static void EncodeFloatFI(vtkX3DExporterFIByteWriter *writer, T *value, size_t size)
static void EncodeQuantizedzlibFloatArray(vtkX3DExporterFIByteWriter *writer, const double *value, size_t size, vtkZLibDataCompressor *compressor)
static void EncodeIntegerFI(vtkX3DExporterFIByteWriter *writer, T *value, size_t size)
static void EncodeLineFeed(vtkX3DExporterFIByteWriter *writer)