changeset 6768:e14c77547f93 libavcodec

Rewrite unpack_input() completely, patch by Vitor Sessak, vitor1001 gmail com.
author diego
date Sat, 10 May 2008 16:02:38 +0000
parents f95c5091b802
children c834f8d9e854
files ra144.c
diffstat 1 files changed, 17 insertions(+), 45 deletions(-) [+]
line wrap: on
line diff
--- a/ra144.c	Sat May 10 15:59:08 2008 +0000
+++ b/ra144.c	Sat May 10 16:02:38 2008 +0000
@@ -20,6 +20,7 @@
  */
 
 #include "avcodec.h"
+#include "bitstream.h"
 #include "ra144.h"
 
 #define DATABLOCK1      20      /* size of 14.4 input block in bytes */
@@ -293,54 +294,25 @@
 /* Decode 20-byte input */
 static void unpack_input(const unsigned char *input, unsigned int *output)
 {
-    unsigned int outbuffer[28];
-    unsigned short inbuffer[10];
-    unsigned int x;
-    unsigned int *ptr;
+    int i;
+    static const uint8_t sizes[10] = {6, 5, 5, 4, 4, 3, 3, 3, 3, 2};
+
+    GetBitContext gb;
 
-    /* fix endianness */
-    for (x=0; x<20; x+=2)
-        inbuffer[x/2] = (input[x] << 8) + input[x+1];
+    init_get_bits(&gb, input, 20 * 8);
+
+    for (i=0; i<10; i++)
+       output[i+1] = get_bits(&gb, sizes[i]);
 
-    /* unpack */
-    ptr=outbuffer;
-    *(ptr++) = 27;
-    *(ptr++) = (inbuffer[0] >> 10) & 0x3f;
-    *(ptr++) = (inbuffer[0] >>  5) & 0x1f;
-    *(ptr++) = inbuffer[0] & 0x1f;
-    *(ptr++) = (inbuffer[1] >> 12) & 0xf;
-    *(ptr++) = (inbuffer[1] >>  8) & 0xf;
-    *(ptr++) = (inbuffer[1] >>  5) & 7;
-    *(ptr++) = (inbuffer[1] >>  2) & 7;
-    *(ptr++) = ((inbuffer[1] << 1) & 6) | ((inbuffer[2] >> 15) & 1);
-    *(ptr++) = (inbuffer[2] >> 12) & 7;
-    *(ptr++) = (inbuffer[2] >> 10) & 3;
-    *(ptr++) = (inbuffer[2] >>  5) & 0x1f;
-    *(ptr++) = ((inbuffer[2] << 2) & 0x7c) | ((inbuffer[3] >> 14) & 3);
-    *(ptr++) = (inbuffer[3] >> 6) & 0xff;
-    *(ptr++) = ((inbuffer[3] << 1) & 0x7e) | ((inbuffer[4] >> 15) & 1);
-    *(ptr++) = (inbuffer[4] >> 8) & 0x7f;
-    *(ptr++) = (inbuffer[4] >> 1) & 0x7f;
-    *(ptr++) = ((inbuffer[4] << 7) & 0x80) | ((inbuffer[5] >> 9) & 0x7f);
-    *(ptr++) = (inbuffer[5] >> 2) & 0x7f;
-    *(ptr++) = ((inbuffer[5] << 5) & 0x60) | ((inbuffer[6] >> 11) & 0x1f);
-    *(ptr++) = (inbuffer[6] >> 4) & 0x7f;
-    *(ptr++) = ((inbuffer[6] << 4) & 0xf0) | ((inbuffer[7] >> 12) & 0xf);
-    *(ptr++) = (inbuffer[7] >> 5) & 0x7f;
-    *(ptr++) = ((inbuffer[7] << 2) & 0x7c) | ((inbuffer[8] >> 14) & 3);
-    *(ptr++) = (inbuffer[8] >> 7) & 0x7f;
-    *(ptr++) = ((inbuffer[8] << 1) & 0xfe) | ((inbuffer[9] >> 15) & 1);
-    *(ptr++) = (inbuffer[9] >> 8) & 0x7f;
-    *(ptr++) = (inbuffer[9] >> 1) & 0x7f;
+    output[0] = get_bits(&gb, 5);
 
-    *(output++) = outbuffer[11];
-    for (x=1; x<11; *(output++) = outbuffer[x++]);
-    ptr = outbuffer+12;
-    for (x=0; x<16; x+=4) {
-        *(output++) = ptr[x];
-        *(output++) = ptr[x+2];
-        *(output++) = ptr[x+3];
-        *(output++) = ptr[x+1];
+    output += 11;
+    for (i=0; i<4; i++) {
+        output[0] = get_bits(&gb, 7);
+        output[3] = get_bits(&gb, 8);
+        output[1] = get_bits(&gb, 7);
+        output[2] = get_bits(&gb, 7);
+        output += 4;
     }
 }