📄 vjpeg.c
字号:
offset = k + adr;
SendYUYVBlockData(offset, width, rest, buf);
break;
case V558_PYUV_422_UYVY:
offset = k + adr;
SendUYVYBlockData(offset, width, rest, buf);
default:
break;
}
}
return k;
}
while(actlen--)
V558_JpegWriteDctData(buf[k++] - 128);
return k;
}
/******************************************************************************
Description:
将以8*8 block输入的YUV数据进行encode。
Parameters:
1,psrc:输入的数据块。用于存放将要encode的以8*8 block 排列的YUV数据。
2,pdst:输出的数据块。用于存放encode之后的图像数据
3,pcall:回调指针。
4,psize:将要转换的原始数据的图像大小。
5,yuvmode:将要转换数据的图像格式。支持,
YUV422,YUV420,YUV411,YUV400, //block type
V558_PYUV_422_YYUV, //point type
V558_PYUV_422_YUYV,
V558_PYUV_422_UYVY。
Returns:
如果encode成功,返回0,否则,返回0xff。
Remarks:
Example:
UINT8 g_dataBuf[0x10000];
UINT8 g_ImageBuf[0x30000];
UINT32 g_bufoffset;
void TestEncode(void)
{
V558_JPEGBUF src, dst;
V558_SIZE size,NewSize;
UINT8 mode;
size.cx = 160;
size.cy = 120;
mode = V558_PYUV_422_YYUV;
g_bufoffset = LoadImageFile("/flash/3.jpg", g_dataBuf,0x30000);
src.ActLen = g_bufoffset;
src.Len = 0x30000;
src.pData = g_dataBuf;
g_bufoffset = 0;
dst.ActLen = g_bufoffset;
dst.Len = 0x30000;
dst.pData = g_ImageBuf;
V558_HostEncode(&src, &dst, JpegNote1, size,mode );
}
******************************************************************************/
UINT8 V558_HostEncode(PV558_JPEGBUF psrc, PV558_JPEGBUF pdst, PV558_JPEGCALLBACK pcall,
V558_SIZE size, UINT8 yuvmode)
{
UINT32 total, temp, k;
V558_SIZE newsize;
if(FillEncodeParm(size, &newsize, yuvmode, &total) != SUCCEED)
return JPEGFAILED;
gJpegContext.pcall = pcall;
gJpegContext.buf = *pdst;
pdst->ActLen = 0;
psrc->ActLen = psrc->ActLen > total ?total : psrc->ActLen ;
V558_JpegStartEncoder();
temp = 0;
do{
temp++;
}while( ((V558_JpegGetStatus() & 8) == 0) && (temp < 0x2000) );
// if(temp == 0x20000)
// return JPEGFAILED;
do{
temp = total;
if(total > psrc->ActLen)
temp = psrc->ActLen;
k = WriteDctData(psrc->pData, psrc->ActLen, size.cx, newsize, yuvmode);
total -= k;
if(total)
pcall(MSG_WRITE_JPGDATA, psrc);
}while(total);
return SUCCEED;
}
UINT8 V558_HostDecode(PV558_JPEGBUF psrc, PV558_JPEGBUF pdst, UINT8 decdatatype, PV558_JPEG_INDEX pinfo, PV558_JPEGCALLBACK pcall)
{
if(pinfo->YUVType > V558_YUV_400)
return JPEGFAILED;
memcpy(&gJpegContext.header, pinfo, sizeof(V558_JPEG_INDEX));
gJpegContext.mode = V558_DECODE_ONLY;
gJpegContext.decdatatype = decdatatype;
gJpegContext.decMaxlinesum = pinfo->ImageSize.cy;
gJpegContext.decline = 0;
gJpegContext.declinesum = 0;
V558_CtrlSetWorkMode(V558_MODE_DECODER);
V558_CtrlDisableBRC();
V558_LbufSetWorkmode(0);
V558_LbufSetImageSize(gJpegContext.header.JpgSize);
gJpegContext.decodewidth = pinfo->ImageSize.cx;
gJpegContext.decMaxline = (UINT16) ((pdst->Len /( gJpegContext.decodewidth <<4))<<3);
HostDecode(psrc, pdst, pcall);
return SUCCEED;
}
UINT8 V558_HostDecodeIppSize(PV558_JPEGBUF psrc, PV558_JPEGBUF pdst, UINT8 decdatatype, PV558_JPEG_INDEX pinfo, PV558_JPEGCALLBACK pcall, PV558_SIZE psize, UINT16 width)
{
V558_POINT pt = {0, 0};
V558_SIZE tempsize;
if(pinfo->YUVType > V558_YUV_400)
return JPEGFAILED;
memcpy(&gJpegContext.header, pinfo, sizeof(V558_JPEG_INDEX));
gJpegContext.mode = V558_DECODE_IPP;
gJpegContext.declinesum = 0;
gJpegContext.decline = 0;
gJpegContext.decdatatype = decdatatype;
V558_CtrlSetWorkMode(V558_MODE_DECODER);
V558_CtrlDisableBRC();
V558_CtrlSwReset(V558_SW_RESET_IPP);
tempsize.cx = ( psize->cx > gJpegContext.header.ImageSize.cx) ? gJpegContext.header.ImageSize.cx : psize->cx;
tempsize.cy = ( psize->cy > gJpegContext.header.ImageSize.cy) ? gJpegContext.header.ImageSize.cy : psize->cy;
V558_IppDisplay(gJpegContext.header.JpgSize, pt, tempsize, width);
gJpegContext.decMaxlinesum = V558_IppGetDispHeight();
V558_IppDisablePrefilter();
gJpegContext.decodewidth = V558_IppGetDispWidth();
V558_LbufSetWorkmode(8);
V558_LbufSetImageSize(gJpegContext.header.JpgSize);
gJpegContext.decMaxline = (UINT16) ((pdst->Len /( gJpegContext.decodewidth <<4))<<3);
HostDecode(psrc, pdst, pcall);
return SUCCEED;
}
UINT8 V558_HostDecodeIpp(PV558_JPEGBUF psrc, PV558_JPEGBUF pdst, UINT8 decdatatype, PV558_JPEG_INDEX pinfo,
PV558_JPEGCALLBACK pcall, UINT16 width)
{
return V558_HostDecodeIppSize(psrc, pdst, decdatatype, pinfo, pcall, &pinfo->ImageSize, width);
}
/******************************************************************************
Description:
Get the minimal ipp width when decode with ipp.
Parameters:
1,pinfo: the pointer of jpeg image information.
Returns:
Return the minimal width.
Remarks:
Call this function to check the decode ipp width before decode with ipp
*******************************************************************************/
UINT16 V558_GetDecodeIppMinWidth(PV558_JPEG_INDEX pinfo)
{
UINT16 temp;
temp = (pinfo->ImageSize.cx>>3);
return temp;
}
UINT8 V558_HostDecodeLcdIF(PV558_JPEGBUF psrc, PV558_JPEGBUF pdst, UINT8 decdatatype, PV558_JPEG_INDEX pinfo, PV558_JPEGCALLBACK pcall,
PV558_LAYER_PROPERTY proty)
{
return V558_HostDecodeLcdIFSize(psrc, pdst, decdatatype, pinfo, pcall, &pinfo->ImageSize, proty);
}
UINT8 V558_HostDecodeLcdIFSize(PV558_JPEGBUF psrc, PV558_JPEGBUF pdst, UINT8 decdatatype, PV558_JPEG_INDEX pinfo,
PV558_JPEGCALLBACK pcall, PV558_SIZE psize, PV558_LAYER_PROPERTY proty)
{
V558_POINT pt = {0, 0};
V558_SIZE tempsize;
if(pinfo->YUVType >= V558_YUV_UNKNOWN)
return JPEGFAILED;
memcpy(&gJpegContext.header, pinfo, sizeof(V558_JPEG_INDEX));
gJpegContext.mode = V558_DECODE_LCDIF;
gJpegContext.decline = 0;
gJpegContext.decdatatype = decdatatype;
V558_CtrlSetWorkMode(V558_MODE_DECODER_FRAME);
V558_CtrlDisableBRC();
V558_CtrlSwReset(V558_SW_RESET_IPP);
tempsize.cx = ( psize->cx > gJpegContext.header.ImageSize.cx) ? gJpegContext.header.ImageSize.cx : psize->cx;
tempsize.cy = ( psize->cy > gJpegContext.header.ImageSize.cy) ? gJpegContext.header.ImageSize.cy : psize->cy;
V558_IppDisplay(gJpegContext.header.LbufSize, pt,
tempsize, proty->Size.cx);
V558_IppDisablePrefilter();
V558_IppGetDispSize(&(proty->Size));
V558_LcdSetALProperty(proty);
gJpegContext.decMaxlinesum = proty->Size.cy;
gJpegContext.decline = 0;
gJpegContext.declinesum = 0;
gJpegContext.decodewidth = proty->DisRect.width;
V558_LbufSetWorkmode(0x14);
V558_LbufSetImageSize(gJpegContext.header.LbufSize);
gJpegContext.decMaxline = (UINT16)((pdst->Len /( gJpegContext.decodewidth <<4))<<3);
HostDecode(psrc, pdst, pcall);
return SUCCEED;
}
void V558_AdjustCaptureSize(V558_SIZE size)
{
UINT32 vwc;
UINT8 ratio;
switch(gJpegContext.mode)
{
case V558_JPEG_IDEL:
case V558_CAPTURE_STILLBRC:
case V558_CAPTURE_STILLBRC_THUMBNAIL:
case V558_CAPTURE_FRAME:
case V558_CAPTURE_FRAMEVIDEO:
case V558_CAPTURE_VIDEO:
V558_JpegSetImageSize(size);
size.cx += 15;
size.cx >>= 4;
size.cx <<= 4;
size.cy += 7;
size.cy >>= 3;
size.cy <<= 3;
V558_LbufSetImageSize(size);
vwc = size.cx;
vwc *= size.cy;
vwc >>= 1;
V558_JpegSetVWC(vwc);
if(gJpegContext.entcr)
{
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;
}
}
break;
case V558_DISPLAY_STILL:
case V558_DISPLAY_THUMBNAIL:
case V558_DISPLAY_VIDEO:
break;
default:
break;
}
}
/********************************************************************************
LBUF module function
*********************************************************************************/
UINT8 V558_LbufOpen(void)
{
V558_CtrlIntAdd(V558_INT_8BUF_FULL, _ISR_LbufFull);
V558_CtrlIntEnable(V558_INT_8BUF_FULL, 0);
return SUCCEED;
}
/********************************************************************************
JBUF module function
*********************************************************************************/
void ReadCapStillBuf(void)
{
UINT32 len;
if(&gJpegContext.buf)
{
len = V558_JbufGetBiuAccLength() + 1;
V558_ReadSram(JBUF_BASEADD, gJpegContext.buf.pData + gJpegContext.buf.ActLen, len);
gJpegContext.buf.ActLen += len;
}
}
/******************************************************************************
Description:
用于读取thumbnail。
Parameters:
1,pbuf:输出的数据块。用于存放生成的thumbnail数据。
2,size:thumbnail的大小。
Returns:
Null
Remarks:
Null
Example:
UINT8 g_ThumbBuf[0x2000];
void TestJbufReadThumb(void)
{
V558_JPEGBUF JpegBuf;
V558_SIZE g_ThumbSize;
JpegBuf.ActLen = 0;
JpegBuf.Len = 0x8000;
JpegBuf.pData = g_ThumbBuf;
g_ThumbSize.cx = 40;
g_ThumbSize.cy = 30;
V558_JbufReadThumb(&JpegBuf, &g_ThumbSize);
}
******************************************************************************/
/*void V558_JbufReadThumb(PV558_JPEGBUF pbuf, V558_SIZE *size)
{
UINT16 i,j;
UINT32 adr;
UINT8* ptr=pbuf->pData;
UINT8 temp0,temp1,temp2,temp3;
ptr = pbuf->pData;
pbuf->ActLen = 0;
*size = gJpegContext.thumb;
for(j=0; j<gJpegContext.thumb.cy ; j++)
{
adr = JBUF_BASEADD + gJpegContext.thumbadr + ((j * gJpegContext.thumb.cx)<<1);
V558_CtrlMultiClrAutoEnable();
V558_ReadSram(adr, ptr, gJpegContext.thumb.cx << 1);
V558_CtrlMultiClrAutoDisable();
for( i = 0 ; i < (gJpegContext.thumb.cx>>1) ; i ++)
{
adr = (i<<2);
temp0 = *(ptr+adr);
temp1 = *(ptr+adr+1);
temp2 = *(ptr+adr+2);
temp3 = *(ptr+adr+3);
*(ptr+adr) = temp1;
*(ptr+adr+1) = temp3;
*(ptr+adr+2) = temp0;
*(ptr+adr+3) = temp2;
}
ptr += (gJpegContext.thumb.cx << 1);
}
pbuf->ActLen = (gJpegContext.thumb.cx * gJpegContext.thumb.cy) << 1;
}*/
void V558_JbufReadThumb(PV558_JPEGBUF pbuf, V558_SIZE *size)
{
UINT16 i,j;
UINT32 adr;
UINT8* ptr=pbuf->pData;
UINT8 temp0,temp1,temp2,temp3;
ptr = pbuf->pData;
pbuf->ActLen = 0;
*size = gJpegContext.thumb;
V558_SetReg(V558_REG_BIU_MUL_CLR_AUTO, 0x1);
for(j=0; j<gJpegContext.thumb.cy ; j++)
{
adr = JBUF_BASEADD + gJpegContext.thumbadr + ((j * gJpegContext.thumb.cx)<<1);
V558_ReadSram(adr, ptr, gJpegContext.thumb.cx << 1);
for( i = 0 ; i < (gJpegContext.thumb.cx>>1) ; i ++)
{
adr = (i<<2);
temp0 = *(ptr+adr);
temp1 = *(ptr+adr+1);
temp2 = *(ptr+adr+2);
temp3 = *(ptr+adr+3);
*(ptr+adr) = temp1;
*(ptr+adr+1) = temp3;
*(ptr+adr+2) = temp0;
*(ptr+adr+3) = temp2;
}
ptr += (gJpegContext.thumb.cx << 1);
}
V558_SetReg(V558_REG_BIU_MUL_CLR_AUTO, 0);
pbuf->ActLen = (gJpegContext.thumb.cx * gJpegContext.thumb.cy) << 1;
}
void _ISR_CaptureDone(void)
{
PV558_JPEGCALLBACK pcall;
UINT8 mode;
V558_JPEGBUF buf;
V558_CtrlIntEnable(V558_INT_CAP_DONE, 0);
V558_CtrlIntEnable(V558_INT_CAP_FIFO_FULL, 0);
if(!gJpegContext.pcall)
return;
switch(gJpegContext.mode)
{
case V558_CAPTURE_FRAME:
case V558_CAPTURE_FRAMEVIDEO:
V558_LcdSetIFControl(gJpegContext.lcdctrl);
break;
case V558_CAPTURE_STILLBRC:
case V558_CAPTURE_STILLBRC_THUMBNAIL:
case V558_CAPTURE_VIDEO:
V558_IppSelectPrefilter(0);
break;
default:
break;
}
mode = gJpegContext.mode;
gJpegContext.mode = V558_JPEG_IDEL;
gJpegContext.State = V558_JPEG_INITED;
pcall = gJpegContext.pcall;
gJpegContext.pcall = NULL;
switch(mode)
{
case V558_CAPTURE_FRAME:
case V558_CAPTURE_STILLBRC:
case V558_CAPTURE_STILLBRC_THUMBNAIL:
buf.ActLen = 0;
pcall(MSG_JPEG_HEADER, &buf);
break;
default:
break;
}
ReadCapStillBuf();
pcall(MSG_CAPTURE_DONE, &gJpegContext.buf);
}
void _ISR_CapFifoFull(void)
{
UINT32 length;
if(!gJpegContext.pcall)
return;
if(!gJpegContext.buf.pData)
return;
length = TOTAL_JBUF_SIZE;
if(gJpegContext.mode ==V558_CAPTURE_STILLBRC_THUMBNAIL)
length = TOTAL_JBUF_SIZE - DEFAULT_THUMB_SIZE;
length = (length>>1);
V558_ReadSram(JBUF_BASEADD, gJpegContext.buf.pData + gJpegContext.buf.ActLen, length);
gJpegContext.buf.ActLen += length;
if(gJpegContext.buf.ActLen > gJpegContext.buf.Len - length)
{
gJpegContext.pcall(MSG_JBUF_FULL, &gJpegContext.buf);
gJpegContext.buf.ActLen = 0;
}
}
void V558_JbufGeInit(void)
{
V558_JbufSetSourceAddr(DEFAULT_SRC_ADR);
V558_JbufSetDestAddr(DEFAULT_DEST_ADR);
V558_JbufSetSourceSize(DEFAULT_SRC_SIZE - 1);
V558_JbufSetDestSize(DEFAULT_DEST_SIZE - 1);
}
UINT8 V558_JbufOpen(void)
{
V558_JbufGeInit();
V558_CtrlIntEnable(V558_INT_CAP_DONE, 0);
V558_CtrlIntEnable(V558_INT_CAP_FIFO_FULL, 0);
V558_CtrlIntAdd(V558_INT_CAP_DONE, _ISR_CaptureDone);
V558_CtrlIntAdd(V558_INT_CAP_FIFO_FULL, _ISR_CapFifoFull);
return SUCCEED;
}
/**********************************
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -