Coverage Report

Created: 2025-08-28 07:12

/src/ffmpeg/libavcodec/ffv1enc_template.c
Line
Count
Source (jump to first uncovered line)
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
16.5M
{
31
16.5M
    PlaneContext *const p = &sc->plane[plane_index];
32
16.5M
    RangeCoder *const c   = &sc->c;
33
16.5M
    int x;
34
16.5M
    int run_index = sc->run_index;
35
16.5M
    int run_count = 0;
36
16.5M
    int run_mode  = 0;
37
38
16.5M
    if (bits == 0)
39
772k
        return 0;
40
41
15.7M
    if (sc->slice_coding_mode == 1) {
42
15.8k
        av_assert0(ac != AC_GOLOMB_RICE);
43
15.8k
        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
36.1M
        for (x = 0; x < w; x++) {
49
36.1M
            int i;
50
36.1M
            int v = sample[0][x];
51
466M
            for (i = bits-1; i>=0; i--) {
52
430M
                uint8_t state = 128;
53
430M
                put_rac(c, &state, (v>>i) & 1);
54
430M
            }
55
36.1M
        }
56
15.8k
        return 0;
57
15.8k
    }
58
59
15.7M
    if (ac != AC_GOLOMB_RICE) {
60
11.1M
        if (c->bytestream_end - c->bytestream < w * 35) {
61
2.59k
            av_log(logctx, AV_LOG_ERROR, "encoded Range Coder frame too large\n");
62
2.59k
            return AVERROR_INVALIDDATA;
63
2.59k
        }
64
11.1M
    } else {
65
4.57M
        if (put_bytes_left(&sc->pb, 0) < w * 4) {
66
49
            av_log(logctx, AV_LOG_ERROR, "encoded Golomb Rice frame too large\n");
67
49
            return AVERROR_INVALIDDATA;
68
49
        }
69
4.57M
    }
70
71
575M
    for (x = 0; x < w; x++) {
72
560M
        int diff, context;
73
74
560M
        context = RENAME(get_context)(f->quant_tables[p->quant_table_index],
75
560M
                                      sample[0] + x, sample[1] + x, sample[2] + x);
76
560M
        diff    = sample[0][x] - RENAME(predict)(sample[0] + x, sample[1] + x);
77
78
560M
        if (context < 0) {
79
28.9M
            context = -context;
80
28.9M
            diff    = -diff;
81
28.9M
        }
82
83
560M
        diff = fold(diff, bits);
84
85
560M
        if (ac != AC_GOLOMB_RICE) {
86
415M
            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
415M
            } else {
90
415M
                put_symbol_inline(c, p->state[context], diff, 1, NULL, NULL);
91
415M
            }
92
415M
        } else {
93
144M
            if (context == 0)
94
124M
                run_mode = 1;
95
96
144M
            if (run_mode) {
97
126M
                if (diff) {
98
1.13M
                    while (run_count >= 1 << ff_log2_run[run_index]) {
99
317k
                        run_count -= 1 << ff_log2_run[run_index];
100
317k
                        run_index++;
101
317k
                        put_bits(&sc->pb, 1, 1);
102
317k
                    }
103
104
821k
                    put_bits(&sc->pb, 1 + ff_log2_run[run_index], run_count);
105
821k
                    if (run_index)
106
433k
                        run_index--;
107
821k
                    run_count = 0;
108
821k
                    run_mode  = 0;
109
821k
                    if (diff > 0)
110
432k
                        diff--;
111
125M
                } else {
112
125M
                    run_count++;
113
125M
                }
114
126M
            }
115
116
144M
            ff_dlog(logctx, "count:%d index:%d, mode:%d, x:%d pos:%d\n",
117
144M
                    run_count, run_index, run_mode, x,
118
144M
                    (int)put_bits_count(&sc->pb));
119
120
144M
            if (run_mode == 0)
121
19.2M
                put_vlc_symbol(&sc->pb, &p->vlc_state[context], diff, bits);
122
144M
        }
123
560M
    }
124
15.7M
    if (run_mode) {
125
4.74M
        while (run_count >= 1 << ff_log2_run[run_index]) {
126
391k
            run_count -= 1 << ff_log2_run[run_index];
127
391k
            run_index++;
128
391k
            put_bits(&sc->pb, 1, 1);
129
391k
        }
130
131
4.35M
        if (run_count)
132
4.29M
            put_bits(&sc->pb, 1, 1);
133
4.35M
    }
134
15.7M
    sc->run_index = run_index;
135
136
15.7M
    return 0;
137
15.7M
}
ffv1enc.c:encode_line
Line
Count
Source
30
9.61M
{
31
9.61M
    PlaneContext *const p = &sc->plane[plane_index];
32
9.61M
    RangeCoder *const c   = &sc->c;
33
9.61M
    int x;
34
9.61M
    int run_index = sc->run_index;
35
9.61M
    int run_count = 0;
36
9.61M
    int run_mode  = 0;
37
38
9.61M
    if (bits == 0)
39
0
        return 0;
40
41
9.61M
    if (sc->slice_coding_mode == 1) {
42
1.04k
        av_assert0(ac != AC_GOLOMB_RICE);
43
1.04k
        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
10.5M
        for (x = 0; x < w; x++) {
49
10.5M
            int i;
50
10.5M
            int v = sample[0][x];
51
179M
            for (i = bits-1; i>=0; i--) {
52
168M
                uint8_t state = 128;
53
168M
                put_rac(c, &state, (v>>i) & 1);
54
168M
            }
55
10.5M
        }
56
1.04k
        return 0;
57
1.04k
    }
58
59
9.61M
    if (ac != AC_GOLOMB_RICE) {
60
7.21M
        if (c->bytestream_end - c->bytestream < w * 35) {
61
363
            av_log(logctx, AV_LOG_ERROR, "encoded Range Coder frame too large\n");
62
363
            return AVERROR_INVALIDDATA;
63
363
        }
64
7.21M
    } else {
65
2.39M
        if (put_bytes_left(&sc->pb, 0) < w * 4) {
66
49
            av_log(logctx, AV_LOG_ERROR, "encoded Golomb Rice frame too large\n");
67
49
            return AVERROR_INVALIDDATA;
68
49
        }
69
2.39M
    }
70
71
256M
    for (x = 0; x < w; x++) {
72
246M
        int diff, context;
73
74
246M
        context = RENAME(get_context)(f->quant_tables[p->quant_table_index],
75
246M
                                      sample[0] + x, sample[1] + x, sample[2] + x);
76
246M
        diff    = sample[0][x] - RENAME(predict)(sample[0] + x, sample[1] + x);
77
78
246M
        if (context < 0) {
79
6.12M
            context = -context;
80
6.12M
            diff    = -diff;
81
6.12M
        }
82
83
246M
        diff = fold(diff, bits);
84
85
246M
        if (ac != AC_GOLOMB_RICE) {
86
175M
            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
175M
            } else {
90
175M
                put_symbol_inline(c, p->state[context], diff, 1, NULL, NULL);
91
175M
            }
92
175M
        } else {
93
71.2M
            if (context == 0)
94
66.8M
                run_mode = 1;
95
96
71.2M
            if (run_mode) {
97
66.9M
                if (diff) {
98
561k
                    while (run_count >= 1 << ff_log2_run[run_index]) {
99
163k
                        run_count -= 1 << ff_log2_run[run_index];
100
163k
                        run_index++;
101
163k
                        put_bits(&sc->pb, 1, 1);
102
163k
                    }
103
104
398k
                    put_bits(&sc->pb, 1 + ff_log2_run[run_index], run_count);
105
398k
                    if (run_index)
106
196k
                        run_index--;
107
398k
                    run_count = 0;
108
398k
                    run_mode  = 0;
109
398k
                    if (diff > 0)
110
217k
                        diff--;
111
66.5M
                } else {
112
66.5M
                    run_count++;
113
66.5M
                }
114
66.9M
            }
115
116
71.2M
            ff_dlog(logctx, "count:%d index:%d, mode:%d, x:%d pos:%d\n",
117
71.2M
                    run_count, run_index, run_mode, x,
118
71.2M
                    (int)put_bits_count(&sc->pb));
119
120
71.2M
            if (run_mode == 0)
121
4.64M
                put_vlc_symbol(&sc->pb, &p->vlc_state[context], diff, bits);
122
71.2M
        }
123
246M
    }
124
9.61M
    if (run_mode) {
125
2.52M
        while (run_count >= 1 << ff_log2_run[run_index]) {
126
263k
            run_count -= 1 << ff_log2_run[run_index];
127
263k
            run_index++;
128
263k
            put_bits(&sc->pb, 1, 1);
129
263k
        }
130
131
2.25M
        if (run_count)
132
2.20M
            put_bits(&sc->pb, 1, 1);
133
2.25M
    }
134
9.61M
    sc->run_index = run_index;
135
136
9.61M
    return 0;
137
9.61M
}
ffv1enc.c:encode_line32
Line
Count
Source
30
6.90M
{
31
6.90M
    PlaneContext *const p = &sc->plane[plane_index];
32
6.90M
    RangeCoder *const c   = &sc->c;
33
6.90M
    int x;
34
6.90M
    int run_index = sc->run_index;
35
6.90M
    int run_count = 0;
36
6.90M
    int run_mode  = 0;
37
38
6.90M
    if (bits == 0)
39
772k
        return 0;
40
41
6.12M
    if (sc->slice_coding_mode == 1) {
42
14.7k
        av_assert0(ac != AC_GOLOMB_RICE);
43
14.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
25.6M
        for (x = 0; x < w; x++) {
49
25.5M
            int i;
50
25.5M
            int v = sample[0][x];
51
287M
            for (i = bits-1; i>=0; i--) {
52
261M
                uint8_t state = 128;
53
261M
                put_rac(c, &state, (v>>i) & 1);
54
261M
            }
55
25.5M
        }
56
14.7k
        return 0;
57
14.7k
    }
58
59
6.11M
    if (ac != AC_GOLOMB_RICE) {
60
3.93M
        if (c->bytestream_end - c->bytestream < w * 35) {
61
2.23k
            av_log(logctx, AV_LOG_ERROR, "encoded Range Coder frame too large\n");
62
2.23k
            return AVERROR_INVALIDDATA;
63
2.23k
        }
64
3.93M
    } else {
65
2.18M
        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.18M
    }
70
71
319M
    for (x = 0; x < w; x++) {
72
313M
        int diff, context;
73
74
313M
        context = RENAME(get_context)(f->quant_tables[p->quant_table_index],
75
313M
                                      sample[0] + x, sample[1] + x, sample[2] + x);
76
313M
        diff    = sample[0][x] - RENAME(predict)(sample[0] + x, sample[1] + x);
77
78
313M
        if (context < 0) {
79
22.7M
            context = -context;
80
22.7M
            diff    = -diff;
81
22.7M
        }
82
83
313M
        diff = fold(diff, bits);
84
85
313M
        if (ac != AC_GOLOMB_RICE) {
86
239M
            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
239M
            } else {
90
239M
                put_symbol_inline(c, p->state[context], diff, 1, NULL, NULL);
91
239M
            }
92
239M
        } else {
93
73.4M
            if (context == 0)
94
58.0M
                run_mode = 1;
95
96
73.4M
            if (run_mode) {
97
59.2M
                if (diff) {
98
577k
                    while (run_count >= 1 << ff_log2_run[run_index]) {
99
154k
                        run_count -= 1 << ff_log2_run[run_index];
100
154k
                        run_index++;
101
154k
                        put_bits(&sc->pb, 1, 1);
102
154k
                    }
103
104
422k
                    put_bits(&sc->pb, 1 + ff_log2_run[run_index], run_count);
105
422k
                    if (run_index)
106
237k
                        run_index--;
107
422k
                    run_count = 0;
108
422k
                    run_mode  = 0;
109
422k
                    if (diff > 0)
110
215k
                        diff--;
111
58.8M
                } else {
112
58.8M
                    run_count++;
113
58.8M
                }
114
59.2M
            }
115
116
73.4M
            ff_dlog(logctx, "count:%d index:%d, mode:%d, x:%d pos:%d\n",
117
73.4M
                    run_count, run_index, run_mode, x,
118
73.4M
                    (int)put_bits_count(&sc->pb));
119
120
73.4M
            if (run_mode == 0)
121
14.6M
                put_vlc_symbol(&sc->pb, &p->vlc_state[context], diff, bits);
122
73.4M
        }
123
313M
    }
124
6.11M
    if (run_mode) {
125
2.22M
        while (run_count >= 1 << ff_log2_run[run_index]) {
126
128k
            run_count -= 1 << ff_log2_run[run_index];
127
128k
            run_index++;
128
128k
            put_bits(&sc->pb, 1, 1);
129
128k
        }
130
131
2.10M
        if (run_count)
132
2.09M
            put_bits(&sc->pb, 1, 1);
133
2.10M
    }
134
6.11M
    sc->run_index = run_index;
135
136
6.11M
    return 0;
137
6.11M
}
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.66k
{
143
5.66k
    int x, y;
144
5.66k
    int transparency = f->transparency;
145
146
22.6k
    for (int p = 0; p<3 + transparency; p++)
147
17.0k
        memset(sc->fltmap[p], 0, 65536 * sizeof(**sc->fltmap));
148
149
445k
    for (y = 0; y < h; y++) {
150
68.8M
        for (x = 0; x < w; x++) {
151
68.4M
            int b, g, r, av_uninit(a);
152
153
68.4M
            if (sizeof(TYPE) == 4 || transparency) {
154
68.4M
                g = *((const uint16_t *)(src[0] + x*2 + stride[0]*y));
155
68.4M
                b = *((const uint16_t *)(src[1] + x*2 + stride[1]*y));
156
68.4M
                r = *((const uint16_t *)(src[2] + x*2 + stride[2]*y));
157
68.4M
                if (transparency)
158
0
                    a = *((const uint16_t *)(src[3] + x*2 + stride[3]*y));
159
68.4M
            } 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
68.4M
            sc->fltmap[0][g] = 1;
166
68.4M
            sc->fltmap[1][b] = 1;
167
68.4M
            sc->fltmap[2][r] = 1;
168
68.4M
            if (transparency)
169
0
                sc->fltmap[3][a] = 1;
170
68.4M
        }
171
440k
    }
172
5.66k
}
ffv1enc.c:load_rgb_frame32
Line
Count
Source
142
5.66k
{
143
5.66k
    int x, y;
144
5.66k
    int transparency = f->transparency;
145
146
22.6k
    for (int p = 0; p<3 + transparency; p++)
147
17.0k
        memset(sc->fltmap[p], 0, 65536 * sizeof(**sc->fltmap));
148
149
445k
    for (y = 0; y < h; y++) {
150
68.8M
        for (x = 0; x < w; x++) {
151
68.4M
            int b, g, r, av_uninit(a);
152
153
68.4M
            if (sizeof(TYPE) == 4 || transparency) {
154
68.4M
                g = *((const uint16_t *)(src[0] + x*2 + stride[0]*y));
155
68.4M
                b = *((const uint16_t *)(src[1] + x*2 + stride[1]*y));
156
68.4M
                r = *((const uint16_t *)(src[2] + x*2 + stride[2]*y));
157
68.4M
                if (transparency)
158
0
                    a = *((const uint16_t *)(src[3] + x*2 + stride[3]*y));
159
68.4M
            } 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
68.4M
            sc->fltmap[0][g] = 1;
166
68.4M
            sc->fltmap[1][b] = 1;
167
68.4M
            sc->fltmap[2][r] = 1;
168
68.4M
            if (transparency)
169
0
                sc->fltmap[3][a] = 1;
170
68.4M
        }
171
440k
    }
172
5.66k
}
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
29.7k
{
178
29.7k
    int x, y, p, i;
179
29.7k
    const int ring_size = f->context_model ? 3 : 2;
180
29.7k
    TYPE *sample[4][3];
181
29.7k
    const int pass1 = !!(f->avctx->flags & AV_CODEC_FLAG_PASS1);
182
29.7k
    int lbd    = f->bits_per_raw_sample <= 8;
183
29.7k
    int packed = !src[1];
184
29.7k
    int bits[4], offset;
185
29.7k
    int transparency = f->transparency;
186
29.7k
    int packed_size = (3 + transparency)*2;
187
188
29.7k
    ff_ffv1_compute_bits_per_plane(f, sc, bits, &offset, NULL, f->bits_per_raw_sample);
189
190
29.7k
    sc->run_index = 0;
191
192
148k
    for (int p = 0; p < MAX_PLANES; ++p)
193
119k
        sample[p][2] = RENAME(sc->sample_buffer);
194
195
29.7k
    memset(RENAME(sc->sample_buffer), 0, ring_size * MAX_PLANES *
196
29.7k
           (w + 6) * sizeof(*RENAME(sc->sample_buffer)));
197
198
2.10M
    for (y = 0; y < h; y++) {
199
7.32M
        for (i = 0; i < ring_size; i++)
200
26.2M
            for (p = 0; p < MAX_PLANES; p++)
201
21.0M
                sample[p][i]= RENAME(sc->sample_buffer) + p*ring_size*(w+6) + ((h+i-y)%ring_size)*(w+6) + 3;
202
203
121M
        for (x = 0; x < w; x++) {
204
119M
            int b, g, r, av_uninit(a);
205
119M
            if (lbd) {
206
21.5M
                unsigned v = *((const uint32_t*)(src[0] + x*4 + stride[0]*y));
207
21.5M
                b =  v        & 0xFF;
208
21.5M
                g = (v >>  8) & 0xFF;
209
21.5M
                r = (v >> 16) & 0xFF;
210
21.5M
                a =  v >> 24;
211
98.1M
            } else if (packed) {
212
4.34M
                const uint16_t *p = ((const uint16_t*)(src[0] + x*packed_size + stride[0]*y));
213
4.34M
                r = p[0];
214
4.34M
                g = p[1];
215
4.34M
                b = p[2];
216
4.34M
                if (transparency)
217
2.33M
                  a = p[3];
218
93.7M
            } else if (sizeof(TYPE) == 4 || transparency) {
219
87.6M
                g = *((const uint16_t *)(src[0] + x*2 + stride[0]*y));
220
87.6M
                b = *((const uint16_t *)(src[1] + x*2 + stride[1]*y));
221
87.6M
                r = *((const uint16_t *)(src[2] + x*2 + stride[2]*y));
222
87.6M
                if (transparency)
223
17.3M
                    a = *((const uint16_t *)(src[3] + x*2 + stride[3]*y));
224
87.6M
            } else {
225
6.14M
                b = *((const uint16_t *)(src[0] + x*2 + stride[0]*y));
226
6.14M
                g = *((const uint16_t *)(src[1] + x*2 + stride[1]*y));
227
6.14M
                r = *((const uint16_t *)(src[2] + x*2 + stride[2]*y));
228
6.14M
            }
229
230
119M
            if (sc->remap) {
231
64.6M
                g = sc->fltmap[0][g];
232
64.6M
                b = sc->fltmap[1][b];
233
64.6M
                r = sc->fltmap[2][r];
234
64.6M
                if (transparency)
235
0
                    a = sc->fltmap[3][a];
236
64.6M
            }
237
238
119M
            if (sc->slice_coding_mode != 1) {
239
108M
                b -= g;
240
108M
                r -= g;
241
108M
                g += (b * sc->slice_rct_by_coef + r * sc->slice_rct_ry_coef) >> 2;
242
108M
                b += offset;
243
108M
                r += offset;
244
108M
            }
245
246
119M
            sample[0][0][x] = g;
247
119M
            sample[1][0][x] = b;
248
119M
            sample[2][0][x] = r;
249
119M
            sample[3][0][x] = a;
250
119M
        }
251
9.02M
        for (p = 0; p < 3 + transparency; p++) {
252
6.94M
            int ret;
253
6.94M
            sample[p][0][-1] = sample[p][1][0  ];
254
6.94M
            sample[p][1][ w] = sample[p][1][w-1];
255
6.94M
            if (bits[p] == 9)
256
1.68M
                ret = RENAME(encode_line)(f, sc, f->avctx, w, sample[p], (p + 1) / 2, 9, ac, pass1);
257
5.26M
            else
258
5.26M
                ret = RENAME(encode_line)(f, sc, f->avctx, w, sample[p], (p + 1) / 2,
259
5.26M
                                          bits[p], ac, pass1);
260
6.94M
            if (ret < 0)
261
379
                return ret;
262
6.94M
        }
263
2.07M
    }
264
29.3k
    return 0;
265
29.7k
}
ffv1enc.c:encode_rgb_frame32
Line
Count
Source
177
11.1k
{
178
11.1k
    int x, y, p, i;
179
11.1k
    const int ring_size = f->context_model ? 3 : 2;
180
11.1k
    TYPE *sample[4][3];
181
11.1k
    const int pass1 = !!(f->avctx->flags & AV_CODEC_FLAG_PASS1);
182
11.1k
    int lbd    = f->bits_per_raw_sample <= 8;
183
11.1k
    int packed = !src[1];
184
11.1k
    int bits[4], offset;
185
11.1k
    int transparency = f->transparency;
186
11.1k
    int packed_size = (3 + transparency)*2;
187
188
11.1k
    ff_ffv1_compute_bits_per_plane(f, sc, bits, &offset, NULL, f->bits_per_raw_sample);
189
190
11.1k
    sc->run_index = 0;
191
192
55.5k
    for (int p = 0; p < MAX_PLANES; ++p)
193
44.4k
        sample[p][2] = RENAME(sc->sample_buffer);
194
195
11.1k
    memset(RENAME(sc->sample_buffer), 0, ring_size * MAX_PLANES *
196
11.1k
           (w + 6) * sizeof(*RENAME(sc->sample_buffer)));
197
198
945k
    for (y = 0; y < h; y++) {
199
3.35M
        for (i = 0; i < ring_size; i++)
200
12.1M
            for (p = 0; p < MAX_PLANES; p++)
201
9.69M
                sample[p][i]= RENAME(sc->sample_buffer) + p*ring_size*(w+6) + ((h+i-y)%ring_size)*(w+6) + 3;
202
203
78.5M
        for (x = 0; x < w; x++) {
204
77.6M
            int b, g, r, av_uninit(a);
205
77.6M
            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
77.6M
            } else if (packed) {
212
4.34M
                const uint16_t *p = ((const uint16_t*)(src[0] + x*packed_size + stride[0]*y));
213
4.34M
                r = p[0];
214
4.34M
                g = p[1];
215
4.34M
                b = p[2];
216
4.34M
                if (transparency)
217
2.33M
                  a = p[3];
218
73.2M
            } else if (sizeof(TYPE) == 4 || transparency) {
219
73.2M
                g = *((const uint16_t *)(src[0] + x*2 + stride[0]*y));
220
73.2M
                b = *((const uint16_t *)(src[1] + x*2 + stride[1]*y));
221
73.2M
                r = *((const uint16_t *)(src[2] + x*2 + stride[2]*y));
222
73.2M
                if (transparency)
223
2.99M
                    a = *((const uint16_t *)(src[3] + x*2 + stride[3]*y));
224
73.2M
            } 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
77.6M
            if (sc->remap) {
231
64.6M
                g = sc->fltmap[0][g];
232
64.6M
                b = sc->fltmap[1][b];
233
64.6M
                r = sc->fltmap[2][r];
234
64.6M
                if (transparency)
235
0
                    a = sc->fltmap[3][a];
236
64.6M
            }
237
238
77.6M
            if (sc->slice_coding_mode != 1) {
239
66.5M
                b -= g;
240
66.5M
                r -= g;
241
66.5M
                g += (b * sc->slice_rct_by_coef + r * sc->slice_rct_ry_coef) >> 2;
242
66.5M
                b += offset;
243
66.5M
                r += offset;
244
66.5M
            }
245
246
77.6M
            sample[0][0][x] = g;
247
77.6M
            sample[1][0][x] = b;
248
77.6M
            sample[2][0][x] = r;
249
77.6M
            sample[3][0][x] = a;
250
77.6M
        }
251
3.87M
        for (p = 0; p < 3 + transparency; p++) {
252
2.94M
            int ret;
253
2.94M
            sample[p][0][-1] = sample[p][1][0  ];
254
2.94M
            sample[p][1][ w] = sample[p][1][w-1];
255
2.94M
            if (bits[p] == 9)
256
111k
                ret = RENAME(encode_line)(f, sc, f->avctx, w, sample[p], (p + 1) / 2, 9, ac, pass1);
257
2.83M
            else
258
2.83M
                ret = RENAME(encode_line)(f, sc, f->avctx, w, sample[p], (p + 1) / 2,
259
2.83M
                                          bits[p], ac, pass1);
260
2.94M
            if (ret < 0)
261
379
                return ret;
262
2.94M
        }
263
934k
    }
264
10.7k
    return 0;
265
11.1k
}
ffv1enc.c:encode_rgb_frame
Line
Count
Source
177
18.6k
{
178
18.6k
    int x, y, p, i;
179
18.6k
    const int ring_size = f->context_model ? 3 : 2;
180
18.6k
    TYPE *sample[4][3];
181
18.6k
    const int pass1 = !!(f->avctx->flags & AV_CODEC_FLAG_PASS1);
182
18.6k
    int lbd    = f->bits_per_raw_sample <= 8;
183
18.6k
    int packed = !src[1];
184
18.6k
    int bits[4], offset;
185
18.6k
    int transparency = f->transparency;
186
18.6k
    int packed_size = (3 + transparency)*2;
187
188
18.6k
    ff_ffv1_compute_bits_per_plane(f, sc, bits, &offset, NULL, f->bits_per_raw_sample);
189
190
18.6k
    sc->run_index = 0;
191
192
93.2k
    for (int p = 0; p < MAX_PLANES; ++p)
193
74.6k
        sample[p][2] = RENAME(sc->sample_buffer);
194
195
18.6k
    memset(RENAME(sc->sample_buffer), 0, ring_size * MAX_PLANES *
196
18.6k
           (w + 6) * sizeof(*RENAME(sc->sample_buffer)));
197
198
1.15M
    for (y = 0; y < h; y++) {
199
3.97M
        for (i = 0; i < ring_size; i++)
200
14.1M
            for (p = 0; p < MAX_PLANES; p++)
201
11.3M
                sample[p][i]= RENAME(sc->sample_buffer) + p*ring_size*(w+6) + ((h+i-y)%ring_size)*(w+6) + 3;
202
203
43.1M
        for (x = 0; x < w; x++) {
204
41.9M
            int b, g, r, av_uninit(a);
205
41.9M
            if (lbd) {
206
21.5M
                unsigned v = *((const uint32_t*)(src[0] + x*4 + stride[0]*y));
207
21.5M
                b =  v        & 0xFF;
208
21.5M
                g = (v >>  8) & 0xFF;
209
21.5M
                r = (v >> 16) & 0xFF;
210
21.5M
                a =  v >> 24;
211
21.5M
            } 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
20.4M
            } else if (sizeof(TYPE) == 4 || transparency) {
219
14.3M
                g = *((const uint16_t *)(src[0] + x*2 + stride[0]*y));
220
14.3M
                b = *((const uint16_t *)(src[1] + x*2 + stride[1]*y));
221
14.3M
                r = *((const uint16_t *)(src[2] + x*2 + stride[2]*y));
222
14.3M
                if (transparency)
223
14.3M
                    a = *((const uint16_t *)(src[3] + x*2 + stride[3]*y));
224
14.3M
            } else {
225
6.14M
                b = *((const uint16_t *)(src[0] + x*2 + stride[0]*y));
226
6.14M
                g = *((const uint16_t *)(src[1] + x*2 + stride[1]*y));
227
6.14M
                r = *((const uint16_t *)(src[2] + x*2 + stride[2]*y));
228
6.14M
            }
229
230
41.9M
            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
41.9M
            if (sc->slice_coding_mode != 1) {
239
41.9M
                b -= g;
240
41.9M
                r -= g;
241
41.9M
                g += (b * sc->slice_rct_by_coef + r * sc->slice_rct_ry_coef) >> 2;
242
41.9M
                b += offset;
243
41.9M
                r += offset;
244
41.9M
            }
245
246
41.9M
            sample[0][0][x] = g;
247
41.9M
            sample[1][0][x] = b;
248
41.9M
            sample[2][0][x] = r;
249
41.9M
            sample[3][0][x] = a;
250
41.9M
        }
251
5.14M
        for (p = 0; p < 3 + transparency; p++) {
252
4.00M
            int ret;
253
4.00M
            sample[p][0][-1] = sample[p][1][0  ];
254
4.00M
            sample[p][1][ w] = sample[p][1][w-1];
255
4.00M
            if (bits[p] == 9)
256
1.57M
                ret = RENAME(encode_line)(f, sc, f->avctx, w, sample[p], (p + 1) / 2, 9, ac, pass1);
257
2.43M
            else
258
2.43M
                ret = RENAME(encode_line)(f, sc, f->avctx, w, sample[p], (p + 1) / 2,
259
2.43M
                                          bits[p], ac, pass1);
260
4.00M
            if (ret < 0)
261
0
                return ret;
262
4.00M
        }
263
1.14M
    }
264
18.6k
    return 0;
265
18.6k
}