# HG changeset patch # User vitor # Date 1214851005 0 # Node ID 9176fe6f17c9a232ace64175608f15abbd323d96 # Parent 04da42c2b7b478b286cf50e7437be31b44c7fce8 Rewrite unpack() using the bitstream reader diff -r 04da42c2b7b4 -r 9176fe6f17c9 ra288.c --- a/ra288.c Mon Jun 30 18:03:38 2008 +0000 +++ b/ra288.c Mon Jun 30 18:36:45 2008 +0000 @@ -20,6 +20,8 @@ */ #include "avcodec.h" +#define ALT_BITSTREAM_READER_LE +#include "bitstream.h" #include "ra288.h" typedef struct { @@ -39,28 +41,15 @@ static void unpack(unsigned short *tgt, const unsigned char *src, unsigned int len) { - int x, y, z; - int n, temp; - int buffer[len]; + int i = 0; + GetBitContext gb; - for (x=0; x < len; tgt[x++] = 0) - buffer[x] = 9 + (x & 1); - - for (x=y=z=0; x < len/*was 38*/; x++) { - n = buffer[y] - z; - temp = src[x]; + init_get_bits(&gb, src, len * 8); - if (n < 8) - temp &= 255 >> (8 - n); - - tgt[y] += temp << z; - - if (n <= 8) { - tgt[++y] += src[x] >> n; - z = 8 - n; - } else - z += 8; - } + while (get_bits_count(&gb) + 9 + (i&1) <= len*8) { + tgt[i] = get_bits(&gb, 9 + (i&1)); + i++; + } } /* Decode and produce output */