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

📄 vjpeg.c

📁 VC0558 backend IC jpeg format program
💻 C
📖 第 1 页 / 共 5 页
字号:
	}
	
	if(gJpegContext.header.restartflag == 0)
	{
		//=======================
//if arm is fast
#if 1
		DecreaseClk();
		//V558_Decrease_PLL();
#endif
		
//===========================================

		V558_WriteSram(JBUF_BASEADD, pbuf, len1);
		if( (len == len1+1) || (len == len1+2) )
			V558_WriteSram(JBUF_BASEADD, dat, 4);
		else if(len == len1+3)
		{
			dat[0] = pbuf[len1];
			V558_WriteSram(JBUF_BASEADD, dat, 4);
		}
	V558_JpegStartDecoder();

	}
	return SUCCEED;
}

static void StartDecodeJpg(UINT8 mode, PV558_LAYER_PROPERTY proty)
{
	V558_POINT pt = {0, 0};
	
	V558_CtrlSetWorkMode(V558_MODE_DISPLAY);
	V558_CtrlDisableBRC();
	
	gJpegContext.pcall = NULL;
	gJpegContext.mode = mode;
	
	V558_JbufSetJpegAddr(0);
	V558_JbufSetJpegSize(TOTAL_JBUF_SIZE-1);
	
	V558_CtrlSwReset(V558_SW_RESET_IPP);
	V558_CtrlSwReset(V558_SW_RESET_JPG);
	
	V558_IppDisplay(gJpegContext.header.LbufSize, pt, 
		gJpegContext.header.ImageSize, proty->Size.cx);
	V558_IppGetDispSize(&(proty->Size));
	V558_LcdSetALProperty(proty);
	
	V558_JpegSetWorkMode(9);
	V558_JpegSetVWC(gJpegContext.header.vwc);
	V558_JpegSetBlockNum(gJpegContext.header.blkcount);
	
	V558_LbufSetYuvMode(gJpegContext.header.YUVType);
	V558_LbufSetImageSize(gJpegContext.header.LbufSize);
}

UINT8 DecodeOneFrame(PV558_JPEGBUF pbuf)
{
	gJpegContext.buf = *pbuf;
	WriteQT();
	WriteHT();
	WriteComponents();
	
	gJpegContext.State = V558_JPEG_ISWORKING;
	return DecodeProcess();			//
}

void V558_StartDispVideo(PV558_JPEGBUF pbuf, PV558_JPEG_INDEX pinfo, 
						 PV558_LAYER_PROPERTY proty)
{
	if(pinfo->YUVType < V558_YUV_UNKNOWN)
	{
		memcpy(&gJpegContext.header, pinfo, sizeof(V558_JPEG_INDEX));
		StartDecodeJpg(V558_DISPLAY_VIDEO, proty);
		DecodeOneFrame(pbuf);
	}
}

void V558_DispOneFrame(PV558_JPEGBUF pbuf, PV558_JPEG_INDEX pinfo)
{
	if(pinfo->YUVType < V558_YUV_UNKNOWN)
	{
		memcpy(&gJpegContext.header, pinfo, sizeof(V558_JPEG_INDEX));
		//		JpegDisplayInit();
		DecodeOneFrame(pbuf);
	}
}
/******************************************************************************
Description:
用于显示静止的图像。
Parameters:
1,pbuf:输入的数据块。用于存放要显示的jpeg图像。
2,pinfo:用于存放要显示的jpeg图像的信息。
3,proty:LCD的属性。
Returns:
Null
Remarks:
Null
Example:
UINT8 g_StillBuf[0x10000];
UINT32	g_StillBufOffset;
void TestDisplayStill(void)
{
V558_JPEG_INDEX info;
V558_LAYER_PROPERTY proty;

		proty.DisPoint.x = 0x0;
		proty.DisPoint.y = 0x0;
		proty.DisRect.height = 0x60;
		proty.DisRect.width = 0x80;
		proty.DisRect.left = 0;
		proty.DisRect.top = 0;
		proty.Size.cx = 0x80;
		proty.Size.cy = 0x60;
		
		  g_JpegBuf.ActLen = g_StillBufOffset ;
		  g_JpegBuf.pData = (UINT8 *)g_StillBuf;
		  g_JpegBuf.Len = 0x8000;
		  
			if(V558_JpegParse(&g_JpegBuf, &info) == 0)
			{
			V558_DisplayStill(&g_JpegBuf, &info, &proty);
			}
			}
******************************************************************************/
void V558_DisplayStill(PV558_JPEGBUF pbuf, PV558_JPEG_INDEX pinfo, 
					   PV558_LAYER_PROPERTY proty)
{
	if(pinfo->YUVType <= V558_YUV_400)
	{
		memcpy(&gJpegContext.header, pinfo, sizeof(V558_JPEG_INDEX));
		StartDecodeJpg(V558_DISPLAY_STILL, proty);
		DecodeOneFrame(pbuf);
	}
}


UINT8 HostDecode(PV558_JPEGBUF psrc, PV558_JPEGBUF pdst, PV558_JPEGCALLBACK pcall)
{
	gJpegContext.pcall = pcall;
	gJpegContext.dst = *pdst;
	pdst->ActLen = 0;
	gJpegContext.buf = *psrc;
	
	V558_LbufSetYuvMode(gJpegContext.header.YUVType);
	V558_CtrlSwReset(V558_SW_RESET_JPG);
	V558_JpegSetWorkMode(0xb);
	V558_JpegSetVWC(gJpegContext.header.vwc);
	V558_JpegSetBlockNum(gJpegContext.header.blkcount);
	V558_JbufSetJpegAddr(0);
	V558_JbufSetJpegSize(TOTAL_JBUF_SIZE-1);
	
	WriteQT();
	WriteHT();
	WriteComponents();
	
	gJpegContext.State = V558_JPEG_ISWORKING;
	//	V558_CtrlIntEnable(V558_INT_8BUF_FULL, 1);
	return HostSendJpgData();			//
}

UINT8 FillEncodeParm(V558_SIZE size, V558_SIZE *newsize, UINT8 yuvmode, UINT32 *total)
{
	UINT8 blkcount, compnum = 0x23;
	UINT32 temp, vwc;
	UINT16 comp[3] = {0x120b, 0x5104, 0x5104};

	temp = size.cx;
	temp *= size.cy;
	switch(yuvmode)
	{
	case V558_YUV_422:
	case V558_PYUV_422_YYUV:
	case V558_PYUV_422_YUYV:
	case V558_PYUV_422_UYVY:
		newsize->cx = ((size.cx + 15) >> 4) << 4;
		newsize->cy = ((size.cy + 7) >> 3) << 3;
		blkcount = newsize->cx >> 2;
		vwc = newsize->cx;
		vwc *= newsize->cy;
		vwc >>= 1;
		break;
	case V558_YUV_420:
		newsize->cx = ((size.cx + 15) >> 4) << 4;
		newsize->cy = ((size.cy + 15) >> 4) << 4;
		blkcount = newsize->cx >> 2;
		blkcount += blkcount >> 1;
		vwc = newsize->cx;
		vwc *= newsize->cy;
		vwc >>= 2;
		vwc += vwc >> 1;
		break;
	case V558_YUV_411:
		newsize->cx = ((size.cx + 31) >> 5) << 5;
		newsize->cy = ((size.cy + 7) >> 3) << 3;
		blkcount = newsize->cx >> 3;
		blkcount += blkcount >> 1;
		vwc = newsize->cx;
		vwc *= newsize->cy;
		vwc >>= 2;
		vwc += vwc >> 1;
		break;
	case V558_YUV_400:
		newsize->cx = ((size.cx + 7) >> 3) << 3;
		newsize->cy = ((size.cy + 7) >> 3) << 3;
		blkcount = newsize->cx >> 3;
		vwc = newsize->cx;
		vwc *= newsize->cy;
		vwc >>= 2;
		compnum = 0x11;
		comp[0] = 0x1107;
//			comp[1] = 0;
//			comp[2] = 0;
		break;
	default:
		return JPEGFAILED;
	}

	gJpegContext.mode = V558_ENCODE_JPG;
	V558_CtrlSetWorkMode(V558_MODE_ENCODER);
	V558_CtrlSwReset(V558_SW_RESET_JPG);

	V558_JpegSetWorkMode(2);
	V558_JbufSetJpegAddr(0);
	V558_JbufSetJpegSize(TOTAL_JBUF_SIZE-1);

	V558_JpegSetComponentNum(compnum);
	V558_JpegSetComponentParm(0, comp[0]);
	V558_JpegSetComponentParm(1, comp[1]);
	V558_JpegSetComponentParm(2, comp[2]);
	V558_JpegSetVWC(vwc);
	V558_JpegSetBlockNum(blkcount);
	V558_JpegSetImageSize(size);
	V558_JbufSetJpegAddr(0);
	V558_JbufSetJpegSize(TOTAL_JBUF_SIZE-1);
	*total = vwc << 2;
	V558_CtrlIntEnable(V558_INT_CAP_DONE, 1);
	V558_CtrlIntEnable(V558_INT_CAP_FIFO_FULL, 1);
	return SUCCEED;
}

void SendBlockData(UINT32 offset, UINT32 width, UINT32 rest, UINT8 *buf)
{
	UINT32 m, n;

	if(rest == 0)
		return;
	for(m = 0; m < 8; m++, offset += width << 1)	//Y0 block
	{
		for(n = 0; n < rest; n++)
			V558_JpegWriteDctData(buf[offset + (n << 2)] - 128);
		for(n = rest; n < 8; n++)
			V558_JpegWriteDctData(0);
	}
}

void SendYYUVBlockData(UINT32 offset, UINT32 width, UINT32 rest, UINT8 *buf)
{
	UINT32 m, n, x;
	UINT32 pos = offset;

	if(rest == 0)
		return;
	for(m = 0; m < 8; m++, pos += width << 1)	//Y0 block
	{
		x = rest > 4 ? 4 : rest;
		for(n = 0; n < x; n++)
		{
			V558_JpegWriteDctData(buf[pos + (n << 2)] - 128);
			V558_JpegWriteDctData(buf[pos + (n << 2)+1] - 128);
		}
		for(n = x; n < 4; n++)
		{
			V558_JpegWriteDctData(0);
			V558_JpegWriteDctData(0);
		}
	}
	pos = offset + 16;
	if(rest < 5)
	{
		for(n = 0; n < 8; n++)
			V558_JpegWriteDctData(0);
	}
	else
	{
		for(m = 0; m < 8; m++, pos += width << 1)	//Y1 block
		{
			for(n = 0; n < rest - 4; n++)
			{
				V558_JpegWriteDctData(buf[pos + (n << 2)] - 128);
				V558_JpegWriteDctData(buf[pos + (n << 2)+1] - 128);
			}
			for(n = rest-4; n < 4; n++)
			{
				V558_JpegWriteDctData(0);
				V558_JpegWriteDctData(0);
			}
		}
	}
	pos = offset + 2;
	for(m = 0; m < 8; m++, pos += width << 1)	//U block
	{
		for(n = 0; n < rest; n++)
			V558_JpegWriteDctData(buf[pos + (n << 2)] - 128);
		for(n = rest; n < 8; n++)
			V558_JpegWriteDctData(0);
	}
	pos = offset + 3;
	for(m = 0; m < 8; m++, pos += width << 1)	//V block
	{
		for(n = 0; n < rest; n++)
			V558_JpegWriteDctData(buf[pos + (n << 2)] - 128);
		for(n = rest; n < 8; n++)
			V558_JpegWriteDctData(0);
	}
}

void SendYUYVBlockData(UINT32 offset, UINT32 width, UINT32 rest, UINT8 *buf)
{
	UINT32 m, n, x;
	UINT32 pos = offset;

	if(rest == 0)
		return;
	for(m = 0; m < 8; m++, pos += width << 1)	//Y0 block
	{
		x = rest > 4 ? 4 : rest;
		for(n = 0; n < x; n++)
		{
			V558_JpegWriteDctData(buf[pos + (n << 2)] - 128);
			V558_JpegWriteDctData(buf[pos + (n << 2)+2] - 128);
		}
		for(n = x; n < 4; n++)
		{
			V558_JpegWriteDctData(0);
			V558_JpegWriteDctData(0);
		}
	}
	pos = offset + 16;
	if(rest < 5)
	{
		for(n = 0; n < 8; n++)
			V558_JpegWriteDctData(0);
	}
	else
	{
		for(m = 0; m < 8; m++, pos += width << 1)	//Y1 block
		{
			for(n = 0; n < rest - 4; n++)
			{
				V558_JpegWriteDctData(buf[pos + (n << 2)] - 128);
				V558_JpegWriteDctData(buf[pos + (n << 2)+2] - 128);
			}
			for(n = rest-4; n < 4; n++)
			{
				V558_JpegWriteDctData(0);
				V558_JpegWriteDctData(0);
			}
		}
	}
	pos = offset + 1;
	for(m = 0; m < 8; m++, pos += width << 1)	//U block
	{
		for(n = 0; n < rest; n++)
			V558_JpegWriteDctData(buf[pos + (n << 2)] - 128);
		for(n = rest; n < 8; n++)
			V558_JpegWriteDctData(0);
	}
	pos = offset + 3;
	for(m = 0; m < 8; m++, pos += width << 1)	//V block
	{
		for(n = 0; n < rest; n++)
			V558_JpegWriteDctData(buf[pos + (n << 2)] - 128);
		for(n = rest; n < 8; n++)
			V558_JpegWriteDctData(0);
	}
}

void SendUYVYBlockData(UINT32 offset, UINT32 width, UINT32 rest, UINT8 *buf)
{
	UINT32 m, n, x;
	UINT32 pos = offset;

	if(rest == 0)
		return;
	for(m = 0; m < 8; m++, pos += width << 1)	//Y0 block
	{
		x = rest > 4 ? 4 : rest;
		for(n = 0; n < x; n++)
		{
			V558_JpegWriteDctData(buf[pos + (n << 2)+1] - 128);
			V558_JpegWriteDctData(buf[pos + (n << 2)+3] - 128);
		}
		for(n = x; n < 4; n++)
		{
			V558_JpegWriteDctData(0);
			V558_JpegWriteDctData(0);
		}
	}
	pos = offset + 16;
	if(rest < 5)
	{
		for(n = 0; n < 8; n++)
			V558_JpegWriteDctData(0);
	}
	else
	{
		for(m = 0; m < 8; m++, pos += width << 1)	//Y1 block
		{
			for(n = 0; n < rest - 4; n++)
			{
				V558_JpegWriteDctData(buf[pos + (n << 2)+1] - 128);
				V558_JpegWriteDctData(buf[pos + (n << 2)+3] - 128);
			}
			for(n = rest-4; n < 4; n++)
			{
				V558_JpegWriteDctData(0);
				V558_JpegWriteDctData(0);
			}
		}
	}
	pos = offset;
	for(m = 0; m < 8; m++, pos += width << 1)	//U block
	{
		for(n = 0; n < rest; n++)
			V558_JpegWriteDctData(buf[pos + (n << 2)] - 128);
		for(n = rest; n < 8; n++)
			V558_JpegWriteDctData(0);
	}
	pos = offset + 2;
	for(m = 0; m < 8; m++, pos += width << 1)	//V block
	{
		for(n = 0; n < rest; n++)
			V558_JpegWriteDctData(buf[pos + (n << 2)] - 128);
		for(n = rest; n < 8; n++)
			V558_JpegWriteDctData(0);
	}
}

UINT32 WriteDctData(UINT8 *buf, UINT32 actlen, UINT32 width, V558_SIZE size, UINT8 yuvmode)
{
	UINT32 k = 0, adr = 0, offset;
	UINT32 i, linelength, unit, rest;

	if( (yuvmode == V558_PYUV_422_YYUV) || (yuvmode == V558_PYUV_422_YUYV) || (yuvmode == V558_PYUV_422_UYVY) )
	{
		linelength = width << 4;
		unit = width >> 4;
		rest = width % 16;
		rest >>= 1;
		for(k = 0; k < actlen; k += linelength)
		{
			adr = 0;
			for(i = 0; i < unit; i++, adr += 32)
			{
				switch(yuvmode)
				{
				case V558_PYUV_422_YYUV:
					offset = k + adr;
					SendYYUVBlockData(offset, width, 8, buf);
					break;
				case V558_PYUV_422_YUYV:
					offset = k + adr;
					SendYUYVBlockData(offset, width, 8, buf);
					break;
				case V558_PYUV_422_UYVY:
					offset = k + adr;
					SendUYVYBlockData(offset, width, 8, buf);
				default:
					break;
				}
			}
			switch(yuvmode)
			{
			case V558_PYUV_422_YYUV:
				offset = k + adr;
				SendYYUVBlockData(offset, width, rest, buf);
				break;
			case V558_PYUV_422_YUYV:

⌨️ 快捷键说明

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