📄 l1_preview.c
字号:
/********************************************************************************
Copyright (c) 2001 Sunplus Technology Co., Ltd.
Module Name: l1.c
Function : Level-1 function
Environment: Keil C51 Compiler
Creation : 2001/10/25 Max Hsu
***********************************************************************************/
#include "general.h"
#include "main.h"
#include "sdramhw.h"
#include "image.h" //ada@0225
#include "timer.h"
//yichang
#include "doslink.h"
#include "dosusr.h"
#include "cffunc.h"
#include "ui.h"
#include "quantdef.h"
#include "initio.h"
#include "uiflow.h"
//#include "sensor.h"
//patch4.2@yichang@0513 for continue snapping
#include "cardui.h"
#include "exifhdr.h"
#include "exiffunc.h"
//patch4.3@andrew@0610
#include "L1_3a.h"
#include "JoeToEvb.h"
#include "unistd.h"
// version4.0@
// andrew@0513
//patch4.3@andrew@0610
//switch for save raw data
//#define K_SAVE_RAW
extern xdata int EV12_index;
#define EV11_index 40
#define EV10_index 30
#define EV9_index 20
#define EV8_index 10
#define EV7_index 0
#define STB_Target 110
#define STB_Target2 128
#define STB_Gain_max 0x180
#define STB_Gain_mid 0x140
#define STB_Gain_min 0x100
#define SAT_PIXEL_CNT 2800
//AWB
#define AWBMaxGain 355
#define AWBMinGain 64
#define STB_RGain 0x4d
#define STB_GrGain 0x3f
#define STB_BGain 0x60
#define STB_GbGain 0x40
#define STB_RGain2 0x51
#define STB_BGain2 0x65
#define STB_GrGain2 0x40
#define STB_GbGain2 0x40
//patch4.4@richie@imgsc
extern UCHAR L1_ScaleImage(ULONG SrcAddr, USHORT SrcHsize, USHORT SrcVsize,ULONG DstAddr, USHORT DstHsize, USHORT DstVsize, ULONG TempAddr);
extern UCHAR L1_ScaleImageOneDim(UCHAR Type,ULONG SrcAddr, USHORT SrcHsize, USHORT SrcVsize,ULONG DstAddr, USHORT DstHsize, USHORT DstVsize);
//version4.3@richie@zo
extern xdata UCHAR G_ucZoomFactor;
//patch5.0@richie@sdram mapping
//patch4.5@richie@smooth zoom begin
extern xdata USHORT G_usZoomX;
//patch4.5@richie@smooth zoom end
//richie@ae0226
//extern unsigned int Shutter;
extern unsigned int AVG_LUM, AVG_LUM2;
extern int AEFlag,AWBFlag;
// versino4.0@andrew@0513
extern unsigned int Gain;
extern unsigned long Shutter;
extern bit AE_START ;
extern int Tidx;//,Pre_Tidx,MinTidx=0;
extern void GetAvgLum(PUSHORT Avg);
extern void SetStdColor2( void );
//patch4.3@andrew@0610
void Preview2SnapAETransfer(void);
void Snap2PreviewAETransfer(void);
void LongShutter(unsigned long Tnum);
void SaveRawProcess(void);
void SetGamma(int);
unsigned long AE_GetShutter(int idx);
unsigned short AE_GetGain(int idx);
unsigned short AE_GetEV(int idx);
void ChangeTable(int);
#ifdef STROBE_DEVICE
void StrobeSetting(void);
#endif
#ifdef TLV990
code unsigned short TLV990_TABLE[15]={1000,1053,1109,1168,1230,1296,1365,1437,1513,1594,1679,1768,1862,1961,2065};
#endif
bit STROBE;
USHORT FR,FG,FB, FG2;
#define AEAWB_DEBUG
#ifdef AEAWB_DEBUG
extern bit Outdoor;
UCHAR max_flag=0;
unsigned short SNAP_Y[3];
unsigned short SNAP_T[3];
#endif
extern UCHAR K_AEAWB_Flag;
extern long Kback;//jhyu@test
extern long YY[5][5];//jhyu@test
extern char method;
//herb for IGBT start @03/03/24
xdata USHORT flashwidth=1;
xdata UCHAR preflash;
extern xdata UCHAR G_FlashStatus;
//herb for IGBT end @03/03/24
//patch4.3@andrew@0610
//simplify L1_SnapOne function,
//package some code in sub function ,, strobe, snap AE transfer
//patch4.3@andrew@0610
// version4.0@andrew@0513
//
unsigned char G_AE_com_index_Temp; //wendy@2004/9/10
//Joe@2003.3.24 20:11 add begin
void IGBTPreflash(void);
//Joe@2003.3.24 20:11 add end
//-----------------------------------------------------------------------------
//L1_SnapOne
//-----------------------------------------------------------------------------
UCHAR L1_SnapOne(PULONG pSize, PULONG ptmbsize) USING_0
{
ULONG i;
// UCHAR reg_addr[1];
// UCHAR mi_reg_data[2];
// UCHAR temp[1];
//UCHAR tmp;//Davis@05.3.3 add for debug
//patch4.2@yichang@0513 for continue snapping
//USHORT captureWidth, captureHeight;
#if AAA_OPTION
#ifdef AEAWB_DEBUG
max_flag=0;
SNAP_Y[0]=0;
SNAP_Y[1]=0;
SNAP_Y[2]=0;
SNAP_T[0]=0;
SNAP_T[1]=0;
SNAP_T[2]=0;
#endif
//UCHAR L2_ReadSSC(UCHAR RegAddr, UCHAR *RegData, UCHAR Count, UCHAR Option)
//L2_ReadSSC(0x00, temp, 0x01, 0x01);
XBYTE[0X20D0] = XBYTE[0X20D0] & 0xDF; //Turn off VD interrupt
L1_3A(1);
/*
if((AEFlag==0)||(AWBFlag==0))
L1_3A(1);
if((AEFlag==0)||(AWBFlag==0))
L1_3A(1);
*/
#if DEBUG_COLOR
CMPGrGb(tmp);
if(tmp)
SetGrEqGb();//add for debug
#endif
#endif
L2_TurnOnOffDisplay(0);
L2_WaitVD(0,2);
#if AAA_OPTION
GetAvgLum(&AVG_LUM);
#endif
#if AAA_OPTION
#if STROBE_DEVICE // andrew add for strobe device
//patch4.3@andrew@0610
StrobeSetting();
UI_Buzzer();
#else // STROBE_DEVICE==0
//patch4.3@andrew@0610
Preview2SnapAETransfer();
#endif
if(Tidx >= 50) //patch4.4@jhyu@change_indoor_outdoor_gamma
SetGamma(K_GAMMA_OUTDOOR);
else
SetGamma(K_GAMMA_INDOOR);
#else // AAA_OPTINO == 0
STROBE=0;
#endif
#ifdef OV3610
XBYTE[0x21A8] = 0x28;
XBYTE[0x21A6] = 0x01; //enable bright and contrast adjustment 对比度
XBYTE[0x21Ae] = 0x2a;
XBYTE[0x21Ac] = 0x01; //enable bright and contrast adjustment
#endif
L2_SetCDSPScale(G_Hsize,G_Hsize); //TurnOff the CDSP H-scale function
L2_SetImageType(0); //Set raw dta type
L2_SetDisplayMode(0,0); //disable frame rate conversion
L2_SetRFBAddr(G_RawImageBufAddr+G_Hsize*6); //captured raw data will be stored in the buffer
L2_SetAFBAddr(G_RawImageBufAddr+G_Hsize*6);
L2_SetAFBSize(G_Hsize,G_Vsize);
L2_SetRFBSize(G_Hsize,G_Vsize); //pointed by the Raw buffer pointer
L2_SetRCDSPWidth(G_Hsize);
L2_SetACDSPWidth(G_Hsize);
L2_SetCamMode(0); //prepare to receiver data fomr the sensor
L2_SetCamMode(2);
L2_WaitVD(0,1); //wait for the falling edge of VD for one time // Set to DSC mode
L2_SnapFront(1); //Trigger the CMOS sensor into the full-frame mode
//UI_PrintOSDNumber(2, 2, 2, 1);
//patch4.5@ada@improve power to shot performance begin
//patch5.0@richie@moto snap
while((L2_CheckDRAMStatus()&0X02)!=0X02) ;
//patch4.5@ada@improve power to shot performance end
//UI_PrintOSDNumber(3, 3, 2, 1);
#ifdef K_SAVE_RAW
SaveRawProcess();
#endif
#if STROBE_DEVICE // andrew 0513 if EV>9 do not really strobe, strobe after finish exposure
if( (Tidx >= EV9_index) && STROBE )
{
STROBE=0;
}
#endif
///////// VERTICAL LINE EXTENSION ////////////////////////////////////////////
//Extend the vertical image size by 12 lines (mirror) for CDSP
//The horizontal extending pixels are mirrored by the CDSP automatically
//patch4.2@yichang@0513 for continue snapping
for(i=1;i<7;i++) //top mirror
L2_DoDRAMDMA(G_RawImageBufAddr*2+(ULONG)G_Hsize*6*2+(ULONG)G_Hsize*i*2,
G_RawImageBufAddr*2+(ULONG)G_Hsize*6*2-(ULONG)G_Hsize*i*2,
G_Hsize*2);
for(i=1;i<7;i++) //bottom mirror
L2_DoDRAMDMA(G_RawImageBufAddr*2+(ULONG)G_Hsize*6*2-(ULONG)G_Hsize*i*2+(ULONG)G_Hsize*(G_Vsize - 1)*2,
G_RawImageBufAddr*2+(ULONG)G_Hsize*6*2+(ULONG)G_Hsize*i*2+(ULONG)G_Hsize*(G_Vsize - 1)*2,
G_Hsize*2);
//UI_PrintOSDNumber(4, 4, 2, 1);
UI_Buzzer1();//wendy@2004/9/7
//patch4.2@yichang@0513 for continue snapping
if(G_CameraOptions.function == K_UIOPTION_FUNCTION_MULTI)
{
*pSize = 0;
*ptmbsize = 0;
return(0);
}
//patch4.4@yichang@badpixel begin
L1_DoAllBadPixel(G_RawImageBufAddr+G_Hsize*6, G_Hsize, G_Vsize);
//patch4.4@yichang@badpixel end
//UI_PrintOSDNumber(5, 5, 2, 1);
//patch4.2@yichang@0513 for continue snapping
postSnapping(pSize, ptmbsize);
//UI_PrintOSDNumber(6, 6, 2, 1);
Snap2PreviewAETransfer();
//UI_PrintOSDNumber(7, 7, 2, 1);
#if AAA_OPTION
L2_InitAEAW(0);
#endif
L2_SetDisplayType(G_DisplayType);
L2_SetDisplaySrcImgSize(G_DSPHsize, G_DSPVsize, G_DisplayType);
// set the displayed address and size
L2_SetBFBAddr(K_SDRAM_ImageCaptureDisplayBufAddr);
L2_SetBFBSize(G_DSPHsize,G_DSPVsize);
// set display buffer index is equal to B frame buffer index
L2_SetDisplayMode(0x00, 0x10);
//wendy@2004/9/9
if (G_DisplayMode == K_DisplayModePowerOff)//hx@2003.6.1 add for mito begin
{
G_DisplayMode = K_DisplayModeOsdOn;
//UI_PreviewStatusOSD();
L2_TurnOnOffDisplay(1);
G_DisplayMode = K_DisplayModePowerOff;
}
else
{
L2_TurnOnOffDisplay(1);
return(0);
}
}
//patch4.2@yichang@0513 for continue snapping
//-----------------------------------------------------------------------------
//void postSnapping(PULONG pSize, PULONG ptmbsize)
//-----------------------------------------------------------------------------
void postSnapping(PULONG pSize, PULONG ptmbsize) USING_0
{
USHORT captureWidth, captureHeight;
//patch5.0@richie@sdram mapping
USHORT zoomOffX, zoomOffY;
ULONG i,j;
#if AAA_OPTION
USHORT RT,GT1,BT,GT2;
ULONG spwnum;
UCHAR spwlum;
CHAR spwry,spwby;
UCHAR LumClamp0,LumClamp1,LumClamp2,LumClamp3,LumClamp4;
CHAR SAT=0;
float ratio=1;
USHORT FR,FG1,FB, FG2;//USHORT tmp;
int SPW_CNT[4], SPW_Y[4], SPW_RY[4], SPW_BY[4];
int r_gain,gr_gain,b_gain,gb_gain,min_gain,Reg_Rg,Reg_Grg,Reg_Bg,Reg_Gbg,Reg_Hg ;
int r_off,gr_off,b_off,gb_off;
//int temp_gain; //patch 4.2@jhyu@0523
#ifdef AEAWB_DEBUG
LONG end_add;
UCHAR hb,lb;
#endif
#endif
#if AAA_OPTION
Reg_Rg =(SHORT)(XBYTE[0x2124]&0xff);
Reg_Grg=(SHORT)(XBYTE[0x2125]&0xff);
Reg_Bg =(SHORT)(XBYTE[0x2126]&0xff);
Reg_Gbg=(SHORT)(XBYTE[0x2127]&0xff);
Reg_Hg =(SHORT)(XBYTE[0x2128]&0xff);
r_off = XBYTE[0x2120];//patch4.3@jhyu@0604
gr_off = XBYTE[0x2121];//patch4.3@jhyu@0604
b_off = XBYTE[0x2122];//patch4.3@jhyu@0604
gb_off = XBYTE[0x2123];//patch4.3@jhyu@0604
r_gain = Reg_Rg | ((Reg_Hg&0x08)<<5);
gr_gain= Reg_Grg| ((Reg_Hg&0x04)<<6);
b_gain = Reg_Bg | ((Reg_Hg&0x02)<<7);
gb_gain= Reg_Gbg| ((Reg_Hg&0x01)<<8);
RT =(USHORT)r_gain;
GT1=(USHORT)gr_gain;
BT =(USHORT)b_gain;
GT2=(USHORT)gb_gain;
if( STROBE )
{
if( Tidx > EV9_index )
{
FR =r_gain;
FG1=gr_gain;
FB =b_gain;
FG2=gb_gain;
}
else if( Tidx > EV8_index )
{
FR =STB_RGain *0.2+0.8*r_gain;
FG1=STB_GrGain*0.2+0.8*gr_gain;
FB =STB_BGain *0.2+0.8*b_gain;
FG2=STB_GbGain*0.2+0.8*gb_gain;
}
else if( Tidx > EV7_index )
{
FR =(STB_RGain *0.5+0.5*r_gain);
FG1=(STB_GrGain*0.5+0.5*gr_gain);
FB =(STB_BGain *0.5+0.5*b_gain);
FG2=(STB_GbGain*0.5+0.5*gb_gain);
}
else
{
FR =STB_RGain *0.8+0.2*r_gain;
FG1=STB_GrGain*0.8+0.2*gr_gain;
FB =STB_BGain *0.8+0.2*b_gain;
FG2=STB_GbGain*0.8+0.2*gb_gain;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -