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

📄 codec.c

📁 这是一个压缩解压包,用C语言进行编程的,里面有详细的源代码.
💻 C
📖 第 1 页 / 共 3 页
字号:
		frame.motion |= XVID_ME_CHROMA_PVOP + XVID_ME_CHROMA_BVOP;	if (quality_preset->turbo) 		frame.motion |= XVID_ME_FASTREFINE16 | XVID_ME_FASTREFINE8 | 						XVID_ME_SKIP_DELTASEARCH | XVID_ME_FAST_MODEINTERPOLATE | 						XVID_ME_BFRAME_EARLYSTOP;	frame.motion |= pmvfast_presets[quality_preset->motion_search];	if (quality_preset->vhq_bframe) frame.vop_flags |= XVID_VOP_RD_BVOP;	switch (quality_preset->vhq_mode)	{	case VHQ_MODE_DECISION :		frame.vop_flags |= XVID_VOP_MODEDECISION_RD;		break;	case VHQ_LIMITED_SEARCH :		frame.vop_flags |= XVID_VOP_MODEDECISION_RD;		frame.motion |= XVID_ME_HALFPELREFINE16_RD;		frame.motion |= XVID_ME_QUARTERPELREFINE16_RD;		break;	case VHQ_MEDIUM_SEARCH :		frame.vop_flags |= XVID_VOP_MODEDECISION_RD;		frame.motion |= XVID_ME_HALFPELREFINE16_RD;		frame.motion |= XVID_ME_HALFPELREFINE8_RD;		frame.motion |= XVID_ME_QUARTERPELREFINE16_RD;		frame.motion |= XVID_ME_QUARTERPELREFINE8_RD;		frame.motion |= XVID_ME_CHECKPREDICTION_RD;		break;	case VHQ_WIDE_SEARCH :		frame.vop_flags |= XVID_VOP_MODEDECISION_RD;		frame.motion |= XVID_ME_HALFPELREFINE16_RD;		frame.motion |= XVID_ME_HALFPELREFINE8_RD;		frame.motion |= XVID_ME_QUARTERPELREFINE16_RD;		frame.motion |= XVID_ME_QUARTERPELREFINE8_RD;		frame.motion |= XVID_ME_CHECKPREDICTION_RD;		frame.motion |= XVID_ME_EXTSEARCH_RD;		break;	default :		break;	}	frame.input.plane[0] = icc->lpInput;	frame.input.stride[0] = CALC_BI_STRIDE(icc->lpbiInput->biWidth, icc->lpbiInput->biBitCount);	if ((frame.input.csp = get_colorspace(inhdr)) == XVID_CSP_NULL)		return ICERR_BADFORMAT;	if (frame.input.csp == XVID_CSP_I420 || frame.input.csp == XVID_CSP_YV12) {		frame.input.stride[0] = (4 * icc->lpbiInput->biWidth + 3) / 4;		frame.input.stride[1] = frame.input.stride[2] = frame.input.stride[0] / 2 ;	}	frame.bitstream = icc->lpOutput;	frame.length = icc->lpbiOutput->biSizeImage;	frame.quant = 0;	if (codec->config.mode == RC_MODE_NULL) {		outhdr->biSizeImage = 0;		*icc->lpdwFlags = AVIIF_KEYFRAME;		return ICERR_OK;	}	// force keyframe spacing in 2-pass 1st pass	if (quality_preset->motion_search == 0)		frame.type = XVID_TYPE_IVOP;	/* frame-based stuff */	apply_zone_modifiers(&frame, &codec->config, codec->framenum);	/* call encore */	memset(&stats, 0, sizeof(stats));	stats.version = XVID_VERSION;	length = codec->xvid_encore_func(codec->ehandle, XVID_ENC_ENCODE, &frame, &stats);	switch (length) 	{	case XVID_ERR_FAIL :			return ICERR_ERROR;	case XVID_ERR_MEMORY :		return ICERR_MEMORY;	case XVID_ERR_FORMAT :		return ICERR_BADFORMAT;		case XVID_ERR_VERSION :		return ICERR_UNSUPPORTED;	}	if (codec->config.display_status && stats.type>0) {		status_update(&codec->status, stats.type, stats.length, stats.quant);	}	DPRINTF("{type=%i len=%i} length=%i", stats.type, stats.length, length);	if (length == 0)	/* no encoder output */	{		*icc->lpdwFlags = 0;		((char*)icc->lpOutput)[0] = 0x7f;	/* virtual dub skip frame */		outhdr->biSizeImage = 1;			}else{		if (frame.out_flags & XVID_KEYFRAME)		{			codec->keyspacing = 0;			*icc->lpdwFlags = AVIIF_KEYFRAME;		}		else		{			 *icc->lpdwFlags = 0;		}		outhdr->biSizeImage = length;		if (codec->config.mode == RC_MODE_2PASS1 && codec->config.discard1pass)		{			outhdr->biSizeImage = 0;		}	}	codec->framenum++;	codec->keyspacing++;	return ICERR_OK;}/* decompressor */LRESULT decompress_query(CODEC * codec, BITMAPINFO *lpbiInput, BITMAPINFO *lpbiOutput){	BITMAPINFOHEADER * inhdr = &lpbiInput->bmiHeader;	BITMAPINFOHEADER * outhdr = &lpbiOutput->bmiHeader;	if (lpbiInput == NULL) 	{		return ICERR_ERROR;	}	if (inhdr->biCompression != FOURCC_XVID && inhdr->biCompression != FOURCC_DIVX && inhdr->biCompression != FOURCC_DX50 && get_colorspace(inhdr) == XVID_CSP_NULL)	{		return ICERR_BADFORMAT;	}	if (lpbiOutput == NULL) 	{		return ICERR_OK;	}	if (inhdr->biWidth != outhdr->biWidth ||		inhdr->biHeight != outhdr->biHeight ||		get_colorspace(outhdr) == XVID_CSP_NULL) 	{		return ICERR_BADFORMAT;	}	return ICERR_OK;}LRESULT decompress_get_format(CODEC * codec, BITMAPINFO * lpbiInput, BITMAPINFO * lpbiOutput){	BITMAPINFOHEADER * inhdr = &lpbiInput->bmiHeader;	BITMAPINFOHEADER * outhdr = &lpbiOutput->bmiHeader;	LRESULT result;	if (lpbiOutput == NULL) 	{		return sizeof(BITMAPINFOHEADER);	}	/* --- yv12 --- */	if (get_colorspace(inhdr) != XVID_CSP_NULL) {		memcpy(outhdr, inhdr, sizeof(BITMAPINFOHEADER));		/* XXX: should we set outhdr->biSize ?? */		return ICERR_OK;	}	/* --- yv12 --- */	result = decompress_query(codec, lpbiInput, lpbiOutput);	if (result != ICERR_OK) 	{		return result;	}	outhdr->biSize = sizeof(BITMAPINFOHEADER);	outhdr->biWidth = inhdr->biWidth;	outhdr->biHeight = inhdr->biHeight;	outhdr->biPlanes = 1;	outhdr->biBitCount = 24;	outhdr->biCompression = BI_RGB;	/* sonic foundry vegas video v3 only supports BI_RGB */	outhdr->biSizeImage = outhdr->biHeight * CALC_BI_STRIDE(outhdr->biWidth, outhdr->biBitCount);	outhdr->biXPelsPerMeter = 0;	outhdr->biYPelsPerMeter = 0;	outhdr->biClrUsed = 0;	outhdr->biClrImportant = 0;	return ICERR_OK;}#define REG_GET_N(X, Y, Z) \{ \	DWORD size = sizeof(int); \	if (RegQueryValueEx(hKey, X, 0, 0, (LPBYTE)&Y, &size) != ERROR_SUCCESS) { \		Y=Z; \	} \}while(0)LRESULT decompress_begin(CODEC * codec, BITMAPINFO * lpbiInput, BITMAPINFO * lpbiOutput){	xvid_gbl_init_t init;	xvid_dec_create_t create;	HKEY hKey;	if (init_dll(codec) != 0) return ICERR_ERROR;	memset(&init, 0, sizeof(init));	init.version = XVID_VERSION;	init.cpu_flags = codec->config.cpu;  init.debug = codec->config.debug;	codec->xvid_global_func(0, XVID_GBL_INIT, &init, NULL);	memset(&create, 0, sizeof(create));	create.version = XVID_VERSION;	create.width = lpbiInput->bmiHeader.biWidth;	create.height = lpbiInput->bmiHeader.biHeight;	switch(codec->xvid_decore_func(0, XVID_DEC_CREATE, &create, NULL)) 	{	case XVID_ERR_FAIL :		return ICERR_ERROR;	case XVID_ERR_MEMORY :		return ICERR_MEMORY;	case XVID_ERR_FORMAT :		return ICERR_BADFORMAT;	case XVID_ERR_VERSION :		return ICERR_UNSUPPORTED;	}	codec->dhandle = create.handle;	RegOpenKeyEx(XVID_REG_KEY, XVID_REG_PARENT "\\" XVID_REG_CHILD, 0, KEY_READ, &hKey);	REG_GET_N("Brightness", pp_brightness, 0);	REG_GET_N("Deblock_Y",  pp_dy, 0)	REG_GET_N("Deblock_UV", pp_duv, 0)	REG_GET_N("Dering_Y",  pp_dry, 0)	REG_GET_N("Dering_UV", pp_druv, 0)	REG_GET_N("FilmEffect", pp_fe, 0)	RegCloseKey(hKey);	return ICERR_OK;}LRESULT decompress_end(CODEC * codec){	if (codec->m_hdll != NULL) {		if (codec->dhandle != NULL) {			codec->xvid_decore_func(codec->dhandle, XVID_DEC_DESTROY, NULL, NULL);			codec->dhandle = NULL;		}	}	return ICERR_OK;}LRESULT decompress(CODEC * codec, ICDECOMPRESS * icd){	xvid_dec_frame_t frame;		/* --- yv12 --- */		if (icd->lpbiInput->biCompression != FOURCC_XVID &&		 icd->lpbiInput->biCompression != FOURCC_DIVX &&		 icd->lpbiInput->biCompression != FOURCC_DX50)	{		xvid_gbl_convert_t convert;		DPRINTF("input=%c%c%c%c output=%c%c%c%c", 			icd->lpbiInput->biCompression&0xff,			(icd->lpbiInput->biCompression>>8)&0xff,			(icd->lpbiInput->biCompression>>16)&0xff,			(icd->lpbiInput->biCompression>>24)&0xff,			icd->lpbiOutput->biCompression&0xff,			(icd->lpbiOutput->biCompression>>8)&0xff,			(icd->lpbiOutput->biCompression>>16)&0xff,			(icd->lpbiOutput->biCompression>>24)&0xff);		memset(&convert, 0, sizeof(convert));		convert.version = XVID_VERSION;		convert.input.csp = get_colorspace(icd->lpbiInput);		convert.input.plane[0] = icd->lpInput;		convert.input.stride[0] = CALC_BI_STRIDE(icd->lpbiInput->biWidth, icd->lpbiInput->biBitCount);		if (convert.input.csp == XVID_CSP_I420 || convert.input.csp == XVID_CSP_YV12)			convert.input.stride[0] = (convert.input.stride[0]*2)/3;		convert.output.csp = get_colorspace(icd->lpbiOutput);		convert.output.plane[0] = icd->lpOutput;		convert.output.stride[0] = CALC_BI_STRIDE(icd->lpbiOutput->biWidth, icd->lpbiOutput->biBitCount);		if (convert.output.csp == XVID_CSP_I420 || convert.output.csp == XVID_CSP_YV12)			convert.output.stride[0] = (convert.output.stride[0]*2)/3;		convert.width = icd->lpbiInput->biWidth;		convert.height = icd->lpbiInput->biHeight;		convert.interlacing = 0;		if (convert.input.csp == XVID_CSP_NULL ||			convert.output.csp == XVID_CSP_NULL ||			codec->xvid_global_func(0, XVID_GBL_CONVERT, &convert, NULL) < 0)		{			 return ICERR_BADFORMAT;		}		return ICERR_OK;	}	/* --- yv12 --- */		memset(&frame, 0, sizeof(frame));	frame.version = XVID_VERSION;	frame.general = XVID_LOWDELAY;	/* force low_delay_default mode */	frame.bitstream = icd->lpInput;	frame.length = icd->lpbiInput->biSizeImage;		if (~((icd->dwFlags & ICDECOMPRESS_HURRYUP) | (icd->dwFlags & ICDECOMPRESS_UPDATE) | (icd->dwFlags & ICDECOMPRESS_PREROLL)))	{		if ((frame.output.csp = get_colorspace(icd->lpbiOutput)) == XVID_CSP_NULL) 		{			return ICERR_BADFORMAT;		}		frame.output.plane[0] = icd->lpOutput;		frame.output.stride[0] = CALC_BI_STRIDE(icd->lpbiOutput->biWidth, icd->lpbiOutput->biBitCount);		if (frame.output.csp == XVID_CSP_I420 || frame.output.csp == XVID_CSP_YV12)			frame.output.stride[0] = CALC_BI_STRIDE(icd->lpbiOutput->biWidth, 8);	}	else	{		frame.output.csp = XVID_CSP_NULL;	}	if (pp_dy)frame.general |= XVID_DEBLOCKY;	if (pp_duv) frame.general |= XVID_DEBLOCKUV;	if (pp_dry) frame.general |= XVID_DERINGY; 	if (pp_druv) frame.general |= XVID_DERINGUV; 	if (pp_fe) frame.general |= XVID_FILMEFFECT;	frame.brightness = pp_brightness;	switch (codec->xvid_decore_func(codec->dhandle, XVID_DEC_DECODE, &frame, NULL)) 	{	case XVID_ERR_FAIL :			return ICERR_ERROR;	case XVID_ERR_MEMORY :		return ICERR_MEMORY;	case XVID_ERR_FORMAT :		return ICERR_BADFORMAT;		case XVID_ERR_VERSION :		return ICERR_UNSUPPORTED;	}	return ICERR_OK;}

⌨️ 快捷键说明

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