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

📄 vjpeg.c

📁 VC0558 backend IC jpeg format program
💻 C
📖 第 1 页 / 共 5 页
字号:
		if(gJpegContext.tcr > 5)
		{
			ratio = gJpegContext.tcr - 1;
			ratio >>= 2;
			vwc /= ratio;
			V558_JpegSetTWC(vwc);
			gJpegContext.entcr = 1;
		}
	}
	else
	{
		if(gJpegContext.twc)
		{
			vwc /= gJpegContext.twc;
			vwc <<= 2;
			vwc += 1;
			V558_JpegSetTCR((UINT8)vwc);
			gJpegContext.entcr = 0;
		}
	}
	
	V558_CtrlIntEnable(V558_INT_CAP_DONE, 1);
	V558_CtrlIntEnable(V558_INT_CAP_FIFO_FULL, 1);
	gJpegContext.State = V558_JPEG_ISWORKING;
}
/******************************************************************************
Description:
用于capture still。
Parameters:
1,pbuf:输出的数据块。用于存放采集到的图像数据。
2,pcall:回调指针。
Returns:
Null
Remarks:
NULL
Example:
UINT8 g_dataBuf[0x10000];
UINT32	g_bufoffset;
void TestCaptureStill(void)
{
V558_JPEGBUF g_buf;
g_buf.ActLen = 0;
g_buf.Len = 0x10000;
g_buf.pData = g_dataBuf;
g_bufoffset = 0;
V558_CaptureStill(&g_buf, JpegNote);
}
******************************************************************************/
void V558_CaptureStill(PV558_JPEGBUF pbuf, PV558_JPEGCALLBACK pcall)
{
	//V558_IppSelectPrefilter(1);
	gJpegContext.qf = V558_JpegGetQfactor();
	V558_CtrlDisableBRC();
	
	V558_JbufSetJpegAddr(0);
	V558_JbufSetJpegSize(TOTAL_JBUF_SIZE-1);
	EncodeJpg(V558_CAPTURE_STILLBRC, pbuf, pcall);
	V558_CtrlSetWorkMode(V558_MODE_CAP_STILL);	//start capture
}
/******************************************************************************
Description:
用于capture still with thumbnail。558芯片除了生成一个普通静止图片以外,
还可以生成一个40*30的缩略图(thumbnail),因此,如果是调用此函数,那么采
集的图像大小只能是4:3的。
Parameters:
1,pbuf:输出的数据块。用于存放采集到的图像数据(还没有加上thumbnail)。
2,pcall:回调指针。
Returns:
Null
Remarks:
Null
Example:
UINT8 g_dataBuf[0x10000];
UINT32	g_bufoffset;
void TestCaptureStillThumb(void)
{
V558_JPEGBUF g_buf;
g_buf.ActLen = 0;
g_buf.Len = 0x10000;
g_buf.pData = g_dataBuf;
g_bufoffset = 0;
V558_CaptureStillThumb(&g_buf, JpegNote);
}
******************************************************************************/
void V558_CaptureStillThumb(PV558_JPEGBUF pbuf, PV558_JPEGCALLBACK pcall)
{
//	V558_IppSelectPrefilter(1);
	gJpegContext.qf = V558_JpegGetQfactor();
	V558_CtrlDisableBRC();
	EncodeJpg(V558_CAPTURE_STILLBRC_THUMBNAIL, pbuf, pcall);
	V558_IppSetThumb(gJpegContext.thumbwidth);
	V558_IppGetDispSize(&gJpegContext.thumb);
	V558_JbufSetJpegAddr(0);
	V558_JbufSetJpegSize(TOTAL_JBUF_SIZE - DEFAULT_THUMB_SIZE - 1);
	V558_JbufSetThumbAddr(DEFAULT_THUMB_ADDR);
	V558_JbufSetThumbSize(DEFAULT_THUMB_SIZE-1);
	V558_CtrlSetWorkMode(V558_MODE_CAP_STILL_THUMB);
}
/******************************************************************************
Description:
用于开始Capture still with frame。
Parameters:
1,pbuf:输出的数据块。用于存放采集到的图像数据。
2,pcall:回调指针。
Note:
NULL
Returns:
Null
Remarks:
Null
Example:
UINT8 g_DataBuf[0x10000];
UINT32	g_StillBufOffset;
void TestCaptureStillFrame(void)
{
V558_JPEGBUF g_JpegBuf;
g_JpegBuf.ActLen = 0;
g_JpegBuf.Len = 0x8000;
g_JpegBuf.pData = g_DataBuf;
g_StillBufOffset = 0;
V558_CaptureFrame(&g_JpegBuf, JpegNote);
}
******************************************************************************/
void V558_CaptureFrame(PV558_JPEGBUF pbuf, PV558_JPEGCALLBACK pcall)
{
	gJpegContext.qf = V558_JpegGetQfactor();
	V558_CtrlDisableBRC();
	
	V558_JbufSetJpegAddr(0);
	V558_JbufSetJpegSize(TOTAL_JBUF_SIZE-1);
	EncodeJpg(V558_CAPTURE_FRAME, pbuf, pcall);
	gJpegContext.lcdctrl = V558_LcdDisableGamma();
	V558_CtrlSetWorkMode(V558_MODE_CAP_STILL_FRAM);
}
/******************************************************************************
Description:
用于开始Capture video with frame。
Parameters:
1,pbuf:输出的数据块。用于存放采集到的图像数据。
2,pcall:回调指针。
Note:
NULL
Returns:
Null
Remarks:
Null
Example:
UINT8 g_DataBuf[0x10000];
UINT32	g_StillBufOffset;
void TestCaptureVideoFrame(UINT8 bFrm)
{
V558_JPEGBUF g_JpegBuf;
g_JpegBuf.ActLen = 0;
g_JpegBuf.Len = 0x8000;
g_JpegBuf.pData = g_DataBuf;
g_StillBufOffset = 0;
V558_CaptureFrameVideo(&g_JpegBuf, JpegNote);
}
******************************************************************************/
void V558_CaptureFrameVideo(PV558_JPEGBUF pbuf, PV558_JPEGCALLBACK pcall)
{
	gJpegContext.qf = V558_JpegGetQfactor();
	V558_CtrlDisableBRC();
	
	V558_JbufSetJpegAddr(0);
	V558_JbufSetJpegSize(TOTAL_JBUF_SIZE-1);
	EncodeJpg(V558_CAPTURE_FRAMEVIDEO, pbuf, pcall);
	gJpegContext.lcdctrl = V558_LcdDisableGamma();
	V558_CtrlSetWorkMode(V558_MODE_CAP_VIDEO_FRAM);
	V558_JbufSetCapViewConf(0x4);
}
/******************************************************************************
Description:
用于开始capture video。
Parameters:
1,pbuf:输出的数据块。用于存放采集到的图像数据。
2,pcall:回调指针。
Returns:
Null
Remarks:
Null
Example:
UINT8 g_dataBuf[0x10000];
UINT32	g_bufoffset;
void TestCaptureVideo(void)
{
V558_JPEGBUF g_buf;
g_buf.ActLen = 0;
g_buf.Len = 0x10000;
g_buf.pData = g_dataBuf;
g_bufoffset = 0;
V558_StartCapVideo(&g_buf, JpegNote);
}
******************************************************************************/
void V558_StartCapVideo(PV558_JPEGBUF pbuf, PV558_JPEGCALLBACK pcall)
{
//	V558_IppSelectPrefilter(1);
	gJpegContext.qf = V558_JpegGetQfactor();
	V558_CtrlDisableBRC();
	
	V558_JbufSetJpegAddr(0);
	V558_JbufSetJpegSize(TOTAL_JBUF_SIZE-1);
	EncodeJpg(V558_CAPTURE_VIDEO, pbuf, pcall);
	V558_CtrlSetWorkMode(V558_MODE_CAP_VIDEO);
	V558_JbufSetCapViewConf(0x4);
}
/******************************************************************************
Description:
用于结束capture video。
Parameters:
NULL
Note:
在开始capture video之后,调用此函数即可停止capture video。
Returns:
Null
Remarks:
Null
******************************************************************************/
void V558_StopCapVideo(void)
{
	V558_JbufSetCapViewConf(0x8);
}



void V558_SetThumbWidth(UINT16 width)
{
	gJpegContext.thumbwidth = width;
}

UINT16 V558_GetThumbWidth(void)
{
	return gJpegContext.thumbwidth;
}



/******************************************************************************
Description:
	Change thumb rgb8 to rgb555 or rgb565.
Parameters:
	dst:	The dst buffer.Store rgb555 or rgb565 data.
	src:	The input buffer.
	xthumb:	The width of thumb.
	ythumb:	The height of thumb.
	rawformat:The rawformat. rgb565:1  ;  rgb555:2
Returns:	
	return the lenght of dst buffer.
Notes:
	NULL
Remarks:
	NULL
*******************************************************************************/
UINT16 V558_ConvertThumbRGB8ToRaw(UINT8* dst, UINT8* src, UINT8 xthumb, UINT8 ythumb,UINT8 rawformat)
{
	UINT8* rgbsrc;
	UINT8  rgbdata;
	RawType raw;
	UINT8  i,j;
	rgbsrc  =  src + 0x300;
	for(j=0 ; j<ythumb ; j++)
	{
		for(i=0 ; i<xthumb ; i++)
		{
			rgbdata = *(rgbsrc + j*xthumb + i);
			raw     = RGB8ToRaw(src, rgbdata, rawformat);
			*(dst + ((i+j*xthumb)<<1)) = raw.high;
			*(dst + ((i+j*xthumb)<<1)+1) = raw.low;
		}
	}
	return  xthumb*ythumb*2;
}

/************************************************************************
Description:
	Get the jpg info,and decide whether it has thumbnail or not.
Parameters:
	pbuf: the buffer of jpeg file.
	pinfo:the information of jpeg file.
Notes:
	NULL
Return:
	if 0,haven't thumbnail,if 1,have thumbnail.
Remark:
	NULL
*************************************************************************/
UINT8 V558_IsThumb(PV558_JPEGBUF pbuf, PV558_JPEG_INDEX pinfo)
{
	V558_JpegParse( pbuf, pinfo);
	return pinfo->isThumb;
}

//========================================================
//
//		Debug Jpeg Header Info
//
//========================================================
UINT8 WriteDecodeData(UINT8 *buf, UINT32 len)
{
	UINT16 value2, value1, value0, flag;

	V558_WriteSram(JBUF_BASEADD, buf, len);

	value0   =   V558_JbufGetWritePointer();
	value1   =   V558_JbufGetReadPointer();
	while(value0 != value1)
	{
		value2 = value1;
		flag = 0xff;
		do{
			if(V558_LbufGetStatus() & 0x3)
				_ISR_LbufFull();
			value1   =   V558_JbufGetReadPointer();
		} while((value1 == value2) && (--flag));
		if(flag == 0)
			return 1;
	}
	V558_Delay(1);
	flag = 0xff;
	value1=0;
		do{
			if(V558_LbufGetStatus() & 0x3)
				{
				_ISR_LbufFull();
				value1=1;
				}
		} while((!value1) && (--flag));
	return 0;
}

UINT8 SendDecodeData(UINT8 *buf, UINT32 len)
{
#if 0
	UINT32 cnt, i;
	UINT8 *pbuf = buf;
	UINT8	bus;
	
	bus = V558_CtrlGetBusType();
	if( (bus != 1) && (gJpegContext.mode != V558_DECODE_ONLY) )
	{
		cnt = len >> 2;
		for(i = 0; i < cnt; i++, pbuf += 4)
		{
			if(WriteDecodeData(pbuf, 4))
				return 1;
		}
		return 0;
	}
#endif
	return WriteDecodeData(buf, len);
}

UINT8 HostSendJpgData(void)
{
	UINT32 len, len1,i;
	UINT8 *pbuf, dat[4] = {0xff, 0xff, 0xff, 0xd9};
	
	len = gJpegContext.header.endpos - gJpegContext.header.offset;
	len1 = (len >> 2) << 2;
	pbuf = gJpegContext.buf.pData + gJpegContext.header.offset;

	
	if(gJpegContext.header.restartflag == 1)
	{
		V558_JpegStartDecoder();
		if( SendDecodeData(pbuf, gJpegContext.header.flagadd[0]+4) )
			return JPEGFAILED;
		for( i=0 ; i<gJpegContext.header.flagindex-1 ; i++)
		{
			if( SendDecodeData(pbuf+gJpegContext.header.flagadd[i]+4, 
				gJpegContext.header.flagadd[i+1]-gJpegContext.header.flagadd[i]) )
				return JPEGFAILED;
		}
		if( SendDecodeData(pbuf+gJpegContext.header.flagadd[i]+4, 
			len1-gJpegContext.header.flagadd[i]-4) )
			return JPEGFAILED;
		
		if( (len == len1+1) || (len == len1+2) )
			SendDecodeData(dat, 4);
		else if(len == len1+3)
		{
			dat[0] = pbuf[len1];
			SendDecodeData(dat, 4);
		}
	}
	if(gJpegContext.header.restartflag == 0)
	{
		V558_JpegStartDecoder();
		if( SendDecodeData(pbuf, len1) )
			return JPEGFAILED;
		
		if( (len == len1+1) || (len == len1+2) )
			SendDecodeData(dat, 4);
		else if(len == len1+3)
		{
			dat[0] = pbuf[len1];
			SendDecodeData(dat, 4);
		}
	}


	if(gJpegContext.declinesum < gJpegContext.decMaxlinesum)
	{
		PV558_JPEGCALLBACK pcall;

		pcall = gJpegContext.pcall;
		gJpegContext.pcall = NULL;
		V558_CtrlIntEnable(V558_INT_8BUF_FULL, 0);

		gJpegContext.State = V558_JPEG_INITED;
		pcall(MSG_READ_YUV_DONE, &gJpegContext.dst);
	}

	return SUCCEED;
}
UINT32 CountNumber;		//angela
UINT8 SendDisplayData(UINT8 *buf, UINT32 len)
{
	UINT8 *pbuf = buf;
	UINT16 value2, value1, value0;
	
	V558_WriteSram(JBUF_BASEADD, pbuf, len);
	value0   =   V558_JbufGetWritePointer();
	value1   =   V558_JbufGetReadPointer();
	while(value0 != value1)
	{
		value2 = value1;
		CountNumber = 0xffff;
		do{
			value1   =   V558_JbufGetReadPointer();
		} while((value1 == value2) && (--CountNumber));
		if(CountNumber == 0)
			return 0;		//angela 1105
	}
	return 0;
}

UINT8 DecodeProcess(void)
{
	UINT32 len, len1, i;
	UINT8 *pbuf, dat[4] = {0xff, 0xff, 0xff, 0xd9};

	len = gJpegContext.header.endpos - gJpegContext.header.offset;
	len1 = (len >> 2) << 2;
	pbuf = gJpegContext.buf.pData + gJpegContext.header.offset;
	pbuf[len1 - 1] = 0xd9;
	pbuf[len1 - 2] = 0xff;
	len = len1;
	if(gJpegContext.header.restartflag == 1)
	{
		V558_JpegStartDecoder();
#if 1
		DecreaseClk();
		//V558_Decrease_PLL();
#endif
		
		if(SendDisplayData(pbuf, gJpegContext.header.flagadd[0]+4))
			return JPEGFAILED;
		for( i=0 ; i<gJpegContext.header.flagindex-1 ; i++)
		{
			if( SendDisplayData(pbuf+gJpegContext.header.flagadd[i]+4, 
				gJpegContext.header.flagadd[i+1]-gJpegContext.header.flagadd[i]) )
				return JPEGFAILED;
		}
		if( SendDisplayData(pbuf+gJpegContext.header.flagadd[i]+4, 
			len1-gJpegContext.header.flagadd[i]-4) )
			return JPEGFAILED;
		
		if( (len == len1+1) || (len == len1+2) )
		{
			if(SendDisplayData(dat, 4))
				return JPEGFAILED;
		}
		else if(len == len1+3)
		{
			dat[0] = pbuf[len1];
			if(SendDisplayData(dat, 4))
				return JPEGFAILED;
		}

⌨️ 快捷键说明

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