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

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @file chiipedefs.h
/// @brief Define Qualcomm Technologies, Inc. IPE proprietary data for defining internal data structures
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

#ifndef CHIIPEDEFS_H
#define CHIIPEDEFS_H
#include "camxcdktypes.h"
#include "GeoLib.h"
#include "Process_ICA.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)

#define SW_MAX_NUM_FACES   10
#define MAX_CATEGORY       32
#define MAX_COLOR_CHANNELS 3
#define MAX_STATS_BINS     256
#define MAX_STATS_CHANNELS 4 // 3 channels for RGB stats, 4 for HSV and YUV stats

static const UINT ICAMaxPerspectiveTransform             = 9;
static const UINT ICAParametersPerPerspectiveTransform   = 9;
static const UINT ICA10GridTransformWidth                = 33; // 33 for ICA10, 35 for ICA20
static const UINT ICA10GridTransformHeight               = 25; // 25 for ICA10, 27 for ICA20
static const UINT ICA20GridTransformWidth                = 35; // 33 for ICA10, 35 for ICA20
static const UINT ICA20GridTransformHeight               = 27; // 25 for ICA10, 27 for ICA20
static const UINT ICA30GridTransformWidth                = 67; // 67 for ICA30
static const UINT ICA30GridTransformHeight               = 51; // 51 for ICA30
static const UINT ICA32GridTransformWidth                = 67; // 67 for ICA30
static const UINT ICA32GridTransformHeight               = 51; // 51 for ICA30
static const UINT ICA40GridTransformWidth                = 67; // 67 for ICA40,
static const UINT ICA40GridTransformHeight               = 51; // 51 for ICA40,
static const UINT ICA41GridTransformWidth                = 67; // 67 for ICA41,
static const UINT ICA41GridTransformHeight               = 51; // 51 for ICA41,
static const UINT ICA43GridTransformWidth                = 67; // 67 for ICA43,
static const UINT ICA43GridTransformHeight               = 51; // 51 for ICA43,
static const UINT MaxGeoLibIpeFrameConfigTagCount        = 4;  // Maximum instances of Geolib tags
static const UINT MaxPolygonSize                         = 32; // Max size of Polygon

///< ICA Virtual domain dimensions
static const uint32_t IcaVirtualDomainWidth  = 8192;
static const uint32_t IcaVirtualDomainHeight = 6144;

///< Cascade 2D LUT control params
static const UINT     MaxCascade2DLutScene   = 2;

/// @brief IPE ICA Grid Geometry
enum ICAGridGeometry
{
    ICAGeometryCol33Row25 = 0,    /// geometry 33 * 25 for ICA10
    ICAGeometryCol35Row27,        /// geometry 35 * 27 for ICA20
    ICAGeometryCol67Row51,        /// geometry 35 * 27 or 67 * 51 ICA30
};

/// @brief IPE ICA domain
enum ICAImageDomain
{
    Distorted = 0,    /// Input image before LDC, RSC, and OISC
    UnDistorted,      /// The domain after applying LDC, RSC, and OISC, but before stabilization
    Stabilized,       /// Output image after stabilization
};

/// @brief Alignment mode data type, also know as DMM/DME
enum AlignmentMode
{
    AlignmentModeNone      = 0x0000,        ///< Invalid none alignment mode
    AlignmentModeTransform = 0x0001,        ///< Use DME to store transform vector
    AlignmentModeMotionMap = 0x0002,        ///< Use DMM to store dense motion map vector, 8x8 pixels per vector
};

/// @brief Cascade 2D LUT control parameters
struct Cascade2DLUTControl
{
    BOOL                        enable;                                 ///< If enable cascade 2D LUT processing per request
    ChiModeSceneSubModeType     sceneOverride[MaxCascade2DLutScene];    ///< The 1st/2nd 2DLUT scene mode override value by OEM
};

/// @brief IPE ICA Grid Array coordinates
typedef struct
{
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// ICAGridArray x coordinate
    ///
    /// Description:   points x coordinate
    /// Type:          FLOAT
    /// Default Value: 0
    /// Range:         [-8192.0f-8191.75f]
    /// Bit Depth:     float
    /// Conversion:    No Conversion needed
    /// Notes:         None
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    FLOAT x;

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// ICAGridArray y coordinate
    ///
    /// Description:   points y coordinate
    /// Type:          FLOAT
    /// Default Value: 0
    /// Range          [-6144.0f-6144.0f]
    /// Bit Depth:     float
    /// Conversion:    No Conversion needed
    /// Notes:         None
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    FLOAT y;
} ICAGridArray;

/// @brief IPE ICA perspective transform associated with vendor tag
typedef struct
{
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// perspectiveTransformEnable
    ///
    /// Description:   Enable or Disable perspective transform
    /// Type:          UINT32
    /// Default Value: 0
    /// Range:         [0, 1]
    /// Bit Depth:     1u
    /// Conversion:    No Conversion needed
    /// Notes:         None
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    UINT32 perspectiveTransformEnable;

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// ReusePerspectiveTransform
    ///
    /// Description:   Reuse stored perspective transform from older frame
    /// Type:          UINT32
    /// Default Value: 0
    /// Range:         [0, 1]
    /// Bit Depth:     1u
    /// Conversion:    No Conversion needed
    /// Notes:         None
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    UINT32 ReusePerspectiveTransform;

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// perspetiveGeometryNumColumns
    ///
    /// Description:   The geometry of the perspective transform partitioning is described in terms of MxN. N stands for column
    /// Type:          UINT32
    /// Default Value: 0
    /// Range:         [1, 9]. MxN = 9
    /// Bit Depth:     1u
    /// Conversion:    No Conversion needed
    /// Notes:         None
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    UINT32 perspetiveGeometryNumColumns;

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// perspectiveGeometryNumRows
    ///
    /// Description:   The geometry of the perspective transform partitioning is described in terms of MxN. M stands for row
    /// Type:          UINT8
    /// Default Value: 0
    /// Range:         [1, 9]. MxN <= 9
    /// Bit Depth:     1u
    /// Conversion:    No Conversion needed
    /// Notes:         None
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    UINT8 perspectiveGeometryNumRows;

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// perspectiveTransformArray
    ///
    /// Description:   Perspective transform parameters, Made up of 81 floats (up to 9 sets * 9 parameters each)
    /// Type:          FLOAT
    /// Default Value: 1.0f 0.0f 0.0f 0.0f 1.0f 0.0f 0.0f 0.0f 1.0f
    ///                1.0f 0.0f 0.0f 0.0f 1.0f 0.0f 0.0f 0.0f 1.0f
    ///                1.0f 0.0f 0.0f 0.0f 1.0f 0.0f 0.0f 0.0f 1.0f
    ///                1.0f 0.0f 0.0f 0.0f 1.0f 0.0f 0.0f 0.0f 1.0f
    ///                1.0f 0.0f 0.0f 0.0f 1.0f 0.0f 0.0f 0.0f 1.0f
    ///                1.0f 0.0f 0.0f 0.0f 1.0f 0.0f 0.0f 0.0f 1.0f
    ///                1.0f 0.0f 0.0f 0.0f 1.0f 0.0f 0.0f 0.0f 1.0f
    ///                1.0f 0.0f 0.0f 0.0f 1.0f 0.0f 0.0f 0.0f 1.0f
    ///                1.0f 0.0f 0.0f 0.0f 1.0f 0.0f 0.0f 0.0f 1.0f
    /// Range:         -4294836224.0f - 2147418112.0f
    /// Bit Depth:     float
    /// Conversion:    No Conversion needed
    /// Notes:         None
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    FLOAT perspectiveTransformArray[ICAMaxPerspectiveTransform *
        ICAParametersPerPerspectiveTransform];

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// perspectiveConfidence
    ///
    /// Description:   Confidence related parameter.
    /// Type:          UINT32
    /// Default Value: 0
    /// Range:         [0-1]
    /// Bit Depth:     1u
    /// Conversion:    No Conversion needed
    /// Notes:         None
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    UINT32 perspectiveConfidence;

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// byPassAlignmentMatrixAdjustement
    ///
    /// Description:   flag to skip alignment matrix adjustment, if needed for forced identity perspective transform cases.
    /// Type:          BOOL
    /// Default Value: 0
    /// Range:         [0-1]
    /// Bit Depth:     1u
    /// Conversion:    No Conversion needed
    /// Notes:         None
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    BOOL byPassAlignmentMatrixAdjustement;

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// transformDefinedOnWidth
    ///
    /// Description:   Width on which transform is defined.
    /// Type:          UINT32
    /// Default Value: 0
    /// Range:         [4, 8192]
    /// Bit Depth:     1u
    /// Conversion:    No Conversion needed
    /// Notes:         None
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    UINT32 transformDefinedOnWidth;

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// transformDefinedOnHeight
    ///
    /// Description:   Height on which transform is defined.
    /// Type:          UINT32
    /// Default Value: 0
    /// Range:         [4, 8192]
    /// Bit Depth:     1u
    /// Conversion:    No Conversion needed
    /// Notes:         None
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    UINT32 transformDefinedOnHeight;

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// alignmentMatrixDomain
    ///
    /// Description:   Alignmnet matrix domain.
    /// Type:          ICAImageDomain
    /// Default Value: 0
    /// Range:         [0-2]
    /// Bit Depth:     1u
    /// Conversion:    No Conversion needed
    /// Notes:         None
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    ICAImageDomain alignmentMatrixDomain;
} IPEICAPerspectiveTransform;

/// @brief IPE ICA grid transform associated with vendor tag
typedef struct
{
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// gridTransformEnable
    ///
    /// Description:   Parameter that indicates whether grid transform is enabled and in which mode.
    ///                0 = disabled, 1 = enabled using the Chromatix settings, 2 = enabled using the settings from this structure
    /// Type:          UINT32

    /// Default Value: 1
    /// Range:         [0, 1]
    /// Bit Depth:     1u
    /// Conversion:    No Conversion needed
    /// Notes:         None
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    UINT32 gridTransformEnable;

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// reuseGridTransform
    ///
    /// Description:   Reuse stored grid transform from older frame
    /// Type:          UINT8
    /// Default Value: 0
    /// Range:         [0, 1]
    /// Bit Depth:     1u
    /// Conversion:    No Conversion needed
    /// Notes:         None
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    UINT32 reuseGridTransform;

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// gridTransformArray (x,y) coordinates
    ///
    /// Description:   Made up of 825  FLOAT: 33 * 25 entries for ICA10, spanning uniformly across the output image:
    ///                Made up of 945  FLOAT: 35 * 27 entries for ICA20, spanning uniformly across the output image:
    ///                Made up of 3417 FLOAT: 67 * 51 entries for ICA30, spanning uniformly across the output image :
    ///                Top-left point maps coordinate (0,0) of the output image.
    ///                Top-right point maps coordinate (OutputWidth,0) of the output image.
    ///                Bottom-left point maps coordinate (0,OutputHeight) of the output image.
    ///                Bottom-left point maps coordinate (OutputWidth,OutputHeight) of the output image.
    /// Type:          ICAGridArray
    /// Default Value: 0
    /// Range:         X: [-8192.0f-8191.75f], Y : [-6144.0f-6144.0f]
    /// Bit Depth:     float
    /// Conversion:    No Conversion needed
    /// Notes:         The origins are located in the center of the input image.
    ///                Grid points map output coordinate to input coordinates. (0,0) is in the center of image
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    ICAGridArray gridTransformArray[ICA30GridTransformWidth *
        ICA30GridTransformHeight];

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// gridTransformArrayExtrapolatedCorners
    ///
    /// Description:   Parameter that indicates whether corners should be extrapolated or custom values are provided for corners
    ///                Valid only for ICA10
    /// Type:          UINT32
    /// Default Value: 0
    /// Range:         [0, 1]
    /// Bit Depth:     1u
    /// Conversion:    No Conversion needed
    /// Notes:         None
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    UINT32 gridTransformArrayExtrapolatedCorners;

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// gridTransformArrayCornersX
    ///
    /// Description:   Made up of 4 float corresponding to the corner pixels: top-left, top-right, bottom-left, bottom-right.
    ///                Used when grid_transform_array_extrapolate_corners is 0.
    ///                Used for ICA10 only.
    /// Type:          FLOAT
    /// Default Value: 0
    /// Range:         [-8192.0f-8191.75f].
    /// Bit Depth:     float
    /// Conversion:    No Conversion needed
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// gridTransformArrayCorners (x,y) coordinates
    ///
    /// Description:   Made up of 4 float corresponding to the corner pixels: top-left, top-right, bottom-left, bottom-right.
    ///                Used when grid_transform_array_extrapolated_corners is 1 or true.
    /// Type:          ICAGridArray
    ///                Used for ICA10 only.
    /// Default Value: 0
    /// Range:         [-8192.0f-8191.75f].
    /// Bit Depth:     float
    /// Conversion:    No Conversion needed
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    ICAGridArray gridTransformArrayCorners[4];

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// transformDefinedOnWidth
    ///
    /// Description:   Width on which transform is defined.
    /// Type:          UINT32
    /// Default Value: 0
    /// Range:         [4, 8192]
    /// Bit Depth:     1u
    /// Conversion:    No Conversion needed
    /// Notes:         None
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    UINT32 transformDefinedOnWidth;

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// transformDefinedOnHeight
    ///
    /// Description:   Height on which transform is defined.
    /// Type:          UINT32
    /// Default Value: 0
    /// Range:         [4, 8192]
    /// Bit Depth:     1u
    /// Conversion:    No Conversion needed
    /// Notes:         None
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    UINT32 transformDefinedOnHeight;

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// geometry
    ///
    /// Description:   Grid geometry parameters.
    /// Type:          UINT32
    /// Default Value: 0 for ICA10, 1 for ICA20, 1 or 2 ICA 30.
    /// Range:         [0-2]
    /// Bit Depth:     1u
    /// Conversion:    No Conversion needed
    /// Notes:         None
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    ICAGridGeometry geometry;

} IPEICAGridTransform;

/// @brief IPE ICA custom interpolation associated with vendor tag
typedef struct
{
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// customInterpolationEnabled
    ///
    /// Description:   Enable custom interpolation parameters. If disabled and y_interpolation_mode is 0 the interpolation is bicubic.
    /// Type:          UINT32
    /// Default Value: 0
    /// Range:         [0, 1]
    /// Bit Depth:     1u
    /// Conversion:    No Conversion needed
    /// Notes:         None
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    UINT32 customInterpolationEnabled;

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// reuseCustomInterpolationParams
    ///
    /// Description:   Reuse custom interpolation parameters from past frame
    /// Type:          UINT32
    /// Default Value: 0
    /// Range:         [0, 1]
    /// Bit Depth:     1u
    /// Conversion:    No Conversion needed
    /// Notes:         None
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    UINT32 reuseCustomInterpolationParams;

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// customInterpolationCoefficients0
    ///
    /// Description:   Interpolation coefficients for luma samples when y_interpolation_mode uses 4x4 kernel.
    /// Type:          INT16
    /// Default Value: 0 -60 -113 -158 -196 -228 -254 -273 -288 -298 -303 -303 -300 -293 -284 -271
    /// Range:         [-8192, 8191]
    /// Bit Depth:     14s
    /// Conversion:    No Conversion needed
    /// Notes:         None
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    INT16 customInterpolationCoefficients0[16];

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// customInterpolationCoefficients1
    ///
    /// Description:   Interpolation coefficients for luma samples when y_interpolation_mode uses 4x4 kernel.
    /// Type:          INT16
    /// Default Value: 2304 4086 4058 4011 3948 3869 3777 3670 3552 3423 3284 3136 2980 2818 2651 2479
    /// Range:         [-8192, 8191]
    /// Bit Depth:     14s
    /// Conversion:    No Conversion needed
    /// Notes:         None
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    INT16 customInterpolationCoefficients1[16];

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// customInterpolationCoefficients2
    ///
    /// Description:   Interpolation coefficients for luma samples when y_interpolation_mode uses 4x4 kernel.
    /// Type:          INT16
    /// Default Value: -256 72 159 259 372 497 632 776 928 1087 1253 1422 1596 1772 1950 2127
    /// Range:         [-8192, 8191]
    /// Bit Depth:     14s
    /// Conversion:    No Conversion needed
    /// Notes:         None
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    INT16 customInterpolationCoefficients2[16];

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// yInterpolationMode
    ///
    /// Description:   Parameter that defines the interpolation mode. 0-4x4 kernel, 1-Bi-linear.
    /// Type:          UINT32
    /// Default Value: 0
    /// Range:         [0, 1]
    /// Bit Depth:     1u
    /// Conversion:    No Conversion needed
    /// Notes:         None
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    UINT32 yInterpolationMode;

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// outOfFramePixelFillMode
    ///
    /// Description:   Parameter that defines Out-of-frame pixel is populated with a predefined value or duplication.
    ///                0: Out-of-frame pixel is populated with a predefined value.
    ///                1: Out-of-frame pixel is populated using duplication.
    /// Type:          UINT32
    /// Default Value: 0
    /// Range:         [0, 1]
    /// Bit Depth:     1u
    /// Conversion:    No Conversion needed
    /// Notes:         None
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    UINT32 outOfFramePixelFillMode;

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// outOfFramePixelFillConstY
    ///
    /// Description:   Y Output sample values for out-of-input-frame pixels when populated with predefined value.
    /// Type:          UINT32
    /// Default Value: 0
    /// Range:         [0, 1023]
    /// Bit Depth:     10u
    /// Conversion:    No Conversion needed
    /// Notes:         None
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    UINT32 outOfFramePixelFillConstY;

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// outOfFramePixelFillConstCb
    ///
    /// Description:   Cb Output sample values for out-of-input-frame pixels when populated with predefined value.
    /// Type:          UINT32
    /// Default Value: 0
    /// Range:         [0, 1023]
    /// Bit Depth:     10u
    /// Conversion:    No Conversion needed
    /// Notes:         None
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    UINT32 outOfFramePixelFillConsCb;

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// outOfFramePixelFillConsCr
    ///
    /// Description:   Cr Output sample values for out-of-input-frame pixels when populated with predefined value.
    /// Type:          UINT32
    /// Default Value: 0
    /// Range:         [0, 1023]
    /// Bit Depth:     10u
    /// Conversion:    No Conversion needed
    /// Notes:         None
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    UINT32 outOfFramePixelFillConsCr;
} IPEICAInterpolationParams;

/// @ triangulation of grid coordinates
typedef enum
{
    NE_DIRECTION       = 0,  ///< triangle strip NE direction
    NW_DIRECTION       = 1,  ///< triangle strip NW direction
    TOGGLING_DIRECTION = 2   ///< triangle strip Toggling direction
} UniformGridTriangulation;

/// @ extrapolation type used for out of grid samples
typedef enum
{
    GRID_EXTRAPOLATION_NEAREST       = 0, ///< using the coordinate of nearest neighbor
    GRID_EXTRAPOLATION_MV_NEAREST    = 1, ///< using the motion vector of nearest neighbor
    GRID_EXTRAPOLATION_APPROX_LINEAR = 2  ///< Approximate linear extrapolation (this is the recommended value)
} InverseGridExtrapolationType;

/// @brief IPE ICA inverse grid transform input associated with vendor tag
typedef struct
{
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// numRows
    ///
    /// Description:   # of samples in srcGridRow and # of rows in dstGridArray
    /// Type:          UINT32
    /// Default Value: 0
    /// Range:         [1, ICAGridTransformHeight]
    /// Bit Depth:     1u
    /// Conversion:    No Conversion needed
    /// Notes:         parameters of forward grid
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    UINT32                   numRows;

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// numColumns
    ///
    /// Description:   # of samples in srcGridColumn and # of col in dstGridArray
    /// Type:          UINT32
    /// Default Value: 0
    /// Range:         [1, ICA30GridTransformWidth]
    /// Bit Depth:     1u
    /// Conversion:    No Conversion needed
    /// Notes:         parameters of forward grid
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    UINT32                   numColumns;

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// srcGridRow
    ///
    /// Description:   Source rectangular grid y coordinates of rows
    /// Type:          FLOAT*
    /// Default Value: 0
    /// Range:         [-6144.00f-6144.00f]
    /// Bit Depth:     float
    /// Conversion:    No Conversion needed
    /// Notes:         parameters of forward grid,
    ///                The origins are located in the center of the input image.
    ///                (0, 0) is in the center of image
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    FLOAT*                   srcGridRow;

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// srcGridColumn
    ///
    /// Description:   Source rectangular grid x coordinates of columns
    /// Type:          FLOAT*
    /// Default Value: 0
    /// Range:         [-8192.0f-8191.75f]
    /// Bit Depth:     float
    /// Conversion:    No Conversion needed
    /// Notes:         parameters of forward grid
    ///                The origins are located in the center of the input image.
    ///                (0, 0) is in the center of image
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    FLOAT*                   srcGridColumn;

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// dstGridArray
    ///
    /// Description:   2-dimensional array of transform definedOn destination coordinates
    /// Type:          ICAGridArray*
    /// Default Value: 0
    /// Range:         [-8192.0f-8191.75f]
    /// Bit Depth:     float
    /// Conversion:    No Conversion needed
    /// Notes:         Max size ICA30GridTransformHeight * ICA30GridTransformWidth. parameters of forward grid.
    ///                The origins are located in the center of the input image. (0, 0) is in the center of image
    ///                at transformDefinedOnWidth/2, transformDefinedOnHeight/2 to keep centered coordinates
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    ICAGridArray*            dstGridArray;

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// inputTriangulationType
    ///
    /// Description:   triangulation type to be used at source
    /// Type:          enum UniformGridTriangulation
    /// Default Value: 0
    /// Range:         [0-2]
    /// Bit Depth:     enum
    /// Conversion:    No Conversion needed
    /// Notes:         parameters of forward grid
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    UniformGridTriangulation inputTriangulationType;

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// extrapolationType
    ///
    /// Description:   extrapolation type used for out-of-grid samples, Recommended value is
    ///                GRID_EXTRAPOLATION_APPROX_LINEAR.
    /// Type:          enum InverseGridExtrapolationType
    /// Default Value: 0
    /// Range:         [0-2]
    /// Bit Depth:     enum
    /// Conversion:    No Conversion needed
    /// Notes:         parameters of forward grid
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    InverseGridExtrapolationType extrapolationType;

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// reversedGridNumRows
    ///
    /// Description:   Number of rows in inverse grid
    /// Type:          UINT32
    /// Default Value: 0
    /// Range:         [1-ICA30GridTransformHeight]
    /// Bit Depth:     1u
    /// Conversion:    No Conversion needed
    /// Notes:         parameters of inverse grid
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    UINT32                   reversedGridNumRows;

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// reversedGridNumColumns
    ///
    /// Description:   Number of columns in inverse grid
    /// Type:          UINT32
    /// Default Value: 0
    /// Range:         [1-ICA30GridTransformWidth]
    /// Bit Depth:     1u
    /// Conversion:    No Conversion needed
    /// Notes:         parameters of inverse grid
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    UINT32                   reversedGridNumColumns;

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// reversedGridSourceTopLeftX
    ///
    /// Description:   Inverse grid: first x coordinate at source
    /// Type:          FLOAT
    /// Default Value: 0
    /// Range:         [-4096.00f-4096.00f]
    /// Bit Depth:     float
    /// Conversion:    No Conversion needed
    /// Notes:         parameters of inverse grid
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    FLOAT                    reversedGridSourceTopLeftX;

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// reversedGridSourceTopLeftY
    ///
    /// Description:   Inverse grid: first y coordinate at source
    /// Type:          FLOAT
    /// Default Value: 0
    /// Range:         [-3072.00f-3072.00f]
    /// Bit Depth:     float
    /// Conversion:    No Conversion needed
    /// Notes:         parameters of inverse grid
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    FLOAT                    reversedGridSourceTopLeftY;

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// reversedGridSourceBottomRightX
    ///
    /// Description:   Inverse grid: last x coordinate at source
    /// Type:          FLOAT
    /// Default Value: 0
    /// Range:         [-4096.00f-4096.00f]
    /// Bit Depth:     float
    /// Conversion:    No Conversion needed
    /// Notes:         parameters of inverse grid
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    FLOAT                    reversedGridSourceBottomRightX;

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// reversedGridSourceBottomRightY
    ///
    /// Description:   Inverse grid: last y coordinate at source
    /// Type:          FLOAT
    /// Default Value: 0
    /// Range:         [-3072.00f-3072.00f]
    /// Bit Depth:     float
    /// Conversion:    No Conversion needed
    /// Notes:         parameters of inverse grid
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    FLOAT                    reversedGridSourceBottomRightY;

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// useExtraCalcsDuringExtrapolation
    ///
    /// Description:   Use extra calculation for corner cases during extrapolation
    /// Type:          BOOL
    /// Default Value: 0
    /// Range:         [0-1]
    /// Bit Depth:     1u
    /// Conversion:    No Conversion needed
    /// Notes:         flags controlling function execution, has runtime penalty
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    BOOL                     useExtraCalcsDuringExtrapolation;
} IPEICAInverGridInput;

/// @brief IPE ICA grid transform output associated with vendor tag
typedef struct
{
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// inverseGridArray
    ///
    /// Description:   2-dimensional array of transform definedOn destination coordinates
    /// Type:          ICAGridArray*
    /// Default Value: 0
    /// Range:         [-8192.0f-8191.75f]
    /// Bit Depth:     float
    /// Conversion:    No Conversion needed
    /// Notes:         Max size ICA30GridTransformHeight * ICA30GridTransformWidth. parameters of inverse grid.
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    ICAGridArray* inverseGridArray;

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// extrapolationPercentage
    ///
    /// Description:   percentage of the Grid points that were extrapolated
    /// Type:          FLOAT
    /// Default Value: 0
    ///
    /// Bit Depth:     float
    /// Conversion:    No Conversion needed
    /// Notes:         Both forward and Reverse grids to defined on the same
    ///                resolution for correct extrapolation
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    FLOAT         extrapolationPercentage;
} IPEICAInverseGridOutput;

/// @brief ICA warps transform related params
struct ICAWarpsCropTransform
{
    IPEICAGridTransform         grid;               ///< LDC+RSC+OIS grid transform for waprs
    IPEICAPerspectiveTransform  persp;              ///< EIS+SAT+MFHDR and any other needed perspective transform for waprs
    StreamCropInfo              streamCrop;         ///< Stream crop info WRT IPE node input which include ICA process
    CHIRectangle                additionalCrop;     ///< Additional crop, e.g.margin/FOVC, included by "cropWRTFinalOut"
    CHIRectangle                cropWRTFinalOut;    ///< Crop WRT finnal out, dimension based on "streamCrop.frameDimension"
    CHIDimension                outFrameDimension;  ///< Frame dimension w.r.t to the final output
};

/// @brief Contains face Rects data.
typedef struct
{
    UINT64          frameNumber;                          /// Number of the frame that is assocoated with requestId
    UINT32          rectCount;                            ///< Total number of regions.
    CHIRectangle    nonWarpedfaceRect[SW_MAX_NUM_FACES];  ///< Detected original face rectangle.
    CHIRectangle    warpedFaceRect[SW_MAX_NUM_FACES];     ///< Detected warped face rectangle.
    UINT32          confidence[SW_MAX_NUM_FACES];         ///< Confidence of each face
    INT32           rollAngle[SW_MAX_NUM_FACES];          ///< Roll angle of each face
} WarpsFaceRectData;

struct EvaNcLibEvaCalcMvData
{
    NcLibImageSize mvSize;
    NcLibFloat2    mvPureSize;
    float          sgmDs;
    float          mvScaleFactorVideo;
    NcLibFloat2    sgmMultVideo;
    NcLibFloat2    sgmMult;
    bool           useSgm;
    bool           performanceBreach;                  /**< Will be set if sgmToIpeRatio is too big and resulting
                                                       *    configuration produces bigger SGM input */
};

/// @brief Face ROI (<= Kailua)
struct ChiQtiSegFaceROI
{
    UINT32 xcor;    ///< x coordinate
    UINT32 ycor;    ///< y coordinate
    UINT32 width;   ///< width
    UINT32 height;  ///< height
    double score;   ///< score of box
};

/// @brief Face ROI stats (>= Lanai)
struct ChiQtiSegFaceROIStats
{
    UINT32 xcor;     ///< x coordinate
    UINT32 ycor;     ///< y coordinate
    UINT32 width;    ///< width
    UINT32 height;   ///< height
    double score;    ///< score of box
    /* FACE SKIN STATS */
    uint32_t qsegnet_faceskin_stats[MAX_STATS_BINS][MAX_STATS_CHANNELS]; ///< RGB or YUV Stats average for Y/U/U channels
    uint32_t qsegnet_faceskin_pixel_count; ///< FaceSkin pixel count
};

/// @brief Qti AI segmentation out Face metadata structure
struct ChiQtiVendorSegFaceMetaOut
{
    UINT32                 cameraId;         ///< stats camera id
    UINT32                 numberOfFaces;    ///< Number of face ROI returned
    union
    {
        // <= Kailua
        ChiQtiSegFaceROI      faceROI[SW_MAX_NUM_FACES];         ///< Array of Face ROI strucutre
        // >= Lanai
        ChiQtiSegFaceROIStats faceROIStats[SW_MAX_NUM_FACES];    ///< Array of Face ROI strucutre and Face RGB/YUV/HSV Stats
    };
};

/// @brief Qti AI segmentation out metadata structure
struct ChiQtiVendorSegMetaOut
{
    uint8_t          globalDynamicConfidence;       ///< Confidence value returned by seglib
};

/// @brief frame AI segmentation face meta-data structure output
struct ChiSegFaceMetadataOut
{
    union VendorSegFaceMetaOut
    {
        ChiQtiVendorSegFaceMetaOut vendorSegFaceMetaOutQti;    ///< seg Face output metadata of Qti
    } vendorSegFaceMetaOut;
};

/// @brief frame AI segmentation meta-data structure output
struct ChiSegMetadataOut
{
    UINT32 segVendorId;                                 ///< seg vendor Id
    UINT32 frameOrientation;                            ///< Frame Orientation
    union VendorSegMetaOut
    {
        ChiQtiVendorSegMetaOut vendorSegMetaOutQti;    ///< seg output metadata of Qti
    } vendorSegMetaOut;
};

#pragma pack(push, 4)

// Depth polygon
struct DepthPolygon
{
    UINT32        numOfPolygonPointsInUndistortedDomain; ///< Polygon number of used points, bounded by MaxPolygonSize
    ICAGridArray  polygonInUndistorted[MaxPolygonSize];  ///< Polygon of valid image in undistorted domain
                                                         ///  start with top left point (from distorted domain) and go clockwise
                                                         ///  Points origin [0,0] is top left pixel of the distorted image
                                                         ///  Bottom right pixels is pointsDefinedOnSize
    UINT32        transformDefinedOnWidth;               ///< Width on which transform is defined.
    UINT32        transformDefinedOnHeight;              ///< Height on which transform is defined.
};

/// @brief Direction of warp matrices and grid
enum ICAWarpDirection
{
    ICA_OUT_2_IN = 0,       ///< Output to Input
    ICA_IN_2_OUT = 1,       ///< Input to Output
};

/// @brief Trasfrom/grid dimension
struct ICAImageSize
{
    UINT32 widthPixel;
    UINT32 HeightPixel;
};

/// @brief Grid x, y co-ordinates
struct ICAWarpGridCoord
{
    FLOAT x;        ///< x coordinate in floating point format
    FLOAT y;        ///< y coordinate in floating point format
};

/// @brief Extrapolation type of the grid
enum ICAWarpGridExtrapolationType
{
    ICA_EXTRAPOLATION_TYPE_MIN_VAL                     = 0,   ///< For SW purpose
    ICA_EXTRAPOLATION_TYPE_NONE                        = 0,   ///< no extrapolation points
    ICA_EXTRAPOLATION_TYPE_FOUR_CORNERS                = 1,   ///< Napali like - four corners (4 points must be provided in gridExtrapolate)
    ICA_EXTRAPOLATION_TYPE_EXTRA_POINT_ALONG_PERIMETER = 2,   ///< Hana/Kona like (must be provided in grid)
    ICA_EXTRAPOLATION_TYPE_MAX_VAL                            ///< For SW purpose - not valid
};

/// @brief  Warp grid data structure
struct ICAWarpGrid
{
    bool                            enable;             ///< If true, enables grid
    ICAImageSize                    transformDefinedOn; ///< Grid transform defined on dimension
    UINT32                          numRows;            ///< Number of rows in array
    UINT32                          numColumns;         ///< Number of columns in array
    ICAWarpGridCoord*               grid;               ///< 2-dimensional array of grid points
    ICAWarpGridExtrapolationType    extrapolateType;    ///< Grid extrapolation type
    ICAWarpGridCoord  *             gridExtrapolate;    ///< Grid extrapolation points array
};

/// @brief  Perspective transform center location
enum ICAPerspTransformSpread
{
    ICA_CENTERED  = 0,  ///< Each matrix is centered with regard to image slice (ICA implementation)
    ICA_STRETCHED = 1   ///< First and last matrices are located on first and last image rows and the rest are spread evenly
};

/// @brief A single perspective transform matrix
struct ICAPerspTransformSingle
{
    float T[9];         /// @brief 9 parameters define perspective transform
};

/// @brief Perspective transform structure
struct ICAWarpMatrices
{
    bool                        enable;             ///< If true, enable perspective matrices
    ICAImageSize                transformDefinedOn; ///< Perspective transform defined on dimension
    ICAPerspTransformSpread     centerType;         ///< Type of perspective transform
    UINT32                      confidence;         ///< Perspective transform confidence parameter - Values range [0,256]
    UINT32                      numRows;            ///< Number of rows in array
    UINT32                      numColumns;         ///< Number of columns in array
    ICAPerspTransformSingle*    perspMatrices;      ///< 2-dimensional array of perspective transform matrices
};


/// @brief Warping data structure
struct ICAWarp
{
    ICAWarpMatrices    matrices;      ///< Perspective matrices transform data structure
    ICAWarpGrid        grid;          ///< Grid transform data structure
    ICAWarpDirection   direction;     ///< Direction of warp matrices and grid
};
#pragma pack(pop)
#pragma pack(pop)

#ifdef __cplusplus
}
#endif // __cplusplus

#endif // CHIIPEDEFS_H
