////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2018-2024 Qualcomm Technologies, Inc.
// All Rights Reserved.
// Confidential and Proprietary - Qualcomm Technologies, Inc.
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @file chieisdefs.h
/// @brief Define Qualcomm Technologies, Inc. EIS proprietary data for defining internal data structures
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

#ifndef CHIEISDEFS_H
#define CHIEISDEFS_H
#include "camxcdktypes.h"

#ifdef __cplusplus

extern "C"
{
#endif // __cplusplus


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

static const CHAR* VendorTagSectionEISLookAheadConfig = "org.quic.camera.eislookahead"; ///< Lookahead EIS config vendor tag section
static const CHAR* VendorTagNameEISLookAheadConfig    = "EISLookAheadConfig";           ///< Lookahead EIS config vendor tag name

static const CHAR* VendorTagSectionEISRealTimeConfig = "org.quic.camera.eisrealtime"; ///< RealTime EIS config vendor tag section
static const CHAR* VendorTagNameEISRealTimeConfig    = "EISRealTimeConfig";           ///< RealTime EIS config vendor tag name

#define MAX_SIZEOF_BUFF_DIS 13568
#define VIDEO4KWIDTH        3840
#define VIDEO4KHEIGHT       2160
#define VIDEO8KWIDTH        7680
#define DISEXTRABUFFERFPS   30

/// @brief Structure Stabilization Margins to be set to the ICA or GPU
struct StabilizationMargin
{
    UINT32 widthPixels;  ///< Margins on the width in pixels
    UINT32 heightLines;  ///< Margins on the height in pixels
    UINT32 fullWidth;    ///< Full width of input in pixels
    UINT32 fullHeight;   ///< Full height of input in pixels
};

/// @brief Structure Request Margins during buffer negotiation
struct MarginRequest
{
    FLOAT widthMargin;   ///<Request margins on the width in percentage (Eg. 0.2 for 20%)
    FLOAT heightMargin;  ///<Request margins on the height in percentage (Eg. 0.1 for 10%)
};

/// @brief Structure DIS motion vector
struct DISMVStats
{
    uint32_t  cvp_mv_image_width;
    uint32_t  cvp_mv_image_height;
    float     cvp_alignment_matrix[9];
    uint32_t  cvp_alignment_matrix_confidence;
    uint32_t  cvp_alignment_matrix_model_type;
    uint32_t  buff_size_bytes;
    uint8_t   buff[MAX_SIZEOF_BUFF_DIS];
};

/// @brief Structure MOFAlignment Warp matrices
struct MOFAlignment
{
    bool      eis_mof_enable;                      // Enable perspective matrices
    uint32_t  eis_mof_image_width;                 // Perspective transform defined on width
    uint32_t  eis_mof_image_height;                // Perspective transform defined on height
    uint32_t  eis_alignment_matrix_transform_type; // Type of perspective transform
    uint32_t  eis_alignment_matrix_confidence;     // Perspective transform confidence parameter
    uint32_t  eis_mof_numRows;                     // Number of rows in array
    uint32_t  eis_mof_numColumns;                  // Number of columns in array
    float     eis_mof_alignment_matrix[9];         // 2-dimensional array of perspective transform matrices
};

/// @brief Enum EIS OIS operation mode
enum EISOISMode
{
    eisOisModeInvalid         = 0,        /**< Output OIS mode is invalid and should be ignored by CamX node,
                                            *   in case previous decision exists in the system use it */
    eisOisModeCenter          = 1,        /**< OIS mode should be switched to center */
    eisOisModeAutomatic       = 2         /**< OIS mode should be switched to automatic operation mode */
};

/// @brief Structure EIS OIS mode data
struct EISOISModeData
{
    EISOISMode    eisOisMode;
    UINT32        sensorIndex;
};

/// @brief Window region crop of interest
typedef struct
{
    float         fullWidth;
    float         fullHeight;
    float         windowWidth;
    float         windowHeight;
    float         windowLeft;
    float         windowTop;
} WindowRegionCropF;

/// @brief Structure Window ROI
struct EISWindowROI
{
    WindowRegionCropF sensorCrop;    // Sensor crop
    WindowRegionCropF preCropVin;    // window at vIN. Relative to IFE input size and FOV
    WindowRegionCropF preCropVout;   // Window at Vout.
    WindowRegionCropF outputCropFOV; // crop ROI that ICA is doing.
};

/// @brief Control for EIS Horizon Leveling
typedef struct EISHorizonLevelControl
{
    INT32   isEnabled;          // Indicate if Horizon Leveling is enabled
    FLOAT   maxRollLevelingDeg; // Control the max degree of Horizon Leveling
} EISHorizonLevelControl;

/// @brief Structure Distortion correction grid meta. Below struct taken from is_interface.h and re-declare here.
///        if anychange happens in is_interface.h, make sure to update here.
struct DistortionCorrectionGridMeta
{
    uint32_t        header[4];          /**< Packet header */
    EISWindowROI    window_regions;     /**< ROI window where grid is calulated */
    uint64_t        last_gyro_ts;       /**< Last ts of gyro sample where grid is calulated */
    uint64_t        last_ois_ts;        /**< Last ts of ois sample where grid is calulated */
    uint64_t        last_ifovc_ts;      /**< Last ts of ifovc sample where grid is calulated */
    uint32_t        reserverd[26];      /**< Reserved parameters */
    uint32_t        footer[4];          /**< Packet footer */
};

/// @brief Structure Bayer alignment shift offset
struct BayerAlignmentShiftOut
{
    INT16 shiftX; // Shift along X axis
    INT16 shiftY; // Shift along Y axis
};

/// @brief Motion Vector Domain
enum MotionVectorDomain
{
    UndistortedImageDomain   = 0, ///< Undistorted Image Domain
    DistortedImageDomain     = 1, ///< Distorted Image Domain
    NoMotionVectorDomain     = 2, ///< If DIS is disabled, Domain will be none.
};

#pragma pack(pop)

#ifdef __cplusplus
}
#endif // __cplusplus

#endif // CHIIPEDEFS_H
