FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/ffv1dec_template.c
Date: 2024-03-29 01:21:52
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 297366322 times.
✓ Branch 1 taken 1840008 times.
598412660 for (x = 0; x < w; x++) {
53 int diff, context, sign;
54
55
2/2
✓ Branch 0 taken 1840008 times.
✓ Branch 1 taken 295526314 times.
594732644 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 594732644 context = RENAME(get_context)(p, sample[1] + x, sample[0] + x, sample[1] + x);
61
2/2
✓ Branch 0 taken 129289340 times.
✓ Branch 1 taken 168076982 times.
594732644 if (context < 0) {
62 258578680 context = -context;
63 258578680 sign = 1;
64 } else
65 336153964 sign = 0;
66
67 av_assert2(context < p->context_count);
68
69
2/2
✓ Branch 0 taken 151603536 times.
✓ Branch 1 taken 145762786 times.
594732644 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 2410430 times.
✓ Branch 1 taken 143352356 times.
✓ Branch 2 taken 1639058 times.
✓ Branch 3 taken 771372 times.
291525572 if (context == 0 && run_mode == 0)
73 3278116 run_mode = 1;
74
75
2/2
✓ Branch 0 taken 3758760 times.
✓ Branch 1 taken 142004026 times.
291525572 if (run_mode) {
76
3/4
✓ Branch 0 taken 3758760 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3101323 times.
✓ Branch 3 taken 657437 times.
7517520 if (run_count == 0 && run_mode == 1) {
77
2/2
✓ Branch 1 taken 1523475 times.
✓ Branch 2 taken 1577848 times.
6202646 if (get_bits1(&s->gb)) {
78 3046950 run_count = 1 << ff_log2_run[run_index];
79
2/2
✓ Branch 0 taken 1481359 times.
✓ Branch 1 taken 42116 times.
3046950 if (x + run_count <= w)
80 2962718 run_index++;
81 } else {
82
2/2
✓ Branch 0 taken 1207607 times.
✓ Branch 1 taken 370241 times.
3155696 if (ff_log2_run[run_index])
83 2415214 run_count = get_bits(&s->gb, ff_log2_run[run_index]);
84 else
85 740482 run_count = 0;
86
2/2
✓ Branch 0 taken 1468485 times.
✓ Branch 1 taken 109363 times.
3155696 if (run_index)
87 2936970 run_index--;
88 3155696 run_mode = 2;
89 }
90 }
91
2/2
✓ Branch 0 taken 3756261 times.
✓ Branch 1 taken 2499 times.
7517520 if (sample[1][x - 1] == sample[0][x - 1]) {
92
4/4
✓ Branch 0 taken 2893765 times.
✓ Branch 1 taken 3714146 times.
✓ Branch 2 taken 2851650 times.
✓ Branch 3 taken 42115 times.
13215822 while (run_count > 1 && w-x > 1) {
93 5703300 sample[1][x] = sample[0][x];
94 5703300 x++;
95 5703300 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 7517520 run_count--;
105
2/2
✓ Branch 0 taken 1577848 times.
✓ Branch 1 taken 2180912 times.
7517520 if (run_count < 0) {
106 3155696 run_mode = 0;
107 3155696 run_count = 0;
108 3155696 diff = get_vlc_symbol(&s->gb, &p->vlc_state[context],
109 bits);
110
2/2
✓ Branch 0 taken 728282 times.
✓ Branch 1 taken 849566 times.
3155696 if (diff >= 0)
111 1456564 diff++;
112 } else
113 4361824 diff = 0;
114 } else
115 284008052 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 129289340 times.
✓ Branch 1 taken 168076982 times.
594732644 if (sign)
122 258578680 diff = -(unsigned)diff;
123
124 594732644 sample[1][x] = av_mod_uintp2(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