#ifndef _HV_DRV_OSDTYPES_H
#define _HV_DRV_OSDTYPES_H

#include "hv_chip_Config.h"
#include "hv_mw_OsdComm.h"
#include "hv_comm_DataType.h"
#include "hv_comm_LinkedList.h"

#define OSD_WINDOW_NUMS                 6
#define OSD_FONT_WINDOW_NUMS            4
#define OSD_WINDOW_MAX_RESOURCE_COUNT   8
#define OSD_ROW_MAX_COLUMNS             254

#define OSD_WINDOW_IS_NORMAL(index) (index < PHY_WIN_RECT_0)

int Hv_Vos_STDIO_GetChar(char* ch);
static inline CHAR8 Hv_Drv_OsdCommon_GetChar(VOID)
{
    CHAR8 cCh = 0;
    INT32 iRet = 0;

    do {
        iRet = Hv_Vos_STDIO_GetChar(&cCh);
        //Hv_Cal_Osd_TimeDelayMs(10);
    } while (iRet != 0);

    //OSD_TEST_LOG_DEBUG("%c", cCh);
    return cCh;
}

#define OSD_ENABLE_STUB
#ifdef OSD_ENABLE_STUB
#define OSD_STUB(s, ...) do {HV_LOGI(#s ". Enter c to continue", ##__VA_ARGS__);} while (Hv_Drv_OsdCommon_GetChar() != 'c')
#else
#define OSD_STUB(s)
#endif

typedef struct
{
    USHORT16 usX;
    USHORT16 usY;
    USHORT16 usWidth;
    USHORT16 usHeight;
} OsdArea;

typedef enum _OsdScalerRatio
{
    OSD_SCALER_RATIO_HALF,
    OSD_SCALER_RATIO_EQUAL,
    OSD_SCALER_RATIO_TWICE,
} OsdScalerRatio;

typedef enum
{
    OSD_DATAPATH_OSDDRAW = 0,
    OSD_DATAPATH_GRAPHIC,
    OSD_DATAPATH_OSDOUTPUT,
    OSD_DATAPATH_DDRWRITE,
    OSD_DATAPATH_DDRREAD,
    OSD_DATAPATH_HSBLEND,
} OsdDataPath;

typedef enum
{
    OSD_ALPHA_FORCE_ALL = 0,
    OSD_ALPHA_FORCE_NONZERO,
} OsdAlphaForceMode;

typedef enum
{
    OSD_WDDR_MODE_WHOLE = 0,
    OSD_WDDR_MODE_EFFECTIVE,
} OsdWriteDDRMode;

typedef enum
{
    OSD_PIXEL_FORMAT_RGBA8888 = 0,
    OSD_PIXEL_FORMAT_RGBA4444,
    OSD_PIXEL_FORMAT_RGB565,
    OSD_PIXEL_FORMAT_Alpha8,
    OSD_PIXEL_FORMAT_Alpha4,
    OSD_PIXEL_FORMAT_RGB888,
    OSD_PIXEL_FORMAT_MAX,
    OSD_PIXEL_FORMAT_ABGR8888,
    OSD_PIXEL_FORMAT_ABGR4444,
    OSD_PIXEL_FORMAT_BGR565,
    OSD_PIXEL_FORMAT_BGR888,
} OsdPixelFormat;

typedef enum _OsdClockType
{
    OSD_CLOCK_FALLING = 0,
    OSD_CLOCK_RISING,
} OsdClockType;

typedef enum _OsdWinClockType
{
    OSD_WIN_HS_CLOCK = 0,
    OSD_WIN_DE_CLOCK,
} OsdWinClockType;

typedef enum
{
    OSD_BLINK_DUTY_25 = 0,
    OSD_BLINK_DUTY_50,
    OSD_BLINK_DUTY_75,
    OSD_BLINK_DUTY_MAX
} OsdBlinkDuty;

typedef enum
{
    OSD_TRANS_MODE_NONE = 0,
    OSD_TRANS_MODE_FADE,
    OSD_TRANS_MODE_SHUTTER,
    OSD_TRANS_MODE_SHUTTER2,
    OSD_TRANS_MODE_MAX
} OsdTransMode;

typedef enum
{
    OSD_TRANS_DI_V = 0,
    OSD_TRANS_DI_H,
    OSD_TRANS_DI_V_H,
    OSD_TRANS_DI_MAX
} OsdTransDirection;

typedef enum
{
    OSD_TRANS2_DI_V_OUT = 0,
    OSD_TRANS2_DI_H_OUT,
    OSD_TRANS2_DI_V_H_OUT,
    OSD_TRANS2_DI_V_IN,
    OSD_TRANS2_DI_H_IN,
    OSD_TRANS2_DI_V_H_IN,
    OSD_TRANS2_DI_MAX
} OsdTrans2Direction;

typedef enum _OsdBlendingStage
{
    OSD_BLENDING_STAGE_RECT_GROUP = 0,
    OSD_BLENDING_STAGE_RECT_FONT,
    OSD_BLENDING_STAGE_WIN01,
    OSD_BLENDING_STAGE_WIN23,
    OSD_BLENDING_STAGE_WIN0123,
    OSD_BLENDING_STAGE_WINRECT,
    OSD_BLENDING_STAGE_WINALL,
    OSD_BLENDING_STAGE_GRAPHIC,
    OSD_BLENDING_STAGE_HSBLEND,

    OSD_BLENDING_STAGE_MAX = OSD_BLENDING_STAGE_HSBLEND,
} OsdBlendingStage;

typedef enum _OsdAlphaSelectType
{
    OSD_ALPHA_TYPE_CH0 = 0,
    OSD_ALPHA_TYPE_CH1,
    OSD_ALPHA_TYPE_SET,
    OSD_ALPHA_TYPE_SET2,
} OsdAlphaSelectType;

typedef enum _OsdAlphaOutputType
{
    OSD_ALPHA_OUTPUT_FF_CH01 = 0,
    OSD_ALPHA_OUTPUT_FF_SET,
    OSD_ALPHA_OUTPUT_CH0,
    OSD_ALPHA_OUTPUT_CH1,
    OSD_ALPHA_OUTPUT_FORCE,
} OsdAlphaOutputType;

typedef struct
{
#define OSD_BLENDING_FLAG_SWITCH_ENABLE             (1 << 0)
#define OSD_BLENDING_FLAG_ALPHA_OUTPUT_FORCE        (1 << 1)
#define OSD_BLENDING_FLAG_ALPHA_OUTPUT_RATIO        (1 << 2)
#define OSD_BLENDING_FLAG_BG_OUTPUT                 (1 << 3)
    UCHAR8 ucBlendingFlags;
    OsdAlphaSelectType enSelectType;
    OsdAlphaOutputType enOutputType;
    UCHAR8 ucValue;
    USHORT16 usBGColor;
} OsdBlendingParam;

typedef enum _OsdBlendingType
{
    OSD_BLENDING_TYPE_NOBLENDING = 0,
    OSD_BLENDING_TYPE_NOBLENDING_FORCE_ALPHA,
    OSD_BLENDING_TYPE_BLENDING,
    OSD_BLENDING_TYPE_BLENDING_FORCE_ALPHA,
} OsdBlendingType;

typedef enum _OsdHsBlendMode
{
    OSD_HSBLEND_MODE_DDR_ONLY = 0,
    OSD_HSBLEND_MODE_OSD_ONLY,
    OSD_HSBLEND_MODE_DDR_FIRST,
    OSD_HSBLEND_MODE_OSD_FIRST,
    OSD_HSBLEND_MODE_DDR_ROTATE,
    OSD_HSBLEND_MODE_MAX,
} OsdHsBlendMode;

typedef struct _OsdDMAEntry
{
    UINT32 uiSrcAddr;
    UINT32 uiDstAddr;
    UINT32 uiLength;
} OsdDMAEntry;

typedef struct _OsdDataDrawn
{
    OsdPixelFormat enFormat;
    USHORT16 usWidth;
    USHORT16 usHeight;
    UINT32 uiStepBytes;
} OsdDataDrawn;

typedef enum _OsdSRAMChangeType
{
    OSD_SRAM_CHANGE_NONE = 0,
    OSD_SRAM_CHANGE_PARTIAL,
    OSD_SRAM_CHANGE_FULL,
} OsdSRAMChangeType;

typedef struct _OsdSRAMChange
{
    OsdSRAMChangeType enType;
    UINT32 uiChangeStart;
    UINT32 uiChangeEnd; // end + 1
} OsdSRAMChange;

typedef struct _OsdLoadedBlock
{
    UCHAR8 ucBlockID;
    USHORT16 usCurrentOffset;
    USHORT16 usMatrixCount;
} OsdLoadedBlock;

typedef struct _OsdLoadedBank
{
    UCHAR8 ucBankID;
    OsdResourceSize enSize;
    OsdResourceType enType;
    BOOL bIsBlankBank;
        /* 实时加载资源的时候,表示当前占用的slot个数 */
    USHORT16 usCurrentSlots;
    USHORT16 usCurrentResourceOffset;
} OsdLoadedBank;

typedef struct _OsdRadixTree
{
    UCHAR8 ucHeight;
    USHORT16 usTotalSlots;
    USHORT16 usLeafCounts;
    USHORT16 usLastAllocatedSlot;
    UINT32 *puiBuffer;
} OsdRadixTree;

//struct OsdRowCatalog;
typedef struct _OsdUpdateManager
{
    USHORT16 usResourceOffset;
    USHORT16 usSize;
    OsdLoadedBank *pstUpdateBank;
    struct _OsdRowCatalog *pstCatalog; // the catalog this update region belongs
    OsdRadixTree *pstUpdateSlotsManager;
    struct LinkedList stEntry; // linked to all update regions
} OsdUpdateManager;

typedef struct _OsdRowCatalog
{
    OsdResourceSize enSize;
    OsdResourceType enType;
#if (HV_OSD_CONFIG_RESERVE_SLOTS_BYROW == HV_CONFIG_OFF)
    UCHAR8 ucWindowId; // the window this catalog belongs to
    UCHAR8 ucUnusedSlots;
    USHORT16 usTotalSlots;
    USHORT16 usResourceOffset; // start address of first slot
    OsdRadixTree *pstSlotsManager; // redraw region slots manager
    OsdUpdateManager *pstUpdateManager;
    OsdLoadedBank *pstCatalogBank;
    struct _OsdRowCatalog *pstNext;
#endif
    struct LinkedList stRowInfos;
} OsdRowCatalog;

typedef struct _OsdRowInfo
{
    OsdResourceSize enSize;
    OsdResourceType enType;
    UCHAR8 ucBankID;
    UCHAR8 ucRowIndex;
    /* 当前行blank列的平均宽度*/
    UCHAR8 ucBlankWidth;
    UCHAR8 ucRowLen;
    /* 当前行字符的个数*/
    USHORT16 usAddedToCatalog   : 1;
    USHORT16 usY                : 15;
    OsdLoadedBank *pstLoadedBank;
#if (HV_OSD_CONFIG_RESERVE_SLOTS_BYROW == HV_CONFIG_ON)
    UCHAR8 ucResourceLen;
    USHORT16 usResourceOffset;
#else
    UCHAR8 ucResourceCount;
    OsdRowCatalog *pstCatalog;
#endif
    USHORT16 usBankSlot;
    UCHAR8 ucCurIndex;
    UCHAR8 *pucColumnStart;
    UCHAR8 ucComponentCount;
    OsdComponentNode *apCurrentComponents[OSD_ROW_MAX_COMPONENTS];

#if (HV_PROJECT_CONFIG_OSD_CPU_CANVAS_SUPPORT == HV_CONFIG_ON)
    /* only support one Canvas per row */
    struct _OsdIndexColumn *pstCPUCanvasStartColumn;
    OsdComponent stCPUCanvasComponent;
    UCHAR8 ucCPUCanvasColumnCount;
#endif

    /*
     * when not used, linked to g_stRowInfoFreeList
     * otherwise, linked to OsdIndexInfo.stRowInfoList
     */
    struct LinkedList stEntry;
} OsdRowInfo;

typedef struct _OsdIndexInfo
{
    UCHAR8 ucRowCount;
    USHORT16 usIndexSize;
    UCHAR8 *pucIndexDDRAddr;
    struct LinkedList stRowInfoList;
} OsdIndexInfo;

typedef struct _OsdPhyFontInfo
{
    /* Index分配信息 */
    OsdIndexInfo stIndexInfo;

    USHORT16 usFontAreaWidth    : 15;
    USHORT16 bIsBackground      : 1;
    /* blank行在apResources数组中的索引,如果还没有设置，要设置成-1 */
    UCHAR8 ucBlankBankIndex;
    /* 当前window绘制需要索引的资源个数 */
    UCHAR8 ucResourceCount;
    /* 当前window绘制需要索引的资源列表 */
    OsdLoadedBank *apResources[OSD_WINDOW_MAX_RESOURCE_COUNT];
#if (HV_OSD_CONFIG_RESERVE_SLOTS_BYROW == HV_CONFIG_OFF)
    OsdRowCatalog *pstCatalogs;
#endif
} OsdPhyFontInfo;

#if (HV_OSD_CONFIG_REAL_DDR_CANVAS == HV_CONFIG_ON)
typedef struct _OsdWindowDrawPart
{
    OsdWindowPhyId enWinId;
    OsdArea stDrawArea;
    OsdArea stRotateArea;
} OsdWindowDrawPart;

typedef struct _OsdSceneDrawPart
{
    BOOL bRotateEnable;
    UCHAR8 ucSceneId;
    BOOL bSceneAbsolutePostion;
    USHORT16 usSceneAbsoluteX;
    USHORT16 usSceneAbsoluteY;
    UCHAR8 ucPartCount;
    OsdWindowDrawPart astAllWindowDrawParts[PHY_WIN_ID_MAX + 1];
    OsdArea stDrawArea;
    OsdArea stRotateArea;
} OsdSceneDrawPart;
#endif

typedef struct _OsdDataPathParam
{
    UCHAR8 ucVsDivNum;
#if (HV_PROJECT_CONFIG_OSD_DDRPATH == HV_CONFIG_ON)
    USHORT16 usMargin;
    /* double buffer之间的copy是否完成 */
    volatile BOOL bCopyDone;
    UINT32 uiDrawBuffer;
    UINT32 uiDisplayBuffer;
#endif
#if (HV_PROJECT_CONFIG_OSD_ROTATION == HV_CONFIG_ON)
    UINT32 uiRotateBuffer;
    OsdRotationType enRotate;
    USHORT16 usRotateX;
    USHORT16 usRotateY;

    USHORT16 usRotateBufferWidth;
    USHORT16 usRotateBufferHeight;
    USHORT16 usRotateOriWidth;
    USHORT16 usRotateOriHeight;
#endif
#if (HV_OSD_CONFIG_REAL_DDR_CANVAS == HV_CONFIG_ON)
    UCHAR8 ucScenePartCount;
    OsdSceneDrawPart astAllDrawParts[6];
    OsdArea stDDRCanvas;
#endif
} OsdDataPathParam;

typedef struct _OsdRowCatalogNode
{
    OsdRowInfo *pstRowInfo;
    /* linked to OsdRowCatalog.stRowInfos */
    struct LinkedList stNode;
} OsdRowCatalogNode;

typedef struct _OsdTextIterator
{
    USHORT16 *pusString;
} OsdTextIterator;

typedef struct _OsdAsciiIterator
{
    USHORT16 usCurIndex;
} OsdAsciiIterator;

typedef struct _OsdNumberIterator
{
    USHORT16 ausCharOffsets[8];
    UCHAR8 ucLen;
    UCHAR8 ucCurIndex;
} OsdNumberIterator;

typedef struct _OsdBmpIconIterator
{
    USHORT16 usCurRow    : 8;
    USHORT16 usCurColumn : 8;
} OsdBmpIconIterator;

typedef struct _OsdComponentIterator OsdComponentIterator;
struct _OsdComponentIterator
{
    OsdComponentNode *pstComponent;
    /* parameters for different type of components */
    VOID *pvArgs;
};

struct _OsdIndexColumn;
#if (HV_PROJECT_CONFIG_OSD_MARQUEE == HV_CONFIG_ON)

typedef enum _OsdMarqueePart
{
    OSD_MARQUEE_PART_FIRST = 0,
    OSD_MARQUEE_PART_SECOND,
} OsdMarqueePart;

typedef enum _OsdMarqueeChoice
{
    OSD_MARQUEE_CHOOSE_PREV = 0,
    OSD_MARQUEE_CHOOSE_NEXT,
} OsdMarqueeChoice;

typedef enum _OsdMarqueeState
{
    OSD_MARQUEE_STAT_RUNNING = 0,
    OSD_MARQUEE_STAT_PAUSED,
} OsdMarqueeState;

typedef struct _OsdMarqueeSlidingNextParam
{
    UCHAR8 ucPart;
    UCHAR8 ucDirection;
    USHORT16 usDestX;
    INT32 iNextValue; /* next value */
} OsdMarqueeSlidingNextParam;

typedef struct _OsdMarqueeSlidingParam
{
    USHORT16 usDestRealX;
    USHORT16 usDestStartPos;
} OsdMarqueeSlidingParam;

typedef struct _OsdMarqueeNode
{
    //OsdMarqueeType enMarqueeType;
    OsdMarqueeState enState;
    BOOL bMallocSlots;
    USHORT16 usStartPos;
    USHORT16 usRealX;
    USHORT16 usRealWidth;
    OsdRowInfo *pstRowInfo;
    struct _OsdIndexColumn *pstColumn;

    OsdComponentIterator stIterator;

    /* parameters for different marquee type */
    VOID *pvMarqueeArgs;
    /* TODO: operation functions of this marquee type */
    //VOID (*pfSetInitialPos)(struct _OsdMarqueeNode *pstNode);

    //VOID (*pfFreeNode)(struct _OsdMarqueeNode *pstNode);
    struct LinkedList stEntry;
} OsdMarqueeNode;
#endif

#if (HV_PROJECT_CONFIG_OSD_TEXT_WRAPPING == HV_CONFIG_ON)
typedef struct _OsdWrapNode
{
    /* current drawing row */
    UCHAR8 ucCurRow;
    OsdComponentIterator stIterator;
    /* linked to stAllWrapNodes */
    struct LinkedList stEntry;
    OsdRowInfo *apDrawnRows[];
} OsdWrapNode;

typedef struct _OsdWrapDrawnInfo
{
    OsdWrapNode *pstWrap;
    UCHAR8 ucRows;
    struct LinkedList stEntry;
    OsdRowInfo **ppRowInfos;
} OsdWrapDrawnInfo;
#endif

#if (HV_PROJECT_CONFIG_OSD_CUSTOM_GROUP_SUPPORT == HV_CONFIG_ON)
typedef struct _OsdCustomGroupInfoNode
{
    OsdComponent stCp;
    OsdCustomGroupInfo stCGInfo;
    struct LinkedList stEntry;
} OsdCustomGroupInfoNode;
#endif

typedef struct _OsdFontResourceInfo
{
    const UCHAR8 *pucMatrixAddr;
    const USHORT16 *pusMatrixOffset;
    USHORT16 usMatrixSize;
    UCHAR8 ucRows;
    UCHAR8 ucColumns;
    UCHAR8 ucResWidth;
    UCHAR8 ucResHeight;
    UCHAR8 ucResBits;
} OsdFontResourceInfo;

typedef struct _OsdFontParam
{
    OsdPhyFontInfo *pstOsdPhyFonts;
    struct LinkedList stRowInfoFreeList;
    UCHAR8 ucRowInfoFreeCount;

    /* 当前窗口按照资源不同分类的行信息 */
    UCHAR8 ucCatalogCount;
#if (HV_OSD_CONFIG_RESERVE_SLOTS_BYROW == HV_CONFIG_OFF)
    OsdRowCatalog *pstCurrentCatalog;
    struct LinkedList stAllUpdateManagers;
#else
    OsdRowCatalog astRowCatalogs[OSD_WINDOW_MAX_RESOURCE_COUNT];
#endif

#if (HV_PROJECT_CONFIG_OSD_MARQUEE == HV_CONFIG_ON)
    struct LinkedList stMarqueeHead;
#endif
#if (HV_PROJECT_CONFIG_OSD_TEXT_WRAPPING == HV_CONFIG_ON)
    struct LinkedList stAllWrapNodes;
#endif

    UCHAR8 *pucComponentDrawingMap;
    OsdComponent stDrawingCp;
    USHORT16 usDrawingMapWidth;
    USHORT16 usDrawingMapHeight;

#if (HV_PROJECT_CONFIG_OSD_CUSTOM_GROUP_SUPPORT == HV_CONFIG_ON)
    struct LinkedList stAllCustomGroups;
#endif

#if (HV_PROJECT_CONFIG_OSD_CPU_CANVAS_SUPPORT == HV_CONFIG_ON)
    UCHAR8 aucCPUCanvasColumns[765];
#endif
} OsdFontParam;

typedef struct _OsdResourceParam
{
    volatile BOOL bResourceCopyDone;
    OsdLoadedBank *pstBlankBank;
    OsdLoadedBank *pstOsdLoadedBanks;
    UCHAR8 ucOsdLoadBankCount;
    UCHAR8 ucOsdMaxLoadBankCount;
    OsdLoadedBlock *pstOsdLoadedBlocks;
    UCHAR8 ucOsdLoadedBlockCount;
    USHORT16 usCurrentResourceOffset;
    OsdSRAMChange stResourceChange;
} OsdResourceParam;

typedef struct _OsdShiftParam
{
    OsdRowInfo *pstCurrentRowInfo;
    OsdResourceSize enSize;
    UCHAR8 ucWidth;
    UCHAR8 ucHeight;
    USHORT16 usBytes;
    UCHAR8 aucBuffer[512] __attribute__((aligned(4)));
    UCHAR8 ucMergeWidth; // 当前已经拼出来的宽度
    BOOL bIsUpdate;
#if (HV_OSD_CONFIG_RESERVE_SLOTS_BYROW == HV_CONFIG_OFF)
    BOOL bUseUpdateRegion;
#endif
#if (HV_PROJECT_CONFIG_OSD_MARQUEE == HV_CONFIG_ON)
    BOOL bReplaceMatrix;
    BOOL bDropNext;
    struct _OsdIndexColumn *pstCurColumn;
#endif
    //UCHAR8 *pucDstAddr; // 拼完要写的地址
    BOOL (*pfShiftRoutine)(OsdRowInfo *pstRowInfo, const UCHAR8 *pucMatrix, USHORT16 usOffset, UCHAR8 ucDelta);
} OsdShiftParam;

typedef struct _OsdGraphicParam
{
    BOOL bGraphicCopyDone;
#if (HV_PROJECT_CONFIG_OSD_GRAPHIC == HV_CONFIG_ON)
    OsdPixelFormat enPixelFormat;
    USHORT16 usWidth;
    USHORT16 usHeight;
    UINT32 uiColumnStep;
    UINT32 uiCanvasDrawBuffer;
    UINT32 uiCanvasDisplayBuffer;
#endif
} OsdGraphicParam;

#define OSD_BLENDING_MAX_STAGES 16
typedef struct _OsdBlendExcludeParam
{
    OsdBlendingStage enStage;
    UINT32 uiParam;
} OsdBlendExcludeParam;

typedef struct _OsdBlendAlphaSelectParam
{
    OsdAlphaSelectType enType;
    UCHAR8 ucAlpha;
} OsdBlendAlphaSelectParam;

typedef struct _OsdBlendAlphaOutputParam
{
    OsdAlphaOutputType enType;
    UCHAR8 ucAlpha;
} OsdBlendAlphaOutputParam;

typedef struct _OsdBlendParam
{
    OsdUniversalAlphaType enUniversalType;
    OsdBlendAlphaSelectParam astAlphaSelectParams[OSD_BLENDING_STAGE_MAX];
    OsdBlendAlphaOutputParam astAlphaOutputParams[OSD_BLENDING_STAGE_MAX];
    OsdBlendExcludeParam astExcludeParams[OSD_BLENDING_MAX_STAGES];
    UCHAR8 ucExcludeCount;
} OsdBlendParam;

typedef struct _OsdLogoWindow
{
    /* window pos && size */
    OsdArea stWindowArea; // window的位置大小
    USHORT16 usFontStartX; // font的起始位置
    USHORT16 usFontStartY;
    USHORT16 usWindowIndex  : 3; // window的编号
    USHORT16 usRowCount     : 13; // 总行数，包括空行和结束行
    USHORT16 usIndexOffset; // window的index在16KBindex区域的偏移
    /*
     * [11:0]   font baseaddr
     * [15:12]  font select
     */
    USHORT16 ausWindowResources[OSD_WINDOW_MAX_RESOURCE_COUNT]; // 8组bank配置
} __attribute__((aligned(4))) OsdLogoWindow;

typedef struct _OsdLogoBgWindow
{
    /* window pos && size */
    OsdArea stWindowArea; // window的位置大小
    USHORT16 usBgColor; // window的背景颜色
    UCHAR8 ucWindowEnable; // 是否启用window背景
} __attribute__((aligned(4))) OsdLogoBgWindow;

typedef struct _OsdLogoIconBmp
{
    /* align to 16Bytes */
    UINT32 uiPaletteOffset; // 调色板在bin文件的偏移
    /* align to 16Bytes */
    UINT32 uiIndexOffset; // index在bin文件的偏移
    /* align to 16Bytes */
    UINT32 uiResourceOffset; // resource点阵在bin文件的偏移
    USHORT16 usPaletteSize; // 调色板大小
    USHORT16 usIndexSize; // index大小
    USHORT16 usResourceSize; // 点阵区域大小
    UCHAR8 ucWindowCount; // 用到的window个数
    OsdLogoWindow astWindows[0]; // 实际的window配置，紧跟着head存放
} __attribute__((aligned(4))) OsdLogoIconBmp;

typedef struct _OsdLogoGraphic
{
    OsdArea stGraphicArea;
    /* align to 16Bytes */
    UINT32 uiGraphicOffset;
    UINT32 uiGraphicSize;
    UCHAR8 ucFormat         : 3;
    UCHAR8 ucSetAlpha       : 1;
    UCHAR8 ucPaddingOne     : 1;
    UCHAR8 ucCompressed     : 1;
    UCHAR8 ucGraphicOnTop   : 1;
    UCHAR8 ucColorKeyEn     : 1;
    UCHAR8 ucAlpha;
    //UINT32 uiColorKey;
    //UINT32 uiColor;
} __attribute__((aligned(4))) OsdLogoGraphic;

typedef enum _OsdLogoType
{
    OSD_LOGO_TYPE_ICONBMP,
    OSD_LOGO_TYPE_GRAPHIC,
    OSD_LOGO_TYPE_BOTH,
} OsdLogoType;

/* head of logo bin file */
typedef struct _OsdLogoHead
{
    UINT32 uiMagic; // magic number: 0x4fe182af
    UINT32 uiLogoSize; // logo整个bin文件的大小
    UCHAR8 ucVersion; // logo的版本，向前兼容
    /* 0: Icon/BMP 1: grahic */
    UCHAR8 ucLogoType;
    OsdLogoIconBmp stIconBmp;
    OsdLogoBgWindow stBgWindow;
    OsdLogoGraphic stGraphic;
} OsdLogoHead;

typedef struct _OsdResourceConfig
{
    OsdResourceSize enSize;
    OsdResourceType enType;
    UCHAR8 ucCountInOneRow;
} OsdResourceConfig;

#endif
