GCC Code Coverage Report
Directory: ../../../ffmpeg/ Exec Total Coverage
File: src/libavcodec/ffv1dec_template.c Lines: 94 109 86.2 %
Date: 2019-11-18 18:00:01 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
1283904
static av_always_inline int RENAME(decode_line)(FFV1Context *s, int w,
24
                                                 TYPE *sample[2],
25
                                                 int plane_index, int bits)
26
{
27
1283904
    PlaneContext *const p = &s->plane[plane_index];
28
1283904
    RangeCoder *const c   = &s->c;
29
    int x;
30
1283904
    int run_count = 0;
31
1283904
    int run_mode  = 0;
32
1283904
    int run_index = s->run_index;
33
34
1283904
    if (is_input_end(s))
35
        return AVERROR_INVALIDDATA;
36
37
1283904
    if (s->slice_coding_mode == 1) {
38
        int i;
39
        for (x = 0; x < w; x++) {
40
            int v = 0;
41
            for (i=0; i<bits; i++) {
42
                uint8_t state = 128;
43
                v += v + get_rac(c, &state);
44
            }
45
            sample[1][x] = v;
46
        }
47
        return 0;
48
    }
49
50
194302715
    for (x = 0; x < w; x++) {
51
        int diff, context, sign;
52
53
193018811
        if (!(x & 1023)) {
54
1283904
            if (is_input_end(s))
55
                return AVERROR_INVALIDDATA;
56
        }
57
58
193018811
        context = RENAME(get_context)(p, sample[1] + x, sample[0] + x, sample[1] + x);
59
193018811
        if (context < 0) {
60
75049073
            context = -context;
61
75049073
            sign    = 1;
62
        } else
63
117969738
            sign = 0;
64
65
        av_assert2(context < p->context_count);
66
67
193018811
        if (s->ac != AC_GOLOMB_RICE) {
68
77850888
            diff = get_symbol_inline(c, p->state[context], 1);
69
        } else {
70

115167923
            if (context == 0 && run_mode == 0)
71
1406364
                run_mode = 1;
72
73
115167923
            if (run_mode) {
74

3179016
                if (run_count == 0 && run_mode == 1) {
75
2648716
                    if (get_bits1(&s->gb)) {
76
1295521
                        run_count = 1 << ff_log2_run[run_index];
77
1295521
                        if (x + run_count <= w)
78
1260471
                            run_index++;
79
                    } else {
80
1353195
                        if (ff_log2_run[run_index])
81
1004563
                            run_count = get_bits(&s->gb, ff_log2_run[run_index]);
82
                        else
83
348632
                            run_count = 0;
84
1353195
                        if (run_index)
85
1249584
                            run_index--;
86
1353195
                        run_mode = 2;
87
                    }
88
                }
89
3179016
                if (sample[1][x - 1] == sample[0][x - 1]) {
90

4938422
                    while (run_count > 1 && w-x > 1) {
91
1761905
                        sample[1][x] = sample[0][x];
92
1761905
                        x++;
93
1761905
                        run_count--;
94
                    }
95
                } else {
96

3005
                while (run_count > 1 && w-x > 1) {
97
506
                    sample[1][x] = RENAME(predict)(sample[1] + x, sample[0] + x);
98
506
                    x++;
99
506
                    run_count--;
100
                }
101
                }
102
3179016
                run_count--;
103
3179016
                if (run_count < 0) {
104
1353195
                    run_mode  = 0;
105
1353195
                    run_count = 0;
106
1353195
                    diff      = get_vlc_symbol(&s->gb, &p->vlc_state[context],
107
                                               bits);
108
1353195
                    if (diff >= 0)
109
631292
                        diff++;
110
                } else
111
1825821
                    diff = 0;
112
            } else
113
111988907
                diff = get_vlc_symbol(&s->gb, &p->vlc_state[context], bits);
114
115
            ff_dlog(s->avctx, "count:%d index:%d, mode:%d, x:%d pos:%d\n",
116
                    run_count, run_index, run_mode, x, get_bits_count(&s->gb));
117
        }
118
119
193018811
        if (sign)
120
75049073
            diff = -(unsigned)diff;
121
122
193018811
        sample[1][x] = av_mod_uintp2(RENAME(predict)(sample[1] + x, sample[0] + x) + (SUINT)diff, bits);
123
    }
124
1283904
    s->run_index = run_index;
125
1283904
    return 0;
126
}
127
128
1632
static int RENAME(decode_rgb_frame)(FFV1Context *s, uint8_t *src[4], int w, int h, int stride[4])
129
{
130
    int x, y, p;
131
    TYPE *sample[4][2];
132
1632
    int lbd    = s->avctx->bits_per_raw_sample <= 8;
133
1632
    int bits   = s->avctx->bits_per_raw_sample > 0 ? s->avctx->bits_per_raw_sample : 8;
134
1632
    int offset = 1 << bits;
135
1632
    int transparency = s->transparency;
136
137
8160
    for (x = 0; x < 4; x++) {
138
6528
        sample[x][0] = RENAME(s->sample_buffer) +  x * 2      * (w + 6) + 3;
139
6528
        sample[x][1] = RENAME(s->sample_buffer) + (x * 2 + 1) * (w + 6) + 3;
140
    }
141
142
1632
    s->run_index = 0;
143
144
1632
    memset(RENAME(s->sample_buffer), 0, 8 * (w + 6) * sizeof(*RENAME(s->sample_buffer)));
145
146
184824
    for (y = 0; y < h; y++) {
147
732768
        for (p = 0; p < 3 + transparency; p++) {
148
            int ret;
149
549576
            TYPE *temp = sample[p][0]; // FIXME: try a normal buffer
150
151
549576
            sample[p][0] = sample[p][1];
152
549576
            sample[p][1] = temp;
153
154
549576
            sample[p][1][-1]= sample[p][0][0  ];
155
549576
            sample[p][0][ w]= sample[p][0][w-1];
156
549576
            if (lbd && s->slice_coding_mode == 0)
157
274788
                ret = RENAME(decode_line)(s, w, sample[p], (p + 1)/2, 9);
158
            else
159
274788
                ret = RENAME(decode_line)(s, w, sample[p], (p + 1)/2, bits + (s->slice_coding_mode != 1));
160
549576
            if (ret < 0)
161
                return ret;
162
        }
163
31322160
        for (x = 0; x < w; x++) {
164
31138968
            int g = sample[0][1][x];
165
31138968
            int b = sample[1][1][x];
166
31138968
            int r = sample[2][1][x];
167
31138968
            int a = sample[3][1][x];
168
169
31138968
            if (s->slice_coding_mode != 1) {
170
31138968
                b -= offset;
171
31138968
                r -= offset;
172
31138968
                g -= (b * s->slice_rct_by_coef + r * s->slice_rct_ry_coef) >> 2;
173
31138968
                b += g;
174
31138968
                r += g;
175
            }
176
177
31138968
            if (lbd)
178
15569484
                *((uint32_t*)(src[0] + x*4 + stride[0]*y)) = b + ((unsigned)g<<8) + ((unsigned)r<<16) + ((unsigned)a<<24);
179
            else if (sizeof(TYPE) == 4 || transparency) {
180
15569484
                *((uint16_t*)(src[0] + x*2 + stride[0]*y)) = g;
181
15569484
                *((uint16_t*)(src[1] + x*2 + stride[1]*y)) = b;
182
15569484
                *((uint16_t*)(src[2] + x*2 + stride[2]*y)) = r;
183
15569484
                if (transparency)
184
                    *((uint16_t*)(src[3] + x*2 + stride[3]*y)) = a;
185
            } else {
186
                *((uint16_t*)(src[0] + x*2 + stride[0]*y)) = b;
187
                *((uint16_t*)(src[1] + x*2 + stride[1]*y)) = g;
188
                *((uint16_t*)(src[2] + x*2 + stride[2]*y)) = r;
189
            }
190
        }
191
    }
192
1632
    return 0;
193
}