ref: 84bff2c915145927daac490b6c93bb83ebd3b530
parent: ab56ea59d3a49486c15200f1db08a3d50b1df964
author: menno <menno>
date: Sat Sep 28 10:03:07 EDT 2002
reverse bitreading functions showbits_rev and flushbits_rev are tested, but initbits_rev is still untested
--- a/libfaad/bits.c
+++ b/libfaad/bits.c
@@ -16,7 +16,7 @@
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
-** $Id: bits.c,v 1.9 2002/09/26 19:01:45 menno Exp $
+** $Id: bits.c,v 1.10 2002/09/28 14:03:07 menno Exp $
**/
#include "common.h"
@@ -86,4 +86,33 @@
}
return buffer;
+}
+
+/* reversed bit reading routines, used for
+ RVLC, HCR and SBR in DRM
+*/
+void faad_initbits_rev(bitfile *ld, void *buffer,
+ uint32_t bits_in_buffer)
+{
+ uint32_t tmp, index;
+
+ index = (bits_in_buffer+31)/32;
+
+ ld->start = (uint32_t*)buffer + index - 2;
+
+ tmp = *((uint32_t*)buffer + index);
+#ifdef ARCH_IS_BIG_ENDIAN
+ BSWAP(tmp);
+#endif
+ ld->bufa = tmp;
+
+ tmp = *((uint32_t*)buffer + index - 1);
+#ifdef ARCH_IS_BIG_ENDIAN
+ BSWAP(tmp);
+#endif
+ ld->bufb = tmp;
+
+ ld->tail = (uint32_t*)buffer + index;
+
+ ld->bits_left = bits_in_buffer % 32;
}
--- a/libfaad/bits.h
+++ b/libfaad/bits.h
@@ -16,7 +16,7 @@
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
-** $Id: bits.h,v 1.8 2002/09/26 19:01:45 menno Exp $
+** $Id: bits.h,v 1.9 2002/09/28 14:03:07 menno Exp $
**/
#ifndef __BITS_H__
@@ -121,6 +121,73 @@
{
return (uint8_t)faad_getbits(ld, 1 DEBUGVAR(print,var,dbg));
}
+
+/* reversed bitreading routines */
+static INLINE uint32_t faad_showbits_rev(bitfile *ld, uint32_t bits)
+{
+ uint8_t i;
+ uint32_t B = 0;
+
+ if (bits <= ld->bits_left)
+ {
+ for (i = 0; i < bits; i++)
+ {
+ if (ld->bufa & (1 << (i + (32 - ld->bits_left))))
+ B |= (1 << (bits - i - 1));
+ }
+ return B;
+ } else {
+ for (i = 0; i < ld->bits_left; i++)
+ {
+ if (ld->bufa & (1 << (i + (32 - ld->bits_left))))
+ B |= (1 << (bits - i - 1));
+ }
+ for (i = 0; i < bits - ld->bits_left; i++)
+ {
+ if (ld->bufb & (1 << (i + (32-ld->bits_left))))
+ B |= (1 << (bits - ld->bits_left - i - 1));
+ }
+ }
+}
+
+static INLINE void faad_flushbits_rev(bitfile *ld, uint32_t bits)
+{
+ if (bits < ld->bits_left)
+ {
+ ld->bits_left -= bits;
+ } else {
+ uint32_t tmp;
+
+ ld->bufa = ld->bufb;
+ tmp = *(uint32_t*)ld->start;
+#ifdef ARCH_IS_BIG_ENDIAN
+ BSWAP(tmp);
+#endif
+ ld->bufb = tmp;
+ ld->start--;
+ ld->bits_left += (32 - bits);
+ }
+}
+
+static INLINE uint32_t faad_getbits_rev(bitfile *ld, uint32_t n
+ DEBUGDEC)
+{
+ uint32_t ret;
+
+ if (n == 0)
+ return 0;
+
+ ret = faad_showbits_rev(ld, n);
+ faad_flushbits_rev(ld, n);
+
+#ifdef ANALYSIS
+ if (print)
+ fprintf(stdout, "%4d %2d bits, val: %4d, variable: %d %s\n", dbg_count++, n, ret, var, dbg);
+#endif
+
+ return ret;
+}
+
#ifdef __cplusplus
}