FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/ffv1dec_template.c
Date: 2024-07-26 21:54:09
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 3680016 static av_always_inline int RENAME(decode_line)(FFV1Context *s, int w,
26 TYPE *sample[2],
27 int plane_index, int bits)
28 {
29 3680016 PlaneContext *const p = &s->plane[plane_index];
30 3680016 RangeCoder *const c = &s->c;
31 int x;
32 3680016 int run_count = 0;
33 3680016 int run_mode = 0;
34 3680016 int run_index = s->run_index;
35
36
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1840008 times.
3680016 if (is_input_end(s))
37 return AVERROR_INVALIDDATA;
38
39
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1840008 times.
3680016 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 297958406 times.
✓ Branch 1 taken 1840008 times.
599596828 for (x = 0; x < w; x++) {
53 int diff, context, sign;
54
55
2/2
✓ Branch 0 taken 1840008 times.
✓ Branch 1 taken 296118398 times.
595916812 if (!(x & 1023)) {
56
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1840008 times.
3680016 if (is_input_end(s))
57 return AVERROR_INVALIDDATA;
58 }
59
60 595916812 context = RENAME(get_context)(p, sample[1] + x, sample[0] + x, sample[1] + x);
61
2/2
✓ Branch 0 taken 131647165 times.
✓ Branch 1 taken 166311241 times.
595916812 if (context < 0) {
62 263294330 context = -context;
63 263294330 sign = 1;
64 } else
65 332622482 sign = 0;
66
67 av_assert2(context < p->context_count);
68
69
2/2
✓ Branch 0 taken 151603536 times.
✓ Branch 1 taken 146354870 times.
595916812 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 2082108 times.
✓ Branch 1 taken 144272762 times.
✓ Branch 2 taken 1435796 times.
✓ Branch 3 taken 646312 times.
292709740 if (context == 0 && run_mode == 0)
73 2871592 run_mode = 1;
74
75
2/2
✓ Branch 0 taken 3257492 times.
✓ Branch 1 taken 143097378 times.
292709740 if (run_mode) {
76
3/4
✓ Branch 0 taken 3257492 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2705666 times.
✓ Branch 3 taken 551826 times.
6514984 if (run_count == 0 && run_mode == 1) {
77
2/2
✓ Branch 1 taken 1324459 times.
✓ Branch 2 taken 1381207 times.
5411332 if (get_bits1(&s->gb)) {
78 2648918 run_count = 1 << ff_log2_run[run_index];
79
2/2
✓ Branch 0 taken 1288050 times.
✓ Branch 1 taken 36409 times.
2648918 if (x + run_count <= w)
80 2576100 run_index++;
81 } else {
82
2/2
✓ Branch 0 taken 1028565 times.
✓ Branch 1 taken 352642 times.
2762414 if (ff_log2_run[run_index])
83 2057130 run_count = get_bits(&s->gb, ff_log2_run[run_index]);
84 else
85 705284 run_count = 0;
86
2/2
✓ Branch 0 taken 1274790 times.
✓ Branch 1 taken 106417 times.
2762414 if (run_index)
87 2549580 run_index--;
88 2762414 run_mode = 2;
89 }
90 }
91
2/2
✓ Branch 0 taken 3254993 times.
✓ Branch 1 taken 2499 times.
6514984 if (sample[1][x - 1] == sample[0][x - 1]) {
92
4/4
✓ Branch 0 taken 2295974 times.
✓ Branch 1 taken 3218585 times.
✓ Branch 2 taken 2259566 times.
✓ Branch 3 taken 36408 times.
11029118 while (run_count > 1 && w-x > 1) {
93 4519132 sample[1][x] = sample[0][x];
94 4519132 x++;
95 4519132 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 6514984 run_count--;
105
2/2
✓ Branch 0 taken 1381207 times.
✓ Branch 1 taken 1876285 times.
6514984 if (run_count < 0) {
106 2762414 run_mode = 0;
107 2762414 run_count = 0;
108 2762414 diff = get_vlc_symbol(&s->gb, &p->vlc_state[context],
109 bits);
110
2/2
✓ Branch 0 taken 644728 times.
✓ Branch 1 taken 736479 times.
2762414 if (diff >= 0)
111 1289456 diff++;
112 } else
113 3752570 diff = 0;
114 } else
115 286194756 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 131647165 times.
✓ Branch 1 taken 166311241 times.
595916812 if (sign)
122 263294330 diff = -(unsigned)diff;
123
124 595916812 sample[1][x] = av_zero_extend(RENAME(predict)(sample[1] + x, sample[0] + x) + (SUINT)diff, bits);
125 }
126 3680016 s->run_index = run_index;
127 3680016 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