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

📄 clrspace.c

📁 以TI 公司的OMAP5910为例
💻 C
字号:

#include "dspdma.h"

static void yuv422_rgb565(WORD *pIn, WORD *pOut, int size);

WORD InBuf_3[320];
WORD InBuf_4[320];
WORD OutBuf_3[320];
WORD OutBuf_4[320];

void IMG_YUV422_RGB565(DWORD addrIn, DWORD addrOut)
{
	int i;
	WORD width = 320;
	WORD height = 240;

	// background transfer buffers
	WORD *pIn_Tran = InBuf_3;
	WORD *pOut_Tran = OutBuf_3;

	// foreground process buffers
	WORD *pIn_Proc = InBuf_4;
	WORD *pOut_Proc = OutBuf_4;

	// temp pointer for swapping
	WORD *ptr;

	// read first line to input buffer
	DMA_SD2DA(pIn_Tran, addrIn, width);
	addrIn += width*2;

	// start double buffering loop
	for(i=0; i<height; i++)
	{
		// swap input buffer
		ptr = pIn_Tran;
		pIn_Tran = pIn_Proc;
		pIn_Proc = ptr;
		
		// start input background transfer
		DMA_SD2DA(pIn_Tran, addrIn, width);
		addrIn += width*2;

		// convert color-mode
		yuv422_rgb565(pIn_Proc, pOut_Proc, width);

		// swap Out buffer
		ptr = pOut_Tran;
		pOut_Tran = pOut_Proc;
		pOut_Proc = ptr;

		// start Out background transfer
		DMA_DA2SD(addrOut, pOut_Tran, width);
		addrOut += width*2;
	}
	DMA_DA2SD(addrOut, pOut_Tran, width);
	addrOut += width*2;
}


void yuv422_rgb565(WORD *pIn, WORD *pOut, int size)
{
	WORD i;
	WORD Y1, Y2;
	short U, V;
	long chrom_r, chrom_g, chrom_b;
	long temp;
	WORD R, G, B;

	// for each 2 pixels
	for (i=0; i<size; i+=2)
	{
		Y1 = pIn[0] << 8;
		U = (short)(pIn[0]>>8) - 128;
		Y2 = pIn[1] << 8;
		V = (short)(pIn[1]>>8) - 128;

		// chrominance modifier
		chrom_r = 359 * V;
		chrom_g = -88 * U - 183 * V;
		chrom_b = 454 * U;

		// R1
		temp = (long)Y1 + chrom_r;
		temp >>= 8;
		temp = (temp > 0xF0)? 0xF0 : temp;
		temp = (temp < 0x10)? 0x10 : temp;
		R = (WORD)temp;
		
		// G1
		temp = (long)Y1 + chrom_g;
		temp >>= 8;
		temp = (temp > 0xF0)? 0xF0 : temp;
		temp = (temp < 0x10)? 0x10 : temp;
		G = (WORD)temp;
		
		// B1
		temp = (long)Y1 + chrom_b;
		temp >>= 8;
		temp = (temp > 0xF0)? 0xF0 : temp;
		temp = (temp < 0x10)? 0x10 : temp;
		B = (WORD)temp;

		// pixel1
		pOut[1] = ((R&0x00F8)<<8) | ((G&0x00FC)<<3) | ((B&0x00F8)>>3);

		// R2
		temp = (long)Y2 + chrom_r;
		temp >>= 8;
		temp = (temp > 0xF0)? 0xF0 : temp;
		temp = (temp < 0x10)? 0x10 : temp;
		R = (WORD)temp;
		
		// G2
		temp = (long)Y2 + chrom_g;
		temp >>= 8;
		temp = (temp > 0xF0)? 0xF0 : temp;
		temp = (temp < 0x10)? 0x10 : temp;
		G = (WORD)temp;
		
		// B2
		temp = (long)Y2 + chrom_b;
		temp >>= 8;
		temp = (temp > 0xF0)? 0xF0 : temp;
		temp = (temp < 0x10)? 0x10 : temp;
		B = (WORD)temp;

		// pixel2
		pOut[0] = ((R&0x00F8)<<8) | ((G&0x00FC)<<3) | ((B&0x00F8)>>3);
		
		pOut += 2;
		pIn += 2;
	}
}

⌨️ 快捷键说明

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