diff options
Diffstat (limited to 'apps/codecs/libffmpegFLAC/golomb.h')
-rw-r--r-- | apps/codecs/libffmpegFLAC/golomb.h | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/apps/codecs/libffmpegFLAC/golomb.h b/apps/codecs/libffmpegFLAC/golomb.h new file mode 100644 index 0000000000..9dcbcb2d54 --- /dev/null +++ b/apps/codecs/libffmpegFLAC/golomb.h | |||
@@ -0,0 +1,106 @@ | |||
1 | /* | ||
2 | * exp golomb vlc stuff | ||
3 | * Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at> | ||
4 | * Copyright (c) 2004 Alex Beregszaszi | ||
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 | /* From libavutil/common.h */ | ||
24 | extern const uint8_t ff_log2_tab[256]; | ||
25 | static inline int av_log2(unsigned int v) | ||
26 | { | ||
27 | int n; | ||
28 | |||
29 | n = 0; | ||
30 | if (v & 0xffff0000) { | ||
31 | v >>= 16; | ||
32 | n += 16; | ||
33 | } | ||
34 | if (v & 0xff00) { | ||
35 | v >>= 8; | ||
36 | n += 8; | ||
37 | } | ||
38 | n += ff_log2_tab[v]; | ||
39 | |||
40 | return n; | ||
41 | } | ||
42 | |||
43 | /** | ||
44 | * @file golomb.h | ||
45 | * @brief | ||
46 | * exp golomb vlc stuff | ||
47 | * @author Michael Niedermayer <michaelni@gmx.at> and Alex Beregszaszi | ||
48 | */ | ||
49 | |||
50 | |||
51 | /** | ||
52 | * read unsigned golomb rice code (jpegls). | ||
53 | */ | ||
54 | static inline int get_ur_golomb_jpegls(GetBitContext *gb, int k, int limit, int esc_len){ | ||
55 | unsigned int buf; | ||
56 | int log; | ||
57 | |||
58 | OPEN_READER(re, gb); | ||
59 | UPDATE_CACHE(re, gb); | ||
60 | buf=GET_CACHE(re, gb); | ||
61 | |||
62 | log= av_log2(buf); | ||
63 | |||
64 | if(log > 31-11){ | ||
65 | buf >>= log - k; | ||
66 | buf += (30-log)<<k; | ||
67 | LAST_SKIP_BITS(re, gb, 32 + k - log); | ||
68 | CLOSE_READER(re, gb); | ||
69 | |||
70 | return buf; | ||
71 | }else{ | ||
72 | int i; | ||
73 | for(i=0; SHOW_UBITS(re, gb, 1) == 0; i++){ | ||
74 | LAST_SKIP_BITS(re, gb, 1); | ||
75 | UPDATE_CACHE(re, gb); | ||
76 | } | ||
77 | SKIP_BITS(re, gb, 1); | ||
78 | |||
79 | if(i < limit - 1){ | ||
80 | if(k){ | ||
81 | buf = SHOW_UBITS(re, gb, k); | ||
82 | LAST_SKIP_BITS(re, gb, k); | ||
83 | }else{ | ||
84 | buf=0; | ||
85 | } | ||
86 | |||
87 | CLOSE_READER(re, gb); | ||
88 | return buf + (i<<k); | ||
89 | }else if(i == limit - 1){ | ||
90 | buf = SHOW_UBITS(re, gb, esc_len); | ||
91 | LAST_SKIP_BITS(re, gb, esc_len); | ||
92 | CLOSE_READER(re, gb); | ||
93 | |||
94 | return buf + 1; | ||
95 | }else | ||
96 | return -1; | ||
97 | } | ||
98 | } | ||
99 | |||
100 | /** | ||
101 | * read signed golomb rice code (flac). | ||
102 | */ | ||
103 | static inline int get_sr_golomb_flac(GetBitContext *gb, int k, int limit, int esc_len){ | ||
104 | int v= get_ur_golomb_jpegls(gb, k, limit, esc_len); | ||
105 | return (v>>1) ^ -(v&1); | ||
106 | } | ||