FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/ffv1enc_template.c
Date: 2024-03-29 01:21:52
Exec Total Coverage
Lines: 96 117 82.1%
Functions: 2 2 100.0%
Branches: 33 40 82.5%

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 3989200 static av_always_inline int RENAME(encode_line)(FFV1Context *s, int w,
26 TYPE *sample[3],
27 int plane_index, int bits)
28 {
29 3989200 PlaneContext *const p = &s->plane[plane_index];
30 3989200 RangeCoder *const c = &s->c;
31 int x;
32 3989200 int run_index = s->run_index;
33 3989200 int run_count = 0;
34 3989200 int run_mode = 0;
35
36
2/2
✓ Branch 0 taken 1189400 times.
✓ Branch 1 taken 805200 times.
3989200 if (s->ac != AC_GOLOMB_RICE) {
37
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1189400 times.
2378800 if (c->bytestream_end - c->bytestream < w * 35) {
38 av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\n");
39 return AVERROR_INVALIDDATA;
40 }
41 } else {
42
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 805200 times.
1610400 if (put_bytes_left(&s->pb, 0) < w * 4) {
43 av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\n");
44 return AVERROR_INVALIDDATA;
45 }
46 }
47
48
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1994600 times.
3989200 if (s->slice_coding_mode == 1) {
49 for (x = 0; x < w; x++) {
50 int i;
51 int v = sample[0][x];
52 for (i = bits-1; i>=0; i--) {
53 uint8_t state = 128;
54 put_rac(c, &state, (v>>i) & 1);
55 }
56 }
57 return 0;
58 }
59
60
2/2
✓ Branch 0 taken 322379500 times.
✓ Branch 1 taken 1994600 times.
648748200 for (x = 0; x < w; x++) {
61 int diff, context;
62
63 644759000 context = RENAME(get_context)(p, sample[0] + x, sample[1] + x, sample[2] + x);
64 644759000 diff = sample[0][x] - RENAME(predict)(sample[0] + x, sample[1] + x);
65
66
2/2
✓ Branch 0 taken 140190903 times.
✓ Branch 1 taken 182188597 times.
644759000 if (context < 0) {
67 280381806 context = -context;
68 280381806 diff = -diff;
69 }
70
71 644759000 diff = fold(diff, bits);
72
73
2/2
✓ Branch 0 taken 177132600 times.
✓ Branch 1 taken 145246900 times.
644759000 if (s->ac != AC_GOLOMB_RICE) {
74
2/2
✓ Branch 0 taken 22899800 times.
✓ Branch 1 taken 154232800 times.
354265200 if (s->flags & AV_CODEC_FLAG_PASS1) {
75 45799600 put_symbol_inline(c, p->state[context], diff, 1, s->rc_stat,
76 45799600 s->rc_stat2[p->quant_table_index][context]);
77 } else {
78 308465600 put_symbol_inline(c, p->state[context], diff, 1, NULL, NULL);
79 }
80 } else {
81
2/2
✓ Branch 0 taken 4100641 times.
✓ Branch 1 taken 141146259 times.
290493800 if (context == 0)
82 8201282 run_mode = 1;
83
84
2/2
✓ Branch 0 taken 6473429 times.
✓ Branch 1 taken 138773471 times.
290493800 if (run_mode) {
85
2/2
✓ Branch 0 taken 1542410 times.
✓ Branch 1 taken 4931019 times.
12946858 if (diff) {
86
2/2
✓ Branch 0 taken 1398825 times.
✓ Branch 1 taken 1542410 times.
5882470 while (run_count >= 1 << ff_log2_run[run_index]) {
87 2797650 run_count -= 1 << ff_log2_run[run_index];
88 2797650 run_index++;
89 2797650 put_bits(&s->pb, 1, 1);
90 }
91
92 3084820 put_bits(&s->pb, 1 + ff_log2_run[run_index], run_count);
93
2/2
✓ Branch 0 taken 1436005 times.
✓ Branch 1 taken 106405 times.
3084820 if (run_index)
94 2872010 run_index--;
95 3084820 run_count = 0;
96 3084820 run_mode = 0;
97
2/2
✓ Branch 0 taken 712297 times.
✓ Branch 1 taken 830113 times.
3084820 if (diff > 0)
98 1424594 diff--;
99 } else {
100 9862038 run_count++;
101 }
102 }
103
104 ff_dlog(s->avctx, "count:%d index:%d, mode:%d, x:%d pos:%d\n",
105 run_count, run_index, run_mode, x,
106 (int)put_bits_count(&s->pb));
107
108
2/2
✓ Branch 0 taken 140315881 times.
✓ Branch 1 taken 4931019 times.
290493800 if (run_mode == 0)
109 280631762 put_vlc_symbol(&s->pb, &p->vlc_state[context], diff, bits);
110 }
111 }
112
2/2
✓ Branch 0 taken 59878 times.
✓ Branch 1 taken 1934722 times.
3989200 if (run_mode) {
113
2/2
✓ Branch 0 taken 49789 times.
✓ Branch 1 taken 59878 times.
219334 while (run_count >= 1 << ff_log2_run[run_index]) {
114 99578 run_count -= 1 << ff_log2_run[run_index];
115 99578 run_index++;
116 99578 put_bits(&s->pb, 1, 1);
117 }
118
119
2/2
✓ Branch 0 taken 41216 times.
✓ Branch 1 taken 18662 times.
119756 if (run_count)
120 82432 put_bits(&s->pb, 1, 1);
121 }
122 3989200 s->run_index = run_index;
123
124 3989200 return 0;
125 }
126
127 1600 static int RENAME(encode_rgb_frame)(FFV1Context *s, const uint8_t *src[4],
128 int w, int h, const int stride[4])
129 {
130 int x, y, p, i;
131 1600 const int ring_size = s->context_model ? 3 : 2;
132 TYPE *sample[4][3];
133 1600 int lbd = s->bits_per_raw_sample <= 8;
134 1600 int packed = !src[1];
135 1600 int bits = s->bits_per_raw_sample > 0 ? s->bits_per_raw_sample : 8;
136 1600 int offset = 1 << bits;
137 1600 int transparency = s->transparency;
138 1600 int packed_size = (3 + transparency)*2;
139
140 1600 s->run_index = 0;
141
142 1600 memset(RENAME(s->sample_buffer), 0, ring_size * MAX_PLANES *
143 1600 (w + 6) * sizeof(*RENAME(s->sample_buffer)));
144
145 181200 for (y = 0; y < h; y++) {
146 538800 for (i = 0; i < ring_size; i++)
147 1796000 for (p = 0; p < MAX_PLANES; p++)
148 1436800 sample[p][i]= RENAME(s->sample_buffer) + p*ring_size*(w+6) + ((h+i-y)%ring_size)*(w+6) + 3;
149
150 30708000 for (x = 0; x < w; x++) {
151 30528400 int b, g, r, av_uninit(a);
152 30528400 if (lbd) {
153 15264200 unsigned v = *((const uint32_t*)(src[0] + x*4 + stride[0]*y));
154 15264200 b = v & 0xFF;
155 15264200 g = (v >> 8) & 0xFF;
156 15264200 r = (v >> 16) & 0xFF;
157 15264200 a = v >> 24;
158 15264200 } else if (packed) {
159 15264200 const uint16_t *p = ((const uint16_t*)(src[0] + x*packed_size + stride[0]*y));
160 15264200 r = p[0];
161 15264200 g = p[1];
162 15264200 b = p[2];
163 15264200 if (transparency)
164 a = p[3];
165 } else if (sizeof(TYPE) == 4 || transparency) {
166 g = *((const uint16_t *)(src[0] + x*2 + stride[0]*y));
167 b = *((const uint16_t *)(src[1] + x*2 + stride[1]*y));
168 r = *((const uint16_t *)(src[2] + x*2 + stride[2]*y));
169 if (transparency)
170 a = *((const uint16_t *)(src[3] + x*2 + stride[3]*y));
171 } else {
172 b = *((const uint16_t *)(src[0] + x*2 + stride[0]*y));
173 g = *((const uint16_t *)(src[1] + x*2 + stride[1]*y));
174 r = *((const uint16_t *)(src[2] + x*2 + stride[2]*y));
175 }
176
177 30528400 if (s->slice_coding_mode != 1) {
178 30528400 b -= g;
179 30528400 r -= g;
180 30528400 g += (b * s->slice_rct_by_coef + r * s->slice_rct_ry_coef) >> 2;
181 30528400 b += offset;
182 30528400 r += offset;
183 }
184
185 30528400 sample[0][0][x] = g;
186 30528400 sample[1][0][x] = b;
187 30528400 sample[2][0][x] = r;
188 30528400 sample[3][0][x] = a;
189 }
190 718400 for (p = 0; p < 3 + transparency; p++) {
191 int ret;
192 538800 sample[p][0][-1] = sample[p][1][0 ];
193 538800 sample[p][1][ w] = sample[p][1][w-1];
194 538800 if (lbd && s->slice_coding_mode == 0)
195 269400 ret = RENAME(encode_line)(s, w, sample[p], (p + 1) / 2, 9);
196 else
197 269400 ret = RENAME(encode_line)(s, w, sample[p], (p + 1) / 2, bits + (s->slice_coding_mode != 1));
198 538800 if (ret < 0)
199 return ret;
200 }
201 }
202 1600 return 0;
203 }
204
205