1 | /** |
---|
2 | * @file szd_int32.c |
---|
3 | * @author Sheng Di |
---|
4 | * @date Aug, 2017 |
---|
5 | * @brief |
---|
6 | * (C) 2016 by Mathematics and Computer Science (MCS), Argonne National Laboratory. |
---|
7 | * See COPYRIGHT in top-level directory. |
---|
8 | */ |
---|
9 | |
---|
10 | #include <stdlib.h> |
---|
11 | #include <stdio.h> |
---|
12 | #include <string.h> |
---|
13 | #include <math.h> |
---|
14 | #include "TightDataPointStorageI.h" |
---|
15 | #include "sz.h" |
---|
16 | #include "szd_int32.h" |
---|
17 | #include "Huffman.h" |
---|
18 | |
---|
19 | /** |
---|
20 | * |
---|
21 | * |
---|
22 | * @return status SUCCESSFUL (SZ_SCES) or not (other error codes) f |
---|
23 | * */ |
---|
24 | int SZ_decompress_args_int32(int32_t** newData, size_t r5, size_t r4, size_t r3, size_t r2, size_t r1, unsigned char* cmpBytes, size_t cmpSize) |
---|
25 | { |
---|
26 | int status = SZ_SCES; |
---|
27 | size_t dataLength = computeDataLength(r5,r4,r3,r2,r1); |
---|
28 | |
---|
29 | //unsigned char* tmpBytes; |
---|
30 | size_t targetUncompressSize = dataLength <<2; //i.e., *4 |
---|
31 | //tmpSize must be "much" smaller than dataLength |
---|
32 | size_t i, tmpSize = 3+MetaDataByteLength+1+sizeof(int32_t)+exe_params->SZ_SIZE_TYPE; |
---|
33 | unsigned char* szTmpBytes; |
---|
34 | |
---|
35 | if(cmpSize!=4+4+4+MetaDataByteLength && cmpSize!=4+4+8+MetaDataByteLength) |
---|
36 | { |
---|
37 | int isZlib = isZlibFormat(cmpBytes[0], cmpBytes[1]); |
---|
38 | if(isZlib) |
---|
39 | confparams_dec->szMode = SZ_BEST_COMPRESSION; |
---|
40 | else |
---|
41 | confparams_dec->szMode = SZ_BEST_SPEED; |
---|
42 | if(confparams_dec->szMode==SZ_BEST_SPEED) |
---|
43 | { |
---|
44 | tmpSize = cmpSize; |
---|
45 | szTmpBytes = cmpBytes; |
---|
46 | } |
---|
47 | else if(confparams_dec->szMode==SZ_BEST_COMPRESSION || confparams_dec->szMode==SZ_DEFAULT_COMPRESSION) |
---|
48 | { |
---|
49 | if(targetUncompressSize<MIN_ZLIB_DEC_ALLOMEM_BYTES) //Considering the minimum size |
---|
50 | targetUncompressSize = MIN_ZLIB_DEC_ALLOMEM_BYTES; |
---|
51 | tmpSize = zlib_uncompress5(cmpBytes, (unsigned long)cmpSize, &szTmpBytes, (unsigned long)targetUncompressSize+4+MetaDataByteLength+exe_params->SZ_SIZE_TYPE);// (unsigned long)targetUncompressSize+8: consider the total length under lossless compression mode is actually 3+4+1+targetUncompressSize |
---|
52 | //szTmpBytes = (unsigned char*)malloc(sizeof(unsigned char)*tmpSize); |
---|
53 | //memcpy(szTmpBytes, tmpBytes, tmpSize); |
---|
54 | //free(tmpBytes); //release useless memory |
---|
55 | } |
---|
56 | else |
---|
57 | { |
---|
58 | printf("Wrong value of confparams_dec->szMode in the double compressed bytes.\n"); |
---|
59 | status = SZ_MERR; |
---|
60 | return status; |
---|
61 | } |
---|
62 | } |
---|
63 | else |
---|
64 | szTmpBytes = cmpBytes; |
---|
65 | //TODO: convert szTmpBytes to data array. |
---|
66 | TightDataPointStorageI* tdps; |
---|
67 | int errBoundMode = new_TightDataPointStorageI_fromFlatBytes(&tdps, szTmpBytes, tmpSize); |
---|
68 | //writeByteData(tdps->typeArray, tdps->typeArray_size, "decompress-typebytes.tbt"); |
---|
69 | int dim = computeDimension(r5,r4,r3,r2,r1); |
---|
70 | int intSize = sizeof(int32_t); |
---|
71 | if(tdps->isLossless) |
---|
72 | { |
---|
73 | *newData = (int32_t*)malloc(intSize*dataLength); |
---|
74 | if(sysEndianType==BIG_ENDIAN_SYSTEM) |
---|
75 | { |
---|
76 | memcpy(*newData, szTmpBytes+4+MetaDataByteLength+exe_params->SZ_SIZE_TYPE, dataLength*intSize); |
---|
77 | } |
---|
78 | else |
---|
79 | { |
---|
80 | unsigned char* p = szTmpBytes+4+MetaDataByteLength+exe_params->SZ_SIZE_TYPE; |
---|
81 | for(i=0;i<dataLength;i++,p+=intSize) |
---|
82 | (*newData)[i] = bytesToInt32_bigEndian(p); |
---|
83 | } |
---|
84 | } |
---|
85 | else if (dim == 1) |
---|
86 | getSnapshotData_int32_1D(newData,r1,tdps, errBoundMode); |
---|
87 | else |
---|
88 | if (dim == 2) |
---|
89 | getSnapshotData_int32_2D(newData,r2,r1,tdps, errBoundMode); |
---|
90 | else |
---|
91 | if (dim == 3) |
---|
92 | getSnapshotData_int32_3D(newData,r3,r2,r1,tdps, errBoundMode); |
---|
93 | else |
---|
94 | if (dim == 4) |
---|
95 | getSnapshotData_int32_4D(newData,r4,r3,r2,r1,tdps, errBoundMode); |
---|
96 | else |
---|
97 | { |
---|
98 | printf("Error: currently support only at most 4 dimensions!\n"); |
---|
99 | status = SZ_DERR; |
---|
100 | } |
---|
101 | free_TightDataPointStorageI2(tdps); |
---|
102 | if(confparams_dec->szMode!=SZ_BEST_SPEED && cmpSize!=4+sizeof(int32_t)+exe_params->SZ_SIZE_TYPE+MetaDataByteLength) |
---|
103 | free(szTmpBytes); |
---|
104 | return status; |
---|
105 | } |
---|
106 | |
---|
107 | |
---|
108 | void decompressDataSeries_int32_1D(int32_t** data, size_t dataSeriesLength, TightDataPointStorageI* tdps) |
---|
109 | { |
---|
110 | updateQuantizationInfo(tdps->intervals); |
---|
111 | size_t i; |
---|
112 | double interval = tdps->realPrecision*2; |
---|
113 | |
---|
114 | *data = (int32_t*)malloc(sizeof(int32_t)*dataSeriesLength); |
---|
115 | |
---|
116 | int* type = (int*)malloc(dataSeriesLength*sizeof(int)); |
---|
117 | |
---|
118 | HuffmanTree* huffmanTree = createHuffmanTree(tdps->stateNum); |
---|
119 | decode_withTree(huffmanTree, tdps->typeArray, dataSeriesLength, type); |
---|
120 | SZ_ReleaseHuffman(huffmanTree); |
---|
121 | |
---|
122 | //sdi:Debug |
---|
123 | //writeUShortData(type, dataSeriesLength, "decompressStateBytes.sb"); |
---|
124 | |
---|
125 | int32_t minValue, exactData, predValue; |
---|
126 | |
---|
127 | minValue = tdps->minValue; |
---|
128 | |
---|
129 | int exactByteSize = tdps->exactByteSize; |
---|
130 | unsigned char* exactDataBytePointer = tdps->exactDataBytes; |
---|
131 | |
---|
132 | unsigned char curBytes[8] = {0,0,0,0,0,0,0,0}; |
---|
133 | |
---|
134 | int rightShiftBits = computeRightShiftBits(exactByteSize, SZ_INT32); |
---|
135 | if(rightShiftBits<0) |
---|
136 | { |
---|
137 | printf("Error: rightShift < 0!\n"); |
---|
138 | exit(0); |
---|
139 | } |
---|
140 | int type_; |
---|
141 | for (i = 0; i < dataSeriesLength; i++) { |
---|
142 | type_ = type[i]; |
---|
143 | switch (type_) { |
---|
144 | case 0: |
---|
145 | // recover the exact data |
---|
146 | memcpy(curBytes, exactDataBytePointer, exactByteSize); |
---|
147 | exactData = bytesToInt32_bigEndian(curBytes); |
---|
148 | exactData = (uint32_t)exactData >> rightShiftBits; |
---|
149 | exactDataBytePointer += exactByteSize; |
---|
150 | (*data)[i] = exactData + minValue; |
---|
151 | break; |
---|
152 | default: |
---|
153 | //predValue = 2 * (*data)[i-1] - (*data)[i-2]; |
---|
154 | predValue = (*data)[i-1]; |
---|
155 | (*data)[i] = predValue + (type_-exe_params->intvRadius)*interval; |
---|
156 | break; |
---|
157 | } |
---|
158 | //printf("%.30G\n",(*data)[i]); |
---|
159 | } |
---|
160 | free(type); |
---|
161 | return; |
---|
162 | } |
---|
163 | |
---|
164 | void decompressDataSeries_int32_2D(int32_t** data, size_t r1, size_t r2, TightDataPointStorageI* tdps) |
---|
165 | { |
---|
166 | updateQuantizationInfo(tdps->intervals); |
---|
167 | //printf("tdps->intervals=%d, exe_params->intvRadius=%d\n", tdps->intervals, exe_params->intvRadius); |
---|
168 | |
---|
169 | size_t dataSeriesLength = r1*r2; |
---|
170 | // printf ("%d %d\n", r1, r2); |
---|
171 | |
---|
172 | double realPrecision = tdps->realPrecision; |
---|
173 | |
---|
174 | *data = (int32_t*)malloc(sizeof(int32_t)*dataSeriesLength); |
---|
175 | |
---|
176 | int* type = (int*)malloc(dataSeriesLength*sizeof(int)); |
---|
177 | |
---|
178 | HuffmanTree* huffmanTree = createHuffmanTree(tdps->stateNum); |
---|
179 | decode_withTree(huffmanTree, tdps->typeArray, dataSeriesLength, type); |
---|
180 | SZ_ReleaseHuffman(huffmanTree); |
---|
181 | |
---|
182 | int32_t minValue, exactData; |
---|
183 | |
---|
184 | minValue = tdps->minValue; |
---|
185 | |
---|
186 | int exactByteSize = tdps->exactByteSize; |
---|
187 | unsigned char* exactDataBytePointer = tdps->exactDataBytes; |
---|
188 | |
---|
189 | unsigned char curBytes[8] = {0,0,0,0,0,0,0,0}; |
---|
190 | |
---|
191 | int rightShiftBits = computeRightShiftBits(exactByteSize, SZ_INT32); |
---|
192 | |
---|
193 | int32_t pred1D, pred2D; |
---|
194 | size_t ii, jj; |
---|
195 | |
---|
196 | /* Process Row-0, data 0 */ |
---|
197 | |
---|
198 | // recover the exact data |
---|
199 | memcpy(curBytes, exactDataBytePointer, exactByteSize); |
---|
200 | exactData = bytesToInt32_bigEndian(curBytes); |
---|
201 | exactData = (uint32_t)exactData >> rightShiftBits; |
---|
202 | exactDataBytePointer += exactByteSize; |
---|
203 | (*data)[0] = exactData + minValue; |
---|
204 | |
---|
205 | /* Process Row-0, data 1 */ |
---|
206 | int type_ = type[1]; |
---|
207 | if (type_ != 0) |
---|
208 | { |
---|
209 | pred1D = (*data)[0]; |
---|
210 | (*data)[1] = pred1D + 2 * (type_ - exe_params->intvRadius) * realPrecision; |
---|
211 | } |
---|
212 | else |
---|
213 | { |
---|
214 | // recover the exact data |
---|
215 | memcpy(curBytes, exactDataBytePointer, exactByteSize); |
---|
216 | exactData = bytesToInt32_bigEndian(curBytes); |
---|
217 | exactData = (uint32_t)exactData >> rightShiftBits; |
---|
218 | exactDataBytePointer += exactByteSize; |
---|
219 | (*data)[1] = exactData + minValue; |
---|
220 | } |
---|
221 | |
---|
222 | /* Process Row-0, data 2 --> data r2-1 */ |
---|
223 | for (jj = 2; jj < r2; jj++) |
---|
224 | { |
---|
225 | type_ = type[jj]; |
---|
226 | if (type_ != 0) |
---|
227 | { |
---|
228 | pred1D = 2*(*data)[jj-1] - (*data)[jj-2]; |
---|
229 | (*data)[jj] = pred1D + 2 * (type_ - exe_params->intvRadius) * realPrecision; |
---|
230 | } |
---|
231 | else |
---|
232 | { |
---|
233 | // recover the exact data |
---|
234 | memcpy(curBytes, exactDataBytePointer, exactByteSize); |
---|
235 | exactData = bytesToInt32_bigEndian(curBytes); |
---|
236 | exactData = (uint32_t)exactData >> rightShiftBits; |
---|
237 | exactDataBytePointer += exactByteSize; |
---|
238 | (*data)[jj] = exactData + minValue; |
---|
239 | } |
---|
240 | } |
---|
241 | |
---|
242 | size_t index; |
---|
243 | /* Process Row-1 --> Row-r1-1 */ |
---|
244 | for (ii = 1; ii < r1; ii++) |
---|
245 | { |
---|
246 | /* Process row-ii data 0 */ |
---|
247 | index = ii*r2; |
---|
248 | |
---|
249 | type_ = type[index]; |
---|
250 | if (type_ != 0) |
---|
251 | { |
---|
252 | pred1D = (*data)[index-r2]; |
---|
253 | (*data)[index] = pred1D + 2 * (type_ - exe_params->intvRadius) * realPrecision; |
---|
254 | } |
---|
255 | else |
---|
256 | { |
---|
257 | // recover the exact data |
---|
258 | memcpy(curBytes, exactDataBytePointer, exactByteSize); |
---|
259 | exactData = bytesToInt32_bigEndian(curBytes); |
---|
260 | exactData = (uint32_t)exactData >> rightShiftBits; |
---|
261 | exactDataBytePointer += exactByteSize; |
---|
262 | (*data)[index] = exactData + minValue; |
---|
263 | } |
---|
264 | |
---|
265 | /* Process row-ii data 1 --> r2-1*/ |
---|
266 | for (jj = 1; jj < r2; jj++) |
---|
267 | { |
---|
268 | index = ii*r2+jj; |
---|
269 | pred2D = (*data)[index-1] + (*data)[index-r2] - (*data)[index-r2-1]; |
---|
270 | |
---|
271 | type_ = type[index]; |
---|
272 | if (type_ != 0) |
---|
273 | { |
---|
274 | (*data)[index] = pred2D + 2 * (type_ - exe_params->intvRadius) * realPrecision; |
---|
275 | } |
---|
276 | else |
---|
277 | { |
---|
278 | // recover the exact data |
---|
279 | memcpy(curBytes, exactDataBytePointer, exactByteSize); |
---|
280 | exactData = bytesToInt32_bigEndian(curBytes); |
---|
281 | exactData = (uint32_t)exactData >> rightShiftBits; |
---|
282 | exactDataBytePointer += exactByteSize; |
---|
283 | (*data)[index] = exactData + minValue; |
---|
284 | } |
---|
285 | } |
---|
286 | } |
---|
287 | |
---|
288 | free(type); |
---|
289 | return; |
---|
290 | } |
---|
291 | |
---|
292 | void decompressDataSeries_int32_3D(int32_t** data, size_t r1, size_t r2, size_t r3, TightDataPointStorageI* tdps) |
---|
293 | { |
---|
294 | updateQuantizationInfo(tdps->intervals); |
---|
295 | size_t dataSeriesLength = r1*r2*r3; |
---|
296 | size_t r23 = r2*r3; |
---|
297 | // printf ("%d %d %d\n", r1, r2, r3); |
---|
298 | double realPrecision = tdps->realPrecision; |
---|
299 | |
---|
300 | *data = (int32_t*)malloc(sizeof(int32_t)*dataSeriesLength); |
---|
301 | int* type = (int*)malloc(dataSeriesLength*sizeof(int)); |
---|
302 | |
---|
303 | HuffmanTree* huffmanTree = createHuffmanTree(tdps->stateNum); |
---|
304 | decode_withTree(huffmanTree, tdps->typeArray, dataSeriesLength, type); |
---|
305 | SZ_ReleaseHuffman(huffmanTree); |
---|
306 | |
---|
307 | int32_t minValue, exactData; |
---|
308 | |
---|
309 | minValue = tdps->minValue; |
---|
310 | |
---|
311 | int exactByteSize = tdps->exactByteSize; |
---|
312 | unsigned char* exactDataBytePointer = tdps->exactDataBytes; |
---|
313 | |
---|
314 | unsigned char curBytes[8] = {0,0,0,0,0,0,0,0}; |
---|
315 | |
---|
316 | int rightShiftBits = computeRightShiftBits(exactByteSize, SZ_INT32); |
---|
317 | |
---|
318 | int32_t pred1D, pred2D, pred3D; |
---|
319 | size_t ii, jj, kk; |
---|
320 | |
---|
321 | /////////////////////////// Process layer-0 /////////////////////////// |
---|
322 | /* Process Row-0 data 0*/ |
---|
323 | |
---|
324 | // recover the exact data |
---|
325 | memcpy(curBytes, exactDataBytePointer, exactByteSize); |
---|
326 | exactData = bytesToInt32_bigEndian(curBytes); |
---|
327 | exactData = (uint32_t)exactData >> rightShiftBits; |
---|
328 | exactDataBytePointer += exactByteSize; |
---|
329 | (*data)[0] = exactData + minValue; |
---|
330 | |
---|
331 | /* Process Row-0, data 1 */ |
---|
332 | pred1D = (*data)[0]; |
---|
333 | |
---|
334 | int type_ = type[1]; |
---|
335 | if (type_ != 0) |
---|
336 | { |
---|
337 | (*data)[1] = pred1D + 2 * (type_ - exe_params->intvRadius) * realPrecision; |
---|
338 | } |
---|
339 | else |
---|
340 | { |
---|
341 | memcpy(curBytes, exactDataBytePointer, exactByteSize); |
---|
342 | exactData = bytesToInt32_bigEndian(curBytes); |
---|
343 | exactData = (uint32_t)exactData >> rightShiftBits; |
---|
344 | exactDataBytePointer += exactByteSize; |
---|
345 | (*data)[1] = exactData + minValue; |
---|
346 | } |
---|
347 | /* Process Row-0, data 2 --> data r3-1 */ |
---|
348 | for (jj = 2; jj < r3; jj++) |
---|
349 | { |
---|
350 | pred1D = 2*(*data)[jj-1] - (*data)[jj-2]; |
---|
351 | |
---|
352 | type_ = type[jj]; |
---|
353 | if (type_ != 0) |
---|
354 | { |
---|
355 | (*data)[jj] = pred1D + 2 * (type_ - exe_params->intvRadius) * realPrecision; |
---|
356 | } |
---|
357 | else |
---|
358 | { |
---|
359 | memcpy(curBytes, exactDataBytePointer, exactByteSize); |
---|
360 | exactData = bytesToInt32_bigEndian(curBytes); |
---|
361 | exactData = (uint32_t)exactData >> rightShiftBits; |
---|
362 | exactDataBytePointer += exactByteSize; |
---|
363 | (*data)[jj] = exactData + minValue; |
---|
364 | } |
---|
365 | } |
---|
366 | |
---|
367 | size_t index; |
---|
368 | /* Process Row-1 --> Row-r2-1 */ |
---|
369 | for (ii = 1; ii < r2; ii++) |
---|
370 | { |
---|
371 | /* Process row-ii data 0 */ |
---|
372 | index = ii*r3; |
---|
373 | pred1D = (*data)[index-r3]; |
---|
374 | |
---|
375 | type_ = type[index]; |
---|
376 | if (type_ != 0) |
---|
377 | { |
---|
378 | (*data)[index] = pred1D + 2 * (type_ - exe_params->intvRadius) * realPrecision; |
---|
379 | } |
---|
380 | else |
---|
381 | { |
---|
382 | memcpy(curBytes, exactDataBytePointer, exactByteSize); |
---|
383 | exactData = bytesToInt32_bigEndian(curBytes); |
---|
384 | exactData = (uint32_t)exactData >> rightShiftBits; |
---|
385 | exactDataBytePointer += exactByteSize; |
---|
386 | (*data)[index] = exactData + minValue; |
---|
387 | } |
---|
388 | |
---|
389 | /* Process row-ii data 1 --> r3-1*/ |
---|
390 | for (jj = 1; jj < r3; jj++) |
---|
391 | { |
---|
392 | index = ii*r3+jj; |
---|
393 | pred2D = (*data)[index-1] + (*data)[index-r3] - (*data)[index-r3-1]; |
---|
394 | |
---|
395 | type_ = type[index]; |
---|
396 | if (type_ != 0) |
---|
397 | { |
---|
398 | (*data)[index] = pred2D + 2 * (type_ - exe_params->intvRadius) * realPrecision; |
---|
399 | } |
---|
400 | else |
---|
401 | { |
---|
402 | memcpy(curBytes, exactDataBytePointer, exactByteSize); |
---|
403 | exactData = bytesToInt32_bigEndian(curBytes); |
---|
404 | exactData = (uint32_t)exactData >> rightShiftBits; |
---|
405 | exactDataBytePointer += exactByteSize; |
---|
406 | (*data)[index] = exactData + minValue; |
---|
407 | } |
---|
408 | } |
---|
409 | } |
---|
410 | |
---|
411 | /////////////////////////// Process layer-1 --> layer-r1-1 /////////////////////////// |
---|
412 | |
---|
413 | for (kk = 1; kk < r1; kk++) |
---|
414 | { |
---|
415 | /* Process Row-0 data 0*/ |
---|
416 | index = kk*r23; |
---|
417 | pred1D = (*data)[index-r23]; |
---|
418 | |
---|
419 | type_ = type[index]; |
---|
420 | if (type_ != 0) |
---|
421 | { |
---|
422 | (*data)[index] = pred1D + 2 * (type_ - exe_params->intvRadius) * realPrecision; |
---|
423 | } |
---|
424 | else |
---|
425 | { |
---|
426 | memcpy(curBytes, exactDataBytePointer, exactByteSize); |
---|
427 | exactData = bytesToInt32_bigEndian(curBytes); |
---|
428 | exactData = (uint32_t)exactData >> rightShiftBits; |
---|
429 | exactDataBytePointer += exactByteSize; |
---|
430 | (*data)[index] = exactData + minValue; |
---|
431 | } |
---|
432 | |
---|
433 | /* Process Row-0 data 1 --> data r3-1 */ |
---|
434 | for (jj = 1; jj < r3; jj++) |
---|
435 | { |
---|
436 | index = kk*r23+jj; |
---|
437 | pred2D = (*data)[index-1] + (*data)[index-r23] - (*data)[index-r23-1]; |
---|
438 | |
---|
439 | type_ = type[index]; |
---|
440 | if (type_ != 0) |
---|
441 | { |
---|
442 | (*data)[index] = pred2D + 2 * (type_ - exe_params->intvRadius) * realPrecision; |
---|
443 | } |
---|
444 | else |
---|
445 | { |
---|
446 | memcpy(curBytes, exactDataBytePointer, exactByteSize); |
---|
447 | exactData = bytesToInt32_bigEndian(curBytes); |
---|
448 | exactData = (uint32_t)exactData >> rightShiftBits; |
---|
449 | exactDataBytePointer += exactByteSize; |
---|
450 | (*data)[index] = exactData + minValue; |
---|
451 | } |
---|
452 | } |
---|
453 | |
---|
454 | /* Process Row-1 --> Row-r2-1 */ |
---|
455 | for (ii = 1; ii < r2; ii++) |
---|
456 | { |
---|
457 | /* Process Row-i data 0 */ |
---|
458 | index = kk*r23 + ii*r3; |
---|
459 | pred2D = (*data)[index-r3] + (*data)[index-r23] - (*data)[index-r23-r3]; |
---|
460 | |
---|
461 | type_ = type[index]; |
---|
462 | if (type_ != 0) |
---|
463 | { |
---|
464 | (*data)[index] = pred2D + 2 * (type_ - exe_params->intvRadius) * realPrecision; |
---|
465 | } |
---|
466 | else |
---|
467 | { |
---|
468 | memcpy(curBytes, exactDataBytePointer, exactByteSize); |
---|
469 | exactData = bytesToInt32_bigEndian(curBytes); |
---|
470 | exactData = (uint32_t)exactData >> rightShiftBits; |
---|
471 | exactDataBytePointer += exactByteSize; |
---|
472 | (*data)[index] = exactData + minValue; |
---|
473 | } |
---|
474 | |
---|
475 | /* Process Row-i data 1 --> data r3-1 */ |
---|
476 | for (jj = 1; jj < r3; jj++) |
---|
477 | { |
---|
478 | index = kk*r23 + ii*r3 + jj; |
---|
479 | pred3D = (*data)[index-1] + (*data)[index-r3] + (*data)[index-r23] |
---|
480 | - (*data)[index-r3-1] - (*data)[index-r23-r3] - (*data)[index-r23-1] + (*data)[index-r23-r3-1]; |
---|
481 | |
---|
482 | type_ = type[index]; |
---|
483 | if (type_ != 0) |
---|
484 | { |
---|
485 | (*data)[index] = pred3D + 2 * (type_ - exe_params->intvRadius) * realPrecision; |
---|
486 | } |
---|
487 | else |
---|
488 | { |
---|
489 | memcpy(curBytes, exactDataBytePointer, exactByteSize); |
---|
490 | exactData = bytesToInt32_bigEndian(curBytes); |
---|
491 | exactData = (uint32_t)exactData >> rightShiftBits; |
---|
492 | exactDataBytePointer += exactByteSize; |
---|
493 | (*data)[index] = exactData + minValue; |
---|
494 | } |
---|
495 | } |
---|
496 | } |
---|
497 | } |
---|
498 | |
---|
499 | free(type); |
---|
500 | return; |
---|
501 | } |
---|
502 | |
---|
503 | |
---|
504 | void decompressDataSeries_int32_4D(int32_t** data, size_t r1, size_t r2, size_t r3, size_t r4, TightDataPointStorageI* tdps) |
---|
505 | { |
---|
506 | updateQuantizationInfo(tdps->intervals); |
---|
507 | size_t dataSeriesLength = r1*r2*r3*r4; |
---|
508 | size_t r234 = r2*r3*r4; |
---|
509 | size_t r34 = r3*r4; |
---|
510 | |
---|
511 | double realPrecision = tdps->realPrecision; |
---|
512 | |
---|
513 | *data = (int32_t*)malloc(sizeof(int32_t)*dataSeriesLength); |
---|
514 | int* type = (int*)malloc(dataSeriesLength*sizeof(int)); |
---|
515 | |
---|
516 | HuffmanTree* huffmanTree = createHuffmanTree(tdps->stateNum); |
---|
517 | decode_withTree(huffmanTree, tdps->typeArray, dataSeriesLength, type); |
---|
518 | SZ_ReleaseHuffman(huffmanTree); |
---|
519 | |
---|
520 | int32_t minValue, exactData; |
---|
521 | |
---|
522 | minValue = tdps->minValue; |
---|
523 | |
---|
524 | int exactByteSize = tdps->exactByteSize; |
---|
525 | unsigned char* exactDataBytePointer = tdps->exactDataBytes; |
---|
526 | |
---|
527 | unsigned char curBytes[8] = {0,0,0,0,0,0,0,0}; |
---|
528 | |
---|
529 | int rightShiftBits = computeRightShiftBits(exactByteSize, SZ_INT32); |
---|
530 | |
---|
531 | int type_; |
---|
532 | |
---|
533 | int32_t pred1D, pred2D, pred3D; |
---|
534 | size_t ii, jj, kk, ll; |
---|
535 | size_t index; |
---|
536 | |
---|
537 | for (ll = 0; ll < r1; ll++) |
---|
538 | { |
---|
539 | /////////////////////////// Process layer-0 /////////////////////////// |
---|
540 | /* Process Row-0 data 0*/ |
---|
541 | index = ll*r234; |
---|
542 | |
---|
543 | // recover the exact data |
---|
544 | memcpy(curBytes, exactDataBytePointer, exactByteSize); |
---|
545 | exactData = bytesToInt32_bigEndian(curBytes); |
---|
546 | exactData = (uint32_t)exactData >> rightShiftBits; |
---|
547 | exactDataBytePointer += exactByteSize; |
---|
548 | (*data)[index] = exactData + minValue; |
---|
549 | |
---|
550 | /* Process Row-0, data 1 */ |
---|
551 | index = ll*r234+1; |
---|
552 | |
---|
553 | pred1D = (*data)[index-1]; |
---|
554 | |
---|
555 | type_ = type[index]; |
---|
556 | if (type_ != 0) |
---|
557 | { |
---|
558 | (*data)[index] = pred1D + 2 * (type_ - exe_params->intvRadius) * realPrecision; |
---|
559 | } |
---|
560 | else |
---|
561 | { |
---|
562 | memcpy(curBytes, exactDataBytePointer, exactByteSize); |
---|
563 | exactData = bytesToInt32_bigEndian(curBytes); |
---|
564 | exactData = (uint32_t)exactData >> rightShiftBits; |
---|
565 | exactDataBytePointer += exactByteSize; |
---|
566 | (*data)[index] = exactData + minValue; |
---|
567 | } |
---|
568 | |
---|
569 | /* Process Row-0, data 2 --> data r4-1 */ |
---|
570 | for (jj = 2; jj < r4; jj++) |
---|
571 | { |
---|
572 | index = ll*r234+jj; |
---|
573 | |
---|
574 | pred1D = 2*(*data)[index-1] - (*data)[index-2]; |
---|
575 | |
---|
576 | type_ = type[index]; |
---|
577 | if (type_ != 0) |
---|
578 | { |
---|
579 | (*data)[index] = pred1D + 2 * (type_ - exe_params->intvRadius) * realPrecision; |
---|
580 | } |
---|
581 | else |
---|
582 | { |
---|
583 | memcpy(curBytes, exactDataBytePointer, exactByteSize); |
---|
584 | exactData = bytesToInt32_bigEndian(curBytes); |
---|
585 | exactData = (uint32_t)exactData >> rightShiftBits; |
---|
586 | exactDataBytePointer += exactByteSize; |
---|
587 | (*data)[index] = exactData + minValue; |
---|
588 | } |
---|
589 | } |
---|
590 | |
---|
591 | /* Process Row-1 --> Row-r3-1 */ |
---|
592 | for (ii = 1; ii < r3; ii++) |
---|
593 | { |
---|
594 | /* Process row-ii data 0 */ |
---|
595 | index = ll*r234+ii*r4; |
---|
596 | |
---|
597 | pred1D = (*data)[index-r4]; |
---|
598 | |
---|
599 | type_ = type[index]; |
---|
600 | if (type_ != 0) |
---|
601 | { |
---|
602 | (*data)[index] = pred1D + 2 * (type_ - exe_params->intvRadius) * realPrecision; |
---|
603 | } |
---|
604 | else |
---|
605 | { |
---|
606 | memcpy(curBytes, exactDataBytePointer, exactByteSize); |
---|
607 | exactData = bytesToInt32_bigEndian(curBytes); |
---|
608 | exactData = (uint32_t)exactData >> rightShiftBits; |
---|
609 | exactDataBytePointer += exactByteSize; |
---|
610 | (*data)[index] = exactData + minValue; |
---|
611 | } |
---|
612 | |
---|
613 | /* Process row-ii data 1 --> r4-1*/ |
---|
614 | for (jj = 1; jj < r4; jj++) |
---|
615 | { |
---|
616 | index = ll*r234+ii*r4+jj; |
---|
617 | |
---|
618 | pred2D = (*data)[index-1] + (*data)[index-r4] - (*data)[index-r4-1]; |
---|
619 | |
---|
620 | type_ = type[index]; |
---|
621 | if (type_ != 0) |
---|
622 | { |
---|
623 | (*data)[index] = pred2D + 2 * (type_ - exe_params->intvRadius) * realPrecision; |
---|
624 | } |
---|
625 | else |
---|
626 | { |
---|
627 | memcpy(curBytes, exactDataBytePointer, exactByteSize); |
---|
628 | exactData = bytesToInt32_bigEndian(curBytes); |
---|
629 | exactData = (uint32_t)exactData >> rightShiftBits; |
---|
630 | exactDataBytePointer += exactByteSize; |
---|
631 | (*data)[index] = exactData + minValue; |
---|
632 | } |
---|
633 | } |
---|
634 | } |
---|
635 | |
---|
636 | /////////////////////////// Process layer-1 --> layer-r2-1 /////////////////////////// |
---|
637 | |
---|
638 | for (kk = 1; kk < r2; kk++) |
---|
639 | { |
---|
640 | /* Process Row-0 data 0*/ |
---|
641 | index = ll*r234+kk*r34; |
---|
642 | |
---|
643 | pred1D = (*data)[index-r34]; |
---|
644 | |
---|
645 | type_ = type[index]; |
---|
646 | if (type_ != 0) |
---|
647 | { |
---|
648 | (*data)[index] = pred1D + 2 * (type_ - exe_params->intvRadius) * realPrecision; |
---|
649 | } |
---|
650 | else |
---|
651 | { |
---|
652 | memcpy(curBytes, exactDataBytePointer, exactByteSize); |
---|
653 | exactData = bytesToInt32_bigEndian(curBytes); |
---|
654 | exactData = (uint32_t)exactData >> rightShiftBits; |
---|
655 | exactDataBytePointer += exactByteSize; |
---|
656 | (*data)[index] = exactData + minValue; |
---|
657 | } |
---|
658 | |
---|
659 | /* Process Row-0 data 1 --> data r4-1 */ |
---|
660 | for (jj = 1; jj < r4; jj++) |
---|
661 | { |
---|
662 | index = ll*r234+kk*r34+jj; |
---|
663 | |
---|
664 | pred2D = (*data)[index-1] + (*data)[index-r34] - (*data)[index-r34-1]; |
---|
665 | |
---|
666 | type_ = type[index]; |
---|
667 | if (type_ != 0) |
---|
668 | { |
---|
669 | (*data)[index] = pred2D + 2 * (type_ - exe_params->intvRadius) * realPrecision; |
---|
670 | } |
---|
671 | else |
---|
672 | { |
---|
673 | memcpy(curBytes, exactDataBytePointer, exactByteSize); |
---|
674 | exactData = bytesToInt32_bigEndian(curBytes); |
---|
675 | exactData = (uint32_t)exactData >> rightShiftBits; |
---|
676 | exactDataBytePointer += exactByteSize; |
---|
677 | (*data)[index] = exactData + minValue; |
---|
678 | } |
---|
679 | } |
---|
680 | |
---|
681 | /* Process Row-1 --> Row-r3-1 */ |
---|
682 | for (ii = 1; ii < r3; ii++) |
---|
683 | { |
---|
684 | /* Process Row-i data 0 */ |
---|
685 | index = ll*r234+kk*r34+ii*r4; |
---|
686 | |
---|
687 | pred2D = (*data)[index-r4] + (*data)[index-r34] - (*data)[index-r34-r4]; |
---|
688 | |
---|
689 | type_ = type[index]; |
---|
690 | if (type_ != 0) |
---|
691 | { |
---|
692 | (*data)[index] = pred2D + 2 * (type_ - exe_params->intvRadius) * realPrecision; |
---|
693 | } |
---|
694 | else |
---|
695 | { |
---|
696 | memcpy(curBytes, exactDataBytePointer, exactByteSize); |
---|
697 | exactData = bytesToInt32_bigEndian(curBytes); |
---|
698 | exactData = (uint32_t)exactData >> rightShiftBits; |
---|
699 | exactDataBytePointer += exactByteSize; |
---|
700 | (*data)[index] = exactData + minValue; |
---|
701 | } |
---|
702 | |
---|
703 | /* Process Row-i data 1 --> data r4-1 */ |
---|
704 | for (jj = 1; jj < r4; jj++) |
---|
705 | { |
---|
706 | index = ll*r234+kk*r34+ii*r4+jj; |
---|
707 | |
---|
708 | pred3D = (*data)[index-1] + (*data)[index-r4] + (*data)[index-r34] |
---|
709 | - (*data)[index-r4-1] - (*data)[index-r34-r4] - (*data)[index-r34-1] + (*data)[index-r34-r4-1]; |
---|
710 | |
---|
711 | |
---|
712 | type_ = type[index]; |
---|
713 | if (type_ != 0) |
---|
714 | { |
---|
715 | (*data)[index] = pred3D + 2 * (type_ - exe_params->intvRadius) * realPrecision; |
---|
716 | } |
---|
717 | else |
---|
718 | { |
---|
719 | memcpy(curBytes, exactDataBytePointer, exactByteSize); |
---|
720 | exactData = bytesToInt32_bigEndian(curBytes); |
---|
721 | exactData = (uint32_t)exactData >> rightShiftBits; |
---|
722 | exactDataBytePointer += exactByteSize; |
---|
723 | (*data)[index] = exactData + minValue; |
---|
724 | } |
---|
725 | } |
---|
726 | } |
---|
727 | } |
---|
728 | } |
---|
729 | |
---|
730 | free(type); |
---|
731 | return; |
---|
732 | } |
---|
733 | |
---|
734 | void getSnapshotData_int32_1D(int32_t** data, size_t dataSeriesLength, TightDataPointStorageI* tdps, int errBoundMode) |
---|
735 | { |
---|
736 | size_t i; |
---|
737 | |
---|
738 | if (tdps->allSameData) { |
---|
739 | int32_t value = bytesToInt32_bigEndian(tdps->exactDataBytes); |
---|
740 | *data = (int32_t*)malloc(sizeof(int32_t)*dataSeriesLength); |
---|
741 | for (i = 0; i < dataSeriesLength; i++) |
---|
742 | (*data)[i] = value; |
---|
743 | } else { |
---|
744 | decompressDataSeries_int32_1D(data, dataSeriesLength, tdps); |
---|
745 | } |
---|
746 | } |
---|
747 | |
---|
748 | void getSnapshotData_int32_2D(int32_t** data, size_t r1, size_t r2, TightDataPointStorageI* tdps, int errBoundMode) |
---|
749 | { |
---|
750 | size_t i; |
---|
751 | size_t dataSeriesLength = r1*r2; |
---|
752 | if (tdps->allSameData) { |
---|
753 | int32_t value = bytesToInt32_bigEndian(tdps->exactDataBytes); |
---|
754 | *data = (int32_t*)malloc(sizeof(int32_t)*dataSeriesLength); |
---|
755 | for (i = 0; i < dataSeriesLength; i++) |
---|
756 | (*data)[i] = value; |
---|
757 | } else { |
---|
758 | decompressDataSeries_int32_2D(data, r1, r2, tdps); |
---|
759 | } |
---|
760 | } |
---|
761 | |
---|
762 | void getSnapshotData_int32_3D(int32_t** data, size_t r1, size_t r2, size_t r3, TightDataPointStorageI* tdps, int errBoundMode) |
---|
763 | { |
---|
764 | size_t i; |
---|
765 | size_t dataSeriesLength = r1*r2*r3; |
---|
766 | if (tdps->allSameData) { |
---|
767 | int32_t value = bytesToInt32_bigEndian(tdps->exactDataBytes); |
---|
768 | *data = (int32_t*)malloc(sizeof(int32_t)*dataSeriesLength); |
---|
769 | for (i = 0; i < dataSeriesLength; i++) |
---|
770 | (*data)[i] = value; |
---|
771 | } else { |
---|
772 | decompressDataSeries_int32_3D(data, r1, r2, r3, tdps); |
---|
773 | } |
---|
774 | } |
---|
775 | |
---|
776 | void getSnapshotData_int32_4D(int32_t** data, size_t r1, size_t r2, size_t r3, size_t r4, TightDataPointStorageI* tdps, int errBoundMode) |
---|
777 | { |
---|
778 | size_t i; |
---|
779 | size_t dataSeriesLength = r1*r2*r3*r4; |
---|
780 | if (tdps->allSameData) { |
---|
781 | int32_t value = bytesToInt32_bigEndian(tdps->exactDataBytes); |
---|
782 | *data = (int32_t*)malloc(sizeof(int32_t)*dataSeriesLength); |
---|
783 | for (i = 0; i < dataSeriesLength; i++) |
---|
784 | (*data)[i] = value; |
---|
785 | } else { |
---|
786 | decompressDataSeries_int32_4D(data, r1, r2, r3, r4, tdps); |
---|
787 | } |
---|
788 | } |
---|