Mercurial > libavcodec.hg
comparison mpegvideo.c @ 625:bb6a69f9d409 libavcodec
slow but accurate integer dct from IJG (should be ok with the LGPL as the old DCT is the fast integer DCT from IJG)
per context DCT selection
author | michaelni |
---|---|
date | Thu, 29 Aug 2002 23:55:32 +0000 |
parents | 2be2cc8fd0a1 |
children | f596db4aa871 |
comparison
equal
deleted
inserted
replaced
624:35353e4520d8 | 625:bb6a69f9d409 |
---|---|
34 static void dct_unquantize_h263_c(MpegEncContext *s, | 34 static void dct_unquantize_h263_c(MpegEncContext *s, |
35 DCTELEM *block, int n, int qscale); | 35 DCTELEM *block, int n, int qscale); |
36 static void draw_edges_c(UINT8 *buf, int wrap, int width, int height, int w); | 36 static void draw_edges_c(UINT8 *buf, int wrap, int width, int height, int w); |
37 static int dct_quantize_c(MpegEncContext *s, DCTELEM *block, int n, int qscale, int *overflow); | 37 static int dct_quantize_c(MpegEncContext *s, DCTELEM *block, int n, int qscale, int *overflow); |
38 | 38 |
39 int (*dct_quantize)(MpegEncContext *s, DCTELEM *block, int n, int qscale, int *overflow)= dct_quantize_c; | |
40 void (*draw_edges)(UINT8 *buf, int wrap, int width, int height, int w)= draw_edges_c; | 39 void (*draw_edges)(UINT8 *buf, int wrap, int width, int height, int w)= draw_edges_c; |
41 static void emulated_edge_mc(MpegEncContext *s, UINT8 *src, int linesize, int block_w, int block_h, | 40 static void emulated_edge_mc(MpegEncContext *s, UINT8 *src, int linesize, int block_w, int block_h, |
42 int src_x, int src_y, int w, int h); | 41 int src_x, int src_y, int w, int h); |
43 | 42 |
44 #define EDGE_WIDTH 16 | 43 #define EDGE_WIDTH 16 |
74 extern UINT8 zigzag_end[64]; | 73 extern UINT8 zigzag_end[64]; |
75 | 74 |
76 /* default motion estimation */ | 75 /* default motion estimation */ |
77 int motion_estimation_method = ME_EPZS; | 76 int motion_estimation_method = ME_EPZS; |
78 | 77 |
79 static void convert_matrix(int (*qmat)[64], uint16_t (*qmat16)[64], uint16_t (*qmat16_bias)[64], | 78 static void convert_matrix(MpegEncContext *s, int (*qmat)[64], uint16_t (*qmat16)[64], uint16_t (*qmat16_bias)[64], |
80 const UINT16 *quant_matrix, int bias) | 79 const UINT16 *quant_matrix, int bias) |
81 { | 80 { |
82 int qscale; | 81 int qscale; |
83 | 82 |
84 for(qscale=1; qscale<32; qscale++){ | 83 for(qscale=1; qscale<32; qscale++){ |
85 int i; | 84 int i; |
86 if (av_fdct == fdct_ifast) { | 85 if (s->fdct == ff_jpeg_fdct_islow) { |
86 for(i=0;i<64;i++) { | |
87 const int j= block_permute_op(i); | |
88 /* 16 <= qscale * quant_matrix[i] <= 7905 */ | |
89 /* 19952 <= aanscales[i] * qscale * quant_matrix[i] <= 249205026 */ | |
90 /* (1<<36)/19952 >= (1<<36)/(aanscales[i] * qscale * quant_matrix[i]) >= (1<<36)/249205026 */ | |
91 /* 3444240 >= (1<<36)/(aanscales[i] * qscale * quant_matrix[i]) >= 275 */ | |
92 | |
93 qmat[qscale][j] = (int)((UINT64_C(1) << (QMAT_SHIFT-3)) / | |
94 (qscale * quant_matrix[j])); | |
95 } | |
96 } else if (s->fdct == fdct_ifast) { | |
87 for(i=0;i<64;i++) { | 97 for(i=0;i<64;i++) { |
88 const int j= block_permute_op(i); | 98 const int j= block_permute_op(i); |
89 /* 16 <= qscale * quant_matrix[i] <= 7905 */ | 99 /* 16 <= qscale * quant_matrix[i] <= 7905 */ |
90 /* 19952 <= aanscales[i] * qscale * quant_matrix[i] <= 249205026 */ | 100 /* 19952 <= aanscales[i] * qscale * quant_matrix[i] <= 249205026 */ |
91 /* (1<<36)/19952 >= (1<<36)/(aanscales[i] * qscale * quant_matrix[i]) >= (1<<36)/249205026 */ | 101 /* (1<<36)/19952 >= (1<<36)/(aanscales[i] * qscale * quant_matrix[i]) >= (1<<36)/249205026 */ |
128 UINT8 *pict; | 138 UINT8 *pict; |
129 | 139 |
130 s->dct_unquantize_h263 = dct_unquantize_h263_c; | 140 s->dct_unquantize_h263 = dct_unquantize_h263_c; |
131 s->dct_unquantize_mpeg1 = dct_unquantize_mpeg1_c; | 141 s->dct_unquantize_mpeg1 = dct_unquantize_mpeg1_c; |
132 s->dct_unquantize_mpeg2 = dct_unquantize_mpeg2_c; | 142 s->dct_unquantize_mpeg2 = dct_unquantize_mpeg2_c; |
143 s->dct_quantize= dct_quantize_c; | |
144 | |
145 if(s->avctx->dct_algo==FF_DCT_FASTINT) | |
146 s->fdct = fdct_ifast; | |
147 else | |
148 s->fdct = ff_jpeg_fdct_islow; | |
133 | 149 |
134 #ifdef HAVE_MMX | 150 #ifdef HAVE_MMX |
135 MPV_common_init_mmx(s); | 151 MPV_common_init_mmx(s); |
136 #endif | 152 #endif |
137 #ifdef ARCH_ALPHA | 153 #ifdef ARCH_ALPHA |
561 } | 577 } |
562 | 578 |
563 /* precompute matrix */ | 579 /* precompute matrix */ |
564 /* for mjpeg, we do include qscale in the matrix */ | 580 /* for mjpeg, we do include qscale in the matrix */ |
565 if (s->out_format != FMT_MJPEG) { | 581 if (s->out_format != FMT_MJPEG) { |
566 convert_matrix(s->q_intra_matrix, s->q_intra_matrix16, s->q_intra_matrix16_bias, | 582 convert_matrix(s, s->q_intra_matrix, s->q_intra_matrix16, s->q_intra_matrix16_bias, |
567 s->intra_matrix, s->intra_quant_bias); | 583 s->intra_matrix, s->intra_quant_bias); |
568 convert_matrix(s->q_inter_matrix, s->q_inter_matrix16, s->q_inter_matrix16_bias, | 584 convert_matrix(s, s->q_inter_matrix, s->q_inter_matrix16, s->q_inter_matrix16_bias, |
569 s->inter_matrix, s->inter_quant_bias); | 585 s->inter_matrix, s->inter_quant_bias); |
570 } | 586 } |
571 | 587 |
572 if(ff_rate_control_init(s) < 0) | 588 if(ff_rate_control_init(s) < 0) |
573 return -1; | 589 return -1; |
1810 #endif | 1826 #endif |
1811 /* DCT & quantize */ | 1827 /* DCT & quantize */ |
1812 if(s->out_format==FMT_MJPEG){ | 1828 if(s->out_format==FMT_MJPEG){ |
1813 for(i=0;i<6;i++) { | 1829 for(i=0;i<6;i++) { |
1814 int overflow; | 1830 int overflow; |
1815 s->block_last_index[i] = dct_quantize(s, s->block[i], i, 8, &overflow); | 1831 s->block_last_index[i] = s->dct_quantize(s, s->block[i], i, 8, &overflow); |
1816 if (overflow) clip_coeffs(s, s->block[i], s->block_last_index[i]); | 1832 if (overflow) clip_coeffs(s, s->block[i], s->block_last_index[i]); |
1817 } | 1833 } |
1818 }else{ | 1834 }else{ |
1819 for(i=0;i<6;i++) { | 1835 for(i=0;i<6;i++) { |
1820 if(!skip_dct[i]){ | 1836 if(!skip_dct[i]){ |
1821 int overflow; | 1837 int overflow; |
1822 s->block_last_index[i] = dct_quantize(s, s->block[i], i, s->qscale, &overflow); | 1838 s->block_last_index[i] = s->dct_quantize(s, s->block[i], i, s->qscale, &overflow); |
1823 // FIXME we could decide to change to quantizer instead of clipping | 1839 // FIXME we could decide to change to quantizer instead of clipping |
1824 // JS: I don't think that would be a good idea it could lower quality instead | 1840 // JS: I don't think that would be a good idea it could lower quality instead |
1825 // of improve it. Just INTRADC clipping deserves changes in quantizer | 1841 // of improve it. Just INTRADC clipping deserves changes in quantizer |
1826 if (overflow) clip_coeffs(s, s->block[i], s->block_last_index[i]); | 1842 if (overflow) clip_coeffs(s, s->block[i], s->block_last_index[i]); |
1827 }else | 1843 }else |
2079 if (s->out_format == FMT_MJPEG) { | 2095 if (s->out_format == FMT_MJPEG) { |
2080 /* for mjpeg, we do include qscale in the matrix */ | 2096 /* for mjpeg, we do include qscale in the matrix */ |
2081 s->intra_matrix[0] = ff_mpeg1_default_intra_matrix[0]; | 2097 s->intra_matrix[0] = ff_mpeg1_default_intra_matrix[0]; |
2082 for(i=1;i<64;i++) | 2098 for(i=1;i<64;i++) |
2083 s->intra_matrix[i] = CLAMP_TO_8BIT((ff_mpeg1_default_intra_matrix[i] * s->qscale) >> 3); | 2099 s->intra_matrix[i] = CLAMP_TO_8BIT((ff_mpeg1_default_intra_matrix[i] * s->qscale) >> 3); |
2084 convert_matrix(s->q_intra_matrix, s->q_intra_matrix16, | 2100 convert_matrix(s, s->q_intra_matrix, s->q_intra_matrix16, |
2085 s->q_intra_matrix16_bias, s->intra_matrix, s->intra_quant_bias); | 2101 s->q_intra_matrix16_bias, s->intra_matrix, s->intra_quant_bias); |
2086 } | 2102 } |
2087 | 2103 |
2088 s->last_bits= get_bit_count(&s->pb); | 2104 s->last_bits= get_bit_count(&s->pb); |
2089 switch(s->out_format) { | 2105 switch(s->out_format) { |
2444 const int *qmat; | 2460 const int *qmat; |
2445 int bias; | 2461 int bias; |
2446 int max=0; | 2462 int max=0; |
2447 unsigned int threshold1, threshold2; | 2463 unsigned int threshold1, threshold2; |
2448 | 2464 |
2449 av_fdct (block); | 2465 s->fdct (block); |
2450 | 2466 |
2451 /* we need this permutation so that we correct the IDCT | 2467 /* we need this permutation so that we correct the IDCT |
2452 permutation. will be moved into DCT code */ | 2468 permutation. will be moved into DCT code */ |
2453 block_permute(block); | 2469 block_permute(block); |
2454 | 2470 |