Mercurial > libavcodec.hg
annotate golomb.h @ 5229:604a09d6cf2e libavcodec
move ff_copy_bits to bitstream.c
author | aurel |
---|---|
date | Fri, 06 Jul 2007 14:13:25 +0000 |
parents | 2b72f9bc4f06 |
children | e12027d324cc |
rev | line source |
---|---|
1168 | 1 /* |
2 * exp golomb vlc stuff | |
3 * Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at> | |
2215 | 4 * Copyright (c) 2004 Alex Beregszaszi |
1168 | 5 * |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3353
diff
changeset
|
6 * This file is part of FFmpeg. |
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3353
diff
changeset
|
7 * |
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3353
diff
changeset
|
8 * FFmpeg is free software; you can redistribute it and/or |
1168 | 9 * modify it under the terms of the GNU Lesser General Public |
10 * License as published by the Free Software Foundation; either | |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3353
diff
changeset
|
11 * version 2.1 of the License, or (at your option) any later version. |
1168 | 12 * |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3353
diff
changeset
|
13 * FFmpeg is distributed in the hope that it will be useful, |
1168 | 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 | |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3353
diff
changeset
|
19 * License along with FFmpeg; if not, write to the Free Software |
3036
0b546eab515d
Update licensing information: The FSF changed postal address.
diego
parents:
2979
diff
changeset
|
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
1168 | 21 */ |
2967 | 22 |
1168 | 23 /** |
24 * @file golomb.h | |
2967 | 25 * @brief |
1168 | 26 * exp golomb vlc stuff |
2215 | 27 * @author Michael Niedermayer <michaelni@gmx.at> and Alex Beregszaszi |
1168 | 28 */ |
29 | |
5163 | 30 #ifndef AVCODEC_GOLOMB_H |
31 #define AVCODEC_GOLOMB_H | |
32 | |
5162 | 33 #include <stdint.h> |
34 #include "bitstream.h" | |
35 | |
1234 | 36 #define INVALID_VLC 0x80000000 |
37 | |
1168 | 38 extern const uint8_t ff_golomb_vlc_len[512]; |
39 extern const uint8_t ff_ue_golomb_vlc_code[512]; | |
40 extern const int8_t ff_se_golomb_vlc_code[512]; | |
41 extern const uint8_t ff_ue_golomb_len[256]; | |
42 | |
1250 | 43 extern const uint8_t ff_interleaved_golomb_vlc_len[256]; |
44 extern const uint8_t ff_interleaved_ue_golomb_vlc_code[256]; | |
45 extern const int8_t ff_interleaved_se_golomb_vlc_code[256]; | |
46 | |
2967 | 47 |
1168 | 48 /** |
49 * read unsigned exp golomb code. | |
50 */ | |
51 static inline int get_ue_golomb(GetBitContext *gb){ | |
52 unsigned int buf; | |
53 int log; | |
2967 | 54 |
1168 | 55 OPEN_READER(re, gb); |
56 UPDATE_CACHE(re, gb); | |
57 buf=GET_CACHE(re, gb); | |
2967 | 58 |
1168 | 59 if(buf >= (1<<27)){ |
60 buf >>= 32 - 9; | |
61 LAST_SKIP_BITS(re, gb, ff_golomb_vlc_len[buf]); | |
62 CLOSE_READER(re, gb); | |
2967 | 63 |
1168 | 64 return ff_ue_golomb_vlc_code[buf]; |
65 }else{ | |
66 log= 2*av_log2(buf) - 31; | |
67 buf>>= log; | |
68 buf--; | |
69 LAST_SKIP_BITS(re, gb, 32 - log); | |
70 CLOSE_READER(re, gb); | |
2967 | 71 |
1168 | 72 return buf; |
73 } | |
74 } | |
75 | |
1234 | 76 static inline int svq3_get_ue_golomb(GetBitContext *gb){ |
1250 | 77 uint32_t buf; |
1234 | 78 int log; |
79 | |
80 OPEN_READER(re, gb); | |
81 UPDATE_CACHE(re, gb); | |
1250 | 82 buf=GET_CACHE(re, gb); |
2967 | 83 |
1250 | 84 if(buf&0xAA800000){ |
85 buf >>= 32 - 8; | |
86 LAST_SKIP_BITS(re, gb, ff_interleaved_golomb_vlc_len[buf]); | |
87 CLOSE_READER(re, gb); | |
2967 | 88 |
1250 | 89 return ff_interleaved_ue_golomb_vlc_code[buf]; |
90 }else{ | |
2087
a4d3699c6636
1000l to the ffsvq3 author, our default bitstream reader is only guranteed to be able to read 25bit at a time
michael
parents:
1812
diff
changeset
|
91 LAST_SKIP_BITS(re, gb, 8); |
a4d3699c6636
1000l to the ffsvq3 author, our default bitstream reader is only guranteed to be able to read 25bit at a time
michael
parents:
1812
diff
changeset
|
92 UPDATE_CACHE(re, gb); |
a4d3699c6636
1000l to the ffsvq3 author, our default bitstream reader is only guranteed to be able to read 25bit at a time
michael
parents:
1812
diff
changeset
|
93 buf |= 1 | (GET_CACHE(re, gb) >> 8); |
a4d3699c6636
1000l to the ffsvq3 author, our default bitstream reader is only guranteed to be able to read 25bit at a time
michael
parents:
1812
diff
changeset
|
94 |
1250 | 95 if((buf & 0xAAAAAAAA) == 0) |
96 return INVALID_VLC; | |
1234 | 97 |
1250 | 98 for(log=31; (buf & 0x80000000) == 0; log--){ |
99 buf = (buf << 2) - ((buf << log) >> (log - 1)) + (buf >> 30); | |
100 } | |
1234 | 101 |
2087
a4d3699c6636
1000l to the ffsvq3 author, our default bitstream reader is only guranteed to be able to read 25bit at a time
michael
parents:
1812
diff
changeset
|
102 LAST_SKIP_BITS(re, gb, 63 - 2*log - 8); |
1250 | 103 CLOSE_READER(re, gb); |
1234 | 104 |
1250 | 105 return ((buf << log) >> log) - 1; |
106 } | |
1234 | 107 } |
108 | |
1168 | 109 /** |
110 * read unsigned truncated exp golomb code. | |
111 */ | |
112 static inline int get_te0_golomb(GetBitContext *gb, int range){ | |
113 assert(range >= 1); | |
2967 | 114 |
1168 | 115 if(range==1) return 0; |
1169 | 116 else if(range==2) return get_bits1(gb)^1; |
1168 | 117 else return get_ue_golomb(gb); |
118 } | |
119 | |
120 /** | |
121 * read unsigned truncated exp golomb code. | |
122 */ | |
123 static inline int get_te_golomb(GetBitContext *gb, int range){ | |
124 assert(range >= 1); | |
2967 | 125 |
1169 | 126 if(range==2) return get_bits1(gb)^1; |
1168 | 127 else return get_ue_golomb(gb); |
128 } | |
129 | |
130 | |
131 /** | |
132 * read signed exp golomb code. | |
133 */ | |
134 static inline int get_se_golomb(GetBitContext *gb){ | |
135 unsigned int buf; | |
136 int log; | |
2967 | 137 |
1168 | 138 OPEN_READER(re, gb); |
139 UPDATE_CACHE(re, gb); | |
140 buf=GET_CACHE(re, gb); | |
2967 | 141 |
1168 | 142 if(buf >= (1<<27)){ |
143 buf >>= 32 - 9; | |
144 LAST_SKIP_BITS(re, gb, ff_golomb_vlc_len[buf]); | |
145 CLOSE_READER(re, gb); | |
2967 | 146 |
1168 | 147 return ff_se_golomb_vlc_code[buf]; |
148 }else{ | |
149 log= 2*av_log2(buf) - 31; | |
150 buf>>= log; | |
2967 | 151 |
1168 | 152 LAST_SKIP_BITS(re, gb, 32 - log); |
153 CLOSE_READER(re, gb); | |
2967 | 154 |
1168 | 155 if(buf&1) buf= -(buf>>1); |
156 else buf= (buf>>1); | |
157 | |
158 return buf; | |
159 } | |
160 } | |
161 | |
1234 | 162 static inline int svq3_get_se_golomb(GetBitContext *gb){ |
163 unsigned int buf; | |
164 int log; | |
165 | |
166 OPEN_READER(re, gb); | |
167 UPDATE_CACHE(re, gb); | |
1250 | 168 buf=GET_CACHE(re, gb); |
1234 | 169 |
1250 | 170 if(buf&0xAA800000){ |
171 buf >>= 32 - 8; | |
172 LAST_SKIP_BITS(re, gb, ff_interleaved_golomb_vlc_len[buf]); | |
173 CLOSE_READER(re, gb); | |
2967 | 174 |
1250 | 175 return ff_interleaved_se_golomb_vlc_code[buf]; |
176 }else{ | |
2439 | 177 LAST_SKIP_BITS(re, gb, 8); |
178 UPDATE_CACHE(re, gb); | |
179 buf |= 1 | (GET_CACHE(re, gb) >> 8); | |
180 | |
1250 | 181 if((buf & 0xAAAAAAAA) == 0) |
182 return INVALID_VLC; | |
1234 | 183 |
1250 | 184 for(log=31; (buf & 0x80000000) == 0; log--){ |
185 buf = (buf << 2) - ((buf << log) >> (log - 1)) + (buf >> 30); | |
186 } | |
1234 | 187 |
2439 | 188 LAST_SKIP_BITS(re, gb, 63 - 2*log - 8); |
1250 | 189 CLOSE_READER(re, gb); |
190 | |
191 return (signed) (((((buf << log) >> log) - 1) ^ -(buf & 0x1)) + 1) >> 1; | |
192 } | |
1234 | 193 } |
194 | |
1306 | 195 /** |
1361
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
196 * read unsigned golomb rice code (ffv1). |
1306 | 197 */ |
198 static inline int get_ur_golomb(GetBitContext *gb, int k, int limit, int esc_len){ | |
199 unsigned int buf; | |
200 int log; | |
2967 | 201 |
1306 | 202 OPEN_READER(re, gb); |
203 UPDATE_CACHE(re, gb); | |
204 buf=GET_CACHE(re, gb); | |
205 | |
206 log= av_log2(buf); | |
1361
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
207 |
1306 | 208 if(log > 31-limit){ |
209 buf >>= log - k; | |
210 buf += (30-log)<<k; | |
211 LAST_SKIP_BITS(re, gb, 32 + k - log); | |
212 CLOSE_READER(re, gb); | |
2967 | 213 |
1306 | 214 return buf; |
1361
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
215 }else{ |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
216 buf >>= 32 - limit - esc_len; |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
217 LAST_SKIP_BITS(re, gb, esc_len + limit); |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
218 CLOSE_READER(re, gb); |
2967 | 219 |
1361
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
220 return buf + limit - 1; |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
221 } |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
222 } |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
223 |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
224 /** |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
225 * read unsigned golomb rice code (jpegls). |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
226 */ |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
227 static inline int get_ur_golomb_jpegls(GetBitContext *gb, int k, int limit, int esc_len){ |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
228 unsigned int buf; |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
229 int log; |
2967 | 230 |
1361
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
231 OPEN_READER(re, gb); |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
232 UPDATE_CACHE(re, gb); |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
233 buf=GET_CACHE(re, gb); |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
234 |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
235 log= av_log2(buf); |
2967 | 236 |
1362 | 237 if(log > 31-11){ |
1361
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
238 buf >>= log - k; |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
239 buf += (30-log)<<k; |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
240 LAST_SKIP_BITS(re, gb, 32 + k - log); |
1306 | 241 CLOSE_READER(re, gb); |
2967 | 242 |
1361
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
243 return buf; |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
244 }else{ |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
245 int i; |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
246 for(i=0; SHOW_UBITS(re, gb, 1) == 0; i++){ |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
247 LAST_SKIP_BITS(re, gb, 1); |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
248 UPDATE_CACHE(re, gb); |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
249 } |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
250 SKIP_BITS(re, gb, 1); |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
251 |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
252 if(i < limit - 1){ |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
253 if(k){ |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
254 buf = SHOW_UBITS(re, gb, k); |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
255 LAST_SKIP_BITS(re, gb, k); |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
256 }else{ |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
257 buf=0; |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
258 } |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
259 |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
260 CLOSE_READER(re, gb); |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
261 return buf + (i<<k); |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
262 }else if(i == limit - 1){ |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
263 buf = SHOW_UBITS(re, gb, esc_len); |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
264 LAST_SKIP_BITS(re, gb, esc_len); |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
265 CLOSE_READER(re, gb); |
2967 | 266 |
1361
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
267 return buf + 1; |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
268 }else |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
269 return -1; |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
270 } |
1306 | 271 } |
272 | |
1812 | 273 /** |
2215 | 274 * read signed golomb rice code (ffv1). |
275 */ | |
2220 | 276 static inline int get_sr_golomb(GetBitContext *gb, int k, int limit, int esc_len){ |
2215 | 277 int v= get_ur_golomb(gb, k, limit, esc_len); |
2967 | 278 |
2215 | 279 v++; |
280 if (v&1) return v>>1; | |
281 else return -(v>>1); | |
2967 | 282 |
2215 | 283 // return (v>>1) ^ -(v&1); |
284 } | |
2220 | 285 |
2215 | 286 /** |
287 * read signed golomb rice code (flac). | |
1812 | 288 */ |
289 static inline int get_sr_golomb_flac(GetBitContext *gb, int k, int limit, int esc_len){ | |
290 int v= get_ur_golomb_jpegls(gb, k, limit, esc_len); | |
291 return (v>>1) ^ -(v&1); | |
292 } | |
293 | |
2525
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
2439
diff
changeset
|
294 /** |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
2439
diff
changeset
|
295 * read unsigned golomb rice code (shorten). |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
2439
diff
changeset
|
296 */ |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
2439
diff
changeset
|
297 static inline unsigned int get_ur_golomb_shorten(GetBitContext *gb, int k){ |
2979 | 298 return get_ur_golomb_jpegls(gb, k, INT_MAX, 0); |
2525
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
2439
diff
changeset
|
299 } |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
2439
diff
changeset
|
300 |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
2439
diff
changeset
|
301 /** |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
2439
diff
changeset
|
302 * read signed golomb rice code (shorten). |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
2439
diff
changeset
|
303 */ |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
2439
diff
changeset
|
304 static inline int get_sr_golomb_shorten(GetBitContext* gb, int k) |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
2439
diff
changeset
|
305 { |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
2439
diff
changeset
|
306 int uvar = get_ur_golomb_jpegls(gb, k + 1, INT_MAX, 0); |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
2439
diff
changeset
|
307 if (uvar & 1) |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
2439
diff
changeset
|
308 return ~(uvar >> 1); |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
2439
diff
changeset
|
309 else |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
2439
diff
changeset
|
310 return uvar >> 1; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
2439
diff
changeset
|
311 } |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
2439
diff
changeset
|
312 |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
2439
diff
changeset
|
313 |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
2439
diff
changeset
|
314 |
1168 | 315 #ifdef TRACE |
316 | |
2438
e98b5e0de86b
compile with TRACE define patch by (Loic <lll+ffmpeg m4x org>)
michael
parents:
2220
diff
changeset
|
317 static inline int get_ue(GetBitContext *s, char *file, const char *func, int line){ |
1168 | 318 int show= show_bits(s, 24); |
319 int pos= get_bits_count(s); | |
320 int i= get_ue_golomb(s); | |
321 int len= get_bits_count(s) - pos; | |
322 int bits= show>>(24-len); | |
2967 | 323 |
1168 | 324 print_bin(bits, len); |
2967 | 325 |
2215 | 326 av_log(NULL, AV_LOG_DEBUG, "%5d %2d %3d ue @%5d in %s %s:%d\n", bits, len, i, pos, file, func, line); |
2967 | 327 |
1168 | 328 return i; |
329 } | |
330 | |
2438
e98b5e0de86b
compile with TRACE define patch by (Loic <lll+ffmpeg m4x org>)
michael
parents:
2220
diff
changeset
|
331 static inline int get_se(GetBitContext *s, char *file, const char *func, int line){ |
1168 | 332 int show= show_bits(s, 24); |
333 int pos= get_bits_count(s); | |
334 int i= get_se_golomb(s); | |
335 int len= get_bits_count(s) - pos; | |
336 int bits= show>>(24-len); | |
2967 | 337 |
1168 | 338 print_bin(bits, len); |
2967 | 339 |
2215 | 340 av_log(NULL, AV_LOG_DEBUG, "%5d %2d %3d se @%5d in %s %s:%d\n", bits, len, i, pos, file, func, line); |
2967 | 341 |
1168 | 342 return i; |
343 } | |
344 | |
2438
e98b5e0de86b
compile with TRACE define patch by (Loic <lll+ffmpeg m4x org>)
michael
parents:
2220
diff
changeset
|
345 static inline int get_te(GetBitContext *s, int r, char *file, const char *func, int line){ |
1168 | 346 int show= show_bits(s, 24); |
347 int pos= get_bits_count(s); | |
348 int i= get_te0_golomb(s, r); | |
349 int len= get_bits_count(s) - pos; | |
350 int bits= show>>(24-len); | |
2967 | 351 |
1168 | 352 print_bin(bits, len); |
2967 | 353 |
2215 | 354 av_log(NULL, AV_LOG_DEBUG, "%5d %2d %3d te @%5d in %s %s:%d\n", bits, len, i, pos, file, func, line); |
2967 | 355 |
1168 | 356 return i; |
357 } | |
358 | |
359 #define get_ue_golomb(a) get_ue(a, __FILE__, __PRETTY_FUNCTION__, __LINE__) | |
360 #define get_se_golomb(a) get_se(a, __FILE__, __PRETTY_FUNCTION__, __LINE__) | |
361 #define get_te_golomb(a, r) get_te(a, r, __FILE__, __PRETTY_FUNCTION__, __LINE__) | |
362 #define get_te0_golomb(a, r) get_te(a, r, __FILE__, __PRETTY_FUNCTION__, __LINE__) | |
363 | |
364 #endif | |
365 | |
366 /** | |
367 * write unsigned exp golomb code. | |
368 */ | |
369 static inline void set_ue_golomb(PutBitContext *pb, int i){ | |
370 int e; | |
2967 | 371 |
1168 | 372 assert(i>=0); |
373 | |
374 #if 0 | |
375 if(i=0){ | |
376 put_bits(pb, 1, 1); | |
377 return; | |
378 } | |
379 #endif | |
380 if(i<256) | |
381 put_bits(pb, ff_ue_golomb_len[i], i+1); | |
382 else{ | |
383 e= av_log2(i+1); | |
2967 | 384 |
1168 | 385 put_bits(pb, 2*e+1, i+1); |
386 } | |
387 } | |
388 | |
389 /** | |
390 * write truncated unsigned exp golomb code. | |
391 */ | |
392 static inline void set_te_golomb(PutBitContext *pb, int i, int range){ | |
393 assert(range >= 1); | |
394 assert(i<=range); | |
395 | |
1169 | 396 if(range==2) put_bits(pb, 1, i^1); |
1168 | 397 else set_ue_golomb(pb, i); |
398 } | |
399 | |
400 /** | |
2905
926ea374947f
set_se_golomb can only write 16bits, add a note about this (ok, maybe it's brain dead using it with more than 16bits, but..)
alex
parents:
2525
diff
changeset
|
401 * write signed exp golomb code. 16 bits at most. |
1168 | 402 */ |
403 static inline void set_se_golomb(PutBitContext *pb, int i){ | |
2905
926ea374947f
set_se_golomb can only write 16bits, add a note about this (ok, maybe it's brain dead using it with more than 16bits, but..)
alex
parents:
2525
diff
changeset
|
404 // if (i>32767 || i<-32767) |
2979 | 405 // av_log(NULL,AV_LOG_ERROR,"value out of range %d\n", i); |
2967 | 406 #if 0 |
1168 | 407 if(i<=0) i= -2*i; |
408 else i= 2*i-1; | |
409 #elif 1 | |
410 i= 2*i-1; | |
411 if(i<0) i^= -1; //FIXME check if gcc does the right thing | |
412 #else | |
413 i= 2*i-1; | |
414 i^= (i>>31); | |
415 #endif | |
416 set_ue_golomb(pb, i); | |
417 } | |
1306 | 418 |
419 /** | |
1361
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
420 * write unsigned golomb rice code (ffv1). |
1306 | 421 */ |
422 static inline void set_ur_golomb(PutBitContext *pb, int i, int k, int limit, int esc_len){ | |
423 int e; | |
2967 | 424 |
1306 | 425 assert(i>=0); |
2967 | 426 |
1306 | 427 e= i>>k; |
428 if(e<limit){ | |
429 put_bits(pb, e + k + 1, (1<<k) + (i&((1<<k)-1))); | |
430 }else{ | |
1361
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
431 put_bits(pb, limit + esc_len, i - limit + 1); |
1306 | 432 } |
433 } | |
1361
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
434 |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
435 /** |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
436 * write unsigned golomb rice code (jpegls). |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
437 */ |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
438 static inline void set_ur_golomb_jpegls(PutBitContext *pb, int i, int k, int limit, int esc_len){ |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
439 int e; |
2967 | 440 |
1361
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
441 assert(i>=0); |
2967 | 442 |
1361
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
443 e= (i>>k) + 1; |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
444 if(e<limit){ |
3353
5b901881d6ed
first rudimentary version of (Justin Ruggles jruggle earthlink net) flac encoder
michael
parents:
3036
diff
changeset
|
445 while(e > 31) { |
5b901881d6ed
first rudimentary version of (Justin Ruggles jruggle earthlink net) flac encoder
michael
parents:
3036
diff
changeset
|
446 put_bits(pb, 31, 0); |
5b901881d6ed
first rudimentary version of (Justin Ruggles jruggle earthlink net) flac encoder
michael
parents:
3036
diff
changeset
|
447 e -= 31; |
5b901881d6ed
first rudimentary version of (Justin Ruggles jruggle earthlink net) flac encoder
michael
parents:
3036
diff
changeset
|
448 } |
1361
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
449 put_bits(pb, e, 1); |
1362 | 450 if(k) |
451 put_bits(pb, k, i&((1<<k)-1)); | |
1361
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
452 }else{ |
4053 | 453 while(limit > 31) { |
454 put_bits(pb, 31, 0); | |
455 limit -= 31; | |
456 } | |
1361
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
457 put_bits(pb, limit , 1); |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
458 put_bits(pb, esc_len, i - 1); |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
459 } |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
460 } |
2215 | 461 |
462 /** | |
463 * write signed golomb rice code (ffv1). | |
464 */ | |
2220 | 465 static inline void set_sr_golomb(PutBitContext *pb, int i, int k, int limit, int esc_len){ |
2215 | 466 int v; |
467 | |
468 v = -2*i-1; | |
469 v ^= (v>>31); | |
470 | |
471 set_ur_golomb(pb, v, k, limit, esc_len); | |
472 } | |
473 | |
474 /** | |
475 * write signed golomb rice code (flac). | |
476 */ | |
477 static inline void set_sr_golomb_flac(PutBitContext *pb, int i, int k, int limit, int esc_len){ | |
478 int v; | |
479 | |
480 v = -2*i-1; | |
481 v ^= (v>>31); | |
482 | |
483 set_ur_golomb_jpegls(pb, v, k, limit, esc_len); | |
484 } | |
5163 | 485 |
5169
3fd46e281bd8
add a comment to indicate which #endif belong to which #define
gpoirier
parents:
5163
diff
changeset
|
486 #endif // AVCODEC_GOLOMB_H |