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
59} VlcState;59} VlcState;
60 60
61typedef struct PlaneContext {61typedef struct PlaneContext {
62 int16_t quant_table[MAX_CONTEXT_INPUTS][256];
63 int quant_table_index;62 int quant_table_index;
64 int context_count;63 int context_count;
65 uint8_t (*state)[CONTEXT_SIZE];64 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
29 return mid_pred(L, L + T - LT, T);29 return mid_pred(L, L + T - LT, T);
30}30}
31 31
32static inline int RENAME(get_context)(PlaneContext *p, TYPE *src,32static inline int RENAME(get_context)(const int16_t quant_table[MAX_CONTEXT_INPUTS][256],
33 TYPE *last, TYPE *last2)33 TYPE *src, TYPE *last, TYPE *last2)
34{34{
35 const int LT = last[-1];35 const int LT = last[-1];
36 const int T = last[0];36 const int T = last[0];
37 const int RT = last[1];37 const int RT = last[1];
38 const int L = src[-1];38 const int L = src[-1];
39 39
40 if (p->quant_table[3][127] || p->quant_table[4][127]) {40 if (quant_table[3][127] || quant_table[4][127]) {
41 const int TT = last2[0];41 const int TT = last2[0];
42 const int LL = src[-2];42 const int LL = src[-2];
43 return p->quant_table[0][(L - LT) & 0xFF] +43 return quant_table[0][(L - LT) & 0xFF] +
44 p->quant_table[1][(LT - T) & 0xFF] +44 quant_table[1][(LT - T) & 0xFF] +
45 p->quant_table[2][(T - RT) & 0xFF] +45 quant_table[2][(T - RT) & 0xFF] +
46 p->quant_table[3][(LL - L) & 0xFF] +46 quant_table[3][(LL - L) & 0xFF] +
47 p->quant_table[4][(TT - T) & 0xFF];47 quant_table[4][(TT - T) & 0xFF];
48 } else48 } else
49 return p->quant_table[0][(L - LT) & 0xFF] +49 return quant_table[0][(L - LT) & 0xFF] +
50 p->quant_table[1][(LT - T) & 0xFF] +50 quant_table[1][(LT - T) & 0xFF] +
51 p->quant_table[2][(T - RT) & 0xFF];51 quant_table[2][(T - RT) & 0xFF];
52}52}
53 53
libavcodec/ffv1dec.c+12−16
@@ -117,7 +117,8 @@ static int is_input_end(FFV1Context *s, GetBitContext *gb) · 116 unmodified lines
117#define RENAME(name) name ## 32117#define RENAME(name) name ## 32
118#include "ffv1dec_template.c"118#include "ffv1dec_template.c"
119 119
120static int decode_plane(FFV1Context *s, FFV1SliceContext *sc,120static int decode_plane(FFV1Context *f,
121 FFV1Context *s, FFV1SliceContext *sc,
121 GetBitContext *gb,122 GetBitContext *gb,
122 uint8_t *src, int w, int h, int stride, int plane_index,123 uint8_t *src, int w, int h, int stride, int plane_index,
123 int pixel_stride)124 int pixel_stride)
@@ -141,13 +142,13 @@ static int decode_plane(FFV1Context *s, FFV1SliceContext *sc, · 17 unmodified lines
141 sample[0][w] = sample[0][w - 1];142 sample[0][w] = sample[0][w - 1];
142 143
143 if (s->avctx->bits_per_raw_sample <= 8) {144 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);
145 if (ret < 0)146 if (ret < 0)
146 return ret;147 return ret;
147 for (x = 0; x < w; x++)148 for (x = 0; x < w; x++)
148 src[x*pixel_stride + stride * y] = sample[1][x];149 src[x*pixel_stride + stride * y] = sample[1][x];
149 } else {150 } 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);
151 if (ret < 0)152 if (ret < 0)
152 return ret;153 return ret;
153 if (s->packed_at_lsb) {154 if (s->packed_at_lsb) {
@@ -207,7 +208,6 @@ static int decode_slice_header(const FFV1Context *f, FFV1Context *fs, · 53 unmodified lines
207 return -1;208 return -1;
208 }209 }
209 p->quant_table_index = idx;210 p->quant_table_index = idx;
210 memcpy(p->quant_table, f->quant_tables[idx], sizeof(p->quant_table));
211 context_count = f->context_count[idx];211 context_count = f->context_count[idx];
212 212
213 if (p->context_count < context_count) {213 if (p->context_count < context_count) {
@@ -335,29 +335,29 @@ static int decode_slice(AVCodecContext *c, void *arg) · 121 unmodified lines
335 const int chroma_height = AV_CEIL_RSHIFT(height, f->chroma_v_shift);335 const int chroma_height = AV_CEIL_RSHIFT(height, f->chroma_v_shift);
336 const int cx = x >> f->chroma_h_shift;336 const int cx = x >> f->chroma_h_shift;
337 const int cy = y >> f->chroma_v_shift;337 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);
339 339
340 if (f->chroma_planes) {340 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);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(fs, sc, &gb, p->data[2] + ps*cx+cy*p->linesize[2], chroma_width, chroma_height, p->linesize[2], 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);
343 }343 }
344 if (fs->transparency)344 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);
346 } else if (f->colorspace == 0) {346 } 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);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(fs, sc, &gb, p->data[0] + ps*x + y*p->linesize[0] + 1, width, height, p->linesize[0], 1, 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);
349 } else if (f->use32bit) {349 } else if (f->use32bit) {
350 uint8_t *planes[4] = { p->data[0] + ps * x + y * p->linesize[0],350 uint8_t *planes[4] = { p->data[0] + ps * x + y * p->linesize[0],
351 p->data[1] + ps * x + y * p->linesize[1],351 p->data[1] + ps * x + y * p->linesize[1],
352 p->data[2] + ps * x + y * p->linesize[2],352 p->data[2] + ps * x + y * p->linesize[2],
353 p->data[3] + ps * x + y * p->linesize[3] };353 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);
355 } else {355 } else {
356 uint8_t *planes[4] = { p->data[0] + ps * x + y * p->linesize[0],356 uint8_t *planes[4] = { p->data[0] + ps * x + y * p->linesize[0],
357 p->data[1] + ps * x + y * p->linesize[1],357 p->data[1] + ps * x + y * p->linesize[1],
358 p->data[2] + ps * x + y * p->linesize[2],358 p->data[2] + ps * x + y * p->linesize[2],
359 p->data[3] + ps * x + y * p->linesize[3] };359 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);
361 }361 }
362 if (fs->ac != AC_GOLOMB_RICE && f->version > 2) {362 if (fs->ac != AC_GOLOMB_RICE && f->version > 2) {
363 int v;363 int v;
@@ -830,11 +830,7 @@ static int read_header(FFV1Context *f) · 466 unmodified lines
830 return AVERROR_INVALIDDATA;830 return AVERROR_INVALIDDATA;
831 }831 }
832 p->quant_table_index = idx;832 p->quant_table_index = idx;
833 memcpy(p->quant_table, f->quant_tables[idx],
834 sizeof(p->quant_table));
835 context_count = f->context_count[idx];833 context_count = f->context_count[idx];
836 } else {
837 memcpy(p->quant_table, f->quant_tables[0], sizeof(p->quant_table));
838 }834 }
839 835
840 if (f->version <= 2) {836 if (f->version <= 2) {
libavcodec/ffv1dec_template.c+10−5
@@ -23,11 +23,14 @@ · 22 unmodified lines
23#include "ffv1_template.c"23#include "ffv1_template.c"
24 24
25static av_always_inline int25static av_always_inline int
26RENAME(decode_line)(FFV1Context *s, FFV1SliceContext *sc, GetBitContext *gb,26RENAME(decode_line)(FFV1Context *f,
27 FFV1Context *s, FFV1SliceContext *sc,
28 GetBitContext *gb,
27 int w, TYPE *sample[2], int plane_index, int bits)29 int w, TYPE *sample[2], int plane_index, int bits)
28{30{
29 PlaneContext *const p = &s->plane[plane_index];31 PlaneContext *const p = &s->plane[plane_index];
30 RangeCoder *const c = &s->c;32 RangeCoder *const c = &s->c;
33 const int16_t (*quant_table)[256] = f->quant_tables[p->quant_table_index];
31 int x;34 int x;
32 int run_count = 0;35 int run_count = 0;
33 int run_mode = 0;36 int run_mode = 0;
@@ -57,7 +60,8 @@ RENAME(decode_line)(FFV1Context *s, FFV1SliceContext *sc, GetBitContext *gb, · 23 unmodified lines
57 return AVERROR_INVALIDDATA;60 return AVERROR_INVALIDDATA;
58 }61 }
59 62
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);
61 if (context < 0) {65 if (context < 0) {
62 context = -context;66 context = -context;
63 sign = 1;67 sign = 1;
@@ -127,7 +131,8 @@ RENAME(decode_line)(FFV1Context *s, FFV1SliceContext *sc, GetBitContext *gb, · 63 unmodified lines
127 return 0;131 return 0;
128}132}
129 133
130static int RENAME(decode_rgb_frame)(FFV1Context *s, FFV1SliceContext *sc,134static int RENAME(decode_rgb_frame)(FFV1Context *f,
135 FFV1Context *s, FFV1SliceContext *sc,
131 GetBitContext *gb,136 GetBitContext *gb,
132 uint8_t *src[4], int w, int h, int stride[4])137 uint8_t *src[4], int w, int h, int stride[4])
133{138{
@@ -158,9 +163,9 @@ static int RENAME(decode_rgb_frame)(FFV1Context *s, FFV1SliceContext *sc, · 24 unmodified lines
158 sample[p][1][-1]= sample[p][0][0 ];163 sample[p][1][-1]= sample[p][0][0 ];
159 sample[p][0][ w]= sample[p][0][w-1];164 sample[p][0][ w]= sample[p][0][w-1];
160 if (lbd && s->slice_coding_mode == 0)165 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);
162 else167 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));
164 if (ret < 0)169 if (ret < 0)
165 return ret;170 return ret;
166 }171 }
libavcodec/ffv1enc.c+12−12
@@ -269,7 +269,8 @@ static inline void put_vlc_symbol(PutBitContext *pb, VlcState *const state, · 268 unmodified lines
269#define RENAME(name) name ## 32269#define RENAME(name) name ## 32
270#include "ffv1enc_template.c"270#include "ffv1enc_template.c"
271 271
272static int encode_plane(FFV1Context *s, FFV1SliceContext *sc,272static int encode_plane(FFV1Context *f,
273 FFV1Context *s, FFV1SliceContext *sc,
273 const uint8_t *src, int w, int h,274 const uint8_t *src, int w, int h,
274 int stride, int plane_index, int pixel_stride)275 int stride, int plane_index, int pixel_stride)
275{276{
@@ -289,7 +290,7 @@ static int encode_plane(FFV1Context *s, FFV1SliceContext *sc, · 13 unmodified lines
289 if (s->bits_per_raw_sample <= 8) {290 if (s->bits_per_raw_sample <= 8) {
290 for (x = 0; x < w; x++)291 for (x = 0; x < w; x++)
291 sample[0][x] = src[x * pixel_stride + stride * y];292 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)
293 return ret;294 return ret;
294 } else {295 } else {
295 if (s->packed_at_lsb) {296 if (s->packed_at_lsb) {
@@ -301,7 +302,7 @@ static int encode_plane(FFV1Context *s, FFV1SliceContext *sc, · 5 unmodified lines
301 sample[0][x] = ((uint16_t*)(src + stride*y))[x] >> (16 - s->bits_per_raw_sample);302 sample[0][x] = ((uint16_t*)(src + stride*y))[x] >> (16 - s->bits_per_raw_sample);
302 }303 }
303 }304 }
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)
305 return ret;306 return ret;
306 }307 }
307 }308 }
@@ -741,7 +742,6 @@ static av_cold int encode_init(AVCodecContext *avctx) · 433 unmodified lines
741 742
742 p->quant_table_index = s->context_model;743 p->quant_table_index = s->context_model;
743 p->context_count = s->context_count[p->quant_table_index];744 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));
745 }745 }
746 746
747 if ((ret = ff_ffv1_allocate_initial_states(s)) < 0)747 if ((ret = ff_ffv1_allocate_initial_states(s)) < 0)
@@ -1066,21 +1066,21 @@ retry: · 318 unmodified lines
1066 const int cx = x >> f->chroma_h_shift;1066 const int cx = x >> f->chroma_h_shift;
1067 const int cy = y >> f->chroma_v_shift;1067 const int cy = y >> f->chroma_v_shift;
1068 1068
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);
1070 1070
1071 if (f->chroma_planes) {1071 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);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(fs, sc, p->data[2] + ps*cx+cy*p->linesize[2], chroma_width, chroma_height, p->linesize[2], 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);
1074 }1074 }
1075 if (fs->transparency)1075 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);
1077 } else if (c->pix_fmt == AV_PIX_FMT_YA8) {1077 } 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);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(fs, sc, p->data[0] + 1 + ps*x + y*p->linesize[0], width, height, p->linesize[0], 1, 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);
1080 } else if (f->use32bit) {1080 } 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);
1082 } else {1082 } 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);
1084 }1084 }
1085 1085
1086 if (ret < 0) {1086 if (ret < 0) {
libavcodec/ffv1enc_template.c+8−5
@@ -23,7 +23,8 @@ · 22 unmodified lines
23#include "ffv1_template.c"23#include "ffv1_template.c"
24 24
25static av_always_inline int25static av_always_inline int
26RENAME(encode_line)(FFV1Context *s, FFV1SliceContext *sc,26RENAME(encode_line)(FFV1Context *f,
27 FFV1Context *s, FFV1SliceContext *sc,
27 int w, TYPE *sample[3], int plane_index, int bits)28 int w, TYPE *sample[3], int plane_index, int bits)
28{29{
29 PlaneContext *const p = &s->plane[plane_index];30 PlaneContext *const p = &s->plane[plane_index];
@@ -60,7 +61,8 @@ RENAME(encode_line)(FFV1Context *s, FFV1SliceContext *sc, · 30 unmodified lines
60 for (x = 0; x < w; x++) {61 for (x = 0; x < w; x++) {
61 int diff, context;62 int diff, context;
62 63
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);
64 diff = sample[0][x] - RENAME(predict)(sample[0] + x, sample[1] + x);66 diff = sample[0][x] - RENAME(predict)(sample[0] + x, sample[1] + x);
65 67
66 if (context < 0) {68 if (context < 0) {
@@ -124,7 +126,8 @@ RENAME(encode_line)(FFV1Context *s, FFV1SliceContext *sc, · 57 unmodified lines
124 return 0;126 return 0;
125}127}
126 128
127static int RENAME(encode_rgb_frame)(FFV1Context *s, FFV1SliceContext *sc,129static int RENAME(encode_rgb_frame)(FFV1Context *f,
130 FFV1Context *s, FFV1SliceContext *sc,
128 const uint8_t *src[4],131 const uint8_t *src[4],
129 int w, int h, const int stride[4])132 int w, int h, const int stride[4])
130{133{
@@ -193,9 +196,9 @@ static int RENAME(encode_rgb_frame)(FFV1Context *s, FFV1SliceContext *sc, · 62 unmodified lines
193 sample[p][0][-1] = sample[p][1][0 ];196 sample[p][0][-1] = sample[p][1][0 ];
194 sample[p][1][ w] = sample[p][1][w-1];197 sample[p][1][ w] = sample[p][1][w-1];
195 if (lbd && s->slice_coding_mode == 0)198 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);
197 else200 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));
199 if (ret < 0)202 if (ret < 0)
200 return ret;203 return ret;
201 }204 }

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