/**
 * @file hv_drv_OsdIndex.h
 * @brief Osd driver layer index orgnization interface.
 * @verbatim
 * ==============================================================================
 *                        ##### How to use this driver #####
 * ==============================================================================
 * (+) Use Hv_Drv_OsdIndex_Init(...) to init index offset.
 * (+) Use Hv_Drv_OsdIndex_AllocRegion(...) to alloc index region for window.
 * (+) Use Hv_Drv_OsdIndex_NewRow(...) to alloc normal row structure.
 * (+) Use Hv_Drv_OsdIndex_NewEndRow(...) to append end row at last.
 * (+) Use Hv_Drv_OsdIndex_FillBlankLines(...) to fill row blank space.
 * (+) Use Hv_Drv_OsdIndex_FillColumnBlanks(...) to fill column blank space.
 * (+) Use Hv_Drv_OsdIndex_SetChangeRange(...) to record index change range.
 * (+) Use Hv_Drv_OsdIndex_TransferIndex(...) to transfer index change to OSD SRAM.
 * @endverbatim
 *
 * @author HiView SoC Software Team
 * @version 0.0.1
 * @date 2022-08-22
 */

#ifndef __HV_DRV_OSDINDEX_H
#define __HV_DRV_OSDINDEX_H

#include "hv_drv_Osd.h"

/**
 * @brief reset index offset to 0
 * @param[in] None
 * @return VOID without return
 */
VOID Hv_Drv_OsdIndex_ResetOffset(VOID);

/**
 * @brief allocate index region for current window
 * @param[in] usSize region size need
 * @return VOID without return
 */
VOID Hv_Drv_OsdIndex_AllocRegion(USHORT16 usSize);

/**
 * @brief Get current index DDR address
 * @param[in] None
 * @return DDR address of index
 */
UCHAR8 *Hv_Drv_OsdIndex_GetCurrentAddress(VOID);

/**
 * @brief Get index management data for current window
 * @param[in] None
 * @return data structure for current window
 */
OsdIndexInfo *Hv_Drv_OsdIndex_GetCurrentIndexInfo(VOID);

/**
 * @brief calculate columns of one row for current window
 * @param[in] usWinWidth width of window
 * @param[in] ucFixColumns user specified fix columns, 0 if not specified
 * @return column number of one row
 */
UCHAR8 Hv_Drv_OsdIndex_RowColumnNum(USHORT16 usWinWidth, UCHAR8 ucFixColumns);

/**
 * @brief fill blank columns between two components
 * @param[in] pstColumn current column
 * @param[in] usDiff total blank pixels need to fill
 * @param[in] ucWidth width of blank column
 * @return column structure after fill
 */
OsdIndexColumn *Hv_Drv_OsdIndex_FillColumnBlanks(OsdIndexColumn *pstColumn,
                                                USHORT16 usDiff, UCHAR8 ucWidth);

/**
 * @brief allocate a new NORMAL row structure
 * @param[in] pstPrevRow previous row structure, NULL for first row
 * @return row structure allocated
 */
OsdIndexRow* Hv_Drv_OsdIndex_NewRow(OsdIndexRow *pstPrevRow);

/**
 * @brief append END row for current window
 * @param[in] None
 * @return VOID without return
 */
VOID Hv_Drv_OsdIndex_NewEndRow(VOID);

/**
 * @brief fill blank rows between two NORMAL rows
 * @param[in] pstCurRow current row structure
 * @param[in] usPixels pixels need to fill between pstCurRow and next row
 * @return row structure after blank filled, blank row maybe inserted
 */
OsdIndexRow* Hv_Drv_OsdIndex_FillBlankLines(OsdIndexRow *pstCurRow, USHORT16 usPixels);

/**
 * @brief Get row structure by row Index
 * @param[in] ucRowIndex row index of current window
 * @return row structure required
 */
OsdIndexRow* Hv_Drv_OsdIndex_GetRow(UCHAR8 ucRowIndex);

/**
 * @brief set Index change range
 * @param[in] enType index change type OSD_SRAM_CHANGE_NONE: index area clean
 *                                     OSD_SRAM_CHANGE_PARTIAL: partial area of index dirty
 *                                     OSD_SRAM_CHANGE_FULL: whole area of index dirty
 * @param[in] uiChangeStart start position of this change
 * @param[in] uiChangeEnd end position of this change
 * @return VOID without return
 */
VOID Hv_Drv_OsdIndex_SetChangeRange(OsdSRAMChangeType enType, UINT32 uiChangeStart, UINT32 uiChangeEnd);

/**
 * @brief transfer index change area to OSD RAM
 * @param[in] None
 * @return VOID without return
 */
VOID Hv_Drv_OsdIndex_TransferIndex(VOID);

/**
 * @brief reset index offset to 0
 * @param[in] None
 * @return VOID without return
 */
VOID Hv_Drv_OsdIndex_Init(VOID);

#ifdef HV_SCALER_DEBUG_VERSION
extern USHORT16 g_usMaxIndexSize;
#endif

#endif
