comparison mpegvideo.c @ 325:15efd80cf51e libavcodec

mpeg2/mpeg4 dequantizer support (c & mmx) mpeg1 dequantizer optimizations
author michaelni
date Wed, 17 Apr 2002 16:30:31 +0000
parents 9c6f056f0e41
children 6ebb8680885d
comparison
equal deleted inserted replaced
324:9c6f056f0e41 325:15efd80cf51e
14 * 14 *
15 * You should have received a copy of the GNU General Public License 15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software 16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 * 18 *
19 * 4MV & hq encoding stuff by Michael Niedermayer <michaelni@gmx.at> 19 * 4MV & hq & b-frame encoding stuff by Michael Niedermayer <michaelni@gmx.at>
20 */ 20 */
21 #include <stdlib.h> 21 #include <stdlib.h>
22 #include <stdio.h> 22 #include <stdio.h>
23 #include <math.h> 23 #include <math.h>
24 #include <string.h> 24 #include <string.h>
32 32
33 static void encode_picture(MpegEncContext *s, int picture_number); 33 static void encode_picture(MpegEncContext *s, int picture_number);
34 static void rate_control_init(MpegEncContext *s); 34 static void rate_control_init(MpegEncContext *s);
35 static int rate_estimate_qscale(MpegEncContext *s); 35 static int rate_estimate_qscale(MpegEncContext *s);
36 static void dct_unquantize_mpeg1_c(MpegEncContext *s, 36 static void dct_unquantize_mpeg1_c(MpegEncContext *s,
37 DCTELEM *block, int n, int qscale);
38 static void dct_unquantize_mpeg2_c(MpegEncContext *s,
37 DCTELEM *block, int n, int qscale); 39 DCTELEM *block, int n, int qscale);
38 static void dct_unquantize_h263_c(MpegEncContext *s, 40 static void dct_unquantize_h263_c(MpegEncContext *s,
39 DCTELEM *block, int n, int qscale); 41 DCTELEM *block, int n, int qscale);
40 static void draw_edges_c(UINT8 *buf, int wrap, int width, int height, int w); 42 static void draw_edges_c(UINT8 *buf, int wrap, int width, int height, int w);
41 static int dct_quantize_c(MpegEncContext *s, DCTELEM *block, int n, int qscale); 43 static int dct_quantize_c(MpegEncContext *s, DCTELEM *block, int n, int qscale);
110 { 112 {
111 int c_size, i; 113 int c_size, i;
112 UINT8 *pict; 114 UINT8 *pict;
113 115
114 s->dct_unquantize_h263 = dct_unquantize_h263_c; 116 s->dct_unquantize_h263 = dct_unquantize_h263_c;
115 s->dct_unquantize_mpeg = dct_unquantize_mpeg1_c; 117 s->dct_unquantize_mpeg1 = dct_unquantize_mpeg1_c;
118 s->dct_unquantize_mpeg2 = dct_unquantize_mpeg2_c;
116 119
117 #ifdef HAVE_MMX 120 #ifdef HAVE_MMX
118 MPV_common_init_mmx(s); 121 MPV_common_init_mmx(s);
119 #endif 122 #endif
120 //setup default unquantizers (mpeg4 might change it later) 123 //setup default unquantizers (mpeg4 might change it later)
121 if(s->out_format == FMT_H263) 124 if(s->out_format == FMT_H263)
122 s->dct_unquantize = s->dct_unquantize_h263; 125 s->dct_unquantize = s->dct_unquantize_h263;
123 else 126 else
124 s->dct_unquantize = s->dct_unquantize_mpeg; 127 s->dct_unquantize = s->dct_unquantize_mpeg1;
125 128
126 s->mb_width = (s->width + 15) / 16; 129 s->mb_width = (s->width + 15) / 16;
127 s->mb_height = (s->height + 15) / 16; 130 s->mb_height = (s->height + 15) / 16;
128 s->mb_num = s->mb_width * s->mb_height; 131 s->mb_num = s->mb_width * s->mb_height;
129 s->linesize = s->mb_width * 16 + 2 * EDGE_WIDTH; 132 s->linesize = s->mb_width * 16 + 2 * EDGE_WIDTH;
1942 } 1945 }
1943 } 1946 }
1944 } 1947 }
1945 } 1948 }
1946 1949
1950 static void dct_unquantize_mpeg2_c(MpegEncContext *s,
1951 DCTELEM *block, int n, int qscale)
1952 {
1953 int i, level, nCoeffs;
1954 const UINT16 *quant_matrix;
1955
1956 if(s->alternate_scan) nCoeffs= 64;
1957 else nCoeffs= s->block_last_index[n]+1;
1958
1959 if (s->mb_intra) {
1960 if (n < 4)
1961 block[0] = block[0] * s->y_dc_scale;
1962 else
1963 block[0] = block[0] * s->c_dc_scale;
1964 quant_matrix = s->intra_matrix;
1965 for(i=1;i<nCoeffs;i++) {
1966 int j= zigzag_direct[i];
1967 level = block[j];
1968 if (level) {
1969 if (level < 0) {
1970 level = -level;
1971 level = (int)(level * qscale * quant_matrix[j]) >> 3;
1972 level = -level;
1973 } else {
1974 level = (int)(level * qscale * quant_matrix[j]) >> 3;
1975 }
1976 #ifdef PARANOID
1977 if (level < -2048 || level > 2047)
1978 fprintf(stderr, "unquant error %d %d\n", i, level);
1979 #endif
1980 block[j] = level;
1981 }
1982 }
1983 } else {
1984 int sum=-1;
1985 i = 0;
1986 quant_matrix = s->non_intra_matrix;
1987 for(;i<nCoeffs;i++) {
1988 int j= zigzag_direct[i];
1989 level = block[j];
1990 if (level) {
1991 if (level < 0) {
1992 level = -level;
1993 level = (((level << 1) + 1) * qscale *
1994 ((int) (quant_matrix[j]))) >> 4;
1995 level = -level;
1996 } else {
1997 level = (((level << 1) + 1) * qscale *
1998 ((int) (quant_matrix[j]))) >> 4;
1999 }
2000 #ifdef PARANOID
2001 if (level < -2048 || level > 2047)
2002 fprintf(stderr, "unquant error %d %d\n", i, level);
2003 #endif
2004 block[j] = level;
2005 sum+=level;
2006 }
2007 }
2008 block[63]^=sum&1;
2009 }
2010 }
2011
2012
1947 static void dct_unquantize_h263_c(MpegEncContext *s, 2013 static void dct_unquantize_h263_c(MpegEncContext *s,
1948 DCTELEM *block, int n, int qscale) 2014 DCTELEM *block, int n, int qscale)
1949 { 2015 {
1950 int i, level, qmul, qadd; 2016 int i, level, qmul, qadd;
1951 int nCoeffs; 2017 int nCoeffs;