Working 3 byte datatype support.
authorMathis Rosenhauer <rosenhauer@dkrz.de>
Sun, 16 Sep 2012 14:16:05 +0000 (16:16 +0200)
committerThomas Jahns <jahns@dkrz.de>
Tue, 19 Feb 2013 10:32:58 +0000 (11:32 +0100)
src/aed.c
src/aee.c
src/aee_accessors.c
src/decode.c
src/encode.c

index c1295e4..6896e05 100644 (file)
--- a/src/aed.c
+++ b/src/aed.c
@@ -84,6 +84,15 @@ static void put_msb_32(ae_streamp strm, int64_t data)
     strm->total_out += 4;
 }
 
+static void put_msb_24(ae_streamp strm, int64_t data)
+{
+    *strm->next_out++ = data >> 16;
+    *strm->next_out++ = data >> 8;
+    *strm->next_out++ = data;
+    strm->avail_out -= 3;
+    strm->total_out += 3;
+}
+
 static void put_msb_16(ae_streamp strm, int64_t data)
 {
     *strm->next_out++ = data >> 8;
@@ -102,6 +111,15 @@ static void put_lsb_32(ae_streamp strm, int64_t data)
     strm->total_out += 4;
 }
 
+static void put_lsb_24(ae_streamp strm, int64_t data)
+{
+    *strm->next_out++ = data;
+    *strm->next_out++ = data >> 8;
+    *strm->next_out++ = data >> 16;
+    strm->avail_out -= 3;
+    strm->total_out += 3;
+}
+
 static void put_lsb_16(ae_streamp strm, int64_t data)
 {
     *strm->next_out++ = data;
@@ -278,13 +296,26 @@ int ae_decode_init(ae_streamp strm)
 
     if (strm->bit_per_sample > 16)
     {
-        state->byte_per_sample = 4;
         state->id_len = 5;
-        state->out_blklen = strm->block_size * 4;
-        if (strm->flags & AE_DATA_MSB)
-            state->put_sample = put_msb_32;
+
+        if (strm->bit_per_sample <= 24 && strm->flags & AE_DATA_3BYTE)
+        {
+            state->byte_per_sample = 3;
+            if (strm->flags & AE_DATA_MSB)
+                state->put_sample = put_msb_24;
+            else
+                state->put_sample = put_lsb_24;
+        }
         else
-            state->put_sample = put_lsb_32;
+        {
+            state->byte_per_sample = 4;
+            if (strm->flags & AE_DATA_MSB)
+                state->put_sample = put_msb_32;
+            else
+                state->put_sample = put_lsb_32;
+        }
+        state->out_blklen = strm->block_size
+            * state->byte_per_sample;
     }
     else if (strm->bit_per_sample > 8)
     {
index 70b6a74..98c42ea 100644 (file)
--- a/src/aee.c
+++ b/src/aee.c
@@ -687,31 +687,30 @@ int ae_encode_init(ae_streamp strm)
 
     if (strm->bit_per_sample > 16)
     {
-        /* 32 bit settings */
+        /* 24/32 input bit settings */
         state->id_len = 5;
-        state->block_len = 4 * strm->block_size;
 
-        if (strm->flags & AE_DATA_MSB)
+        if (strm->bit_per_sample <= 24 && strm->flags & AE_DATA_3BYTE)
         {
-            if (strm->bit_per_sample == 24
-                && strm->flags & AE_DATA_3BYTE)
+            state->block_len = 3 * strm->block_size;
+            if (strm->flags & AE_DATA_MSB)
             {
                 state->get_sample = get_msb_24;
                 state->get_block = get_block_funcs_msb_24[bsi];
             }
             else
             {
-                state->get_sample = get_msb_32;
-                state->get_block = get_block_funcs_msb_32[bsi];
+                state->get_sample = get_lsb_24;
+                state->get_block = get_block_funcs_lsb_24[bsi];
             }
         }
         else
         {
-            if (strm->bit_per_sample == 24
-                && strm->flags & AE_DATA_3BYTE)
+            state->block_len = 4 * strm->block_size;
+            if (strm->flags & AE_DATA_MSB)
             {
-                state->get_sample = get_lsb_24;
-                state->get_block = get_block_funcs_lsb_24[bsi];
+                state->get_sample = get_msb_32;
+                state->get_block = get_block_funcs_msb_32[bsi];
             }
             else
             {
index 5256fc6..391c445 100644 (file)
@@ -218,10 +218,10 @@ uint32_t get_msb_32(ae_streamp strm)
         for (i = 0; i < strm->rsi; i++)                              \
             for (j = 0; j < BS; j++)                                 \
                 block[i * BS + j] =                                  \
-                    (uint32_t)strm->next_in[4 * (i * BS + j)]        \
-                    | ((uint32_t)strm->next_in[4 * (i * BS + j) + 1] \
+                    (uint32_t)strm->next_in[3 * (i * BS + j)]        \
+                    | ((uint32_t)strm->next_in[3 * (i * BS + j) + 1] \
                        << 8)                                         \
-                    | ((uint32_t)strm->next_in[4 * (i * BS + j) + 2] \
+                    | ((uint32_t)strm->next_in[3 * (i * BS + j) + 2] \
                        << 16);                                       \
                                                                      \
         strm->next_in += 3 * BS * strm->rsi;                         \
@@ -238,11 +238,11 @@ uint32_t get_msb_32(ae_streamp strm)
         for (i = 0; i < strm->rsi; i++)                              \
             for (j = 0; j < BS; j++)                                 \
                 block[i * BS + j] =                                  \
-                    ((uint32_t)strm->next_in[4 * (i * BS + j)]       \
+                    ((uint32_t)strm->next_in[3 * (i * BS + j)]       \
                        << 16)                                        \
-                    | ((uint32_t)strm->next_in[4 * (i * BS + j) + 1] \
+                    | ((uint32_t)strm->next_in[3 * (i * BS + j) + 1] \
                        << 8)                                         \
-                    | (uint32_t)strm->next_in[4 * (i * BS + j) + 2]; \
+                    | (uint32_t)strm->next_in[3 * (i * BS + j) + 2]; \
                                                                      \
         strm->next_in += 3 * BS * strm->rsi;                         \
         strm->total_in += 3 * BS * strm->rsi;                        \
index 81ae92b..474954e 100644 (file)
@@ -27,7 +27,7 @@ int main(int argc, char *argv[])
     strm.flags = AE_DATA_PREPROCESS;
     opterr = 0;
 
-    while ((c = getopt (argc, argv, "Mscb:B:J:R:")) != -1)
+    while ((c = getopt (argc, argv, "3Mscb:B:J:R:")) != -1)
         switch (c)
         {
         case 'b':
@@ -51,6 +51,9 @@ int main(int argc, char *argv[])
         case 'M':
             strm.flags |= AE_DATA_MSB;
             break;
+        case '3':
+            strm.flags |= AE_DATA_3BYTE;
+            break;
         case '?':
             if (optopt == 'b')
                 fprintf (stderr, "Option -%c requires an argument.\n", optopt);
@@ -75,6 +78,18 @@ int main(int argc, char *argv[])
         exit(-1);
     }
 
+    if (strm.bit_per_sample > 16)
+    {
+        if (strm.bit_per_sample <= 24 && strm.flags & AE_DATA_3BYTE)
+            chunk *= 3;
+        else
+            chunk *= 4;
+    }
+    else if (strm.bit_per_sample > 8)
+    {
+        chunk *= 2;
+    }
+
     in = (uint8_t *)malloc(chunk);
     out = (uint8_t *)malloc(chunk);
     if (in == NULL || out == NULL)
index 626516a..6927588 100644 (file)
@@ -27,7 +27,7 @@ int main(int argc, char *argv[])
     strm.flags = AE_DATA_PREPROCESS;
     opterr = 0;
 
-    while ((c = getopt (argc, argv, "Mscb:B:R:J:")) != -1)
+    while ((c = getopt (argc, argv, "3Mscb:B:R:J:")) != -1)
         switch (c)
         {
         case 'b':
@@ -51,6 +51,9 @@ int main(int argc, char *argv[])
         case 'M':
             strm.flags |= AE_DATA_MSB;
             break;
+        case '3':
+            strm.flags |= AE_DATA_3BYTE;
+            break;
         case '?':
             if (optopt == 'b')
                 fprintf (stderr, "Option -%c requires an argument.\n", optopt);
@@ -75,6 +78,18 @@ int main(int argc, char *argv[])
         exit(-1);
     }
 
+    if (strm.bit_per_sample > 16)
+    {
+        if (strm.bit_per_sample <= 24 && strm.flags & AE_DATA_3BYTE)
+            chunk *= 3;
+        else
+            chunk *= 4;
+    }
+    else if (strm.bit_per_sample > 8)
+    {
+        chunk *= 2;
+    }
+
     out = (uint8_t *)malloc(chunk);
     in = (uint8_t *)malloc(chunk);