/*
 *******************************************************************************
 *  Copyright (c) 2010-2022 VATICS(KNERON) Inc. All rights reserved.
 *
 *  +-----------------------------------------------------------------+
 *  | THIS SOFTWARE IS FURNISHED UNDER A LICENSE AND MAY ONLY BE USED |
 *  | AND COPIED IN ACCORDANCE WITH THE TERMS AND CONDITIONS OF SUCH  |
 *  | A LICENSE AND WITH THE INCLUSION OF THE THIS COPY RIGHT NOTICE. |
 *  | THIS SOFTWARE OR ANY OTHER COPIES OF THIS SOFTWARE MAY NOT BE   |
 *  | PROVIDED OR OTHERWISE MADE AVAILABLE TO ANY OTHER PERSON. THE   |
 *  | OWNERSHIP AND TITLE OF THIS SOFTWARE IS NOT TRANSFERRED.        |
 *  |                                                                 |
 *  | THE INFORMATION IN THIS SOFTWARE IS SUBJECT TO CHANGE WITHOUT   |
 *  | ANY PRIOR NOTICE AND SHOULD NOT BE CONSTRUED AS A COMMITMENT BY |
 *  | VATICS(KNERON) INC.                                             |
 *  +-----------------------------------------------------------------+
 *
 *******************************************************************************
 */
#ifndef CONFIG_AE_H
#define CONFIG_AE_H

#include <comm/video_buf.h>

#ifdef __cplusplus
extern "C" {
#endif

/*
 * AE option flag enumeration 
 */ 
typedef enum
{
	//! AE option flag: reset
	AE_OPTION_RESET,

	//! AE option flag: converge speed
	AE_OPTION_CONVERGE_SPEED,

	//! AE option flag: control
	AE_OPTION_CONTROL,

	//! AE option flag: autoscene
	AE_OPTION_AUTOSCENE,

	//! AE option flag: sensor info
	AE_OPTION_SENSOR_INFO,

	//! AE option flag: statistic range
	AE_OPTION_STATISTIC_RANGE,

	//! AE option flag: target exchange
	AE_OPTION_TARGET_EXCHANGE,

	//! AE option flag: ai control
	AE_OPTION_AI_CONTROL,

	//! AE option flag: previous shutter info
	AE_OPTION_PREV_AE_SETTINGS,

	//! AE option flag: linear/HDR control
	AE_OPTION_AUTO_LINEAR_HDR_CONTROL,    

	//! AE option flag: reserved
	VMF_AE_RESERVED,
	
	//! AE option flag: iris control info
	AE_OPTION_IRIS_CONTROL,

	//! AE option flag: current shutter info
	AE_OPTION_CURR_SHUTTER,

	//! AE option flag: resume control
	AE_OPTION_RESUME_CONTROL,

	//! ASC option flag: aiae set enable
	AE_OPTION_AI_MODE,
    
	//! ASC option flag: aiae set response time
	AE_OPTION_AI_RESP_CTRL,

	//! Ifp option: reserved max
	VMF_AE_RESERVED_MAX
} VMF_AE_OPTION_FLAG_T;

/*
 * A data structure for AE general option
 */
typedef struct
{
	//! A data for option flags
    VMF_AE_OPTION_FLAG_T eOptionFlags;

    //! A data for AE handle index (Available in dual lens 360 mode)
	unsigned int dwIndex;

    //!  A pointer data for user data
    void *pData; 
} VMF_AE_OPTION_T;

/*
 * A data structure for AE in autoscene option, AE_OPTION_AUTOSCENE
 */
typedef struct
{
	//! A data for power frequence of video signal : 1:50HZ, 2:60HZ, 3:24HZ, 4:30HZ 
	VMF_VIDEO_SIGNAL_FREQUENCY eVideoSignalFreq;

	//! A data for AE control mode : 0: Auto, 1: Black light, 2: Customized 
	unsigned int dwMode;

	//! A data for AE lock : 1: AE lock, 0: AE unlock 
	unsigned int bLock;

	//! A data for AE's target luma : range: 0~255 
	unsigned int dwTargetLuma;

	//! A data for AE's target offset : range 0~255 
	unsigned int dwTargetOffset;

	//! A data for AE's action range with min shutter speed : range 1~1000000,  1000000 = 1 second 
	unsigned int dwMinShutter;

	//! A data for AE's action range with max shutter speed : range 1~1000000,  1000000 = 1 second 
	unsigned int dwMaxShutter;

	//! A data for AE's action range with min gain : range 1~128,  1 = 1x gain 
	unsigned int dwMinGain;

	//! A data for AE's action range with max gain : range 1~128,  1 = 1x gain
	unsigned int dwMaxGain;

    //! A data for iris status : 0: fixed to largest, 1: auto iris, 2: manual iris
    unsigned int dwIrisStatus;

    //! A data for active shutter speed for auto iris conrol when dwIrisStatus = 1 : range 1~1000000,  1000000 = 1 second
    unsigned int dwIrisActiveTime;

	//! A data for WDR ratio : range 1,2,4,8,16,32,64,128,256
    unsigned int dwWdrRatio;
} VMF_AE_ASC_PARAM_T;

/*
 * A data structure for AE FAS option, AE_OPTION_AUTO_LINEAR_HDR_CONTROL
 */  
typedef struct
{
    //! Pointer to VMF_AE_ASC_PARAM_T structure
    VMF_AE_ASC_PARAM_T tAeAscParam;

    /*! A data for AE's converge speed : range 1~9 */
    unsigned int dwSpeed;

    /*! A data for WDR enable : 0: disable, 1: enable */
    unsigned int bWdrEn;

    /*! A data for WDR exposure control mode : unsigned int (0: linear mode, 2: Multi-exposure WDR) */
    unsigned int dwWdrExposureMode;

    /*! A data for WDR's descent of ROI in histogram of short exposure frame : unsigned int (range 1~99) */
    unsigned int dwWdrDescentRoiInShortExpHist;

    /*! A data for minimum WDR output ratio : range 1000~256000 */
    unsigned int dwWdrMinOutputWdrRatio;

    /*! A data for maximum WDR output ratio : range 1000~256000 */
    unsigned int dwWdrMaxOutputWdrRatio;

    /*! A data for target luma with WDR short exposure frame : range 0~255 */
    unsigned int dwWdrShortExpTarget;

    /*! A data for target offset with WDR short exposure frame : range 0~255 */
    unsigned int dwWdrShortExpConvergeRange;

    /*! A data for WDR's converge step size : range 1~256000 */
    unsigned int dwWdrConvergeStepSize;

    /*! A data for TE's target offset: range -255~255 */
    int sdwTEAETargetOffset;

    /*! A data for TE's high gain threshold : range 1000~255000 */
    unsigned int dwTEHighGain;

    /*! A data for TE's low gain threshold : range 1000~255000 */
    unsigned int dwTELowGain;

    /*! A data for SR's calculation start ratio for auto mode : range 0~100 */
    unsigned int dwSRAutoStartRatio;

    /*! A data for SR's calculation end ratio for auto mode : range 0~100 */
    unsigned int dwSRAutoEndRatio;

    /*! A data for SR's calculation start ratio for back light mode : range 0~100 */
    unsigned int dwSRBLightStartRatio;

    /*! A data for SR's calculation end ratio for back light mode : range 0~100 */
    unsigned int dwSRBLightEndRatio;

    /*! A data for minimum sensor shutter : range 1~1000000 */
    unsigned int dwSIMinShutter;

    /*! A data for maximum sensor shutter : range 1~1000000 */
    unsigned int dwSIMaxShutter;

    /*! A data for minimum sensor gain : range 1~1000000 */
    unsigned int dwSIMinGain;

    /*! A data for maximum sensor gain : range 1~1000000 */
    unsigned int dwSIMaxGain;

} VMF_AE_FAS_PARAM_T;
/*
 * A data structure for AE ctrl option, AE_OPTION_CONTROL
 */  
typedef struct
{
	//! A data for Video Signal Frequency
    unsigned int dwVideoSignalFreq;

    //! A data for Metering type
    unsigned int dwMeteringType;

    //! A data for AE luma target
    unsigned int dwTarget;	

    //! A data for AE luma convergence range
    unsigned int dwOffset;	

    //! A data for max system gain  		
    unsigned int dwMaxGain;	

    //! A data for min system gain  	
    unsigned int dwMinGain;	

    //! A data for max sensor shutter  		
    unsigned int dwMaxShutter;	

    //! A data for min sensor shutter  	
    unsigned int dwMinShutter;	

    //! A data for WDR enable. (0: Linear mode(WDR off), 1: WDR mode(WDR on))
    unsigned int bWdrEn;

    //! A data for WDR ratio
    unsigned int dwWdrRatio;

    //! A data for exposure mode
    unsigned int dwExposureMode;

    //! A data for the ROI percentage for short exposure histogram which will be taken into consideration (from histogram brightness part)
    unsigned int dwDescentRoiInShortExpHist;

    //! A data for minimum WDR output ratio
    unsigned int dwMinOutputWdrRatio;

    //! A data for maximum WDR output ratio
    unsigned int dwMaxOutputWdrRatio;

    //! A data for luma target of WDR short exposure
    unsigned int dwWdrShortExpTarget;

    //! A data for luma convergence range of WDR short exposure
    unsigned int dwWdrShortExpConvergeRange;

    //! A data for stepping size of WDR convergence
    unsigned int dwWdrConvergeStepSize;

    //! Array for smart IR control
    unsigned int adwSmartIRParam[32];

    //! Array for PQ tool to get priority windows
    unsigned int adwWinPriority4PQT[256];

    //! A flag for updating priority windows
    unsigned int bUpdateWinPriority;

    //! A pointer data for priority windows
    unsigned int* pdwWinPriority;
} VMF_AE_CTRL_OPTION_T;

/*
 * A data structure for AE sensor info option, AE_OPTION_SENSOR_INFO
 */ 
typedef struct
{
	//! A data for AE's sensor info range with min shutter  
    unsigned int dwMinShutter;

    //! A data for AE's sensor info range with max shutter  
    unsigned int dwMaxShutter;

    //! A data for AE's sensor info range with min gain 
    unsigned int dwMinGain;

    //! A data for AE's sensor info range with max gain 
    unsigned int dwMaxGain;

    //! A data for min expect step 
    unsigned int dwMinExpStep;

    //! A data for min gain step 
    unsigned int dwMinGainStep;

    //! A data for frame rate
    unsigned int dwFrameRate;
} VMF_AE_SENSOR_INFO_OPTION_T;

/*
 * A data structure for AE converge speed option, AE_OPTION_CONVERGE_SPEED
 */ 
typedef struct
{
	//! A data for AE speed
    unsigned int dwSpeed;
} VMF_AE_SPEED_OPTION_T;

/*
 * A data structure for AE target exchange option, AE_OPTION_TARGET_EXCHANGE
 */
typedef struct
{
	//! A data for AE's target offset
    int iAETargetOffset;

    //! A data for AE's target high gain
    unsigned int dwHighGain;

    //! A data for AE's target low gain
    unsigned int dwLowGain;
} VMF_AE_TARGET_EXCHANGE_OPTION_T;

/*
 * A data structure for AE statistic range option, AE_OPTION_STATISTIC_RANGE
 */
typedef struct
{
	//! A data for auto start ratio 
    unsigned int dwAutoStartRatio;

    //! A data for auto end ratio 
    unsigned int dwAutoEndRatio;

    //! A data for BLight  start ratio
    unsigned int dwBLightStartRatio;

    //! A data for BLight end ratio
    unsigned int dwBLightEndRatio;
} VMF_AE_STATS_RANGE_OPTION_T;

/*
 * A data structure for AE auto iris option, AE_OPTION_AI_CONTROL
 */
typedef struct
{
	//! A data for auto iris enable
    unsigned int bAutoIrisEn;

    //! A data for AI active time
    unsigned int dwAIActiveTime;
} VMF_AE_AUTO_IRIS_OPTION_T;

/*
 * A data structure for AE iris control info
 */
typedef struct
{
    //! A data for iris speed
    unsigned int dwSpeed;
} VMF_AE_IRIS_CONTROL_INFO_T;

/*
 * A data structure for AE current shutter info
 */
typedef struct
{
    //! A data for current shutter
    unsigned int dwCurrShutter;

	 //! A data for current sensor gain
    unsigned int dwCurrSensorGain;

	 //! A data for current ISP gain
    unsigned int dwCurrISPGain;

    //! A data for current weighted brightness
    unsigned int dwCurrWgtLuma;
} VMF_AE_CURR_SHUTTER_INFO_T;

/*
 * A data structure for AE previous shutter info
 */
typedef struct
{
    //! A data for previous shutter
    unsigned int dwPreShutter;

	 //! A data for previous gain
    unsigned int dwPreGain;

	 //! A data for previous HDRRatio
    unsigned int dwPreHDRRatio;

    //! A data for Exposure Value
    unsigned int dwPreEvVal;
} VMF_AE_PREV_SHUTTER_INFO_T;

/*
 * A data structure for AIAE enable info
 */
typedef struct
{
    //! A data for Ai Ae enable
    unsigned int dwAiMode;
} VMF_AE_AI_MODE_INFO_T;

/*
 * A data structure for AIAE response time control info
 * chenge vml TAutoExposureState.dwAIResponseCtrl
 */
typedef struct
{
    //! A data for Ai Ae response time
    unsigned int dwAIRespCtrl;
} VMF_AE_AI_RESP_CTRL_INFO_T;



/*
 * A data structure for AE resume control
 */
typedef struct
{
    //! A data for converged range of resume mode. (Range: 0~255, default: 10)
    unsigned int dwConvergedRange;

     //! A data for force accelerate mode enable. (0: Disable, 1: Enable)
    unsigned int bForceAccEn;

     //! A data for operation frames of resume mode. (Range: 1~255, default: 1)
    unsigned int dwResumeOpFrames;

    //! A data for converge speed of resume mode. (Range: 1~9, default:9)
    unsigned int dwResumeSpeed;
} VMF_AE_RESUME_CONTROL_T;

#ifdef __cplusplus
}
#endif

#endif
