History

lavc/ffv1: drop redundant PlaneContext.quant_table

It is a copy of FFV1Context.quant_tables[quant_table_index].

Anton Khirnov committed 2 years ago

Commit a411fc51 parent 4b9f7c76 files · +53 −50Browse files

Unified · Split

6 files
  1. libavcodec/ffv1.h +0 −1
  2. libavcodec/ffv1_template.c +11 −11
  3. libavcodec/ffv1dec.c +12 −16
  4. libavcodec/ffv1dec_template.c +10 −5
  5. libavcodec/ffv1enc.c +12 −12
  6. libavcodec/ffv1enc_template.c +8 −5
libavcodec/ffv1.h+0−1
@@ -59,7 +59,6 @@ typedef struct VlcState { · 58 unmodified lines
5959 } VlcState;
6060
6161 typedef struct PlaneContext {
62− int16_t quant_table[MAX_CONTEXT_INPUTS][256];
6362 int quant_table_index;
6463 int context_count;
6564 uint8_t (*state)[CONTEXT_SIZE];
libavcodec/ffv1_template.c+11−11
@@ -29,25 +29,25 @@ static inline int RENAME(predict)(TYPE *src, TYPE *last) · 28 unmodified lines
2929 return mid_pred(L, L + T - LT, T);
3030 }
3131
32−static inline int RENAME(get_context)(PlaneContext *p, TYPE *src,
33− TYPE *last, TYPE *last2)
32+static inline int RENAME(get_context)(const int16_t quant_table[MAX_CONTEXT_INPUTS][256],
33+ TYPE *src, TYPE *last, TYPE *last2)
3434 {
3535 const int LT = last[-1];
3636 const int T = last[0];
3737 const int RT = last[1];
3838 const int L = src[-1];
3939
40− if (p->quant_table[3][127] || p->quant_table[4][127]) {
40+ if (quant_table[3][127] || quant_table[4][127]) {
4141 const int TT = last2[0];
4242 const int LL = src[-2];
43− return p->quant_table[0][(L - LT) & 0xFF] +
44− p->quant_table[1][(LT - T) & 0xFF] +
45− p->quant_table[2][(T - RT) & 0xFF] +
46− p->quant_table[3][(LL - L) & 0xFF] +
47− p->quant_table[4][(TT - T) & 0xFF];
43+ return quant_table[0][(L - LT) & 0xFF] +
44+ quant_table[1][(LT - T) & 0xFF] +
45+ quant_table[2][(T - RT) & 0xFF] +
46+ quant_table[3][(LL - L) & 0xFF] +
47+ quant_table[4][(TT - T) & 0xFF];
4848 } else
49− return p->quant_table[0][(L - LT) & 0xFF] +
50− p->quant_table[1][(LT - T) & 0xFF] +
51− p->quant_table[2][(T - RT) & 0xFF];
49+ return quant_table[0][(L - LT) & 0xFF] +
50+ quant_table[1][(LT - T) & 0xFF] +
51+ quant_table[2][(T - RT) & 0xFF];
5252 }
5353
libavcodec/ffv1dec.c+12−16
@@ -117,7 +117,8 @@ static int is_input_end(FFV1Context *s, GetBitContext *gb) · 116 unmodified lines
117117 #define RENAME(name) name ## 32
118118 #include "ffv1dec_template.c"
119119
120−static int decode_plane(FFV1Context *s, FFV1SliceContext *sc,
120+static int decode_plane(FFV1Context *f,
121+ FFV1Context *s, FFV1SliceContext *sc,
121122 GetBitContext *gb,
122123 uint8_t *src, int w, int h, int stride, int plane_index,
123124 int pixel_stride)
@@ -141,13 +142,13 @@ static int decode_plane(FFV1Context *s, FFV1SliceContext *sc, · 17 unmodified lines
141142 sample[0][w] = sample[0][w - 1];
142143
143144 if (s->avctx->bits_per_raw_sample <= 8) {
144− int ret = decode_line(s, sc, gb, w, sample, plane_index, 8);
145+ int ret = decode_line(f, s, sc, gb, w, sample, plane_index, 8);
145146 if (ret < 0)
146147 return ret;
147148 for (x = 0; x < w; x++)
148149 src[x*pixel_stride + stride * y] = sample[1][x];
149150 } else {
150− int ret = decode_line(s, sc, gb, w, sample, plane_index, s->avctx->bits_per_raw_sample);
151+ int ret = decode_line(f, s, sc, gb, w, sample, plane_index, s->avctx->bits_per_raw_sample);
151152 if (ret < 0)
152153 return ret;
153154 if (s->packed_at_lsb) {
@@ -207,7 +208,6 @@ static int decode_slice_header(const FFV1Context *f, FFV1Context *fs, · 53 unmodified lines
207208 return -1;
208209 }
209210 p->quant_table_index = idx;
210− memcpy(p->quant_table, f->quant_tables[idx], sizeof(p->quant_table));
211211 context_count = f->context_count[idx];
212212
213213 if (p->context_count < context_count) {
@@ -335,29 +335,29 @@ static int decode_slice(AVCodecContext *c, void *arg) · 121 unmodified lines
335335 const int chroma_height = AV_CEIL_RSHIFT(height, f->chroma_v_shift);
336336 const int cx = x >> f->chroma_h_shift;
337337 const int cy = y >> f->chroma_v_shift;
338− decode_plane(fs, sc, &gb, p->data[0] + ps*x + y*p->linesize[0], width, height, p->linesize[0], 0, 1);
338+ decode_plane(f, fs, sc, &gb, p->data[0] + ps*x + y*p->linesize[0], width, height, p->linesize[0], 0, 1);
339339
340340 if (f->chroma_planes) {
341− decode_plane(fs, sc, &gb, p->data[1] + ps*cx+cy*p->linesize[1], chroma_width, chroma_height, p->linesize[1], 1, 1);
342− decode_plane(fs, sc, &gb, p->data[2] + ps*cx+cy*p->linesize[2], chroma_width, chroma_height, p->linesize[2], 1, 1);
341+ decode_plane(f, fs, sc, &gb, p->data[1] + ps*cx+cy*p->linesize[1], chroma_width, chroma_height, p->linesize[1], 1, 1);
342+ decode_plane(f, fs, sc, &gb, p->data[2] + ps*cx+cy*p->linesize[2], chroma_width, chroma_height, p->linesize[2], 1, 1);
343343 }
344344 if (fs->transparency)
345− decode_plane(fs, sc, &gb, p->data[3] + ps*x + y*p->linesize[3], width, height, p->linesize[3], (f->version >= 4 && !f->chroma_planes) ? 1 : 2, 1);
345+ decode_plane(f, fs, sc, &gb, p->data[3] + ps*x + y*p->linesize[3], width, height, p->linesize[3], (f->version >= 4 && !f->chroma_planes) ? 1 : 2, 1);
346346 } else if (f->colorspace == 0) {
347− decode_plane(fs, sc, &gb, p->data[0] + ps*x + y*p->linesize[0] , width, height, p->linesize[0], 0, 2);
348− decode_plane(fs, sc, &gb, p->data[0] + ps*x + y*p->linesize[0] + 1, width, height, p->linesize[0], 1, 2);
347+ decode_plane(f, fs, sc, &gb, p->data[0] + ps*x + y*p->linesize[0] , width, height, p->linesize[0], 0, 2);
348+ decode_plane(f, fs, sc, &gb, p->data[0] + ps*x + y*p->linesize[0] + 1, width, height, p->linesize[0], 1, 2);
349349 } else if (f->use32bit) {
350350 uint8_t *planes[4] = { p->data[0] + ps * x + y * p->linesize[0],
351351 p->data[1] + ps * x + y * p->linesize[1],
352352 p->data[2] + ps * x + y * p->linesize[2],
353353 p->data[3] + ps * x + y * p->linesize[3] };
354− decode_rgb_frame32(fs, sc, &gb, planes, width, height, p->linesize);
354+ decode_rgb_frame32(f, fs, sc, &gb, planes, width, height, p->linesize);
355355 } else {
356356 uint8_t *planes[4] = { p->data[0] + ps * x + y * p->linesize[0],
357357 p->data[1] + ps * x + y * p->linesize[1],
358358 p->data[2] + ps * x + y * p->linesize[2],
359359 p->data[3] + ps * x + y * p->linesize[3] };
360− decode_rgb_frame(fs, sc, &gb, planes, width, height, p->linesize);
360+ decode_rgb_frame(f, fs, sc, &gb, planes, width, height, p->linesize);
361361 }
362362 if (fs->ac != AC_GOLOMB_RICE && f->version > 2) {
363363 int v;
@@ -830,11 +830,7 @@ static int read_header(FFV1Context *f) · 466 unmodified lines
830830 return AVERROR_INVALIDDATA;
831831 }
832832 p->quant_table_index = idx;
833− memcpy(p->quant_table, f->quant_tables[idx],
834− sizeof(p->quant_table));
835833 context_count = f->context_count[idx];
836− } else {
837− memcpy(p->quant_table, f->quant_tables[0], sizeof(p->quant_table));
838834 }
839835
840836 if (f->version <= 2) {
libavcodec/ffv1dec_template.c+10−5
@@ -23,11 +23,14 @@ · 22 unmodified lines
2323 #include "ffv1_template.c"
2424
2525 static av_always_inline int
26−RENAME(decode_line)(FFV1Context *s, FFV1SliceContext *sc, GetBitContext *gb,
26+RENAME(decode_line)(FFV1Context *f,
27+ FFV1Context *s, FFV1SliceContext *sc,
28+ GetBitContext *gb,
2729 int w, TYPE *sample[2], int plane_index, int bits)
2830 {
2931 PlaneContext *const p = &s->plane[plane_index];
3032 RangeCoder *const c = &s->c;
33+ const int16_t (*quant_table)[256] = f->quant_tables[p->quant_table_index];
3134 int x;
3235 int run_count = 0;
3336 int run_mode = 0;
@@ -57,7 +60,8 @@ RENAME(decode_line)(FFV1Context *s, FFV1SliceContext *sc, GetBitContext *gb, · 23 unmodified lines
5760 return AVERROR_INVALIDDATA;
5861 }
5962
60− context = RENAME(get_context)(p, sample[1] + x, sample[0] + x, sample[1] + x);
63+ context = RENAME(get_context)(quant_table,
64+ sample[1] + x, sample[0] + x, sample[1] + x);
6165 if (context < 0) {
6266 context = -context;
6367 sign = 1;
@@ -127,7 +131,8 @@ RENAME(decode_line)(FFV1Context *s, FFV1SliceContext *sc, GetBitContext *gb, · 63 unmodified lines
127131 return 0;
128132 }
129133
130−static int RENAME(decode_rgb_frame)(FFV1Context *s, FFV1SliceContext *sc,
134+static int RENAME(decode_rgb_frame)(FFV1Context *f,
135+ FFV1Context *s, FFV1SliceContext *sc,
131136 GetBitContext *gb,
132137 uint8_t *src[4], int w, int h, int stride[4])
133138 {
@@ -158,9 +163,9 @@ static int RENAME(decode_rgb_frame)(FFV1Context *s, FFV1SliceContext *sc, · 24 unmodified lines
158163 sample[p][1][-1]= sample[p][0][0 ];
159164 sample[p][0][ w]= sample[p][0][w-1];
160165 if (lbd && s->slice_coding_mode == 0)
161− ret = RENAME(decode_line)(s, sc, gb, w, sample[p], (p + 1)/2, 9);
166+ ret = RENAME(decode_line)(f, s, sc, gb, w, sample[p], (p + 1)/2, 9);
162167 else
163− ret = RENAME(decode_line)(s, sc, gb, w, sample[p], (p + 1)/2, bits + (s->slice_coding_mode != 1));
168+ ret = RENAME(decode_line)(f, s, sc, gb, w, sample[p], (p + 1)/2, bits + (s->slice_coding_mode != 1));
164169 if (ret < 0)
165170 return ret;
166171 }
libavcodec/ffv1enc.c+12−12
@@ -269,7 +269,8 @@ static inline void put_vlc_symbol(PutBitContext *pb, VlcState *const state, · 268 unmodified lines
269269 #define RENAME(name) name ## 32
270270 #include "ffv1enc_template.c"
271271
272−static int encode_plane(FFV1Context *s, FFV1SliceContext *sc,
272+static int encode_plane(FFV1Context *f,
273+ FFV1Context *s, FFV1SliceContext *sc,
273274 const uint8_t *src, int w, int h,
274275 int stride, int plane_index, int pixel_stride)
275276 {
@@ -289,7 +290,7 @@ static int encode_plane(FFV1Context *s, FFV1SliceContext *sc, · 13 unmodified lines
289290 if (s->bits_per_raw_sample <= 8) {
290291 for (x = 0; x < w; x++)
291292 sample[0][x] = src[x * pixel_stride + stride * y];
292− if((ret = encode_line(s, sc, w, sample, plane_index, 8)) < 0)
293+ if((ret = encode_line(f, s, sc, w, sample, plane_index, 8)) < 0)
293294 return ret;
294295 } else {
295296 if (s->packed_at_lsb) {
@@ -301,7 +302,7 @@ static int encode_plane(FFV1Context *s, FFV1SliceContext *sc, · 5 unmodified lines
301302 sample[0][x] = ((uint16_t*)(src + stride*y))[x] >> (16 - s->bits_per_raw_sample);
302303 }
303304 }
304− if((ret = encode_line(s, sc, w, sample, plane_index, s->bits_per_raw_sample)) < 0)
305+ if((ret = encode_line(f, s, sc, w, sample, plane_index, s->bits_per_raw_sample)) < 0)
305306 return ret;
306307 }
307308 }
@@ -741,7 +742,6 @@ static av_cold int encode_init(AVCodecContext *avctx) · 433 unmodified lines
741742
742743 p->quant_table_index = s->context_model;
743744 p->context_count = s->context_count[p->quant_table_index];
744− memcpy(p->quant_table, s->quant_tables[p->quant_table_index], sizeof(p->quant_table));
745745 }
746746
747747 if ((ret = ff_ffv1_allocate_initial_states(s)) < 0)
@@ -1066,21 +1066,21 @@ retry: · 318 unmodified lines
10661066 const int cx = x >> f->chroma_h_shift;
10671067 const int cy = y >> f->chroma_v_shift;
10681068
1069− ret = encode_plane(fs, sc, p->data[0] + ps*x + y*p->linesize[0], width, height, p->linesize[0], 0, 1);
1069+ ret = encode_plane(f, fs, sc, p->data[0] + ps*x + y*p->linesize[0], width, height, p->linesize[0], 0, 1);
10701070
10711071 if (f->chroma_planes) {
1072− ret |= encode_plane(fs, sc, p->data[1] + ps*cx+cy*p->linesize[1], chroma_width, chroma_height, p->linesize[1], 1, 1);
1073− ret |= encode_plane(fs, sc, p->data[2] + ps*cx+cy*p->linesize[2], chroma_width, chroma_height, p->linesize[2], 1, 1);
1072+ ret |= encode_plane(f, fs, sc, p->data[1] + ps*cx+cy*p->linesize[1], chroma_width, chroma_height, p->linesize[1], 1, 1);
1073+ ret |= encode_plane(f, fs, sc, p->data[2] + ps*cx+cy*p->linesize[2], chroma_width, chroma_height, p->linesize[2], 1, 1);
10741074 }
10751075 if (fs->transparency)
1076− ret |= encode_plane(fs, sc, p->data[3] + ps*x + y*p->linesize[3], width, height, p->linesize[3], 2, 1);
1076+ ret |= encode_plane(f, fs, sc, p->data[3] + ps*x + y*p->linesize[3], width, height, p->linesize[3], 2, 1);
10771077 } else if (c->pix_fmt == AV_PIX_FMT_YA8) {
1078− ret = encode_plane(fs, sc, p->data[0] + ps*x + y*p->linesize[0], width, height, p->linesize[0], 0, 2);
1079− ret |= encode_plane(fs, sc, p->data[0] + 1 + ps*x + y*p->linesize[0], width, height, p->linesize[0], 1, 2);
1078+ ret = encode_plane(f, fs, sc, p->data[0] + ps*x + y*p->linesize[0], width, height, p->linesize[0], 0, 2);
1079+ ret |= encode_plane(f, fs, sc, p->data[0] + 1 + ps*x + y*p->linesize[0], width, height, p->linesize[0], 1, 2);
10801080 } else if (f->use32bit) {
1081− ret = encode_rgb_frame32(fs, sc, planes, width, height, p->linesize);
1081+ ret = encode_rgb_frame32(f, fs, sc, planes, width, height, p->linesize);
10821082 } else {
1083− ret = encode_rgb_frame(fs, sc, planes, width, height, p->linesize);
1083+ ret = encode_rgb_frame(f, fs, sc, planes, width, height, p->linesize);
10841084 }
10851085
10861086 if (ret < 0) {
libavcodec/ffv1enc_template.c+8−5
@@ -23,7 +23,8 @@ · 22 unmodified lines
2323 #include "ffv1_template.c"
2424
2525 static av_always_inline int
26−RENAME(encode_line)(FFV1Context *s, FFV1SliceContext *sc,
26+RENAME(encode_line)(FFV1Context *f,
27+ FFV1Context *s, FFV1SliceContext *sc,
2728 int w, TYPE *sample[3], int plane_index, int bits)
2829 {
2930 PlaneContext *const p = &s->plane[plane_index];
@@ -60,7 +61,8 @@ RENAME(encode_line)(FFV1Context *s, FFV1SliceContext *sc, · 30 unmodified lines
6061 for (x = 0; x < w; x++) {
6162 int diff, context;
6263
63− context = RENAME(get_context)(p, sample[0] + x, sample[1] + x, sample[2] + x);
64+ context = RENAME(get_context)(f->quant_tables[p->quant_table_index],
65+ sample[0] + x, sample[1] + x, sample[2] + x);
6466 diff = sample[0][x] - RENAME(predict)(sample[0] + x, sample[1] + x);
6567
6668 if (context < 0) {
@@ -124,7 +126,8 @@ RENAME(encode_line)(FFV1Context *s, FFV1SliceContext *sc, · 57 unmodified lines
124126 return 0;
125127 }
126128
127−static int RENAME(encode_rgb_frame)(FFV1Context *s, FFV1SliceContext *sc,
129+static int RENAME(encode_rgb_frame)(FFV1Context *f,
130+ FFV1Context *s, FFV1SliceContext *sc,
128131 const uint8_t *src[4],
129132 int w, int h, const int stride[4])
130133 {
@@ -193,9 +196,9 @@ static int RENAME(encode_rgb_frame)(FFV1Context *s, FFV1SliceContext *sc, · 62 unmodified lines
193196 sample[p][0][-1] = sample[p][1][0 ];
194197 sample[p][1][ w] = sample[p][1][w-1];
195198 if (lbd && s->slice_coding_mode == 0)
196− ret = RENAME(encode_line)(s, sc, w, sample[p], (p + 1) / 2, 9);
199+ ret = RENAME(encode_line)(f, s, sc, w, sample[p], (p + 1) / 2, 9);
197200 else
198− ret = RENAME(encode_line)(s, sc, w, sample[p], (p + 1) / 2, bits + (s->slice_coding_mode != 1));
201+ ret = RENAME(encode_line)(f, s, sc, w, sample[p], (p + 1) / 2, bits + (s->slice_coding_mode != 1));
199202 if (ret < 0)
200203 return ret;
201204 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t