diff options
Diffstat (limited to 'lib/rbcodec/codecs/libffmpegFLAC/golomb.h')
-rw-r--r-- | lib/rbcodec/codecs/libffmpegFLAC/golomb.h | 110 |
1 files changed, 110 insertions, 0 deletions
diff --git a/lib/rbcodec/codecs/libffmpegFLAC/golomb.h b/lib/rbcodec/codecs/libffmpegFLAC/golomb.h new file mode 100644 index 0000000000..197b78ee1c --- /dev/null +++ b/lib/rbcodec/codecs/libffmpegFLAC/golomb.h | |||
@@ -0,0 +1,110 @@ | |||
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 | #include <limits.h> | ||
23 | #include "codeclib.h" | ||
24 | |||
25 | /** | ||
26 | * @file golomb.h | ||
27 | * @brief | ||
28 | * exp golomb vlc stuff | ||
29 | * @author Michael Niedermayer <michaelni@gmx.at> and Alex Beregszaszi | ||
30 | */ | ||
31 | |||
32 | |||
33 | /** | ||
34 | * read unsigned golomb rice code (jpegls). | ||
35 | */ | ||
36 | static inline int get_ur_golomb_jpegls(GetBitContext *gb, int k, int limit, int esc_len){ | ||
37 | unsigned int buf; | ||
38 | int log; | ||
39 | |||
40 | OPEN_READER(re, gb); | ||
41 | UPDATE_CACHE(re, gb); | ||
42 | buf=GET_CACHE(re, gb); | ||
43 | |||
44 | log= av_log2(buf); | ||
45 | |||
46 | if(log - k >= 32-MIN_CACHE_BITS+(MIN_CACHE_BITS==32) && 32-log < limit){ | ||
47 | buf >>= log - k; | ||
48 | buf += (30-log)<<k; | ||
49 | LAST_SKIP_BITS(re, gb, 32 + k - log); | ||
50 | CLOSE_READER(re, gb); | ||
51 | |||
52 | return buf; | ||
53 | }else{ | ||
54 | int i; | ||
55 | for(i=0; SHOW_UBITS(re, gb, 1) == 0; i++){ | ||
56 | LAST_SKIP_BITS(re, gb, 1); | ||
57 | UPDATE_CACHE(re, gb); | ||
58 | } | ||
59 | SKIP_BITS(re, gb, 1); | ||
60 | |||
61 | if(i < limit - 1){ | ||
62 | if(k){ | ||
63 | buf = SHOW_UBITS(re, gb, k); | ||
64 | LAST_SKIP_BITS(re, gb, k); | ||
65 | }else{ | ||
66 | buf=0; | ||
67 | } | ||
68 | |||
69 | CLOSE_READER(re, gb); | ||
70 | return buf + (i<<k); | ||
71 | }else if(i == limit - 1){ | ||
72 | buf = SHOW_UBITS(re, gb, esc_len); | ||
73 | LAST_SKIP_BITS(re, gb, esc_len); | ||
74 | CLOSE_READER(re, gb); | ||
75 | |||
76 | return buf + 1; | ||
77 | }else | ||
78 | return -1; | ||
79 | } | ||
80 | } | ||
81 | |||
82 | /** | ||
83 | * read signed golomb rice code (flac). | ||
84 | */ | ||
85 | static inline int get_sr_golomb_flac(GetBitContext *gb, int k, int limit, int esc_len){ | ||
86 | int v= get_ur_golomb_jpegls(gb, k, limit, esc_len); | ||
87 | return (v>>1) ^ -(v&1); | ||
88 | } | ||
89 | |||
90 | /** | ||
91 | * read unsigned golomb rice code (shorten). | ||
92 | */ | ||
93 | #define get_ur_golomb_shorten(gb, k) get_ur_golomb_jpegls(gb, k, INT_MAX, 0) | ||
94 | /* | ||
95 | static inline unsigned int get_ur_golomb_shorten(GetBitContext *gb, int k){ | ||
96 | return get_ur_golomb_jpegls(gb, k, INT_MAX, 0); | ||
97 | } | ||
98 | */ | ||
99 | |||
100 | /** | ||
101 | * read signed golomb rice code (shorten). | ||
102 | */ | ||
103 | static inline int get_sr_golomb_shorten(GetBitContext* gb, int k) | ||
104 | { | ||
105 | int uvar = get_ur_golomb_jpegls(gb, k + 1, INT_MAX, 0); | ||
106 | if (uvar & 1) | ||
107 | return ~(uvar >> 1); | ||
108 | else | ||
109 | return uvar >> 1; | ||
110 | } | ||