Coverage Report

Created: 2026-02-14 06:59

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/ffmpeg/libavcodec/ffv1enc_template.c
Line
Count
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
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
18.3M
{
31
18.3M
    PlaneContext *const p = &sc->plane[plane_index];
32
18.3M
    RangeCoder *const c   = &sc->c;
33
18.3M
    int x;
34
18.3M
    int run_index = sc->run_index;
35
18.3M
    int run_count = 0;
36
18.3M
    int run_mode  = 0;
37
38
18.3M
    if (bits == 0)
39
834k
        return 0;
40
41
17.5M
    if (sc->slice_coding_mode == 1) {
42
22.7k
        av_assert0(ac != AC_GOLOMB_RICE);
43
22.7k
        if (c->bytestream_end - c->bytestream < (w * bits + 7LL)>>3) {
44
0
            av_log(logctx, AV_LOG_ERROR, "encoded Range Coder frame too large\n");
45
0
            return AVERROR_INVALIDDATA;
46
0
        }
47
48
33.9M
        for (x = 0; x < w; x++) {
49
33.9M
            int i;
50
33.9M
            int v = sample[0][x];
51
452M
            for (i = bits-1; i>=0; i--) {
52
419M
                uint8_t state = 128;
53
419M
                put_rac(c, &state, (v>>i) & 1);
54
419M
            }
55
33.9M
        }
56
22.7k
        return 0;
57
22.7k
    }
58
59
17.5M
    if (ac != AC_GOLOMB_RICE) {
60
12.8M
        if (c->bytestream_end - c->bytestream < w * 35) {
61
2.54k
            av_log(logctx, AV_LOG_ERROR, "encoded Range Coder frame too large\n");
62
2.54k
            return AVERROR_INVALIDDATA;
63
2.54k
        }
64
12.8M
    } else {
65
4.70M
        if (put_bytes_left(&sc->pb, 0) < w * 4) {
66
0
            av_log(logctx, AV_LOG_ERROR, "encoded Golomb Rice frame too large\n");
67
0
            return AVERROR_INVALIDDATA;
68
0
        }
69
4.70M
    }
70
71
575M
    for (x = 0; x < w; x++) {
72
558M
        int diff, context;
73
74
558M
        context = RENAME(get_context)(f->quant_tables[p->quant_table_index],
75
558M
                                      sample[0] + x, sample[1] + x, sample[2] + x);
76
558M
        diff    = sample[0][x] - RENAME(predict)(sample[0] + x, sample[1] + x);
77
78
558M
        if (context < 0) {
79
26.7M
            context = -context;
80
26.7M
            diff    = -diff;
81
26.7M
        }
82
83
558M
        diff = fold(diff, bits);
84
85
558M
        if (ac != AC_GOLOMB_RICE) {
86
437M
            if (pass1) {
87
0
                put_symbol_inline(c, p->state[context], diff, 1, sc->rc_stat,
88
0
                                  sc->rc_stat2[p->quant_table_index][context]);
89
437M
            } else {
90
437M
                put_symbol_inline(c, p->state[context], diff, 1, NULL, NULL);
91
437M
            }
92
437M
        } else {
93
121M
            if (context == 0)
94
99.8M
                run_mode = 1;
95
96
121M
            if (run_mode) {
97
100M
                if (diff) {
98
823k
                    while (run_count >= 1 << ff_log2_run[run_index]) {
99
229k
                        run_count -= 1 << ff_log2_run[run_index];
100
229k
                        run_index++;
101
229k
                        put_bits(&sc->pb, 1, 1);
102
229k
                    }
103
104
594k
                    put_bits(&sc->pb, 1 + ff_log2_run[run_index], run_count);
105
594k
                    if (run_index)
106
307k
                        run_index--;
107
594k
                    run_count = 0;
108
594k
                    run_mode  = 0;
109
594k
                    if (diff > 0)
110
341k
                        diff--;
111
99.8M
                } else {
112
99.8M
                    run_count++;
113
99.8M
                }
114
100M
            }
115
116
121M
            ff_dlog(logctx, "count:%d index:%d, mode:%d, x:%d pos:%d\n",
117
121M
                    run_count, run_index, run_mode, x,
118
121M
                    (int)put_bits_count(&sc->pb));
119
120
121M
            if (run_mode == 0)
121
21.2M
                put_vlc_symbol(&sc->pb, &p->vlc_state[context], diff, bits);
122
121M
        }
123
558M
    }
124
17.5M
    if (run_mode) {
125
4.75M
        while (run_count >= 1 << ff_log2_run[run_index]) {
126
325k
            run_count -= 1 << ff_log2_run[run_index];
127
325k
            run_index++;
128
325k
            put_bits(&sc->pb, 1, 1);
129
325k
        }
130
131
4.42M
        if (run_count)
132
4.35M
            put_bits(&sc->pb, 1, 1);
133
4.42M
    }
134
17.5M
    sc->run_index = run_index;
135
136
17.5M
    return 0;
137
17.5M
}
ffv1enc.c:encode_line
Line
Count
Source
30
9.74M
{
31
9.74M
    PlaneContext *const p = &sc->plane[plane_index];
32
9.74M
    RangeCoder *const c   = &sc->c;
33
9.74M
    int x;
34
9.74M
    int run_index = sc->run_index;
35
9.74M
    int run_count = 0;
36
9.74M
    int run_mode  = 0;
37
38
9.74M
    if (bits == 0)
39
0
        return 0;
40
41
9.74M
    if (sc->slice_coding_mode == 1) {
42
1.28k
        av_assert0(ac != AC_GOLOMB_RICE);
43
1.28k
        if (c->bytestream_end - c->bytestream < (w * bits + 7LL)>>3) {
44
0
            av_log(logctx, AV_LOG_ERROR, "encoded Range Coder frame too large\n");
45
0
            return AVERROR_INVALIDDATA;
46
0
        }
47
48
11.1M
        for (x = 0; x < w; x++) {
49
11.1M
            int i;
50
11.1M
            int v = sample[0][x];
51
189M
            for (i = bits-1; i>=0; i--) {
52
178M
                uint8_t state = 128;
53
178M
                put_rac(c, &state, (v>>i) & 1);
54
178M
            }
55
11.1M
        }
56
1.28k
        return 0;
57
1.28k
    }
58
59
9.74M
    if (ac != AC_GOLOMB_RICE) {
60
7.36M
        if (c->bytestream_end - c->bytestream < w * 35) {
61
508
            av_log(logctx, AV_LOG_ERROR, "encoded Range Coder frame too large\n");
62
508
            return AVERROR_INVALIDDATA;
63
508
        }
64
7.36M
    } else {
65
2.37M
        if (put_bytes_left(&sc->pb, 0) < w * 4) {
66
0
            av_log(logctx, AV_LOG_ERROR, "encoded Golomb Rice frame too large\n");
67
0
            return AVERROR_INVALIDDATA;
68
0
        }
69
2.37M
    }
70
71
223M
    for (x = 0; x < w; x++) {
72
213M
        int diff, context;
73
74
213M
        context = RENAME(get_context)(f->quant_tables[p->quant_table_index],
75
213M
                                      sample[0] + x, sample[1] + x, sample[2] + x);
76
213M
        diff    = sample[0][x] - RENAME(predict)(sample[0] + x, sample[1] + x);
77
78
213M
        if (context < 0) {
79
5.01M
            context = -context;
80
5.01M
            diff    = -diff;
81
5.01M
        }
82
83
213M
        diff = fold(diff, bits);
84
85
213M
        if (ac != AC_GOLOMB_RICE) {
86
163M
            if (pass1) {
87
0
                put_symbol_inline(c, p->state[context], diff, 1, sc->rc_stat,
88
0
                                  sc->rc_stat2[p->quant_table_index][context]);
89
163M
            } else {
90
163M
                put_symbol_inline(c, p->state[context], diff, 1, NULL, NULL);
91
163M
            }
92
163M
        } else {
93
50.0M
            if (context == 0)
94
47.1M
                run_mode = 1;
95
96
50.0M
            if (run_mode) {
97
47.1M
                if (diff) {
98
387k
                    while (run_count >= 1 << ff_log2_run[run_index]) {
99
118k
                        run_count -= 1 << ff_log2_run[run_index];
100
118k
                        run_index++;
101
118k
                        put_bits(&sc->pb, 1, 1);
102
118k
                    }
103
104
269k
                    put_bits(&sc->pb, 1 + ff_log2_run[run_index], run_count);
105
269k
                    if (run_index)
106
145k
                        run_index--;
107
269k
                    run_count = 0;
108
269k
                    run_mode  = 0;
109
269k
                    if (diff > 0)
110
169k
                        diff--;
111
46.8M
                } else {
112
46.8M
                    run_count++;
113
46.8M
                }
114
47.1M
            }
115
116
50.0M
            ff_dlog(logctx, "count:%d index:%d, mode:%d, x:%d pos:%d\n",
117
50.0M
                    run_count, run_index, run_mode, x,
118
50.0M
                    (int)put_bits_count(&sc->pb));
119
120
50.0M
            if (run_mode == 0)
121
3.14M
                put_vlc_symbol(&sc->pb, &p->vlc_state[context], diff, bits);
122
50.0M
        }
123
213M
    }
124
9.74M
    if (run_mode) {
125
2.47M
        while (run_count >= 1 << ff_log2_run[run_index]) {
126
237k
            run_count -= 1 << ff_log2_run[run_index];
127
237k
            run_index++;
128
237k
            put_bits(&sc->pb, 1, 1);
129
237k
        }
130
131
2.23M
        if (run_count)
132
2.17M
            put_bits(&sc->pb, 1, 1);
133
2.23M
    }
134
9.74M
    sc->run_index = run_index;
135
136
9.74M
    return 0;
137
9.74M
}
ffv1enc.c:encode_line32
Line
Count
Source
30
8.63M
{
31
8.63M
    PlaneContext *const p = &sc->plane[plane_index];
32
8.63M
    RangeCoder *const c   = &sc->c;
33
8.63M
    int x;
34
8.63M
    int run_index = sc->run_index;
35
8.63M
    int run_count = 0;
36
8.63M
    int run_mode  = 0;
37
38
8.63M
    if (bits == 0)
39
834k
        return 0;
40
41
7.79M
    if (sc->slice_coding_mode == 1) {
42
21.4k
        av_assert0(ac != AC_GOLOMB_RICE);
43
21.4k
        if (c->bytestream_end - c->bytestream < (w * bits + 7LL)>>3) {
44
0
            av_log(logctx, AV_LOG_ERROR, "encoded Range Coder frame too large\n");
45
0
            return AVERROR_INVALIDDATA;
46
0
        }
47
48
22.8M
        for (x = 0; x < w; x++) {
49
22.7M
            int i;
50
22.7M
            int v = sample[0][x];
51
263M
            for (i = bits-1; i>=0; i--) {
52
240M
                uint8_t state = 128;
53
240M
                put_rac(c, &state, (v>>i) & 1);
54
240M
            }
55
22.7M
        }
56
21.4k
        return 0;
57
21.4k
    }
58
59
7.77M
    if (ac != AC_GOLOMB_RICE) {
60
5.45M
        if (c->bytestream_end - c->bytestream < w * 35) {
61
2.04k
            av_log(logctx, AV_LOG_ERROR, "encoded Range Coder frame too large\n");
62
2.04k
            return AVERROR_INVALIDDATA;
63
2.04k
        }
64
5.45M
    } else {
65
2.32M
        if (put_bytes_left(&sc->pb, 0) < w * 4) {
66
0
            av_log(logctx, AV_LOG_ERROR, "encoded Golomb Rice frame too large\n");
67
0
            return AVERROR_INVALIDDATA;
68
0
        }
69
2.32M
    }
70
71
352M
    for (x = 0; x < w; x++) {
72
344M
        int diff, context;
73
74
344M
        context = RENAME(get_context)(f->quant_tables[p->quant_table_index],
75
344M
                                      sample[0] + x, sample[1] + x, sample[2] + x);
76
344M
        diff    = sample[0][x] - RENAME(predict)(sample[0] + x, sample[1] + x);
77
78
344M
        if (context < 0) {
79
21.7M
            context = -context;
80
21.7M
            diff    = -diff;
81
21.7M
        }
82
83
344M
        diff = fold(diff, bits);
84
85
344M
        if (ac != AC_GOLOMB_RICE) {
86
273M
            if (pass1) {
87
0
                put_symbol_inline(c, p->state[context], diff, 1, sc->rc_stat,
88
0
                                  sc->rc_stat2[p->quant_table_index][context]);
89
273M
            } else {
90
273M
                put_symbol_inline(c, p->state[context], diff, 1, NULL, NULL);
91
273M
            }
92
273M
        } else {
93
71.1M
            if (context == 0)
94
52.7M
                run_mode = 1;
95
96
71.1M
            if (run_mode) {
97
53.3M
                if (diff) {
98
436k
                    while (run_count >= 1 << ff_log2_run[run_index]) {
99
111k
                        run_count -= 1 << ff_log2_run[run_index];
100
111k
                        run_index++;
101
111k
                        put_bits(&sc->pb, 1, 1);
102
111k
                    }
103
104
325k
                    put_bits(&sc->pb, 1 + ff_log2_run[run_index], run_count);
105
325k
                    if (run_index)
106
161k
                        run_index--;
107
325k
                    run_count = 0;
108
325k
                    run_mode  = 0;
109
325k
                    if (diff > 0)
110
172k
                        diff--;
111
52.9M
                } else {
112
52.9M
                    run_count++;
113
52.9M
                }
114
53.3M
            }
115
116
71.1M
            ff_dlog(logctx, "count:%d index:%d, mode:%d, x:%d pos:%d\n",
117
71.1M
                    run_count, run_index, run_mode, x,
118
71.1M
                    (int)put_bits_count(&sc->pb));
119
120
71.1M
            if (run_mode == 0)
121
18.1M
                put_vlc_symbol(&sc->pb, &p->vlc_state[context], diff, bits);
122
71.1M
        }
123
344M
    }
124
7.77M
    if (run_mode) {
125
2.27M
        while (run_count >= 1 << ff_log2_run[run_index]) {
126
88.1k
            run_count -= 1 << ff_log2_run[run_index];
127
88.1k
            run_index++;
128
88.1k
            put_bits(&sc->pb, 1, 1);
129
88.1k
        }
130
131
2.18M
        if (run_count)
132
2.18M
            put_bits(&sc->pb, 1, 1);
133
2.18M
    }
134
7.77M
    sc->run_index = run_index;
135
136
7.77M
    return 0;
137
7.77M
}
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
5.20k
{
143
5.20k
    int x, y;
144
5.20k
    int transparency = f->transparency;
145
146
20.8k
    for (int p = 0; p<3 + transparency; p++)
147
15.6k
        memset(sc->fltmap[p], 0, 65536 * sizeof(**sc->fltmap));
148
149
448k
    for (y = 0; y < h; y++) {
150
67.3M
        for (x = 0; x < w; x++) {
151
66.9M
            int b, g, r, av_uninit(a);
152
153
66.9M
            if (sizeof(TYPE) == 4 || transparency) {
154
66.9M
                g = *((const uint16_t *)(src[0] + x*2 + stride[0]*y));
155
66.9M
                b = *((const uint16_t *)(src[1] + x*2 + stride[1]*y));
156
66.9M
                r = *((const uint16_t *)(src[2] + x*2 + stride[2]*y));
157
66.9M
                if (transparency)
158
0
                    a = *((const uint16_t *)(src[3] + x*2 + stride[3]*y));
159
66.9M
            } else {
160
0
                b = *((const uint16_t *)(src[0] + x*2 + stride[0]*y));
161
0
                g = *((const uint16_t *)(src[1] + x*2 + stride[1]*y));
162
0
                r = *((const uint16_t *)(src[2] + x*2 + stride[2]*y));
163
0
            }
164
165
66.9M
            sc->fltmap[0][g] = 1;
166
66.9M
            sc->fltmap[1][b] = 1;
167
66.9M
            sc->fltmap[2][r] = 1;
168
66.9M
            if (transparency)
169
0
                sc->fltmap[3][a] = 1;
170
66.9M
        }
171
443k
    }
172
5.20k
}
ffv1enc.c:load_rgb_frame32
Line
Count
Source
142
5.20k
{
143
5.20k
    int x, y;
144
5.20k
    int transparency = f->transparency;
145
146
20.8k
    for (int p = 0; p<3 + transparency; p++)
147
15.6k
        memset(sc->fltmap[p], 0, 65536 * sizeof(**sc->fltmap));
148
149
448k
    for (y = 0; y < h; y++) {
150
67.3M
        for (x = 0; x < w; x++) {
151
66.9M
            int b, g, r, av_uninit(a);
152
153
66.9M
            if (sizeof(TYPE) == 4 || transparency) {
154
66.9M
                g = *((const uint16_t *)(src[0] + x*2 + stride[0]*y));
155
66.9M
                b = *((const uint16_t *)(src[1] + x*2 + stride[1]*y));
156
66.9M
                r = *((const uint16_t *)(src[2] + x*2 + stride[2]*y));
157
66.9M
                if (transparency)
158
0
                    a = *((const uint16_t *)(src[3] + x*2 + stride[3]*y));
159
66.9M
            } else {
160
0
                b = *((const uint16_t *)(src[0] + x*2 + stride[0]*y));
161
0
                g = *((const uint16_t *)(src[1] + x*2 + stride[1]*y));
162
0
                r = *((const uint16_t *)(src[2] + x*2 + stride[2]*y));
163
0
            }
164
165
66.9M
            sc->fltmap[0][g] = 1;
166
66.9M
            sc->fltmap[1][b] = 1;
167
66.9M
            sc->fltmap[2][r] = 1;
168
66.9M
            if (transparency)
169
0
                sc->fltmap[3][a] = 1;
170
66.9M
        }
171
443k
    }
172
5.20k
}
Unexecuted instantiation: ffv1enc.c:load_rgb_frame
173
174
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
16.6k
{
178
16.6k
    int x, y, p, i;
179
16.6k
    const int ring_size = f->context_model ? 3 : 2;
180
16.6k
    TYPE *sample[4][3];
181
16.6k
    const int pass1 = !!(f->avctx->flags & AV_CODEC_FLAG_PASS1);
182
16.6k
    int lbd    = f->bits_per_raw_sample <= 8;
183
16.6k
    int packed = !src[1];
184
16.6k
    int bits[4], offset;
185
16.6k
    int transparency = f->transparency;
186
16.6k
    int packed_size = (3 + transparency)*2;
187
188
16.6k
    ff_ffv1_compute_bits_per_plane(f, sc, bits, &offset, NULL, f->bits_per_raw_sample);
189
190
16.6k
    sc->run_index = 0;
191
192
83.3k
    for (int p = 0; p < MAX_PLANES; ++p)
193
66.6k
        sample[p][2] = RENAME(sc->sample_buffer);
194
195
16.6k
    memset(RENAME(sc->sample_buffer), 0, ring_size * MAX_PLANES *
196
16.6k
           (w + 6) * sizeof(*RENAME(sc->sample_buffer)));
197
198
2.55M
    for (y = 0; y < h; y++) {
199
8.40M
        for (i = 0; i < ring_size; i++)
200
29.3M
            for (p = 0; p < MAX_PLANES; p++)
201
23.4M
                sample[p][i]= RENAME(sc->sample_buffer) + p*ring_size*(w+6) + ((h+i-y)%ring_size)*(w+6) + 3;
202
203
117M
        for (x = 0; x < w; x++) {
204
114M
            int b, g, r, av_uninit(a);
205
114M
            if (lbd) {
206
16.9M
                unsigned v = *((const uint32_t*)(src[0] + x*4 + stride[0]*y));
207
16.9M
                b =  v        & 0xFF;
208
16.9M
                g = (v >>  8) & 0xFF;
209
16.9M
                r = (v >> 16) & 0xFF;
210
16.9M
                a =  v >> 24;
211
97.6M
            } else if (packed) {
212
4.77M
                const uint16_t *p = ((const uint16_t*)(src[0] + x*packed_size + stride[0]*y));
213
4.77M
                r = p[0];
214
4.77M
                g = p[1];
215
4.77M
                b = p[2];
216
4.77M
                if (transparency)
217
2.12M
                  a = p[3];
218
92.8M
            } else if (sizeof(TYPE) == 4 || transparency) {
219
88.0M
                g = *((const uint16_t *)(src[0] + x*2 + stride[0]*y));
220
88.0M
                b = *((const uint16_t *)(src[1] + x*2 + stride[1]*y));
221
88.0M
                r = *((const uint16_t *)(src[2] + x*2 + stride[2]*y));
222
88.0M
                if (transparency)
223
17.0M
                    a = *((const uint16_t *)(src[3] + x*2 + stride[3]*y));
224
88.0M
            } else {
225
4.78M
                b = *((const uint16_t *)(src[0] + x*2 + stride[0]*y));
226
4.78M
                g = *((const uint16_t *)(src[1] + x*2 + stride[1]*y));
227
4.78M
                r = *((const uint16_t *)(src[2] + x*2 + stride[2]*y));
228
4.78M
            }
229
230
114M
            if (sc->remap) {
231
65.6M
                g = sc->fltmap[0][g];
232
65.6M
                b = sc->fltmap[1][b];
233
65.6M
                r = sc->fltmap[2][r];
234
65.6M
                if (transparency)
235
0
                    a = sc->fltmap[3][a];
236
65.6M
            }
237
238
114M
            if (sc->slice_coding_mode != 1) {
239
105M
                b -= g;
240
105M
                r -= g;
241
105M
                g += (b * sc->slice_rct_by_coef + r * sc->slice_rct_ry_coef) >> 2;
242
105M
                b += offset;
243
105M
                r += offset;
244
105M
            }
245
246
114M
            sample[0][0][x] = g;
247
114M
            sample[1][0][x] = b;
248
114M
            sample[2][0][x] = r;
249
114M
            sample[3][0][x] = a;
250
114M
        }
251
10.5M
        for (p = 0; p < 3 + transparency; p++) {
252
7.97M
            int ret;
253
7.97M
            sample[p][0][-1] = sample[p][1][0  ];
254
7.97M
            sample[p][1][ w] = sample[p][1][w-1];
255
7.97M
            if (bits[p] == 9)
256
1.27M
                ret = RENAME(encode_line)(f, sc, f->avctx, w, sample[p], (p + 1) / 2, 9, ac, pass1);
257
6.69M
            else
258
6.69M
                ret = RENAME(encode_line)(f, sc, f->avctx, w, sample[p], (p + 1) / 2,
259
6.69M
                                          bits[p], ac, pass1);
260
7.97M
            if (ret < 0)
261
336
                return ret;
262
7.97M
        }
263
2.53M
    }
264
16.3k
    return 0;
265
16.6k
}
ffv1enc.c:encode_rgb_frame32
Line
Count
Source
177
11.3k
{
178
11.3k
    int x, y, p, i;
179
11.3k
    const int ring_size = f->context_model ? 3 : 2;
180
11.3k
    TYPE *sample[4][3];
181
11.3k
    const int pass1 = !!(f->avctx->flags & AV_CODEC_FLAG_PASS1);
182
11.3k
    int lbd    = f->bits_per_raw_sample <= 8;
183
11.3k
    int packed = !src[1];
184
11.3k
    int bits[4], offset;
185
11.3k
    int transparency = f->transparency;
186
11.3k
    int packed_size = (3 + transparency)*2;
187
188
11.3k
    ff_ffv1_compute_bits_per_plane(f, sc, bits, &offset, NULL, f->bits_per_raw_sample);
189
190
11.3k
    sc->run_index = 0;
191
192
56.6k
    for (int p = 0; p < MAX_PLANES; ++p)
193
45.2k
        sample[p][2] = RENAME(sc->sample_buffer);
194
195
11.3k
    memset(RENAME(sc->sample_buffer), 0, ring_size * MAX_PLANES *
196
11.3k
           (w + 6) * sizeof(*RENAME(sc->sample_buffer)));
197
198
1.47M
    for (y = 0; y < h; y++) {
199
4.75M
        for (i = 0; i < ring_size; i++)
200
16.4M
            for (p = 0; p < MAX_PLANES; p++)
201
13.1M
                sample[p][i]= RENAME(sc->sample_buffer) + p*ring_size*(w+6) + ((h+i-y)%ring_size)*(w+6) + 3;
202
203
80.6M
        for (x = 0; x < w; x++) {
204
79.1M
            int b, g, r, av_uninit(a);
205
79.1M
            if (lbd) {
206
0
                unsigned v = *((const uint32_t*)(src[0] + x*4 + stride[0]*y));
207
0
                b =  v        & 0xFF;
208
0
                g = (v >>  8) & 0xFF;
209
0
                r = (v >> 16) & 0xFF;
210
0
                a =  v >> 24;
211
79.1M
            } else if (packed) {
212
4.77M
                const uint16_t *p = ((const uint16_t*)(src[0] + x*packed_size + stride[0]*y));
213
4.77M
                r = p[0];
214
4.77M
                g = p[1];
215
4.77M
                b = p[2];
216
4.77M
                if (transparency)
217
2.12M
                  a = p[3];
218
74.4M
            } else if (sizeof(TYPE) == 4 || transparency) {
219
74.4M
                g = *((const uint16_t *)(src[0] + x*2 + stride[0]*y));
220
74.4M
                b = *((const uint16_t *)(src[1] + x*2 + stride[1]*y));
221
74.4M
                r = *((const uint16_t *)(src[2] + x*2 + stride[2]*y));
222
74.4M
                if (transparency)
223
3.36M
                    a = *((const uint16_t *)(src[3] + x*2 + stride[3]*y));
224
74.4M
            } else {
225
0
                b = *((const uint16_t *)(src[0] + x*2 + stride[0]*y));
226
0
                g = *((const uint16_t *)(src[1] + x*2 + stride[1]*y));
227
0
                r = *((const uint16_t *)(src[2] + x*2 + stride[2]*y));
228
0
            }
229
230
79.1M
            if (sc->remap) {
231
65.6M
                g = sc->fltmap[0][g];
232
65.6M
                b = sc->fltmap[1][b];
233
65.6M
                r = sc->fltmap[2][r];
234
65.6M
                if (transparency)
235
0
                    a = sc->fltmap[3][a];
236
65.6M
            }
237
238
79.1M
            if (sc->slice_coding_mode != 1) {
239
70.3M
                b -= g;
240
70.3M
                r -= g;
241
70.3M
                g += (b * sc->slice_rct_by_coef + r * sc->slice_rct_ry_coef) >> 2;
242
70.3M
                b += offset;
243
70.3M
                r += offset;
244
70.3M
            }
245
246
79.1M
            sample[0][0][x] = g;
247
79.1M
            sample[1][0][x] = b;
248
79.1M
            sample[2][0][x] = r;
249
79.1M
            sample[3][0][x] = a;
250
79.1M
        }
251
5.87M
        for (p = 0; p < 3 + transparency; p++) {
252
4.40M
            int ret;
253
4.40M
            sample[p][0][-1] = sample[p][1][0  ];
254
4.40M
            sample[p][1][ w] = sample[p][1][w-1];
255
4.40M
            if (bits[p] == 9)
256
127k
                ret = RENAME(encode_line)(f, sc, f->avctx, w, sample[p], (p + 1) / 2, 9, ac, pass1);
257
4.27M
            else
258
4.27M
                ret = RENAME(encode_line)(f, sc, f->avctx, w, sample[p], (p + 1) / 2,
259
4.27M
                                          bits[p], ac, pass1);
260
4.40M
            if (ret < 0)
261
336
                return ret;
262
4.40M
        }
263
1.46M
    }
264
10.9k
    return 0;
265
11.3k
}
ffv1enc.c:encode_rgb_frame
Line
Count
Source
177
5.34k
{
178
5.34k
    int x, y, p, i;
179
5.34k
    const int ring_size = f->context_model ? 3 : 2;
180
5.34k
    TYPE *sample[4][3];
181
5.34k
    const int pass1 = !!(f->avctx->flags & AV_CODEC_FLAG_PASS1);
182
5.34k
    int lbd    = f->bits_per_raw_sample <= 8;
183
5.34k
    int packed = !src[1];
184
5.34k
    int bits[4], offset;
185
5.34k
    int transparency = f->transparency;
186
5.34k
    int packed_size = (3 + transparency)*2;
187
188
5.34k
    ff_ffv1_compute_bits_per_plane(f, sc, bits, &offset, NULL, f->bits_per_raw_sample);
189
190
5.34k
    sc->run_index = 0;
191
192
26.7k
    for (int p = 0; p < MAX_PLANES; ++p)
193
21.3k
        sample[p][2] = RENAME(sc->sample_buffer);
194
195
5.34k
    memset(RENAME(sc->sample_buffer), 0, ring_size * MAX_PLANES *
196
5.34k
           (w + 6) * sizeof(*RENAME(sc->sample_buffer)));
197
198
1.07M
    for (y = 0; y < h; y++) {
199
3.65M
        for (i = 0; i < ring_size; i++)
200
12.9M
            for (p = 0; p < MAX_PLANES; p++)
201
10.3M
                sample[p][i]= RENAME(sc->sample_buffer) + p*ring_size*(w+6) + ((h+i-y)%ring_size)*(w+6) + 3;
202
203
36.4M
        for (x = 0; x < w; x++) {
204
35.3M
            int b, g, r, av_uninit(a);
205
35.3M
            if (lbd) {
206
16.9M
                unsigned v = *((const uint32_t*)(src[0] + x*4 + stride[0]*y));
207
16.9M
                b =  v        & 0xFF;
208
16.9M
                g = (v >>  8) & 0xFF;
209
16.9M
                r = (v >> 16) & 0xFF;
210
16.9M
                a =  v >> 24;
211
18.4M
            } else if (packed) {
212
0
                const uint16_t *p = ((const uint16_t*)(src[0] + x*packed_size + stride[0]*y));
213
0
                r = p[0];
214
0
                g = p[1];
215
0
                b = p[2];
216
0
                if (transparency)
217
0
                  a = p[3];
218
18.4M
            } else if (sizeof(TYPE) == 4 || transparency) {
219
13.6M
                g = *((const uint16_t *)(src[0] + x*2 + stride[0]*y));
220
13.6M
                b = *((const uint16_t *)(src[1] + x*2 + stride[1]*y));
221
13.6M
                r = *((const uint16_t *)(src[2] + x*2 + stride[2]*y));
222
13.6M
                if (transparency)
223
13.6M
                    a = *((const uint16_t *)(src[3] + x*2 + stride[3]*y));
224
13.6M
            } else {
225
4.78M
                b = *((const uint16_t *)(src[0] + x*2 + stride[0]*y));
226
4.78M
                g = *((const uint16_t *)(src[1] + x*2 + stride[1]*y));
227
4.78M
                r = *((const uint16_t *)(src[2] + x*2 + stride[2]*y));
228
4.78M
            }
229
230
35.3M
            if (sc->remap) {
231
0
                g = sc->fltmap[0][g];
232
0
                b = sc->fltmap[1][b];
233
0
                r = sc->fltmap[2][r];
234
0
                if (transparency)
235
0
                    a = sc->fltmap[3][a];
236
0
            }
237
238
35.3M
            if (sc->slice_coding_mode != 1) {
239
35.3M
                b -= g;
240
35.3M
                r -= g;
241
35.3M
                g += (b * sc->slice_rct_by_coef + r * sc->slice_rct_ry_coef) >> 2;
242
35.3M
                b += offset;
243
35.3M
                r += offset;
244
35.3M
            }
245
246
35.3M
            sample[0][0][x] = g;
247
35.3M
            sample[1][0][x] = b;
248
35.3M
            sample[2][0][x] = r;
249
35.3M
            sample[3][0][x] = a;
250
35.3M
        }
251
4.64M
        for (p = 0; p < 3 + transparency; p++) {
252
3.57M
            int ret;
253
3.57M
            sample[p][0][-1] = sample[p][1][0  ];
254
3.57M
            sample[p][1][ w] = sample[p][1][w-1];
255
3.57M
            if (bits[p] == 9)
256
1.15M
                ret = RENAME(encode_line)(f, sc, f->avctx, w, sample[p], (p + 1) / 2, 9, ac, pass1);
257
2.42M
            else
258
2.42M
                ret = RENAME(encode_line)(f, sc, f->avctx, w, sample[p], (p + 1) / 2,
259
2.42M
                                          bits[p], ac, pass1);
260
3.57M
            if (ret < 0)
261
0
                return ret;
262
3.57M
        }
263
1.07M
    }
264
5.34k
    return 0;
265
5.34k
}