Mercurial > libavcodec.hg
comparison mace.c @ 7810:06d3f6968b90 libavcodec
Factorize broken clipping in its own function and document it.
author | vitor |
---|---|
date | Sun, 07 Sep 2008 13:42:34 +0000 |
parents | 74a7ac273231 |
children | ed61b4ffdd7e |
comparison
equal
deleted
inserted
replaced
7809:74a7ac273231 | 7810:06d3f6968b90 |
---|---|
242 | 242 |
243 typedef struct MACEContext { | 243 typedef struct MACEContext { |
244 ChannelData chd[2]; | 244 ChannelData chd[2]; |
245 } MACEContext; | 245 } MACEContext; |
246 | 246 |
247 /** | |
248 * MACE version of av_clip_int16(). We have to do this to keep binary | |
249 * identical output to the binary decoder. | |
250 */ | |
251 static inline int16_t mace_broken_clip_int16(int n) | |
252 { | |
253 if (n > 32767) | |
254 return 32767; | |
255 else if (n < -32768) | |
256 return -32767; | |
257 else | |
258 return n; | |
259 } | |
260 | |
247 static void chomp3(ChannelData *ctx, int16_t *output, uint8_t val, | 261 static void chomp3(ChannelData *ctx, int16_t *output, uint8_t val, |
248 const uint16_t tab1[], | 262 const uint16_t tab1[], |
249 const uint16_t tab2[][8], uint32_t numChannels) | 263 const uint16_t tab2[][8], uint32_t numChannels) |
250 { | 264 { |
251 short current; | 265 short current; |
252 | 266 |
253 current = (short) tab2[(ctx->index & 0x7f0) >> 4][val]; | 267 current = (short) tab2[(ctx->index & 0x7f0) >> 4][val]; |
254 | 268 |
255 if (current + ctx->lev > 32767) | 269 current = mace_broken_clip_int16(current + ctx->lev); |
256 current = 32767; | |
257 else if (current + ctx->lev < -32768) | |
258 current = -32767; | |
259 else | |
260 current += ctx->lev; | |
261 | 270 |
262 ctx->lev = current - (current >> 3); | 271 ctx->lev = current - (current >> 3); |
263 //*ctx->outPtr++=current >> 8; | 272 //*ctx->outPtr++=current >> 8; |
264 *output = QT_8S_2_16S(current); | 273 *output = QT_8S_2_16S(current); |
265 if (( ctx->index += tab1[val]-(ctx->index >> 5) ) < 0) | 274 if (( ctx->index += tab1[val]-(ctx->index >> 5) ) < 0) |
284 ctx->factor = -32767; | 293 ctx->factor = -32767; |
285 else | 294 else |
286 ctx->factor -= 314; | 295 ctx->factor -= 314; |
287 } | 296 } |
288 | 297 |
289 if (current + ctx->level > 32767) | 298 current = mace_broken_clip_int16(current + ctx->level); |
290 current = 32767; | |
291 else if (current + ctx->level < -32768) | |
292 current = -32767; | |
293 else | |
294 current += ctx->level; | |
295 | 299 |
296 ctx->level = ((current*ctx->factor) >> 15); | 300 ctx->level = ((current*ctx->factor) >> 15); |
297 current >>= 1; | 301 current >>= 1; |
298 | 302 |
299 // *ctx->outPtr++=(ctx->previous+ctx->prev2-((ctx->prev2-current) >> 2)) >> 8; | 303 // *ctx->outPtr++=(ctx->previous+ctx->prev2-((ctx->prev2-current) >> 2)) >> 8; |