Mercurial > libavcodec.hg
comparison golomb.h @ 5546:e12027d324cc libavcodec
Make the Golomb decoder work for Dirac
author | marco |
---|---|
date | Wed, 15 Aug 2007 12:59:27 +0000 |
parents | 2b72f9bc4f06 |
children | 1d83e9c34641 |
comparison
equal
deleted
inserted
replaced
5545:397cb90b66d0 | 5546:e12027d324cc |
---|---|
41 extern const uint8_t ff_ue_golomb_len[256]; | 41 extern const uint8_t ff_ue_golomb_len[256]; |
42 | 42 |
43 extern const uint8_t ff_interleaved_golomb_vlc_len[256]; | 43 extern const uint8_t ff_interleaved_golomb_vlc_len[256]; |
44 extern const uint8_t ff_interleaved_ue_golomb_vlc_code[256]; | 44 extern const uint8_t ff_interleaved_ue_golomb_vlc_code[256]; |
45 extern const int8_t ff_interleaved_se_golomb_vlc_code[256]; | 45 extern const int8_t ff_interleaved_se_golomb_vlc_code[256]; |
46 extern const uint8_t ff_interleaved_dirac_golomb_vlc_code[256]; | |
46 | 47 |
47 | 48 |
48 /** | 49 /** |
49 * read unsigned exp golomb code. | 50 * read unsigned exp golomb code. |
50 */ | 51 */ |
73 } | 74 } |
74 } | 75 } |
75 | 76 |
76 static inline int svq3_get_ue_golomb(GetBitContext *gb){ | 77 static inline int svq3_get_ue_golomb(GetBitContext *gb){ |
77 uint32_t buf; | 78 uint32_t buf; |
78 int log; | |
79 | 79 |
80 OPEN_READER(re, gb); | 80 OPEN_READER(re, gb); |
81 UPDATE_CACHE(re, gb); | 81 UPDATE_CACHE(re, gb); |
82 buf=GET_CACHE(re, gb); | 82 buf=GET_CACHE(re, gb); |
83 | 83 |
86 LAST_SKIP_BITS(re, gb, ff_interleaved_golomb_vlc_len[buf]); | 86 LAST_SKIP_BITS(re, gb, ff_interleaved_golomb_vlc_len[buf]); |
87 CLOSE_READER(re, gb); | 87 CLOSE_READER(re, gb); |
88 | 88 |
89 return ff_interleaved_ue_golomb_vlc_code[buf]; | 89 return ff_interleaved_ue_golomb_vlc_code[buf]; |
90 }else{ | 90 }else{ |
91 int ret = 1; | |
92 | |
93 while (1) { | |
94 buf >>= 32 - 8; | |
95 LAST_SKIP_BITS(re, gb, FFMIN(ff_interleaved_golomb_vlc_len[buf], 8)); | |
96 | |
97 if (ff_interleaved_golomb_vlc_len[buf] != 9){ | |
98 ret <<= (ff_interleaved_golomb_vlc_len[buf] - 1) >> 1; | |
99 ret |= ff_interleaved_dirac_golomb_vlc_code[buf]; | |
100 break; | |
101 } | |
102 ret = (ret << 4) | ff_interleaved_dirac_golomb_vlc_code[buf]; | |
103 UPDATE_CACHE(re, gb); | |
104 buf = GET_CACHE(re, gb); | |
105 } | |
106 | |
107 CLOSE_READER(re, gb); | |
108 return ret - 1; | |
109 } | |
110 } | |
111 | |
112 /** | |
113 * read unsigned truncated exp golomb code. | |
114 */ | |
115 static inline int get_te0_golomb(GetBitContext *gb, int range){ | |
116 assert(range >= 1); | |
117 | |
118 if(range==1) return 0; | |
119 else if(range==2) return get_bits1(gb)^1; | |
120 else return get_ue_golomb(gb); | |
121 } | |
122 | |
123 /** | |
124 * read unsigned truncated exp golomb code. | |
125 */ | |
126 static inline int get_te_golomb(GetBitContext *gb, int range){ | |
127 assert(range >= 1); | |
128 | |
129 if(range==2) return get_bits1(gb)^1; | |
130 else return get_ue_golomb(gb); | |
131 } | |
132 | |
133 | |
134 /** | |
135 * read signed exp golomb code. | |
136 */ | |
137 static inline int get_se_golomb(GetBitContext *gb){ | |
138 unsigned int buf; | |
139 int log; | |
140 | |
141 OPEN_READER(re, gb); | |
142 UPDATE_CACHE(re, gb); | |
143 buf=GET_CACHE(re, gb); | |
144 | |
145 if(buf >= (1<<27)){ | |
146 buf >>= 32 - 9; | |
147 LAST_SKIP_BITS(re, gb, ff_golomb_vlc_len[buf]); | |
148 CLOSE_READER(re, gb); | |
149 | |
150 return ff_se_golomb_vlc_code[buf]; | |
151 }else{ | |
152 log= 2*av_log2(buf) - 31; | |
153 buf>>= log; | |
154 | |
155 LAST_SKIP_BITS(re, gb, 32 - log); | |
156 CLOSE_READER(re, gb); | |
157 | |
158 if(buf&1) buf= -(buf>>1); | |
159 else buf= (buf>>1); | |
160 | |
161 return buf; | |
162 } | |
163 } | |
164 | |
165 static inline int svq3_get_se_golomb(GetBitContext *gb){ | |
166 unsigned int buf; | |
167 int log; | |
168 | |
169 OPEN_READER(re, gb); | |
170 UPDATE_CACHE(re, gb); | |
171 buf=GET_CACHE(re, gb); | |
172 | |
173 if(buf&0xAA800000){ | |
174 buf >>= 32 - 8; | |
175 LAST_SKIP_BITS(re, gb, ff_interleaved_golomb_vlc_len[buf]); | |
176 CLOSE_READER(re, gb); | |
177 | |
178 return ff_interleaved_se_golomb_vlc_code[buf]; | |
179 }else{ | |
91 LAST_SKIP_BITS(re, gb, 8); | 180 LAST_SKIP_BITS(re, gb, 8); |
92 UPDATE_CACHE(re, gb); | 181 UPDATE_CACHE(re, gb); |
93 buf |= 1 | (GET_CACHE(re, gb) >> 8); | 182 buf |= 1 | (GET_CACHE(re, gb) >> 8); |
94 | 183 |
95 if((buf & 0xAAAAAAAA) == 0) | 184 if((buf & 0xAAAAAAAA) == 0) |
100 } | 189 } |
101 | 190 |
102 LAST_SKIP_BITS(re, gb, 63 - 2*log - 8); | 191 LAST_SKIP_BITS(re, gb, 63 - 2*log - 8); |
103 CLOSE_READER(re, gb); | 192 CLOSE_READER(re, gb); |
104 | 193 |
105 return ((buf << log) >> log) - 1; | 194 return (signed) (((((buf << log) >> log) - 1) ^ -(buf & 0x1)) + 1) >> 1; |
106 } | 195 } |
107 } | 196 } |
108 | 197 |
109 /** | 198 static inline int dirac_get_se_golomb(GetBitContext *gb){ |
110 * read unsigned truncated exp golomb code. | 199 uint32_t buf; |
111 */ | 200 uint32_t ret; |
112 static inline int get_te0_golomb(GetBitContext *gb, int range){ | 201 |
113 assert(range >= 1); | 202 ret = svq3_get_ue_golomb(gb); |
114 | 203 |
115 if(range==1) return 0; | 204 if (ret) { |
116 else if(range==2) return get_bits1(gb)^1; | 205 OPEN_READER(re, gb); |
117 else return get_ue_golomb(gb); | |
118 } | |
119 | |
120 /** | |
121 * read unsigned truncated exp golomb code. | |
122 */ | |
123 static inline int get_te_golomb(GetBitContext *gb, int range){ | |
124 assert(range >= 1); | |
125 | |
126 if(range==2) return get_bits1(gb)^1; | |
127 else return get_ue_golomb(gb); | |
128 } | |
129 | |
130 | |
131 /** | |
132 * read signed exp golomb code. | |
133 */ | |
134 static inline int get_se_golomb(GetBitContext *gb){ | |
135 unsigned int buf; | |
136 int log; | |
137 | |
138 OPEN_READER(re, gb); | |
139 UPDATE_CACHE(re, gb); | |
140 buf=GET_CACHE(re, gb); | |
141 | |
142 if(buf >= (1<<27)){ | |
143 buf >>= 32 - 9; | |
144 LAST_SKIP_BITS(re, gb, ff_golomb_vlc_len[buf]); | |
145 CLOSE_READER(re, gb); | |
146 | |
147 return ff_se_golomb_vlc_code[buf]; | |
148 }else{ | |
149 log= 2*av_log2(buf) - 31; | |
150 buf>>= log; | |
151 | |
152 LAST_SKIP_BITS(re, gb, 32 - log); | |
153 CLOSE_READER(re, gb); | |
154 | |
155 if(buf&1) buf= -(buf>>1); | |
156 else buf= (buf>>1); | |
157 | |
158 return buf; | |
159 } | |
160 } | |
161 | |
162 static inline int svq3_get_se_golomb(GetBitContext *gb){ | |
163 unsigned int buf; | |
164 int log; | |
165 | |
166 OPEN_READER(re, gb); | |
167 UPDATE_CACHE(re, gb); | |
168 buf=GET_CACHE(re, gb); | |
169 | |
170 if(buf&0xAA800000){ | |
171 buf >>= 32 - 8; | |
172 LAST_SKIP_BITS(re, gb, ff_interleaved_golomb_vlc_len[buf]); | |
173 CLOSE_READER(re, gb); | |
174 | |
175 return ff_interleaved_se_golomb_vlc_code[buf]; | |
176 }else{ | |
177 LAST_SKIP_BITS(re, gb, 8); | |
178 UPDATE_CACHE(re, gb); | 206 UPDATE_CACHE(re, gb); |
179 buf |= 1 | (GET_CACHE(re, gb) >> 8); | 207 buf = SHOW_SBITS(re, gb, 1); |
180 | 208 LAST_SKIP_BITS(re, gb, 1); |
181 if((buf & 0xAAAAAAAA) == 0) | 209 ret = (ret ^ buf) - buf; |
182 return INVALID_VLC; | 210 CLOSE_READER(re, gb); |
183 | 211 } |
184 for(log=31; (buf & 0x80000000) == 0; log--){ | 212 |
185 buf = (buf << 2) - ((buf << log) >> (log - 1)) + (buf >> 30); | 213 return ret; |
186 } | |
187 | |
188 LAST_SKIP_BITS(re, gb, 63 - 2*log - 8); | |
189 CLOSE_READER(re, gb); | |
190 | |
191 return (signed) (((((buf << log) >> log) - 1) ^ -(buf & 0x1)) + 1) >> 1; | |
192 } | |
193 } | 214 } |
194 | 215 |
195 /** | 216 /** |
196 * read unsigned golomb rice code (ffv1). | 217 * read unsigned golomb rice code (ffv1). |
197 */ | 218 */ |