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

📄 blit_soft.c

📁 大名鼎鼎的CE下播放软件,TCPPMP的源代码!!!2410下可以流畅的解QVGA的H264,MPEG4等格式.
💻 C
📖 第 1 页 / 共 5 页
字号:
	Height >>= This->SrcUVY2;
	SrcPitch >>= This->SrcUVPitch2;
	DstPitch >>= This->DstUVPitch2;

	Blit_PYUV_PYUV_2Plane(SrcPtr[1],DstPtr[1],Width,Height,SrcPitch,DstPitch,This->RScaleX,This->RScaleY);
	Blit_PYUV_PYUV_2Plane(SrcPtr[2],DstPtr[2],Width,Height,SrcPitch,DstPitch,This->RScaleX,This->RScaleY);
}

#if defined(_M_IX86) || !defined(CONFIG_DYNCODE) || defined(BLITTEST)

// !SwapXY
// !DstLeftRight
// SrcType == 12
// DstType == 12
// RScaleX == 16 && RScaleY == 16
// SrcUVX2 == DstUVX2

static void STDCALL Blit_PYUV_PYUV(blit_soft* This, uint8_t** DstPtr,uint8_t** SrcPtr,int DstPitch,int SrcPitch,
	               int Width,int Height,uintptr_t Src2SrcLast) 
{
	uint8_t* Src[3];
	uint8_t* Dst[3];

	uint8_t* LookUp = This->LookUp_Data;
	int UVY = 1 << This->DstUVY2;
	int UVDup = 1;
	int SrcPitchUV = SrcPitch >> This->SrcUVPitch2;
	int DstPitchUV = DstPitch >> This->DstUVPitch2;
	int WidthUV = Width >> This->SrcUVX2;
	int YAdd = This->FX.Brightness;
	int x,y,i;

	for (i=0;i<3;++i)
	{
		Src[i] = SrcPtr[i];
		Dst[i] = DstPtr[i];
	}

	// skip some UV lines?
	if (This->DstUVY2 > This->SrcUVY2)
		SrcPitchUV <<= This->DstUVY2 - This->SrcUVY2;
	else
		UVDup = 1 << (This->SrcUVY2 - This->DstUVY2);

	Height >>= This->DstUVY2;

	for (y=0;y<Height;++y)
	{
		for (i=0;i<UVY;++i)
		{
			if (LookUp)
			{
				uint8_t* s = Src[0];
				uint8_t* d = Dst[0];
				for (x=0;x<Width;++x,++s,++d)
					*d = LookUp[*s];
			}
			else
			if (YAdd)
			{
				uint8_t* s = Src[0];
				uint8_t* d = Dst[0];
				for (x=0;x<Width;++x,++s,++d)
				{
					int Y = *s + YAdd;
					Y = SAT(Y);
					*d = (uint8_t)Y;
				}
			}
			else
				memcpy(Dst[0],Src[0],Width);

			Src[0] += SrcPitch;
			Dst[0] += DstPitch;
		}

		for (i=0;i<UVDup;++i)
		{
			if (LookUp)
			{
				for (x=0;x<WidthUV;++x)
				{
					Dst[1][x] = LookUp[256+Src[1][x]];
					Dst[2][x] = LookUp[512+Src[2][x]];
				}
			}
			else
			{
				memcpy(Dst[1],Src[1],WidthUV);
				memcpy(Dst[2],Src[2],WidthUV);
			}

			Dst[1] += DstPitchUV;
			Dst[2] += DstPitchUV;
		}

		Src[1] += SrcPitchUV;
		Src[2] += SrcPitchUV;
	}
}

// !SwapXY
// !DstLeftRight
// SrcType == 10
// SrcUVX2 == 1
// DstType == 8		00000000rrrrrrrrggggggggbbbbbbbb

static void STDCALL Blit_PYUV_RGB32(blit_soft* This, uint8_t** DstPtr,uint8_t** SrcPtr,int DstPitch,int SrcPitch,
	                 int Width,int Height,uintptr_t Src2SrcLast) 
{
	int i,x,y;
	uint8_t* Src[3];
	uint8_t* Dst;
	int SrcStepX[16];
	int SrcStepY[16];
	int SrcUVY2 = This->SrcUVY2;
	int SrcUVPitch2 = This->SrcUVPitch2;

	int YAdd = This->FX.Brightness;
	int sy0;
	int sy=0;

	for (i=0;i<3;++i)
		Src[i] = SrcPtr[i];
	Dst = DstPtr[0];

	for (i=0;i<16;++i)
	{
		SrcStepX[i] = ((This->RScaleX * (i+1)) >> 4) - ((This->RScaleX * i) >> 4);
		SrcStepY[i] = ((This->RScaleY * (i+1)) >> 4) - ((This->RScaleY * i) >> 4);
	}

	for (y=0;y<Height;++y)
	{
		uint8_t* dx = Dst;
		int sx = 0;

		for (x=0;x<Width;++x)
		{
			int cR,cG,cB;
			int sx2 = sx>>1;

			cR = ((Src[0][sx]+YAdd-16)*0x2568						      + 0x3343*(Src[2][sx2]-128)) /0x2000;
			cG = ((Src[0][sx]+YAdd-16)*0x2568 - 0x0c92*(Src[1][sx2]-128)  - 0x1a1e*(Src[2][sx2]-128)) /0x2000;
			cB = ((Src[0][sx]+YAdd-16)*0x2568 + 0x40cf*(Src[1][sx2]-128))                             /0x2000;
			
			cR = SAT(cR);
			cG = SAT(cG);
			cB = SAT(cB);

			do
			{
				dx[0]=(uint8_t)cB;
				dx[1]=(uint8_t)cG;
				dx[2]=(uint8_t)cR;
				dx+=4;
			} while (SrcStepX[x&15]==0 && ++x<Width);

			sx += SrcStepX[x&15];
		}
		Dst += DstPitch;

		while (SrcStepY[y&15]==0 && ++y<Height)
		{
			memcpy(Dst,Dst-DstPitch,4*Width);
			Dst += DstPitch;
		}

		sy0 = sy;
		sy += SrcStepY[y&15];
		Src[0] += SrcPitch * (sy - sy0);
		Src[1] += (SrcPitch >> SrcUVPitch2) * ((sy >> SrcUVY2) - (sy0 >> SrcUVY2));
		Src[2] += (SrcPitch >> SrcUVPitch2) * ((sy >> SrcUVY2) - (sy0 >> SrcUVY2));
	}
}

// !SwapXY
// !DstLeftRight
// SrcType == 10
// SrcUVX2 == 1
// DstType == 6		rrrrrggggggbbbbb

static void STDCALL Blit_PYUV_RGB16(blit_soft* This, uint8_t** DstPtr,uint8_t** SrcPtr,int DstPitch,int SrcPitch,
	                 int Width,int Height,uintptr_t Src2SrcLast) 
{
	int i,x,y;
	uint8_t* Src[3];
	uint8_t* Dst;
	int SrcStepX[16];
	int SrcStepY[16];
	int SrcUVY2 = This->SrcUVY2;
	int SrcUVPitch2 = This->SrcUVPitch2;

	int YAdd = This->FX.Brightness;
	int sy0;
	int sy=0;

	for (i=0;i<3;++i)
		Src[i] = SrcPtr[i];
	Dst = DstPtr[0];

	for (i=0;i<16;++i)
	{
		SrcStepX[i] = ((This->RScaleX * (i+1)) >> 4) - ((This->RScaleX * i) >> 4);
		SrcStepY[i] = ((This->RScaleY * (i+1)) >> 4) - ((This->RScaleY * i) >> 4);
	}

	for (y=0;y<Height;++y)
	{
		uint16_t* dx = (uint16_t*)Dst;
		int sx = 0;

		for (x=0;x<Width;++x)
		{
			int cR,cG,cB;
			int sx2 = sx>>1;

			cR = ((Src[0][sx]+YAdd-16)*0x2568						      + 0x3343*(Src[2][sx2]-128)) /0x2000;
			cG = ((Src[0][sx]+YAdd-16)*0x2568 - 0x0c92*(Src[1][sx2]-128)  - 0x1a1e*(Src[2][sx2]-128)) /0x2000;
			cB = ((Src[0][sx]+YAdd-16)*0x2568 + 0x40cf*(Src[1][sx2]-128))                             /0x2000;
			
			cR = SAT(cR);
			cG = SAT(cG);
			cB = SAT(cB);

			do
			{
				*dx = (uint16_t)(((cR << 8)&0xF800)|((cG << 3)&0x07E0)|(cB >> 3));
				++dx;
			} while (SrcStepX[x&15]==0 && ++x<Width);

			sx += SrcStepX[x&15];
		}
		Dst += DstPitch;

		while (SrcStepY[y&15]==0 && ++y<Height)
		{
			memcpy(Dst,Dst-DstPitch,2*Width);
			Dst += DstPitch;
		}

		sy0 = sy;
		sy += SrcStepY[y&15];
		Src[0] += SrcPitch * (sy - sy0);
		Src[1] += (SrcPitch >> SrcUVPitch2) * ((sy >> SrcUVY2) - (sy0 >> SrcUVY2));
		Src[2] += (SrcPitch >> SrcUVPitch2) * ((sy >> SrcUVY2) - (sy0 >> SrcUVY2));
	}
}

static void STDCALL BlitUniversal(blit_soft* This, uint8_t** DstPtr,uint8_t** SrcPtr,int DstPitch,int SrcPitch,
	               int Width,int Height,uintptr_t Src2SrcLast) 
{
	//this will be very-very slow, only for compability and testing

	int i,j,x,y;

	uint8_t* Src[3];
	uint8_t* Dst[3];

	int SrcType = This->SrcType;
	int DstType = This->DstType;

	int DstMask[3],DstPos[3];
	int SrcMask[3],SrcPos[3];
	int DitherMask[3];

	uint8_t* PalLookUp = (uint8_t*)This->LookUp_Data;
	uint8_t* wp;
	int Flags = This->FX.Flags;
	bool_t Dither = (Flags & BLITFX_DITHER) != 0 && !(This->Dst.Flags & PF_FOURCC);
	bool_t PalDither = Dither && (This->Dst.Flags & PF_PALETTE);

	const rgb* SrcPalette = This->SrcPalette;

	int SrcStepX[16];
	int SrcStepY[16];
	int RScaleX = This->RScaleX;
	int RScaleY = This->RScaleY;

	int SrcUVPitch2 = This->SrcUVPitch2;
	int SrcUVX2 = This->SrcUVX2;
	int SrcUVY2 = This->SrcUVY2;
	int DstUVX2 = This->DstUVX2;
	int DstUVY2 = This->DstUVY2;
	int DstStepX = This->DstBPP;
	int DstStepX2 = This->DstBPP;
	int DstStepY = DstPitch << 3;
	int DstStepY2 = DstStepY >> This->DstUVPitch2;
	int dy = 0;
	int dy2 = 0;

	int cR,cG,cB;
	int Y,U,V;
	int sy0;
	int sy=0;
	int YAdd = This->FX.Brightness;

	uint32_t SrcInvert = 0;
	uint32_t DstInvert = 0;

	SrcMask[0] = This->Src.BitMask[0];
	SrcMask[1] = This->Src.BitMask[1];
	SrcMask[2] = This->Src.BitMask[2];

	DstMask[0] = This->Dst.BitMask[0];
	DstMask[1] = This->Dst.BitMask[1];
	DstMask[2] = This->Dst.BitMask[2];

	for (i=0;i<3;++i)
	{
		DitherMask[i] = Dither ? (1 << (8 - BitMaskSize(DstMask[i]))) - 1 : 0;
		SrcPos[i] = BitMaskPos(SrcMask[i]) + BitMaskSize(SrcMask[i]);
		DstPos[i] = BitMaskPos(DstMask[i]) + BitMaskSize(DstMask[i]);
		SrcMask[i] <<= 8;
		DstMask[i] <<= 8;
		Src[i] = SrcPtr[i];
		Dst[i] = DstPtr[i];
	}

	if (This->DstPalette)
	{
		DstPos[0] = 11;
		DstPos[1] = 7;
		DstPos[2] = 3; 
		DstMask[0] = 0xF0000;
		DstMask[1] = 0x0F000;
		DstMask[2] = 0x00F00;
	}

	for (j=0;j<16;++j)
	{
		SrcStepX[j] = ((RScaleX * (j+1)) >> 4) - ((RScaleX * j) >> 4);
		SrcStepY[j] = ((RScaleY * (j+1)) >> 4) - ((RScaleY * j) >> 4);
	}

	if (This->DstLeftRight)
	{	
		DstStepX = -DstStepX;
		DstStepX2 = -DstStepX2;
		if (This->DstBPP < 8)
			dy = 8 - This->DstBPP;
	}

	if (This->SwapXY)
	{
		SwapInt(&DstUVX2,&DstUVY2);
		SwapInt(&DstStepX,&DstStepY);
		SwapInt(&DstStepX2,&DstStepY2);
	}

	cR = (DitherMask[0] >> 1);
	cG = (DitherMask[1] >> 1);
	cB = (DitherMask[2] >> 1);
	Y=U=V=0;

	if (This->Src.Flags & PF_INVERTED)
		SrcInvert = (This->Src.BitCount>=32?0:(1 << This->Src.BitCount))-1;
	if (This->Dst.Flags & PF_INVERTED)
		DstInvert = (This->Dst.BitCount>=32?0:(1 << This->Dst.BitCount))-1;

	for (y=0;y<Height;++y)
	{
		int dx=dy;
		int dx2=dy2;
		int sx=0;

		for (x=0;x<Width;sx+=SrcStepX[x&15],++x,dx+=DstStepX)
		{
			uint8_t* q;
			const rgb* p;
			uint32_t v,w;

			switch (SrcType)
			{
			case 10: //Planar YUV->RGB
				cR += ((Src[0][sx]+YAdd-16)*0x2568						              + 0x3343*(Src[2][sx>>SrcUVX2]-128)) /0x2000;
				cG += ((Src[0][sx]+YAdd-16)*0x2568 - 0x0c92*(Src[1][sx>>SrcUVX2]-128)  - 0x1a1e*(Src[2][sx>>SrcUVX2]-128)) /0x2000;
				cB += ((Src[0][sx]+YAdd-16)*0x2568 + 0x40cf*(Src[1][sx>>SrcUVX2]-128))                                     /0x2000;

				cR=SAT(cR);
				cG=SAT(cG);
				cB=SAT(cB);
				break;
			case 11: //Packed YUV->RGB
				cR += ((Src[0][sx*2]+YAdd-16)*0x2568									  + 0x3343*(Src[2][4*(sx>>1)]-128)) /0x2000;
				cG += ((Src[0][sx*2]+YAdd-16)*0x2568 - 0x0c92*(Src[1][4*(sx>>1)]-128)  - 0x1a1e*(Src[2][4*(sx>>1)]-128)) /0x2000;
				cB += ((Src[0][sx*2]+YAdd-16)*0x2568 + 0x40cf*(Src[1][4*(sx>>1)]-128))                                   /0x2000;

				cR=SAT(cR);
				cG=SAT(cG);
				cB=SAT(cB);
				break;
			case 12: //Planar YUV->YUV
				Y += Src[0][sx];
				U += Src[1][sx>>SrcUVX2];
				V += Src[2][sx>>SrcUVX2];

				//Y=SAT(Y);
				//U=SAT(U);
				//V=SAT(V);
				break;
			case 13: //Packed YUV->YUV
				Y += Src[0][sx*2];
				U += Src[1][4*(sx>>1)];
				V += Src[2][4*(sx>>1)];

				//Y=SAT(Y);
				//U=SAT(U);
				//V=SAT(V);
				break;
			case 1: //Pal1->RGB
				p = &SrcPalette[ ((Src[0][sx>>3] >> ((~sx)&7)) & 1) ^ SrcInvert];
				cR += p->c.r; cG += p->c.g; cB += p->c.b;

				cR=SAT(cR);
				cG=SAT(cG);
				cB=SAT(cB);
				break;
			case 2: //Pal2->RGB
				p = &SrcPalette[ ((Src[0][sx>>2] >> (((~sx)&3)*2)) & 3) ^ SrcInvert];
				cR += p->c.r; cG += p->c.g; cB += p->c.b;

				cR=SAT(cR);
				cG=SAT(cG);
				cB=SAT(cB);
				break;
			case 3: //Pal4->RGB
				p = &SrcPalette[ ((Src[0][sx>>1] >> (((~sx)&1)*4)) & 15) ^ SrcInvert];
				cR += p->c.r; cG += p->c.g; cB += p->c.b;

				cR=SAT(cR);
				cG=SAT(cG);
				cB=SAT(cB);
				break;
			case 4: //Pal8->RGB
				p = &SrcPalette[Src[0][sx] ^ SrcInvert];
				cR += p->c.r; cG += p->c.g; cB += p->c.b;

				cR=SAT(cR);
				cG=SAT(cG);
				cB=SAT(cB);
				break;
			case 5: //RGB8->RGB
				v = Src[0][sx];
				v ^= SrcInvert;
				v <<= 8;
				cR += (v & SrcMask[0]) >> SrcPos[0];
				cG += (v & SrcMask[1]) >> SrcPos[1];
				cB += (v & SrcMask[2]) >> SrcPos[2];

				cR=SAT(cR);
				cG=SAT(cG);
				cB=SAT(cB);
				break;
			case 6: //RGB16->RGB
				v = ((uint16_t*)Src[0])[sx];
				v ^= SrcInvert;
				v <<= 8;
				cR += (v & SrcMask[0]) >> SrcPos[0];
				cG += (v & SrcMask[1]) >> SrcPos[1];
				cB += (v & SrcMask[2]) >> SrcPos[2];

				cR=SAT(cR);
				cG=SAT(cG);
				cB=SAT(cB);
				break;
			case 7: //RGB24->RGB
				v = Src[0][sx*3] | (Src[0][sx*3+1] << 8) | (Src[0][sx*3+2] << 16);
				v ^= SrcInvert;
				v <<= 8;
				cR += (v & SrcMask[0]) >> SrcPos[0];
				cG += (v & SrcMask[1]) >> SrcPos[1];
				cB += (v & SrcMask[2]) >> SrcPos[2];

				cR=SAT(cR);
				cG=SAT(cG);
				cB=SAT(cB);
				break;
			default: //RGB32->RGB
				v = ((uint32_t*)Src[0])[sx];
				v ^= SrcInvert;
				v <<= 8;
				cR += (v & SrcMask[0]) >> SrcPos[0];
				cG += (v & SrcMask[1]) >> SrcPos[1];
				cB += (v & SrcMask[2]) >> SrcPos[2];

				cR=SAT(cR);
				cG=SAT(cG);
				cB=SAT(cB);
				break;
			}

			q = Dst[0]+(dx >> 3);
			switch (DstType)
			{
			case 10: //RGB->Planar YUV
				Y = ((2105 * cR) + (4128 * cG) + (802 * cB))/0x2000 + 16;
				U = (-(1212 * cR) - (2384 * cG) + (3596 * cB))/0x2000 + 128;
				V = ((3596 * cR) - (3015 * cG) - (582 * cB))/0x2000 + 128;

				*q = (uint8_t)Y;
				Dst[1][dx2 >> 3] = (uint8_t)U;
				Dst[2][dx2 >> 3] = (uint8_t)V;

⌨️ 快捷键说明

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