Commit 70ecab6e authored by michaelni's avatar michaelni

slow but accurate integer dct from IJG (should be ok with the LGPL as the old...

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


git-svn-id: file:///var/local/repositories/ffmpeg/trunk@878 9553f0bf-9b14-0410-a0b8-cfaf0461ba5b
parent 233d5f51
...@@ -11,7 +11,7 @@ CFLAGS= $(OPTFLAGS) -Wall -g -DHAVE_AV_CONFIG_H -I.. -D_FILE_OFFSET_BITS=64 -D_L ...@@ -11,7 +11,7 @@ CFLAGS= $(OPTFLAGS) -Wall -g -DHAVE_AV_CONFIG_H -I.. -D_FILE_OFFSET_BITS=64 -D_L
LDFLAGS= -g LDFLAGS= -g
OBJS= common.o utils.o mem.o allcodecs.o \ OBJS= common.o utils.o mem.o allcodecs.o \
mpegvideo.o h263.o jrevdct.o jfdctfst.o \ mpegvideo.o h263.o jrevdct.o jfdctfst.o jfdctint.o\
mpegaudio.o ac3enc.o mjpeg.o resample.o dsputil.o \ mpegaudio.o ac3enc.o mjpeg.o resample.o dsputil.o \
motion_est.o imgconvert.o imgresample.o msmpeg4.o \ motion_est.o imgconvert.o imgresample.o msmpeg4.o \
mpeg12.o h263dec.o svq1.o rv10.o mpegaudiodec.o pcm.o simple_idct.o \ mpeg12.o h263dec.o svq1.o rv10.o mpegaudiodec.o pcm.o simple_idct.o \
......
...@@ -5,8 +5,8 @@ ...@@ -5,8 +5,8 @@
#define LIBAVCODEC_VERSION_INT 0x000406 #define LIBAVCODEC_VERSION_INT 0x000406
#define LIBAVCODEC_VERSION "0.4.6" #define LIBAVCODEC_VERSION "0.4.6"
#define LIBAVCODEC_BUILD 4620 #define LIBAVCODEC_BUILD 4621
#define LIBAVCODEC_BUILD_STR "4620" #define LIBAVCODEC_BUILD_STR "4621"
enum CodecID { enum CodecID {
CODEC_ID_NONE, CODEC_ID_NONE,
...@@ -96,6 +96,7 @@ extern int motion_estimation_method; ...@@ -96,6 +96,7 @@ extern int motion_estimation_method;
static const int Motion_Est_QTab[] = { ME_ZERO, ME_PHODS, ME_LOG, static const int Motion_Est_QTab[] = { ME_ZERO, ME_PHODS, ME_LOG,
ME_X1, ME_EPZS, ME_FULL }; ME_X1, ME_EPZS, ME_FULL };
#define FF_MAX_B_FRAMES 4 #define FF_MAX_B_FRAMES 4
/* encoding support */ /* encoding support */
...@@ -308,6 +309,12 @@ typedef struct AVCodecContext { ...@@ -308,6 +309,12 @@ typedef struct AVCodecContext {
int aspected_width; int aspected_width;
int aspected_height; int aspected_height;
int dct_algo;
#define FF_DCT_AUTO 0
#define FF_DCT_FASTINT 1
#define FF_DCT_INT 2
#define FF_DCT_MMX 3
//FIXME this should be reordered after kabis API is finished ... //FIXME this should be reordered after kabis API is finished ...
//TODO kill kabi //TODO kill kabi
/* /*
...@@ -338,7 +345,7 @@ typedef struct AVCodecContext { ...@@ -338,7 +345,7 @@ typedef struct AVCodecContext {
uc_res6,uc_res7,uc_res8,uc_res9,uc_res10,uc_res11,uc_res12; uc_res6,uc_res7,uc_res8,uc_res9,uc_res10,uc_res11,uc_res12;
unsigned int unsigned int
ui_res0,ui_res1,ui_res2,ui_res3,ui_res4,ui_res5,ui_res6,ui_res7,ui_res8,ui_res9, ui_res0,ui_res1,ui_res2,ui_res3,ui_res4,ui_res5,ui_res6,ui_res7,ui_res8,ui_res9,
ui_res10,ui_res11,ui_res12,ui_res13,ui_res14,ui_res15,ui_res16,ui_res17; ui_res10,ui_res11,ui_res12,ui_res13,ui_res14,ui_res15,ui_res16;
} AVCodecContext; } AVCodecContext;
typedef struct AVCodec { typedef struct AVCodec {
......
...@@ -25,7 +25,6 @@ ...@@ -25,7 +25,6 @@
void (*ff_idct)(DCTELEM *block); void (*ff_idct)(DCTELEM *block);
void (*ff_idct_put)(UINT8 *dest, int line_size, DCTELEM *block); void (*ff_idct_put)(UINT8 *dest, int line_size, DCTELEM *block);
void (*ff_idct_add)(UINT8 *dest, int line_size, DCTELEM *block); void (*ff_idct_add)(UINT8 *dest, int line_size, DCTELEM *block);
void (*av_fdct)(DCTELEM *block);
void (*get_pixels)(DCTELEM *block, const UINT8 *pixels, int line_size); void (*get_pixels)(DCTELEM *block, const UINT8 *pixels, int line_size);
void (*diff_pixels)(DCTELEM *block, const UINT8 *s1, const UINT8 *s2, int stride); void (*diff_pixels)(DCTELEM *block, const UINT8 *s1, const UINT8 *s2, int stride);
void (*put_pixels_clamped)(const DCTELEM *block, UINT8 *pixels, int line_size); void (*put_pixels_clamped)(const DCTELEM *block, UINT8 *pixels, int line_size);
...@@ -1323,7 +1322,6 @@ void dsputil_init(void) ...@@ -1323,7 +1322,6 @@ void dsputil_init(void)
pix_abs8x8_x2 = pix_abs8x8_x2_c; pix_abs8x8_x2 = pix_abs8x8_x2_c;
pix_abs8x8_y2 = pix_abs8x8_y2_c; pix_abs8x8_y2 = pix_abs8x8_y2_c;
pix_abs8x8_xy2 = pix_abs8x8_xy2_c; pix_abs8x8_xy2 = pix_abs8x8_xy2_c;
av_fdct = fdct_ifast;
use_permuted_idct = 1; use_permuted_idct = 1;
......
...@@ -27,13 +27,12 @@ ...@@ -27,13 +27,12 @@
typedef short DCTELEM; typedef short DCTELEM;
void fdct_ifast (DCTELEM *data); void fdct_ifast (DCTELEM *data);
void ff_jpeg_fdct_islow (DCTELEM *data);
void j_rev_dct (DCTELEM *data); void j_rev_dct (DCTELEM *data);
void fdct_mmx(DCTELEM *block); void fdct_mmx(DCTELEM *block);
extern void (*av_fdct)(DCTELEM *block);
/* encoding scans */ /* encoding scans */
extern UINT8 ff_alternate_horizontal_scan[64]; extern UINT8 ff_alternate_horizontal_scan[64];
extern UINT8 ff_alternate_vertical_scan[64]; extern UINT8 ff_alternate_vertical_scan[64];
......
...@@ -424,8 +424,6 @@ void dsputil_init_mmx(void) ...@@ -424,8 +424,6 @@ void dsputil_init_mmx(void)
pix_abs8x8_y2 = pix_abs8x8_y2_mmx; pix_abs8x8_y2 = pix_abs8x8_y2_mmx;
pix_abs8x8_xy2= pix_abs8x8_xy2_mmx; pix_abs8x8_xy2= pix_abs8x8_xy2_mmx;
av_fdct = fdct_mmx;
put_pixels_tab[0] = put_pixels_mmx; put_pixels_tab[0] = put_pixels_mmx;
put_pixels_tab[1] = put_pixels_x2_mmx; put_pixels_tab[1] = put_pixels_x2_mmx;
put_pixels_tab[2] = put_pixels_y2_mmx; put_pixels_tab[2] = put_pixels_y2_mmx;
......
...@@ -552,16 +552,21 @@ void unused_var_warning_killer(){ ...@@ -552,16 +552,21 @@ void unused_var_warning_killer(){
void MPV_common_init_mmx(MpegEncContext *s) void MPV_common_init_mmx(MpegEncContext *s)
{ {
if (mm_flags & MM_MMX) { if (mm_flags & MM_MMX) {
const int dct_algo= s->avctx->dct_algo;
s->dct_unquantize_h263 = dct_unquantize_h263_mmx; s->dct_unquantize_h263 = dct_unquantize_h263_mmx;
s->dct_unquantize_mpeg1 = dct_unquantize_mpeg1_mmx; s->dct_unquantize_mpeg1 = dct_unquantize_mpeg1_mmx;
s->dct_unquantize_mpeg2 = dct_unquantize_mpeg2_mmx; s->dct_unquantize_mpeg2 = dct_unquantize_mpeg2_mmx;
draw_edges = draw_edges_mmx; draw_edges = draw_edges_mmx;
if(mm_flags & MM_MMXEXT){ if(dct_algo==FF_DCT_AUTO || dct_algo==FF_DCT_MMX){
dct_quantize= dct_quantize_MMX2; s->fdct = fdct_mmx;
} else {
dct_quantize= dct_quantize_MMX; if(mm_flags & MM_MMXEXT){
s->dct_quantize= dct_quantize_MMX2;
} else {
s->dct_quantize= dct_quantize_MMX;
}
} }
} }
} }
...@@ -40,7 +40,8 @@ static int RENAME(dct_quantize)(MpegEncContext *s, ...@@ -40,7 +40,8 @@ static int RENAME(dct_quantize)(MpegEncContext *s,
const UINT16 *qmat, *bias; const UINT16 *qmat, *bias;
static __align8 INT16 temp_block[64]; static __align8 INT16 temp_block[64];
av_fdct (block); //s->fdct (block);
fdct_mmx (block); //cant be anything else ...
if (s->mb_intra) { if (s->mb_intra) {
int dummy; int dummy;
......
This diff is collapsed.
...@@ -36,7 +36,6 @@ static void dct_unquantize_h263_c(MpegEncContext *s, ...@@ -36,7 +36,6 @@ static void dct_unquantize_h263_c(MpegEncContext *s,
static void draw_edges_c(UINT8 *buf, int wrap, int width, int height, int w); static void draw_edges_c(UINT8 *buf, int wrap, int width, int height, int w);
static int dct_quantize_c(MpegEncContext *s, DCTELEM *block, int n, int qscale, int *overflow); static int dct_quantize_c(MpegEncContext *s, DCTELEM *block, int n, int qscale, int *overflow);
int (*dct_quantize)(MpegEncContext *s, DCTELEM *block, int n, int qscale, int *overflow)= dct_quantize_c;
void (*draw_edges)(UINT8 *buf, int wrap, int width, int height, int w)= draw_edges_c; void (*draw_edges)(UINT8 *buf, int wrap, int width, int height, int w)= draw_edges_c;
static void emulated_edge_mc(MpegEncContext *s, UINT8 *src, int linesize, int block_w, int block_h, static void emulated_edge_mc(MpegEncContext *s, UINT8 *src, int linesize, int block_w, int block_h,
int src_x, int src_y, int w, int h); int src_x, int src_y, int w, int h);
...@@ -76,14 +75,25 @@ extern UINT8 zigzag_end[64]; ...@@ -76,14 +75,25 @@ extern UINT8 zigzag_end[64];
/* default motion estimation */ /* default motion estimation */
int motion_estimation_method = ME_EPZS; int motion_estimation_method = ME_EPZS;
static void convert_matrix(int (*qmat)[64], uint16_t (*qmat16)[64], uint16_t (*qmat16_bias)[64], static void convert_matrix(MpegEncContext *s, int (*qmat)[64], uint16_t (*qmat16)[64], uint16_t (*qmat16_bias)[64],
const UINT16 *quant_matrix, int bias) const UINT16 *quant_matrix, int bias)
{ {
int qscale; int qscale;
for(qscale=1; qscale<32; qscale++){ for(qscale=1; qscale<32; qscale++){
int i; int i;
if (av_fdct == fdct_ifast) { if (s->fdct == ff_jpeg_fdct_islow) {
for(i=0;i<64;i++) {
const int j= block_permute_op(i);
/* 16 <= qscale * quant_matrix[i] <= 7905 */
/* 19952 <= aanscales[i] * qscale * quant_matrix[i] <= 249205026 */
/* (1<<36)/19952 >= (1<<36)/(aanscales[i] * qscale * quant_matrix[i]) >= (1<<36)/249205026 */
/* 3444240 >= (1<<36)/(aanscales[i] * qscale * quant_matrix[i]) >= 275 */
qmat[qscale][j] = (int)((UINT64_C(1) << (QMAT_SHIFT-3)) /
(qscale * quant_matrix[j]));
}
} else if (s->fdct == fdct_ifast) {
for(i=0;i<64;i++) { for(i=0;i<64;i++) {
const int j= block_permute_op(i); const int j= block_permute_op(i);
/* 16 <= qscale * quant_matrix[i] <= 7905 */ /* 16 <= qscale * quant_matrix[i] <= 7905 */
...@@ -130,6 +140,12 @@ int MPV_common_init(MpegEncContext *s) ...@@ -130,6 +140,12 @@ int MPV_common_init(MpegEncContext *s)
s->dct_unquantize_h263 = dct_unquantize_h263_c; s->dct_unquantize_h263 = dct_unquantize_h263_c;
s->dct_unquantize_mpeg1 = dct_unquantize_mpeg1_c; s->dct_unquantize_mpeg1 = dct_unquantize_mpeg1_c;
s->dct_unquantize_mpeg2 = dct_unquantize_mpeg2_c; s->dct_unquantize_mpeg2 = dct_unquantize_mpeg2_c;
s->dct_quantize= dct_quantize_c;
if(s->avctx->dct_algo==FF_DCT_FASTINT)
s->fdct = fdct_ifast;
else
s->fdct = ff_jpeg_fdct_islow;
#ifdef HAVE_MMX #ifdef HAVE_MMX
MPV_common_init_mmx(s); MPV_common_init_mmx(s);
...@@ -563,9 +579,9 @@ int MPV_encode_init(AVCodecContext *avctx) ...@@ -563,9 +579,9 @@ int MPV_encode_init(AVCodecContext *avctx)
/* precompute matrix */ /* precompute matrix */
/* for mjpeg, we do include qscale in the matrix */ /* for mjpeg, we do include qscale in the matrix */
if (s->out_format != FMT_MJPEG) { if (s->out_format != FMT_MJPEG) {
convert_matrix(s->q_intra_matrix, s->q_intra_matrix16, s->q_intra_matrix16_bias, convert_matrix(s, s->q_intra_matrix, s->q_intra_matrix16, s->q_intra_matrix16_bias,
s->intra_matrix, s->intra_quant_bias); s->intra_matrix, s->intra_quant_bias);
convert_matrix(s->q_inter_matrix, s->q_inter_matrix16, s->q_inter_matrix16_bias, convert_matrix(s, s->q_inter_matrix, s->q_inter_matrix16, s->q_inter_matrix16_bias,
s->inter_matrix, s->inter_quant_bias); s->inter_matrix, s->inter_quant_bias);
} }
...@@ -1812,14 +1828,14 @@ static void encode_mb(MpegEncContext *s, int motion_x, int motion_y) ...@@ -1812,14 +1828,14 @@ static void encode_mb(MpegEncContext *s, int motion_x, int motion_y)
if(s->out_format==FMT_MJPEG){ if(s->out_format==FMT_MJPEG){
for(i=0;i<6;i++) { for(i=0;i<6;i++) {
int overflow; int overflow;
s->block_last_index[i] = dct_quantize(s, s->block[i], i, 8, &overflow); s->block_last_index[i] = s->dct_quantize(s, s->block[i], i, 8, &overflow);
if (overflow) clip_coeffs(s, s->block[i], s->block_last_index[i]); if (overflow) clip_coeffs(s, s->block[i], s->block_last_index[i]);
} }
}else{ }else{
for(i=0;i<6;i++) { for(i=0;i<6;i++) {
if(!skip_dct[i]){ if(!skip_dct[i]){
int overflow; int overflow;
s->block_last_index[i] = dct_quantize(s, s->block[i], i, s->qscale, &overflow); s->block_last_index[i] = s->dct_quantize(s, s->block[i], i, s->qscale, &overflow);
// FIXME we could decide to change to quantizer instead of clipping // FIXME we could decide to change to quantizer instead of clipping
// JS: I don't think that would be a good idea it could lower quality instead // JS: I don't think that would be a good idea it could lower quality instead
// of improve it. Just INTRADC clipping deserves changes in quantizer // of improve it. Just INTRADC clipping deserves changes in quantizer
...@@ -2081,7 +2097,7 @@ static void encode_picture(MpegEncContext *s, int picture_number) ...@@ -2081,7 +2097,7 @@ static void encode_picture(MpegEncContext *s, int picture_number)
s->intra_matrix[0] = ff_mpeg1_default_intra_matrix[0]; s->intra_matrix[0] = ff_mpeg1_default_intra_matrix[0];
for(i=1;i<64;i++) for(i=1;i<64;i++)
s->intra_matrix[i] = CLAMP_TO_8BIT((ff_mpeg1_default_intra_matrix[i] * s->qscale) >> 3); s->intra_matrix[i] = CLAMP_TO_8BIT((ff_mpeg1_default_intra_matrix[i] * s->qscale) >> 3);
convert_matrix(s->q_intra_matrix, s->q_intra_matrix16, convert_matrix(s, s->q_intra_matrix, s->q_intra_matrix16,
s->q_intra_matrix16_bias, s->intra_matrix, s->intra_quant_bias); s->q_intra_matrix16_bias, s->intra_matrix, s->intra_quant_bias);
} }
...@@ -2446,7 +2462,7 @@ static int dct_quantize_c(MpegEncContext *s, ...@@ -2446,7 +2462,7 @@ static int dct_quantize_c(MpegEncContext *s,
int max=0; int max=0;
unsigned int threshold1, threshold2; unsigned int threshold1, threshold2;
av_fdct (block); s->fdct (block);
/* we need this permutation so that we correct the IDCT /* we need this permutation so that we correct the IDCT
permutation. will be moved into DCT code */ permutation. will be moved into DCT code */
......
...@@ -465,6 +465,8 @@ typedef struct MpegEncContext { ...@@ -465,6 +465,8 @@ typedef struct MpegEncContext {
DCTELEM *block, int n, int qscale); DCTELEM *block, int n, int qscale);
void (*dct_unquantize)(struct MpegEncContext *s, // unquantizer to use (mpeg4 can use both) void (*dct_unquantize)(struct MpegEncContext *s, // unquantizer to use (mpeg4 can use both)
DCTELEM *block, int n, int qscale); DCTELEM *block, int n, int qscale);
int (*dct_quantize)(struct MpegEncContext *s, DCTELEM *block, int n, int qscale, int *overflow);
void (*fdct)(DCTELEM *block);
} MpegEncContext; } MpegEncContext;
int MPV_common_init(MpegEncContext *s); int MPV_common_init(MpegEncContext *s);
...@@ -478,7 +480,6 @@ void MPV_common_init_mmx(MpegEncContext *s); ...@@ -478,7 +480,6 @@ void MPV_common_init_mmx(MpegEncContext *s);
#ifdef ARCH_ALPHA #ifdef ARCH_ALPHA
void MPV_common_init_axp(MpegEncContext *s); void MPV_common_init_axp(MpegEncContext *s);
#endif #endif
extern int (*dct_quantize)(MpegEncContext *s, DCTELEM *block, int n, int qscale, int *overflow);
extern void (*draw_edges)(UINT8 *buf, int wrap, int width, int height, int w); extern void (*draw_edges)(UINT8 *buf, int wrap, int width, int height, int w);
void ff_conceal_past_errors(MpegEncContext *s, int conceal_all); void ff_conceal_past_errors(MpegEncContext *s, int conceal_all);
void ff_copy_bits(PutBitContext *pb, UINT8 *src, int length); void ff_copy_bits(PutBitContext *pb, UINT8 *src, int length);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment