Mercurial > libavcodec.hg
comparison mpegvideo.c @ 1554:d736e24bf303 libavcodec
move mmx quantizer matrixes out of MpegEncContext (23k -> 7k) (no meassureable slowdown)
author | michael |
---|---|
date | Wed, 22 Oct 2003 11:23:39 +0000 |
parents | 541681146f83 |
children | 27073c5532dc |
comparison
equal
deleted
inserted
replaced
1553:541681146f83 | 1554:d736e24bf303 |
---|---|
91 static uint8_t (*default_mv_penalty)[MAX_MV*2+1]=NULL; | 91 static uint8_t (*default_mv_penalty)[MAX_MV*2+1]=NULL; |
92 static uint8_t default_fcode_tab[MAX_MV*2+1]; | 92 static uint8_t default_fcode_tab[MAX_MV*2+1]; |
93 | 93 |
94 enum PixelFormat ff_yuv420p_list[2]= {PIX_FMT_YUV420P, -1}; | 94 enum PixelFormat ff_yuv420p_list[2]= {PIX_FMT_YUV420P, -1}; |
95 | 95 |
96 static void convert_matrix(MpegEncContext *s, int (*qmat)[64], uint16_t (*qmat16)[64], uint16_t (*qmat16_bias)[64], | 96 static void convert_matrix(MpegEncContext *s, int (*qmat)[64], uint16_t (*qmat16)[2][64], |
97 const uint16_t *quant_matrix, int bias, int qmin, int qmax) | 97 const uint16_t *quant_matrix, int bias, int qmin, int qmax) |
98 { | 98 { |
99 int qscale; | 99 int qscale; |
100 | 100 |
101 for(qscale=qmin; qscale<=qmax; qscale++){ | 101 for(qscale=qmin; qscale<=qmax; qscale++){ |
130 so (1<<19) / 16 >= (1<<19) / (qscale * quant_matrix[i]) >= (1<<19) / 7905 | 130 so (1<<19) / 16 >= (1<<19) / (qscale * quant_matrix[i]) >= (1<<19) / 7905 |
131 so 32768 >= (1<<19) / (qscale * quant_matrix[i]) >= 67 | 131 so 32768 >= (1<<19) / (qscale * quant_matrix[i]) >= 67 |
132 */ | 132 */ |
133 qmat[qscale][i] = (int)((uint64_t_C(1) << QMAT_SHIFT) / (qscale * quant_matrix[j])); | 133 qmat[qscale][i] = (int)((uint64_t_C(1) << QMAT_SHIFT) / (qscale * quant_matrix[j])); |
134 // qmat [qscale][i] = (1 << QMAT_SHIFT_MMX) / (qscale * quant_matrix[i]); | 134 // qmat [qscale][i] = (1 << QMAT_SHIFT_MMX) / (qscale * quant_matrix[i]); |
135 qmat16[qscale][i] = (1 << QMAT_SHIFT_MMX) / (qscale * quant_matrix[j]); | 135 qmat16[qscale][0][i] = (1 << QMAT_SHIFT_MMX) / (qscale * quant_matrix[j]); |
136 | 136 |
137 if(qmat16[qscale][i]==0 || qmat16[qscale][i]==128*256) qmat16[qscale][i]=128*256-1; | 137 if(qmat16[qscale][0][i]==0 || qmat16[qscale][0][i]==128*256) qmat16[qscale][0][i]=128*256-1; |
138 qmat16_bias[qscale][i]= ROUNDED_DIV(bias<<(16-QUANT_BIAS_SHIFT), qmat16[qscale][i]); | 138 qmat16[qscale][1][i]= ROUNDED_DIV(bias<<(16-QUANT_BIAS_SHIFT), qmat16[qscale][0][i]); |
139 } | 139 } |
140 } | 140 } |
141 } | 141 } |
142 } | 142 } |
143 | 143 |
443 | 443 |
444 CHECKED_ALLOCZ(s->lambda_table, mb_array_size * sizeof(int)) | 444 CHECKED_ALLOCZ(s->lambda_table, mb_array_size * sizeof(int)) |
445 | 445 |
446 CHECKED_ALLOCZ(s->q_intra_matrix, 64*32 * sizeof(int)) | 446 CHECKED_ALLOCZ(s->q_intra_matrix, 64*32 * sizeof(int)) |
447 CHECKED_ALLOCZ(s->q_inter_matrix, 64*32 * sizeof(int)) | 447 CHECKED_ALLOCZ(s->q_inter_matrix, 64*32 * sizeof(int)) |
448 CHECKED_ALLOCZ(s->q_intra_matrix16, 64*32*2 * sizeof(uint16_t)) | |
449 CHECKED_ALLOCZ(s->q_inter_matrix16, 64*32*2 * sizeof(uint16_t)) | |
448 } | 450 } |
449 | 451 |
450 CHECKED_ALLOCZ(s->picture, MAX_PICTURE_COUNT * sizeof(Picture)) | 452 CHECKED_ALLOCZ(s->picture, MAX_PICTURE_COUNT * sizeof(Picture)) |
451 | 453 |
452 CHECKED_ALLOCZ(s->error_status_table, mb_array_size*sizeof(uint8_t)) | 454 CHECKED_ALLOCZ(s->error_status_table, mb_array_size*sizeof(uint8_t)) |
563 av_freep(&s->error_status_table); | 565 av_freep(&s->error_status_table); |
564 av_freep(&s->mb_index2xy); | 566 av_freep(&s->mb_index2xy); |
565 av_freep(&s->lambda_table); | 567 av_freep(&s->lambda_table); |
566 av_freep(&s->q_intra_matrix); | 568 av_freep(&s->q_intra_matrix); |
567 av_freep(&s->q_inter_matrix); | 569 av_freep(&s->q_inter_matrix); |
570 av_freep(&s->q_intra_matrix16); | |
571 av_freep(&s->q_inter_matrix16); | |
568 | 572 |
569 for(i=0; i<MAX_PICTURE_COUNT; i++){ | 573 for(i=0; i<MAX_PICTURE_COUNT; i++){ |
570 free_picture(s, &s->picture[i]); | 574 free_picture(s, &s->picture[i]); |
571 } | 575 } |
572 av_freep(&s->picture); | 576 av_freep(&s->picture); |
880 } | 884 } |
881 | 885 |
882 /* precompute matrix */ | 886 /* precompute matrix */ |
883 /* for mjpeg, we do include qscale in the matrix */ | 887 /* for mjpeg, we do include qscale in the matrix */ |
884 if (s->out_format != FMT_MJPEG) { | 888 if (s->out_format != FMT_MJPEG) { |
885 convert_matrix(s, s->q_intra_matrix, s->q_intra_matrix16, s->q_intra_matrix16_bias, | 889 convert_matrix(s, s->q_intra_matrix, s->q_intra_matrix16, |
886 s->intra_matrix, s->intra_quant_bias, 1, 31); | 890 s->intra_matrix, s->intra_quant_bias, 1, 31); |
887 convert_matrix(s, s->q_inter_matrix, s->q_inter_matrix16, s->q_inter_matrix16_bias, | 891 convert_matrix(s, s->q_inter_matrix, s->q_inter_matrix16, |
888 s->inter_matrix, s->inter_quant_bias, 1, 31); | 892 s->inter_matrix, s->inter_quant_bias, 1, 31); |
889 } | 893 } |
890 | 894 |
891 if(ff_rate_control_init(s) < 0) | 895 if(ff_rate_control_init(s) < 0) |
892 return -1; | 896 return -1; |
3500 int j= s->dsp.idct_permutation[i]; | 3504 int j= s->dsp.idct_permutation[i]; |
3501 | 3505 |
3502 s->intra_matrix[j] = CLAMP_TO_8BIT((ff_mpeg1_default_intra_matrix[i] * s->qscale) >> 3); | 3506 s->intra_matrix[j] = CLAMP_TO_8BIT((ff_mpeg1_default_intra_matrix[i] * s->qscale) >> 3); |
3503 } | 3507 } |
3504 convert_matrix(s, s->q_intra_matrix, s->q_intra_matrix16, | 3508 convert_matrix(s, s->q_intra_matrix, s->q_intra_matrix16, |
3505 s->q_intra_matrix16_bias, s->intra_matrix, s->intra_quant_bias, 8, 8); | 3509 s->intra_matrix, s->intra_quant_bias, 8, 8); |
3506 } | 3510 } |
3507 | 3511 |
3508 //FIXME var duplication | 3512 //FIXME var duplication |
3509 s->current_picture.key_frame= s->pict_type == I_TYPE; | 3513 s->current_picture.key_frame= s->pict_type == I_TYPE; |
3510 s->current_picture.pict_type= s->pict_type; | 3514 s->current_picture.pict_type= s->pict_type; |