Additions from 121x0b2: option selection, larger blocks.
authorMathis Rosenhauer <rosenhauer@dkrz.de>
Fri, 31 Aug 2012 14:28:27 +0000 (16:28 +0200)
committerMathis Rosenhauer <rosenhauer@dkrz.de>
Mon, 3 Sep 2012 07:12:39 +0000 (09:12 +0200)
src/Makefile
src/aed.c
src/aee.c
src/aee_mutators.c
src/aee_mutators.h
src/decode.c
src/encode.c

index c3877cd..6a83629 100644 (file)
@@ -40,12 +40,10 @@ clean:
        *.gcno *.gcda *.gcov gmon.out
 
 check: encode decode test_szcomp
-        ./encode -c -b1 -B8 -R128 ../data/example_data > ../data/test.aee
-        ./decode -b1 -B8 -R128 ../data/test.aee
+        ./encode -c -b1 -B8 -R128 -J64 ../data/example_data > ../data/test.aee
+        ./decode -b1 -B8 -R128 -J64 ../data/test.aee
         diff ../data/test ../data/example_data
-        ./encode -c -b1024 -B8 -R128 ../data/example_data > ../data/test.aee
-        ./decode -b1024 -B8 -R128 ../data/test.aee
+        ./encode -c -b1024 -B8 -R128 -J64 ../data/example_data > ../data/test.aee
+        ./decode -b1024 -B8 -R128 -J64 ../data/test.aee
         diff ../data/test ../data/example_data
         ./test_szcomp 65536 ../data/example_data_16
-
-
index fc87e38..9217a6f 100644 (file)
--- a/src/aed.c
+++ b/src/aed.c
@@ -42,7 +42,7 @@ typedef struct internal_state {
 } decode_state;
 
 /* decoding table for the second-extension option */
-static const int second_extension[36][2] = {
+static const int second_extension[92][2] = {
     {0, 0},
     {1, 1}, {1, 1},
     {2, 3}, {2, 3}, {2, 3},
@@ -50,7 +50,12 @@ static const int second_extension[36][2] = {
     {4, 10}, {4, 10}, {4, 10}, {4, 10}, {4, 10},
     {5, 15}, {5, 15}, {5, 15}, {5, 15}, {5, 15}, {5, 15},
     {6, 21}, {6, 21}, {6, 21}, {6, 21}, {6, 21}, {6, 21}, {6, 21},
-    {7, 28}, {7, 28}, {7, 28}, {7, 28}, {7, 28}, {7, 28}, {7, 28}, {7, 28}
+    {7, 28}, {7, 28}, {7, 28}, {7, 28}, {7, 28}, {7, 28}, {7, 28}, {7, 28},
+    {8, 36}, {8, 36}, {8, 36}, {8, 36}, {8, 36}, {8, 36}, {8, 36}, {8, 36}, {8, 36},
+    {9, 45}, {9, 45}, {9, 45}, {9, 45}, {9, 45}, {9, 45}, {9, 45}, {9, 45}, {9, 45}, {9, 45},
+    {10, 55}, {10, 55}, {10, 55}, {10, 55}, {10, 55}, {10, 55}, {10, 55}, {10, 55}, {10, 55}, {10, 55}, {10, 55},
+    {11, 66}, {11, 66}, {11, 66}, {11, 66}, {11, 66}, {11, 66}, {11, 66}, {11, 66}, {11, 66}, {11, 66}, {11, 66}, {11, 66},
+    {12, 78}, {12, 78}, {12, 78}, {12, 78}, {12, 78}, {12, 78}, {12, 78}, {12, 78}, {12, 78}, {12, 78}, {12, 78}, {12, 78}, {12, 78}
 };
 
 enum
index 08b3723..818d1e9 100644 (file)
--- a/src/aee.c
+++ b/src/aee.c
@@ -336,7 +336,7 @@ static inline int m_check_zero_block(ae_streamp strm)
 
 static inline int m_select_code_option(ae_streamp strm)
 {
-    int i, k, this_bs, looked_bothways, direction;
+    int i, j, k, this_bs, looked_bothways, direction;
     int64_t d, split_len, uncomp_len;
     int64_t split_len_min, se_len, fs_len;
     encode_state *state = strm->state;
@@ -365,15 +365,9 @@ static inline int m_select_code_option(ae_streamp strm)
         if (state->ref == 0)
             fs_len += (state->in_block[0] >> i);
 
-        if (strm->block_size == 16)
-            fs_len += (state->in_block[8] >> i)
-                + (state->in_block[9] >> i)
-                + (state->in_block[10] >> i)
-                + (state->in_block[11] >> i)
-                + (state->in_block[12] >> i)
-                + (state->in_block[13] >> i)
-                + (state->in_block[14] >> i)
-                + (state->in_block[15] >> i);
+        if (strm->block_size > 8)
+            for (j = 8; j < strm->block_size; j++)
+                fs_len += state->in_block[j] >> i;
 
         split_len = fs_len + this_bs * (i + 1);
 
@@ -480,7 +474,7 @@ static inline int m_select_code_option(ae_streamp strm)
     /* Decide which option to use */
     if (split_len_min < uncomp_len)
     {
-        if (split_len_min <= se_len)
+        if (split_len_min < se_len)
         {
             /* Splitting won - the most common case. */
             return m_encode_splitting(strm);
@@ -622,9 +616,16 @@ int ae_encode_init(ae_streamp strm)
 
     /* Some sanity checks */
     if (strm->bit_per_sample > 32 || strm->bit_per_sample == 0)
-    {
         return AE_ERRNO;
-    }
+
+    if (strm->block_size != 8
+        && strm->block_size != 16
+        && strm->block_size != 32
+        && strm->block_size != 64)
+        return AE_ERRNO;
+
+    if (strm->rsi > 4096)
+        return AE_ERRNO;
 
     /* Internal state for encoder */
     state = (encode_state *) malloc(sizeof(encode_state));
@@ -642,7 +643,10 @@ int ae_encode_init(ae_streamp strm)
         state->in_blklen = 4 * strm->block_size;
 
         if (strm->flags & AE_DATA_MSB)
+        {
             state->get_sample = get_msb_32;
+            state->get_block = get_block_msb_32;
+        }
         else
             state->get_sample = get_lsb_32;
     }
@@ -659,7 +663,7 @@ int ae_encode_init(ae_streamp strm)
             if (strm->block_size == 8)
                 state->get_block = get_block_msb_16_bs_8;
             else
-                state->get_block = get_block_msb_16_bs_16;
+                state->get_block = get_block_msb_16;
         }
         else
             state->get_sample = get_lsb_16;
@@ -675,7 +679,7 @@ int ae_encode_init(ae_streamp strm)
         if (strm->block_size == 8)
             state->get_block = get_block_8_bs_8;
         else
-            state->get_block = get_block_8_bs_16;
+            state->get_block = get_block_8;
     }
 
     if (strm->flags & AE_DATA_SIGNED)
@@ -696,7 +700,7 @@ int ae_encode_init(ae_streamp strm)
     }
 
     /* Largest possible block according to specs */
-    state->out_blklen = (5 + 16 * 32) / 8 + 3;
+    state->out_blklen = (5 + 64 * 32) / 8 + 3;
     state->out_block = (uint8_t *)malloc(state->out_blklen);
     if (state->out_block == NULL)
     {
index f6a88e8..1c32342 100644 (file)
@@ -82,7 +82,7 @@ void get_block_msb_16_bs_8(ae_streamp strm)
     strm->avail_in -= 16;
 }
 
-void get_block_msb_16_bs_16(ae_streamp strm)
+void get_block_msb_16(ae_streamp strm)
 {
     int i;
     int64_t *block = strm->state->in_block;
@@ -92,9 +92,26 @@ void get_block_msb_16_bs_16(ae_streamp strm)
         block[i] = (strm->next_in[2 * i] << 8)
             | strm->next_in[2 * i + 1];
     }
-    strm->next_in += 32;
-    strm->total_in += 32;
-    strm->avail_in -= 32;
+    strm->next_in += 2 * strm->block_size;
+    strm->total_in += 2 * strm->block_size;
+    strm->avail_in -= 2 * strm->block_size;
+}
+
+void get_block_msb_32(ae_streamp strm)
+{
+    int i;
+    int64_t *block = strm->state->in_block;
+
+    for (i = 0; i < strm->block_size; i++)
+    {
+        block[i] = (strm->next_in[4 * i] << 24)
+            | (strm->next_in[4 * i + 1] << 16)
+            | (strm->next_in[4 * i + 2] << 8)
+            | strm->next_in[4 * i + 3];
+    }
+    strm->next_in += 4 * strm->block_size;
+    strm->total_in += 4 * strm->block_size;
+    strm->avail_in -= 4 * strm->block_size;
 }
 
 void get_block_8_bs_8(ae_streamp strm)
@@ -115,28 +132,15 @@ void get_block_8_bs_8(ae_streamp strm)
     strm->avail_in -= 8;
 }
 
-void get_block_8_bs_16(ae_streamp strm)
+void get_block_8(ae_streamp strm)
 {
+    int i;
     int64_t *block = strm->state->in_block;
 
-    block[0] = strm->next_in[0];
-    block[1] = strm->next_in[1];
-    block[2] = strm->next_in[2];
-    block[3] = strm->next_in[3];
-    block[4] = strm->next_in[4];
-    block[5] = strm->next_in[5];
-    block[6] = strm->next_in[6];
-    block[7] = strm->next_in[7];
-    block[8] = strm->next_in[8];
-    block[9] = strm->next_in[9];
-    block[10] = strm->next_in[10];
-    block[11] = strm->next_in[11];
-    block[12] = strm->next_in[12];
-    block[13] = strm->next_in[13];
-    block[14] = strm->next_in[14];
-    block[15] = strm->next_in[15];
+    for (i = 0; i < strm->block_size; i++)
+        block[i] = strm->next_in[i];
 
-    strm->next_in += 16;
-    strm->total_in += 16;
-    strm->avail_in -= 16;
+    strm->next_in += strm->block_size;
+    strm->total_in += strm->block_size;
+    strm->avail_in -= strm->block_size;
 }
index 84ae370..5139170 100644 (file)
@@ -10,9 +10,10 @@ int64_t get_msb_32(ae_streamp);
 int64_t get_msb_16(ae_streamp);
 int64_t get_8(ae_streamp);
 
+void get_block_msb_32(ae_streamp);
 void get_block_msb_16_bs_8(ae_streamp);
-void get_block_msb_16_bs_16(ae_streamp);
+void get_block_msb_16(ae_streamp);
 void get_block_8_bs_8(ae_streamp);
-void get_block_8_bs_16(ae_streamp);
+void get_block_8(ae_streamp);
 
 #endif
index b76015d..c7e25ed 100644 (file)
@@ -27,7 +27,7 @@ int main(int argc, char *argv[])
     strm.flags = AE_DATA_MSB | AE_DATA_PREPROCESS;
     opterr = 0;
 
-    while ((c = getopt (argc, argv, "cb:B:R:")) != -1)
+    while ((c = getopt (argc, argv, "cb:B:J:R:")) != -1)
         switch (c)
         {
         case 'b':
@@ -36,6 +36,9 @@ int main(int argc, char *argv[])
         case 'B':
             strm.bit_per_sample = atoi(optarg);
             break;
+        case 'J':
+            strm.block_size = atoi(optarg);
+            break;
         case 'R':
             strm.rsi = atoi(optarg);
             break;
index d574fbb..85465c7 100644 (file)
@@ -27,7 +27,7 @@ int main(int argc, char *argv[])
     strm.flags = AE_DATA_MSB | AE_DATA_PREPROCESS;
     opterr = 0;
 
-    while ((c = getopt (argc, argv, "cb:B:R:")) != -1)
+    while ((c = getopt (argc, argv, "cb:B:R:J:")) != -1)
         switch (c)
         {
         case 'b':
@@ -36,6 +36,9 @@ int main(int argc, char *argv[])
         case 'B':
             strm.bit_per_sample = atoi(optarg);
             break;
+        case 'J':
+            strm.block_size = atoi(optarg);
+            break;
         case 'R':
             strm.rsi = atoi(optarg);
             break;