/*
 * @file hv_mw_OsdAnimation.h
 * @brief Header file of osd animation.
 *
 * @verbatim
 * ==============================================================================
 *                        ##### How to use #####
 * ==============================================================================
 * (+) Use Hv_Mw_OsdAnimInit() to init osd animation.
 *
 * @endverbatim
 * @author HiView SoC Software Team
 * @version 1.0.0
 * @date 2024-02-20
 */

#ifndef _HV_MW_OSD_ANIMATION_H
#define _HV_MW_OSD_ANIMATION_H

#if (HV_PROJECT_CONFIG_OSD_ANIMITION_SUPPORT == HV_CONFIG_ON)

typedef enum _AnimCurveType
{
    ANIM_CURVE_LINEAR = 0,          /* 线性 */
    ANIM_CURVE_EASE_IN,             /* 缓入：先慢后快 */
    ANIM_CURVE_EASE_OUT,            /* 缓出：先快后慢 */
    ANIM_CURVE_EASE_INOUT,          /* 缓入缓出：先慢后快最后慢 */
} AnimCurveType;

typedef enum _AnimPosType
{
    ANIM_POS_X = 0,                 /* Only x change */
    ANIM_POS_Y,                     /* Only y change */
    ANIM_POS_XY,                    /* x and y change */
} AnimPosType;

typedef enum _AnimSizeType
{
    ANIM_SIZE_LR_EXPAND = 0,        /* From left to right expand */
    ANIM_SIZE_LR_COLLAPSE,          /* From left to right collapse */
    ANIM_SIZE_RL_EXPAND,            /* From right to left expand */
    ANIM_SIZE_RL_COLLAPSE,          /* From right to left collapse */
    ANIM_SIZE_TB_EXPAND,            /* From top to bottom expand */
    ANIM_SIZE_TB_COLLAPSE,          /* From top to bottom collapse */
    ANIM_SIZE_BT_EXPAND,            /* From bottom to top expand */
    ANIM_SIZE_BT_COLLAPSE,          /* From bottom to top collapse */
    ANIM_SIZE_CE_EXPAND,            /* From center to edge expand */
    ANIM_SIZE_CE_COLLAPSE,          /* From center to edge collapse */
    ANIM_SIZE_EC_EXPAND,            /* From edge to center expand */
    ANIM_SIZE_EC_COLLAPSE,          /* From edge to center collapse */
} AnimSizeType;

typedef enum _AnimPaletteType
{
    ANIM_PALETTE_INDEPENDENT = 0,   /* 使用用户指定的palette */
    ANIM_PALETTE_SHARED,            /* 使用工具生成的palette */
} AnimPaletteType;

typedef enum _AnimMarqueeType
{
    ANIM_MARQUEE = 0,
    ANIM_MARQUEE_AUTO,
    ANIM_MARQUEE_LIST,
} AnimMarqueeType;

typedef struct _OsdAnimition OsdAnimitionParam;
typedef void (*AnimitonExecuteCallbackFn)(OsdAnimitionParam* pstAnimitionParam);
typedef void (*AnimitonFinishCallbackFn)(OsdAnimitionParam* pstFinishParam);

typedef struct _OsdAnimition
{
    /* 动画属性 */
    USHORT16 usDelayTime;                   /* Delay frame numbers before the animation starting */
    USHORT16 usDurationTime;                /* Duration of animation in frame numbers */
    USHORT16 usSpacingTime;                 /* Spacing frame numbers of animation between two execution */
    USHORT16 usStart;                       /* Animation start value */
    USHORT16 usEnd;                         /* Animation end value */
    USHORT16 usId;                          /* Element id, include cp id, item id and scene id */
    UCHAR8 ucElementType;                   /* Element type, include cp, item and scene id */
    UCHAR8 ucOperateType;                   /* Operate type */
    AnimCurveType enCurveType;              /* Curve type, linearity is default */
    VOID *UserParam;                      /* User param to animate */
    AnimitonExecuteCallbackFn ExecuteCbFn;  /* Function to set the new value */
    AnimitonFinishCallbackFn FinishCbFn;    /* Function to call when animation is finished */

    /* 内部状态 */
    BOOL bRunning;                          /* True: the animation is running */
    USHORT16 usRemainTime;                  /* Remaining frame numbers for animation */

    /* 双向链表节点 */
    struct LinkedList stNode;               /* Animation note list */
} OsdAnimition;

typedef struct _AnimPosParam
{
    USHORT16 usYStart;
    USHORT16 usYEnd;
} AnimPosParam;

typedef struct _AnimSizeParam
{
    USHORT16 usHeightStart;
    USHORT16 usHeightEnd;
} AnimSizeParam;

typedef struct _AnimColorParam
{
    UINT32 uiStart;
    UINT32 uiEnd;
    USHORT16 usOriginalPalette;
    USHORT16 usNewPalette; /* no used for shared */
    UCHAR8 ucPaletteLen;
    UCHAR8 ucPaletteType;
} AnimColorParam;

typedef struct _AnimCurveMap
{
    USHORT16 usStart;
    USHORT16 usEnd;
    USHORT16 usDurationTime;
    USHORT16 usRemainTime;
} AnimCurveMap;

typedef struct _AnimRangeParam
{
    USHORT16 usX;
    USHORT16 usY;
    USHORT16 usWidth;
    USHORT16 usHeight;
} AnimRangeParam;

/*入：大到小：先快后慢；出：小到大：先慢后快*/
#define EASE_MAPPING_VALUE(Cur, Total, newMin, newMax) \
({\
    UINT32 uiVal;\
    UINT32 uiClampCurVal = clamp_val(Cur, 0, Total);\
    if(Total == 0)\
    {\
        uiVal = newMin;\
    }\
    else\
    {\
        uiVal = (((uiClampCurVal) * (uiClampCurVal) * ((newMax)-(newMin))) / ((Total) * (Total))+(newMin));\
    }\
    uiVal;\
})

/*入：大到小：先慢后快；出：小到大：先快后慢*/
#define EASE2_MAPPING_VALUE(Cur, Total, newMin, newMax) \
({\
    UINT32 uiVal;\
    UINT32 uiClampCurVal = clamp_val(Cur, 0, Total);\
    if(Total == 0)\
    {\
        uiVal = newMin;\
    }\
    else\
    {\
        uiVal = ((newMax) - ((uiClampCurVal) * (uiClampCurVal) * ((newMax)-(newMin))) / ((Total) * (Total)));\
    }\
    uiVal;\
})


/**
 * @brief OSD动画初始化
 * @param[in] pstAnimParam Osd动画相关初始化数据
 */
VOID Hv_Mw_OsdAnimInit(VOID);
BOOL Hv_Mw_OsdAnimIsDoing(VOID);
Status Hv_Mw_OsdDoAnimition(VOID);
VOID Hv_Mw_OsdAnimDefaultExecCbFn(OsdAnimition *pstAnimParam);
VOID Hv_Mw_OsdAnimDefaultFinishCbFn(OsdAnimition *pstAnimParam);

OsdAnimition *Hv_Mw_OsdAnimCreate(OsdAnimitionParam *pstAnimParam);
VOID Hv_Mw_OsdAnimDestroy(OsdAnimition *pstAnimNode);
VOID Hv_Mw_OsdAnimFinish(OsdAnimition *pstAnimNode);
VOID Hv_Mw_OsdAnimFinishAll(VOID);
VOID Hv_Mw_OsdAnimForceTerminal(OsdAnimition *pstAnimNode);
VOID Hv_Mw_OsdAnimTerminal();

VOID Hv_Mw_OsdAnimSetAlpha(OsdUniversalAlphaType enType, UCHAR8 ucAlpha);
USHORT16 Hv_Mw_OsdAnimGetCompPaletteOffset(OsdComponent stCp);
VOID Hv_Mw_OsdAnimSetCompPaletteOffset(OsdComponent stCp, USHORT16 usPaletteOffset);
VOID Hv_Mw_OsdAnimGetCompColor(USHORT16 usPaletteOffset, UINT32 *puiRGBTbl, CHAR8 ucRGBLen);
VOID Hv_Mw_OsdAnimSetCompColor(OsdComponent stCp, USHORT16 usPaletteOffset, UINT32 *puiRGBTbl, CHAR8 ucRGBLen);
UINT32 Hv_Mw_OsdAnimGetSingleColor(USHORT16 usPaletteOffset);
VOID Hv_Mw_OsdAnimSetSingleColor(OsdComponent stCp, USHORT16 usPaletteOffset, UINT32 uiRGB);
UCHAR8 Hv_Mw_OsdAnimGetCompNums(OsdComponent stCp);
VOID Hv_Mw_OsdAnimSetCompTurns(OsdComponent stCp, CHAR8 ucCurNum);
USHORT16 Hv_Mw_OsdAnimGetTransparency(UCHAR8 ucTrans, UCHAR8 ucMaxTrans, UCHAR8 ucMaxRealTrans);
VOID Hv_Mw_OsdAnimGetCompRange(OsdComponent stCp, AnimRangeParam *pstRangeParam);
VOID Hv_Mw_OsdAnimSetCompRange(OsdComponent stCp, AnimRangeParam *pstRangeParam);
USHORT16 Hv_Mw_OsdAnimGetCompResourceSize(OsdComponent stCp);
VOID Hv_Mw_OsdAnimSetItemPosition(USHORT16 usItemId, USHORT16 usX, USHORT16 usY);

USHORT16 Hv_Mw_OsdAnimCurveMapping(AnimCurveType enCurveType, AnimCurveMap *pstMapParam);
VOID Hv_Mw_OsdAnimUpdateScenePos(OsdAnimition *pstAnimParam);
VOID Hv_Mw_OsdAnimUpdateSceneAlpha(OsdAnimition *pstAnimParam);
VOID Hv_Mw_OsdAnimUpdateCompColor(OsdAnimition *pstAnimParam);
VOID Hv_Mw_OsdAnimUpdateBmpColor(OsdAnimition *pstAnimParam);
VOID Hv_Mw_OsdAnimUpdateItemSequence(OsdAnimition *pstAnimParam);
VOID Hv_Mw_OsdAnimUpdateCompList(OsdAnimition *pstAnimParam);
VOID Hv_Mw_OsdAnimUpdateCompSize(OsdAnimition *pstAnimParam);
VOID Hv_Mw_OsdAnimUpdateCompPos(OsdAnimition *pstAnimParam);
VOID Hv_Mw_OsdAnimUpdateItemPos(OsdAnimition *pstAnimParam);
VOID Hv_Mw_OsdAnimUpdateCursorPos(OsdAnimition *pstAnimParam);

#if (HV_CONFIG_ON == HV_PROJECT_CONFIG_OSD_MARQUEE)
#if (HV_CONFIG_ON == HV_OSD_CONFIG_MARQUEE_AUTO_CHECK_EXCESS)
VOID Hv_Mw_OsdCheckAutoMarquee(VOID);
#endif
VOID Hv_Mw_OsdAnimUpdateMarquee(OsdAnimition *pstAnimParam);
VOID Hv_Mw_OsdAnimFinishMarquee(OsdAnimition *pstAnimParam);
VOID Hv_Mw_OsdComponentInitMarquee(OsdComponent stCp);
#endif

#endif

#endif
