Mercurial > libavcodec.hg
comparison golomb.h @ 1306:799839d1e2e1 libavcodec
golomb rice codes
use gradients instead of prediction errors as context model
store independant quantization tables for each point
merge contexts with opposit sign
author | michaelni |
---|---|
date | Fri, 13 Jun 2003 21:31:28 +0000 |
parents | fa181d095027 |
children | 8479b875a989 |
comparison
equal
deleted
inserted
replaced
1305:abca3b39231d | 1306:799839d1e2e1 |
---|---|
176 | 176 |
177 return (signed) (((((buf << log) >> log) - 1) ^ -(buf & 0x1)) + 1) >> 1; | 177 return (signed) (((((buf << log) >> log) - 1) ^ -(buf & 0x1)) + 1) >> 1; |
178 } | 178 } |
179 } | 179 } |
180 | 180 |
181 /** | |
182 * read unsigned golomb rice code. | |
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); | |
193 //printf("buf:%X log:%d\n", buf, log); | |
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; | |
201 }else if(log == 31-limit){ | |
202 buf >>= log - esc_len; | |
203 buf -= 1<<esc_len; | |
204 LAST_SKIP_BITS(re, gb, esc_len + limit + 1); | |
205 CLOSE_READER(re, gb); | |
206 | |
207 return buf + 1; | |
208 }else | |
209 return -1; | |
210 } | |
211 | |
181 #ifdef TRACE | 212 #ifdef TRACE |
182 | 213 |
183 static inline int get_ue(GetBitContext *s, char *file, char *func, int line){ | 214 static inline int get_ue(GetBitContext *s, char *file, char *func, int line){ |
184 int show= show_bits(s, 24); | 215 int show= show_bits(s, 24); |
185 int pos= get_bits_count(s); | 216 int pos= get_bits_count(s); |
277 i= 2*i-1; | 308 i= 2*i-1; |
278 i^= (i>>31); | 309 i^= (i>>31); |
279 #endif | 310 #endif |
280 set_ue_golomb(pb, i); | 311 set_ue_golomb(pb, i); |
281 } | 312 } |
313 | |
314 /** | |
315 * write unsigned golomb rice code. | |
316 */ | |
317 static inline void set_ur_golomb(PutBitContext *pb, int i, int k, int limit, int esc_len){ | |
318 int e; | |
319 | |
320 assert(i>=0); | |
321 | |
322 e= i>>k; | |
323 if(e<limit){ | |
324 put_bits(pb, e + k + 1, (1<<k) + (i&((1<<k)-1))); | |
325 }else{ | |
326 // printf("set %08X, %d\n", (1<<esc_len) + i - 1, limit + esc_len + 1); | |
327 put_bits(pb, limit + esc_len + 1, (1<<esc_len) + i - 1); | |
328 // put_bits(pb, 1, limit + 1); | |
329 // put_bits(pb, i - 1, esc_len); | |
330 } | |
331 } |