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

📄 jpeg.c

📁 bf533平台图像采集程序
💻 C
字号:

#include "libjpeg/libjpeg.h"
#include "videoin.h"

extern char frame_flag;
extern unsigned char *YUV_656;
char* frame_buf;
int width, height;
int Q;
int D1;

//d1: 0, cif; 1, d1
jpeg_init(int d1)
{
//	cache_init();
	
	if(d1 == 0)
	{
		width	= 352;
		height	= 288;
	}
	else
	{
		width	= 720;
		height	= 576;
	}
	
	D1 = d1;
	
	frame_buf = (char*) malloc(width*height*3/2);
	if(frame_buf==0)
	{
		while(1);
	}
	
	//videoin_init();
	//camera_init();
}


//q: quality
jpeg_select_channel(int channel)
{
	camera_select(channel);  
}


jpeg_uninit()
{
	if(frame_buf)
		free(frame_buf);
	frame_buf = 0;
}

		     
void YUV656_TO_CIF(unsigned char *pSrc,unsigned char *pDst)
{
	int i,j;
	for(j = 0;j < 288;j++)
		for(i = 0;i < 352 ;i++)
			pDst[i + j*352 ] = pSrc[j*1440 + i*4 + 1];
			
	for(j = 0;j < 144; j++)
		for(i = 0;i < 176;i++)
		   pDst[i + j*176 + 352*288] = pSrc[j*1440*2 + 8*i];
		   
	for(j = 0;j < 144; j++)
		for(i = 0;i < 176;i++)
		   pDst[i + j*176 + 352*288 + 352*288/4] = pSrc[j*1440*2 + 8*i + 2]; 

}

void YUV656_TO_D1(unsigned char *pSrc,unsigned char *pDst)
{
	int i,j,a,b;
	
	for(i=0;i<576;i++)
		    for(j=0;j<720;j++)
				pDst[i*720+j] = pSrc[1+2*j + 1440*(i/2) +((i&1)?1440*288:0)];

      for(i=0;i<288;i++)
		     for(j=0;j<360;j++)
			 {
			  a=pSrc[i*1440 + 4*j]+pSrc[i*1440 + 4*j +1440*288];
			  b= pSrc[i*1440 + 4*j +2] + pSrc[i*1440 + 4*j +1440*288 +2];
			  pDst[720*576 +j+360*i ] = a/2;
	          pDst[720*576+720*576/4+j+360*i] = b/2;
			 }

	for(i=0;i<575;i++)
	   for(j=0;j<720;j++)
	   {
	   	     a = (pDst[i*720+j] +pDst[(i+1)*720+j])>>1;
	   	      pDst[i*720+j] = a;
	   }
	      
}
//return stream_len
int jpeg_snapshot(unsigned char *YUV_src,char* stream_buf, int Q)
{
	int size;
	
/*
	videoin_start();

	while(frame_flag !=4)
	{
		delay(1000);
	}
	
	videoin_stop();
*/

	if(D1== 1)
	  YUV656_TO_D1(YUV_src,frame_buf);
	else
	  YUV656_TO_CIF(YUV_src,frame_buf);


	return jpeg_compress(frame_buf, stream_buf, width, height, Q);
}


⌨️ 快捷键说明

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