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

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @file  camxchiiqutilshandler.h
/// @brief camx chi iq utils handler
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

#ifndef CAMXCHIIQUTILSHANDLER_H
#define CAMXCHIIQUTILSHANDLER_H

#include "chi.h"
#include "chivendortagdefines.h"
#include "chiipedefs.h"
#include "chxdebugprint.h"

/// @ingroup chi_iq_specific_util
/// @brief General chi IQ specific utility class implementation.
class ChiIQUtils
{
public:
    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// @cond AllocateNcLibWarpsMemory @endcond
    ///
    /// @brief Allocate the memory which may used by NcLib internal calculation.
    ///
    /// @param[in]      numOfWarps        Identifier for the warps element number we want to allocate.
    /// @param[in/out]  ppWarps           The allocated warps memory, managed by user and release it after end of process.
    ///                                   should be defined as "VOID* ppWarps[numOfWarps]"
    ///
    /// @return CDKResultSuccess if success or appropriate error code.
    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    static CDK_VISIBILITY_PUBLIC CDKResult AllocateNcLibWarpsMemory(
        UINT32 numOfWarps,
        VOID** ppWarps);

    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// @cond DeAllocateNcLibWarpsMemory @endcond
    ///
    /// @brief De-allocate the memory we've allocated for NcLib internal calculation.
    ///
    /// @param[in]      numOfWarps        Identifier for the warps element number we want to de-allocate.
    /// @param[in]      ppWarps           The allocated warps memory, will be release here.
    ///
    /// @return CDKResultSuccess if success or appropriate error code.
    static CDK_VISIBILITY_PUBLIC CDKResult DeAllocateNcLibWarpsMemory(
        UINT32 numOfWarps,
        VOID** ppWarps);

    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// @cond GetICAVirtualDomainDimension @endcond
    ///
    /// @brief Get the ICA virtual domain dimension size.
    ///
    /// @param[in]      rVirtualWidth      Virtual domain width.
    /// @param[in]      rVirtualHeight     Virtual domain height.
    ///
    /// @return None.
    static CDK_VISIBILITY_PUBLIC VOID GetICAVirtualDomainDimension(
        UINT32& rVirtualWidth,
        UINT32& rVirtualHeight);

    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// @cond ConvertToApplyWarpsForPoints @endcond
    ///
    /// @brief Apply the warp transform for points.
    ///
    /// @param[in]      pWarpsCrop        The warps transform we want to apply.
    /// @param[in]      numOfPoints       The number of points we want to convert.
    /// @param[in]      pPointsIn         The points on dostorted domain.
    /// @param[out]     pPointsOut        The points on undistorted domain which has apply the warps transform.
    /// @param[in]      pTempWarps        Temporary warps used to do internal calculation.
    ///
    /// @return CDKResultSuccess if success or appropriate error code.
    static CDK_VISIBILITY_PUBLIC CDKResult ConvertToApplyWarpsForPoints(
        const ICAWarpsCropTransform*    pWarpsCrop,
        const UINT32                    numOfPoints,
        const CHIPointF*                pPointsIn,
        CHIPointF*                      pPointsOut,
        VOID*                           pTempWarps);

    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// @cond ConvertToApplyCropForRegions @endcond
    ///
    /// @brief Apply the crops for regions, will set origin coord(0,0) to pWarpsCrop->cropWRTICAOut's (left, top).
    ///
    ///  ____________2400________________
    /// |                                |
    /// |(0,0)_____cropWRTICAOut____     |
    /// |   |                       |    |
    /// |   |                       |    |
    /// |   |                       |    |
    /// |   |                    ___|__  |
    /// |   |                   |///|  | <- FD2
    /// |   |___________________|///|  | Only keep shadow region
    /// |  __                   |______| |
    /// | |  | <-- FD1                   |
    /// | |__| convert to[0,0,0,0]       |
    /// |________________________________|
    ///
    /// @param[in]      pApplyCrop        The crops we want to apply, should be based on "pDimensionIn".
    /// @param[in]      pDimensionIn      The input crop dimension size.
    /// @param[in]      numOfRegions      The number of regions we want to convert.
    /// @param[in]      pRegionsIn        The regions before crop.
    /// @param[out]     pRegionsOut       The regions after crop applied.
    ///
    /// @return CDKResultSuccess if success or appropriate error code.
    static CDK_VISIBILITY_PUBLIC CDKResult ConvertToApplyCropForRegions(
        const CHIRectangle*             pApplyCrop,
        const CHIDimension*             pDimensionIn,
        const UINT32                    numOfRegions,
        const CHIRectangle*             pRegionsIn,
        CHIRectangle*                   pRegionsOut);

    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// @cond ConvertToApplyCropForPoints @endcond
    ///
    /// @brief Apply the crops for points, will set origin coord(0,0) to pWarpsCrop->cropWRTICAOut's (left, top).
    ///
    ///  ____________2400________________
    /// |                                |
    /// |(0,0)_____cropWRTICAOut____     |
    /// |   |                       |    |
    /// |   |        _              |  _ |
    /// |   |       |_|<- Point     | |_|<- Point, cut to "cropWRTICAOut" right
    /// |   |             Keep it   |    |
    /// |   |                       |    |
    /// |   |_______________________|    |
    /// |   _                            |
    /// |  |_|<- Point                   |
    /// |  Cut to "cropWRTICAOut" bottom |
    /// |________________________________|
    ///
    /// @param[in]      pApplyCrop        The crops we want to apply, should be based on "pDimensionIn".
    /// @param[in]      pDimensionIn      The input crop dimension size.
    /// @param[in]      numOfPoints       The number of points we want to convert.
    /// @param[in]      pPointsIn         The points before crop.
    /// @param[out]     pPointsOut        The points after crop applied.
    ///
    /// @return CDKResultSuccess if success or appropriate error code.
    static CDK_VISIBILITY_PUBLIC CDKResult ConvertToApplyCropForPoints(
        const CHIRectangle*             pApplyCrop,
        const CHIDimension*             pDimensionIn,
        const UINT32                    numOfPoints,
        const CHIPoint*                 pPointsIn,
        CHIPoint*                       pPointsOut);

private:
    ChiIQUtils() = default;
    ChiIQUtils(const ChiIQUtils&) = delete;
    ChiIQUtils& operator=(const ChiIQUtils&) = delete;
};

#endif // CAMXCHIIQUTILSHANDLER_H
