Coverage Report

Created: 2026-09-28 07:27

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/vlc/contrib/contrib-build/bpg/libavcodec/golomb.c
Line
Count
Source
1
/*
2
 * exp golomb vlc stuff
3
 * Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
4
 *
5
 * This file is part of FFmpeg.
6
 *
7
 * FFmpeg is free software; you can redistribute it and/or
8
 * modify it under the terms of the GNU Lesser General Public
9
 * License as published by the Free Software Foundation; either
10
 * version 2.1 of the License, or (at your option) any later version.
11
 *
12
 * FFmpeg is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
 * Lesser General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU Lesser General Public
18
 * License along with FFmpeg; if not, write to the Free Software
19
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
 */
21
22
/**
23
 * @file
24
 * @brief
25
 *     exp golomb vlc stuff
26
 * @author Michael Niedermayer <michaelni@gmx.at>
27
 */
28
29
#include "libavutil/common.h"
30
31
#ifdef CONFIG_SMALL
32
33
#include "golomb.h"
34
35
unsigned int get_bits(GetBitContext *s, int n)
36
0
{
37
0
    register int tmp;
38
0
    OPEN_READER(re, s);
39
0
    av_assert2(n>0 && n<=25);
40
0
    UPDATE_CACHE(re, s);
41
0
    tmp = SHOW_UBITS(re, s, n);
42
0
    LAST_SKIP_BITS(re, s, n);
43
0
    CLOSE_READER(re, s);
44
0
    return tmp;
45
0
}
46
47
/**
48
 * Show 1-25 bits.
49
 */
50
unsigned int show_bits(GetBitContext *s, int n)
51
0
{
52
0
    register int tmp;
53
0
    OPEN_READER_NOSIZE(re, s);
54
0
    av_assert2(n>0 && n<=25);
55
0
    UPDATE_CACHE(re, s);
56
0
    tmp = SHOW_UBITS(re, s, n);
57
0
    return tmp;
58
0
}
59
60
void skip_bits(GetBitContext *s, int n)
61
0
{
62
0
    OPEN_READER(re, s);
63
0
    LAST_SKIP_BITS(re, s, n);
64
0
    CLOSE_READER(re, s);
65
0
}
66
67
unsigned int get_bits1(GetBitContext *s)
68
0
{
69
0
    unsigned int index = s->index;
70
0
    uint8_t result     = s->buffer[index >> 3];
71
#ifdef BITSTREAM_READER_LE
72
    result >>= index & 7;
73
    result  &= 1;
74
#else
75
0
    result <<= index & 7;
76
0
    result >>= 8 - 1;
77
0
#endif
78
0
#if !UNCHECKED_BITSTREAM_READER
79
0
    if (s->index < s->size_in_bits_plus8)
80
0
#endif
81
0
        index++;
82
0
    s->index = index;
83
84
0
    return result;
85
0
}
86
87
unsigned int show_bits1(GetBitContext *s)
88
0
{
89
0
    return show_bits(s, 1);
90
0
}
91
92
void skip_bits1(GetBitContext *s)
93
0
{
94
0
    skip_bits(s, 1);
95
0
}
96
97
/**
98
 * Read 0-32 bits.
99
 */
100
unsigned int get_bits_long(GetBitContext *s, int n)
101
0
{
102
0
    if (!n) {
103
0
        return 0;
104
0
    } else if (n <= MIN_CACHE_BITS) {
105
0
        return get_bits(s, n);
106
0
    } else {
107
#ifdef BITSTREAM_READER_LE
108
        unsigned ret = get_bits(s, 16);
109
        return ret | (get_bits(s, n - 16) << 16);
110
#else
111
0
        unsigned ret = get_bits(s, 16) << (n - 16);
112
0
        return ret | get_bits(s, n - 16);
113
0
#endif
114
0
    }
115
0
}
116
117
unsigned get_ue_golomb_long(GetBitContext *gb)
118
0
{
119
0
    unsigned buf, log;
120
121
0
    buf = show_bits_long(gb, 32);
122
0
    log = 31 - av_log2(buf);
123
0
    skip_bits_long(gb, log);
124
125
0
    return get_bits_long(gb, log + 1) - 1;
126
0
}
127
128
int get_se_golomb_long(GetBitContext *gb)
129
0
{
130
0
    unsigned int buf = get_ue_golomb_long(gb);
131
132
0
    if (buf & 1)
133
0
        buf = (buf + 1) >> 1;
134
0
    else
135
0
        buf = -(buf >> 1);
136
137
0
    return buf;
138
0
}
139
140
#else
141
142
const uint8_t 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, 0, 0, 0,
172
 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
173
 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
174
 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
175
 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
176
 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
177
 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
178
};
179
180
const int8_t ff_se_golomb_vlc_code[512]={
181
 17, 17, 17, 17, 17, 17, 17, 17, 16, 17, 17, 17, 17, 17, 17, 17,  8, -8,  9, -9, 10,-10, 11,-11, 12,-12, 13,-13, 14,-14, 15,-15,
182
  4,  4,  4,  4, -4, -4, -4, -4,  5,  5,  5,  5, -5, -5, -5, -5,  6,  6,  6,  6, -6, -6, -6, -6,  7,  7,  7,  7, -7, -7, -7, -7,
183
  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
184
  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3,
185
  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,
186
  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,
187
 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
188
 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
189
  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
190
  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
191
  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
192
  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
193
  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
194
  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
195
  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
196
  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
197
};
198
199
const uint8_t ff_ue_golomb_len[256]={
200
 1, 3, 3, 5, 5, 5, 5, 7, 7, 7, 7, 7, 7, 7, 7, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,
201
11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,13,
202
13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
203
13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,15,
204
15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,
205
15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,
206
15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,
207
15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,17,
208
};
209
210
const uint8_t ff_interleaved_golomb_vlc_len[256]={
211
9,9,7,7,9,9,7,7,5,5,5,5,5,5,5,5,
212
9,9,7,7,9,9,7,7,5,5,5,5,5,5,5,5,
213
3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
214
3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
215
9,9,7,7,9,9,7,7,5,5,5,5,5,5,5,5,
216
9,9,7,7,9,9,7,7,5,5,5,5,5,5,5,5,
217
3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
218
3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
219
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
220
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
221
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
222
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
223
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
224
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
225
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
226
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
227
};
228
229
const uint8_t ff_interleaved_ue_golomb_vlc_code[256]={
230
 15,16,7, 7, 17,18,8, 8, 3, 3, 3, 3, 3, 3, 3, 3,
231
 19,20,9, 9, 21,22,10,10,4, 4, 4, 4, 4, 4, 4, 4,
232
 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
233
 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
234
 23,24,11,11,25,26,12,12,5, 5, 5, 5, 5, 5, 5, 5,
235
 27,28,13,13,29,30,14,14,6, 6, 6, 6, 6, 6, 6, 6,
236
 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
237
 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
238
 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
239
 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
240
 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
241
 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
242
 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
243
 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
244
 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
245
 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
246
};
247
248
const int8_t ff_interleaved_se_golomb_vlc_code[256]={
249
  8, -8,  4,  4,  9, -9, -4, -4,  2,  2,  2,  2,  2,  2,  2,  2,
250
 10,-10,  5,  5, 11,-11, -5, -5, -2, -2, -2, -2, -2, -2, -2, -2,
251
  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,
252
  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,
253
 12,-12,  6,  6, 13,-13, -6, -6,  3,  3,  3,  3,  3,  3,  3,  3,
254
 14,-14,  7,  7, 15,-15, -7, -7, -3, -3, -3, -3, -3, -3, -3, -3,
255
 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
256
 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
257
  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
258
  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
259
  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
260
  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
261
  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
262
  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
263
  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
264
  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
265
};
266
267
const uint8_t ff_interleaved_dirac_golomb_vlc_code[256]={
268
0, 1, 0, 0, 2, 3, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0,
269
4, 5, 2, 2, 6, 7, 3, 3, 1, 1, 1, 1, 1, 1, 1, 1,
270
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
271
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
272
8, 9, 4, 4, 10,11,5, 5, 2, 2, 2, 2, 2, 2, 2, 2,
273
12,13,6, 6, 14,15,7, 7, 3, 3, 3, 3, 3, 3, 3, 3,
274
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
275
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
276
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
277
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
278
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
279
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
280
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
281
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
282
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
283
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,};
284
285
#endif