19 #ifndef vtkX3DExporterFIWriterHelper_h
20 #define vtkX3DExporterFIWriterHelper_h
26 #define EXPONENT_MASK_32 0x7f800000
27 #define MANTISSA_MASK_32 0x007fffff
30 #define max(a,b) (((a) > (b)) ? (a) : (b))
46 assert(writer->CurrentBytePos == 2);
50 writer->PutBits(
"11");
52 writer->PutBits(7-1, 8);
56 for (
size_t i = 0; i <
size; i++)
62 if (v.
ui == 0x80000000)
72 bytes.append(byte, 4);
81 assert(writer->CurrentBytePos == 2);
85 writer->PutBits(
"11");
87 writer->PutBits(4-1, 8);
89 for(
size_t i = 0; i <
size; i++)
92 int f = ReverseBytes(&v);
93 char *p = reinterpret_cast <
char*> (&f);
102 assert(writer->CurrentBytePos == 2);
106 writer->PutBits(
"00");
115 int length =
static_cast<int>(value.length());
119 writer->PutBits(length - 1, 3);
121 else if (length <= 264)
123 writer->PutBits(
"1000");
124 writer->PutBits(length - 9, 8);
128 writer->PutBits(
"1100");
129 writer->PutBits(length - 265, 32);
131 writer->PutBytes(value.c_str(),
length);
140 assert(writer->CurrentBytePos == 2);
145 writer->PutBits(value - 1, 5);
147 else if (value <= 2080)
149 writer->PutBits(
"100");
150 writer->PutBits(value - 33, 11);
152 else if (value < 526368)
154 writer->PutBits(
"101");
155 writer->PutBits(value - 2081, 19);
159 writer->PutBits(
"1100000000");
160 writer->PutBits(value - 526369, 20);
169 assert(writer->CurrentBytePos == 1);
173 writer->PutBits(
"0");
174 writer->PutBits(value - 1, 6);
176 else if (value <= 8256)
178 writer->PutBits(
"10");
179 writer->PutBits(value - 65, 13);
183 writer->PutBits(
"110");
184 writer->PutBits(value - 8257, 20);
190 static bool firstTime =
true;
194 writer->PutBits(
"1001000000001010");
200 writer->PutBits(
"10100000");
206 static int ReverseBytes(
int* x) {
208 int part1 = (*x) & 0xFF;
209 int part2 = ((*x) >> 8) & 0xFF;
210 int part3 = ((*x) >> 16) & 0xFF;
211 int part4 = ((*x) >> 24) & 0xFF;
212 return (part1 << 24) | ( part2 << 16) | (part3 << 8) | part4;
228 assert(writer->CurrentBytePos == 2);
232 writer->PutBits(
"11");
234 writer->PutBits(34-1, 8);
239 int f;
unsigned char *p;
240 std::vector<unsigned char> deltas;
245 for(i = 0; i <
size; i++)
247 int v = 1 + (value[i]);
248 int *vp =
reinterpret_cast<int*
>(&v);
249 f = vtkX3DExporterFIWriterHelper::ReverseBytes(vp);
250 p = reinterpret_cast <
unsigned char*> (&f);
251 deltas.push_back(p[0]);
252 deltas.push_back(p[1]);
253 deltas.push_back(p[2]);
254 deltas.push_back(p[3]);
260 for (i = 0; i < 20; i++)
264 span =
static_cast<char>(i) + 1;
270 for(i = 0; i < static_cast<size_t>(span); i++)
272 int v = 1 + value[i];
273 int *vp =
reinterpret_cast<int*
>(&v);
274 f = vtkX3DExporterFIWriterHelper::ReverseBytes(vp);
276 p = reinterpret_cast <
unsigned char*> (&f);
277 deltas.push_back(p[0]);
278 deltas.push_back(p[1]);
279 deltas.push_back(p[2]);
280 deltas.push_back(p[3]);
282 for(i = span; i <
size; i++)
284 int v = 1 + (value[i] - value[i-span]);
285 f = vtkX3DExporterFIWriterHelper::ReverseBytes(&v);
287 p = reinterpret_cast <
unsigned char*> (&f);
288 deltas.push_back(p[0]);
289 deltas.push_back(p[1]);
290 deltas.push_back(p[2]);
291 deltas.push_back(p[3]);
295 size_t bufferSize = deltas.size() +
static_cast<unsigned int>(ceil(deltas.size()*0.001)) + 12;
296 unsigned char* buffer =
new unsigned char[bufferSize];
297 size_t newSize = compressor->
Compress(&deltas[0],static_cast<unsigned long>(deltas.size()), buffer, static_cast<unsigned long>(bufferSize));
300 int size32 =
static_cast<int>(
size);
301 int size32_reversed = vtkX3DExporterFIWriterHelper::ReverseBytes(&size32);
302 char *s = reinterpret_cast <
char*> (&size32_reversed);
304 bytes.append(&span, 1);
306 for (i = 0; i < newSize; i++)
308 unsigned char c = buffer[i];
323 assert(writer->CurrentBytePos == 2);
327 writer->PutBits(
"11");
329 writer->PutBits(34, 8);
331 unsigned char* bytes =
new unsigned char[size*4];
332 unsigned char* bytepos = bytes;
336 const double* vd =
value;
337 for (i = 0; i <
size; i++)
339 union float_to_unsigned_int_to_bytes
345 float_to_unsigned_int_to_bytes v;
349 if (v.ui == 0x80000000)
354 *bytepos++ = v.ub[3];
355 *bytepos++ = v.ub[2];
356 *bytepos++ = v.ub[1];
357 *bytepos++ = v.ub[0];
363 size_t bufferSize = (size * 4) + static_cast<size_t>(ceil((size * 4)*0.001)) + 12;
364 unsigned char* buffer =
new unsigned char[bufferSize];
365 size_t newSize = compressor->
Compress(bytes,
366 static_cast<unsigned long>(size * 4), buffer,
367 static_cast<unsigned long>(bufferSize));
371 bytesCompressed +=
static_cast<char>(8);
373 bytesCompressed +=
static_cast<char>(23);
375 int length =
static_cast<int>(size*4);
376 int length_reversed = vtkX3DExporterFIWriterHelper::ReverseBytes(&length);
377 s = reinterpret_cast <
char*> (&length_reversed);
378 bytesCompressed.append(s, 4);
381 int numFloats =
static_cast<int>(
size);
382 int numFloats_reversed = vtkX3DExporterFIWriterHelper::ReverseBytes(&numFloats);;
383 s = reinterpret_cast <
char*> (&numFloats_reversed);
384 bytesCompressed.append(s, 4);
386 for (i = 0; i < newSize; i++)
388 unsigned char c = buffer[i];
389 bytesCompressed += c;
static void EncodeIntegerDeltaZ(vtkX3DExporterFIByteWriter *writer, T *value, size_t size, vtkZLibDataCompressor *compressor, bool image=false)
static void EncodeNonEmptyByteString5(vtkX3DExporterFIByteWriter *writer, std::string value)
virtual void SetCompressionLevel(int)
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)
static void EncodeInteger3(vtkX3DExporterFIByteWriter *writer, unsigned int value)
static void EncodeCharacterString3(vtkX3DExporterFIByteWriter *writer, std::string value)
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)