aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Niedermayer <michael@niedermayer.cc>2024-10-15 22:39:58 +0200
committerMichael Niedermayer <michael@niedermayer.cc>2024-10-16 21:41:19 +0200
commit81a360a5ed9e7dcc841e791c2779f09cbd99b5d3 (patch)
tree31901c761f0602fc655d09614e85daa2e52425c1
parent2542e9296c76524494a2d17a4423d756560b5273 (diff)
downloadffmpeg-81a360a5ed9e7dcc841e791c2779f09cbd99b5d3.tar.gz
avcodec/ffv1: add a named constant for the quant table size
Sponsored-by: Sovereign Tech Fund Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
-rw-r--r--libavcodec/ffv1.h4
-rw-r--r--libavcodec/ffv1_template.c18
-rw-r--r--libavcodec/ffv1enc.c6
3 files changed, 15 insertions, 13 deletions
diff --git a/libavcodec/ffv1.h b/libavcodec/ffv1.h
index b98f0b3685..da841cf655 100644
--- a/libavcodec/ffv1.h
+++ b/libavcodec/ffv1.h
@@ -44,6 +44,8 @@
#define CONTEXT_SIZE 32
#define MAX_QUANT_TABLES 8
+#define MAX_QUANT_TABLE_SIZE 256
+#define MAX_QUANT_TABLE_MASK (MAX_QUANT_TABLE_SIZE - 1)
#define MAX_CONTEXT_INPUTS 5
#define AC_GOLOMB_RICE 0
@@ -124,7 +126,7 @@ typedef struct FFV1Context {
const AVFrame *cur_enc_frame;
int plane_count;
int ac; ///< 1=range coder <-> 0=golomb rice
- int16_t quant_tables[MAX_QUANT_TABLES][MAX_CONTEXT_INPUTS][256];
+ int16_t quant_tables[MAX_QUANT_TABLES][MAX_CONTEXT_INPUTS][MAX_QUANT_TABLE_SIZE];
int context_count[MAX_QUANT_TABLES];
uint8_t state_transition[256];
uint8_t (*initial_states[MAX_QUANT_TABLES])[32];
diff --git a/libavcodec/ffv1_template.c b/libavcodec/ffv1_template.c
index d15ad11021..abb90a12e4 100644
--- a/libavcodec/ffv1_template.c
+++ b/libavcodec/ffv1_template.c
@@ -29,7 +29,7 @@ static inline int RENAME(predict)(TYPE *src, TYPE *last)
return mid_pred(L, L + T - LT, T);
}
-static inline int RENAME(get_context)(const int16_t quant_table[MAX_CONTEXT_INPUTS][256],
+static inline int RENAME(get_context)(const int16_t quant_table[MAX_CONTEXT_INPUTS][MAX_QUANT_TABLE_SIZE],
TYPE *src, TYPE *last, TYPE *last2)
{
const int LT = last[-1];
@@ -40,14 +40,14 @@ static inline int RENAME(get_context)(const int16_t quant_table[MAX_CONTEXT_INPU
if (quant_table[3][127] || quant_table[4][127]) {
const int TT = last2[0];
const int LL = src[-2];
- return quant_table[0][(L - LT) & 0xFF] +
- quant_table[1][(LT - T) & 0xFF] +
- quant_table[2][(T - RT) & 0xFF] +
- quant_table[3][(LL - L) & 0xFF] +
- quant_table[4][(TT - T) & 0xFF];
+ return quant_table[0][(L - LT) & MAX_QUANT_TABLE_MASK] +
+ quant_table[1][(LT - T) & MAX_QUANT_TABLE_MASK] +
+ quant_table[2][(T - RT) & MAX_QUANT_TABLE_MASK] +
+ quant_table[3][(LL - L) & MAX_QUANT_TABLE_MASK] +
+ quant_table[4][(TT - T) & MAX_QUANT_TABLE_MASK];
} else
- return quant_table[0][(L - LT) & 0xFF] +
- quant_table[1][(LT - T) & 0xFF] +
- quant_table[2][(T - RT) & 0xFF];
+ return quant_table[0][(L - LT) & MAX_QUANT_TABLE_MASK] +
+ quant_table[1][(LT - T) & MAX_QUANT_TABLE_MASK] +
+ quant_table[2][(T - RT) & MAX_QUANT_TABLE_MASK];
}
diff --git a/libavcodec/ffv1enc.c b/libavcodec/ffv1enc.c
index bd64a46791..74d7e6c850 100644
--- a/libavcodec/ffv1enc.c
+++ b/libavcodec/ffv1enc.c
@@ -317,7 +317,7 @@ static void write_quant_table(RangeCoder *c, int16_t *quant_table)
uint8_t state[CONTEXT_SIZE];
memset(state, 128, sizeof(state));
- for (i = 1; i < 128; i++)
+ for (i = 1; i < MAX_QUANT_TABLE_SIZE/2; i++)
if (quant_table[i] != quant_table[i - 1]) {
put_symbol(c, state, i - last - 1, 0);
last = i;
@@ -326,7 +326,7 @@ static void write_quant_table(RangeCoder *c, int16_t *quant_table)
}
static void write_quant_tables(RangeCoder *c,
- int16_t quant_table[MAX_CONTEXT_INPUTS][256])
+ int16_t quant_table[MAX_CONTEXT_INPUTS][MAX_QUANT_TABLE_SIZE])
{
int i;
for (i = 0; i < 5; i++)
@@ -726,7 +726,7 @@ static av_cold int encode_init(AVCodecContext *avctx)
s->state_transition[i] = c.one_state[i];
}
- for (i = 0; i < 256; i++) {
+ for (i = 0; i < MAX_QUANT_TABLE_SIZE; i++) {
s->quant_table_count = 2;
if (s->bits_per_raw_sample <= 8) {
s->quant_tables[0][0][i]= quant11[i];