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