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

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @file   chicommonhwconfigoverride.h
/// @brief  Defines Chi HwNode Common Configuration
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

#ifndef CHICOMMONHWCONFIGOVERRIDE_H
#define CHICOMMONHWCONFIGOVERRIDE_H

#include <inttypes.h>
#include <string.h>
#include "camera_metadata.h"

#include "camxcdktypes.h"
#include "camxdefs.h"
#include "camxosutils.h"
#include "chituningmodeparam.h"
#include "chivendortagdefines.h"
#include "chivendortagoemdefines.h"
#include "chxdebugprint.h"
#include "tuningsetmanager.h"

#include "camxhal3metadatatags.h"
#include "camxhal3metadatatagtypes.h"
#include "camxsensorproperty.h"

static const UINT32 OEMFeatureTypeCapability  = 64;          ///< OEM feature type capability
static const UINT32 MaxGammaSize              = 512;         ///< Maximum number of OEM Gamma Size
static const UINT32 MaxGammaTableSize         = 257;         ///< Maximum number of Gamma Table Size
static const UINT32 MaxOEMTriggerCount        = 5;           ///< Maximun number of OEM trigger customization
static const UINT32 ColorCorrectionRows       = 3;           ///< Color correction transform matrix rows
static const UINT32 ColorCorrectionColumns    = 3;           ///< Color correction transform matrix columns
static const UINT32 LSC_MESH_PT_H_MAX         = 17;          ///< MESH_PT_H = MESH_H + 1
static const UINT32 LSC_MESH_PT_V_MAX         = 13;          ///< MESH_PT_V = MESH_V + 1
static const UINT32 LSC_CHANNEL_MAX           = 4;           ///< 4 LSC channel
static const UINT32 MaxGTMLUTSize             = 256;         ///< Maximum number of OEM GTM YRatio curve size

/// @brief  Define IQControl
enum OEMIQControl
{
    OEMIQControlNone            = 0,            ///< OEM do nothing for this IQ module
    OEMIQControlOverwrite,                      ///< OEM overwrite HW node input data
    OEMIQControlUseLastValid,                   ///< OEM enable this IQ module but use last frame valid data
    OEMIQControlCalculateNoApply,               ///< OEM enable IQ module calculation but not apply
};

/// @brief  Define HW node common OEM feature type
enum CommonOEMFeatureType
{
    CommonOEMInputBufferType          = 0,      ///< OEM feature type of input buffer requirement
    CommonOEMMetadataType,                      ///< OEM feature type of using metadata
    CommonOEMTuningModeType,                    ///< OEM feature type of tuning mode overwrite
    CommonOEMTuningSetManagerType,              ///< OEM feature type of TuningSetManager
    CommonOEMIQTriggerType,                     ///< OEM feature type of IQ trigger

    CommonOEMFeatureTypeNumber,                 ///< OEM feature type supported number
};

/// @brief Define OEM LSC Modes
enum OEMLSCModeType
{
    OEMLSCMeshTableOnly = 0,                       ///< Overwrite MeshTable Only
    OEMLSCSensorDataOnly,                          ///< Overwrite SensorData Only
    OEMLSCSensorDataWithSR,                        ///< Overwrite SensorData and disable SR
    OEMLSCModeMax,
};

/// @brief Define OEM Gamma Modes
enum OEMGammaModeType
{
    OEMGammaToneMapCurvesOnly = 0,                 ///< Overwrite ToneMap Only
    OEMGammaWeightOnly,                            ///< Overwrite Weight Only
    OEMGammaModeMax,
};

/// @brief Defines the Query type InputBufferNego data to OEM structure
struct InputBufferNegoToOEM
{
    UINT32      optimalInputWidth;              ///< required optimal width
    UINT32      optimalInputHeight;             ///< required optimal height
    UINT32      minInputWidth;                  ///< required min width
    UINT32      minInputHeight;                 ///< required min height
    UINT32      maxInputWidth;                  ///< required max width
    UINT32      maxInputHeight;                 ///< required max height
};

/// @brief Defines the Query type InputBufferNego data to Hw Node structure
struct OEMInputBufferNegoToHwNode
{
    UINT32      OEMOptimalInputWidth;           ///< OEM Optimal input width
    UINT32      OEMOptimalInputHeight;          ///< OEM Optimal input height
};

/// @brief Define the metadata information structure
struct HwCfgMetaInfo
{
    UINT*   pTagIdList;         ///< Array of tag id used to get metadata
    VOID**  ppDataList;         ///< Array of data to update in the pool
                                ///  Only ppDataList is filled by HW Node, others are filled by OEM
    UINT64* pOffsetList;        ///< Array of offsets from the current requestID to determine
                                ///  slot from which data pointer is obtained
    BOOL*   pNegateList;        ///< Array of negate flags to indicate if the value of offsets are negative
    UINT32* pTypeIdList;        ///< Array of Type IDs which represents types for a given meta data
    SIZE_T  length;             ///< Length of all the arrays
};

/// @brief Define Valid Float Data Type
struct OEMValidFLOAT
{
    BOOL                isValid;
    FLOAT               data;
};

/// @brief parameters needed by OEMs for their lsc calculation.
struct LSCSensorDataToOEMParameter
{
    const CamX::EEPROMOTPData*          pOTPData;                      ///< OTP Calibration Data
    const CamX::SensorMode*             pSensorMode;                   ///< Sensor mode related data for the current mode
    UINT32                              SFEBinningFactor;              ///< SFE Binning Factor Data
};

/// @brief parameters needed by OEMs for their IQTriggerData calculation.
struct NodeIQTriggerToOEMParameter
{
    UINT32          cameraId;                  ///< Camera ID
    BOOL            isRealTime;                ///< Has Sensor node
};

/// @brief Define OEM LSC MeshTable configuration
struct LSCMeshTable
{
    UINT16*         pMeshTable;                             /// OEM calculated mesh table
};

/// @brief Define OEM LSC Sensor configuration
struct LSCSensorData
{
    UINT32          sensorFullResolutionWidth;              ///< Sensor active array width
    UINT32          sensorFullResolutionHeight;             ///< Sensor active array height
    UINT32          imageWidth;                             ///< Image Width;
    UINT32          imageHeight;                            ///< Image Height;
    UINT32          sensorOffsetX;                          ///< Current Sensor Image Output horizontal offset
    UINT32          sensorOffsetY;                          ///< Current Sensor Image Output vertical offset
    UINT32          scale;                                  ///< Include Sensor scalei*Binning*CSID&SFE Binning
};

/// @brief Define OEM LSC Sensor and SR configuration
struct LSCSensorDataWithSR
{
    LSCSensorData   sensorData;                             ///< Sensor Data
    BOOL            disableSR;                              ///< Flag to disable SR
};

/// @brief OEM Trigger Data
struct OEMTriggerData
{
    OEMValidFLOAT    CustomAEC[MaxOEMTriggerCount];      ///< OEM Input Trigger AEC
    OEMValidFLOAT    CustomAWB[MaxOEMTriggerCount];      ///< OEM Input Trigger AWB
    OEMValidFLOAT    CustomAF[MaxOEMTriggerCount];       ///< OEM Input Trigger AF
    OEMValidFLOAT    CustomReserved[MaxOEMTriggerCount]; ///< OEM Input Trigger Reserved
    OEMValidFLOAT    DRCGain;                            ///< OEM Trigger DRCGain
    OEMValidFLOAT    DRCGainDark;                        ///< OEM Trigger DRCGainDark
    OEMValidFLOAT    AECSensitivity;                     ///< OEM Trigger AEC sensitivity
};

/// @brief Define OEM tintless dynamic disable
struct OEMTintlessDisableControl
{
    BOOL            isTintlessDisabled;                                     ///< dynamic disable tintless
};

/// @brief parameters needed by OEMs for their GTM curve calculation.
struct GTMInputToOEM
{
    BOOL          IsFirstRequestAfterFlush;                             ///< requead Id after flush for init time
    UINT          fps;                                                  ///< framerate
};

/// @brief parameters needed by OEMs for their GTM curve calculation.
struct GTMManualCurveInfo
{
    DOUBLE         YratioBase[YRatioGTMLUTSize + 1];     ///< manual curve
    FLOAT          CurveStrength;                        ///< manual curve strength
};

/// @brief Define OEM tintless dynamic disable
struct OEMLSCCalibrationTable
{
    OEMIQControl    IQControl;                              ///< OEM mask to control need overwrite/use last
                                                            /// configuration/calculate but not apply.
                                                            /// Following data would be used
                                                            /// only when OEMIQControlOverwirte
    UINT32 numberOfLightSrc;
    FLOAT  calibB[CamX::MaxLightTypes][CamX::HWRollOffTableSize];
    FLOAT  calibR[CamX::MaxLightTypes][CamX::HWRollOffTableSize];
    FLOAT  calibGB[CamX::MaxLightTypes][CamX::HWRollOffTableSize];
    FLOAT  calibGR[CamX::MaxLightTypes][CamX::HWRollOffTableSize];
};

/// @brief Define OEM LSC fast converge
struct OEMLSCFastConvergeControl
{
    BOOL            isLSCFastConvergeEnabled;               ///< Will force to run LSC & disable temporal filtering if enabled.
};

#endif //CHICOMMONHWCONFIGOVERRIDE_H
