FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/ffv1dec_template.c
Date: 2024-12-12 01:08:13
Exec Total Coverage
Lines: 98 114 86.0%
Functions: 2 2 100.0%
Branches: 44 52 84.6%

Line Branch Exec Source
1 /*
2 * FFV1 decoder template
3 *
4 * Copyright (c) 2003-2016 Michael Niedermayer <michaelni@gmx.at>
5 *
6 * This file is part of FFmpeg.
7 *
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23 #include "ffv1_template.c"
24
25 static av_always_inline int
26 4596384 RENAME(decode_line)(FFV1Context *f, FFV1SliceContext *sc,
27 GetBitContext *gb,
28 int w, TYPE *sample[2], int plane_index, int bits,
29 int ac)
30 {
31 4596384 PlaneContext *const p = &sc->plane[plane_index];
32 4596384 RangeCoder *const c = &sc->c;
33 4596384 const int16_t (*quant_table)[256] = f->quant_tables[p->quant_table_index];
34 int x;
35 4596384 int run_count = 0;
36 4596384 int run_mode = 0;
37 4596384 int run_index = sc->run_index;
38
39
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2298192 times.
4596384 if (is_input_end(c, gb, ac))
40 return AVERROR_INVALIDDATA;
41
42
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2298192 times.
4596384 if (sc->slice_coding_mode == 1) {
43 int i;
44 for (x = 0; x < w; x++) {
45 int v = 0;
46 for (i=0; i<bits; i++) {
47 uint8_t state = 128;
48 v += v + get_rac(c, &state);
49 }
50 sample[1][x] = v;
51 }
52 return 0;
53 }
54
55
2/2
✓ Branch 0 taken 352274948 times.
✓ Branch 1 taken 2298192 times.
709146280 for (x = 0; x < w; x++) {
56 int diff, context, sign;
57
58
2/2
✓ Branch 0 taken 2298192 times.
✓ Branch 1 taken 349976756 times.
704549896 if (!(x & 1023)) {
59
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2298192 times.
4596384 if (is_input_end(c, gb, ac))
60 return AVERROR_INVALIDDATA;
61 }
62
63 704549896 context = RENAME(get_context)(quant_table,
64 704549896 sample[1] + x, sample[0] + x, sample[1] + x);
65
2/2
✓ Branch 0 taken 159366214 times.
✓ Branch 1 taken 192908734 times.
704549896 if (context < 0) {
66 318732428 context = -context;
67 318732428 sign = 1;
68 } else
69 385817468 sign = 0;
70
71 av_assert2(context < p->context_count);
72
73
2/2
✓ Branch 0 taken 182745972 times.
✓ Branch 1 taken 169528976 times.
704549896 if (ac != AC_GOLOMB_RICE) {
74 365491944 diff = get_symbol_inline(c, p->state[context], 1);
75 } else {
76
4/4
✓ Branch 0 taken 2417907 times.
✓ Branch 1 taken 167111069 times.
✓ Branch 2 taken 1670696 times.
✓ Branch 3 taken 747211 times.
339057952 if (context == 0 && run_mode == 0)
77 3341392 run_mode = 1;
78
79
2/2
✓ Branch 0 taken 3754968 times.
✓ Branch 1 taken 165774008 times.
339057952 if (run_mode) {
80
3/4
✓ Branch 0 taken 3754968 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3139393 times.
✓ Branch 3 taken 615575 times.
7509936 if (run_count == 0 && run_mode == 1) {
81
2/2
✓ Branch 1 taken 1527524 times.
✓ Branch 2 taken 1611869 times.
6278786 if (get_bits1(gb)) {
82 3055048 run_count = 1 << ff_log2_run[run_index];
83
2/2
✓ Branch 0 taken 1488959 times.
✓ Branch 1 taken 38565 times.
3055048 if (x + run_count <= w)
84 2977918 run_index++;
85 } else {
86
2/2
✓ Branch 0 taken 1161029 times.
✓ Branch 1 taken 450840 times.
3223738 if (ff_log2_run[run_index])
87 2322058 run_count = get_bits(gb, ff_log2_run[run_index]);
88 else
89 901680 run_count = 0;
90
2/2
✓ Branch 0 taken 1472632 times.
✓ Branch 1 taken 139237 times.
3223738 if (run_index)
91 2945264 run_index--;
92 3223738 run_mode = 2;
93 }
94 }
95
2/2
✓ Branch 0 taken 3752469 times.
✓ Branch 1 taken 2499 times.
7509936 if (sample[1][x - 1] == sample[0][x - 1]) {
96
4/4
✓ Branch 0 taken 2481820 times.
✓ Branch 1 taken 3713905 times.
✓ Branch 2 taken 2443256 times.
✓ Branch 3 taken 38564 times.
12391450 while (run_count > 1 && w-x > 1) {
97 4886512 sample[1][x] = sample[0][x];
98 4886512 x++;
99 4886512 run_count--;
100 }
101 } else {
102
4/4
✓ Branch 0 taken 507 times.
✓ Branch 1 taken 2498 times.
✓ Branch 2 taken 506 times.
✓ Branch 3 taken 1 times.
6010 while (run_count > 1 && w-x > 1) {
103 1012 sample[1][x] = RENAME(predict)(sample[1] + x, sample[0] + x);
104 1012 x++;
105 1012 run_count--;
106 }
107 }
108 7509936 run_count--;
109
2/2
✓ Branch 0 taken 1611869 times.
✓ Branch 1 taken 2143099 times.
7509936 if (run_count < 0) {
110 3223738 run_mode = 0;
111 3223738 run_count = 0;
112 3223738 diff = get_vlc_symbol(gb, &p->vlc_state[context],
113 bits);
114
2/2
✓ Branch 0 taken 756975 times.
✓ Branch 1 taken 854894 times.
3223738 if (diff >= 0)
115 1513950 diff++;
116 } else
117 4286198 diff = 0;
118 } else
119 331548016 diff = get_vlc_symbol(gb, &p->vlc_state[context], bits);
120
121 ff_dlog(f->avctx, "count:%d index:%d, mode:%d, x:%d pos:%d\n",
122 run_count, run_index, run_mode, x, get_bits_count(gb));
123 }
124
125
2/2
✓ Branch 0 taken 159366214 times.
✓ Branch 1 taken 192908734 times.
704549896 if (sign)
126 318732428 diff = -(unsigned)diff;
127
128 704549896 sample[1][x] = av_zero_extend(RENAME(predict)(sample[1] + x, sample[0] + x) + (SUINT)diff, bits);
129 }
130 4596384 sc->run_index = run_index;
131 4596384 return 0;
132 }
133
134 1632 static int RENAME(decode_rgb_frame)(FFV1Context *f, FFV1SliceContext *sc,
135 GetBitContext *gb,
136 uint8_t *src[4], int w, int h, int stride[4])
137 {
138 int x, y, p;
139 TYPE *sample[4][2];
140 1632 int lbd = f->avctx->bits_per_raw_sample <= 8;
141 1632 int bits = f->avctx->bits_per_raw_sample > 0 ? f->avctx->bits_per_raw_sample : 8;
142 1632 int offset = 1 << bits;
143 1632 int transparency = f->transparency;
144 1632 int ac = f->ac;
145
146 1632 if (sc->slice_coding_mode == 1)
147 ac = 1;
148
149 8160 for (x = 0; x < 4; x++) {
150 6528 sample[x][0] = RENAME(sc->sample_buffer) + x * 2 * (w + 6) + 3;
151 6528 sample[x][1] = RENAME(sc->sample_buffer) + (x * 2 + 1) * (w + 6) + 3;
152 }
153
154 1632 sc->run_index = 0;
155
156 1632 memset(RENAME(sc->sample_buffer), 0, 8 * (w + 6) * sizeof(*RENAME(sc->sample_buffer)));
157
158 184824 for (y = 0; y < h; y++) {
159 732768 for (p = 0; p < 3 + transparency; p++) {
160 int ret;
161 549576 TYPE *temp = sample[p][0]; // FIXME: try a normal buffer
162
163 549576 sample[p][0] = sample[p][1];
164 549576 sample[p][1] = temp;
165
166 549576 sample[p][1][-1]= sample[p][0][0 ];
167 549576 sample[p][0][ w]= sample[p][0][w-1];
168 549576 if (lbd && sc->slice_coding_mode == 0)
169 274788 ret = RENAME(decode_line)(f, sc, gb, w, sample[p], (p + 1)/2, 9, ac);
170 else
171 274788 ret = RENAME(decode_line)(f, sc, gb, w, sample[p], (p + 1)/2, bits + (sc->slice_coding_mode != 1), ac);
172 549576 if (ret < 0)
173 return ret;
174 }
175 31322160 for (x = 0; x < w; x++) {
176 31138968 int g = sample[0][1][x];
177 31138968 int b = sample[1][1][x];
178 31138968 int r = sample[2][1][x];
179 31138968 int a = sample[3][1][x];
180
181 31138968 if (sc->slice_coding_mode != 1) {
182 31138968 b -= offset;
183 31138968 r -= offset;
184 31138968 g -= (b * sc->slice_rct_by_coef + r * sc->slice_rct_ry_coef) >> 2;
185 31138968 b += g;
186 31138968 r += g;
187 }
188
189 31138968 if (lbd)
190 15569484 *((uint32_t*)(src[0] + x*4 + stride[0]*y)) = b + ((unsigned)g<<8) + ((unsigned)r<<16) + ((unsigned)a<<24);
191 else if (sizeof(TYPE) == 4 || transparency) {
192 15569484 *((uint16_t*)(src[0] + x*2 + stride[0]*y)) = g;
193 15569484 *((uint16_t*)(src[1] + x*2 + stride[1]*y)) = b;
194 15569484 *((uint16_t*)(src[2] + x*2 + stride[2]*y)) = r;
195 15569484 if (transparency)
196 *((uint16_t*)(src[3] + x*2 + stride[3]*y)) = a;
197 } else {
198 *((uint16_t*)(src[0] + x*2 + stride[0]*y)) = b;
199 *((uint16_t*)(src[1] + x*2 + stride[1]*y)) = g;
200 *((uint16_t*)(src[2] + x*2 + stride[2]*y)) = r;
201 }
202 }
203 }
204 1632 return 0;
205 }
206