Mercurial > libavcodec.hg
comparison dv.c @ 7536:910087e97750 libavcodec
Coalescing the un-weighting and de-quantization steps for faster
processing
author | romansh |
---|---|
date | Mon, 11 Aug 2008 09:35:58 +0000 |
parents | 2552555c8a92 |
children | 06c291f42d5f |
comparison
equal
deleted
inserted
replaced
7535:699c33b2eabf | 7536:910087e97750 |
---|---|
48 AVFrame picture; | 48 AVFrame picture; |
49 AVCodecContext *avctx; | 49 AVCodecContext *avctx; |
50 uint8_t *buf; | 50 uint8_t *buf; |
51 | 51 |
52 uint8_t dv_zigzag[2][64]; | 52 uint8_t dv_zigzag[2][64]; |
53 uint8_t dv_idct_shift[2][2][22][64]; | 53 uint32_t dv_idct_factor[2][2][22][64]; |
54 | 54 |
55 void (*get_pixels)(DCTELEM *block, const uint8_t *pixels, int line_size); | 55 void (*get_pixels)(DCTELEM *block, const uint8_t *pixels, int line_size); |
56 void (*fdct[2])(DCTELEM *block); | 56 void (*fdct[2])(DCTELEM *block); |
57 void (*idct_put[2])(uint8_t *dest, int line_size, DCTELEM *block); | 57 void (*idct_put[2])(uint8_t *dest, int line_size, DCTELEM *block); |
58 } DVVideoContext; | 58 } DVVideoContext; |
82 uint8_t size; | 82 uint8_t size; |
83 } dv_vlc_map[DV_VLC_MAP_RUN_SIZE][DV_VLC_MAP_LEV_SIZE]; | 83 } dv_vlc_map[DV_VLC_MAP_RUN_SIZE][DV_VLC_MAP_LEV_SIZE]; |
84 | 84 |
85 static void dv_build_unquantize_tables(DVVideoContext *s, uint8_t* perm) | 85 static void dv_build_unquantize_tables(DVVideoContext *s, uint8_t* perm) |
86 { | 86 { |
87 int i, q, j; | 87 int i, q, a; |
88 | 88 |
89 /* NOTE: max left shift is 6 */ | 89 /* NOTE: max left shift is 6 */ |
90 for(q = 0; q < 22; q++) { | 90 for(q = 0; q < 22; q++) { |
91 /* 88DCT */ | 91 /* 88DCT */ |
92 for(i = 1; i < 64; i++) { | 92 i=1; |
93 /* 88 table */ | 93 for(a = 0; a<4; a++) { |
94 j = perm[i]; | 94 for(; i < dv_quant_areas[a]; i++) { |
95 s->dv_idct_shift[0][0][q][j] = | 95 /* 88 table */ |
96 dv_quant_shifts[q][dv_88_areas[i]] + 1; | 96 s->dv_idct_factor[0][0][q][i] = dv_iweight_88[i]<<(dv_quant_shifts[q][a] + 1); |
97 s->dv_idct_shift[1][0][q][j] = s->dv_idct_shift[0][0][q][j] + 1; | 97 s->dv_idct_factor[1][0][q][i] = s->dv_idct_factor[0][0][q][i]<<1; |
98 } | 98 |
99 | 99 /* 248 table */ |
100 /* 248DCT */ | 100 s->dv_idct_factor[0][1][q][i] = dv_iweight_248[i]<<(dv_quant_shifts[q][a] + 1); |
101 for(i = 1; i < 64; i++) { | 101 s->dv_idct_factor[1][1][q][i] = s->dv_idct_factor[0][1][q][i]<<1; |
102 /* 248 table */ | 102 } |
103 s->dv_idct_shift[0][1][q][i] = | |
104 dv_quant_shifts[q][dv_248_areas[i]] + 1; | |
105 s->dv_idct_shift[1][1][q][i] = s->dv_idct_shift[0][1][q][i] + 1; | |
106 } | 103 } |
107 } | 104 } |
108 } | 105 } |
109 | 106 |
110 static av_cold int dvvideo_init(AVCodecContext *avctx) | 107 static av_cold int dvvideo_init(AVCodecContext *avctx) |
245 | 242 |
246 // #define VLC_DEBUG | 243 // #define VLC_DEBUG |
247 // #define printf(...) av_log(NULL, AV_LOG_ERROR, __VA_ARGS__) | 244 // #define printf(...) av_log(NULL, AV_LOG_ERROR, __VA_ARGS__) |
248 | 245 |
249 typedef struct BlockInfo { | 246 typedef struct BlockInfo { |
250 const uint8_t *shift_table; | 247 const uint32_t *factor_table; |
251 const uint8_t *scan_table; | 248 const uint8_t *scan_table; |
252 const int *iweight_table; | |
253 uint8_t pos; /* position in block */ | 249 uint8_t pos; /* position in block */ |
254 uint8_t dct_mode; | 250 uint8_t dct_mode; |
255 uint8_t partial_bit_count; | 251 uint8_t partial_bit_count; |
256 uint16_t partial_bit_buffer; | 252 uint16_t partial_bit_buffer; |
257 int shift_offset; | 253 int shift_offset; |
279 /* decode ac coefs */ | 275 /* decode ac coefs */ |
280 static void dv_decode_ac(GetBitContext *gb, BlockInfo *mb, DCTELEM *block) | 276 static void dv_decode_ac(GetBitContext *gb, BlockInfo *mb, DCTELEM *block) |
281 { | 277 { |
282 int last_index = gb->size_in_bits; | 278 int last_index = gb->size_in_bits; |
283 const uint8_t *scan_table = mb->scan_table; | 279 const uint8_t *scan_table = mb->scan_table; |
284 const uint8_t *shift_table = mb->shift_table; | 280 const uint32_t *factor_table = mb->factor_table; |
285 const int *iweight_table = mb->iweight_table; | |
286 int pos = mb->pos; | 281 int pos = mb->pos; |
287 int partial_bit_count = mb->partial_bit_count; | 282 int partial_bit_count = mb->partial_bit_count; |
288 int level, pos1, run, vlc_len, index; | 283 int level, run, vlc_len, index; |
289 | 284 |
290 OPEN_READER(re, gb); | 285 OPEN_READER(re, gb); |
291 UPDATE_CACHE(re, gb); | 286 UPDATE_CACHE(re, gb); |
292 | 287 |
293 /* if we must parse a partial vlc, we do it here */ | 288 /* if we must parse a partial vlc, we do it here */ |
328 #endif | 323 #endif |
329 pos += run; | 324 pos += run; |
330 if (pos >= 64) | 325 if (pos >= 64) |
331 break; | 326 break; |
332 | 327 |
333 pos1 = scan_table[pos]; | 328 level = (level*factor_table[pos] + (1 << (dv_iweight_bits-1))) >> dv_iweight_bits; |
334 level <<= shift_table[pos1]; | 329 block[scan_table[pos]] = level; |
335 | |
336 /* unweigh, round, and shift down */ | |
337 level = (level*iweight_table[pos] + (1 << (dv_iweight_bits-1))) >> dv_iweight_bits; | |
338 | |
339 block[pos1] = level; | |
340 | 330 |
341 UPDATE_CACHE(re, gb); | 331 UPDATE_CACHE(re, gb); |
342 } | 332 } |
343 CLOSE_READER(re, gb); | 333 CLOSE_READER(re, gb); |
344 mb->pos = pos; | 334 mb->pos = pos; |
400 /* get the dc */ | 390 /* get the dc */ |
401 dc = get_sbits(&gb, 9); | 391 dc = get_sbits(&gb, 9); |
402 dct_mode = get_bits1(&gb); | 392 dct_mode = get_bits1(&gb); |
403 mb->dct_mode = dct_mode; | 393 mb->dct_mode = dct_mode; |
404 mb->scan_table = s->dv_zigzag[dct_mode]; | 394 mb->scan_table = s->dv_zigzag[dct_mode]; |
405 mb->iweight_table = dct_mode ? dv_iweight_248 : dv_iweight_88; | |
406 class1 = get_bits(&gb, 2); | 395 class1 = get_bits(&gb, 2); |
407 mb->shift_table = s->dv_idct_shift[class1 == 3][dct_mode] | 396 mb->factor_table = s->dv_idct_factor[class1 == 3][dct_mode] |
408 [quant + dv_quant_offset[class1]]; | 397 [quant + dv_quant_offset[class1]]; |
409 dc = dc << 2; | 398 dc = dc << 2; |
410 /* convert to unsigned because 128 is not added in the | 399 /* convert to unsigned because 128 is not added in the |
411 standard IDCT */ | 400 standard IDCT */ |
412 dc += 1024; | 401 dc += 1024; |