comparison mace.c @ 7998:2dbed1c6a963 libavcodec

Factorize duplicate table reading code.
author vitor
date Sun, 05 Oct 2008 14:36:10 +0000
parents 3e7e3cb59bd4
children 5ef823d919d5
comparison
equal deleted inserted replaced
7997:d38acad6d4bb 7998:2dbed1c6a963
160 return -32767; 160 return -32767;
161 else 161 else
162 return n; 162 return n;
163 } 163 }
164 164
165 static int16_t read_table(ChannelData *chd, uint8_t val, const int16_t tab1[],
166 const int16_t *tab2, int tab2_stride)
167 {
168 int16_t current;
169
170 if (val < tab2_stride)
171 current = tab2[((chd->index & 0x7f0) >> 4)*tab2_stride + val];
172 else
173 current = - 1 - tab2[((chd->index & 0x7f0) >> 4)*tab2_stride + 2*tab2_stride-val-1];
174
175 if (( chd->index += tab1[val]-(chd->index >> 5) ) < 0)
176 chd->index = 0;
177
178 return current;
179 }
180
165 static void chomp3(ChannelData *chd, int16_t *output, uint8_t val, 181 static void chomp3(ChannelData *chd, int16_t *output, uint8_t val,
166 const int16_t tab1[], 182 const int16_t tab1[],
167 const int16_t *tab2, int tab2_stride, 183 const int16_t *tab2, int tab2_stride,
168 uint32_t numChannels) 184 uint32_t numChannels)
169 { 185 {
170 int16_t current; 186
171 187 int16_t current = read_table(chd, val, tab1, tab2, tab2_stride);
172 if (val < tab2_stride)
173 current = tab2[((chd->index & 0x7f0) >> 4)*tab2_stride + val];
174 else
175 current = - 1 - tab2[((chd->index & 0x7f0) >> 4)*tab2_stride + 2*tab2_stride-val-1];
176 188
177 current = mace_broken_clip_int16(current + chd->level); 189 current = mace_broken_clip_int16(current + chd->level);
178 190
179 chd->level = current - (current >> 3); 191 chd->level = current - (current >> 3);
180 *output = QT_8S_2_16S(current); 192 *output = QT_8S_2_16S(current);
181 if (( chd->index += tab1[val]-(chd->index >> 5) ) < 0)
182 chd->index = 0;
183 } 193 }
184 194
185 static void chomp6(ChannelData *chd, int16_t *output, uint8_t val, 195 static void chomp6(ChannelData *chd, int16_t *output, uint8_t val,
186 const int16_t tab1[], 196 const int16_t tab1[],
187 const int16_t *tab2, int tab2_stride, 197 const int16_t *tab2, int tab2_stride,
188 uint32_t numChannels) 198 uint32_t numChannels)
189 { 199 {
190 int16_t current; 200 int16_t current = read_table(chd, val, tab1, tab2, tab2_stride);
191
192 if (val < tab2_stride)
193 current = tab2[((chd->index & 0x7f0) >> 4)*tab2_stride + val];
194 else
195 current = - 1 - tab2[((chd->index & 0x7f0) >> 4)*tab2_stride + 2*tab2_stride-val-1];
196 201
197 if ((chd->previous ^ current) >= 0) { 202 if ((chd->previous ^ current) >= 0) {
198 chd->factor = FFMIN(chd->factor + 506, 32767); 203 chd->factor = FFMIN(chd->factor + 506, 32767);
199 } else { 204 } else {
200 if (chd->factor - 314 < -32768) 205 if (chd->factor - 314 < -32768)
212 ((chd->prev2-current) >> 2)); 217 ((chd->prev2-current) >> 2));
213 output[numChannels] = QT_8S_2_16S(chd->previous + current + 218 output[numChannels] = QT_8S_2_16S(chd->previous + current +
214 ((chd->prev2-current) >> 2)); 219 ((chd->prev2-current) >> 2));
215 chd->prev2 = chd->previous; 220 chd->prev2 = chd->previous;
216 chd->previous = current; 221 chd->previous = current;
217
218 if ((chd->index += tab1[val] - (chd->index >> 5)) < 0)
219 chd->index = 0;
220 } 222 }
221 223
222 static av_cold int mace_decode_init(AVCodecContext * avctx) 224 static av_cold int mace_decode_init(AVCodecContext * avctx)
223 { 225 {
224 if (avctx->channels > 2) 226 if (avctx->channels > 2)