FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/ffv1dec_template.c
Date: 2022-12-09 07:38:14
Exec Total Coverage
Lines: 94 109 86.2%
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 3501456 static av_always_inline int RENAME(decode_line)(FFV1Context *s, int w,
26 TYPE *sample[2],
27 int plane_index, int bits)
28 {
29 3501456 PlaneContext *const p = &s->plane[plane_index];
30 3501456 RangeCoder *const c = &s->c;
31 int x;
32 3501456 int run_count = 0;
33 3501456 int run_mode = 0;
34 3501456 int run_index = s->run_index;
35
36
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1750728 times.
3501456 if (is_input_end(s))
37 return AVERROR_INVALIDDATA;
38
39
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1750728 times.
3501456 if (s->slice_coding_mode == 1) {
40 int i;
41 for (x = 0; x < w; x++) {
42 int v = 0;
43 for (i=0; i<bits; i++) {
44 uint8_t state = 128;
45 v += v + get_rac(c, &state);
46 }
47 sample[1][x] = v;
48 }
49 return 0;
50 }
51
52
2/2
✓ Branch 0 taken 266771459 times.
✓ Branch 1 taken 1750728 times.
537044374 for (x = 0; x < w; x++) {
53 int diff, context, sign;
54
55
2/2
✓ Branch 0 taken 1750728 times.
✓ Branch 1 taken 265020731 times.
533542918 if (!(x & 1023)) {
56
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1750728 times.
3501456 if (is_input_end(s))
57 return AVERROR_INVALIDDATA;
58 }
59
60 533542918 context = RENAME(get_context)(p, sample[1] + x, sample[0] + x, sample[1] + x);
61
2/2
✓ Branch 0 taken 111538319 times.
✓ Branch 1 taken 155233140 times.
533542918 if (context < 0) {
62 223076638 context = -context;
63 223076638 sign = 1;
64 } else
65 310466280 sign = 0;
66
67 av_assert2(context < p->context_count);
68
69
2/2
✓ Branch 0 taken 151603536 times.
✓ Branch 1 taken 115167923 times.
533542918 if (s->ac != AC_GOLOMB_RICE) {
70 303207072 diff = get_symbol_inline(c, p->state[context], 1);
71 } else {
72
4/4
✓ Branch 0 taken 2028966 times.
✓ Branch 1 taken 113138957 times.
✓ Branch 2 taken 1406364 times.
✓ Branch 3 taken 622602 times.
230335846 if (context == 0 && run_mode == 0)
73 2812728 run_mode = 1;
74
75
2/2
✓ Branch 0 taken 3179016 times.
✓ Branch 1 taken 111988907 times.
230335846 if (run_mode) {
76
3/4
✓ Branch 0 taken 3179016 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2648716 times.
✓ Branch 3 taken 530300 times.
6358032 if (run_count == 0 && run_mode == 1) {
77
2/2
✓ Branch 1 taken 1295521 times.
✓ Branch 2 taken 1353195 times.
5297432 if (get_bits1(&s->gb)) {
78 2591042 run_count = 1 << ff_log2_run[run_index];
79
2/2
✓ Branch 0 taken 1260471 times.
✓ Branch 1 taken 35050 times.
2591042 if (x + run_count <= w)
80 2520942 run_index++;
81 } else {
82
2/2
✓ Branch 0 taken 1004563 times.
✓ Branch 1 taken 348632 times.
2706390 if (ff_log2_run[run_index])
83 2009126 run_count = get_bits(&s->gb, ff_log2_run[run_index]);
84 else
85 697264 run_count = 0;
86
2/2
✓ Branch 0 taken 1249584 times.
✓ Branch 1 taken 103611 times.
2706390 if (run_index)
87 2499168 run_index--;
88 2706390 run_mode = 2;
89 }
90 }
91
2/2
✓ Branch 0 taken 3176517 times.
✓ Branch 1 taken 2499 times.
6358032 if (sample[1][x - 1] == sample[0][x - 1]) {
92
4/4
✓ Branch 0 taken 1796954 times.
✓ Branch 1 taken 3141468 times.
✓ Branch 2 taken 1761905 times.
✓ Branch 3 taken 35049 times.
9876844 while (run_count > 1 && w-x > 1) {
93 3523810 sample[1][x] = sample[0][x];
94 3523810 x++;
95 3523810 run_count--;
96 }
97 } else {
98
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) {
99 1012 sample[1][x] = RENAME(predict)(sample[1] + x, sample[0] + x);
100 1012 x++;
101 1012 run_count--;
102 }
103 }
104 6358032 run_count--;
105
2/2
✓ Branch 0 taken 1353195 times.
✓ Branch 1 taken 1825821 times.
6358032 if (run_count < 0) {
106 2706390 run_mode = 0;
107 2706390 run_count = 0;
108 2706390 diff = get_vlc_symbol(&s->gb, &p->vlc_state[context],
109 bits);
110
2/2
✓ Branch 0 taken 631292 times.
✓ Branch 1 taken 721903 times.
2706390 if (diff >= 0)
111 1262584 diff++;
112 } else
113 3651642 diff = 0;
114 } else
115 223977814 diff = get_vlc_symbol(&s->gb, &p->vlc_state[context], bits);
116
117 ff_dlog(s->avctx, "count:%d index:%d, mode:%d, x:%d pos:%d\n",
118 run_count, run_index, run_mode, x, get_bits_count(&s->gb));
119 }
120
121
2/2
✓ Branch 0 taken 111538319 times.
✓ Branch 1 taken 155233140 times.
533542918 if (sign)
122 223076638 diff = -(unsigned)diff;
123
124 533542918 sample[1][x] = av_mod_uintp2(RENAME(predict)(sample[1] + x, sample[0] + x) + (SUINT)diff, bits);
125 }
126 3501456 s->run_index = run_index;
127 3501456 return 0;
128 }
129
130 1632 static int RENAME(decode_rgb_frame)(FFV1Context *s, uint8_t *src[4], int w, int h, int stride[4])
131 {
132 int x, y, p;
133 TYPE *sample[4][2];
134 1632 int lbd = s->avctx->bits_per_raw_sample <= 8;
135 1632 int bits = s->avctx->bits_per_raw_sample > 0 ? s->avctx->bits_per_raw_sample : 8;
136 1632 int offset = 1 << bits;
137 1632 int transparency = s->transparency;
138
139 8160 for (x = 0; x < 4; x++) {
140 6528 sample[x][0] = RENAME(s->sample_buffer) + x * 2 * (w + 6) + 3;
141 6528 sample[x][1] = RENAME(s->sample_buffer) + (x * 2 + 1) * (w + 6) + 3;
142 }
143
144 1632 s->run_index = 0;
145
146 1632 memset(RENAME(s->sample_buffer), 0, 8 * (w + 6) * sizeof(*RENAME(s->sample_buffer)));
147
148 184824 for (y = 0; y < h; y++) {
149 732768 for (p = 0; p < 3 + transparency; p++) {
150 int ret;
151 549576 TYPE *temp = sample[p][0]; // FIXME: try a normal buffer
152
153 549576 sample[p][0] = sample[p][1];
154 549576 sample[p][1] = temp;
155
156 549576 sample[p][1][-1]= sample[p][0][0 ];
157 549576 sample[p][0][ w]= sample[p][0][w-1];
158 549576 if (lbd && s->slice_coding_mode == 0)
159 274788 ret = RENAME(decode_line)(s, w, sample[p], (p + 1)/2, 9);
160 else
161 274788 ret = RENAME(decode_line)(s, w, sample[p], (p + 1)/2, bits + (s->slice_coding_mode != 1));
162 549576 if (ret < 0)
163 return ret;
164 }
165 31322160 for (x = 0; x < w; x++) {
166 31138968 int g = sample[0][1][x];
167 31138968 int b = sample[1][1][x];
168 31138968 int r = sample[2][1][x];
169 31138968 int a = sample[3][1][x];
170
171 31138968 if (s->slice_coding_mode != 1) {
172 31138968 b -= offset;
173 31138968 r -= offset;
174 31138968 g -= (b * s->slice_rct_by_coef + r * s->slice_rct_ry_coef) >> 2;
175 31138968 b += g;
176 31138968 r += g;
177 }
178
179 31138968 if (lbd)
180 15569484 *((uint32_t*)(src[0] + x*4 + stride[0]*y)) = b + ((unsigned)g<<8) + ((unsigned)r<<16) + ((unsigned)a<<24);
181 else if (sizeof(TYPE) == 4 || transparency) {
182 15569484 *((uint16_t*)(src[0] + x*2 + stride[0]*y)) = g;
183 15569484 *((uint16_t*)(src[1] + x*2 + stride[1]*y)) = b;
184 15569484 *((uint16_t*)(src[2] + x*2 + stride[2]*y)) = r;
185 15569484 if (transparency)
186 *((uint16_t*)(src[3] + x*2 + stride[3]*y)) = a;
187 } else {
188 *((uint16_t*)(src[0] + x*2 + stride[0]*y)) = b;
189 *((uint16_t*)(src[1] + x*2 + stride[1]*y)) = g;
190 *((uint16_t*)(src[2] + x*2 + stride[2]*y)) = r;
191 }
192 }
193 }
194 1632 return 0;
195 }
196