1 /*
2 * This file is part of FFmpeg.
3 *
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19 #include <stdint.h>
20 #include <string.h>
21
25
27
29 {
30 int i;
31
32 for (i = 0; i < 2; i++) {
36 }
37 }
38
41 {
45
46 /* If table is static, we can quit if rl->max_level[0] is not NULL */
48 return 0;
49
50 /* compute max_level[], max_run[] and index_run[] */
51 for (last = 0; last < 2; last++) {
52 if (last == 0) {
53 start = 0;
55 } else {
58 }
59
60 memset(max_level, 0,
MAX_RUN + 1);
62 memset(index_run, rl->
n,
MAX_RUN + 1);
63 for (i = start; i <
end; i++) {
66 if (index_run[run] == rl->
n)
68 if (level > max_level[run])
70 if (run > max_run[level])
72 }
73 if (static_store)
75 else {
79 }
81 if (static_store)
83 else {
87 }
89 if (static_store)
91 else {
95 }
96 memcpy(rl->
index_run[last], index_run, MAX_RUN + 1);
97 }
98 return 0;
99
103 }
104
106 {
107 int i, q;
109 VLC vlc = { .
table =
table, .table_allocated = static_size };
112
113 for (q = 0; q < 32; q++) {
114 int qmul = q * 2;
115 int qadd = (q - 1) | 1;
116
117 if (q == 0) {
118 qmul = 1;
119 qadd = 0;
120 }
122 int code = vlc.
table[i][0];
125
126 if (len == 0) { // illegal code
127 run = 66;
129 } else if (len < 0) { // more bits needed
130 run = 0;
131 level = code;
132 } else {
133 if (code == rl->
n) {
// esc
134 run = 66;
135 level = 0;
136 } else {
139 if (code >= rl->
last) run += 192;
140 }
141 }
145 }
146 }
147 }
int last
number of values for last = 0
Memory handling functions.
const int8_t * table_level
Macro definitions for various function/variable attributes.
#define av_assert0(cond)
assert() equivalent, that is always enabled.
int8_t * max_run[2]
encoding & decoding
static av_cold int end(AVCodecContext *avctx)
int8_t * max_level[2]
encoding & decoding
#define init_vlc(vlc, nb_bits, nb_codes,bits, bits_wrap, bits_size,codes, codes_wrap, codes_size,flags)
static const struct endianess table[]
simple assert() macros that are a bit more flexible than ISO C assert().
int n
number of entries of table_vlc minus 1
const uint16_t(* table_vlc)[2]
void ff_rl_free(RLTable *rl)
Free the contents of a dynamically allocated table.
RL_VLC_ELEM * rl_vlc[32]
decoding only
#define FF_ARRAY_ELEMS(a)
av_cold int ff_rl_init(RLTable *rl, uint8_t static_store[2][2 *MAX_RUN+MAX_LEVEL+3])
uint8_t * index_run[2]
encoding only
#define INIT_VLC_USE_NEW_STATIC
VLC_TYPE(* table)[2]
code, bits
av_cold void ff_rl_init_vlc(RLTable *rl, unsigned static_size)