../../../ffmpeg/
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
187 / 300
62.3%
Branches:
105 / 180
58.3%
Functions:
4 / 6
66.7%

libavcodec/ffv1enc_template.c
Line Branch Exec Source
1 /*
2 * FFV1 encoder 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 2763456 RENAME(encode_line)(FFV1Context *f, FFV1SliceContext *sc,
27 void *logctx,
28 int w, TYPE *const sample[3], int plane_index, int bits,
29 int ac, int pass1)
30 {
31 2763456 PlaneContext *const p = &sc->plane[plane_index];
32 2763456 RangeCoder *const c = &sc->c;
33 int x;
34 2763456 int run_index = sc->run_index;
35 2763456 int run_count = 0;
36 2763456 int run_mode = 0;
37
38
2/4
encode_line:
✗ Branch 2 → 3 not taken.
✓ Branch 2 → 4 taken 2483400 times.
encode_line32:
✗ Branch 2 → 3 not taken.
✓ Branch 2 → 4 taken 280056 times.
2763456 if (bits == 0)
39 ✗ return 0;
40
41
2/4
encode_line:
✗ Branch 4 → 5 not taken.
✓ Branch 4 → 19 taken 2483400 times.
encode_line32:
✗ Branch 4 → 5 not taken.
✓ Branch 4 → 19 taken 280056 times.
2763456 if (sc->slice_coding_mode == 1) {
42
0/4
encode_line:
✗ Branch 5 → 6 not taken.
✗ Branch 5 → 8 not taken.
encode_line32:
✗ Branch 5 → 6 not taken.
✗ Branch 5 → 8 not taken.
✗ av_assert0(ac != AC_GOLOMB_RICE);
43
0/4
encode_line:
✗ Branch 8 → 9 not taken.
✗ Branch 8 → 11 not taken.
encode_line32:
✗ Branch 8 → 9 not taken.
✗ Branch 8 → 11 not taken.
✗ if (c->bytestream_end - c->bytestream < (w * bits + 7LL)>>3) {
44 ✗ av_log(logctx, AV_LOG_ERROR, "encoded Range Coder frame too large\n");
45 ✗ return AVERROR_INVALIDDATA;
46 }
47
48
0/4
encode_line:
✗ Branch 17 → 12 not taken.
✗ Branch 17 → 18 not taken.
encode_line32:
✗ Branch 17 → 12 not taken.
✗ Branch 17 → 18 not taken.
✗ for (x = 0; x < w; x++) {
49 int i;
50 ✗ int v = sample[0][x];
51
0/4
encode_line:
✗ Branch 15 → 13 not taken.
✗ Branch 15 → 16 not taken.
encode_line32:
✗ Branch 15 → 13 not taken.
✗ Branch 15 → 16 not taken.
✗ for (i = bits-1; i>=0; i--) {
52 ✗ uint8_t state = 128;
53 ✗ put_rac(c, &state, (v>>i) & 1);
54 }
55 }
56 ✗ return 0;
57 }
58
59
4/4
encode_line:
✓ Branch 19 → 20 taken 1469600 times.
✓ Branch 19 → 23 taken 1013800 times.
encode_line32:
✓ Branch 19 → 20 taken 269400 times.
✓ Branch 19 → 23 taken 10656 times.
2763456 if (ac != AC_GOLOMB_RICE) {
60
2/4
encode_line:
✗ Branch 20 → 21 not taken.
✓ Branch 20 → 27 taken 1469600 times.
encode_line32:
✗ Branch 20 → 21 not taken.
✓ Branch 20 → 27 taken 269400 times.
1739000 if (c->bytestream_end - c->bytestream < w * 35) {
61 ✗ av_log(logctx, AV_LOG_ERROR, "encoded Range Coder frame too large\n");
62 ✗ return AVERROR_INVALIDDATA;
63 }
64 } else {
65
2/4
encode_line:
✗ Branch 24 → 25 not taken.
✓ Branch 24 → 27 taken 1013800 times.
encode_line32:
✗ Branch 24 → 25 not taken.
✓ Branch 24 → 27 taken 10656 times.
1024456 if (put_bytes_left(&sc->pb, 0) < w * 4) {
66 ✗ av_log(logctx, AV_LOG_ERROR, "encoded Golomb Rice frame too large\n");
67 ✗ return AVERROR_INVALIDDATA;
68 }
69 }
70
71
4/4
encode_line:
✓ Branch 53 → 28 taken 360557500 times.
✓ Branch 53 → 54 taken 2483400 times.
encode_line32:
✓ Branch 53 → 28 taken 49451352 times.
✓ Branch 53 → 54 taken 280056 times.
412772308 for (x = 0; x < w; x++) {
72 int diff, context;
73
74 410008852 context = RENAME(get_context)(f->quant_tables[p->quant_table_index],
75 410008852 sample[0] + x, sample[1] + x, sample[2] + x);
76 410008852 diff = sample[0][x] - RENAME(predict)(sample[0] + x, sample[1] + x);
77
78
4/4
encode_line:
✓ Branch 30 → 31 taken 161256200 times.
✓ Branch 30 → 32 taken 199301300 times.
encode_line32:
✓ Branch 30 → 31 taken 22904421 times.
✓ Branch 30 → 32 taken 26546931 times.
410008852 if (context < 0) {
79 184160621 context = -context;
80 184160621 diff = -diff;
81 }
82
83 410008852 diff = fold(diff, bits);
84
85
4/4
encode_line:
✓ Branch 33 → 34 taken 192410800 times.
✓ Branch 33 → 37 taken 168146700 times.
encode_line32:
✓ Branch 33 → 34 taken 45792600 times.
✓ Branch 33 → 37 taken 3658752 times.
410008852 if (ac != AC_GOLOMB_RICE) {
86
3/4
encode_line:
✓ Branch 34 → 35 taken 53431600 times.
✓ Branch 34 → 36 taken 138979200 times.
encode_line32:
✗ Branch 34 → 35 not taken.
✓ Branch 34 → 36 taken 45792600 times.
238203400 if (pass1) {
87 53431600 put_symbol_inline(c, p->state[context], diff, 1, sc->rc_stat,
88 53431600 sc->rc_stat2[p->quant_table_index][context]);
89 } else {
90 184771800 put_symbol_inline(c, p->state[context], diff, 1, NULL, NULL);
91 }
92 } else {
93
4/4
encode_line:
✓ Branch 37 → 38 taken 3890915 times.
✓ Branch 37 → 39 taken 164255785 times.
encode_line32:
✓ Branch 37 → 38 taken 2673472 times.
✓ Branch 37 → 39 taken 985280 times.
171805452 if (context == 0)
94 6564387 run_mode = 1;
95
96
4/4
encode_line:
✓ Branch 39 → 40 taken 6062596 times.
✓ Branch 39 → 50 taken 162084104 times.
encode_line32:
✓ Branch 39 → 40 taken 2700786 times.
✓ Branch 39 → 50 taken 957966 times.
171805452 if (run_mode) {
97
4/4
encode_line:
✓ Branch 40 → 41 taken 1575887 times.
✓ Branch 40 → 49 taken 4486709 times.
encode_line32:
✓ Branch 40 → 41 taken 3588 times.
✓ Branch 40 → 49 taken 2697198 times.
8763382 if (diff) {
98
4/4
encode_line:
✓ Branch 43 → 42 taken 1413677 times.
✓ Branch 43 → 44 taken 1575887 times.
encode_line32:
✓ Branch 43 → 42 taken 933 times.
✓ Branch 43 → 44 taken 3588 times.
2994085 while (run_count >= 1 << ff_log2_run[run_index]) {
99 1414610 run_count -= 1 << ff_log2_run[run_index];
100 1414610 run_index++;
101 1414610 put_bits(&sc->pb, 1, 1);
102 }
103
104 1579475 put_bits(&sc->pb, 1 + ff_log2_run[run_index], run_count);
105
4/4
encode_line:
✓ Branch 45 → 46 taken 1439479 times.
✓ Branch 45 → 47 taken 136408 times.
encode_line32:
✓ Branch 45 → 46 taken 3440 times.
✓ Branch 45 → 47 taken 148 times.
1579475 if (run_index)
106 1442919 run_index--;
107 1579475 run_count = 0;
108 1579475 run_mode = 0;
109
4/4
encode_line:
✓ Branch 47 → 48 taken 740677 times.
✓ Branch 47 → 50 taken 835210 times.
encode_line32:
✓ Branch 47 → 48 taken 1166 times.
✓ Branch 47 → 50 taken 2422 times.
1579475 if (diff > 0)
110 741843 diff--;
111 } else {
112 7183907 run_count++;
113 }
114 }
115
116 ff_dlog(logctx, "count:%d index:%d, mode:%d, x:%d pos:%d\n",
117 run_count, run_index, run_mode, x,
118 (int)put_bits_count(&sc->pb));
119
120
4/4
encode_line:
✓ Branch 50 → 51 taken 163659991 times.
✓ Branch 50 → 52 taken 4486709 times.
encode_line32:
✓ Branch 50 → 51 taken 961554 times.
✓ Branch 50 → 52 taken 2697198 times.
171805452 if (run_mode == 0)
121 164621545 put_vlc_symbol(&sc->pb, &p->vlc_state[context], diff, bits);
122 }
123 }
124
4/4
encode_line:
✓ Branch 54 → 55 taken 57502 times.
✓ Branch 54 → 60 taken 2425898 times.
encode_line32:
✓ Branch 54 → 55 taken 7891 times.
✓ Branch 54 → 60 taken 272165 times.
2763456 if (run_mode) {
125
4/4
encode_line:
✓ Branch 57 → 56 taken 43475 times.
✓ Branch 57 → 58 taken 57502 times.
encode_line32:
✓ Branch 57 → 56 taken 2870 times.
✓ Branch 57 → 58 taken 7891 times.
111738 while (run_count >= 1 << ff_log2_run[run_index]) {
126 46345 run_count -= 1 << ff_log2_run[run_index];
127 46345 run_index++;
128 46345 put_bits(&sc->pb, 1, 1);
129 }
130
131
4/4
encode_line:
✓ Branch 58 → 59 taken 37708 times.
✓ Branch 58 → 60 taken 19794 times.
encode_line32:
✓ Branch 58 → 59 taken 7809 times.
✓ Branch 58 → 60 taken 82 times.
65393 if (run_count)
132 45517 put_bits(&sc->pb, 1, 1);
133 }
134 2763456 sc->run_index = run_index;
135
136 2763456 return 0;
137 }
138
139 ✗ static void RENAME(load_rgb_frame)(FFV1Context *f, FFV1SliceContext *sc,
140 const uint8_t *src[4],
141 int w, int h, const int stride[4])
142 {
143 int x, y;
144 ✗ int transparency = f->transparency;
145
146
0/4
load_rgb_frame:
✗ Branch 4 → 3 not taken.
✗ Branch 4 → 5 not taken.
load_rgb_frame32:
✗ Branch 4 → 3 not taken.
✗ Branch 4 → 5 not taken.
✗ for (int p = 0; p<3 + transparency; p++)
147 ✗ memset(sc->fltmap[p], 0, 65536 * sizeof(**sc->fltmap));
148
149
0/4
load_rgb_frame:
✗ Branch 16 → 6 not taken.
✗ Branch 16 → 17 not taken.
load_rgb_frame32:
✗ Branch 14 → 6 not taken.
✗ Branch 14 → 15 not taken.
✗ for (y = 0; y < h; y++) {
150
0/4
load_rgb_frame:
✗ Branch 14 → 7 not taken.
✗ Branch 14 → 15 not taken.
load_rgb_frame32:
✗ Branch 12 → 7 not taken.
✗ Branch 12 → 13 not taken.
✗ for (x = 0; x < w; x++) {
151 ✗ int b, g, r, av_uninit(a);
152
153
0/2
✗ Branch 7 → 8 not taken.
✗ Branch 7 → 10 not taken.
✗ if (sizeof(TYPE) == 4 || transparency) {
154 ✗ g = *((const uint16_t *)(src[0] + x*2 + stride[0]*y));
155 ✗ b = *((const uint16_t *)(src[1] + x*2 + stride[1]*y));
156 ✗ r = *((const uint16_t *)(src[2] + x*2 + stride[2]*y));
157
0/4
load_rgb_frame:
✗ Branch 8 → 9 not taken.
✗ Branch 8 → 11 not taken.
load_rgb_frame32:
✗ Branch 7 → 8 not taken.
✗ Branch 7 → 9 not taken.
✗ if (transparency)
158 ✗ a = *((const uint16_t *)(src[3] + x*2 + stride[3]*y));
159 } else {
160 ✗ b = *((const uint16_t *)(src[0] + x*2 + stride[0]*y));
161 ✗ g = *((const uint16_t *)(src[1] + x*2 + stride[1]*y));
162 ✗ r = *((const uint16_t *)(src[2] + x*2 + stride[2]*y));
163 }
164
165 ✗ sc->fltmap[0][g] = 1;
166 ✗ sc->fltmap[1][b] = 1;
167 ✗ sc->fltmap[2][r] = 1;
168
0/4
load_rgb_frame:
✗ Branch 11 → 12 not taken.
✗ Branch 11 → 13 not taken.
load_rgb_frame32:
✗ Branch 9 → 10 not taken.
✗ Branch 9 → 11 not taken.
✗ if (transparency)
169 ✗ sc->fltmap[3][a] = 1;
170 }
171 }
172 ✗ }
173
174 1600 static int RENAME(encode_rgb_frame)(FFV1Context *f, FFV1SliceContext *sc,
175 const uint8_t *src[4],
176 int w, int h, const int stride[4], int ac)
177 {
178 int x, y, p, i;
179
2/4
encode_rgb_frame:
✗ Branch 2 → 3 not taken.
✓ Branch 2 → 4 taken 800 times.
encode_rgb_frame32:
✗ Branch 2 → 3 not taken.
✓ Branch 2 → 4 taken 800 times.
1600 const int ring_size = f->context_model ? 3 : 2;
180 TYPE *sample[4][3];
181 1600 const int pass1 = !!(f->avctx->flags & AV_CODEC_FLAG_PASS1);
182 1600 int lbd = f->bits_per_raw_sample <= 8;
183 1600 int packed = !src[1];
184 int bits[4], offset;
185 1600 int transparency = f->transparency;
186 1600 int packed_size = (3 + transparency)*2;
187
188 1600 ff_ffv1_compute_bits_per_plane(f, sc, bits, &offset, NULL, f->bits_per_raw_sample);
189
190 1600 sc->run_index = 0;
191
192
4/4
encode_rgb_frame:
✓ Branch 8 → 7 taken 3200 times.
✓ Branch 8 → 9 taken 800 times.
encode_rgb_frame32:
✓ Branch 8 → 7 taken 3200 times.
✓ Branch 8 → 9 taken 800 times.
8000 for (int p = 0; p < MAX_PLANES; ++p)
193 6400 sample[p][2] = RENAME(sc->sample_buffer);
194
195 1600 memset(RENAME(sc->sample_buffer), 0, ring_size * MAX_PLANES *
196 1600 (w + 6) * sizeof(*RENAME(sc->sample_buffer)));
197
198
4/4
encode_rgb_frame:
✓ Branch 42 → 10 taken 89800 times.
✓ Branch 42 → 43 taken 800 times.
encode_rgb_frame32:
✓ Branch 40 → 10 taken 89800 times.
✓ Branch 40 → 41 taken 800 times.
181200 for (y = 0; y < h; y++) {
199
4/4
encode_rgb_frame:
✓ Branch 15 → 11 taken 179600 times.
✓ Branch 15 → 16 taken 89800 times.
encode_rgb_frame32:
✓ Branch 15 → 11 taken 179600 times.
✓ Branch 15 → 16 taken 89800 times.
538800 for (i = 0; i < ring_size; i++)
200
4/4
encode_rgb_frame:
✓ Branch 13 → 12 taken 718400 times.
✓ Branch 13 → 14 taken 179600 times.
encode_rgb_frame32:
✓ Branch 13 → 12 taken 718400 times.
✓ Branch 13 → 14 taken 179600 times.
1796000 for (p = 0; p < MAX_PLANES; p++)
201 1436800 sample[p][i]= RENAME(sc->sample_buffer) + p*ring_size*(w+6) + ((h+i-y)%ring_size)*(w+6) + 3;
202
203
4/4
encode_rgb_frame:
✓ Branch 32 → 17 taken 15264200 times.
✓ Branch 32 → 33 taken 89800 times.
encode_rgb_frame32:
✓ Branch 30 → 17 taken 15264200 times.
✓ Branch 30 → 31 taken 89800 times.
30708000 for (x = 0; x < w; x++) {
204 30528400 int b, g, r, av_uninit(a);
205
2/4
encode_rgb_frame:
✓ Branch 17 → 18 taken 15264200 times.
✗ Branch 17 → 19 not taken.
encode_rgb_frame32:
✗ Branch 17 → 18 not taken.
✓ Branch 17 → 19 taken 15264200 times.
30528400 if (lbd) {
206 15264200 unsigned v = *((const uint32_t*)(src[0] + x*4 + stride[0]*y));
207 15264200 b = v & 0xFF;
208 15264200 g = (v >> 8) & 0xFF;
209 15264200 r = (v >> 16) & 0xFF;
210 15264200 a = v >> 24;
211
1/4
encode_rgb_frame:
✗ Branch 19 → 20 not taken.
✗ Branch 19 → 22 not taken.
encode_rgb_frame32:
✓ Branch 19 → 20 taken 15264200 times.
✗ Branch 19 → 22 not taken.
15264200 } else if (packed) {
212 15264200 const uint16_t *p = ((const uint16_t*)(src[0] + x*packed_size + stride[0]*y));
213 15264200 r = p[0];
214 15264200 g = p[1];
215 15264200 b = p[2];
216
1/4
encode_rgb_frame:
✗ Branch 20 → 21 not taken.
✗ Branch 20 → 26 not taken.
encode_rgb_frame32:
✗ Branch 20 → 21 not taken.
✓ Branch 20 → 24 taken 15264200 times.
15264200 if (transparency)
217 ✗ a = p[3];
218
0/2
✗ Branch 22 → 23 not taken.
✗ Branch 22 → 25 not taken.
✗ } else if (sizeof(TYPE) == 4 || transparency) {
219 ✗ g = *((const uint16_t *)(src[0] + x*2 + stride[0]*y));
220 ✗ b = *((const uint16_t *)(src[1] + x*2 + stride[1]*y));
221 ✗ r = *((const uint16_t *)(src[2] + x*2 + stride[2]*y));
222
0/4
encode_rgb_frame:
✗ Branch 23 → 24 not taken.
✗ Branch 23 → 26 not taken.
encode_rgb_frame32:
✗ Branch 22 → 23 not taken.
✗ Branch 22 → 24 not taken.
✗ if (transparency)
223 ✗ a = *((const uint16_t *)(src[3] + x*2 + stride[3]*y));
224 } else {
225 ✗ b = *((const uint16_t *)(src[0] + x*2 + stride[0]*y));
226 ✗ g = *((const uint16_t *)(src[1] + x*2 + stride[1]*y));
227 ✗ r = *((const uint16_t *)(src[2] + x*2 + stride[2]*y));
228 }
229
230
2/4
encode_rgb_frame:
✗ Branch 26 → 27 not taken.
✓ Branch 26 → 29 taken 15264200 times.
encode_rgb_frame32:
✗ Branch 24 → 25 not taken.
✓ Branch 24 → 27 taken 15264200 times.
30528400 if (sc->remap) {
231 ✗ g = sc->fltmap[0][g];
232 ✗ b = sc->fltmap[1][b];
233 ✗ r = sc->fltmap[2][r];
234
0/4
encode_rgb_frame:
✗ Branch 27 → 28 not taken.
✗ Branch 27 → 29 not taken.
encode_rgb_frame32:
✗ Branch 25 → 26 not taken.
✗ Branch 25 → 27 not taken.
✗ if (transparency)
235 ✗ a = sc->fltmap[3][a];
236 }
237
238
2/4
encode_rgb_frame:
✓ Branch 29 → 30 taken 15264200 times.
✗ Branch 29 → 31 not taken.
encode_rgb_frame32:
✓ Branch 27 → 28 taken 15264200 times.
✗ Branch 27 → 29 not taken.
30528400 if (sc->slice_coding_mode != 1) {
239 30528400 b -= g;
240 30528400 r -= g;
241 30528400 g += (b * sc->slice_rct_by_coef + r * sc->slice_rct_ry_coef) >> 2;
242 30528400 b += offset;
243 30528400 r += offset;
244 }
245
246 30528400 sample[0][0][x] = g;
247 30528400 sample[1][0][x] = b;
248 30528400 sample[2][0][x] = r;
249 30528400 sample[3][0][x] = a;
250 }
251
4/4
encode_rgb_frame:
✓ Branch 40 → 34 taken 269400 times.
✓ Branch 40 → 41 taken 89800 times.
encode_rgb_frame32:
✓ Branch 38 → 32 taken 269400 times.
✓ Branch 38 → 39 taken 89800 times.
718400 for (p = 0; p < 3 + transparency; p++) {
252 int ret;
253 538800 sample[p][0][-1] = sample[p][1][0 ];
254 538800 sample[p][1][ w] = sample[p][1][w-1];
255
2/4
encode_rgb_frame:
✓ Branch 34 → 35 taken 269400 times.
✗ Branch 34 → 36 not taken.
encode_rgb_frame32:
✗ Branch 32 → 33 not taken.
✓ Branch 32 → 34 taken 269400 times.
538800 if (bits[p] == 9)
256 269400 ret = RENAME(encode_line)(f, sc, f->avctx, w, sample[p], (p + 1) / 2, 9, ac, pass1);
257 else
258 269400 ret = RENAME(encode_line)(f, sc, f->avctx, w, sample[p], (p + 1) / 2,
259 bits[p], ac, pass1);
260
2/4
encode_rgb_frame:
✗ Branch 37 → 38 not taken.
✓ Branch 37 → 39 taken 269400 times.
encode_rgb_frame32:
✗ Branch 35 → 36 not taken.
✓ Branch 35 → 37 taken 269400 times.
538800 if (ret < 0)
261 ✗ return ret;
262 }
263 }
264 1600 return 0;
265 }
266