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

📄 display.c

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

#include <stdio.h>
#include <string.h>
#include "display.h"
#include "sys.h"


int Cr2R[256];
int Cb2G[256];
int Cr2G[256];
int Cb2B[256];

void build_logo(WORD* rgb565)
{
	int i, j;
	FILE* file;
	WORD* out = rgb565 + 240*319;
	BYTE rgb[3];
	int r, g, b;

	file = fopen("logo.bmp", "rb");
	// read bmp header
	fread(rgb565, 1, 54, file);
	// process rows
	for(i=0; i<320; i++)
	{
		for(j=0; j<240; j++)
		{
			fread(rgb, 1, 3, file);
			b = (rgb[0]&0xF8)>>3;
			g = (rgb[1]&0xFC)>>2;
			r = (rgb[2]&0xF8)>>3;
			out[j] = b | (g<<5) | (r<<11);
		}
		out -= 240;
	}
	fclose(file);
}

void DrawImage(WORD *pImg)
{
	int i;
	WORD* pLCD = (WORD*)(LCD_BUF+32);
	
	for(i=0; i<240; i++)
	{
		memcpy(pLCD, pImg, 480);
		pLCD += 240;
		pImg += 320;
	}
}

void DrawHalf(WORD *pImg, int x, int y)
{
	int i, j;
	WORD* pLCD = (WORD*)(LCD_BUF+32);
	pLCD += (x + y*240);
	
	for(i=0; i<120; i++)
	{
		for(j=0; j<160; j++)
		{
			pLCD[j] = pImg[j*2];
		}
		pLCD += 240;
		pImg += 640;
	}
}

//___________________________________________________________________
// Function: Build_YUV2RGB_Table
// Usage: Build YUV to RGB convertion table.
// Parameters:		N/A
// Return Values:	N/A
//___________________________________________________________________
//
// R = Y                   + 1.402  *(V-128)
// G = Y - 0.34414*(U-128) - 0.71414*(V-128)
// B = Y + 1.772  *(U-128)
//
void Build_YUV2RGB_Table(void)
{
	int i;

	for(i=0; i<256; i++)
	{
		Cr2R[i] =  359 * (i-128);
		Cb2G[i] =  -88 * (i-128);
		Cr2G[i] = -183 * (i-128);
		Cb2B[i] =  454 * (i-128);
	}
}

//___________________________________________________________________
// Function: IMShow
// Usage: Show thumbnailed camera image on LCD.
// Parameters:
//	pImg			camera YUYV data
//	pLCD		out	LCD buffer
// Return Values:	N/A
//___________________________________________________________________
//
void IMShow(DWORD *pImg, WORD *pLCD)
{
	int i;

	for(i=0; i<120; i++)
	{
		YUV2RGB(pImg, pLCD, 160);
		// camera data move 2 row: 320*2pixels/160*2 DWORD
		pImg += 320;
		// lcd pointer move 1 row: 240pixels/240 WORD
		pLCD += 240;
	}
}
/*
void IMShow2(DWORD *pImg, WORD *pLCD)
{
	int i;

	for(i=0; i<240; i++)
	{
		YUV2RGB2(pImg, pLCD, 320);
		// camera data move 1 row: 320pixels/160 DWORD
		pImg += 160;
		// lcd pointer move 1 row: 240pixels/240 WORD
		pLCD += 240;
	}
}
*/
//___________________________________________________________________
// Function: YUV2RGB
// Usage: Convert YUYV to RGB16 for LCD display.
// Parameters:
//	pYUV			YUYV data in
//	pRGB		out	RGB565 data out
// Return Values:	N/A
//___________________________________________________________________
//
void YUV2RGB(DWORD *pYUV, WORD *pRGB, int size)
{
	int i;
	int Y, U, V;
	int temp;
	BYTE R, G, B;
	BYTE *pIn = (BYTE*)pYUV;

	for(i=0; i<size; i++)
	{
		Y = pIn[0] << 8;
		U = pIn[1];
		V = pIn[3];

		temp = Y + Cr2R[V];
		temp >>= 8;
		temp = (temp > 0xF0)? 0xF0 : temp;
		temp = (temp < 0x10)? 0x10 : temp;
		R = (BYTE)temp;

		temp = Y + Cb2G[U] + Cr2G[V];
		temp >>= 8;
		temp = (temp > 0xF0)? 0xF0 : temp;
		temp = (temp < 0x10)? 0x10 : temp;
		G = (BYTE)temp;

		temp = Y + Cb2B[U];
		temp >>= 8;
		temp = (temp > 0xF0)? 0xF0 : temp;
		temp = (temp < 0x10)? 0x10 : temp;
		B = (BYTE)temp;

		pRGB[i] = ((R & 0xF8)<<8) | ((G & 0xFC)<<3) | ((B & 0xF8)>>3);
		pIn+=4;
	}
}
/*
void YUV2RGB(DWORD *pYUV, WORD *pRGB, int size)
{
	int i;
	int Y, U, V;
	int temp;
	BYTE R, G, B;
	BYTE *pIn = (BYTE*)pYUV;

	for(i=0; i<size; i++)
	{
		Y = pIn[0] << 8;
		U = pIn[1];
		Y2 = pIn[2] << 8;
		V = pIn[3];

		temp = Y + Cr2R[V];
		temp >>= 8;
		temp = (temp > 0xF0)? 0xF0 : temp;
		temp = (temp < 0x10)? 0x10 : temp;
		R = (BYTE)temp;

		temp = Y + Cb2G[U] + Cr2G[V];
		temp >>= 8;
		temp = (temp > 0xF0)? 0xF0 : temp;
		temp = (temp < 0x10)? 0x10 : temp;
		G = (BYTE)temp;

		temp = Y + Cb2B[U];
		temp >>= 8;
		temp = (temp > 0xF0)? 0xF0 : temp;
		temp = (temp < 0x10)? 0x10 : temp;
		B = (BYTE)temp;

		pRGB[i] = ((R & 0xF8)<<8) | ((G & 0xFC)<<3) | ((B & 0xF8)>>3);
		pIn+=4;
	}
}
*/


// the end
//////////////////////////////////////////////////////////////////////////

⌨️ 快捷键说明

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