2 * exp golomb vlc writing stuff
3 * Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
4 * Copyright (c) 2004 Alex Beregszaszi
6 * This file is part of FFmpeg.
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.
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.
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
26 * exp golomb vlc writing stuff
27 * @author Michael Niedermayer <michaelni@gmx.at> and Alex Beregszaszi
30 #ifndef AVCODEC_PUT_GOLOMB_H
31 #define AVCODEC_PUT_GOLOMB_H
36 extern const uint8_t ff_ue_golomb_len
[256];
39 * write unsigned exp golomb code. 2^16 - 2 at most
41 static inline void set_ue_golomb(PutBitContext
*pb
, int i
)
44 av_assert2(i
<= 0xFFFE);
47 put_bits(pb
, ff_ue_golomb_len
[i
], i
+ 1);
49 int e
= av_log2(i
+ 1);
50 put_bits(pb
, 2 * e
+ 1, i
+ 1);
55 * write unsigned exp golomb code. 2^32-2 at most.
57 static inline void set_ue_golomb_long(PutBitContext
*pb
, uint32_t i
)
59 av_assert2(i
<= (UINT32_MAX
- 1));
62 put_bits(pb
, ff_ue_golomb_len
[i
], i
+ 1);
64 int e
= av_log2(i
+ 1);
65 put_bits64(pb
, 2 * e
+ 1, i
+ 1);
70 * write truncated unsigned exp golomb code.
72 static inline void set_te_golomb(PutBitContext
*pb
, int i
, int range
)
74 av_assert2(range
>= 1);
75 av_assert2(i
<= range
);
78 put_bits(pb
, 1, i
^ 1);
84 * write signed exp golomb code. 16 bits at most.
86 static inline void set_se_golomb(PutBitContext
*pb
, int i
)
90 i
^= -1; //FIXME check if gcc does the right thing
95 * write unsigned golomb rice code (ffv1).
97 static inline void set_ur_golomb(PutBitContext
*pb
, int i
, int k
, int limit
,
106 put_bits(pb
, e
+ k
+ 1, (1 << k
) + av_zero_extend(i
, k
));
108 put_bits(pb
, limit
+ esc_len
, i
- limit
+ 1);
112 * write unsigned golomb rice code (jpegls).
114 static inline void set_ur_golomb_jpegls(PutBitContext
*pb
, int i
, int k
,
115 int limit
, int esc_len
)
135 put_bits(pb
, limit
, 1);
136 put_bits(pb
, esc_len
, i
- 1);
141 * write signed golomb rice code (ffv1).
143 static inline void set_sr_golomb(PutBitContext
*pb
, int i
, int k
, int limit
,
151 set_ur_golomb(pb
, v
, k
, limit
, esc_len
);
154 #endif /* AVCODEC_PUT_GOLOMB_H */