/******************************************************************************
<Filename> AF.c
<Contents> Auto Focus algorithm file
<Environment> Zoran COACH8
<Creation Date> Jun-09-2006
<Author> Jacky Liang
*******************************************************************************/
#include "FlexAF.h"
#include "Copal_AQJ1677.h"
#include "Common.h"
#include "I43_Api.h"
#include "Host.h"
#include "HcelensDrive.h"
#include "captureStillMenu.h"
#include "DB.h"
#include "Ael.h"
#include "menuTask.h"
#include "osd.h"
#include "ErrorMsg.h"
#include "Timing.h"
#define ERROR_PRINT 0
#if ERROR_PRINT
#include <stdio.h>
#define PRINTERROR printf
#else
#define PRINTERROR(format, ...)
#endif
#define DBUG_PRINT 0
#if DBUG_PRINT
#include <stdio.h>
#define DPRINT printf
#else
#define DPRINT(format, ...)
#endif
#define AF_DATA_PRINT 0
#if AF_DATA_PRINT
#include <stdio.h>
#define PRINTDATA printf
#else
#define PRINTDATA(format, ...)
#endif
#define MANUAL_FOCUS 0
STATIC AF_STAT s_iAfStat = kIdleStat;
STATIC AF_RESULT s_iAfResult = kAFOutFocus;
STATIC INT s_iAfPeakPos = 0;
STATIC INT s_iCoarseAfPeakPos = 0;
STATIC INT s_iFineAfPeakPos = 0;
STATIC INT s_iAfCurIdx = 0;
STATIC AF_VALUE s_AfValue[AF_MAX_FRAME_NUM];
STATIC AF_MODE s_AfMode = kSingleAF;
STATIC INT s_iBufferFrame = 2;
STATIC BOOL s_bFocusCal = FALSE;
STATIC BOOL s_bContinuousAf = FALSE;
STATIC AF_VALUE s_PeakAfValue;
STATIC AF_VALUE s_CurFrameAfValue;
STATIC INT FineScanEnable = 0;
UINT16 PuwPeakIdxHor =0,PuwPeakIdxVer=0;
UINT ThreePointWindowShow=0;
UINT FErrorNum = 255;
INT CurveStatus = 0;
BOOL LeftWindow = 0;
BOOL CenterWindow = 0;
BOOL RightWindow = 0;
STATIC UINT16 AF_Windows_X = 0;
STATIC UINT16 AF_Windows_Y = 0;
STATIC UINT16 AF_Windows_Length = 0;
STATIC UINT16 AF_Windows_Width = 0;
/* Jacky Nov-23-2006 comment about scan step: the last table is caculated by Depth of View tool. Because of the frame rate limited, we only use the pre-table. */
//CONST INT c_iFineAfScanStepTable[ZOOM_PI_MAX] = { 4, 4, 3, 3, 3, 2, 2 };//{ 25, 18, 11, 8, 7, 6, 5 };
CONST INT c_iFineAfScanStepTable[ZOOM_PI_MAX] = { 2, 2, 2, 2, 2, 2, 2 };//{ 25, 18, 11, 8, 7, 6, 5 };
#if MULTIPLE_AF
STATIC INT s_iAfmMaxWindow = 0;
STATIC AFM_STATISTICS s_AfmStatistics;
#endif
STATIC ULONG HCE_GetAfValue(ULONG *ulVerEdge, ULONG *ulHorEdge);
STATIC INT HCE_GetAfPeakPos(VOID);
STATIC BOOL HCE_ClearupAfValue(AF_VALUE *AfValue, INT Idx);
STATIC INT HCE_GetFineAfScanStep(VOID);
STATIC INT HCE_GetCoarseAfScanStep(VOID);
INT HCE_GetAfScanStartPos(VOID);
INT HCE_GetAfScanEndPos(VOID);
STATIC BOOL HCE_CheckAfFallingTrend(VOID);
STATIC VOID HCE_FocusGoPosCB(ULONG data);
STATIC BOOL HCE_SceneChangeDetection(VOID);
void SinglePeakAlgorithm(UINT16* PeakIdxHor,UINT16* PeakIdxVer,UINT CoarseOrFine);
void CoarseScanThresHoldSet();
UINT16 MeasurePointSingleHVvalue(USHORT uwAfTestCntNum,UINT16 HORV, ULONG* MaxVlaue,ULONG* MinVlaue);
UINT16 MeasureThreePointSingleHVvalue(USHORT uwAfTestCntNum,UINT16 HORV);
UINT16 MeasureFivePointSingleHVvalue(USHORT uwAfTestCntNum,UINT16 HORV);
UINT16 MeasureFiveOrThreeOrSinglePointVH(UINT16 FivePoint,UINT16 ThreePoint,UINT16 Single);
INT16 EstMidPeakPos(UINT16 peakIndex,INT16 iFarLimit);
INT16 EstMidPeakPosFFF(UINT16 peakIndex,INT16 iFarLimit);
INT16 CoarsePeakAlgorithm(UINT16 peakIndex,INT16 iFarLimit);
INT16 EstMidPeakPosThreeToOne(UINT16 peakIndex,INT16 iFarLimit,UINT Check_Flag);
UINT8 LowLightDetect(void);
void CoarseScanStartPositionSet(void);
void AFWindowsSizeSet(void);
void SingleCorseScanPeakCheck(void);
UINT8 SingleFineScanPeakCheck(void);
void MultipleCorseScanPeakCheck(void);
INT MultiplePeakAlgorithm(INT NUM,INT Af_Value_Max_Windows,INT Max_idx);
void VerValueChangeToHorValue(INT uwAfTestCntNum);
UINT16 AF_WindowsXGet(void) {return AF_Windows_X;}
UINT16 AF_WindowsYGet(void) {return AF_Windows_Y;}
UINT16 AF_WindowsLengthGet(void) {return AF_Windows_Length;}
UINT16 AF_WindowsWidthGet(void) {return AF_Windows_Width;}
void ThreePointShowSet(UINT value_value)
{
ThreePointWindowShow = value_value;
printf("ThreePointWindowShow=%d\n",ThreePointWindowShow);
}
UINT ThreePointShowGet()
{
return ThreePointWindowShow;
}
void HceSetCurveStatus(UINT curveSta)
{
CurveStatus = curveSta;
}
UINT HceGetCurveStatus()
{
return CurveStatus;
}
void HceSetiFocus_test(UINT FocusWrongNUm)
{
FErrorNum = FocusWrongNUm;
}
UINT HceGetiFocus_test()
{
return FErrorNum;
}
INT HceGetAFCoarsePosition()
{
return s_iCoarseAfPeakPos;
}
INT HceGetAFFinePosition()
{
return s_iFineAfPeakPos;
}
BOOL HceAF_WindowsSet(LONG X_Windows,LONG Y_Windows,LONG Length_Windows,LONG Width_Windows)
{
PRINTDATA("X_Windows=%d,Y_Windows=%d,Length_Windows=%d,Width_Windows=%d\n",X_Windows,Y_Windows,Length_Windows,Width_Windows);
X_Windows = (LONG)(X_Windows*1024/320);
Y_Windows = (LONG)(Y_Windows*1024/240);
Length_Windows = (LONG)(Length_Windows*1024/320);
Width_Windows = (LONG)(Width_Windows*1024/240);
if((X_Windows<0)||(X_Windows>1023)
||(Y_Windows<0)||(Y_Windows>1023)
||(Length_Windows<=0)||(Length_Windows>1023)
||(Width_Windows<=0)||(Width_Windows>1023))
{
AF_Windows_X = 0;
AF_Windows_Y = 0;
AF_Windows_Length = 0;
AF_Windows_Width = 0;
}
else
{
AF_Windows_X = X_Windows+(16-X_Windows%16);
AF_Windows_Y = Y_Windows+(16-Y_Windows%16);
AF_Windows_Length = Length_Windows+(16-Length_Windows%16);
AF_Windows_Width = Width_Windows+(16-Width_Windows%16);
if(AF_Windows_X>1023) AF_Windows_X = AF_Windows_X - 16;
if(AF_Windows_Y>1023) AF_Windows_Y = AF_Windows_Y - 16;
if(AF_Windows_Length>1023) AF_Windows_Length = AF_Windows_Length - 16;
if(AF_Windows_Width>1023) AF_Windows_Width = AF_Windows_Width - 16;
}
PRINTDATA("AF_Windows_X=%d,AF_Windows_Y=%d,AF_Windows_Length=%d,AF_Windows_Width=%d\n",AF_Windows_X,AF_Windows_Y,AF_Windows_Length,AF_Windows_Width);
return 0;
}
void PreAFReady()
{
}
void CoarseScan()
{
}
void FineScan()
{
}
void PeakPositionCheck()
{
}
void CoarseScanThresHoldSet()
{
if(HceGetZoomCurPI()<4)
{
if(!s_bFocusCal)
I43_SetAFThresholds(48, 48);
else
I43_SetAFThresholds(48, 48);
}
else
I43_SetAFThresholds(32,32);
// I43_SetAFThresholds(16,16);
}
void CoarseScanOutOfFocusCheck(ULONG Max_Single,ULONG Min_Single)
{
if(Max_Single<1000)
{
HceSetiFocus_test(1);
s_iAfResult = kAFInFocus;
s_iAfStat = kGoingIntoPeakPos;
return;
}
if(gstrDatabase.m_items.m_sceneMode == SCENE_MODE_TEXT||
gstrDatabase.m_items.m_sceneMode == SCENE_MODE_COLLECTION||
gstrDatabase.m_items.m_sceneMode == SCENE_MODE_FOOD||
gstrDatabase.m_items.m_sceneMode == SCENE_MODE_FLOWER||
gstrDatabase.m_items.m_macroMode == MACRO_ON)
{
printf("Min=%d,Max=%d,Contrast=%d\n",Min_Single,Max_Single,Min_Single*100/Max_Single);
if((Min_Single*100/Max_Single)>88)
{
HceSetiFocus_test(2);
printf("!!!!!!!!!!!!the Min and Max contrast is so small\n");
return;
}
}
else
{
if((Min_Single*100/Max_Single)>95)
{
HceSetiFocus_test(2);
s_iAfResult = kAFInFocus;
s_iAfStat = kGoingIntoPeakPos;
return;
}
}
HceSetiFocus_test(0);
s_iAfResult = kAFInFocus;
}
void Duuumy()
{}
void AFVarClear()
{
PuwPeakIdxHor =0,
PuwPeakIdxVer=0;
}
void Hce_ManualFocus()
{
static UINT16 kkk=0;
static UINT16 www = 0;
if(kkk==0)
{
if(HceGetZoomCurPI()<4)
I43_SetAFThresholds(16, 16);
else
I43_SetAFThresholds(32,32);
HceSetFocusCommandStep(2);
LensDriveparameterSet(FOCUSNEAR);
lockAE();
OsThreadSleepMS(33);
while(HceGetFocusFlagFun());
I43_SetStatisticsPattern(1, "
自动对焦算法AF(auto AF)
1星 需积分: 44 161 浏览量
2021-11-17
00:07:43
上传
评论 10
收藏 11KB RAR 举报
hddzxyhyj
- 粉丝: 19
- 资源: 44
评论1