📄 camera.cpp
字号:
break;
case 3:
buffer_y = (U8 *)s2443CAM->CICOYSA4;
buffer_cb = (U8 *)s2443CAM->CICOCBSA4;
buffer_cr = (U8 *)s2443CAM->CICOCRSA4;
break;
default :
buffer_y = (U8 *)s2443CAM->CICOYSA1;
buffer_cb = (U8 *)s2443CAM->CICOCBSA1;
buffer_cr = (U8 *)s2443CAM->CICOCRSA1;
break;
}
}
buffer_y += VIRTUAL_ADDR_OFFSET;
buffer_cb += VIRTUAL_ADDR_OFFSET;
buffer_cr += VIRTUAL_ADDR_OFFSET;
RETAILMSG(MSG_EN_1,(_T("buffer_y = 0x%x\r\n"), buffer_y));
RETAILMSG(MSG_EN_1,(_T("buffer_cb = 0x%x\r\n"), buffer_cb));
RETAILMSG(MSG_EN_1,(_T("buffer_cr = 0x%x\r\n"), buffer_cr));
if (image_size == 1) // QCIF
{
yuvinfo.frame_width = QCIF_XSIZE;
yuvinfo.frame_height = QCIF_YSIZE;
}
else if (image_size == 2) // CIF
{
yuvinfo.frame_width = CIF_XSIZE;
yuvinfo.frame_height = CIF_YSIZE;
}
if (temp == frame_bank_prev) yuvinfo.frame_stamp = frame_timestamp_prev;
else
{
yuvinfo.frame_stamp = GetTickCount();
frame_timestamp_prev = yuvinfo.frame_stamp;
frame_bank_prev = temp;
}
RETAILMSG(MSG_EN_1,(_T("pBufOut 0 offset = 0x%x\r\n"), pImage));
memcpy(pImage, &yuvinfo, sizeof(YUVINFO));
pImage += sizeof(YUVINFO);
RETAILMSG(MSG_EN_1,(_T("pBufOut Y = 0x%x\r\n"), pImage));
memcpy(pImage, buffer_y, Y_size);
pImage += (Y_size);
RETAILMSG(MSG_EN_1,(_T("pBufOut cb = 0x%x\r\n"), pImage));
memcpy(pImage, buffer_cb, C_size);
pImage += C_size;
RETAILMSG(MSG_EN_1,(_T("pBufOut cr = 0x%x\r\n"), pImage));
memcpy(pImage, buffer_cr, C_size);
// pBufOut += (size_x*size_y)/4;
// RETAILMSG(MSG_EN_1,(TEXT("1:buffer_y:0x%x,buffer_cb:0x%x,buffer_cr:0x%x\r\n"),buffer_y,buffer_cb,buffer_cr));
//s2443IOP->GPFDAT |= (1<<6);
Tick_COPY_FRAME = GetTickCount();
RETAILMSG(MSG_EN_1,(_T("COPY_Tick = %d\r\n"), (Tick_COPY_FRAME-Tick_GET_FRAME_CUR)));
RETAILMSG(MSG_EN_1,(_T("Frame_Tick = %d\r\n"), (Tick_GET_FRAME_CUR-Tick_GET_FRAME_PREV)));
// RETAILMSG(1,(_T("Tick_COPY_FRAME = %d\r\n"), Tick_COPY_FRAME));
// RETAILMSG(1,(_T("Tick_GET_FRAME_PREV = %d\r\n"), Tick_GET_FRAME_PREV));
// RETAILMSG(1,(_T("Tick_GET_FRAME_CUR = %d\r\n"), Tick_GET_FRAME_CUR));
}
void Samsung_camcoder(U8 *pBufOut)
{
U8 *pImage;
PINGPONG caminfo;
pImage = pBufOut;
if( codec_flag )
{
caminfo.flag = 1;
caminfo.y_address = y_address;
caminfo.cb_address = cb_address;
caminfo.cr_address = cr_address;
memcpy(pImage, &caminfo, sizeof(PINGPONG));
codec_flag = 0;
}
}
void Samsung_camcoder_pr(U8 *pBufOut)
{
U8 *pImage;
PINGPONG_PR prinfo;
pImage = pBufOut;
if ( rgb_flag )
{
prinfo.flag = 1;
prinfo.rgb_address = rgb_address;
memcpy(pImage, &prinfo, sizeof(PINGPONG_PR));
rgb_flag = 0;
}
}
void Buffer_codec_info_update()
{
U32 Y_size, C_size, P_size;
int temp;
unsigned int buffer_y, buffer_cb, buffer_cr;
if ( image_size == 1 )
Y_size = QCIF_XSIZE*QCIF_YSIZE;
else if ( image_size == 2 )
Y_size = CIF_XSIZE*CIF_YSIZE;
C_size = Y_size/4;
P_size = Y_size + C_size*2;
temp = (s2443CAM->CICOSTATUS>>26)&3;
temp = (temp + 3) % 4;
RETAILMSG(MSG_EN_2,(_T("codec index = %d, size %d\r\n"), temp, image_size));
switch (temp)
{
case 0:
buffer_y = s2443CAM->CICOYSA1;
buffer_cb = s2443CAM->CICOCBSA1;
buffer_cr = s2443CAM->CICOCRSA1;
break;
case 1:
buffer_y = s2443CAM->CICOYSA2;
buffer_cb = s2443CAM->CICOCBSA2;
buffer_cr = s2443CAM->CICOCRSA2;
break;
case 2:
buffer_y = s2443CAM->CICOYSA3;
buffer_cb = s2443CAM->CICOCBSA3;
buffer_cr = s2443CAM->CICOCRSA3;
break;
case 3:
buffer_y = s2443CAM->CICOYSA4;
buffer_cb = s2443CAM->CICOCBSA4;
buffer_cr = s2443CAM->CICOCRSA4;
break;
default :
buffer_y = s2443CAM->CICOYSA1;
buffer_cb = s2443CAM->CICOCBSA1;
buffer_cr = s2443CAM->CICOCRSA1;
break;
}
buffer_y += VIRTUAL_ADDR_OFFSET;
buffer_cb += VIRTUAL_ADDR_OFFSET;
buffer_cr += VIRTUAL_ADDR_OFFSET;
#if 0
RETAILMSG(1,(_T("buffer_y = 0x%x\r\n"), buffer_y));
RETAILMSG(1,(_T("buffer_cb = 0x%x\r\n"), buffer_cb));
RETAILMSG(1,(_T("buffer_cr = 0x%x\r\n"), buffer_cr));
#endif
if( codec_flag ) RETAILMSG(MSG_EN_1,(_T("Buffer is not read\r\n")));
codec_flag = 1;
y_address = buffer_y;
cb_address = buffer_cb;
cr_address = buffer_cr;
}
void Buffer_preview_info_update()
{
// U32 Y_size;
int temp;
unsigned int buffer_rgb;
/*
if ( image_size == 1 )
Y_size = QCIF_XSIZE*QCIF_YSIZE;
else if ( image_size == 2 )
Y_size = CIF_XSIZE*CIF_YSIZE;
*/
temp = (s2443CAM->CIPRSTATUS>>26)&3;
temp = (temp + 2) % 4;
RETAILMSG(MSG_EN_2,(_T("preview index = %d, size %d\r\n"), temp, image_size));
switch (temp)
{
case 0:
buffer_rgb = s2443CAM->CIPRCLRSA1;
break;
case 1:
buffer_rgb = s2443CAM->CIPRCLRSA2;
break;
case 2:
buffer_rgb = s2443CAM->CIPRCLRSA3;
break;
case 3:
buffer_rgb = s2443CAM->CIPRCLRSA4;
break;
default :
buffer_rgb = s2443CAM->CIPRCLRSA1;
break;
}
RETAILMSG(MSG_EN_1,(_T("buffer_rgb[PHY] = 0x%x\r\n"), buffer_rgb));
buffer_rgb += VIRTUAL_ADDR_OFFSET;
#if 1
RETAILMSG(MSG_EN_1,(_T("buffer_rgb = 0x%x\r\n"), buffer_rgb));
#endif
if( rgb_flag ) RETAILMSG(MSG_EN_1,(_T("Prev Buffer is not read\r\n")));
rgb_flag = 1;
rgb_address = buffer_rgb;
}
void CamInit(U32 CoDstWidth, U32 CoDstHeight, U32 PrDstWidth, U32 PrDstHeight,
U32 WinHorOffset, U32 WinVerOffset, U32 CoFrameBuffer, U32 PrFrameBuffer)
{
U32 WinOfsEn;
U32 divisor, multiplier;
U32 MainBurstSizeY, RemainedBurstSizeY, MainBurstSizeC, RemainedBurstSizeC, MainBurstSizeRGB, RemainedBurstSizeRGB;
U32 H_Shift, V_Shift, PreHorRatio, PreVerRatio, MainHorRatio, MainVerRatio;
U32 SrcWidth, SrcHeight;
U32 ScaleUp_H_Co, ScaleUp_V_Co, ScaleUp_H_Pr, ScaleUp_V_Pr;
WinHorOffset = 0;
WinVerOffset = 0;
//constant for calculating codec dma address
if(CAM_CODEC_OUTPUT)
divisor=2; //CCIR-422
else
divisor=4; //CCIR-420
//constant for calculating preview dma address
if(CAM_PVIEW_OUTPUT)
multiplier=4;
else
multiplier=2;
if(WinHorOffset==0 && WinVerOffset==0)
WinOfsEn=0;
else
WinOfsEn=1;
SrcWidth=CAM_SRC_HSIZE-WinHorOffset*2;
SrcHeight=CAM_SRC_VSIZE-WinVerOffset*2;
if(SrcWidth>=CoDstWidth) ScaleUp_H_Co=0; //down
else ScaleUp_H_Co=1; //up
if(SrcHeight>=CoDstHeight) ScaleUp_V_Co=0;
else ScaleUp_V_Co=1;
if(SrcWidth>=PrDstWidth) ScaleUp_H_Pr=0; //down
else ScaleUp_H_Pr=1; //up
if(SrcHeight>=PrDstHeight) ScaleUp_V_Pr=0;
else ScaleUp_V_Pr=1;
////////////////// common control setting
s2443CAM->CIGCTRL |= (1<<26)|(0<<27); // inverse PCLK, test pattern
s2443CAM->CIWDOFST = (1<<30)|(0xf<<12); // clear overflow
s2443CAM->CIWDOFST = 0;
s2443CAM->CIWDOFST=(WinOfsEn<<31)|(WinHorOffset<<16)|(WinVerOffset);
#if(CIS_TYPE == CIS_S5X3A1)
s2443CAM->CISRCFMT=(CAM_ITU601<<31)|(0<<30)|(0<<29)|(CAM_SRC_HSIZE<<16)|(CAM_ORDER_YCBYCR<<14)|(CAM_SRC_VSIZE);
#elif(CIS_TYPE == CIS_S5K3AA)
s2443CAM->CISRCFMT=(CAM_ITU601<<31)|(0<<30)|(0<<29)|(CAM_SRC_HSIZE<<16)|(CAM_ORDER_YCRYCB<<14)|(CAM_SRC_VSIZE);
#elif(CIS_TYPE == CIS_S5K3BAFB)
s2443CAM->CISRCFMT=(CAM_ITU601<<31)|(0<<30)|(0<<29)|(CAM_SRC_HSIZE<<16)|(CAM_ORDER_YCBYCR<<14)|(CAM_SRC_VSIZE);
#endif
////////////////// codec port setting
s2443CAM->CICOYSA1=CoFrameBuffer;
s2443CAM->CICOYSA2=s2443CAM->CICOYSA1+CoDstWidth*CoDstHeight+2*CoDstWidth*CoDstHeight/divisor;
if(CoDstWidth*CoDstHeight < 655360) // Codec Max. Size = 1280*1024 Above sXGA, use only 2 memory of the 4 pingpong memory
{
s2443CAM->CICOYSA3=s2443CAM->CICOYSA2+CoDstWidth*CoDstHeight+2*CoDstWidth*CoDstHeight/divisor;
s2443CAM->CICOYSA4=s2443CAM->CICOYSA3+CoDstWidth*CoDstHeight+2*CoDstWidth*CoDstHeight/divisor;
}
else
{
s2443CAM->CICOYSA3=s2443CAM->CICOYSA1;
s2443CAM->CICOYSA4=s2443CAM->CICOYSA2;
}
s2443CAM->CICOCBSA1=s2443CAM->CICOYSA1+CoDstWidth*CoDstHeight;
s2443CAM->CICOCBSA2=s2443CAM->CICOYSA2+CoDstWidth*CoDstHeight;
s2443CAM->CICOCBSA3=s2443CAM->CICOYSA3+CoDstWidth*CoDstHeight;
s2443CAM->CICOCBSA4=s2443CAM->CICOYSA4+CoDstWidth*CoDstHeight;
s2443CAM->CICOCRSA1=s2443CAM->CICOCBSA1+CoDstWidth*CoDstHeight/divisor;
s2443CAM->CICOCRSA2=s2443CAM->CICOCBSA2+CoDstWidth*CoDstHeight/divisor;
s2443CAM->CICOCRSA3=s2443CAM->CICOCBSA3+CoDstWidth*CoDstHeight/divisor;
s2443CAM->CICOCRSA4=s2443CAM->CICOCBSA4+CoDstWidth*CoDstHeight/divisor;
g_CodecFrameSize = CoDstWidth*CoDstHeight+2*CoDstWidth*CoDstHeight/divisor;
s2443CAM->CICOTRGFMT=(CAM_CODEC_IN_422<<31)|(CAM_CODEC_OUTPUT<<30)|(CoDstWidth<<16)|(CAM_FLIP_NORMAL<<14)|(CoDstHeight);
CalculateBurstSize(CoDstWidth, &MainBurstSizeY, &RemainedBurstSizeY);
CalculateBurstSize(CoDstWidth/2, &MainBurstSizeC, &RemainedBurstSizeC);
s2443CAM->CICOCTRL=(MainBurstSizeY<<19)|(RemainedBurstSizeY<<14)|(MainBurstSizeC<<9)|(RemainedBurstSizeC<<4);
CalculatePrescalerRatioShift(SrcWidth, CoDstWidth, &PreHorRatio, &H_Shift);
CalculatePrescalerRatioShift(SrcHeight, CoDstHeight, &PreVerRatio, &V_Shift);
MainHorRatio=(SrcWidth<<8)/(CoDstWidth<<H_Shift);
MainVerRatio=(SrcHeight<<8)/(CoDstHeight<<V_Shift);
s2443CAM->CICOSCPRERATIO=((10-H_Shift-V_Shift)<<28)|(PreHorRatio<<16)|(PreVerRatio);
s2443CAM->CICOSCPREDST=((SrcWidth/PreHorRatio)<<16)|(SrcHeight/PreVerRatio);
s2443CAM->CICOSCCTRL=(CAM_SCALER_BYPASS_OFF<<31)|(ScaleUp_H_Co<<30)|(ScaleUp_V_Co<<29)|(MainHorRatio<<16)|(1<<15)|(MainVerRatio);
s2443CAM->CICOTAREA=CoDstWidth*CoDstHeight;
///////////////// preview port setting
s2443CAM->CIPRCLRSA1=PrFrameBuffer;
s2443CAM->CIPRCLRSA2=s2443CAM->CIPRCLRSA1+PrDstWidth*PrDstHeight*multiplier;
s2443CAM->CIPRCLRSA3=s2443CAM->CIPRCLRSA2+PrDstWidth*PrDstHeight*multiplier;
s2443CAM->CIPRCLRSA4=s2443CAM->CIPRCLRSA3+PrDstWidth*PrDstHeight*multiplier;
/*
if(CIS_TYPE == CIS_S5X3A1)
s2443CAM->CIPRTRGFMT=(PrDstWidth<<16)|(CAM_FLIP_YAXIS<<14)|(PrDstHeight);
else
s2443CAM->CIPRTRGFMT=(PrDstWidth<<16)|(CAM_FLIP_NORMAL<<14)|(PrDstHeight);*/
s2443CAM->CIPRTRGFMT=(2<<30)|(PrDstWidth<<16)|(CAM_FLIP_XAXIS<<14)|(PrDstHeight);
if (CAM_PVIEW_OUTPUT==CAM_RGB24B)
CalculateBurstSize(PrDstWidth*4, &MainBurstSizeRGB, &RemainedBurstSizeRGB);
else // RGB16B
CalculateBurstSize(PrDstWidth*2, &MainBurstSizeRGB, &RemainedBurstSizeRGB);
s2443CAM->CIPRCTRL=(MainBurstSizeRGB<<19)|(RemainedBurstSizeRGB<<14);
CalculatePrescalerRatioShift(SrcWidth, PrDstWidth, &PreHorRatio, &H_Shift);
CalculatePrescalerRatioShift(SrcHeight, PrDstHeight, &PreVerRatio, &V_Shift);
MainHorRatio=(SrcWidth<<8)/(PrDstWidth<<H_Shift);
MainVerRatio=(SrcHeight<<8)/(PrDstHeight<<V_Shift);
s2443CAM->CIPRSCPRERATIO=((10-H_Shift-V_Shift)<<28)|(PreHorRatio<<16)|(PreVerRatio);
s2443CAM->CIPRSCPREDST=((SrcWidth/PreHorRatio)<<16)|(SrcHeight/PreVerRatio);
s2443CAM->CIPRSCCTRL=(1<<31)|(CAM_RGB16B<<30)|(ScaleUp_H_Pr<<29)|(ScaleUp_V_Pr<<28)|(MainHorRatio<<16)|(1<<15)|(MainVerRatio);
s2443CAM->CIPRTAREA= PrDstWidth*PrDstHeight;
s2443CAM->CIMSCTRL &= ~(1<<2);
// LJY, added 040615
// initialization for buffer addresses
y_address = s2443CAM->CICOYSA1;
cb_address = s2443CAM->CICOCBSA1;
cr_address = s2443CAM->CICOCRSA1;
rgb_address = s2443CAM->CIPRCLRSA1;
}
void SetImageEffect(int effectType)
{
s2443CAM->CIIMGEFF &= ~(7<<26);
if(effectType >=0 && effectType <=6)
{
s2443CAM->CIIMGEFF |= (effectType <<26);
}
}
//
//
// Authur : JJG 06.07.28
// purpose : set MSDMA shows CODEC
//
//
//
void SetMSDMAView(U32 MSDMAWidth, U32 MSDMAHeight, U32 PrDstWidth, U32 PrDstHeight)
{
U32 ScaleUp_H_Pr, ScaleUp_V_Pr;
U32 H_Shift, V_Shift, PreHorRatio, PreVerRatio, MainHorRatio, MainVerRatio;
if(MSDMAWidth>=PrDstWidth) ScaleUp_H_Pr=0; //down
else ScaleUp_H_Pr=1; //up
if(MSDMAHeight>=PrDstHeight) ScaleUp_V_Pr=0;
else ScaleUp_V_Pr=1;
CalculatePrescalerRatioShift(MSDMAWidth, PrDstWidth, &PreHorRatio, &H_Shift);
CalculatePrescalerRatioShift(MSDMAHeight, PrDstHeight, &PreVerRatio, &V_Shift);
MainHorRatio=(MSDMAWidth<<8)/(PrDstWidth<<H_Shift);
MainVerRatio=(MSDMAHeight<<8)/(PrDstHeight<<V_Shift);
Camif_Capture(CAPTURE_OFF, CAPTURE_OFF);
s2443CAM->CIPRSCPRERATIO=((10-H_Shift-V_Shift)<<28)|(PreHorRatio<<16)|(PreVerRatio);
s2443CAM->CIPRSCPREDST=((MSDMAWidth/PreHorRatio)<<16)|(MSDMAHeight/PreVerRatio);
s2443CAM->CIPRSCCTRL=(1<<31)|(CAM_RGB16B<<30)|(ScaleUp_H_Pr<<29)|(ScaleUp_V_Pr<<28)|(MainHorRatio<<16)|(1<<15)|(MainVerRatio);
if(CAM_CODEC_OUTPUT)//CCIR-422
{
}
else//CCIR-420
{
s2443CAM->CIMSYSA = (U32)(g_PhysCodecAddr.LowPart);
s2443CAM->CIMSCBSA = s2443CAM->CIMSYSA + MSDMAWidth * MSDMAHeight;
s2443CAM->CIMSCRSA = s2443CAM->CIMSCBSA + MSDMAWidth * MSDMAHeight / 4;
s2443CAM->CIMSYEND = s2443CAM->CIMSYSA + MSDMAWidth* MSDMAHeight;
s2443CAM->CIMSCBEND= s2443CAM->CIMSCBSA + MSDMAWidth * MSDMAHeight / 4;
s2443CAM->CIMSCREND= s2443CAM->CIMSCRSA + MSDMAWidth * MSDMAHeight / 4;
s2443CAM->CIMSCTRL &= ~(0x3f);
s2443CAM->CIMSCTRL |= (0<<5|1<<2|1<<1);
}
Camif_Capture(CAPTURE_ON, CAPTURE_OFF);
s2443CAM->CIMSCTRL |= (1<<0);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -