5605
|
1 /*
|
|
2 * copyright (c) 2004 Michael Niedermayer <michaelni@gmx.at>
|
|
3 *
|
|
4 * This file is part of FFmpeg.
|
|
5 *
|
|
6 * FFmpeg 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.1 of the License, or (at your option) any later version.
|
|
10 *
|
|
11 * FFmpeg 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 FFmpeg; if not, write to the Free Software
|
|
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
19 */
|
|
20
|
|
21 #ifndef AVCODEC_UNARY_H
|
|
22 #define AVCODEC_UNARY_H
|
|
23
|
|
24 #include "bitstream.h"
|
|
25
|
|
26 /**
|
|
27 * Get unary code of limited length
|
|
28 * @todo FIXME Slow and ugly
|
|
29 * @param gb GetBitContext
|
|
30 * @param[in] stop The bitstop value (unary code of 1's or 0's)
|
|
31 * @param[in] len Maximum length
|
|
32 * @return Unary length/index
|
|
33 */
|
|
34 static int get_unary(GetBitContext *gb, int stop, int len)
|
|
35 {
|
|
36 #if 1
|
|
37 int i;
|
|
38
|
|
39 for(i = 0; i < len && get_bits1(gb) != stop; i++);
|
|
40 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 }
|
|
71
|
|
72 #endif /* AVCODEC_UNARY_H */
|