⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xvid.c

📁 xvid解码的精简版本.非常好的版本,节省了分离xvid源代码的过程
💻 C
字号:
/***************************************************************************** * *  XVID MPEG-4 VIDEO CODEC *  - Native API implementation  - * *  Copyright(C) 2001-2004 Peter Ross <pross@xvid.org> * *  This program is free software ; you can redistribute it and/or modify *  it under the terms of the GNU General Public License as published by *  the Free Software Foundation ; either version 2 of the License, or *  (at your option) any later version. * *  This program is distributed in the hope that it will be useful, *  but WITHOUT ANY WARRANTY ; without even the implied warranty of *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the *  GNU General Public License for more details. * *  You should have received a copy of the GNU General Public License *  along with this program ; if not, write to the Free Software *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA * * $Id: xvid.c,v 1.65.2.1 2005/11/22 10:44:09 suxen_drol Exp $ * ****************************************************************************/#include <stdio.h>#include <stdlib.h>#include <string.h>#include <time.h>#include "xvid.h"#include "decoder.h"#include "encoder.h"#include "idct.h"#include "colorspace.h"#include "interpolate8x8.h"#include "mem_transfer.h"#include "quant.h"#include "mbcoding.h"#include "qpel.h"#include "postprocessing.h"#if defined(_DEBUG)unsigned int xvid_debug = 0; /* xvid debug mask */#endif/* detect cpu flags  */static unsigned intdetect_cpu_flags(void){	/* enable native assembly optimizations by default */	unsigned int cpu_flags = XVID_CPU_ASM;	return cpu_flags;}/***************************************************************************** * XviD Init 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. * * Returned value : XVID_ERR_OK *                  + API_VERSION in the input XVID_INIT_PARAM structure *                  + core build  "   "    "       "               " * ****************************************************************************/staticint xvid_gbl_init(xvid_gbl_init_t * init){	unsigned int cpu_flags;	if (XVID_VERSION_MAJOR(init->version) != 1) /* v1.x.x */		return XVID_ERR_VERSION;	cpu_flags = (init->cpu_flags & XVID_CPU_FORCE) ? init->cpu_flags : detect_cpu_flags();	/* Initialize the function pointers *///	idct_int32_init();	init_vlc_tables();	/* Fixed Point Forward/Inverse DCT transformations */	/* Only needed on PPC Altivec archs */	/* Restore FPU context : emms_c is a nop functions */		/* Qpel stuff */	xvid_QP_Funcs = &xvid_QP_Funcs_C;	xvid_QP_Add_Funcs = &xvid_QP_Add_Funcs_C;	xvid_Init_QP();	/* Quantization functions */	dequant_h263_intra = dequant_h263_intra_c;	dequant_h263_inter = dequant_h263_inter_c;	dequant_mpeg_intra = dequant_mpeg_intra_c;	dequant_mpeg_inter = dequant_mpeg_inter_c;	/* Block transfer related functions *///	transfer_8to16copy = transfer_8to16copy_c;	transfer_16to8copy = transfer_16to8copy_c;	transfer_16to8add  = transfer_16to8add_c;	transfer8x8_copy   = transfer8x8_copy_c;	transfer8x4_copy   = transfer8x4_copy_c;	/* Interlacing functions */	/* Image interpolation related functions */	interpolate8x8_halfpel_h  = interpolate8x8_halfpel_h_c;	interpolate8x8_halfpel_v  = interpolate8x8_halfpel_v_c;	interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_c;	interpolate8x4_halfpel_h  = interpolate8x4_halfpel_h_c;	interpolate8x4_halfpel_v  = interpolate8x4_halfpel_v_c;	interpolate8x4_halfpel_hv = interpolate8x4_halfpel_hv_c;	interpolate8x8_halfpel_add = interpolate8x8_halfpel_add_c;	interpolate8x8_halfpel_h_add = interpolate8x8_halfpel_h_add_c;	interpolate8x8_halfpel_v_add = interpolate8x8_halfpel_v_add_c;	interpolate8x8_halfpel_hv_add = interpolate8x8_halfpel_hv_add_c;	interpolate16x16_lowpass_h = interpolate16x16_lowpass_h_c;	interpolate16x16_lowpass_v = interpolate16x16_lowpass_v_c;	interpolate16x16_lowpass_hv = interpolate16x16_lowpass_hv_c;	interpolate8x8_lowpass_h = interpolate8x8_lowpass_h_c;	interpolate8x8_lowpass_v = interpolate8x8_lowpass_v_c;	interpolate8x8_lowpass_hv = interpolate8x8_lowpass_hv_c;	interpolate8x8_6tap_lowpass_h = interpolate8x8_6tap_lowpass_h_c;	interpolate8x8_6tap_lowpass_v = interpolate8x8_6tap_lowpass_v_c;	interpolate8x8_avg2 = interpolate8x8_avg2_c;	interpolate8x8_avg4 = interpolate8x8_avg4_c;	/* postprocessing */	image_brightness = image_brightness_c;	/* Initialize internal colorspace transformation tables */	colorspace_init();	/* All colorspace transformation functions User Format->YV12 */	yv12_to_yv12    = yv12_to_yv12_c;	rgb555_to_yv12  = rgb555_to_yv12_c;	rgb565_to_yv12  = rgb565_to_yv12_c;	bgr_to_yv12     = bgr_to_yv12_c;	bgra_to_yv12    = bgra_to_yv12_c;	abgr_to_yv12    = abgr_to_yv12_c;	rgba_to_yv12    = rgba_to_yv12_c;	argb_to_yv12    = argb_to_yv12_c;	yuyv_to_yv12    = yuyv_to_yv12_c;	uyvy_to_yv12    = uyvy_to_yv12_c;	rgb555i_to_yv12 = rgb555i_to_yv12_c;	rgb565i_to_yv12 = rgb565i_to_yv12_c;	bgri_to_yv12    = bgri_to_yv12_c;	bgrai_to_yv12   = bgrai_to_yv12_c;	abgri_to_yv12   = abgri_to_yv12_c;	rgbai_to_yv12   = rgbai_to_yv12_c;	argbi_to_yv12   = argbi_to_yv12_c;	yuyvi_to_yv12   = yuyvi_to_yv12_c;	uyvyi_to_yv12   = uyvyi_to_yv12_c;	/* All colorspace transformation functions YV12->User format */	yv12_to_rgb555  = yv12_to_rgb555_c;	yv12_to_rgb565  = yv12_to_rgb565_c;	yv12_to_bgr     = yv12_to_bgr_c;	yv12_to_bgra    = yv12_to_bgra_c;	yv12_to_abgr    = yv12_to_abgr_c;	yv12_to_rgba    = yv12_to_rgba_c;	yv12_to_argb    = yv12_to_argb_c;	yv12_to_yuyv    = yv12_to_yuyv_c;	yv12_to_uyvy    = yv12_to_uyvy_c;	yv12_to_rgb555i = yv12_to_rgb555i_c;	yv12_to_rgb565i = yv12_to_rgb565i_c;	yv12_to_bgri    = yv12_to_bgri_c;	yv12_to_bgrai   = yv12_to_bgrai_c;	yv12_to_abgri   = yv12_to_abgri_c;	yv12_to_rgbai   = yv12_to_rgbai_c;	yv12_to_argbi   = yv12_to_argbi_c;	yv12_to_yuyvi   = yv12_to_yuyvi_c;	yv12_to_uyvyi   = yv12_to_uyvyi_c;   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.1.0";	info->cpu_flags = detect_cpu_flags();#if defined(_SMP) && defined(WIN32)	info->num_threads = pthread_num_processors_np();;#else	info->num_threads = 0;#endif	return 0;}static intxvid_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;	}	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. * ****************************************************************************/intxvid_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 * ****************************************************************************/intxvid_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;	}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -