Mercurial > libavcodec.hg
annotate golomb.h @ 5169:3fd46e281bd8 libavcodec
add a comment to indicate which #endif belong to which #define
author | gpoirier |
---|---|
date | Sun, 17 Jun 2007 18:59:28 +0000 |
parents | 9ecbfc0c82bf |
children | 2b72f9bc4f06 |
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 * |
22 */ | |
2967 | 23 |
1168 | 24 /** |
25 * @file golomb.h | |
2967 | 26 * @brief |
1168 | 27 * exp golomb vlc stuff |
2215 | 28 * @author Michael Niedermayer <michaelni@gmx.at> and Alex Beregszaszi |
1168 | 29 */ |
30 | |
5163 | 31 #ifndef AVCODEC_GOLOMB_H |
32 #define AVCODEC_GOLOMB_H | |
33 | |
5162 | 34 #include <stdint.h> |
35 #include "bitstream.h" | |
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]; | |
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 int log; |
80 | |
81 OPEN_READER(re, gb); | |
82 UPDATE_CACHE(re, gb); | |
1250 | 83 buf=GET_CACHE(re, gb); |
2967 | 84 |
1250 | 85 if(buf&0xAA800000){ |
86 buf >>= 32 - 8; | |
87 LAST_SKIP_BITS(re, gb, ff_interleaved_golomb_vlc_len[buf]); | |
88 CLOSE_READER(re, gb); | |
2967 | 89 |
1250 | 90 return ff_interleaved_ue_golomb_vlc_code[buf]; |
91 }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
|
92 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
|
93 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
|
94 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
|
95 |
1250 | 96 if((buf & 0xAAAAAAAA) == 0) |
97 return INVALID_VLC; | |
1234 | 98 |
1250 | 99 for(log=31; (buf & 0x80000000) == 0; log--){ |
100 buf = (buf << 2) - ((buf << log) >> (log - 1)) + (buf >> 30); | |
101 } | |
1234 | 102 |
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
|
103 LAST_SKIP_BITS(re, gb, 63 - 2*log - 8); |
1250 | 104 CLOSE_READER(re, gb); |
1234 | 105 |
1250 | 106 return ((buf << log) >> log) - 1; |
107 } | |
1234 | 108 } |
109 | |
1168 | 110 /** |
111 * read unsigned truncated exp golomb code. | |
112 */ | |
113 static inline int get_te0_golomb(GetBitContext *gb, int range){ | |
114 assert(range >= 1); | |
2967 | 115 |
1168 | 116 if(range==1) return 0; |
1169 | 117 else if(range==2) return get_bits1(gb)^1; |
1168 | 118 else return get_ue_golomb(gb); |
119 } | |
120 | |
121 /** | |
122 * read unsigned truncated exp golomb code. | |
123 */ | |
124 static inline int get_te_golomb(GetBitContext *gb, int range){ | |
125 assert(range >= 1); | |
2967 | 126 |
1169 | 127 if(range==2) return get_bits1(gb)^1; |
1168 | 128 else return get_ue_golomb(gb); |
129 } | |
130 | |
131 | |
132 /** | |
133 * read signed exp golomb code. | |
134 */ | |
135 static inline int get_se_golomb(GetBitContext *gb){ | |
136 unsigned int buf; | |
137 int log; | |
2967 | 138 |
1168 | 139 OPEN_READER(re, gb); |
140 UPDATE_CACHE(re, gb); | |
141 buf=GET_CACHE(re, gb); | |
2967 | 142 |
1168 | 143 if(buf >= (1<<27)){ |
144 buf >>= 32 - 9; | |
145 LAST_SKIP_BITS(re, gb, ff_golomb_vlc_len[buf]); | |
146 CLOSE_READER(re, gb); | |
2967 | 147 |
1168 | 148 return ff_se_golomb_vlc_code[buf]; |
149 }else{ | |
150 log= 2*av_log2(buf) - 31; | |
151 buf>>= log; | |
2967 | 152 |
1168 | 153 LAST_SKIP_BITS(re, gb, 32 - log); |
154 CLOSE_READER(re, gb); | |
2967 | 155 |
1168 | 156 if(buf&1) buf= -(buf>>1); |
157 else buf= (buf>>1); | |
158 | |
159 return buf; | |
160 } | |
161 } | |
162 | |
1234 | 163 static inline int svq3_get_se_golomb(GetBitContext *gb){ |
164 unsigned int buf; | |
165 int log; | |
166 | |
167 OPEN_READER(re, gb); | |
168 UPDATE_CACHE(re, gb); | |
1250 | 169 buf=GET_CACHE(re, gb); |
1234 | 170 |
1250 | 171 if(buf&0xAA800000){ |
172 buf >>= 32 - 8; | |
173 LAST_SKIP_BITS(re, gb, ff_interleaved_golomb_vlc_len[buf]); | |
174 CLOSE_READER(re, gb); | |
2967 | 175 |
1250 | 176 return ff_interleaved_se_golomb_vlc_code[buf]; |
177 }else{ | |
2439 | 178 LAST_SKIP_BITS(re, gb, 8); |
179 UPDATE_CACHE(re, gb); | |
180 buf |= 1 | (GET_CACHE(re, gb) >> 8); | |
181 | |
1250 | 182 if((buf & 0xAAAAAAAA) == 0) |
183 return INVALID_VLC; | |
1234 | 184 |
1250 | 185 for(log=31; (buf & 0x80000000) == 0; log--){ |
186 buf = (buf << 2) - ((buf << log) >> (log - 1)) + (buf >> 30); | |
187 } | |
1234 | 188 |
2439 | 189 LAST_SKIP_BITS(re, gb, 63 - 2*log - 8); |
1250 | 190 CLOSE_READER(re, gb); |
191 | |
192 return (signed) (((((buf << log) >> log) - 1) ^ -(buf & 0x1)) + 1) >> 1; | |
193 } | |
1234 | 194 } |
195 | |
1306 | 196 /** |
1361
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
197 * read unsigned golomb rice code (ffv1). |
1306 | 198 */ |
199 static inline int get_ur_golomb(GetBitContext *gb, int k, int limit, int esc_len){ | |
200 unsigned int buf; | |
201 int log; | |
2967 | 202 |
1306 | 203 OPEN_READER(re, gb); |
204 UPDATE_CACHE(re, gb); | |
205 buf=GET_CACHE(re, gb); | |
206 | |
207 log= av_log2(buf); | |
1361
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
208 |
1306 | 209 if(log > 31-limit){ |
210 buf >>= log - k; | |
211 buf += (30-log)<<k; | |
212 LAST_SKIP_BITS(re, gb, 32 + k - log); | |
213 CLOSE_READER(re, gb); | |
2967 | 214 |
1306 | 215 return buf; |
1361
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
216 }else{ |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
217 buf >>= 32 - limit - esc_len; |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
218 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
|
219 CLOSE_READER(re, gb); |
2967 | 220 |
1361
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
221 return buf + limit - 1; |
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 /** |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
226 * read unsigned golomb rice code (jpegls). |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
227 */ |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
228 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
|
229 unsigned int buf; |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
230 int log; |
2967 | 231 |
1361
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
232 OPEN_READER(re, gb); |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
233 UPDATE_CACHE(re, gb); |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
234 buf=GET_CACHE(re, gb); |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
235 |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
236 log= av_log2(buf); |
2967 | 237 |
1362 | 238 if(log > 31-11){ |
1361
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
239 buf >>= log - k; |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
240 buf += (30-log)<<k; |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
241 LAST_SKIP_BITS(re, gb, 32 + k - log); |
1306 | 242 CLOSE_READER(re, gb); |
2967 | 243 |
1361
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
244 return buf; |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
245 }else{ |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
246 int i; |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
247 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
|
248 LAST_SKIP_BITS(re, gb, 1); |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
249 UPDATE_CACHE(re, gb); |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
250 } |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
251 SKIP_BITS(re, gb, 1); |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
252 |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
253 if(i < limit - 1){ |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
254 if(k){ |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
255 buf = SHOW_UBITS(re, gb, k); |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
256 LAST_SKIP_BITS(re, gb, k); |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
257 }else{ |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
258 buf=0; |
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 |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
261 CLOSE_READER(re, gb); |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
262 return buf + (i<<k); |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
263 }else if(i == limit - 1){ |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
264 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
|
265 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
|
266 CLOSE_READER(re, gb); |
2967 | 267 |
1361
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
268 return buf + 1; |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
269 }else |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
270 return -1; |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
271 } |
1306 | 272 } |
273 | |
1812 | 274 /** |
2215 | 275 * read signed golomb rice code (ffv1). |
276 */ | |
2220 | 277 static inline int get_sr_golomb(GetBitContext *gb, int k, int limit, int esc_len){ |
2215 | 278 int v= get_ur_golomb(gb, k, limit, esc_len); |
2967 | 279 |
2215 | 280 v++; |
281 if (v&1) return v>>1; | |
282 else return -(v>>1); | |
2967 | 283 |
2215 | 284 // return (v>>1) ^ -(v&1); |
285 } | |
2220 | 286 |
2215 | 287 /** |
288 * read signed golomb rice code (flac). | |
1812 | 289 */ |
290 static inline int get_sr_golomb_flac(GetBitContext *gb, int k, int limit, int esc_len){ | |
291 int v= get_ur_golomb_jpegls(gb, k, limit, esc_len); | |
292 return (v>>1) ^ -(v&1); | |
293 } | |
294 | |
2525
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
2439
diff
changeset
|
295 /** |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
2439
diff
changeset
|
296 * read unsigned golomb rice code (shorten). |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
2439
diff
changeset
|
297 */ |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
2439
diff
changeset
|
298 static inline unsigned int get_ur_golomb_shorten(GetBitContext *gb, int k){ |
2979 | 299 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
|
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 /** |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
2439
diff
changeset
|
303 * read signed golomb rice code (shorten). |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
2439
diff
changeset
|
304 */ |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
2439
diff
changeset
|
305 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
|
306 { |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
2439
diff
changeset
|
307 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
|
308 if (uvar & 1) |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
2439
diff
changeset
|
309 return ~(uvar >> 1); |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
2439
diff
changeset
|
310 else |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
2439
diff
changeset
|
311 return uvar >> 1; |
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 |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
2439
diff
changeset
|
315 |
1168 | 316 #ifdef TRACE |
317 | |
2438
e98b5e0de86b
compile with TRACE define patch by (Loic <lll+ffmpeg m4x org>)
michael
parents:
2220
diff
changeset
|
318 static inline int get_ue(GetBitContext *s, char *file, const char *func, int line){ |
1168 | 319 int show= show_bits(s, 24); |
320 int pos= get_bits_count(s); | |
321 int i= get_ue_golomb(s); | |
322 int len= get_bits_count(s) - pos; | |
323 int bits= show>>(24-len); | |
2967 | 324 |
1168 | 325 print_bin(bits, len); |
2967 | 326 |
2215 | 327 av_log(NULL, AV_LOG_DEBUG, "%5d %2d %3d ue @%5d in %s %s:%d\n", bits, len, i, pos, file, func, line); |
2967 | 328 |
1168 | 329 return i; |
330 } | |
331 | |
2438
e98b5e0de86b
compile with TRACE define patch by (Loic <lll+ffmpeg m4x org>)
michael
parents:
2220
diff
changeset
|
332 static inline int get_se(GetBitContext *s, char *file, const char *func, int line){ |
1168 | 333 int show= show_bits(s, 24); |
334 int pos= get_bits_count(s); | |
335 int i= get_se_golomb(s); | |
336 int len= get_bits_count(s) - pos; | |
337 int bits= show>>(24-len); | |
2967 | 338 |
1168 | 339 print_bin(bits, len); |
2967 | 340 |
2215 | 341 av_log(NULL, AV_LOG_DEBUG, "%5d %2d %3d se @%5d in %s %s:%d\n", bits, len, i, pos, file, func, line); |
2967 | 342 |
1168 | 343 return i; |
344 } | |
345 | |
2438
e98b5e0de86b
compile with TRACE define patch by (Loic <lll+ffmpeg m4x org>)
michael
parents:
2220
diff
changeset
|
346 static inline int get_te(GetBitContext *s, int r, char *file, const char *func, int line){ |
1168 | 347 int show= show_bits(s, 24); |
348 int pos= get_bits_count(s); | |
349 int i= get_te0_golomb(s, r); | |
350 int len= get_bits_count(s) - pos; | |
351 int bits= show>>(24-len); | |
2967 | 352 |
1168 | 353 print_bin(bits, len); |
2967 | 354 |
2215 | 355 av_log(NULL, AV_LOG_DEBUG, "%5d %2d %3d te @%5d in %s %s:%d\n", bits, len, i, pos, file, func, line); |
2967 | 356 |
1168 | 357 return i; |
358 } | |
359 | |
360 #define get_ue_golomb(a) get_ue(a, __FILE__, __PRETTY_FUNCTION__, __LINE__) | |
361 #define get_se_golomb(a) get_se(a, __FILE__, __PRETTY_FUNCTION__, __LINE__) | |
362 #define get_te_golomb(a, r) get_te(a, r, __FILE__, __PRETTY_FUNCTION__, __LINE__) | |
363 #define get_te0_golomb(a, r) get_te(a, r, __FILE__, __PRETTY_FUNCTION__, __LINE__) | |
364 | |
365 #endif | |
366 | |
367 /** | |
368 * write unsigned exp golomb code. | |
369 */ | |
370 static inline void set_ue_golomb(PutBitContext *pb, int i){ | |
371 int e; | |
2967 | 372 |
1168 | 373 assert(i>=0); |
374 | |
375 #if 0 | |
376 if(i=0){ | |
377 put_bits(pb, 1, 1); | |
378 return; | |
379 } | |
380 #endif | |
381 if(i<256) | |
382 put_bits(pb, ff_ue_golomb_len[i], i+1); | |
383 else{ | |
384 e= av_log2(i+1); | |
2967 | 385 |
1168 | 386 put_bits(pb, 2*e+1, i+1); |
387 } | |
388 } | |
389 | |
390 /** | |
391 * write truncated unsigned exp golomb code. | |
392 */ | |
393 static inline void set_te_golomb(PutBitContext *pb, int i, int range){ | |
394 assert(range >= 1); | |
395 assert(i<=range); | |
396 | |
1169 | 397 if(range==2) put_bits(pb, 1, i^1); |
1168 | 398 else set_ue_golomb(pb, i); |
399 } | |
400 | |
401 /** | |
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
|
402 * write signed exp golomb code. 16 bits at most. |
1168 | 403 */ |
404 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
|
405 // if (i>32767 || i<-32767) |
2979 | 406 // av_log(NULL,AV_LOG_ERROR,"value out of range %d\n", i); |
2967 | 407 #if 0 |
1168 | 408 if(i<=0) i= -2*i; |
409 else i= 2*i-1; | |
410 #elif 1 | |
411 i= 2*i-1; | |
412 if(i<0) i^= -1; //FIXME check if gcc does the right thing | |
413 #else | |
414 i= 2*i-1; | |
415 i^= (i>>31); | |
416 #endif | |
417 set_ue_golomb(pb, i); | |
418 } | |
1306 | 419 |
420 /** | |
1361
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
421 * write unsigned golomb rice code (ffv1). |
1306 | 422 */ |
423 static inline void set_ur_golomb(PutBitContext *pb, int i, int k, int limit, int esc_len){ | |
424 int e; | |
2967 | 425 |
1306 | 426 assert(i>=0); |
2967 | 427 |
1306 | 428 e= i>>k; |
429 if(e<limit){ | |
430 put_bits(pb, e + k + 1, (1<<k) + (i&((1<<k)-1))); | |
431 }else{ | |
1361
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
432 put_bits(pb, limit + esc_len, i - limit + 1); |
1306 | 433 } |
434 } | |
1361
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 /** |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
437 * write unsigned golomb rice code (jpegls). |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
438 */ |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
439 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
|
440 int e; |
2967 | 441 |
1361
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
442 assert(i>=0); |
2967 | 443 |
1361
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
444 e= (i>>k) + 1; |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
445 if(e<limit){ |
3353
5b901881d6ed
first rudimentary version of (Justin Ruggles jruggle earthlink net) flac encoder
michael
parents:
3036
diff
changeset
|
446 while(e > 31) { |
5b901881d6ed
first rudimentary version of (Justin Ruggles jruggle earthlink net) flac encoder
michael
parents:
3036
diff
changeset
|
447 put_bits(pb, 31, 0); |
5b901881d6ed
first rudimentary version of (Justin Ruggles jruggle earthlink net) flac encoder
michael
parents:
3036
diff
changeset
|
448 e -= 31; |
5b901881d6ed
first rudimentary version of (Justin Ruggles jruggle earthlink net) flac encoder
michael
parents:
3036
diff
changeset
|
449 } |
1361
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
450 put_bits(pb, e, 1); |
1362 | 451 if(k) |
452 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
|
453 }else{ |
4053 | 454 while(limit > 31) { |
455 put_bits(pb, 31, 0); | |
456 limit -= 31; | |
457 } | |
1361
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
458 put_bits(pb, limit , 1); |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
459 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
|
460 } |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
461 } |
2215 | 462 |
463 /** | |
464 * write signed golomb rice code (ffv1). | |
465 */ | |
2220 | 466 static inline void set_sr_golomb(PutBitContext *pb, int i, int k, int limit, int esc_len){ |
2215 | 467 int v; |
468 | |
469 v = -2*i-1; | |
470 v ^= (v>>31); | |
471 | |
472 set_ur_golomb(pb, v, k, limit, esc_len); | |
473 } | |
474 | |
475 /** | |
476 * write signed golomb rice code (flac). | |
477 */ | |
478 static inline void set_sr_golomb_flac(PutBitContext *pb, int i, int k, int limit, int esc_len){ | |
479 int v; | |
480 | |
481 v = -2*i-1; | |
482 v ^= (v>>31); | |
483 | |
484 set_ur_golomb_jpegls(pb, v, k, limit, esc_len); | |
485 } | |
5163 | 486 |
5169
3fd46e281bd8
add a comment to indicate which #endif belong to which #define
gpoirier
parents:
5163
diff
changeset
|
487 #endif // AVCODEC_GOLOMB_H |