Mercurial > libavcodec.hg
annotate golomb.h @ 2710:b71d3566fc6d libavcodec
fix mpeg2 chroma_420_type
author | michael |
---|---|
date | Wed, 18 May 2005 19:42:42 +0000 |
parents | b47af698085e |
children | 926ea374947f |
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 * |
6 * This library is free software; you can redistribute it and/or | |
7 * modify it under the terms of the GNU Lesser General Public | |
8 * License as published by the Free Software Foundation; either | |
9 * version 2 of the License, or (at your option) any later version. | |
10 * | |
11 * This library is distributed in the hope that it will be useful, | |
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 * Lesser General Public License for more details. | |
15 * | |
16 * You should have received a copy of the GNU Lesser General Public | |
17 * License along with this library; if not, write to the Free Software | |
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
19 * | |
20 */ | |
21 | |
22 /** | |
23 * @file golomb.h | |
24 * @brief | |
25 * exp golomb vlc stuff | |
2215 | 26 * @author Michael Niedermayer <michaelni@gmx.at> and Alex Beregszaszi |
1168 | 27 */ |
28 | |
1234 | 29 #define INVALID_VLC 0x80000000 |
30 | |
1168 | 31 extern const uint8_t ff_golomb_vlc_len[512]; |
32 extern const uint8_t ff_ue_golomb_vlc_code[512]; | |
33 extern const int8_t ff_se_golomb_vlc_code[512]; | |
34 extern const uint8_t ff_ue_golomb_len[256]; | |
35 | |
1250 | 36 extern const uint8_t ff_interleaved_golomb_vlc_len[256]; |
37 extern const uint8_t ff_interleaved_ue_golomb_vlc_code[256]; | |
38 extern const int8_t ff_interleaved_se_golomb_vlc_code[256]; | |
39 | |
1168 | 40 |
41 /** | |
42 * read unsigned exp golomb code. | |
43 */ | |
44 static inline int get_ue_golomb(GetBitContext *gb){ | |
45 unsigned int buf; | |
46 int log; | |
47 | |
48 OPEN_READER(re, gb); | |
49 UPDATE_CACHE(re, gb); | |
50 buf=GET_CACHE(re, gb); | |
51 | |
52 if(buf >= (1<<27)){ | |
53 buf >>= 32 - 9; | |
54 LAST_SKIP_BITS(re, gb, ff_golomb_vlc_len[buf]); | |
55 CLOSE_READER(re, gb); | |
56 | |
57 return ff_ue_golomb_vlc_code[buf]; | |
58 }else{ | |
59 log= 2*av_log2(buf) - 31; | |
60 buf>>= log; | |
61 buf--; | |
62 LAST_SKIP_BITS(re, gb, 32 - log); | |
63 CLOSE_READER(re, gb); | |
64 | |
65 return buf; | |
66 } | |
67 } | |
68 | |
1234 | 69 static inline int svq3_get_ue_golomb(GetBitContext *gb){ |
1250 | 70 uint32_t buf; |
1234 | 71 int log; |
72 | |
73 OPEN_READER(re, gb); | |
74 UPDATE_CACHE(re, gb); | |
1250 | 75 buf=GET_CACHE(re, gb); |
76 | |
77 if(buf&0xAA800000){ | |
78 buf >>= 32 - 8; | |
79 LAST_SKIP_BITS(re, gb, ff_interleaved_golomb_vlc_len[buf]); | |
80 CLOSE_READER(re, gb); | |
81 | |
82 return ff_interleaved_ue_golomb_vlc_code[buf]; | |
83 }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
|
84 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
|
85 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
|
86 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
|
87 |
1250 | 88 if((buf & 0xAAAAAAAA) == 0) |
89 return INVALID_VLC; | |
1234 | 90 |
1250 | 91 for(log=31; (buf & 0x80000000) == 0; log--){ |
92 buf = (buf << 2) - ((buf << log) >> (log - 1)) + (buf >> 30); | |
93 } | |
1234 | 94 |
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
|
95 LAST_SKIP_BITS(re, gb, 63 - 2*log - 8); |
1250 | 96 CLOSE_READER(re, gb); |
1234 | 97 |
1250 | 98 return ((buf << log) >> log) - 1; |
99 } | |
1234 | 100 } |
101 | |
1168 | 102 /** |
103 * read unsigned truncated exp golomb code. | |
104 */ | |
105 static inline int get_te0_golomb(GetBitContext *gb, int range){ | |
106 assert(range >= 1); | |
107 | |
108 if(range==1) return 0; | |
1169 | 109 else if(range==2) return get_bits1(gb)^1; |
1168 | 110 else return get_ue_golomb(gb); |
111 } | |
112 | |
113 /** | |
114 * read unsigned truncated exp golomb code. | |
115 */ | |
116 static inline int get_te_golomb(GetBitContext *gb, int range){ | |
117 assert(range >= 1); | |
118 | |
1169 | 119 if(range==2) return get_bits1(gb)^1; |
1168 | 120 else return get_ue_golomb(gb); |
121 } | |
122 | |
123 | |
124 /** | |
125 * read signed exp golomb code. | |
126 */ | |
127 static inline int get_se_golomb(GetBitContext *gb){ | |
128 unsigned int buf; | |
129 int log; | |
130 | |
131 OPEN_READER(re, gb); | |
132 UPDATE_CACHE(re, gb); | |
133 buf=GET_CACHE(re, gb); | |
134 | |
135 if(buf >= (1<<27)){ | |
136 buf >>= 32 - 9; | |
137 LAST_SKIP_BITS(re, gb, ff_golomb_vlc_len[buf]); | |
138 CLOSE_READER(re, gb); | |
139 | |
140 return ff_se_golomb_vlc_code[buf]; | |
141 }else{ | |
142 log= 2*av_log2(buf) - 31; | |
143 buf>>= log; | |
144 | |
145 LAST_SKIP_BITS(re, gb, 32 - log); | |
146 CLOSE_READER(re, gb); | |
147 | |
148 if(buf&1) buf= -(buf>>1); | |
149 else buf= (buf>>1); | |
150 | |
151 return buf; | |
152 } | |
153 } | |
154 | |
1234 | 155 static inline int svq3_get_se_golomb(GetBitContext *gb){ |
156 unsigned int buf; | |
157 int log; | |
158 | |
159 OPEN_READER(re, gb); | |
160 UPDATE_CACHE(re, gb); | |
1250 | 161 buf=GET_CACHE(re, gb); |
1234 | 162 |
1250 | 163 if(buf&0xAA800000){ |
164 buf >>= 32 - 8; | |
165 LAST_SKIP_BITS(re, gb, ff_interleaved_golomb_vlc_len[buf]); | |
166 CLOSE_READER(re, gb); | |
167 | |
168 return ff_interleaved_se_golomb_vlc_code[buf]; | |
169 }else{ | |
2439 | 170 LAST_SKIP_BITS(re, gb, 8); |
171 UPDATE_CACHE(re, gb); | |
172 buf |= 1 | (GET_CACHE(re, gb) >> 8); | |
173 | |
1250 | 174 if((buf & 0xAAAAAAAA) == 0) |
175 return INVALID_VLC; | |
1234 | 176 |
1250 | 177 for(log=31; (buf & 0x80000000) == 0; log--){ |
178 buf = (buf << 2) - ((buf << log) >> (log - 1)) + (buf >> 30); | |
179 } | |
1234 | 180 |
2439 | 181 LAST_SKIP_BITS(re, gb, 63 - 2*log - 8); |
1250 | 182 CLOSE_READER(re, gb); |
183 | |
184 return (signed) (((((buf << log) >> log) - 1) ^ -(buf & 0x1)) + 1) >> 1; | |
185 } | |
1234 | 186 } |
187 | |
1306 | 188 /** |
1361
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
189 * read unsigned golomb rice code (ffv1). |
1306 | 190 */ |
191 static inline int get_ur_golomb(GetBitContext *gb, int k, int limit, int esc_len){ | |
192 unsigned int buf; | |
193 int log; | |
194 | |
195 OPEN_READER(re, gb); | |
196 UPDATE_CACHE(re, gb); | |
197 buf=GET_CACHE(re, gb); | |
198 | |
199 log= av_log2(buf); | |
1361
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
200 |
1306 | 201 if(log > 31-limit){ |
202 buf >>= log - k; | |
203 buf += (30-log)<<k; | |
204 LAST_SKIP_BITS(re, gb, 32 + k - log); | |
205 CLOSE_READER(re, gb); | |
206 | |
207 return buf; | |
1361
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
208 }else{ |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
209 buf >>= 32 - limit - esc_len; |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
210 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
|
211 CLOSE_READER(re, gb); |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
212 |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
213 return buf + limit - 1; |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
214 } |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
215 } |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
216 |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
217 /** |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
218 * read unsigned golomb rice code (jpegls). |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
219 */ |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
220 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
|
221 unsigned int buf; |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
222 int log; |
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 OPEN_READER(re, gb); |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
225 UPDATE_CACHE(re, gb); |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
226 buf=GET_CACHE(re, gb); |
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 log= av_log2(buf); |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
229 |
1362 | 230 if(log > 31-11){ |
1361
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
231 buf >>= log - k; |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
232 buf += (30-log)<<k; |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
233 LAST_SKIP_BITS(re, gb, 32 + k - log); |
1306 | 234 CLOSE_READER(re, gb); |
235 | |
1361
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
236 return buf; |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
237 }else{ |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
238 int i; |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
239 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
|
240 LAST_SKIP_BITS(re, gb, 1); |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
241 UPDATE_CACHE(re, gb); |
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 SKIP_BITS(re, gb, 1); |
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 if(i < limit - 1){ |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
246 if(k){ |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
247 buf = SHOW_UBITS(re, gb, k); |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
248 LAST_SKIP_BITS(re, gb, k); |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
249 }else{ |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
250 buf=0; |
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 |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
253 CLOSE_READER(re, gb); |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
254 return buf + (i<<k); |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
255 }else if(i == limit - 1){ |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
256 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
|
257 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
|
258 CLOSE_READER(re, gb); |
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 return buf + 1; |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
261 }else |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
262 return -1; |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
263 } |
1306 | 264 } |
265 | |
1812 | 266 /** |
2215 | 267 * read signed golomb rice code (ffv1). |
268 */ | |
2220 | 269 static inline int get_sr_golomb(GetBitContext *gb, int k, int limit, int esc_len){ |
2215 | 270 int v= get_ur_golomb(gb, k, limit, esc_len); |
271 | |
272 v++; | |
273 if (v&1) return v>>1; | |
274 else return -(v>>1); | |
275 | |
276 // return (v>>1) ^ -(v&1); | |
277 } | |
2220 | 278 |
2215 | 279 /** |
280 * read signed golomb rice code (flac). | |
1812 | 281 */ |
282 static inline int get_sr_golomb_flac(GetBitContext *gb, int k, int limit, int esc_len){ | |
283 int v= get_ur_golomb_jpegls(gb, k, limit, esc_len); | |
284 return (v>>1) ^ -(v&1); | |
285 } | |
286 | |
2525
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
2439
diff
changeset
|
287 /** |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
2439
diff
changeset
|
288 * read unsigned golomb rice code (shorten). |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
2439
diff
changeset
|
289 */ |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
2439
diff
changeset
|
290 static inline unsigned int get_ur_golomb_shorten(GetBitContext *gb, int k){ |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
2439
diff
changeset
|
291 return get_ur_golomb_jpegls(gb, k, INT_MAX, 0); |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
2439
diff
changeset
|
292 } |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
2439
diff
changeset
|
293 |
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 signed 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 int get_sr_golomb_shorten(GetBitContext* gb, int k) |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
2439
diff
changeset
|
298 { |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
2439
diff
changeset
|
299 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
|
300 if (uvar & 1) |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
2439
diff
changeset
|
301 return ~(uvar >> 1); |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
2439
diff
changeset
|
302 else |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
2439
diff
changeset
|
303 return uvar >> 1; |
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 |
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 |
1168 | 308 #ifdef TRACE |
309 | |
2438
e98b5e0de86b
compile with TRACE define patch by (Loic <lll+ffmpeg m4x org>)
michael
parents:
2220
diff
changeset
|
310 static inline int get_ue(GetBitContext *s, char *file, const char *func, int line){ |
1168 | 311 int show= show_bits(s, 24); |
312 int pos= get_bits_count(s); | |
313 int i= get_ue_golomb(s); | |
314 int len= get_bits_count(s) - pos; | |
315 int bits= show>>(24-len); | |
316 | |
317 print_bin(bits, len); | |
318 | |
2215 | 319 av_log(NULL, AV_LOG_DEBUG, "%5d %2d %3d ue @%5d in %s %s:%d\n", bits, len, i, pos, file, func, line); |
1168 | 320 |
321 return i; | |
322 } | |
323 | |
2438
e98b5e0de86b
compile with TRACE define patch by (Loic <lll+ffmpeg m4x org>)
michael
parents:
2220
diff
changeset
|
324 static inline int get_se(GetBitContext *s, char *file, const char *func, int line){ |
1168 | 325 int show= show_bits(s, 24); |
326 int pos= get_bits_count(s); | |
327 int i= get_se_golomb(s); | |
328 int len= get_bits_count(s) - pos; | |
329 int bits= show>>(24-len); | |
330 | |
331 print_bin(bits, len); | |
332 | |
2215 | 333 av_log(NULL, AV_LOG_DEBUG, "%5d %2d %3d se @%5d in %s %s:%d\n", bits, len, i, pos, file, func, line); |
1168 | 334 |
335 return i; | |
336 } | |
337 | |
2438
e98b5e0de86b
compile with TRACE define patch by (Loic <lll+ffmpeg m4x org>)
michael
parents:
2220
diff
changeset
|
338 static inline int get_te(GetBitContext *s, int r, 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_te0_golomb(s, r); | |
342 int len= get_bits_count(s) - pos; | |
343 int bits= show>>(24-len); | |
344 | |
345 print_bin(bits, len); | |
346 | |
2215 | 347 av_log(NULL, AV_LOG_DEBUG, "%5d %2d %3d te @%5d in %s %s:%d\n", bits, len, i, pos, file, func, line); |
1168 | 348 |
349 return i; | |
350 } | |
351 | |
352 #define get_ue_golomb(a) get_ue(a, __FILE__, __PRETTY_FUNCTION__, __LINE__) | |
353 #define get_se_golomb(a) get_se(a, __FILE__, __PRETTY_FUNCTION__, __LINE__) | |
354 #define get_te_golomb(a, r) get_te(a, r, __FILE__, __PRETTY_FUNCTION__, __LINE__) | |
355 #define get_te0_golomb(a, r) get_te(a, r, __FILE__, __PRETTY_FUNCTION__, __LINE__) | |
356 | |
357 #endif | |
358 | |
359 /** | |
360 * write unsigned exp golomb code. | |
361 */ | |
362 static inline void set_ue_golomb(PutBitContext *pb, int i){ | |
363 int e; | |
364 | |
365 assert(i>=0); | |
366 | |
367 #if 0 | |
368 if(i=0){ | |
369 put_bits(pb, 1, 1); | |
370 return; | |
371 } | |
372 #endif | |
373 if(i<256) | |
374 put_bits(pb, ff_ue_golomb_len[i], i+1); | |
375 else{ | |
376 e= av_log2(i+1); | |
377 | |
378 put_bits(pb, 2*e+1, i+1); | |
379 } | |
380 } | |
381 | |
382 /** | |
383 * write truncated unsigned exp golomb code. | |
384 */ | |
385 static inline void set_te_golomb(PutBitContext *pb, int i, int range){ | |
386 assert(range >= 1); | |
387 assert(i<=range); | |
388 | |
1169 | 389 if(range==2) put_bits(pb, 1, i^1); |
1168 | 390 else set_ue_golomb(pb, i); |
391 } | |
392 | |
393 /** | |
394 * write signed exp golomb code. | |
395 */ | |
396 static inline void set_se_golomb(PutBitContext *pb, int i){ | |
397 #if 0 | |
398 if(i<=0) i= -2*i; | |
399 else i= 2*i-1; | |
400 #elif 1 | |
401 i= 2*i-1; | |
402 if(i<0) i^= -1; //FIXME check if gcc does the right thing | |
403 #else | |
404 i= 2*i-1; | |
405 i^= (i>>31); | |
406 #endif | |
407 set_ue_golomb(pb, i); | |
408 } | |
1306 | 409 |
410 /** | |
1361
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
411 * write unsigned golomb rice code (ffv1). |
1306 | 412 */ |
413 static inline void set_ur_golomb(PutBitContext *pb, int i, int k, int limit, int esc_len){ | |
414 int e; | |
415 | |
416 assert(i>=0); | |
417 | |
418 e= i>>k; | |
419 if(e<limit){ | |
420 put_bits(pb, e + k + 1, (1<<k) + (i&((1<<k)-1))); | |
421 }else{ | |
1361
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
422 put_bits(pb, limit + esc_len, i - limit + 1); |
1306 | 423 } |
424 } | |
1361
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
425 |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
426 /** |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
427 * write unsigned golomb rice code (jpegls). |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
428 */ |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
429 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
|
430 int e; |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
431 |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
432 assert(i>=0); |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
433 |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
434 e= (i>>k) + 1; |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
435 if(e<limit){ |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
436 put_bits(pb, e, 1); |
1362 | 437 if(k) |
438 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
|
439 }else{ |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
440 put_bits(pb, limit , 1); |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
441 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
|
442 } |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
443 } |
2215 | 444 |
445 /** | |
446 * write signed golomb rice code (ffv1). | |
447 */ | |
2220 | 448 static inline void set_sr_golomb(PutBitContext *pb, int i, int k, int limit, int esc_len){ |
2215 | 449 int v; |
450 | |
451 v = -2*i-1; | |
452 v ^= (v>>31); | |
453 | |
454 set_ur_golomb(pb, v, k, limit, esc_len); | |
455 } | |
456 | |
457 /** | |
458 * write signed golomb rice code (flac). | |
459 */ | |
460 static inline void set_sr_golomb_flac(PutBitContext *pb, int i, int k, int limit, int esc_len){ | |
461 int v; | |
462 | |
463 v = -2*i-1; | |
464 v ^= (v>>31); | |
465 | |
466 set_ur_golomb_jpegls(pb, v, k, limit, esc_len); | |
467 } |