Mercurial > libavcodec.hg
comparison unary.h @ 5606:0bc48f6f78a2 libavcodec
cleanup get_unary()
author | aurel |
---|---|
date | Sun, 26 Aug 2007 22:34:49 +0000 |
parents | d92fa6e5fc8c |
children | 5b80d560cdca |
comparison
equal
deleted
inserted
replaced
5605:d92fa6e5fc8c | 5606:0bc48f6f78a2 |
---|---|
23 | 23 |
24 #include "bitstream.h" | 24 #include "bitstream.h" |
25 | 25 |
26 /** | 26 /** |
27 * Get unary code of limited length | 27 * Get unary code of limited length |
28 * @todo FIXME Slow and ugly | |
29 * @param gb GetBitContext | 28 * @param gb GetBitContext |
30 * @param[in] stop The bitstop value (unary code of 1's or 0's) | 29 * @param[in] stop The bitstop value (unary code of 1's or 0's) |
31 * @param[in] len Maximum length | 30 * @param[in] len Maximum length |
32 * @return Unary length/index | 31 * @return Unary length/index |
33 */ | 32 */ |
34 static int get_unary(GetBitContext *gb, int stop, int len) | 33 static inline int get_unary(GetBitContext *gb, int stop, int len) |
35 { | 34 { |
36 #if 1 | |
37 int i; | 35 int i; |
38 | 36 |
39 for(i = 0; i < len && get_bits1(gb) != stop; i++); | 37 for(i = 0; i < len && get_bits1(gb) != stop; i++); |
40 return i; | 38 return i; |
41 /* int i = 0, tmp = !stop; | |
42 | |
43 while (i != len && tmp != stop) | |
44 { | |
45 tmp = get_bits(gb, 1); | |
46 i++; | |
47 } | |
48 if (i == len && tmp != stop) return len+1; | |
49 return i;*/ | |
50 #else | |
51 unsigned int buf; | |
52 int log; | |
53 | |
54 OPEN_READER(re, gb); | |
55 UPDATE_CACHE(re, gb); | |
56 buf=GET_CACHE(re, gb); //Still not sure | |
57 if (stop) buf = ~buf; | |
58 | |
59 log= av_log2(-buf); //FIXME: -? | |
60 if (log < limit){ | |
61 LAST_SKIP_BITS(re, gb, log+1); | |
62 CLOSE_READER(re, gb); | |
63 return log; | |
64 } | |
65 | |
66 LAST_SKIP_BITS(re, gb, limit); | |
67 CLOSE_READER(re, gb); | |
68 return limit; | |
69 #endif | |
70 } | 39 } |
71 | 40 |
72 #endif /* AVCODEC_UNARY_H */ | 41 #endif /* AVCODEC_UNARY_H */ |