1 | /** |
---|
2 | * @file szd_int16.c |
---|
3 | * @author Sheng Di |
---|
4 | * @date Aug, 2017 |
---|
5 | * @brief |
---|
6 | * (C) 2017 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_int16.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_int16(int16_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(int16_t)+exe_params->SZ_SIZE_TYPE; |
---|
33 | unsigned char* szTmpBytes; |
---|
34 | |
---|
35 | if(cmpSize!=4+2+4+MetaDataByteLength && cmpSize!=4+2+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(int16_t); |
---|
71 | if(tdps->isLossless) |
---|
72 | { |
---|
73 | *newData = (int16_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] = bytesToInt16_bigEndian(p); |
---|
83 | } |
---|
84 | } |
---|
85 | else if (dim == 1) |
---|
86 | getSnapshotData_int16_1D(newData,r1,tdps, errBoundMode); |
---|
87 | else |
---|
88 | if (dim == 2) |
---|
89 | getSnapshotData_int16_2D(newData,r2,r1,tdps, errBoundMode); |
---|
90 | else |
---|
91 | if (dim == 3) |
---|
92 | getSnapshotData_int16_3D(newData,r3,r2,r1,tdps, errBoundMode); |
---|
93 | else |
---|
94 | if (dim == 4) |
---|
95 | getSnapshotData_int16_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(int16_t)+exe_params->SZ_SIZE_TYPE+MetaDataByteLength) |
---|
103 | free(szTmpBytes); |
---|
104 | return status; |
---|
105 | } |
---|
106 | |
---|
107 | |
---|
108 | void decompressDataSeries_int16_1D(int16_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 = (int16_t*)malloc(sizeof(int16_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 | long predValue, tmp; |
---|
126 | int16_t minValue, exactData; |
---|
127 | |
---|
128 | minValue = tdps->minValue; |
---|
129 | |
---|
130 | int exactByteSize = tdps->exactByteSize; |
---|
131 | unsigned char* exactDataBytePointer = tdps->exactDataBytes; |
---|
132 | |
---|
133 | unsigned char curBytes[8] = {0,0,0,0,0,0,0,0}; |
---|
134 | |
---|
135 | int rightShiftBits = computeRightShiftBits(exactByteSize, SZ_INT16); |
---|
136 | if(rightShiftBits<0) |
---|
137 | { |
---|
138 | printf("Error: rightShift < 0!\n"); |
---|
139 | exit(0); |
---|
140 | } |
---|
141 | int type_; |
---|
142 | for (i = 0; i < dataSeriesLength; i++) { |
---|
143 | type_ = type[i]; |
---|
144 | switch (type_) { |
---|
145 | case 0: |
---|
146 | // recover the exact data |
---|
147 | memcpy(curBytes, exactDataBytePointer, exactByteSize); |
---|
148 | exactData = bytesToInt16_bigEndian(curBytes); |
---|
149 | exactData = (uint16_t)exactData >> rightShiftBits; |
---|
150 | exactDataBytePointer += exactByteSize; |
---|
151 | (*data)[i] = exactData + minValue; |
---|
152 | break; |
---|
153 | default: |
---|
154 | //predValue = 2 * (*data)[i-1] - (*data)[i-2]; |
---|
155 | predValue = (*data)[i-1]; |
---|
156 | tmp = predValue + (type_-exe_params->intvRadius)*interval; |
---|
157 | if(tmp >= SZ_INT16_MIN&&tmp<SZ_INT16_MAX) |
---|
158 | (*data)[i] = tmp; |
---|
159 | else if(tmp < SZ_INT16_MIN) |
---|
160 | (*data)[i] = SZ_INT16_MIN; |
---|
161 | else |
---|
162 | (*data)[i] = SZ_INT16_MAX; |
---|
163 | break; |
---|
164 | } |
---|
165 | //printf("%.30G\n",(*data)[i]); |
---|
166 | } |
---|
167 | free(type); |
---|
168 | return; |
---|
169 | } |
---|
170 | |
---|
171 | void decompressDataSeries_int16_2D(int16_t** data, size_t r1, size_t r2, TightDataPointStorageI* tdps) |
---|
172 | { |
---|
173 | updateQuantizationInfo(tdps->intervals); |
---|
174 | //printf("tdps->intervals=%d, exe_params->intvRadius=%d\n", tdps->intervals, exe_params->intvRadius); |
---|
175 | |
---|
176 | size_t dataSeriesLength = r1*r2; |
---|
177 | // printf ("%d %d\n", r1, r2); |
---|
178 | |
---|
179 | double realPrecision = tdps->realPrecision; |
---|
180 | |
---|
181 | *data = (int16_t*)malloc(sizeof(int16_t)*dataSeriesLength); |
---|
182 | |
---|
183 | int* type = (int*)malloc(dataSeriesLength*sizeof(int)); |
---|
184 | |
---|
185 | HuffmanTree* huffmanTree = createHuffmanTree(tdps->stateNum); |
---|
186 | decode_withTree(huffmanTree, tdps->typeArray, dataSeriesLength, type); |
---|
187 | SZ_ReleaseHuffman(huffmanTree); |
---|
188 | |
---|
189 | int16_t minValue, exactData; |
---|
190 | |
---|
191 | minValue = tdps->minValue; |
---|
192 | |
---|
193 | int exactByteSize = tdps->exactByteSize; |
---|
194 | unsigned char* exactDataBytePointer = tdps->exactDataBytes; |
---|
195 | |
---|
196 | unsigned char curBytes[8] = {0,0,0,0,0,0,0,0}; |
---|
197 | |
---|
198 | int rightShiftBits = computeRightShiftBits(exactByteSize, SZ_INT16); |
---|
199 | |
---|
200 | long pred1D, pred2D, tmp; |
---|
201 | size_t ii, jj; |
---|
202 | |
---|
203 | /* Process Row-0, data 0 */ |
---|
204 | |
---|
205 | // recover the exact data |
---|
206 | memcpy(curBytes, exactDataBytePointer, exactByteSize); |
---|
207 | exactData = bytesToInt16_bigEndian(curBytes); |
---|
208 | exactData = (uint16_t)exactData >> rightShiftBits; |
---|
209 | exactDataBytePointer += exactByteSize; |
---|
210 | (*data)[0] = exactData + minValue; |
---|
211 | |
---|
212 | /* Process Row-0, data 1 */ |
---|
213 | int type_ = type[1]; |
---|
214 | if (type_ != 0) |
---|
215 | { |
---|
216 | pred1D = (*data)[0]; |
---|
217 | tmp = pred1D + 2 * (type_ - exe_params->intvRadius) * realPrecision; |
---|
218 | if(tmp >= SZ_INT16_MIN&&tmp<SZ_INT16_MAX) |
---|
219 | (*data)[1] = tmp; |
---|
220 | else if(tmp < SZ_INT16_MIN) |
---|
221 | (*data)[1] = SZ_INT16_MIN; |
---|
222 | else |
---|
223 | (*data)[1] = SZ_INT16_MAX; |
---|
224 | |
---|
225 | } |
---|
226 | else |
---|
227 | { |
---|
228 | // recover the exact data |
---|
229 | memcpy(curBytes, exactDataBytePointer, exactByteSize); |
---|
230 | exactData = bytesToInt16_bigEndian(curBytes); |
---|
231 | exactData = (uint16_t)exactData >> rightShiftBits; |
---|
232 | exactDataBytePointer += exactByteSize; |
---|
233 | (*data)[1] = exactData + minValue; |
---|
234 | } |
---|
235 | |
---|
236 | /* Process Row-0, data 2 --> data r2-1 */ |
---|
237 | for (jj = 2; jj < r2; jj++) |
---|
238 | { |
---|
239 | type_ = type[jj]; |
---|
240 | if (type_ != 0) |
---|
241 | { |
---|
242 | pred1D = 2*(*data)[jj-1] - (*data)[jj-2]; |
---|
243 | tmp = pred1D + 2 * (type_ - exe_params->intvRadius) * realPrecision; |
---|
244 | if(tmp >= SZ_INT16_MIN&&tmp<SZ_INT16_MAX) |
---|
245 | (*data)[jj] = tmp; |
---|
246 | else if(tmp < SZ_INT16_MIN) |
---|
247 | (*data)[jj] = SZ_INT16_MIN; |
---|
248 | else |
---|
249 | (*data)[jj] = SZ_INT16_MAX; |
---|
250 | } |
---|
251 | else |
---|
252 | { |
---|
253 | // recover the exact data |
---|
254 | memcpy(curBytes, exactDataBytePointer, exactByteSize); |
---|
255 | exactData = bytesToInt16_bigEndian(curBytes); |
---|
256 | exactData = (uint16_t)exactData >> rightShiftBits; |
---|
257 | exactDataBytePointer += exactByteSize; |
---|
258 | (*data)[jj] = exactData + minValue; |
---|
259 | } |
---|
260 | } |
---|
261 | |
---|
262 | size_t index; |
---|
263 | /* Process Row-1 --> Row-r1-1 */ |
---|
264 | for (ii = 1; ii < r1; ii++) |
---|
265 | { |
---|
266 | /* Process row-ii data 0 */ |
---|
267 | index = ii*r2; |
---|
268 | |
---|
269 | type_ = type[index]; |
---|
270 | if (type_ != 0) |
---|
271 | { |
---|
272 | pred1D = (*data)[index-r2]; |
---|
273 | tmp = pred1D + 2 * (type_ - exe_params->intvRadius) * realPrecision; |
---|
274 | if(tmp >= SZ_INT16_MIN&&tmp<SZ_INT16_MAX) |
---|
275 | (*data)[index] = tmp; |
---|
276 | else if(tmp < SZ_INT16_MIN) |
---|
277 | (*data)[index] = SZ_INT16_MIN; |
---|
278 | else |
---|
279 | (*data)[index] = SZ_INT16_MAX; |
---|
280 | } |
---|
281 | else |
---|
282 | { |
---|
283 | // recover the exact data |
---|
284 | memcpy(curBytes, exactDataBytePointer, exactByteSize); |
---|
285 | exactData = bytesToInt16_bigEndian(curBytes); |
---|
286 | exactData = (uint16_t)exactData >> rightShiftBits; |
---|
287 | exactDataBytePointer += exactByteSize; |
---|
288 | (*data)[index] = exactData + minValue; |
---|
289 | } |
---|
290 | |
---|
291 | /* Process row-ii data 1 --> r2-1*/ |
---|
292 | for (jj = 1; jj < r2; jj++) |
---|
293 | { |
---|
294 | index = ii*r2+jj; |
---|
295 | pred2D = (*data)[index-1] + (*data)[index-r2] - (*data)[index-r2-1]; |
---|
296 | |
---|
297 | type_ = type[index]; |
---|
298 | if (type_ != 0) |
---|
299 | { |
---|
300 | tmp = pred2D + 2 * (type_ - exe_params->intvRadius) * realPrecision; |
---|
301 | if(tmp >= SZ_INT16_MIN&&tmp<SZ_INT16_MAX) |
---|
302 | (*data)[index] = tmp; |
---|
303 | else if(tmp < SZ_INT16_MIN) |
---|
304 | (*data)[index] = SZ_INT16_MIN; |
---|
305 | else |
---|
306 | (*data)[index] = SZ_INT16_MAX; |
---|
307 | } |
---|
308 | else |
---|
309 | { |
---|
310 | // recover the exact data |
---|
311 | memcpy(curBytes, exactDataBytePointer, exactByteSize); |
---|
312 | exactData = bytesToInt16_bigEndian(curBytes); |
---|
313 | exactData = (uint16_t)exactData >> rightShiftBits; |
---|
314 | exactDataBytePointer += exactByteSize; |
---|
315 | (*data)[index] = exactData + minValue; |
---|
316 | } |
---|
317 | } |
---|
318 | } |
---|
319 | |
---|
320 | free(type); |
---|
321 | return; |
---|
322 | } |
---|
323 | |
---|
324 | void decompressDataSeries_int16_3D(int16_t** data, size_t r1, size_t r2, size_t r3, TightDataPointStorageI* tdps) |
---|
325 | { |
---|
326 | updateQuantizationInfo(tdps->intervals); |
---|
327 | size_t dataSeriesLength = r1*r2*r3; |
---|
328 | size_t r23 = r2*r3; |
---|
329 | // printf ("%d %d %d\n", r1, r2, r3); |
---|
330 | double realPrecision = tdps->realPrecision; |
---|
331 | |
---|
332 | *data = (int16_t*)malloc(sizeof(int16_t)*dataSeriesLength); |
---|
333 | int* type = (int*)malloc(dataSeriesLength*sizeof(int)); |
---|
334 | |
---|
335 | HuffmanTree* huffmanTree = createHuffmanTree(tdps->stateNum); |
---|
336 | decode_withTree(huffmanTree, tdps->typeArray, dataSeriesLength, type); |
---|
337 | SZ_ReleaseHuffman(huffmanTree); |
---|
338 | |
---|
339 | int16_t minValue, exactData; |
---|
340 | |
---|
341 | minValue = tdps->minValue; |
---|
342 | |
---|
343 | int exactByteSize = tdps->exactByteSize; |
---|
344 | unsigned char* exactDataBytePointer = tdps->exactDataBytes; |
---|
345 | |
---|
346 | unsigned char curBytes[8] = {0,0,0,0,0,0,0,0}; |
---|
347 | |
---|
348 | int rightShiftBits = computeRightShiftBits(exactByteSize, SZ_INT16); |
---|
349 | |
---|
350 | long pred1D, pred2D, pred3D, tmp; |
---|
351 | size_t ii, jj, kk; |
---|
352 | |
---|
353 | /////////////////////////// Process layer-0 /////////////////////////// |
---|
354 | /* Process Row-0 data 0*/ |
---|
355 | |
---|
356 | // recover the exact data |
---|
357 | memcpy(curBytes, exactDataBytePointer, exactByteSize); |
---|
358 | exactData = bytesToInt16_bigEndian(curBytes); |
---|
359 | exactData = (uint16_t)exactData >> rightShiftBits; |
---|
360 | exactDataBytePointer += exactByteSize; |
---|
361 | (*data)[0] = exactData + minValue; |
---|
362 | |
---|
363 | /* Process Row-0, data 1 */ |
---|
364 | pred1D = (*data)[0]; |
---|
365 | |
---|
366 | int type_ = type[1]; |
---|
367 | if (type_ != 0) |
---|
368 | { |
---|
369 | tmp = pred1D + 2 * (type_ - exe_params->intvRadius) * realPrecision; |
---|
370 | if(tmp >= SZ_INT16_MIN&&tmp<SZ_INT16_MAX) |
---|
371 | (*data)[1] = tmp; |
---|
372 | else if(tmp < SZ_INT16_MIN) |
---|
373 | (*data)[1] = SZ_INT16_MIN; |
---|
374 | else |
---|
375 | (*data)[1] = SZ_INT16_MAX; |
---|
376 | } |
---|
377 | else |
---|
378 | { |
---|
379 | memcpy(curBytes, exactDataBytePointer, exactByteSize); |
---|
380 | exactData = bytesToInt16_bigEndian(curBytes); |
---|
381 | exactData = (uint16_t)exactData >> rightShiftBits; |
---|
382 | exactDataBytePointer += exactByteSize; |
---|
383 | (*data)[1] = exactData + minValue; |
---|
384 | } |
---|
385 | /* Process Row-0, data 2 --> data r3-1 */ |
---|
386 | for (jj = 2; jj < r3; jj++) |
---|
387 | { |
---|
388 | pred1D = 2*(*data)[jj-1] - (*data)[jj-2]; |
---|
389 | |
---|
390 | type_ = type[jj]; |
---|
391 | if (type_ != 0) |
---|
392 | { |
---|
393 | tmp = pred1D + 2 * (type_ - exe_params->intvRadius) * realPrecision; |
---|
394 | if(tmp >= SZ_INT16_MIN&&tmp<SZ_INT16_MAX) |
---|
395 | (*data)[jj] = tmp; |
---|
396 | else if(tmp < SZ_INT16_MIN) |
---|
397 | (*data)[jj] = SZ_INT16_MIN; |
---|
398 | else |
---|
399 | (*data)[jj] = SZ_INT16_MAX; } |
---|
400 | else |
---|
401 | { |
---|
402 | memcpy(curBytes, exactDataBytePointer, exactByteSize); |
---|
403 | exactData = bytesToInt16_bigEndian(curBytes); |
---|
404 | exactData = (uint16_t)exactData >> rightShiftBits; |
---|
405 | exactDataBytePointer += exactByteSize; |
---|
406 | (*data)[jj] = exactData + minValue; |
---|
407 | } |
---|
408 | } |
---|
409 | |
---|
410 | size_t index; |
---|
411 | /* Process Row-1 --> Row-r2-1 */ |
---|
412 | for (ii = 1; ii < r2; ii++) |
---|
413 | { |
---|
414 | /* Process row-ii data 0 */ |
---|
415 | index = ii*r3; |
---|
416 | pred1D = (*data)[index-r3]; |
---|
417 | |
---|
418 | type_ = type[index]; |
---|
419 | if (type_ != 0) |
---|
420 | { |
---|
421 | tmp = pred1D + 2 * (type_ - exe_params->intvRadius) * realPrecision; |
---|
422 | if(tmp >= SZ_INT16_MIN&&tmp<SZ_INT16_MAX) |
---|
423 | (*data)[index] = tmp; |
---|
424 | else if(tmp < SZ_INT16_MIN) |
---|
425 | (*data)[index] = SZ_INT16_MIN; |
---|
426 | else |
---|
427 | (*data)[index] = SZ_INT16_MAX; |
---|
428 | } |
---|
429 | else |
---|
430 | { |
---|
431 | memcpy(curBytes, exactDataBytePointer, exactByteSize); |
---|
432 | exactData = bytesToInt16_bigEndian(curBytes); |
---|
433 | exactData = (uint16_t)exactData >> rightShiftBits; |
---|
434 | exactDataBytePointer += exactByteSize; |
---|
435 | (*data)[index] = exactData + minValue; |
---|
436 | } |
---|
437 | |
---|
438 | /* Process row-ii data 1 --> r3-1*/ |
---|
439 | for (jj = 1; jj < r3; jj++) |
---|
440 | { |
---|
441 | index = ii*r3+jj; |
---|
442 | pred2D = (*data)[index-1] + (*data)[index-r3] - (*data)[index-r3-1]; |
---|
443 | |
---|
444 | type_ = type[index]; |
---|
445 | if (type_ != 0) |
---|
446 | { |
---|
447 | tmp = pred2D + 2 * (type_ - exe_params->intvRadius) * realPrecision; |
---|
448 | if(tmp >= SZ_INT16_MIN&&tmp<SZ_INT16_MAX) |
---|
449 | (*data)[index] = tmp; |
---|
450 | else if(tmp < SZ_INT16_MIN) |
---|
451 | (*data)[index] = SZ_INT16_MIN; |
---|
452 | else |
---|
453 | (*data)[index] = SZ_INT16_MAX; |
---|
454 | } |
---|
455 | else |
---|
456 | { |
---|
457 | memcpy(curBytes, exactDataBytePointer, exactByteSize); |
---|
458 | exactData = bytesToInt16_bigEndian(curBytes); |
---|
459 | exactData = (uint16_t)exactData >> rightShiftBits; |
---|
460 | exactDataBytePointer += exactByteSize; |
---|
461 | (*data)[index] = exactData + minValue; |
---|
462 | } |
---|
463 | } |
---|
464 | } |
---|
465 | |
---|
466 | /////////////////////////// Process layer-1 --> layer-r1-1 /////////////////////////// |
---|
467 | |
---|
468 | for (kk = 1; kk < r1; kk++) |
---|
469 | { |
---|
470 | /* Process Row-0 data 0*/ |
---|
471 | index = kk*r23; |
---|
472 | pred1D = (*data)[index-r23]; |
---|
473 | |
---|
474 | type_ = type[index]; |
---|
475 | if (type_ != 0) |
---|
476 | { |
---|
477 | tmp = pred1D + 2 * (type_ - exe_params->intvRadius) * realPrecision; |
---|
478 | if(tmp >= SZ_INT16_MIN&&tmp<SZ_INT16_MAX) |
---|
479 | (*data)[index] = tmp; |
---|
480 | else if(tmp < SZ_INT16_MIN) |
---|
481 | (*data)[index] = SZ_INT16_MIN; |
---|
482 | else |
---|
483 | (*data)[index] = SZ_INT16_MAX; |
---|
484 | } |
---|
485 | else |
---|
486 | { |
---|
487 | memcpy(curBytes, exactDataBytePointer, exactByteSize); |
---|
488 | exactData = bytesToInt16_bigEndian(curBytes); |
---|
489 | exactData = (uint16_t)exactData >> rightShiftBits; |
---|
490 | exactDataBytePointer += exactByteSize; |
---|
491 | (*data)[index] = exactData + minValue; |
---|
492 | } |
---|
493 | |
---|
494 | /* Process Row-0 data 1 --> data r3-1 */ |
---|
495 | for (jj = 1; jj < r3; jj++) |
---|
496 | { |
---|
497 | index = kk*r23+jj; |
---|
498 | pred2D = (*data)[index-1] + (*data)[index-r23] - (*data)[index-r23-1]; |
---|
499 | |
---|
500 | type_ = type[index]; |
---|
501 | if (type_ != 0) |
---|
502 | { |
---|
503 | tmp = pred2D + 2 * (type_ - exe_params->intvRadius) * realPrecision; |
---|
504 | if(tmp >= SZ_INT16_MIN&&tmp<SZ_INT16_MAX) |
---|
505 | (*data)[index] = tmp; |
---|
506 | else if(tmp < SZ_INT16_MIN) |
---|
507 | (*data)[index] = SZ_INT16_MIN; |
---|
508 | else |
---|
509 | (*data)[index] = SZ_INT16_MAX; |
---|
510 | } |
---|
511 | else |
---|
512 | { |
---|
513 | memcpy(curBytes, exactDataBytePointer, exactByteSize); |
---|
514 | exactData = bytesToInt16_bigEndian(curBytes); |
---|
515 | exactData = (uint16_t)exactData >> rightShiftBits; |
---|
516 | exactDataBytePointer += exactByteSize; |
---|
517 | (*data)[index] = exactData + minValue; |
---|
518 | } |
---|
519 | } |
---|
520 | |
---|
521 | /* Process Row-1 --> Row-r2-1 */ |
---|
522 | for (ii = 1; ii < r2; ii++) |
---|
523 | { |
---|
524 | /* Process Row-i data 0 */ |
---|
525 | index = kk*r23 + ii*r3; |
---|
526 | pred2D = (*data)[index-r3] + (*data)[index-r23] - (*data)[index-r23-r3]; |
---|
527 | |
---|
528 | type_ = type[index]; |
---|
529 | if (type_ != 0) |
---|
530 | { |
---|
531 | tmp = pred2D + 2 * (type_ - exe_params->intvRadius) * realPrecision; |
---|
532 | if(tmp >= SZ_INT16_MIN&&tmp<SZ_INT16_MAX) |
---|
533 | (*data)[index] = tmp; |
---|
534 | else if(tmp < SZ_INT16_MIN) |
---|
535 | (*data)[index] = SZ_INT16_MIN; |
---|
536 | else |
---|
537 | (*data)[index] = SZ_INT16_MAX; |
---|
538 | } |
---|
539 | else |
---|
540 | { |
---|
541 | memcpy(curBytes, exactDataBytePointer, exactByteSize); |
---|
542 | exactData = bytesToInt16_bigEndian(curBytes); |
---|
543 | exactData = (uint16_t)exactData >> rightShiftBits; |
---|
544 | exactDataBytePointer += exactByteSize; |
---|
545 | (*data)[index] = exactData + minValue; |
---|
546 | } |
---|
547 | |
---|
548 | /* Process Row-i data 1 --> data r3-1 */ |
---|
549 | for (jj = 1; jj < r3; jj++) |
---|
550 | { |
---|
551 | index = kk*r23 + ii*r3 + jj; |
---|
552 | pred3D = (*data)[index-1] + (*data)[index-r3] + (*data)[index-r23] |
---|
553 | - (*data)[index-r3-1] - (*data)[index-r23-r3] - (*data)[index-r23-1] + (*data)[index-r23-r3-1]; |
---|
554 | |
---|
555 | type_ = type[index]; |
---|
556 | if (type_ != 0) |
---|
557 | { |
---|
558 | tmp = pred3D + 2 * (type_ - exe_params->intvRadius) * realPrecision; |
---|
559 | if(tmp >= SZ_INT16_MIN&&tmp<SZ_INT16_MAX) |
---|
560 | (*data)[index] = tmp; |
---|
561 | else if(tmp < SZ_INT16_MIN) |
---|
562 | (*data)[index] = SZ_INT16_MIN; |
---|
563 | else |
---|
564 | (*data)[index] = SZ_INT16_MAX; |
---|
565 | } |
---|
566 | else |
---|
567 | { |
---|
568 | memcpy(curBytes, exactDataBytePointer, exactByteSize); |
---|
569 | exactData = bytesToInt16_bigEndian(curBytes); |
---|
570 | exactData = (uint16_t)exactData >> rightShiftBits; |
---|
571 | exactDataBytePointer += exactByteSize; |
---|
572 | (*data)[index] = exactData + minValue; |
---|
573 | } |
---|
574 | } |
---|
575 | } |
---|
576 | } |
---|
577 | |
---|
578 | free(type); |
---|
579 | return; |
---|
580 | } |
---|
581 | |
---|
582 | |
---|
583 | void decompressDataSeries_int16_4D(int16_t** data, size_t r1, size_t r2, size_t r3, size_t r4, TightDataPointStorageI* tdps) |
---|
584 | { |
---|
585 | updateQuantizationInfo(tdps->intervals); |
---|
586 | size_t dataSeriesLength = r1*r2*r3*r4; |
---|
587 | size_t r234 = r2*r3*r4; |
---|
588 | size_t r34 = r3*r4; |
---|
589 | |
---|
590 | double realPrecision = tdps->realPrecision; |
---|
591 | |
---|
592 | *data = (int16_t*)malloc(sizeof(int16_t)*dataSeriesLength); |
---|
593 | int* type = (int*)malloc(dataSeriesLength*sizeof(int)); |
---|
594 | |
---|
595 | HuffmanTree* huffmanTree = createHuffmanTree(tdps->stateNum); |
---|
596 | decode_withTree(huffmanTree, tdps->typeArray, dataSeriesLength, type); |
---|
597 | SZ_ReleaseHuffman(huffmanTree); |
---|
598 | |
---|
599 | int16_t minValue, exactData; |
---|
600 | |
---|
601 | minValue = tdps->minValue; |
---|
602 | |
---|
603 | int exactByteSize = tdps->exactByteSize; |
---|
604 | unsigned char* exactDataBytePointer = tdps->exactDataBytes; |
---|
605 | |
---|
606 | unsigned char curBytes[8] = {0,0,0,0,0,0,0,0}; |
---|
607 | |
---|
608 | int rightShiftBits = computeRightShiftBits(exactByteSize, SZ_INT16); |
---|
609 | |
---|
610 | int type_; |
---|
611 | |
---|
612 | long pred1D, pred2D, pred3D, tmp; |
---|
613 | size_t ii, jj, kk, ll; |
---|
614 | size_t index; |
---|
615 | |
---|
616 | for (ll = 0; ll < r1; ll++) |
---|
617 | { |
---|
618 | /////////////////////////// Process layer-0 /////////////////////////// |
---|
619 | /* Process Row-0 data 0*/ |
---|
620 | index = ll*r234; |
---|
621 | |
---|
622 | // recover the exact data |
---|
623 | memcpy(curBytes, exactDataBytePointer, exactByteSize); |
---|
624 | exactData = bytesToInt16_bigEndian(curBytes); |
---|
625 | exactData = (uint16_t)exactData >> rightShiftBits; |
---|
626 | exactDataBytePointer += exactByteSize; |
---|
627 | (*data)[index] = exactData + minValue; |
---|
628 | |
---|
629 | /* Process Row-0, data 1 */ |
---|
630 | index = ll*r234+1; |
---|
631 | |
---|
632 | pred1D = (*data)[index-1]; |
---|
633 | |
---|
634 | type_ = type[index]; |
---|
635 | if (type_ != 0) |
---|
636 | { |
---|
637 | tmp = pred1D + 2 * (type_ - exe_params->intvRadius) * realPrecision; |
---|
638 | if(tmp >= SZ_INT16_MIN&&tmp<SZ_INT16_MAX) |
---|
639 | (*data)[index] = tmp; |
---|
640 | else if(tmp < SZ_INT16_MIN) |
---|
641 | (*data)[index] = SZ_INT16_MIN; |
---|
642 | else |
---|
643 | (*data)[index] = SZ_INT16_MAX; |
---|
644 | } |
---|
645 | else |
---|
646 | { |
---|
647 | memcpy(curBytes, exactDataBytePointer, exactByteSize); |
---|
648 | exactData = bytesToInt16_bigEndian(curBytes); |
---|
649 | exactData = (uint16_t)exactData >> rightShiftBits; |
---|
650 | exactDataBytePointer += exactByteSize; |
---|
651 | (*data)[index] = exactData + minValue; |
---|
652 | } |
---|
653 | |
---|
654 | /* Process Row-0, data 2 --> data r4-1 */ |
---|
655 | for (jj = 2; jj < r4; jj++) |
---|
656 | { |
---|
657 | index = ll*r234+jj; |
---|
658 | |
---|
659 | pred1D = 2*(*data)[index-1] - (*data)[index-2]; |
---|
660 | |
---|
661 | type_ = type[index]; |
---|
662 | if (type_ != 0) |
---|
663 | { |
---|
664 | tmp = pred1D + 2 * (type_ - exe_params->intvRadius) * realPrecision; |
---|
665 | if(tmp >= SZ_INT16_MIN&&tmp<SZ_INT16_MAX) |
---|
666 | (*data)[index] = tmp; |
---|
667 | else if(tmp < SZ_INT16_MIN) |
---|
668 | (*data)[index] = SZ_INT16_MIN; |
---|
669 | else |
---|
670 | (*data)[index] = SZ_INT16_MAX; |
---|
671 | } |
---|
672 | else |
---|
673 | { |
---|
674 | memcpy(curBytes, exactDataBytePointer, exactByteSize); |
---|
675 | exactData = bytesToInt16_bigEndian(curBytes); |
---|
676 | exactData = (uint16_t)exactData >> rightShiftBits; |
---|
677 | exactDataBytePointer += exactByteSize; |
---|
678 | (*data)[index] = exactData + minValue; |
---|
679 | } |
---|
680 | } |
---|
681 | |
---|
682 | /* Process Row-1 --> Row-r3-1 */ |
---|
683 | for (ii = 1; ii < r3; ii++) |
---|
684 | { |
---|
685 | /* Process row-ii data 0 */ |
---|
686 | index = ll*r234+ii*r4; |
---|
687 | |
---|
688 | pred1D = (*data)[index-r4]; |
---|
689 | |
---|
690 | type_ = type[index]; |
---|
691 | if (type_ != 0) |
---|
692 | { |
---|
693 | tmp = pred1D + 2 * (type_ - exe_params->intvRadius) * realPrecision; |
---|
694 | if(tmp >= SZ_INT16_MIN&&tmp<SZ_INT16_MAX) |
---|
695 | (*data)[index] = tmp; |
---|
696 | else if(tmp < SZ_INT16_MIN) |
---|
697 | (*data)[index] = SZ_INT16_MIN; |
---|
698 | else |
---|
699 | (*data)[index] = SZ_INT16_MAX; |
---|
700 | } |
---|
701 | else |
---|
702 | { |
---|
703 | memcpy(curBytes, exactDataBytePointer, exactByteSize); |
---|
704 | exactData = bytesToInt16_bigEndian(curBytes); |
---|
705 | exactData = (uint16_t)exactData >> rightShiftBits; |
---|
706 | exactDataBytePointer += exactByteSize; |
---|
707 | (*data)[index] = exactData + minValue; |
---|
708 | } |
---|
709 | |
---|
710 | /* Process row-ii data 1 --> r4-1*/ |
---|
711 | for (jj = 1; jj < r4; jj++) |
---|
712 | { |
---|
713 | index = ll*r234+ii*r4+jj; |
---|
714 | |
---|
715 | pred2D = (*data)[index-1] + (*data)[index-r4] - (*data)[index-r4-1]; |
---|
716 | |
---|
717 | type_ = type[index]; |
---|
718 | if (type_ != 0) |
---|
719 | { |
---|
720 | tmp = pred2D + 2 * (type_ - exe_params->intvRadius) * realPrecision; |
---|
721 | if(tmp >= SZ_INT16_MIN&&tmp<SZ_INT16_MAX) |
---|
722 | (*data)[index] = tmp; |
---|
723 | else if(tmp < SZ_INT16_MIN) |
---|
724 | (*data)[index] = SZ_INT16_MIN; |
---|
725 | else |
---|
726 | (*data)[index] = SZ_INT16_MAX; |
---|
727 | } |
---|
728 | else |
---|
729 | { |
---|
730 | memcpy(curBytes, exactDataBytePointer, exactByteSize); |
---|
731 | exactData = bytesToInt16_bigEndian(curBytes); |
---|
732 | exactData = (uint16_t)exactData >> rightShiftBits; |
---|
733 | exactDataBytePointer += exactByteSize; |
---|
734 | (*data)[index] = exactData + minValue; |
---|
735 | } |
---|
736 | } |
---|
737 | } |
---|
738 | |
---|
739 | /////////////////////////// Process layer-1 --> layer-r2-1 /////////////////////////// |
---|
740 | |
---|
741 | for (kk = 1; kk < r2; kk++) |
---|
742 | { |
---|
743 | /* Process Row-0 data 0*/ |
---|
744 | index = ll*r234+kk*r34; |
---|
745 | |
---|
746 | pred1D = (*data)[index-r34]; |
---|
747 | |
---|
748 | type_ = type[index]; |
---|
749 | if (type_ != 0) |
---|
750 | { |
---|
751 | tmp = pred1D + 2 * (type_ - exe_params->intvRadius) * realPrecision; |
---|
752 | if(tmp >= SZ_INT16_MIN&&tmp<SZ_INT16_MAX) |
---|
753 | (*data)[index] = tmp; |
---|
754 | else if(tmp < SZ_INT16_MIN) |
---|
755 | (*data)[index] = SZ_INT16_MIN; |
---|
756 | else |
---|
757 | (*data)[index] = SZ_INT16_MAX; |
---|
758 | } |
---|
759 | else |
---|
760 | { |
---|
761 | memcpy(curBytes, exactDataBytePointer, exactByteSize); |
---|
762 | exactData = bytesToInt16_bigEndian(curBytes); |
---|
763 | exactData = (uint16_t)exactData >> rightShiftBits; |
---|
764 | exactDataBytePointer += exactByteSize; |
---|
765 | (*data)[index] = exactData + minValue; |
---|
766 | } |
---|
767 | |
---|
768 | /* Process Row-0 data 1 --> data r4-1 */ |
---|
769 | for (jj = 1; jj < r4; jj++) |
---|
770 | { |
---|
771 | index = ll*r234+kk*r34+jj; |
---|
772 | |
---|
773 | pred2D = (*data)[index-1] + (*data)[index-r34] - (*data)[index-r34-1]; |
---|
774 | |
---|
775 | type_ = type[index]; |
---|
776 | if (type_ != 0) |
---|
777 | { |
---|
778 | tmp = pred2D + 2 * (type_ - exe_params->intvRadius) * realPrecision; |
---|
779 | if(tmp >= SZ_INT16_MIN&&tmp<SZ_INT16_MAX) |
---|
780 | (*data)[index] = tmp; |
---|
781 | else if(tmp < SZ_INT16_MIN) |
---|
782 | (*data)[index] = SZ_INT16_MIN; |
---|
783 | else |
---|
784 | (*data)[index] = SZ_INT16_MAX; |
---|
785 | } |
---|
786 | else |
---|
787 | { |
---|
788 | memcpy(curBytes, exactDataBytePointer, exactByteSize); |
---|
789 | exactData = bytesToInt16_bigEndian(curBytes); |
---|
790 | exactData = (uint16_t)exactData >> rightShiftBits; |
---|
791 | exactDataBytePointer += exactByteSize; |
---|
792 | (*data)[index] = exactData + minValue; |
---|
793 | } |
---|
794 | } |
---|
795 | |
---|
796 | /* Process Row-1 --> Row-r3-1 */ |
---|
797 | for (ii = 1; ii < r3; ii++) |
---|
798 | { |
---|
799 | /* Process Row-i data 0 */ |
---|
800 | index = ll*r234+kk*r34+ii*r4; |
---|
801 | |
---|
802 | pred2D = (*data)[index-r4] + (*data)[index-r34] - (*data)[index-r34-r4]; |
---|
803 | |
---|
804 | type_ = type[index]; |
---|
805 | if (type_ != 0) |
---|
806 | { |
---|
807 | tmp = pred2D + 2 * (type_ - exe_params->intvRadius) * realPrecision; |
---|
808 | if(tmp >= SZ_INT16_MIN&&tmp<SZ_INT16_MAX) |
---|
809 | (*data)[index] = tmp; |
---|
810 | else if(tmp < SZ_INT16_MIN) |
---|
811 | (*data)[index] = SZ_INT16_MIN; |
---|
812 | else |
---|
813 | (*data)[index] = SZ_INT16_MAX; |
---|
814 | } |
---|
815 | else |
---|
816 | { |
---|
817 | memcpy(curBytes, exactDataBytePointer, exactByteSize); |
---|
818 | exactData = bytesToInt16_bigEndian(curBytes); |
---|
819 | exactData = (uint16_t)exactData >> rightShiftBits; |
---|
820 | exactDataBytePointer += exactByteSize; |
---|
821 | (*data)[index] = exactData + minValue; |
---|
822 | } |
---|
823 | |
---|
824 | /* Process Row-i data 1 --> data r4-1 */ |
---|
825 | for (jj = 1; jj < r4; jj++) |
---|
826 | { |
---|
827 | index = ll*r234+kk*r34+ii*r4+jj; |
---|
828 | |
---|
829 | pred3D = (*data)[index-1] + (*data)[index-r4] + (*data)[index-r34] |
---|
830 | - (*data)[index-r4-1] - (*data)[index-r34-r4] - (*data)[index-r34-1] + (*data)[index-r34-r4-1]; |
---|
831 | |
---|
832 | |
---|
833 | type_ = type[index]; |
---|
834 | if (type_ != 0) |
---|
835 | { |
---|
836 | tmp = pred3D + 2 * (type_ - exe_params->intvRadius) * realPrecision; |
---|
837 | if(tmp >= SZ_INT16_MIN&&tmp<SZ_INT16_MAX) |
---|
838 | (*data)[index] = tmp; |
---|
839 | else if(tmp < SZ_INT16_MIN) |
---|
840 | (*data)[index] = SZ_INT16_MIN; |
---|
841 | else |
---|
842 | (*data)[index] = SZ_INT16_MAX; |
---|
843 | } |
---|
844 | else |
---|
845 | { |
---|
846 | memcpy(curBytes, exactDataBytePointer, exactByteSize); |
---|
847 | exactData = bytesToInt16_bigEndian(curBytes); |
---|
848 | exactData = (uint16_t)exactData >> rightShiftBits; |
---|
849 | exactDataBytePointer += exactByteSize; |
---|
850 | (*data)[index] = exactData + minValue; |
---|
851 | } |
---|
852 | } |
---|
853 | } |
---|
854 | } |
---|
855 | } |
---|
856 | |
---|
857 | free(type); |
---|
858 | return; |
---|
859 | } |
---|
860 | |
---|
861 | void getSnapshotData_int16_1D(int16_t** data, size_t dataSeriesLength, TightDataPointStorageI* tdps, int errBoundMode) |
---|
862 | { |
---|
863 | size_t i; |
---|
864 | |
---|
865 | if (tdps->allSameData) { |
---|
866 | int16_t value = bytesToInt16_bigEndian(tdps->exactDataBytes); |
---|
867 | *data = (int16_t*)malloc(sizeof(int16_t)*dataSeriesLength); |
---|
868 | for (i = 0; i < dataSeriesLength; i++) |
---|
869 | (*data)[i] = value; |
---|
870 | } else { |
---|
871 | decompressDataSeries_int16_1D(data, dataSeriesLength, tdps); |
---|
872 | } |
---|
873 | } |
---|
874 | |
---|
875 | void getSnapshotData_int16_2D(int16_t** data, size_t r1, size_t r2, TightDataPointStorageI* tdps, int errBoundMode) |
---|
876 | { |
---|
877 | size_t i; |
---|
878 | size_t dataSeriesLength = r1*r2; |
---|
879 | if (tdps->allSameData) { |
---|
880 | int16_t value = bytesToInt16_bigEndian(tdps->exactDataBytes); |
---|
881 | *data = (int16_t*)malloc(sizeof(int16_t)*dataSeriesLength); |
---|
882 | for (i = 0; i < dataSeriesLength; i++) |
---|
883 | (*data)[i] = value; |
---|
884 | } else { |
---|
885 | decompressDataSeries_int16_2D(data, r1, r2, tdps); |
---|
886 | } |
---|
887 | } |
---|
888 | |
---|
889 | void getSnapshotData_int16_3D(int16_t** data, size_t r1, size_t r2, size_t r3, TightDataPointStorageI* tdps, int errBoundMode) |
---|
890 | { |
---|
891 | size_t i; |
---|
892 | size_t dataSeriesLength = r1*r2*r3; |
---|
893 | if (tdps->allSameData) { |
---|
894 | int16_t value = bytesToInt16_bigEndian(tdps->exactDataBytes); |
---|
895 | *data = (int16_t*)malloc(sizeof(int16_t)*dataSeriesLength); |
---|
896 | for (i = 0; i < dataSeriesLength; i++) |
---|
897 | (*data)[i] = value; |
---|
898 | } else { |
---|
899 | decompressDataSeries_int16_3D(data, r1, r2, r3, tdps); |
---|
900 | } |
---|
901 | } |
---|
902 | |
---|
903 | void getSnapshotData_int16_4D(int16_t** data, size_t r1, size_t r2, size_t r3, size_t r4, TightDataPointStorageI* tdps, int errBoundMode) |
---|
904 | { |
---|
905 | size_t i; |
---|
906 | size_t dataSeriesLength = r1*r2*r3*r4; |
---|
907 | if (tdps->allSameData) { |
---|
908 | int16_t value = bytesToInt16_bigEndian(tdps->exactDataBytes); |
---|
909 | *data = (int16_t*)malloc(sizeof(int16_t)*dataSeriesLength); |
---|
910 | for (i = 0; i < dataSeriesLength; i++) |
---|
911 | (*data)[i] = value; |
---|
912 | } else { |
---|
913 | decompressDataSeries_int16_4D(data, r1, r2, r3, r4, tdps); |
---|
914 | } |
---|
915 | } |
---|