summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEmeric Grange <emeric.grange@gmail.com>2012-01-14 18:29:02 +0100
committerEmeric Grange <emeric.grange@gmail.com>2012-06-24 16:57:32 +0200
commit6990b42fc197aaa83ffb7bf5a7e21db97c5487c4 (patch)
treef16376a30fdf86429e773cb4adc7c056b083beaa
parent582ecc28cf0d98845e458c138a5df25141c2967c (diff)
g3dvl: Merge treereader and dboolhuff
Signed-off-by: Emeric Grange <emeric.grange@gmail.com>
-rw-r--r--src/gallium/auxiliary/Makefile.sources4
-rw-r--r--src/gallium/auxiliary/vl/vp8/common/alloccommon.c2
-rw-r--r--src/gallium/auxiliary/vl/vp8/common/entropy.c21
-rw-r--r--src/gallium/auxiliary/vl/vp8/common/entropy.h4
-rw-r--r--src/gallium/auxiliary/vl/vp8/common/treecoder.c9
-rw-r--r--src/gallium/auxiliary/vl/vp8/common/treecoder.h8
-rw-r--r--src/gallium/auxiliary/vl/vp8/decoder/dboolhuff.c73
-rw-r--r--src/gallium/auxiliary/vl/vp8/decoder/dboolhuff.h137
-rw-r--r--src/gallium/auxiliary/vl/vp8/decoder/decodeframe.c5
-rw-r--r--src/gallium/auxiliary/vl/vp8/decoder/treereader.h76
10 files changed, 92 insertions, 247 deletions
diff --git a/src/gallium/auxiliary/Makefile.sources b/src/gallium/auxiliary/Makefile.sources
index 0e13226e2d..a06cd13a93 100644
--- a/src/gallium/auxiliary/Makefile.sources
+++ b/src/gallium/auxiliary/Makefile.sources
@@ -170,13 +170,13 @@ C_SOURCES := \
vl/vp8/common/reconintra4x4.c \
vl/vp8/common/treecoder.c \
vl/vp8/common/yv12utils.c \
- vl/vp8/decoder/dboolhuff.c \
vl/vp8/decoder/decodeframe.c \
vl/vp8/decoder/decodemv.c \
vl/vp8/decoder/dequantize.c \
vl/vp8/decoder/detokenize.c \
vl/vp8/decoder/idct_blk.c \
- vl/vp8/decoder/onyxd_if.c
+ vl/vp8/decoder/onyxd_if.c \
+ vl/vp8/decoder/treereader.c
GENERATED_SOURCES := \
indices/u_indices_gen.c \
diff --git a/src/gallium/auxiliary/vl/vp8/common/alloccommon.c b/src/gallium/auxiliary/vl/vp8/common/alloccommon.c
index 0190cbd871..183806605e 100644
--- a/src/gallium/auxiliary/vl/vp8/common/alloccommon.c
+++ b/src/gallium/auxiliary/vl/vp8/common/alloccommon.c
@@ -16,7 +16,7 @@
#include "findnearmv.h"
#include "entropymode.h"
-extern void vp8_init_scan_order_mask();
+//extern void vp8_init_scan_order_mask();
static void update_mode_info_border(MODE_INFO *mi, int rows, int cols)
{
diff --git a/src/gallium/auxiliary/vl/vp8/common/entropy.c b/src/gallium/auxiliary/vl/vp8/common/entropy.c
index 598e680626..38d0b9f5bb 100644
--- a/src/gallium/auxiliary/vl/vp8/common/entropy.c
+++ b/src/gallium/auxiliary/vl/vp8/common/entropy.c
@@ -99,7 +99,6 @@ static vp8_tree_index cat1[2], cat2[4], cat3[6], cat4[8], cat5[10], cat6[22];
void vp8_init_scan_order_mask()
{
int i;
-
for (i = 0; i < 16; i++)
{
vp8_default_zig_zag_mask[vp8_default_zig_zag1d[i]] = 1 << i;
@@ -109,7 +108,6 @@ void vp8_init_scan_order_mask()
static void init_bit_tree(vp8_tree_index *p, int n)
{
int i = 0;
-
while (++i < n)
{
p[0] = p[1] = i << 1;
@@ -132,24 +130,23 @@ static void init_bit_trees()
void vp8_default_coef_probs(VP8_COMMON *pc)
{
int h = 0;
-
do
{
int i = 0;
-
do
{
int k = 0;
-
do
{
- unsigned int branch_ct [ENTROPY_NODES] [2];
- vp8_tree_probs_from_distribution(
- MAX_ENTROPY_TOKENS, vp8_coef_encodings, vp8_coef_tree,
- pc->fc.coef_probs[h][i][k],
- branch_ct,
- vp8_default_coef_counts[h][i][k],
- 256, 1);
+ unsigned int branch_ct[ENTROPY_NODES][2];
+ vp8_tree_probs_from_distribution(MAX_ENTROPY_TOKENS,
+ vp8_coef_encodings,
+ vp8_coef_tree,
+ pc->fc.coef_probs[h][i][k],
+ branch_ct,
+ vp8_default_coef_counts[h][i][k],
+ 256,
+ 1);
}
while (++k < PREV_COEF_CONTEXTS);
}
diff --git a/src/gallium/auxiliary/vl/vp8/common/entropy.h b/src/gallium/auxiliary/vl/vp8/common/entropy.h
index bbcea51c5a..d0c885fcbb 100644
--- a/src/gallium/auxiliary/vl/vp8/common/entropy.h
+++ b/src/gallium/auxiliary/vl/vp8/common/entropy.h
@@ -79,6 +79,8 @@ extern DECLARE_ALIGNED(16, const short, vp8_default_inv_zig_zag[16]);
extern short vp8_default_zig_zag_mask[16];
extern const int vp8_mb_feature_data_bits[MB_LVL_MAX];
-void vp8_coef_tree_initialize(void);
+void vp8_init_scan_order_mask();
+void vp8_default_coef_probs(struct VP8Common *);
+void vp8_coef_tree_initialize();
#endif /* ENTROPY_H */
diff --git a/src/gallium/auxiliary/vl/vp8/common/treecoder.c b/src/gallium/auxiliary/vl/vp8/common/treecoder.c
index 1e5efc24c9..5bec16612e 100644
--- a/src/gallium/auxiliary/vl/vp8/common/treecoder.c
+++ b/src/gallium/auxiliary/vl/vp8/common/treecoder.c
@@ -36,6 +36,9 @@ static void tree2tok(struct vp8_token_struct *const p, vp8_tree t, int i, int v,
while (++v & 1);
}
+/**
+ * Construct encoding array from tree.
+ */
void vp8_tokens_from_tree(struct vp8_token_struct *p, vp8_tree t)
{
tree2tok(p, t, 0, 0, 0);
@@ -94,6 +97,12 @@ static void branch_counts(int n, /* n = size of alphabet */
while (++t < n);
}
+/**
+ * Convert array of token occurrence counts into a table of probabilities
+ * for the associated binary encoding tree. Also writes count of branches
+ * taken for each node on the tree; this facilitiates decisions as to
+ * probability updates.
+ */
void vp8_tree_probs_from_distribution(int n, /* n = size of alphabet */
vp8_token tok[ /* n */ ],
vp8_tree tree,
diff --git a/src/gallium/auxiliary/vl/vp8/common/treecoder.h b/src/gallium/auxiliary/vl/vp8/common/treecoder.h
index 58cb4f4582..fb272734e0 100644
--- a/src/gallium/auxiliary/vl/vp8/common/treecoder.h
+++ b/src/gallium/auxiliary/vl/vp8/common/treecoder.h
@@ -33,18 +33,10 @@ typedef const struct vp8_token_struct
int Len;
} vp8_token;
-/* Construct encoding array from tree. */
-
void vp8_tokens_from_tree(struct vp8_token_struct *, vp8_tree);
void vp8_tokens_from_tree_offset(struct vp8_token_struct *, vp8_tree, int offset);
-/**
- * Convert array of token occurrence counts into a table of probabilities
- * for the associated binary encoding tree. Also writes count of branches
- * taken for each node on the tree; this facilitiates decisions as to
- * probability updates.
- */
void vp8_tree_probs_from_distribution(int n, /* n = size of alphabet */
vp8_token tok[/* n */],
vp8_tree tree,
diff --git a/src/gallium/auxiliary/vl/vp8/decoder/dboolhuff.c b/src/gallium/auxiliary/vl/vp8/decoder/dboolhuff.c
deleted file mode 100644
index f801d9e3f9..0000000000
--- a/src/gallium/auxiliary/vl/vp8/decoder/dboolhuff.c
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * Copyright (c) 2010 The WebM project authors. All Rights Reserved.
- *
- * Use of this source code is governed by a BSD-style license
- * that can be found in the LICENSE file in the root of the source
- * tree. An additional intellectual property rights grant can be found
- * in the file PATENTS. All contributing project authors may
- * be found in the AUTHORS file in the root of the source tree.
- */
-
-
-#include "dboolhuff.h"
-
-int vp8dx_start_decode(BOOL_DECODER *bd,
- const unsigned char *data,
- unsigned int data_size)
-{
- bd->user_buffer_end = data + data_size;
- bd->user_buffer = data;
- bd->value = 0;
- bd->count = -8;
- bd->range = 255;
-
- if (data_size && !data)
- return 1;
-
- /* Populate the buffer */
- vp8dx_bool_decoder_fill(bd);
-
- return 0;
-}
-
-void vp8dx_bool_decoder_fill(BOOL_DECODER *bd)
-{
- const unsigned char *bufptr;
- const unsigned char *bufend;
- VP8_BD_VALUE value;
- int count;
- bufend = bd->user_buffer_end;
- bufptr = bd->user_buffer;
- value = bd->value;
- count = bd->count;
-
- VP8DX_BOOL_DECODER_FILL(count, value, bufptr, bufend);
-
- bd->user_buffer = bufptr;
- bd->value = value;
- bd->count = count;
-}
-
-/**
- * Check if we have reached the end of the buffer.
- *
- * Variable 'count' stores the number of bits in the 'value' buffer, minus
- * 8. The top byte is part of the algorithm, and the remainder is buffered
- * to be shifted into it. So if count == 8, the top 16 bits of 'value' are
- * occupied, 8 for the algorithm and 8 in the buffer.
- *
- * When reading a byte from the user's buffer, count is filled with 8 and
- * one byte is filled into the value buffer. When we reach the end of the
- * data, count is additionally filled with VP8_LOTS_OF_BITS. So when
- * count == VP8_LOTS_OF_BITS - 1, the user's data has been exhausted.
- */
-int vp8dx_bool_error(BOOL_DECODER *bd)
-{
- if ((bd->count > VP8_BD_VALUE_SIZE) && (bd->count < VP8_LOTS_OF_BITS))
- {
- /* We have tried to decode bits after the end of stream was encountered. */
- return 1;
- }
-
- return 0;
-}
diff --git a/src/gallium/auxiliary/vl/vp8/decoder/dboolhuff.h b/src/gallium/auxiliary/vl/vp8/decoder/dboolhuff.h
deleted file mode 100644
index 9329e2983d..0000000000
--- a/src/gallium/auxiliary/vl/vp8/decoder/dboolhuff.h
+++ /dev/null
@@ -1,137 +0,0 @@
-/*
- * Copyright (c) 2010 The WebM project authors. All Rights Reserved.
- *
- * Use of this source code is governed by a BSD-style license
- * that can be found in the LICENSE file in the root of the source
- * tree. An additional intellectual property rights grant can be found
- * in the file PATENTS. All contributing project authors may
- * be found in the AUTHORS file in the root of the source tree.
- */
-
-
-#ifndef DBOOLHUFF_H
-#define DBOOLHUFF_H
-
-#include <stddef.h>
-#include <limits.h>
-
-#include "../vp8_mem.h"
-
-typedef size_t VP8_BD_VALUE;
-
-#define VP8_BD_VALUE_SIZE ((int)sizeof(VP8_BD_VALUE)*CHAR_BIT)
-
-/**
- * This is meant to be a large, positive constant that can still be efficiently
- * loaded as an immediate (on platforms like ARM, for example).
- * Even relatively modest values like 100 would work fine.
- */
-#define VP8_LOTS_OF_BITS (0x40000000)
-
-typedef struct
-{
- const unsigned char *user_buffer_end;
- const unsigned char *user_buffer;
- VP8_BD_VALUE value;
- int count;
- unsigned int range;
-} BOOL_DECODER;
-
-DECLARE_ALIGNED(16, extern const unsigned char, vp8_norm[256]);
-
-int vp8dx_start_decode(BOOL_DECODER *bd,
- const unsigned char *data,
- unsigned int data_size);
-
-void vp8dx_bool_decoder_fill(BOOL_DECODER *bd);
-
-int vp8dx_bool_error(BOOL_DECODER *bd);
-
-/**
- * The refill loop is used in several places, so define it in a macro to make
- * sure they're all consistent.
- * An inline function would be cleaner, but has a significant penalty, because
- * multiple BOOL_DECODER fields must be modified, and the compiler is not smart
- * enough to eliminate the stores to those fields and the subsequent reloads
- * from them when inlining the function.
- */
-#define VP8DX_BOOL_DECODER_FILL(_count,_value,_bufptr,_bufend) \
- do \
- { \
- int shift = VP8_BD_VALUE_SIZE - 8 - ((_count) + 8); \
- int loop_end, x; \
- size_t bits_left = ((_bufend)-(_bufptr))*CHAR_BIT; \
- \
- x = shift + CHAR_BIT - bits_left; \
- loop_end = 0; \
- if (x >= 0) \
- { \
- (_count) += VP8_LOTS_OF_BITS; \
- loop_end = x; \
- if (!bits_left) break; \
- } \
- while (shift >= loop_end) \
- { \
- (_count) += CHAR_BIT; \
- (_value) |= (VP8_BD_VALUE)*(_bufptr)++ << shift; \
- shift -= CHAR_BIT; \
- } \
- } \
- while(0)
-
-static int vp8dx_decode_bool(BOOL_DECODER *bd, int probability)
-{
- unsigned int bit = 0;
- VP8_BD_VALUE value;
- unsigned int split;
- VP8_BD_VALUE bigsplit;
- int count;
- unsigned int range;
-
- split = 1 + (((bd->range - 1) * probability) >> 8);
-
- if (bd->count < 0)
- vp8dx_bool_decoder_fill(bd);
-
- value = bd->value;
- count = bd->count;
-
- bigsplit = (VP8_BD_VALUE)split << (VP8_BD_VALUE_SIZE - 8);
-
- range = split;
-
- if (value >= bigsplit)
- {
- range = bd->range - split;
- value = value - bigsplit;
- bit = 1;
- }
-
- {
- register unsigned int shift = vp8_norm[range];
- range <<= shift;
- value <<= shift;
- count -= shift;
- }
-
- bd->value = value;
- bd->count = count;
- bd->range = range;
-
- return bit;
-}
-
-static int vp8_decode_value(BOOL_DECODER *bd, int bits)
-{
- int z = 0;
- int bit;
-
- for (bit = bits - 1; bit >= 0; bit--)
- {
- z |= (vp8dx_decode_bool(bd, 0x80) << bit);
- }
-
- return z;
-}
-
-#endif /* DBOOLHUFF_H */
diff --git a/src/gallium/auxiliary/vl/vp8/decoder/decodeframe.c b/src/gallium/auxiliary/vl/vp8/decoder/decodeframe.c
index e96f3c4c63..779711ec58 100644
--- a/src/gallium/auxiliary/vl/vp8/decoder/decodeframe.c
+++ b/src/gallium/auxiliary/vl/vp8/decoder/decodeframe.c
@@ -21,11 +21,12 @@
#include "../common/entropymode.h"
#include "../common/quant_common.h"
#include "../common/yv12utils.h"
+#include "../common/idct.h"
#include "decodemv.h"
+#include "treereader.h"
+
#include "../vp8_mem.h"
-#include "../common/idct.h"
-#include "dboolhuff.h"
#include <assert.h>
#include <stdio.h>
diff --git a/src/gallium/auxiliary/vl/vp8/decoder/treereader.h b/src/gallium/auxiliary/vl/vp8/decoder/treereader.h
index 3ca517f417..baf917bf75 100644
--- a/src/gallium/auxiliary/vl/vp8/decoder/treereader.h
+++ b/src/gallium/auxiliary/vl/vp8/decoder/treereader.h
@@ -9,26 +9,80 @@
*/
-#ifndef tree_reader_h
-#define tree_reader_h
+#ifndef TREEREADER_H
+#define TREEREADER_H
#include "../common/treecoder.h"
-#include "dboolhuff.h"
+#include "../vp8_mem.h"
#define vp8_read vp8dx_decode_bool
#define vp8_read_literal vp8_decode_value
#define vp8_read_bit( R) vp8_read( R, vp8_prob_half)
-/* Intent of tree data structure is to make decoding trivial. */
+/**
+ * This is meant to be a large, positive constant that can still be efficiently
+ * loaded as an immediate (on platforms like ARM, for example).
+ * Even relatively modest values like 100 would work fine.
+ */
+#define VP8_LOTS_OF_BITS (0x40000000)
+
+#define VP8_BD_VALUE_SIZE ((int)sizeof(VP8_BD_VALUE)*CHAR_BIT)
+
+typedef size_t VP8_BD_VALUE;
-/** must return a 0 or 1 !!! */
-static int vp8_treed_read(BOOL_DECODER *const bd, vp8_tree t, const vp8_prob *const p)
+typedef struct
{
- register vp8_tree_index i = 0;
+ const unsigned char *user_buffer_end;
+ const unsigned char *user_buffer;
+ VP8_BD_VALUE value;
+ int count;
+ unsigned int range;
+} BOOL_DECODER;
+
+DECLARE_ALIGNED(16, extern const unsigned char, vp8_norm[256]);
+
+int vp8dx_start_decode(BOOL_DECODER *bd, const unsigned char *data, unsigned int data_size);
- while ((i = t[i + vp8_read(bd, p[i >> 1])]) > 0);
+void vp8dx_bool_decoder_fill(BOOL_DECODER *bd);
- return -i;
-}
+int vp8dx_bool_error(BOOL_DECODER *bd);
+
+int vp8dx_decode_bool(BOOL_DECODER *bd, int probability);
+
+int vp8_decode_value(BOOL_DECODER *bd, int bits);
+
+int vp8_treed_read(BOOL_DECODER *const bd, vp8_tree t, const vp8_prob *const p);
+
+/**
+ * The refill loop is used in several places, so define it in a macro to make
+ * sure they're all consistent.
+ * An inline function would be cleaner, but has a significant penalty, because
+ * multiple BOOL_DECODER fields must be modified, and the compiler is not smart
+ * enough to eliminate the stores to those fields and the subsequent reloads
+ * from them when inlining the function.
+ */
+#define VP8DX_BOOL_DECODER_FILL(_count,_value,_bufptr,_bufend) \
+ do \
+ { \
+ int shift = VP8_BD_VALUE_SIZE - 8 - ((_count) + 8); \
+ int loop_end, x; \
+ size_t bits_left = ((_bufend)-(_bufptr))*CHAR_BIT; \
+ \
+ x = shift + CHAR_BIT - bits_left; \
+ loop_end = 0; \
+ if (x >= 0) \
+ { \
+ (_count) += VP8_LOTS_OF_BITS; \
+ loop_end = x; \
+ if (!bits_left) break; \
+ } \
+ while (shift >= loop_end) \
+ { \
+ (_count) += CHAR_BIT; \
+ (_value) |= (VP8_BD_VALUE)*(_bufptr)++ << shift; \
+ shift -= CHAR_BIT; \
+ } \
+ } \
+ while(0)
-#endif /* tree_reader_h */
+#endif /* TREEREADER_H */