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

📄 ime9650_utils.c

📁 这个是基于在CCS开发环境下
💻 C
字号:
/*
 *  Copyright 2004 by Texas Instruments Incorporated.
 *  All rights reserved. Property of Texas Instruments Incorporated.
 *  Restricted rights to use, duplicate or disclose this code are
 *  granted through contract.
 *  
 */

/*********************************************************
 IME9650_utils
 This file contains utilities to aid in data display 		
*********************************************************/

#include "math.h"
#include <csl_cache.h>
#include <csl_edma.h>
#include <csl_dat.h>
#include "IME9650_utils.h"
 static Uint8 temp[720*576];
#define CSTRINGNUMBER 21
#define CSTRINGHEIGHT 21
char cDSPWB[CSTRINGNUMBER*CSTRINGHEIGHT]=
{
//--  正在调整白平衡...  --  **  华文新魏, 16  **
// 当前所选字体下一个汉字对应的点阵为:  宽度x高度=165x21,  调整后为: 168x21
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x03,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,
0x00,0x00,0x03,0x18,0x00,0x02,0x00,0x00,0x1E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x1E,0x00,0x01,0x20,0x01,0x00,0x00,0x03,0x90,0x00,0x06,0x00,0x00,0xFC,0x00,0x01,
0x80,0x00,0x00,0x00,0x01,0xFE,0x00,0x03,0xF0,0x01,0x83,0xE0,0x07,0xB2,0x00,0x0C,
0x00,0x00,0x90,0x00,0x1B,0x83,0x00,0x00,0x00,0x01,0xF8,0x00,0x1F,0xE0,0x01,0x9F,
0x20,0x07,0x3C,0x00,0x18,0x00,0x00,0x13,0x00,0x12,0xCE,0x00,0x00,0x00,0x00,0x30,
0x00,0x1F,0x00,0x00,0x13,0x20,0x07,0xE8,0x00,0x20,0x00,0x00,0x36,0x00,0x34,0x80,
0x00,0x00,0x00,0x00,0x30,0x00,0x04,0x00,0x00,0x17,0xA0,0x09,0x68,0x00,0x43,0xF0,
0x01,0xDC,0x00,0x03,0xE1,0xC0,0x00,0x00,0x00,0x3E,0x00,0x0C,0x60,0x01,0x93,0x20,
0x0F,0x98,0x00,0xDE,0x38,0x01,0x98,0x00,0x15,0xBF,0xC0,0x00,0x00,0x01,0x3C,0x00,
0x08,0x60,0x0F,0x9F,0xE0,0x03,0xBE,0x01,0xF8,0x38,0x00,0x3F,0xC0,0x35,0xBE,0x00,
0x00,0x00,0x01,0x30,0x00,0x18,0x60,0x1F,0x18,0x20,0x05,0x43,0x01,0xF7,0x30,0x03,
0xFF,0xE0,0x63,0xE6,0x00,0x00,0x00,0x01,0x30,0x00,0x30,0x78,0x03,0x17,0xA0,0x19,
0x70,0x00,0x37,0x30,0x0F,0x10,0x00,0x61,0x02,0x00,0x00,0x00,0x01,0x30,0x00,0x53,
0xF0,0x02,0x59,0xA0,0x01,0xE0,0x00,0x34,0x30,0x00,0x10,0x00,0xA1,0xE2,0x00,0x00,
0x00,0x01,0x7F,0xC0,0xD3,0xE0,0x02,0x6B,0x20,0x00,0x68,0x00,0x33,0x70,0x00,0x10,
0x00,0x2F,0x82,0x00,0x00,0x00,0x07,0xFF,0xE1,0xD0,0xE0,0x02,0xA7,0x20,0x02,0x70,
0x00,0x1F,0xE0,0x00,0x10,0x00,0x22,0x62,0x07,0x1C,0x70,0x1C,0x00,0x63,0x10,0xE0,
0x03,0x20,0x20,0x02,0x60,0x00,0x1C,0xE0,0x00,0x10,0x00,0x24,0x02,0x07,0x1C,0x70,
0x00,0x00,0x00,0x11,0xFE,0x01,0x40,0x20,0x03,0xFF,0x80,0x00,0x00,0x00,0x10,0x00,
0x20,0x1E,0x00,0x00,0x00,0x00,0x00,0x00,0x16,0x00,0x00,0x83,0xE0,0x1F,0xFF,0x80,
0x00,0x00,0x00,0x10,0x00,0x00,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x00,
0x00,0x60,0x30,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};

// 工作变量
Uint8 *pwy,*pwu,*pwv,*py,*pu,*pv;

//********************************************************
//* 将交叉排列的图象数据(连续存放)存放到输出缓冲区(各自独立)
//
//		Cb11 Y11 Cr11 Y12 Cb12 Y13 Cr12 Y14 ...			Y11 Y12 Y13 Y14...		Cb11 Cb12...	Cr11 Cr12...
//		Cb21 Y21 Cr21 Y22 Cb22 Y23 Cr22 Y24 ...   ==>	Y21 Y22 Y23 Y24...		Cb21 Cb22...	Cr21 Cr22...
//		Cb31 Y31 Cr31 Y32 Cb32 Y33 Cr32 Y34 ...			Y31 Y32 Y33 Y34...		Cb31 Cb32...	Cr31 Cr32...
//		
//********************************************************
void BT656ToPAL(Uint8 *srcBuf,Uint8 *Y,Uint8 *Cb,Uint8 *Cr,int width,int height,int x0,int y0)
{
	register int i,j,k,m,n;
	
	pwy=pwu=pwv=srcBuf; pwy++; pwv++; pwv++; py=Y; pu=Cb; pv=Cr; k=width/2; 
	m=x0; py+=m; m>>=1; pu+=m; pv+=m; 
	m=y0*720; py+=m; m>>=1; pu+=m; pv+=m;
	m=720-width; n=360-k;
	for ( j=0;j<height;j++ )
	{
		for ( i=0;i<k;i++ )	
		{
			(*py++)=(*pwy++); pwy++; (*py++)=(*pwy++); pwy++;
			/*(*pu++)=(*pwu++); pwu++; pwu++; pwu++;   //显示灰度图像
			(*pv++)=(*pwv++); pwv++; pwv++; pwv++;*/
		}
		py+=m; pu+=n; pv+=n;
	}
	CACHE_clean(CACHE_L2ALL, 0, 0);
}

unsigned int uGainRed=0x80,uGainBlue=0x80,uBWCount=0;
int nRedChange=0,nBlueChange=0;
extern unsigned int bDSPWB;
//****************************************************************************
// 白平衡算法: 根据屏幕中心100x100区域图象情况计算并设置白平衡
//****************************************************************************
void DSPWhiteBlance(Uint8 *Y,Uint8 *Cb,Uint8 *Cr,int x0,int y0)
{
	int i,j,u,v,y,r,g,b,sr,sg,sb;
	char *pwork;
    
	if ( uBWCount==0 )	IME9650_SetRegister(0x13,0x8d);	// 关闭自动白平衡
	uBWCount++;
	py=Y+y0*720+x0; pv=Cb+y0*360+x0/2; pu=Cr+y0*360+x0/2; sr=sg=sb=0; 
	for ( j=0;j<100;j++ )
	{
		for ( i=0;i<100;i++,py++,pu++,pv++ )
		{
			u=(*pu); v=(*pv); y=(*py++);
			u-=128; v-=128;
			r=y+1.402*u; if ( r<0 )	r=0; else if ( r>255 )	r=255;
			g=y-0.34414*u-0.71414*v; if ( g<0 )	g=0; else if ( g>255 )	g=255;
			b=y+1.772*v;	if ( b<0 )	b=0; else if ( b>255 )	b=255;
			sr+=r; sg+=g; sb+=b;
		}
		py+=520; pu+=260; pv+=260;
	}
	j=abs(sr-sg); j/=10000; i=( j>=10 )?(4):(1);
	if ( sr<sg )	uGainRed+=i;
	if ( sr>sg )	uGainRed-=i;
	uGainRed%=256;
	j=abs(sb-sg); j/=10000; i=( j>=10 )?(4):(1);
	if ( sb<sg )	uGainBlue+=i;
	if ( sb>sg )	uGainBlue-=i;
	uGainBlue%=256;
	IME9650_SetRegister(0x01,uGainBlue);	// 重新设置蓝色增益
	IME9650_SetRegister(0x02,uGainRed);		// 重新设置红色增益
	sr/=10000; sg/=10000; sb/=10000;
	if ( (sr==sg && sb==sg)||uBWCount>256  )	// 结束条件
	{ 
		bDSPWB=0; uBWCount=0; IME9650_SetRegister(0x13,0x8f);		// 使能自动白平衡
	}
	py=Y+y0*720+x0; pu=Cb+y0*360+x0/2; pv=Cr+y0*360+x0/2; pwork=cDSPWB;
	u=720-CSTRINGNUMBER*8; v=u/2;
	for ( j=0;j<CSTRINGHEIGHT;j++ )			// 显示提示信息
	{
		for ( i=0;i<CSTRINGNUMBER;i++ )
		{
			y=(*pwork++);
			for ( g=0;g<4;g++ )
			{
				(*py++)=( y&0x80 )?(255):(0); y<<=1;
				(*py++)=( y&0x80 )?(255):(0); y<<=1;
				(*pu++)=(*pv++)=0x80;
			}
		}
		py+=u; pu+=v; pv+=v;
	}
}

//****************************************************************************
// Sobel边缘检测
//****************************************************************************
void Sobel(Uint8 *Y) // 边缘检测
{
   int i,j;
   int  sobelV ,sobelH;
   Uint8* pmemtemp; 
   
     int height;
     int width ; 
     height = 576;  width = 720; 
     pmemtemp=Y;
   	for (i=0;i<height;i++)        
      for (j=0;j<width;j++)
        temp[width*i+j]=pmemtemp[width*i+j];  
        
        for (i=1;i<height-1;i++)        
      for (j=1;j<width-1;j++)
        {
         //sobelV = (a0+2a1+a2)-(a6+2a5+a4)   sobelH = (a2+2a3+a4)-(a0+2a7+a6)
         sobelV=abs(pmemtemp[width*(i-1)+j-1]
                    +2*pmemtemp[width*i+j-1]+pmemtemp[width*(i+1)+j-1]-pmemtemp[width*(i-1)+j+1]-2*pmemtemp[width*i+j+1]-pmemtemp[width*(i+1)+j+1]);
         sobelH=abs(pmemtemp[width*(i+1)+j-1]
                    +2*pmemtemp[width*(i+1)+j]+pmemtemp[width*(i+1)+j+1]-pmemtemp[width*(i-1)+j-1]-2*pmemtemp[width*(i-1)+j]-pmemtemp[width*(i-1)+j+1]);
         
        /* sqt = sqrt(sobelV*sobelV +sobelH*sobelH) ;   	
              
         temp[width*i+j]=sqt;  */
        if(sobelH>sobelV)                          
        	temp[width*i+j]=sobelH;
        else
        	temp[width*i+j]=sobelV;
        
        if(temp[width*i+j]>255)
        	temp[width*i+j]=255;         	
         
        } 
        
       for (i=0;i<48;i++)        
        for (j=0;j<width;j++)
        pmemtemp[width*i+j]=0;          
         
       for (i=48;i<528;i++)      //480+48=528   
        for (j=0;j<width;j++)
        {         
        pmemtemp[width*i+j]=temp[width*i+j];
        }   
        
        for (i=528;i<height;i++)        
        for (j=0;j<width;j++)
        pmemtemp[width*i+j]=0;   
        
        for (i=48;i<528;i++)       
        for (j=0;j<40;j++)
        {         
        pmemtemp[width*i+j]=0;
        }   
        
        for (i=48;i<528;i++)        
        for (j=680;j<width;j++)
        {         
        pmemtemp[width*i+j]=0;
        }   
}

⌨️ 快捷键说明

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