Mercurial > libavcodec.hg
annotate golomb.h @ 8326:678c7604463e libavcodec
Document register_avcodec().
author | stefano |
---|---|
date | Sun, 14 Dec 2008 20:04:41 +0000 |
parents | cd18f66b3663 |
children | d6faaf27eacf |
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 | |
7760 | 30 #ifndef AVCODEC_GOLOMB_H |
31 #define AVCODEC_GOLOMB_H | |
5163 | 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]; | |
5546 | 46 extern const uint8_t ff_interleaved_dirac_golomb_vlc_code[256]; |
1250 | 47 |
2967 | 48 |
1168 | 49 /** |
50 * read unsigned exp golomb code. | |
51 */ | |
52 static inline int get_ue_golomb(GetBitContext *gb){ | |
53 unsigned int buf; | |
54 int log; | |
2967 | 55 |
1168 | 56 OPEN_READER(re, gb); |
57 UPDATE_CACHE(re, gb); | |
58 buf=GET_CACHE(re, gb); | |
2967 | 59 |
1168 | 60 if(buf >= (1<<27)){ |
61 buf >>= 32 - 9; | |
62 LAST_SKIP_BITS(re, gb, ff_golomb_vlc_len[buf]); | |
63 CLOSE_READER(re, gb); | |
2967 | 64 |
1168 | 65 return ff_ue_golomb_vlc_code[buf]; |
66 }else{ | |
67 log= 2*av_log2(buf) - 31; | |
68 buf>>= log; | |
69 buf--; | |
70 LAST_SKIP_BITS(re, gb, 32 - log); | |
71 CLOSE_READER(re, gb); | |
2967 | 72 |
1168 | 73 return buf; |
74 } | |
75 } | |
76 | |
1234 | 77 static inline int svq3_get_ue_golomb(GetBitContext *gb){ |
1250 | 78 uint32_t buf; |
1234 | 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{ | |
5546 | 91 int ret = 1; |
92 | |
93 while (1) { | |
94 buf >>= 32 - 8; | |
95 LAST_SKIP_BITS(re, gb, FFMIN(ff_interleaved_golomb_vlc_len[buf], 8)); | |
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
|
96 |
5546 | 97 if (ff_interleaved_golomb_vlc_len[buf] != 9){ |
98 ret <<= (ff_interleaved_golomb_vlc_len[buf] - 1) >> 1; | |
99 ret |= ff_interleaved_dirac_golomb_vlc_code[buf]; | |
100 break; | |
101 } | |
102 ret = (ret << 4) | ff_interleaved_dirac_golomb_vlc_code[buf]; | |
103 UPDATE_CACHE(re, gb); | |
104 buf = GET_CACHE(re, gb); | |
1250 | 105 } |
1234 | 106 |
1250 | 107 CLOSE_READER(re, gb); |
5546 | 108 return ret - 1; |
1250 | 109 } |
1234 | 110 } |
111 | |
1168 | 112 /** |
113 * read unsigned truncated exp golomb code. | |
114 */ | |
115 static inline int get_te0_golomb(GetBitContext *gb, int range){ | |
116 assert(range >= 1); | |
2967 | 117 |
1168 | 118 if(range==1) return 0; |
1169 | 119 else if(range==2) return get_bits1(gb)^1; |
1168 | 120 else return get_ue_golomb(gb); |
121 } | |
122 | |
123 /** | |
124 * read unsigned truncated exp golomb code. | |
125 */ | |
126 static inline int get_te_golomb(GetBitContext *gb, int range){ | |
127 assert(range >= 1); | |
2967 | 128 |
1169 | 129 if(range==2) return get_bits1(gb)^1; |
1168 | 130 else return get_ue_golomb(gb); |
131 } | |
132 | |
133 | |
134 /** | |
135 * read signed exp golomb code. | |
136 */ | |
137 static inline int get_se_golomb(GetBitContext *gb){ | |
138 unsigned int buf; | |
139 int log; | |
2967 | 140 |
1168 | 141 OPEN_READER(re, gb); |
142 UPDATE_CACHE(re, gb); | |
143 buf=GET_CACHE(re, gb); | |
2967 | 144 |
1168 | 145 if(buf >= (1<<27)){ |
146 buf >>= 32 - 9; | |
147 LAST_SKIP_BITS(re, gb, ff_golomb_vlc_len[buf]); | |
148 CLOSE_READER(re, gb); | |
2967 | 149 |
1168 | 150 return ff_se_golomb_vlc_code[buf]; |
151 }else{ | |
152 log= 2*av_log2(buf) - 31; | |
153 buf>>= log; | |
2967 | 154 |
1168 | 155 LAST_SKIP_BITS(re, gb, 32 - log); |
156 CLOSE_READER(re, gb); | |
2967 | 157 |
1168 | 158 if(buf&1) buf= -(buf>>1); |
159 else buf= (buf>>1); | |
160 | |
161 return buf; | |
162 } | |
163 } | |
164 | |
1234 | 165 static inline int svq3_get_se_golomb(GetBitContext *gb){ |
166 unsigned int buf; | |
167 int log; | |
168 | |
169 OPEN_READER(re, gb); | |
170 UPDATE_CACHE(re, gb); | |
1250 | 171 buf=GET_CACHE(re, gb); |
1234 | 172 |
1250 | 173 if(buf&0xAA800000){ |
174 buf >>= 32 - 8; | |
175 LAST_SKIP_BITS(re, gb, ff_interleaved_golomb_vlc_len[buf]); | |
176 CLOSE_READER(re, gb); | |
2967 | 177 |
1250 | 178 return ff_interleaved_se_golomb_vlc_code[buf]; |
179 }else{ | |
2439 | 180 LAST_SKIP_BITS(re, gb, 8); |
181 UPDATE_CACHE(re, gb); | |
182 buf |= 1 | (GET_CACHE(re, gb) >> 8); | |
183 | |
1250 | 184 if((buf & 0xAAAAAAAA) == 0) |
185 return INVALID_VLC; | |
1234 | 186 |
1250 | 187 for(log=31; (buf & 0x80000000) == 0; log--){ |
188 buf = (buf << 2) - ((buf << log) >> (log - 1)) + (buf >> 30); | |
189 } | |
1234 | 190 |
2439 | 191 LAST_SKIP_BITS(re, gb, 63 - 2*log - 8); |
1250 | 192 CLOSE_READER(re, gb); |
193 | |
194 return (signed) (((((buf << log) >> log) - 1) ^ -(buf & 0x1)) + 1) >> 1; | |
195 } | |
1234 | 196 } |
197 | |
5546 | 198 static inline int dirac_get_se_golomb(GetBitContext *gb){ |
199 uint32_t buf; | |
200 uint32_t ret; | |
201 | |
202 ret = svq3_get_ue_golomb(gb); | |
203 | |
204 if (ret) { | |
205 OPEN_READER(re, gb); | |
206 UPDATE_CACHE(re, gb); | |
207 buf = SHOW_SBITS(re, gb, 1); | |
208 LAST_SKIP_BITS(re, gb, 1); | |
209 ret = (ret ^ buf) - buf; | |
210 CLOSE_READER(re, gb); | |
211 } | |
212 | |
213 return ret; | |
214 } | |
215 | |
1306 | 216 /** |
1361
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
217 * read unsigned golomb rice code (ffv1). |
1306 | 218 */ |
219 static inline int get_ur_golomb(GetBitContext *gb, int k, int limit, int esc_len){ | |
220 unsigned int buf; | |
221 int log; | |
2967 | 222 |
1306 | 223 OPEN_READER(re, gb); |
224 UPDATE_CACHE(re, gb); | |
225 buf=GET_CACHE(re, gb); | |
226 | |
227 log= av_log2(buf); | |
1361
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
228 |
1306 | 229 if(log > 31-limit){ |
230 buf >>= log - k; | |
231 buf += (30-log)<<k; | |
232 LAST_SKIP_BITS(re, gb, 32 + k - log); | |
233 CLOSE_READER(re, gb); | |
2967 | 234 |
1306 | 235 return buf; |
1361
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
236 }else{ |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
237 buf >>= 32 - limit - esc_len; |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
238 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
|
239 CLOSE_READER(re, gb); |
2967 | 240 |
1361
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
241 return buf + limit - 1; |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
242 } |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
243 } |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
244 |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
245 /** |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
246 * read unsigned golomb rice code (jpegls). |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
247 */ |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
248 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
|
249 unsigned int buf; |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
250 int log; |
2967 | 251 |
1361
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
252 OPEN_READER(re, gb); |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
253 UPDATE_CACHE(re, gb); |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
254 buf=GET_CACHE(re, gb); |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
255 |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
256 log= av_log2(buf); |
2967 | 257 |
7869
cd18f66b3663
Fix regression test failure caused by golomb limit not being considered
michael
parents:
7866
diff
changeset
|
258 if(log - k >= 32-MIN_CACHE_BITS && 32-log < limit){ |
1361
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
259 buf >>= log - k; |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
260 buf += (30-log)<<k; |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
261 LAST_SKIP_BITS(re, gb, 32 + k - log); |
1306 | 262 CLOSE_READER(re, gb); |
2967 | 263 |
1361
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
264 return buf; |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
265 }else{ |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
266 int i; |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
267 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
|
268 LAST_SKIP_BITS(re, gb, 1); |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
269 UPDATE_CACHE(re, gb); |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
270 } |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
271 SKIP_BITS(re, gb, 1); |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
272 |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
273 if(i < limit - 1){ |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
274 if(k){ |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
275 buf = SHOW_UBITS(re, gb, k); |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
276 LAST_SKIP_BITS(re, gb, k); |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
277 }else{ |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
278 buf=0; |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
279 } |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
280 |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
281 CLOSE_READER(re, gb); |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
282 return buf + (i<<k); |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
283 }else if(i == limit - 1){ |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
284 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
|
285 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
|
286 CLOSE_READER(re, gb); |
2967 | 287 |
1361
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
288 return buf + 1; |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
289 }else |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
290 return -1; |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
291 } |
1306 | 292 } |
293 | |
1812 | 294 /** |
2215 | 295 * read signed golomb rice code (ffv1). |
296 */ | |
2220 | 297 static inline int get_sr_golomb(GetBitContext *gb, int k, int limit, int esc_len){ |
2215 | 298 int v= get_ur_golomb(gb, k, limit, esc_len); |
2967 | 299 |
2215 | 300 v++; |
301 if (v&1) return v>>1; | |
302 else return -(v>>1); | |
2967 | 303 |
2215 | 304 // return (v>>1) ^ -(v&1); |
305 } | |
2220 | 306 |
2215 | 307 /** |
308 * read signed golomb rice code (flac). | |
1812 | 309 */ |
310 static inline int get_sr_golomb_flac(GetBitContext *gb, int k, int limit, int esc_len){ | |
311 int v= get_ur_golomb_jpegls(gb, k, limit, esc_len); | |
312 return (v>>1) ^ -(v&1); | |
313 } | |
314 | |
2525
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
2439
diff
changeset
|
315 /** |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
2439
diff
changeset
|
316 * read unsigned golomb rice code (shorten). |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
2439
diff
changeset
|
317 */ |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
2439
diff
changeset
|
318 static inline unsigned int get_ur_golomb_shorten(GetBitContext *gb, int k){ |
2979 | 319 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
|
320 } |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
2439
diff
changeset
|
321 |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
2439
diff
changeset
|
322 /** |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
2439
diff
changeset
|
323 * read signed golomb rice code (shorten). |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
2439
diff
changeset
|
324 */ |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
2439
diff
changeset
|
325 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
|
326 { |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
2439
diff
changeset
|
327 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
|
328 if (uvar & 1) |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
2439
diff
changeset
|
329 return ~(uvar >> 1); |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
2439
diff
changeset
|
330 else |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
2439
diff
changeset
|
331 return uvar >> 1; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
2439
diff
changeset
|
332 } |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
2439
diff
changeset
|
333 |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
2439
diff
changeset
|
334 |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
2439
diff
changeset
|
335 |
1168 | 336 #ifdef TRACE |
337 | |
2438
e98b5e0de86b
compile with TRACE define patch by (Loic <lll+ffmpeg m4x org>)
michael
parents:
2220
diff
changeset
|
338 static inline int get_ue(GetBitContext *s, char *file, const char *func, int line){ |
1168 | 339 int show= show_bits(s, 24); |
340 int pos= get_bits_count(s); | |
341 int i= get_ue_golomb(s); | |
342 int len= get_bits_count(s) - pos; | |
343 int bits= show>>(24-len); | |
2967 | 344 |
1168 | 345 print_bin(bits, len); |
2967 | 346 |
2215 | 347 av_log(NULL, AV_LOG_DEBUG, "%5d %2d %3d ue @%5d in %s %s:%d\n", bits, len, i, pos, file, func, line); |
2967 | 348 |
1168 | 349 return i; |
350 } | |
351 | |
2438
e98b5e0de86b
compile with TRACE define patch by (Loic <lll+ffmpeg m4x org>)
michael
parents:
2220
diff
changeset
|
352 static inline int get_se(GetBitContext *s, char *file, const char *func, int line){ |
1168 | 353 int show= show_bits(s, 24); |
354 int pos= get_bits_count(s); | |
355 int i= get_se_golomb(s); | |
356 int len= get_bits_count(s) - pos; | |
357 int bits= show>>(24-len); | |
2967 | 358 |
1168 | 359 print_bin(bits, len); |
2967 | 360 |
2215 | 361 av_log(NULL, AV_LOG_DEBUG, "%5d %2d %3d se @%5d in %s %s:%d\n", bits, len, i, pos, file, func, line); |
2967 | 362 |
1168 | 363 return i; |
364 } | |
365 | |
2438
e98b5e0de86b
compile with TRACE define patch by (Loic <lll+ffmpeg m4x org>)
michael
parents:
2220
diff
changeset
|
366 static inline int get_te(GetBitContext *s, int r, char *file, const char *func, int line){ |
1168 | 367 int show= show_bits(s, 24); |
368 int pos= get_bits_count(s); | |
369 int i= get_te0_golomb(s, r); | |
370 int len= get_bits_count(s) - pos; | |
371 int bits= show>>(24-len); | |
2967 | 372 |
1168 | 373 print_bin(bits, len); |
2967 | 374 |
2215 | 375 av_log(NULL, AV_LOG_DEBUG, "%5d %2d %3d te @%5d in %s %s:%d\n", bits, len, i, pos, file, func, line); |
2967 | 376 |
1168 | 377 return i; |
378 } | |
379 | |
380 #define get_ue_golomb(a) get_ue(a, __FILE__, __PRETTY_FUNCTION__, __LINE__) | |
381 #define get_se_golomb(a) get_se(a, __FILE__, __PRETTY_FUNCTION__, __LINE__) | |
382 #define get_te_golomb(a, r) get_te(a, r, __FILE__, __PRETTY_FUNCTION__, __LINE__) | |
383 #define get_te0_golomb(a, r) get_te(a, r, __FILE__, __PRETTY_FUNCTION__, __LINE__) | |
384 | |
385 #endif | |
386 | |
387 /** | |
388 * write unsigned exp golomb code. | |
389 */ | |
390 static inline void set_ue_golomb(PutBitContext *pb, int i){ | |
391 int e; | |
2967 | 392 |
1168 | 393 assert(i>=0); |
394 | |
395 #if 0 | |
396 if(i=0){ | |
397 put_bits(pb, 1, 1); | |
398 return; | |
399 } | |
400 #endif | |
401 if(i<256) | |
402 put_bits(pb, ff_ue_golomb_len[i], i+1); | |
403 else{ | |
404 e= av_log2(i+1); | |
2967 | 405 |
1168 | 406 put_bits(pb, 2*e+1, i+1); |
407 } | |
408 } | |
409 | |
410 /** | |
411 * write truncated unsigned exp golomb code. | |
412 */ | |
413 static inline void set_te_golomb(PutBitContext *pb, int i, int range){ | |
414 assert(range >= 1); | |
415 assert(i<=range); | |
416 | |
1169 | 417 if(range==2) put_bits(pb, 1, i^1); |
1168 | 418 else set_ue_golomb(pb, i); |
419 } | |
420 | |
421 /** | |
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
|
422 * write signed exp golomb code. 16 bits at most. |
1168 | 423 */ |
424 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
|
425 // if (i>32767 || i<-32767) |
2979 | 426 // av_log(NULL,AV_LOG_ERROR,"value out of range %d\n", i); |
2967 | 427 #if 0 |
1168 | 428 if(i<=0) i= -2*i; |
429 else i= 2*i-1; | |
430 #elif 1 | |
431 i= 2*i-1; | |
432 if(i<0) i^= -1; //FIXME check if gcc does the right thing | |
433 #else | |
434 i= 2*i-1; | |
435 i^= (i>>31); | |
436 #endif | |
437 set_ue_golomb(pb, i); | |
438 } | |
1306 | 439 |
440 /** | |
1361
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
441 * write unsigned golomb rice code (ffv1). |
1306 | 442 */ |
443 static inline void set_ur_golomb(PutBitContext *pb, int i, int k, int limit, int esc_len){ | |
444 int e; | |
2967 | 445 |
1306 | 446 assert(i>=0); |
2967 | 447 |
1306 | 448 e= i>>k; |
449 if(e<limit){ | |
450 put_bits(pb, e + k + 1, (1<<k) + (i&((1<<k)-1))); | |
451 }else{ | |
1361
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
452 put_bits(pb, limit + esc_len, i - limit + 1); |
1306 | 453 } |
454 } | |
1361
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
455 |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
456 /** |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
457 * write unsigned golomb rice code (jpegls). |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
458 */ |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
459 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
|
460 int e; |
2967 | 461 |
1361
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
462 assert(i>=0); |
2967 | 463 |
1361
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
464 e= (i>>k) + 1; |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
465 if(e<limit){ |
3353
5b901881d6ed
first rudimentary version of (Justin Ruggles jruggle earthlink net) flac encoder
michael
parents:
3036
diff
changeset
|
466 while(e > 31) { |
5b901881d6ed
first rudimentary version of (Justin Ruggles jruggle earthlink net) flac encoder
michael
parents:
3036
diff
changeset
|
467 put_bits(pb, 31, 0); |
5b901881d6ed
first rudimentary version of (Justin Ruggles jruggle earthlink net) flac encoder
michael
parents:
3036
diff
changeset
|
468 e -= 31; |
5b901881d6ed
first rudimentary version of (Justin Ruggles jruggle earthlink net) flac encoder
michael
parents:
3036
diff
changeset
|
469 } |
1361
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
470 put_bits(pb, e, 1); |
1362 | 471 if(k) |
7260
3ec34b551aae
bitstream: move put_sbits() from flacenc.c to bitstream.h and use it
ramiro
parents:
5830
diff
changeset
|
472 put_sbits(pb, k, i); |
1361
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
473 }else{ |
4053 | 474 while(limit > 31) { |
475 put_bits(pb, 31, 0); | |
476 limit -= 31; | |
477 } | |
1361
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
478 put_bits(pb, limit , 1); |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
479 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
|
480 } |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
481 } |
2215 | 482 |
483 /** | |
484 * write signed golomb rice code (ffv1). | |
485 */ | |
2220 | 486 static inline void set_sr_golomb(PutBitContext *pb, int i, int k, int limit, int esc_len){ |
2215 | 487 int v; |
488 | |
489 v = -2*i-1; | |
490 v ^= (v>>31); | |
491 | |
492 set_ur_golomb(pb, v, k, limit, esc_len); | |
493 } | |
494 | |
495 /** | |
496 * write signed golomb rice code (flac). | |
497 */ | |
498 static inline void set_sr_golomb_flac(PutBitContext *pb, int i, int k, int limit, int esc_len){ | |
499 int v; | |
500 | |
501 v = -2*i-1; | |
502 v ^= (v>>31); | |
503 | |
504 set_ur_golomb_jpegls(pb, v, k, limit, esc_len); | |
505 } | |
5163 | 506 |
7760 | 507 #endif /* AVCODEC_GOLOMB_H */ |