FFmpeg coverage


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