Mercurial > libavcodec.hg
annotate golomb.h @ 1966:e1fc7c598558 libavcodec
License change and cpu detection patch by (James Morrison <ja2morri at csclub dot uwaterloo dot ca>)
author | michael |
---|---|
date | Sat, 24 Apr 2004 15:23:50 +0000 |
parents | 6d762acfff5d |
children | a4d3699c6636 |
rev | line source |
---|---|
1168 | 1 /* |
2 * exp golomb vlc stuff | |
3 * Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at> | |
4 * | |
5 * This library is free software; you can redistribute it and/or | |
6 * modify it under the terms of the GNU Lesser General Public | |
7 * License as published by the Free Software Foundation; either | |
8 * version 2 of the License, or (at your option) any later version. | |
9 * | |
10 * This library is distributed in the hope that it will be useful, | |
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 * Lesser General Public License for more details. | |
14 * | |
15 * You should have received a copy of the GNU Lesser General Public | |
16 * License along with this library; if not, write to the Free Software | |
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 * | |
19 */ | |
20 | |
21 /** | |
22 * @file golomb.h | |
23 * @brief | |
24 * exp golomb vlc stuff | |
25 * @author Michael Niedermayer <michaelni@gmx.at> | |
26 */ | |
27 | |
1234 | 28 #define INVALID_VLC 0x80000000 |
29 | |
1168 | 30 extern const uint8_t ff_golomb_vlc_len[512]; |
31 extern const uint8_t ff_ue_golomb_vlc_code[512]; | |
32 extern const int8_t ff_se_golomb_vlc_code[512]; | |
33 extern const uint8_t ff_ue_golomb_len[256]; | |
34 | |
1250 | 35 extern const uint8_t ff_interleaved_golomb_vlc_len[256]; |
36 extern const uint8_t ff_interleaved_ue_golomb_vlc_code[256]; | |
37 extern const int8_t ff_interleaved_se_golomb_vlc_code[256]; | |
38 | |
1168 | 39 |
40 /** | |
41 * read unsigned exp golomb code. | |
42 */ | |
43 static inline int get_ue_golomb(GetBitContext *gb){ | |
44 unsigned int buf; | |
45 int log; | |
46 | |
47 OPEN_READER(re, gb); | |
48 UPDATE_CACHE(re, gb); | |
49 buf=GET_CACHE(re, gb); | |
50 | |
51 if(buf >= (1<<27)){ | |
52 buf >>= 32 - 9; | |
53 LAST_SKIP_BITS(re, gb, ff_golomb_vlc_len[buf]); | |
54 CLOSE_READER(re, gb); | |
55 | |
56 return ff_ue_golomb_vlc_code[buf]; | |
57 }else{ | |
58 log= 2*av_log2(buf) - 31; | |
59 buf>>= log; | |
60 buf--; | |
61 LAST_SKIP_BITS(re, gb, 32 - log); | |
62 CLOSE_READER(re, gb); | |
63 | |
64 return buf; | |
65 } | |
66 } | |
67 | |
1234 | 68 static inline int svq3_get_ue_golomb(GetBitContext *gb){ |
1250 | 69 uint32_t buf; |
1234 | 70 int log; |
71 | |
72 OPEN_READER(re, gb); | |
73 UPDATE_CACHE(re, gb); | |
1250 | 74 buf=GET_CACHE(re, gb); |
75 | |
76 if(buf&0xAA800000){ | |
77 buf >>= 32 - 8; | |
78 LAST_SKIP_BITS(re, gb, ff_interleaved_golomb_vlc_len[buf]); | |
79 CLOSE_READER(re, gb); | |
80 | |
81 return ff_interleaved_ue_golomb_vlc_code[buf]; | |
82 }else{ | |
83 buf|=1; | |
84 if((buf & 0xAAAAAAAA) == 0) | |
85 return INVALID_VLC; | |
1234 | 86 |
1250 | 87 for(log=31; (buf & 0x80000000) == 0; log--){ |
88 buf = (buf << 2) - ((buf << log) >> (log - 1)) + (buf >> 30); | |
89 } | |
1234 | 90 |
1250 | 91 LAST_SKIP_BITS(re, gb, 63 - 2*log); |
92 CLOSE_READER(re, gb); | |
1234 | 93 |
1250 | 94 return ((buf << log) >> log) - 1; |
95 } | |
1234 | 96 } |
97 | |
1168 | 98 /** |
99 * read unsigned truncated exp golomb code. | |
100 */ | |
101 static inline int get_te0_golomb(GetBitContext *gb, int range){ | |
102 assert(range >= 1); | |
103 | |
104 if(range==1) return 0; | |
1169 | 105 else if(range==2) return get_bits1(gb)^1; |
1168 | 106 else return get_ue_golomb(gb); |
107 } | |
108 | |
109 /** | |
110 * read unsigned truncated exp golomb code. | |
111 */ | |
112 static inline int get_te_golomb(GetBitContext *gb, int range){ | |
113 assert(range >= 1); | |
114 | |
1169 | 115 if(range==2) return get_bits1(gb)^1; |
1168 | 116 else return get_ue_golomb(gb); |
117 } | |
118 | |
119 | |
120 /** | |
121 * read signed exp golomb code. | |
122 */ | |
123 static inline int get_se_golomb(GetBitContext *gb){ | |
124 unsigned int buf; | |
125 int log; | |
126 | |
127 OPEN_READER(re, gb); | |
128 UPDATE_CACHE(re, gb); | |
129 buf=GET_CACHE(re, gb); | |
130 | |
131 if(buf >= (1<<27)){ | |
132 buf >>= 32 - 9; | |
133 LAST_SKIP_BITS(re, gb, ff_golomb_vlc_len[buf]); | |
134 CLOSE_READER(re, gb); | |
135 | |
136 return ff_se_golomb_vlc_code[buf]; | |
137 }else{ | |
138 log= 2*av_log2(buf) - 31; | |
139 buf>>= log; | |
140 | |
141 LAST_SKIP_BITS(re, gb, 32 - log); | |
142 CLOSE_READER(re, gb); | |
143 | |
144 if(buf&1) buf= -(buf>>1); | |
145 else buf= (buf>>1); | |
146 | |
147 return buf; | |
148 } | |
149 } | |
150 | |
1234 | 151 static inline int svq3_get_se_golomb(GetBitContext *gb){ |
152 unsigned int buf; | |
153 int log; | |
154 | |
155 OPEN_READER(re, gb); | |
156 UPDATE_CACHE(re, gb); | |
1250 | 157 buf=GET_CACHE(re, gb); |
1234 | 158 |
1250 | 159 if(buf&0xAA800000){ |
160 buf >>= 32 - 8; | |
161 LAST_SKIP_BITS(re, gb, ff_interleaved_golomb_vlc_len[buf]); | |
162 CLOSE_READER(re, gb); | |
163 | |
164 return ff_interleaved_se_golomb_vlc_code[buf]; | |
165 }else{ | |
166 buf |=1; | |
167 if((buf & 0xAAAAAAAA) == 0) | |
168 return INVALID_VLC; | |
1234 | 169 |
1250 | 170 for(log=31; (buf & 0x80000000) == 0; log--){ |
171 buf = (buf << 2) - ((buf << log) >> (log - 1)) + (buf >> 30); | |
172 } | |
1234 | 173 |
1250 | 174 LAST_SKIP_BITS(re, gb, 63 - 2*log); |
175 CLOSE_READER(re, gb); | |
176 | |
177 return (signed) (((((buf << log) >> log) - 1) ^ -(buf & 0x1)) + 1) >> 1; | |
178 } | |
1234 | 179 } |
180 | |
1306 | 181 /** |
1361
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
182 * read unsigned golomb rice code (ffv1). |
1306 | 183 */ |
184 static inline int get_ur_golomb(GetBitContext *gb, int k, int limit, int esc_len){ | |
185 unsigned int buf; | |
186 int log; | |
187 | |
188 OPEN_READER(re, gb); | |
189 UPDATE_CACHE(re, gb); | |
190 buf=GET_CACHE(re, gb); | |
191 | |
192 log= av_log2(buf); | |
1361
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
193 |
1306 | 194 if(log > 31-limit){ |
195 buf >>= log - k; | |
196 buf += (30-log)<<k; | |
197 LAST_SKIP_BITS(re, gb, 32 + k - log); | |
198 CLOSE_READER(re, gb); | |
199 | |
200 return buf; | |
1361
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
201 }else{ |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
202 buf >>= 32 - limit - esc_len; |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
203 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
|
204 CLOSE_READER(re, gb); |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
205 |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
206 return buf + limit - 1; |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
207 } |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
208 } |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
209 |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
210 /** |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
211 * read unsigned golomb rice code (jpegls). |
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 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
|
214 unsigned int buf; |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
215 int log; |
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 OPEN_READER(re, gb); |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
218 UPDATE_CACHE(re, gb); |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
219 buf=GET_CACHE(re, gb); |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
220 |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
221 log= av_log2(buf); |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
222 |
1362 | 223 if(log > 31-11){ |
1361
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
224 buf >>= log - k; |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
225 buf += (30-log)<<k; |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
226 LAST_SKIP_BITS(re, gb, 32 + k - log); |
1306 | 227 CLOSE_READER(re, gb); |
228 | |
1361
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
229 return buf; |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
230 }else{ |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
231 int i; |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
232 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
|
233 LAST_SKIP_BITS(re, gb, 1); |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
234 UPDATE_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 SKIP_BITS(re, gb, 1); |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
237 |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
238 if(i < limit - 1){ |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
239 if(k){ |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
240 buf = SHOW_UBITS(re, gb, 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, k); |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
242 }else{ |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
243 buf=0; |
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 CLOSE_READER(re, gb); |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
247 return buf + (i<<k); |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
248 }else if(i == limit - 1){ |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
249 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
|
250 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
|
251 CLOSE_READER(re, gb); |
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 return buf + 1; |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
254 }else |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
255 return -1; |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
256 } |
1306 | 257 } |
258 | |
1812 | 259 /** |
260 * read unsigned golomb rice code (flac). | |
261 */ | |
262 static inline int get_sr_golomb_flac(GetBitContext *gb, int k, int limit, int esc_len){ | |
263 int v= get_ur_golomb_jpegls(gb, k, limit, esc_len); | |
264 return (v>>1) ^ -(v&1); | |
265 } | |
266 | |
1168 | 267 #ifdef TRACE |
268 | |
269 static inline int get_ue(GetBitContext *s, char *file, char *func, int line){ | |
270 int show= show_bits(s, 24); | |
271 int pos= get_bits_count(s); | |
272 int i= get_ue_golomb(s); | |
273 int len= get_bits_count(s) - pos; | |
274 int bits= show>>(24-len); | |
275 | |
276 print_bin(bits, len); | |
277 | |
278 printf("%5d %2d %3d ue @%5d in %s %s:%d\n", bits, len, i, pos, file, func, line); | |
279 | |
280 return i; | |
281 } | |
282 | |
283 static inline int get_se(GetBitContext *s, char *file, char *func, int line){ | |
284 int show= show_bits(s, 24); | |
285 int pos= get_bits_count(s); | |
286 int i= get_se_golomb(s); | |
287 int len= get_bits_count(s) - pos; | |
288 int bits= show>>(24-len); | |
289 | |
290 print_bin(bits, len); | |
291 | |
292 printf("%5d %2d %3d se @%5d in %s %s:%d\n", bits, len, i, pos, file, func, line); | |
293 | |
294 return i; | |
295 } | |
296 | |
297 static inline int get_te(GetBitContext *s, int r, char *file, char *func, int line){ | |
298 int show= show_bits(s, 24); | |
299 int pos= get_bits_count(s); | |
300 int i= get_te0_golomb(s, r); | |
301 int len= get_bits_count(s) - pos; | |
302 int bits= show>>(24-len); | |
303 | |
304 print_bin(bits, len); | |
305 | |
306 printf("%5d %2d %3d te @%5d in %s %s:%d\n", bits, len, i, pos, file, func, line); | |
307 | |
308 return i; | |
309 } | |
310 | |
311 #define get_ue_golomb(a) get_ue(a, __FILE__, __PRETTY_FUNCTION__, __LINE__) | |
312 #define get_se_golomb(a) get_se(a, __FILE__, __PRETTY_FUNCTION__, __LINE__) | |
313 #define get_te_golomb(a, r) get_te(a, r, __FILE__, __PRETTY_FUNCTION__, __LINE__) | |
314 #define get_te0_golomb(a, r) get_te(a, r, __FILE__, __PRETTY_FUNCTION__, __LINE__) | |
315 | |
316 #endif | |
317 | |
318 /** | |
319 * write unsigned exp golomb code. | |
320 */ | |
321 static inline void set_ue_golomb(PutBitContext *pb, int i){ | |
322 int e; | |
323 | |
324 assert(i>=0); | |
325 | |
326 #if 0 | |
327 if(i=0){ | |
328 put_bits(pb, 1, 1); | |
329 return; | |
330 } | |
331 #endif | |
332 if(i<256) | |
333 put_bits(pb, ff_ue_golomb_len[i], i+1); | |
334 else{ | |
335 e= av_log2(i+1); | |
336 | |
337 put_bits(pb, 2*e+1, i+1); | |
338 } | |
339 } | |
340 | |
341 /** | |
342 * write truncated unsigned exp golomb code. | |
343 */ | |
344 static inline void set_te_golomb(PutBitContext *pb, int i, int range){ | |
345 assert(range >= 1); | |
346 assert(i<=range); | |
347 | |
1169 | 348 if(range==2) put_bits(pb, 1, i^1); |
1168 | 349 else set_ue_golomb(pb, i); |
350 } | |
351 | |
352 /** | |
353 * write signed exp golomb code. | |
354 */ | |
355 static inline void set_se_golomb(PutBitContext *pb, int i){ | |
356 #if 0 | |
357 if(i<=0) i= -2*i; | |
358 else i= 2*i-1; | |
359 #elif 1 | |
360 i= 2*i-1; | |
361 if(i<0) i^= -1; //FIXME check if gcc does the right thing | |
362 #else | |
363 i= 2*i-1; | |
364 i^= (i>>31); | |
365 #endif | |
366 set_ue_golomb(pb, i); | |
367 } | |
1306 | 368 |
369 /** | |
1361
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
370 * write unsigned golomb rice code (ffv1). |
1306 | 371 */ |
372 static inline void set_ur_golomb(PutBitContext *pb, int i, int k, int limit, int esc_len){ | |
373 int e; | |
374 | |
375 assert(i>=0); | |
376 | |
377 e= i>>k; | |
378 if(e<limit){ | |
379 put_bits(pb, e + k + 1, (1<<k) + (i&((1<<k)-1))); | |
380 }else{ | |
1361
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
381 put_bits(pb, limit + esc_len, i - limit + 1); |
1306 | 382 } |
383 } | |
1361
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
384 |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
385 /** |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
386 * write unsigned golomb rice code (jpegls). |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
387 */ |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
388 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
|
389 int e; |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
390 |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
391 assert(i>=0); |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
392 |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
393 e= (i>>k) + 1; |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
394 if(e<limit){ |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
395 put_bits(pb, e, 1); |
1362 | 396 if(k) |
397 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
|
398 }else{ |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
399 put_bits(pb, limit , 1); |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
400 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
|
401 } |
8479b875a989
golomb rice code cleanup / simplify (~0.5% compression gain and slightly faster)
michaelni
parents:
1306
diff
changeset
|
402 } |