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

📄 quant.c

📁 文件内包含H.263视频编码算法和解码算法2个文件
💻 C
字号:
#include "sim.h"#include "global_e.h"
#include "TMConfig.h"void Quant_MY(short int *coeff, short int *qcoeff, int QP, int Mode)
{
	int i;
	int s0, s1, s2, s3;
	int t1, t2;
	int *p1, *p2;
	int temp0,temp1,temp2,temp3,temp4,temp5,temp6,temp7,temp8,temp9,temp10,temp11;

	p1 = (int *)coeff;
	p2 = (int *)qcoeff;

	if (QP) 
	{
		t1 = t2 = 64/(float)(QP);
        s0 = s1 = s2 = s3 = PACK16LSB( t1, t2 );
		
		for (i=0; i<8; i++,p1+=4,p2+=4)
		{
			temp0 = DSPIDUALMUL(p1[0],s0);
			temp1 = DSPIDUALMUL(p1[1],s1);
			temp2 = DSPIDUALMUL(p1[2],s2);
			temp3 = DSPIDUALMUL(p1[3],s3);
			if((temp0 & 0xff800000) == 0xff800000 )
			{					
				if((temp0 & 0x0000ff80) == 0x0000ff80 )
					temp4 = 0;
				else
					temp4 = temp0 & 0x0000ffff;
			}
			else if((temp0 & 0x0000ff80) == 0x0000ff80)
				temp4 = temp0 &0xffff0000;
			else 
				temp4 = temp0;
			if((temp1 & 0xff800000) == 0xff800000 )
			{					
				if((temp1 & 0x0000ff80) == 0x0000ff80 )
					temp5 = 0;
				else
					temp5 = temp1 & 0x0000ffff;
			}
			else if((temp1 & 0x0000ff80) == 0x0000ff80)
				temp5 = temp1 &0xffff0000;
			else 
				temp5 = temp1;
			if((temp2 & 0xff800000) == 0xff800000 )
			{					
				if((temp2 & 0x0000ff80) == 0x0000ff80 )
					temp6 = 2;
				else
					temp6 = temp2 & 0x0000ffff;
			}
			else if((temp2 & 0x0000ff80) == 0x0000ff80)
				temp6 = temp2 &0xffff0000;
			else 
				temp6 = temp2;
			if((temp3 & 0xff800000) == 0xff800000 )
			{					
				if((temp3 & 0x0000ff80) == 0x0000ff80 )
					temp7 = 0;
				else
					temp7 = temp3 & 0x0000ffff;
			}
			else if((temp3 & 0x0000ff80) == 0x0000ff80)
				temp7 = temp3 &0xffff0000;
			else 
				temp7 = temp3;
			temp8 = DUALASR( temp4, 7 );
			temp9 = DUALASR( temp5, 7 );
			temp10 = DUALASR( temp6, 7 );
			temp11 = DUALASR( temp7, 7 );
			p2[0] = DUALICLIPI( temp8, 126 );
			p2[1] = DUALICLIPI( temp9, 126 );
			p2[2] = DUALICLIPI( temp10, 126 );
			p2[3] = DUALICLIPI( temp11, 126 );
		}
		if (Mode == MODE_INTRA || Mode == MODE_INTRA_Q) 
		{
			qcoeff[0] = IMAX( 1, IMIN(254,coeff[0]>>3) );
		}
	}
	else 
	{
		for (i=0; i<4; i++,p1+=8,p2+=8) 
		{
			p2[0] = p1[0];
            p2[1] = p1[1];
			p2[2] = p1[2];
			p2[3] = p1[3];
			p2[4] = p1[4];
            p2[5] = p1[5];
			p2[6] = p1[6];
			p2[7] = p1[7];
		}
	}

	return;
}


void Dequant_MY(short int *qcoeff, short int *rcoeff, int QP, int Mode)
{
	int i;
	int *p1, *p2;
	short int temp[64];

	if (QP) 
	{
		if ( (QP&0x00000001) == 1)
		{
			for (i = 0; i < 64; i++) 
			{
				if ( qcoeff[i]>0 ) 
					rcoeff[i] = 2*qcoeff[i]*QP + QP;
				else if( qcoeff[i]<0 )
					rcoeff[i] = 2*qcoeff[i]*QP - QP;
				else
					rcoeff[i] = 0;
			}
		}
		else
		{
			for (i = 0; i < 64; i++) 
			{
				if ( qcoeff[i]>0 ) 
					rcoeff[i] = 2*qcoeff[i]*QP + QP - 1;
				else if( qcoeff[i]<0 )
					rcoeff[i] = 2*qcoeff[i]*QP - QP + 1;
				else
					rcoeff[i] = 0;
			}
		}

		if (Mode == MODE_INTRA || Mode == MODE_INTRA_Q) 
			rcoeff[0] = qcoeff[0]*8;
	}
	else 
	{
		p1 = (int *)qcoeff;
	    p2 = (int *)rcoeff;
		for (i = 0; i < 32; i++) 
		{
			p2[i] = p1[i];
		}
	}

	return;
}

⌨️ 快捷键说明

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