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

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @file   chiipeconfigoverride.h
/// @brief  Defines IPE Node Override Configuration
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

#ifndef CHIIPECONFIGOVERRIDE_H
#define CHIIPECONFIGOVERRIDE_H

#include "chicommonhwconfigoverride.h"

/// @brief  Defines the property of a IPE Node.
struct ChiIPENodeProperty
{
    UINT profileId;                                         ///< Profile Id
    UINT stabilizationType;                                 ///< Stability Id
    UINT processingType;                                    ///< Processing type
};

/// @brief  Define IPE OEM feature type
enum OEMIPEFeatureType
{
    IPEIQControlGammaType       = CommonOEMFeatureTypeNumber,   ///< OEM feature type of gamma control
    IPEIQControlCCMType,                                        ///< OEM feature type of ccm control
    IPEOnlineTuningType,                                        ///< OEM feature type of online tuning
    IPEIQControlASFType,                                        ///< OEM feature type of asf control
    IPEOverwriteFaceLevel,                                      ///< OEM feature type of overwriting face level
    IPEIQControlUVGamma,                                        ///< OEM feature type of uv gamma control
    IPEIQControlWBType,                                         ///< OEM feature type of wb control

    IPEFeatureTypeNumber,                                       ///< OEM feature type supported number
    IPEFeatureTypeMax           = OEMFeatureTypeCapability      ///< OEM feature type capability
};

static_assert(IPEFeatureTypeNumber < IPEFeatureTypeMax, "IPE OEM Feature type number overflow!");

static const UINT64 IPEInputBufferTypeMask          = (1ULL << static_cast<UINT>(CommonOEMInputBufferType));
static const UINT64 IPEMetadataTypeMask             = (1ULL << static_cast<UINT>(CommonOEMMetadataType));
static const UINT64 IPETuningModeTypeMask           = (1ULL << static_cast<UINT>(CommonOEMTuningModeType));
static const UINT64 IPETuningSetManagerTypeMask     = (1ULL << static_cast<UINT>(CommonOEMTuningSetManagerType));
static const UINT64 IPEIQTriggerCustomizeMask       = (1ULL << static_cast<UINT>(CommonOEMIQTriggerType));
static const UINT64 IPEIQControlGammaTypeMask       = (1ULL << static_cast<UINT>(IPEIQControlGammaType));
static const UINT64 IPEIQControlCCMTypeMask         = (1ULL << static_cast<UINT>(IPEIQControlCCMType));
static const UINT64 IPEOnlineTuningTypeMask         = (1ULL << static_cast<UINT>(IPEOnlineTuningType));
static const UINT64 IPEIQControlASFTypeMask         = (1ULL << static_cast<UINT>(IPEIQControlASFType));
static const UINT64 IPEOverwriteFaceLevelMask       = (1ULL << static_cast<UINT>(IPEOverwriteFaceLevel));
static const UINT64 IPEIQControlUVGammaMask         = (1ULL << static_cast<UINT>(IPEIQControlUVGamma));
static const UINT64 IPEIQControlWBTypeMask          = (1ULL << static_cast<UINT>(IPEIQControlWBType));

/// @brief Define IPE OEM Gamma Configuration
struct OEMGammaPoint
{
    FLOAT                   point[2];                       ///< OEM Gamma point data
};

/// @brief Define OEM Gamma Channel Table
struct GammaChannelTable
{
    OEMGammaPoint           oemGammaR[MaxGammaSize];        ///< OEM gamma table for channel R
    OEMGammaPoint           oemGammaG[MaxGammaSize];        ///< OEM gamma table for channel G
    OEMGammaPoint           oemGammaB[MaxGammaSize];        ///< OEM gamma table for channel B
};

/// @brief Define OEM Gamma Weight Table
struct GammaWeightTable
{
    BOOL                    enableGammaWeight;              ///< Flag to indicate Gamma Weights is eanbled/disabled
    UINT32                  numOfGammaWeights;              ///< Indicates the number of valid data in Gamma Weight Table
    FLOAT*                  pGammaWeightForR;               ///< Pointer to Gamma Weight for R
    FLOAT*                  pGammaWeightForG;               ///< Pointer to Gamma Weight for G
    FLOAT*                  pGammaWeightForB;               ///< Pointer to Gamma Weight for B
};

/// @brief  Define IPE OEMGamma Configuration
struct OEMGammaToIPENode
{
    OEMIQControl            IQControl;                      ///< OEM mask to control need overwrite/use last configuration
                                                            ///< Following data would be used only when OEMIQControlOverwrite

    OEMGammaModeType        GammaMode;                      ///< Indicate OEM Gamma Mode

    union
    {
        GammaChannelTable   toneMapCurves;                  ///< Gamma Tone Map Curves
        GammaWeightTable    weights;                        ///< Gamma Weights
    };
};

enum ASFFeatureSubType
{
    ASFFeatureSubTypeGainWeight = 0,                        ///< ASF gain weight for LUT
    ASFFeatureSubTypeSharpness,                             ///< ASF sharpness adjust
};

/// @brief Define OEM ASF Gain LUT Weight Table
struct ASFGainLUTWeight
{
    FLOAT   gainLUTWeightForLayer1;                 ///< Layer1 Gain LUT Weight
    FLOAT   gainLUTWeightForLayer2;                 ///< Layer2 Gain LUT Weight
};

/// @brief Define OEM ASF Sharpness Weight
struct ASFSharpnessWeight
{
    FLOAT   sharpness;                              ///< sharpness data
    FLOAT   sharpnessWeightForLayer1;               ///< Layer1 sharpness LUT Weight
    FLOAT   sharpnessWeightForLayer2;               ///< Layer2 sharpness LUT Weight
};

/// @brief  Define IPE OEM ASF Configuration
struct OEMASFToIPENode
{
    OEMIQControl            IQControl;                      ///< OEM mask to control need overwrite/use last configuration
                                                            ///< Following data would be used only when OEMIQControlOverwrite
    ASFFeatureSubType       subType;                        ///< ASF subtype, gain weight or sharpness weight
    union
    {
        ASFGainLUTWeight      asfGainLUTData;               ///< ASF gain lut weight
        ASFSharpnessWeight    asfSharpnessData;             ///< ASF sharpness weight
    };
};

/// @brief Define OEM CCM configuration
struct OEMCCMToIPENode
{
    OEMIQControl    IQControl;                                          ///< OEM mask to control need overwrite/use last
                                                                        /// configuration. Following data would be used
                                                                        /// only when OEMIQControlOverwrite

    CamxRational    CCM[ColorCorrectionRows][ColorCorrectionColumns];   ///< Color correction matrix
};

/// @brief Define OEM Trigger
struct OEMTriggerToIPENode
{
    OEMIQControl    IQControl;                                          ///< OEM mask to control need overwrite/use last
                                                                        /// configuration. Following data would be used
                                                                        /// only when OEMIQControlOverwrite

    OEMTriggerData  triggerData;                                        /// OEM Trigger Data
};


/// @brief OEM WB weight data
struct WBData
{
    FLOAT           resGGain;                                     ///< WB G gain
    FLOAT           resBGain;                                     ///< WB B gain
    FLOAT           resRGain;                                     ///< WB R gain
};

/// @brief Define OEM CCM configuration
struct OEMWBToIPENode
{
    OEMIQControl    IQControl;                                          ///< OEM mask to control need overwrite/use last
                                                                        /// configuration. Following data would be used
                                                                        /// only when OEMIQControlOverwrite
    WBData          wbData;                                             ///< WB data
};

/// @brief Define IPE data structure to OEM, feature type would decide which data should be used
struct IPEFeatureTypeDataToOEM
{
    BOOL                            isRealTimeIPE;              ///< IPE is part of realtime pipeline

    union
    {
        TuningSetManager*           pTuningSetManager;          ///< Pointer to tuning set manager
        ChiTuningModeParameter      tuningModeData;             ///< Tuning mode to OEM
        NodeIQTriggerToOEMParameter IQTriggerInputToOEM;        ///< parameters needed by OEMs for their IQTriggerData calculation.
    };
};

/// @brief Define IPE data structure to Hw node, feature type would decide which data should be used
struct OEMFeatureTypeDataToIPENode
{
    union
    {
        HwCfgMetaInfo*                   pHwCfgMetaInfo;         ///< Meta Data Info
        ChiTuningModeParameter           tuningModeData;         ///< Tuning mode to HwNode
        OEMASFToIPENode                  asfData;                ///< ASF data to HwNode
        OEMGammaToIPENode                gammaData;              ///< Gamma data to HwNode
        OEMCCMToIPENode                  ccmData;                ///< CCM data to HwNode
        OEMTriggerToIPENode              oemTriggerData;         ///< OEM Triggger to HwNode
        OEMIPEIQSetting*                 pOnlineTuningSetting;   ///< OEM IQ cfg settings for OnlineTuning
        FLOAT                            oemFaceLevel;           ///< OEM face level
        BOOL                             oemUVGammaEnable;       ///< OEM UV Gamma data to HWNode
        OEMWBToIPENode                   wbData;                 ///< WB data to HwNode
    };
};

#endif //CHIIPECONFIGOVERRIDE_H

