summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/libmad/huffman.c53
-rw-r--r--src/libmad/huffman.h4
2 files changed, 51 insertions, 6 deletions
diff --git a/src/libmad/huffman.c b/src/libmad/huffman.c
index 17ffa825e..602003e80 100644
--- a/src/libmad/huffman.c
+++ b/src/libmad/huffman.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: huffman.c,v 1.1 2001/08/12 02:57:55 guenter Exp $
+ * $Id: huffman.c,v 1.2 2001/10/03 15:12:09 jkeil Exp $
*/
# ifdef HAVE_CONFIG_H
@@ -28,14 +28,42 @@
# include "huffman.h"
/*
+ * Allocation order of bitfield structure members
+ */
+#if WORDS_BIGENDIAN
+#define BIT_FIELDS_HTOL 1 /* high bits allocated first */
+#else
+#define BIT_FIELDS_HTOL 0 /* low bits allocated first */
+#endif
+#define BIT_FIELDS_LTOH (!BIT_FIELDS_HTOL)
+
+
+/*
* These are the Huffman code words for Layer III.
* The data for these tables are derived from Table B.7 of ISO/IEC 11172-3.
*
* These tables support decoding up to 4 Huffman code bits at a time.
*/
-# define V(v, w, x, y, hlen) { { 1, hlen, v, w, x, y } }
-# define PTR(offs, bits) { ptr: { 0, bits, offs } }
+#if ISO_C99 /* initialize union variants ... with ISO C99 */
+# define V(v, w, x, y, hlen) { .value = { 1, hlen, v, w, x, y } }
+# define PTR(offs, bits) { .ptr = { 0, bits, offs } }
+#elif __GNUC__ /* ... using a GNU C compiler extension */
+# define V(v, w, x, y, hlen) { value: { 1, hlen, v, w, x, y } }
+# define PTR(offs, bits) { ptr: { 0, bits, offs } }
+#else /* ... hack for non-iso-c99/non-gnu compilers */
+# if BIT_FIELDS_LTOH
+# define V(v, w, x, y, hlen) { 1 | ((hlen)&7) << 1 | \
+ ((v)&1) << 4 | ((w)&1) << 5 | \
+ ((x)&1) << 6 | ((y)&1) << 7 }
+# define PTR(offs, bits) { 0 | ((bits)&7) << 1 | ((offs)&0xfff) << 4 }
+# else
+# define V(v, w, x, y, hlen) { 0x8000 | ((hlen)&7) << 12 | \
+ ((v)&1) << 11 | ((w)&1) << 10 | \
+ ((x)&1) << 9 | ((y)&1) << 8 }
+# define PTR(offs, bits) { 0x0000 | ((bits)&7) << 12 | ((offs)&0xfff) }
+# endif
+#endif
static
union huffquad const hufftabA[] = {
@@ -100,8 +128,23 @@ union huffquad const hufftabB[] = {
# undef V
# undef PTR
-# define V(x, y, hlen) { { 1, hlen, x, y } }
-# define PTR(offs, bits) { ptr: { 0, bits, offs } }
+#if ISO_C99 /* initialize union variants ... with ISO C99 */
+# define V(x, y, hlen) { .value = { 1, hlen, x, y } }
+# define PTR(offs, bits) { .ptr = { 0, bits, offs } }
+#elif __GNUC__ /* ... using a GNU C compiler extension */
+# define V(x, y, hlen) { value: { 1, hlen, x, y } }
+# define PTR(offs, bits) { ptr: { 0, bits, offs } }
+#else /* ... hack for non-iso-c99/non-gnu compilers */
+# if BIT_FIELDS_LTOH
+# define V(x, y, hlen) { 1 | ((hlen)&7) << 1 | \
+ ((x)&15) << 4 | ((y)&15) << 8 }
+# define PTR(offs, bits) { 0 | ((bits)&7) << 1 | ((offs)&0xfff) << 4 }
+# else
+# define V(x, y, hlen) { 0x8000 | ((hlen)&7) << 12 | \
+ ((x)&15) << 8 | ((y)&15) << 4 }
+# define PTR(offs, bits) { 0x0000 | ((bits)&7) << 12 | ((offs)&0xfff) }
+# endif
+#endif
static
union huffpair const hufftab0[] = {
diff --git a/src/libmad/huffman.h b/src/libmad/huffman.h
index 82cf670e5..198f2f3cb 100644
--- a/src/libmad/huffman.h
+++ b/src/libmad/huffman.h
@@ -16,13 +16,14 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
- * $Id: huffman.h,v 1.1 2001/08/12 02:57:55 guenter Exp $
+ * $Id: huffman.h,v 1.2 2001/10/03 15:12:09 jkeil Exp $
*/
# ifndef LIBMAD_HUFFMAN_H
# define LIBMAD_HUFFMAN_H
union huffquad {
+ unsigned short _; /* helper for non-gcc union initialization */
struct {
unsigned short final : 1;
unsigned short hlen : 3;
@@ -40,6 +41,7 @@ union huffquad {
};
union huffpair {
+ unsigned short _; /* helper for non-gcc union initialization */
struct {
unsigned short final : 1;
unsigned short hlen : 3;