///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2016-2023 Qualcomm Technologies, Inc.
// All Rights Reserved.
// Confidential and Proprietary - Qualcomm Technologies, Inc.
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @file chistatsproperty.h
/// @brief Define Qualcomm Technologies, Inc. statistics proprietary data for holding external/internal properties/events
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

#ifndef CHISTATSPROPERTY_H
#define CHISTATSPROPERTY_H

#include "chistatspropertydefines.h"
#include "camxcdktypes.h"
#include "chipdlibcommon.h"

#ifdef __cplusplus

extern "C"
{
#endif // __cplusplus

// Data structures that are exposed to OEM must be packed to have the expected layout.
#pragma pack(push, CDK_PACK_SIZE)

static const UINT32 MaxAFFocusMapNum             = 3072;   ///< Maximum number of autofocus map grids (up to 64x48).
static const UINT32 MaxTableKnees                = 50;     ///< Defines the maximum number of knees allowed for an exposure
                                                           ///  table.
static const UINT32 MaxMeteringTableSize         = 256;    ///< Maximum size of the metering table.
                                                           ///  @newpage

/** @addtogroup chi_stats_prop
@{ */

/// @brief Valid statistics operation modes.
typedef enum
{
    StatsOperationModeInvalid           = -1,
    StatsOperationModeNormal            = 0,
    StatsOperationModeFastConvergence   = 1
} StatsOperationMode;

/// @brief Valid AEC startup modes.
typedef enum
{
    AECStartupModeInvalid         = -1,
    AECStartupModeNormal          =  0,
    AECStartupModeFastConvergence =  1,
    AECStartupModeWarmStart       =  2
} AECStartupMode;

/// @brief Frame control information for the AEC.
typedef struct
{
    AECExposureData   exposureInfo[AlgoOutputExposureCount];        ///< Exposure information, including gain and exposure
                                                                    ///  time, consumed by the ISP and sensor.
    FLOAT                       luxIndex;                           ///< Future scene brightness (consumed by the ISP).
    FLOAT                       prevLuxIndex;                       ///< Previous scene brightness (consumed by the ISP).
    AECFlashInfoType            flashInfo;                          ///< Flash information: main or preflash.
    PreFlashState               preFlashState;                      ///< Preflash state from the AEC (consumed by the sensor)
    CalibrationFlashState       calibFlashState;                    ///< Calibration state from the AEC (consumed by the
                                                                    ///  sensor)
    FLOAT                       LEDFirstEntryRatio;                 ///< Ratio of the LED entry with respect to the first entry
    FLOAT                       LEDLastEntryRatio;                  ///< Ratio of the LED entry with respect to the last entry
    UINT32                      LEDCurrents[LEDSettingCount];       ///< LED current value for the LED snapshot use case.
    FLOAT                       LEDInfluenceRatio;                  ///< Sensitivity ratio that is calculated as sensitivity
                                                                    ///  with no flash or sensitivity with preflash.
    FLOAT                       predictiveGain;                     ///< Digital gain from the predictive convergence algorithm
                                                                    ///  to be applied to the ISP module (AWB).
    FLOAT                       digitalGainForSimulation;           ///< Digital gain for the AEC simulation.
    FLOAT                       compenADRCGain;                     ///< Gain compensation when ADRC is enabled.

    BOOL                        isInSensorHDR3ExpSnapshot;          ///< Indicates whether the sensor mode is in three-exposure
                                                                    ///  HDR Snapshot mode.
                                                                    ///
                                                                    ///  @valuesbul
                                                                    ///  - 0 -- FALSE
                                                                    ///  - 1 -- TRUE @tablebulletend

    AECYHistStretchData         stretchControl;                     ///< Stretch control for the Y histogram.
    InSensorHDR3ExpTriggerInfo  inSensorHDR3ExpTriggerOutput;       ///< Information about the in-sensor HDR3 exposure
                                                                    ///  trigger output.
    AECSkipStatsParser          skipStatsParse;                     ///< Flag that indicates whether to skip statistics
                                                                    ///  parsing.
    FLOAT                       compensationDarkBoostGain;          ///< Compensation for dark boost gain.
    UINT64                      snapshotFlashDuration;              ///< Flash duration time for precision-based flash control,
                                                                    ///  where > 0 means the duration is precision-based.

    FLOAT                       shortBlendRatio;                    ///< Indicates whether to blend or discard short-exposure
                                                                    ///  pixels.
                                                                    ///
                                                                    ///  @valuesbul
                                                                    ///  - 0 -- Discard the pixels
                                                                    ///  - 1 -- Fully blend the pixels @tablebulletend

    FLOAT                       faceLuma;                           ///< Face luma CDF for the frame.
    FLOAT                       faceLumaTarget;                     ///< Face luma target.
    FLOAT                       faceConfidence;                     ///< Face confidence.
    AECSAConfInfo               SAOutputConf[AECAlgoSAOutputCount]; ///< Array of scene analyzer confidence outputs.
    FLOAT                       qllLongUnderExposureFactor;         ///< Factor by which a long exposure is actually reduced
                                                                    ///  by QLL.

    BOOL                        bIsTorchHDRRequired;                ///< Indicates whether trigger torch is required for an
                                                                    ///  HDR snapshot.
                                                                    ///
                                                                    ///  @valuesbul
                                                                    ///  - 0 -- FALSE
                                                                    ///  - 1 -- TRUE @tablebulletend
    BOOL                        bNeedAdjFPS;                        ///< Flag to ask sensor node adjust FPS
} AECFrameControl;

/// @brief Statistics control information for the AEC.
typedef struct
{
    // External Member Variables
    AECConfig   statsConfig;           ///< AEC statistics configuration (consumed by the ISP).
} AECStatsControl;

/// @brief Frame control information for the AWB algorithm.
typedef struct
{
    // Internal Member Variables
    AWBGainParams               AWBGains;                               ///< Per-channel gains (red, green, blue).
    UINT32                      colorTemperature;                       ///< Warmth or coolness of the lighting in a scene
                                                                        ///  (in degrees Kelvin).
    AWBCCMParams                AWBCCM[MaxCCMs];                        ///< Color correction matrix value.
    UINT32                      numValidCCMs;                           ///< Number of valid color correction matrix values.
    AWBAlgoDecisionInformation  AWBDecision;                            ///< Information about the AWB decision: RGB, color
                                                                        ///  temperature, and number of decisions.
    AWBSAConfInfo               SAOutputConf[AWBAlgoSAOutputConfSize];  ///< Array of scene analyzer confidence outputs.
    LocalGainAdjustData         AWBLocalGainAdjustData;                 ///< Local AWB gains adjustment.
} AWBFrameControl;

/// @brief Statistics control information for the AWB algorithm.
typedef struct
{
    // External Member Variables
    AWBConfig        statsConfig;      ///< Statistics configuration for AWB.

} AWBStatsControl;

/// @brief Frame control information for autofocus.
typedef struct
{
    RectangleCoordinate    ROICoordinate;                 ///< Coordinates of the default ROI rectangle.
    MoveLensOutput         moveLensOutput;                ///< Information about the default lens movement.

    BOOL                   exposureCompensationEnable;    ///< Indicates whether exposure compensation is enabled.
                                                          ///
                                                          ///  @valuesbul
                                                          ///  - 0 -- FALSE
                                                          ///  - 1 -- TRUE @tablebulletend

    FOVCOutput             fovcOutput;                    ///< Field of view compensation factor.
    PDLibWindowConfig      PDLibROI;                      ///< ROI information for the type 1 sensor.
    FLOAT                  focalLengthRatio;              ///< Focal length ratio
} AFFrameControl;

/// @brief Frame control information for Auto Flicker Detection.
typedef struct
{
    StatsRowSum rowSumStats[MaxNumOfInputExposures];    //< RowSum Stats used to determine flicker.
} AFDFrameControl;

/// @brief Statistics control information for autofocus.
typedef struct
{
    // External Member Variables
    AFConfigParams  statsConfig;                    ///< Configuration of Bayer autofocus statistics.
    CAFConfigParams CAFStatsConfig;                 ///< Configuration of contrast autofocus statistics.
} AFStatsControl;

/// @brief Sensitivity information for AEC Fast Convergence.
typedef struct
{
    FLOAT                   sensitivity[AlgoOutputExposureCount];       ///< Initial sensitivity information.
    AECStartupMode          startMode;                                  ///< AEC startup mode.
    FLOAT                   startUpLuxIndex;                            ///< Indicates the scene brightness on AEC startup.
    FLOAT                   startUpCompenDarkBoostGain;                 ///< Indicates the compensation for dark boost gain
                                                                        ///  on AEC startup.
    FLOAT                   startUpCompenADRCGain;                      ///< Indicates the compensation for ADRC gain on AEC
                                                                        ///  startup.
} AECStartupSensitivity;

/// @brief Initial statistics configuration used for stream initialization during a camera open sequence.
typedef struct
{
    StatsOperationMode      operationMode;                         ///< Indicates the initial converge speed requested
                                                                   ///  during a camera open sequence.
    AECStartupSensitivity   aecStartSensitivity;                   ///< Initial sensitivity information for the AEC.
    AWBFrameControl         awbFrameControl;                       ///< Initial startup gains for AWB.
} StatsStreamInitConfig;

/// @brief Statistics control information for Auto Flicker Detection (AFD).
typedef struct
{
    // External Member Variables
    AFDStatsRSConfig    statsConfig;                                ///< Statistics configuration for the row sum.
    AFDStatsRSConfig    bayerRSStatsConfig;                         ///< Statistics configuration for the Bayer row sum.
    StatsFCGConfig      statsFCGConfig;                             ///< Stats FCG Configuration
} AFDStatsControl;

/// @brief Statistics control information for the image histogram.
typedef struct
{
    // External Member Variables
    IHistStatsConfig    statsConfig;    ///< Statistics configuration for the image histogram. If the ROI is 0, the image
                                        ///  histogram uses the default ROI (full).
} IHistStatsControl;

/// @brief Statistics control information for the column sum.
typedef struct
{
    // External Member Variables
    CSStatsConfig    statsConfig;    ///< Statistics configuration for the column sum.
} CSStatsControl;

/** @} */ /* end_addtogroup chi_stats_prop */

#pragma pack(pop)

#ifdef __cplusplus
}
#endif // __cplusplus

#endif // CHISTATSPROPERTY_H
