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

📄 mt9t001_utils.c

📁 TI DM642 DSP 驱动CMOS 成像芯片MT9T001(Micron)源代码,TI原版资料.包含驱动环境配置,对如基于DSP的数码相机,摄像机开发有重要参考价值.
💻 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.
 *  
 */

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

#include "MT9T001_utils.h"
//#include "MT9T001_config.h"

/********************************************************/
/* Fill the display buffers with a background color		*/
/********************************************************/
void fillBackgroundSVGA(int numlines, int linesz, Uint16 *rawBuf, Uint8 value)
{

 int ii;

 for(ii = 0; ii < (numlines*linesz); ii++)
 {
  rawBuf[ii] = value;
 }

}

/********************************************************
  Convert Bayer pattern souce data to RGB565 for 
	SVGA out.
	Bayer Pattern:
		GRGRGR
		BGBGBG
		GRGRGR
		BGBGBG
	Each 4x4 block of data is treated as a single pixel.
		GR - \  1 pixel of RGB
		BG - / 
	The 2 green pixels are averaged together
	The R and B are extracted.
	After the MSBs are extracted from the RGB data, 
	they are stored in 16 bit memory locations.
	This type of processing uses only 1/4 of the 
	captured resolution, ie, 1/2 the number of pixels / line
	and 1/2 the lines			
*********************************************************/

// Use for 8 Bit Raw
void Bayer_2_RGB565(Uint8 *srcBuf, Uint16 *outBuf, int numlinesCap, int lineszCap, int numlinesDis, int lineszDis, int scaleHoriz, int scaleVert)
{

	// Structures and Unions to aid in conversion to RGB565
	typedef struct sRGB565
	{
		unsigned int blue 	:5;
		unsigned int green	:6;
		unsigned int red	:5; 
	} s_RGB565;
	
	typedef union   
	{
		Uint16 RGB16;
		s_RGB565 color;

	} u_RGB565;

	
	// Structure and Union to extract 5 MSBs
	typedef struct sRB
	{
		unsigned int d2_d0	:3;
		unsigned int MSBs	:5; 
	} s_RB;
	
	typedef union   
	{
		Uint8 data;
		s_RB extract;

	} u_RB;


	// Structure and Union to extract 6 MSBs
	typedef struct sG
	{
		unsigned int d1_d0	:2;
		unsigned int MSBs	:6; 
	} s_G;
	
	typedef union   
	{
		Uint8 data;
		s_G extract;

	} u_G;



	u_G Green;
	u_RB RB;
	u_RGB565 RGB565;

	int ii, jj, kk, tmp;
	Uint8 rPixel, gPixel[2], bPixel, gPxl; 
	int numLines;
	int numPixels;	
    int disPitch;
    
    // Find the effective number of lines to display
    if(numlinesCap < numlinesDis)
    {
      	numLines = numlinesCap;
    	
    }
    else
    {
    
    	if(numlinesCap/2 <= numlinesDis)
    	{
    		numLines = numlinesCap;
    	}
    	else 
    	{
    		numLines = numlinesDis;
    	}
    } 
    
    // Find the effective number of pixels / line to display
    if(lineszCap/2 > lineszDis)
    {
      	numPixels = lineszDis;
      	disPitch = lineszDis/2;
    }
    else
    {
    	numPixels = lineszCap/2;
    	disPitch = lineszDis/2;
    
    } 
    
    numLines = numLines / scaleVert;
    numPixels = numPixels / scaleHoriz;
    
	// cycle through each line
	for(jj = 0; jj < numLines; jj=jj+2)
	{
		kk = 0;
		// cycle through the pixels
		for(ii = 0; ii < numPixels; ii++)
		{
			/********************************************/
				// Even Line
				// Green Pixel 0
				tmp = EVEN_PIXELS(ii) + lineszCap*jj;
				gPixel[0] = srcBuf[tmp];
				
				// Red Pixel
				tmp = ODD_PIXELS(ii) + lineszCap*jj;
				rPixel = srcBuf[tmp];
			/********************************************/
			// increment line
			jj++;
			/********************************************/
				// Odd Line
				// Green Pixel 1			
				tmp = ODD_PIXELS(ii) + lineszCap*jj;
				gPixel[1] = srcBuf[tmp];
			
				// Blue Pixel
				tmp = EVEN_PIXELS(ii) + lineszCap*jj;
				bPixel = srcBuf[tmp];
			/********************************************/
			
		// Take average of green pixels
		gPxl = (gPixel[0] + gPixel[1])/2;
		
		RB.data = rPixel;		
		RGB565.color.red = RB.extract.MSBs;
		
		RB.data = bPixel;
		RGB565.color.blue = RB.extract.MSBs;
		
		Green.data = gPxl;
		RGB565.color.green = Green.extract.MSBs;  
		
		// decrement the line
		jj--;

		// copy RGB565 to Display Buffer
		outBuf[kk++ + disPitch*jj] = RGB565.RGB16;	
			
		} // end lineszCap Loop 
	}// end numlinesCap Loop
}// end function



// Use for 10 Bit Raw
void Bayer_2_RGB565_10Bit(Uint16 *srcBuf, Uint16 *outBuf, int numlinesCap, int lineszCap, int numlinesDis, int lineszDis, int scaleHoriz, int scaleVert)
{

	// Structures and Unions to aid in conversion to RGB565
	typedef struct sRGB565
	{
		unsigned int blue 	:5;
		unsigned int green	:6;
		unsigned int red	:5; 
	} s_RGB565;
	
	typedef union   
	{
		Uint16 RGB16;
		s_RGB565 color;

	} u_RGB565;

	
	// Structure and Union to extract 5 MSBs
	typedef struct sRB
	{
		unsigned int d4_d0	:5;
		unsigned int MSBs	:5;
		unsigned int d15_d10 : 6; 
	} s_RB;
	
	typedef union   
	{
		Uint16 data;
		s_RB extract;

	} u_RB;


	// Structure and Union to extract 6 MSBs
	typedef struct sG
	{
		unsigned int d3_d0	:4;
		unsigned int MSBs	:6;
		unsigned int d15_d10 :6; 
	} s_G;
	
	typedef union   
	{
		Uint16 data;
		s_G extract;

	} u_G;



	u_G Green;
	u_RB RB;
	u_RGB565 RGB565;

	int ii, jj, kk, tmp;
	Uint16 rPixel, gPixel[2], bPixel, gPxl; 
	int numLines;
	int numPixels;	
    int disPitch;
    
    // Find the effective number of lines to display
    if(numlinesCap < numlinesDis)
    {
      	numLines = numlinesCap;
    	
    }
    else
    {
    
    	if(numlinesCap/2 <= numlinesDis)
    	{
    		numLines = numlinesCap;
    	}
    	else 
    	{
    		numLines = numlinesDis;
    	}
    } 
    
    // Find the effective number of pixels / line to display
    if(lineszCap/2 > lineszDis)
    {
      	numPixels = lineszDis;
      	disPitch = lineszDis/2;
    }
    else
    {
    	numPixels = lineszCap/2;
    	disPitch = lineszDis/2;
    
    } 
    
    numLines = numLines / scaleVert;
    numPixels = numPixels / scaleHoriz;
    
	// cycle through each line
	for(jj = 0; jj < numLines; jj=jj+2)
	{
		kk = 0;
		// cycle through the pixels
		for(ii = 0; ii < numPixels; ii++)
		{
			/********************************************/
				// Even Line
				// Green Pixel 0
				tmp = EVEN_PIXELS(ii) + lineszCap*jj;
				gPixel[0] = srcBuf[tmp];
				
				// Red Pixel
				tmp = ODD_PIXELS(ii) + lineszCap*jj;
				rPixel = srcBuf[tmp];
			/********************************************/
			// increment line
			jj++;
			/********************************************/
				// Odd Line
				// Green Pixel 1			
				tmp = ODD_PIXELS(ii) + lineszCap*jj;
				gPixel[1] = srcBuf[tmp];
			
				// Blue Pixel
				tmp = EVEN_PIXELS(ii) + lineszCap*jj;
				bPixel = srcBuf[tmp];
			/********************************************/
			
		// Take average of green pixels
		gPxl = (gPixel[0] + gPixel[1])/2;
		
		RB.data = rPixel;		
		RGB565.color.red = RB.extract.MSBs;
		
		RB.data = bPixel;
		RGB565.color.blue = RB.extract.MSBs;
		
		Green.data = gPxl;
		RGB565.color.green = Green.extract.MSBs;  
		
		// decrement the line
		jj--;

		// copy RGB565 to Display Buffer
		outBuf[kk++ + disPitch*jj] = RGB565.RGB16;	
			
		} // end lineszCap Loop 
	}// end numlinesCap Loop
}// end function



// Use for 20 Bit Raw
void Bayer_2_RGB565_20Bit(Uint32 *srcBuf, Uint16 *outBuf, int numlinesCap, int lineszCap, int numlinesDis, int lineszDis, int scaleHoriz, int scaleVert)
{

	// Structures and Unions to aid in conversion to RGB565
	typedef struct sRGB565
	{
		unsigned int blue 	:5;
		unsigned int green	:6;
		unsigned int red	:5; 
	} s_RGB565;
	
	typedef union   
	{
		Uint16 RGB16;
		s_RGB565 color;

	} u_RGB565;

	
	// Structure and Union to extract 5 MSBs
	typedef struct sRB
	{
		unsigned int d4_d0	:5;
		unsigned int MSBs	:5;
		unsigned int d15_d32 :22; 
	} s_RB;
	
	typedef union   
	{
		Uint32 data;
		s_RB extract;

	} u_RB;


	// Structure and Union to extract 6 MSBs
	typedef struct sG
	{
		unsigned int d3_d0	:4;
		unsigned int MSBs	:6;
		unsigned int d15_d32 :22; 
	} s_G;
	
	typedef union   
	{
		Uint32 data;
		s_G extract;

	} u_G;



	u_G Green;
	u_RB RB;
	u_RGB565 RGB565;

	int ii, jj, kk, tmp;
	Uint32 rPixel, gPixel[2], bPixel, gPxl; 
	int numLines;
	int numPixels;	
    int disPitch;
    
    // Find the effective number of lines to display
    if(numlinesCap < numlinesDis)
    {
      	numLines = numlinesCap;
    	
    }
    else
    {
    
    	if(numlinesCap/2 <= numlinesDis)
    	{
    		numLines = numlinesCap;
    	}
    	else 
    	{
    		numLines = numlinesDis;
    	}
    } 
    
    // Find the effective number of pixels / line to display
    if(lineszCap/2 > lineszDis)
    {
      	numPixels = lineszDis;
      	disPitch = lineszDis/2;
    }
    else
    {
    	numPixels = lineszCap/2;
    	disPitch = lineszDis/2;
    
    } 
    
    numLines = numLines / scaleVert;
    numPixels = numPixels / scaleHoriz;
      
	// cycle through each line
	for(jj = 0; jj < numLines; jj=jj+2)
	{
		kk = 0;
		// cycle through the pixels
		for(ii = 0; ii < numPixels; ii++)
		{
			/********************************************/
				// Even Line
				// Green Pixel 0
				tmp = EVEN_PIXELS(ii) + lineszCap*jj;
				gPixel[0] = srcBuf[tmp];
				
				// Red Pixel
				tmp = ODD_PIXELS(ii) + lineszCap*jj;
				rPixel = srcBuf[tmp];
			/********************************************/
			// increment line
			jj++;
			/********************************************/
				// Odd Line
				// Green Pixel 1			
				tmp = ODD_PIXELS(ii) + lineszCap*jj;
				gPixel[1] = srcBuf[tmp];
			
				// Blue Pixel
				tmp = EVEN_PIXELS(ii) + lineszCap*jj;
				bPixel = srcBuf[tmp];
			/********************************************/
			
		// Take average of green pixels
		gPxl = (gPixel[0] + gPixel[1])/2;
		
		RB.data = rPixel;		
		RGB565.color.red = RB.extract.MSBs;
		
		RB.data = bPixel;
		RGB565.color.blue = RB.extract.MSBs;
		
		Green.data = gPxl;
		RGB565.color.green = Green.extract.MSBs;  
		
		// decrement the line
		jj--;

		// copy RGB565 to Display Buffer
		outBuf[kk++ + disPitch*jj] = RGB565.RGB16;	
			
		} // end lineszCap Loop 
	}// end numlinesCap Loop
}// end function




⌨️ 快捷键说明

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