Commit 79136519 authored by Mathis Rosenhauer's avatar Mathis Rosenhauer

Szip decompression error be gone

parent d1f7331a
...@@ -39,11 +39,11 @@ clean: ...@@ -39,11 +39,11 @@ clean:
*.gcno *.gcda *.gcov gmon.out *.gcno *.gcda *.gcov gmon.out
check: encode decode test_szcomp check: encode decode test_szcomp
./encode -c -b1 -B8 -S128 ../data/example_data > ../data/test.aee ./encode -c -b1 -B8 -R128 ../data/example_data > ../data/test.aee
./decode -b1 -B8 -S128 ../data/test.aee ./decode -b1 -B8 -R128 ../data/test.aee
diff ../data/test ../data/example_data diff ../data/test ../data/example_data
./encode -c -b1024 -B8 -S128 ../data/example_data > ../data/test.aee ./encode -c -b1024 -B8 -R128 ../data/example_data > ../data/test.aee
./decode -b1024 -B8 -S128 ../data/test.aee ./decode -b1024 -B8 -R128 ../data/test.aee
diff ../data/test ../data/example_data diff ../data/test ../data/example_data
./test_szcomp 65536 ../data/example_data_16 ./test_szcomp 65536 ../data/example_data_16
......
...@@ -302,7 +302,7 @@ int ae_decode_init(ae_streamp strm) ...@@ -302,7 +302,7 @@ int ae_decode_init(ae_streamp strm)
state->xmax = (1ULL << strm->bit_per_sample) - 1; state->xmax = (1ULL << strm->bit_per_sample) - 1;
} }
state->ref_int = strm->block_size * strm->segment_size; state->ref_int = strm->block_size * strm->rsi;
state->in_blklen = (strm->block_size * strm->bit_per_sample state->in_blklen = (strm->block_size * strm->bit_per_sample
+ state->id_len) / 8 + 1; + state->id_len) / 8 + 1;
...@@ -431,7 +431,7 @@ int ae_decode(ae_streamp strm, int flush) ...@@ -431,7 +431,7 @@ int ae_decode(ae_streamp strm, int flush)
{ {
case M_ID: case M_ID:
if (state->pp if (state->pp
&& (state->samples_out / strm->block_size) % strm->segment_size == 0) && (state->samples_out / strm->block_size) % strm->rsi == 0)
state->ref = 1; state->ref = 1;
else else
state->ref = 0; state->ref = 0;
...@@ -513,9 +513,9 @@ int ae_decode(ae_streamp strm, int flush) ...@@ -513,9 +513,9 @@ int ae_decode(ae_streamp strm, int flush)
if (zero_blocks == ROS) if (zero_blocks == ROS)
{ {
zero_blocks = strm->segment_size - ( zero_blocks = 64 - (
(state->samples_out / strm->block_size) (state->samples_out / strm->block_size)
% strm->segment_size); % strm->rsi % 64);
} }
else if (zero_blocks > ROS) else if (zero_blocks > ROS)
{ {
......
...@@ -182,11 +182,8 @@ int ae_encode_init(ae_streamp strm) ...@@ -182,11 +182,8 @@ int ae_encode_init(ae_streamp strm)
return AE_MEM_ERROR; return AE_MEM_ERROR;
} }
/* Zero blocks can span a segment and thus need up to segment_size /* Largest possible block according to specs */
bits in encoded block */ blklen = (5 + 16 * 32) / 8 + 3;
blklen = MAX(strm->block_size * strm->bit_per_sample,
strm->segment_size + 10);
blklen = (blklen + state->id_len) / 8 + 3;
state->block_out = (uint8_t *)malloc(blklen); state->block_out = (uint8_t *)malloc(blklen);
if (state->block_out == NULL) if (state->block_out == NULL)
{ {
...@@ -380,7 +377,7 @@ int ae_encode(ae_streamp strm, int flush) ...@@ -380,7 +377,7 @@ int ae_encode(ae_streamp strm, int flush)
/* If this is the first block in a segment /* If this is the first block in a segment
then we need to insert a reference sample. then we need to insert a reference sample.
*/ */
if(state->total_blocks % strm->segment_size == 1) if(state->total_blocks % strm->rsi == 1)
{ {
state->ref = 1; state->ref = 1;
state->last_in = state->block_in[0]; state->last_in = state->block_in[0];
...@@ -430,7 +427,7 @@ int ae_encode(ae_streamp strm, int flush) ...@@ -430,7 +427,7 @@ int ae_encode(ae_streamp strm, int flush)
state->zero_blocks++; state->zero_blocks++;
if (state->total_blocks % strm->segment_size == 0) if (state->total_blocks % strm->rsi % 64 == 0)
{ {
#ifdef PROFILE #ifdef PROFILE
state->prof[0] += state->zero_blocks; state->prof[0] += state->zero_blocks;
......
...@@ -22,11 +22,11 @@ int main(int argc, char *argv[]) ...@@ -22,11 +22,11 @@ int main(int argc, char *argv[])
chunk = CHUNK; chunk = CHUNK;
strm.bit_per_sample = 8; strm.bit_per_sample = 8;
strm.block_size = 8; strm.block_size = 8;
strm.segment_size = 2; strm.rsi = 2;
strm.flags = AE_DATA_MSB | AE_DATA_PREPROCESS; strm.flags = AE_DATA_MSB | AE_DATA_PREPROCESS;
opterr = 0; opterr = 0;
while ((c = getopt (argc, argv, "cb:B:S:")) != -1) while ((c = getopt (argc, argv, "cb:B:R:")) != -1)
switch (c) switch (c)
{ {
case 'b': case 'b':
...@@ -35,8 +35,8 @@ int main(int argc, char *argv[]) ...@@ -35,8 +35,8 @@ int main(int argc, char *argv[])
case 'B': case 'B':
strm.bit_per_sample = atoi(optarg); strm.bit_per_sample = atoi(optarg);
break; break;
case 'S': case 'R':
strm.segment_size = atoi(optarg); strm.rsi = atoi(optarg);
break; break;
case 'c': case 'c':
cflag = 1; cflag = 1;
......
...@@ -22,11 +22,11 @@ int main(int argc, char *argv[]) ...@@ -22,11 +22,11 @@ int main(int argc, char *argv[])
chunk = CHUNK; chunk = CHUNK;
strm.bit_per_sample = 8; strm.bit_per_sample = 8;
strm.block_size = 8; strm.block_size = 8;
strm.segment_size = 2; strm.rsi = 2;
strm.flags = AE_DATA_MSB | AE_DATA_PREPROCESS; strm.flags = AE_DATA_MSB | AE_DATA_PREPROCESS;
opterr = 0; opterr = 0;
while ((c = getopt (argc, argv, "cb:B:S:")) != -1) while ((c = getopt (argc, argv, "cb:B:R:")) != -1)
switch (c) switch (c)
{ {
case 'b': case 'b':
...@@ -35,8 +35,8 @@ int main(int argc, char *argv[]) ...@@ -35,8 +35,8 @@ int main(int argc, char *argv[])
case 'B': case 'B':
strm.bit_per_sample = atoi(optarg); strm.bit_per_sample = atoi(optarg);
break; break;
case 'S': case 'R':
strm.segment_size = atoi(optarg); strm.rsi = atoi(optarg);
break; break;
case 'c': case 'c':
cflag = 1; cflag = 1;
......
...@@ -18,8 +18,9 @@ typedef struct _ae_stream ...@@ -18,8 +18,9 @@ typedef struct _ae_stream
uint32_t bit_per_sample; /* resolution in bits per sample (n = uint32_t bit_per_sample; /* resolution in bits per sample (n =
* 1,..., 32) */ * 1,..., 32) */
uint32_t block_size; /* block size in samples (J = 8 or 16) */ uint32_t block_size; /* block size in samples (J = 8 or 16) */
uint32_t segment_size; /* set of blocks between consecutive uint32_t rsi; /* Reference sample interval, the number of
* reference samples */ blocks between consecutive reference
samples. */
uint32_t flags; uint32_t flags;
struct internal_state *state; struct internal_state *state;
......
...@@ -8,7 +8,7 @@ int SZ_BufftoBuffCompress(void *dest, size_t *destLen, const void *source, size_ ...@@ -8,7 +8,7 @@ int SZ_BufftoBuffCompress(void *dest, size_t *destLen, const void *source, size_
strm.bit_per_sample = param->bits_per_pixel; strm.bit_per_sample = param->bits_per_pixel;
strm.block_size = param->pixels_per_block; strm.block_size = param->pixels_per_block;
strm.segment_size = param->pixels_per_scanline / param->pixels_per_block; strm.rsi = param->pixels_per_scanline / param->pixels_per_block;
strm.flags = param->options_mask; strm.flags = param->options_mask;
strm.avail_in = sourceLen; strm.avail_in = sourceLen;
strm.avail_out = *destLen; strm.avail_out = *destLen;
...@@ -36,7 +36,7 @@ int SZ_BufftoBuffDecompress(void *dest, size_t *destLen, const void *source, siz ...@@ -36,7 +36,7 @@ int SZ_BufftoBuffDecompress(void *dest, size_t *destLen, const void *source, siz
strm.bit_per_sample = param->bits_per_pixel; strm.bit_per_sample = param->bits_per_pixel;
strm.block_size = param->pixels_per_block; strm.block_size = param->pixels_per_block;
strm.segment_size = param->pixels_per_scanline / param->pixels_per_block; strm.rsi = param->pixels_per_scanline / param->pixels_per_block;
strm.flags = param->options_mask; strm.flags = param->options_mask;
strm.avail_in = sourceLen; strm.avail_in = sourceLen;
strm.avail_out = *destLen; strm.avail_out = *destLen;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment