📄 xvid.c
字号:
quant_mpeg_inter = quant_mpeg_inter_xmm;
dequant_h263_intra = dequant_h263_intra_xmm;
dequant_h263_inter = dequant_h263_inter_xmm;
/* Buffer transfer */
transfer_8to16sub2 = transfer_8to16sub2_xmm;
transfer_8to16sub2ro = transfer_8to16sub2ro_xmm;
/* Colorspace transformation */
yv12_to_yv12 = yv12_to_yv12_xmm;
yuyv_to_yv12 = yuyv_to_yv12_xmm;
uyvy_to_yv12 = uyvy_to_yv12_xmm;
/* ME functions */
sad16 = sad16_xmm;
sad8 = sad8_xmm;
sad16bi = sad16bi_xmm;
sad8bi = sad8bi_xmm;
dev16 = dev16_xmm;
sad16v = sad16v_xmm;
}
if ((cpu_flags & XVID_CPU_3DNOW)) {
/* Interpolation */
interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_3dn;
interpolate8x8_halfpel_v = interpolate8x8_halfpel_v_3dn;
interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_3dn;
interpolate8x4_halfpel_h = interpolate8x4_halfpel_h_3dn;
interpolate8x4_halfpel_v = interpolate8x4_halfpel_v_3dn;
interpolate8x4_halfpel_hv = interpolate8x4_halfpel_hv_3dn;
}
if ((cpu_flags & XVID_CPU_3DNOWEXT)) {
/* Buffer transfer */
transfer_8to16copy = transfer_8to16copy_3dne;
transfer_16to8copy = transfer_16to8copy_3dne;
transfer_8to16sub = transfer_8to16sub_3dne;
transfer_8to16subro = transfer_8to16subro_3dne;
transfer_16to8add = transfer_16to8add_3dne;
transfer8x8_copy = transfer8x8_copy_3dne;
transfer8x4_copy = transfer8x4_copy_3dne;
if ((cpu_flags & XVID_CPU_MMXEXT)) {
/* Inverse DCT */
idct = idct_3dne;
/* Buffer transfer */
transfer_8to16sub2 = transfer_8to16sub2_3dne;
/* Interpolation */
interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_3dne;
interpolate8x8_halfpel_v = interpolate8x8_halfpel_v_3dne;
interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_3dne;
interpolate8x4_halfpel_h = interpolate8x4_halfpel_h_3dne;
interpolate8x4_halfpel_v = interpolate8x4_halfpel_v_3dne;
interpolate8x4_halfpel_hv = interpolate8x4_halfpel_hv_3dne;
/* Quantization */
quant_h263_intra = quant_h263_intra_3dne; /* cmov only */
quant_h263_inter = quant_h263_inter_3dne;
dequant_mpeg_intra = dequant_mpeg_intra_3dne; /* cmov only */
dequant_mpeg_inter = dequant_mpeg_inter_3dne;
dequant_h263_intra = dequant_h263_intra_3dne;
dequant_h263_inter = dequant_h263_inter_3dne;
/* ME functions */
calc_cbp = calc_cbp_3dne;
sad16 = sad16_3dne;
sad8 = sad8_3dne;
sad16bi = sad16bi_3dne;
sad8bi = sad8bi_3dne;
dev16 = dev16_3dne;
}
}
if ((cpu_flags & XVID_CPU_SSE2)) {
calc_cbp = calc_cbp_sse2;
/* Quantization */
quant_h263_intra = quant_h263_intra_sse2;
quant_h263_inter = quant_h263_inter_sse2;
dequant_h263_intra = dequant_h263_intra_sse2;
dequant_h263_inter = dequant_h263_inter_sse2;
/* SAD operators */
sad16 = sad16_sse2;
dev16 = dev16_sse2;
/* DCT operators */
fdct = fdct_sse2_skal;
/* idct = idct_sse2_skal; */ /* Is now IEEE1180 and Walken compliant. Disabled until fully tested. */
/* postprocessing */
image_brightness = image_brightness_sse2;
}
#if 0 // TODO: test...
if ((cpu_flags & XVID_CPU_SSE3)) {
/* SAD operators */
sad16 = sad16_sse3;
dev16 = dev16_sse3;
}
#endif
#endif /* ARCH_IS_IA32 */
#if defined(ARCH_IS_IA64)
if ((cpu_flags & XVID_CPU_ASM)) { /* use assembler routines? */
idct_ia64_init();
fdct = fdct_ia64;
idct = idct_ia64; /*not yet working, crashes */
interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_ia64;
interpolate8x8_halfpel_v = interpolate8x8_halfpel_v_ia64;
interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_ia64;
sad16 = sad16_ia64;
sad16bi = sad16bi_ia64;
sad8 = sad8_ia64;
dev16 = dev16_ia64;
/* Halfpel8_Refine = Halfpel8_Refine_ia64; */
quant_h263_intra = quant_h263_intra_ia64;
quant_h263_inter = quant_h263_inter_ia64;
dequant_h263_intra = dequant_h263_intra_ia64;
dequant_h263_inter = dequant_h263_inter_ia64;
transfer_8to16copy = transfer_8to16copy_ia64;
transfer_16to8copy = transfer_16to8copy_ia64;
transfer_8to16sub = transfer_8to16sub_ia64;
transfer_8to16sub2 = transfer_8to16sub2_ia64;
transfer_16to8add = transfer_16to8add_ia64;
transfer8x8_copy = transfer8x8_copy_ia64;
}
#endif
#if defined(ARCH_IS_PPC)
if ((cpu_flags & XVID_CPU_ALTIVEC)) {
/* sad operators */
sad16 = sad16_altivec_c;
sad16bi = sad16bi_altivec_c;
sad8 = sad8_altivec_c;
dev16 = dev16_altivec_c;
sse8_16bit = sse8_16bit_altivec_c;
/* mem transfer */
transfer_8to16copy = transfer_8to16copy_altivec_c;
transfer_16to8copy = transfer_16to8copy_altivec_c;
transfer_8to16sub = transfer_8to16sub_altivec_c;
transfer_8to16subro = transfer_8to16subro_altivec_c;
transfer_8to16sub2 = transfer_8to16sub2_altivec_c;
transfer_16to8add = transfer_16to8add_altivec_c;
transfer8x8_copy = transfer8x8_copy_altivec_c;
/* Inverse DCT */
idct = idct_altivec_c;
/* Interpolation */
interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_altivec_c;
interpolate8x8_halfpel_v = interpolate8x8_halfpel_v_altivec_c;
interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_altivec_c;
interpolate8x8_avg2 = interpolate8x8_avg2_altivec_c;
interpolate8x8_avg4 = interpolate8x8_avg4_altivec_c;
interpolate8x8_halfpel_add = interpolate8x8_halfpel_add_altivec_c;
interpolate8x8_halfpel_h_add = interpolate8x8_halfpel_h_add_altivec_c;
interpolate8x8_halfpel_v_add = interpolate8x8_halfpel_v_add_altivec_c;
interpolate8x8_halfpel_hv_add = interpolate8x8_halfpel_hv_add_altivec_c;
/* Colorspace conversion */
bgra_to_yv12 = bgra_to_yv12_altivec_c;
abgr_to_yv12 = abgr_to_yv12_altivec_c;
rgba_to_yv12 = rgba_to_yv12_altivec_c;
argb_to_yv12 = argb_to_yv12_altivec_c;
yuyv_to_yv12 = yuyv_to_yv12_altivec_c;
uyvy_to_yv12 = uyvy_to_yv12_altivec_c;
yv12_to_yuyv = yv12_to_yuyv_altivec_c;
yv12_to_uyvy = yv12_to_uyvy_altivec_c;
/* Quantization */
quant_h263_intra = quant_h263_intra_altivec_c;
quant_h263_inter = quant_h263_inter_altivec_c;
dequant_h263_intra = dequant_h263_intra_altivec_c;
dequant_h263_inter = dequant_h263_inter_altivec_c;
dequant_mpeg_intra = dequant_mpeg_intra_altivec_c;
dequant_mpeg_inter = dequant_mpeg_inter_altivec_c;
/* Qpel stuff */
xvid_QP_Funcs = &xvid_QP_Funcs_Altivec_C;
xvid_QP_Add_Funcs = &xvid_QP_Add_Funcs_Altivec_C;
}
#endif
#if defined(ARCH_IS_X86_64)
/* For now, only XVID_CPU_ASM is looked for, so user can still
* disable asm usage the usual way. When Intel EMT64 cpus will
* be out, maybe we'll have to check more precisely what cpu
* features there really are. */
if (cpu_flags & XVID_CPU_ASM) {
/* SIMD state flusher */
emms = emms_mmx;
/* DCT operators */
fdct = fdct_skal_x86_64;
idct = idct_x86_64;
/* SAD operators */
sad16 = sad16_x86_64;
sad8 = sad8_x86_64;
sad16bi = sad16bi_x86_64;
sad8bi = sad8bi_x86_64;
dev16 = dev16_x86_64;
sad16v = sad16v_x86_64;
sse8_16bit = sse8_16bit_x86_64;
sse8_8bit = sse8_8bit_x86_64;
/* Interpolation operators */
interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_x86_64;
interpolate8x8_halfpel_v = interpolate8x8_halfpel_v_x86_64;
interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_x86_64;
interpolate8x8_halfpel_add = interpolate8x8_halfpel_add_x86_64;
interpolate8x8_halfpel_h_add = interpolate8x8_halfpel_h_add_x86_64;
interpolate8x8_halfpel_v_add = interpolate8x8_halfpel_v_add_x86_64;
interpolate8x8_halfpel_hv_add = interpolate8x8_halfpel_hv_add_x86_64;
interpolate8x8_6tap_lowpass_h = interpolate8x8_6tap_lowpass_h_x86_64;
interpolate8x8_6tap_lowpass_v = interpolate8x8_6tap_lowpass_v_x86_64;
interpolate8x8_avg2 = interpolate8x8_avg2_x86_64;
interpolate8x8_avg4 = interpolate8x8_avg4_x86_64;
/* Quantization related functions */
quant_h263_intra = quant_h263_intra_x86_64;
quant_h263_inter = quant_h263_inter_x86_64;
dequant_h263_intra = dequant_h263_intra_x86_64;
dequant_h263_inter = dequant_h263_inter_x86_64;
/*quant_mpeg_intra = quant_mpeg_intra_x86_64; fix me! */
quant_mpeg_inter = quant_mpeg_inter_x86_64;
dequant_mpeg_intra = dequant_mpeg_intra_x86_64;
dequant_mpeg_inter = dequant_mpeg_inter_x86_64;
/* Block related functions */
transfer_8to16copy = transfer_8to16copy_x86_64;
transfer_16to8copy = transfer_16to8copy_x86_64;
transfer_8to16sub = transfer_8to16sub_x86_64;
transfer_8to16subro = transfer_8to16subro_x86_64;
transfer_8to16sub2 = transfer_8to16sub2_x86_64;
transfer_8to16sub2ro= transfer_8to16sub2ro_x86_64;
transfer_16to8add = transfer_16to8add_x86_64;
transfer8x8_copy = transfer8x8_copy_x86_64;
/* Qpel stuff */
xvid_QP_Funcs = &xvid_QP_Funcs_x86_64;
xvid_QP_Add_Funcs = &xvid_QP_Add_Funcs_x86_64;
/* Interlacing Functions */
MBFieldTest = MBFieldTest_x86_64;
}
#endif
#if defined(_DEBUG)
xvid_debug = init->debug;
#endif
return(0);
}
static int
xvid_gbl_info(xvid_gbl_info_t * info)
{
if (XVID_VERSION_MAJOR(info->version) != 1) /* v1.x.x */
return XVID_ERR_VERSION;
info->actual_version = XVID_VERSION;
info->build = "xvid-1.2.0-dev";
info->cpu_flags = detect_cpu_flags();
info->num_threads = 0;
#if defined(WIN32)
{
DWORD dwProcessAffinityMask, dwSystemAffinityMask;
if (GetProcessAffinityMask(GetCurrentProcess(), &dwProcessAffinityMask, &dwSystemAffinityMask)) {
int i;
for(i=0; i<32; i++) {
if ((dwProcessAffinityMask & (1<<i)))
info->num_threads++;
}
}
}
#endif
return 0;
}
static int
xvid_gbl_convert(xvid_gbl_convert_t* convert)
{
int width;
int height;
int width2;
int height2;
IMAGE img;
if (XVID_VERSION_MAJOR(convert->version) != 1) /* v1.x.x */
return XVID_ERR_VERSION;
#if 0
const int flip1 = (convert->input.colorspace & XVID_CSP_VFLIP) ^ (convert->output.colorspace & XVID_CSP_VFLIP);
#endif
width = convert->width;
height = convert->height;
width2 = convert->width/2;
height2 = convert->height/2;
switch (convert->input.csp & ~XVID_CSP_VFLIP)
{
case XVID_CSP_YV12 :
img.y = convert->input.plane[0];
img.v = (uint8_t*)convert->input.plane[0] + convert->input.stride[0]*height;
img.u = (uint8_t*)convert->input.plane[0] + convert->input.stride[0]*height + (convert->input.stride[0]/2)*height2;
image_output(&img, width, height, width,
(uint8_t**)convert->output.plane, convert->output.stride,
convert->output.csp, convert->interlacing);
break;
default :
return XVID_ERR_FORMAT;
}
emms();
return 0;
}
/*****************************************************************************
* XviD Global Entry point
*
* Well this function initialize all internal function pointers according
* to the CPU features forced by the library client or autodetected (depending
* on the XVID_CPU_FORCE flag). It also initializes vlc coding tables and all
* image colorspace transformation tables.
*
****************************************************************************/
int
xvid_global(void *handle,
int opt,
void *param1,
void *param2)
{
switch(opt)
{
case XVID_GBL_INIT :
return xvid_gbl_init((xvid_gbl_init_t*)param1);
case XVID_GBL_INFO :
return xvid_gbl_info((xvid_gbl_info_t*)param1);
case XVID_GBL_CONVERT :
return xvid_gbl_convert((xvid_gbl_convert_t*)param1);
default :
return XVID_ERR_FAIL;
}
}
/*****************************************************************************
* XviD Native decoder entry point
*
* This function is just a wrapper to all the option cases.
*
* Returned values : XVID_ERR_FAIL when opt is invalid
* else returns the wrapped function result
*
****************************************************************************/
int
xvid_decore(void *handle,
int opt,
void *param1,
void *param2)
{
switch (opt) {
case XVID_DEC_CREATE:
return decoder_create((xvid_dec_create_t *) param1);
case XVID_DEC_DESTROY:
return decoder_destroy((DECODER *) handle);
case XVID_DEC_DECODE:
return decoder_decode((DECODER *) handle, (xvid_dec_frame_t *) param1, (xvid_dec_stats_t*) param2);
default:
return XVID_ERR_FAIL;
}
}
/*****************************************************************************
* XviD Native encoder entry point
*
* This function is just a wrapper to all the option cases.
*
* Returned values : XVID_ERR_FAIL when opt is invalid
* else returns the wrapped function result
*
****************************************************************************/
int
xvid_encore(void *handle,
int opt,
void *param1,
void *param2)
{
switch (opt) {
case XVID_ENC_ENCODE:
return enc_encode((Encoder *) handle,
(xvid_enc_frame_t *) param1,
(xvid_enc_stats_t *) param2);
case XVID_ENC_CREATE:
return enc_create((xvid_enc_create_t *) param1);
case XVID_ENC_DESTROY:
return enc_destroy((Encoder *) handle);
default:
return XVID_ERR_FAIL;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -