MI GFX API


1. OVERVIEW


1.1. Module Description

GFX (Graphic Engine) hardware provides fast graphics rendering function to draw UI, mainly including rectangle color filling and bitmap moving.(Support for scaling, rotation, mirror flipping, format conversion, alpha blending and overlay, Color Key and etc.). It is supported by Tauyaki, Takoyaki, Ikayaki.

Rotate: The hardware supports 90/180/270 degree rotation.

Alpha blending overlay: Supports normal 2D Alpha operation.

Mirror: Support H mirror, V mirror and HV mirror.

Zooming: Supports zooming at Bitblit.

The other operations are generally consistent with standard 2D acceleration.


1.2. Flow diagram of invocation

If you want to use GE to process video or UI data, they can use the following procedure.

1.3. Keyword Description

  • Fence

    The state in which a GFX operation needs to wait blocks the wait, but there is also an internal timeout mechanism to prevent latencies.

  • Colorkey

    Key colors, such as removing a color from the bitmap when moving, can be set to key colors.

  • Pitch

    The number of bytes per row of pixels,(pixel bits /8) * Width. It also corresponds to the commonly used Stride and LineLength.


2. API LIST

The MI GFX module provides the following APIs:

Name of API Function
MI_GFX_Open Open GFX device
MI_GFX_Close Close GFX device
MI_GFX_WaitAllDone Wait for one/all GFX tasks to complete
MI_GFX_QuickFill Add quick fill operation to the task
MI_GFX_GetAlphaThresholdValue Get alpha threshold value
MI_GFX_SetAlphaThresholdValue Set alpha threshold value
MI_GFX_Bitblit Add a raster bitmap to the task to perform move operations with additional functions
MI_GFX_SetPalette Set palette for Index Color format
MI_GFX_InitDev Initialize GFX device
MI_GFX_DeInitDev De-initialize GFX device
MI_GFX_DrawLine Add line drawing operations to the task

2.1. MI_GFX_Open

  • Function

    Call this interface to open GFX device and initialize hardware system

  • Syntax

    MI_ S32 MI_GFX_Open(void);
    
  • Return Value

    • Zero: Successful

    • Non-zero: Failed, see error code for details

  • Requirement

    • Header: mi_gfx.h

    • Library: libmi_gfx.a/libmi_gfx.so/libmi_gfx.so

  • Note

    • Before performing any GFX related operations, call this interface and make sure GFX device is opened.

    • Calling this interface after the GFX device has been initialized will return a “module initialized” message.

  • Example

    1.  MI_S32 s32Ret = 0;    
    2.    
    3.  MI_SYS_Init();  
    4.  /* open GFX device*/    
    5.  s32Ret = MI_GFX_Open();     
    6.  if (MI_SUCCESS != s32Ret)    
    7.  {    
    8.          return -1;    
    9.  }    
    10. /* close GFX device*/     
    11. MI_GFX_Close();    
    12. MI_SYS_Exit();
    

2.2. MI_GFX_Close

  • Function

    Call this interface to close GFX device

  • Syntax

    MI_ S32 MI_GFX_Close(void);
    
  • Return Value

    • Zero: Successful

    • Non-zero: Failed, see error code for  details

  • Requirement

    • Header: mi_gfx.h

    • Library: libmi_gfx.a/libmi_gfx.so

  • Note

    The number of times of calling MI_GFX_Open and the number of times of calling MI_GFX_Close must be consistent. Repeated calling is allowed. When the number of Opens is the same as the number of Closes, the GFX API will no longer be able to be called.


2.3. MI_GFX_WaitAllDone

  • Function

    Call this interface to wait for completion of all or specified GFX tasks.

  • Syntax

    MI_S32 MI_GFX_WaitAllDone(MI_BOOL bWaitAllDone, MI_penU16 u16TargetFence);
    
  • Parameter

    Parameter Name Description Input/Output
    bWaitAllDone Wait until all GFX tasks are completed Input
    u16TargetFence Wait until specified fence is reached. This parameter takes effect only when bWaitAllDone is FALSE. Input
  • Return Value

    • Zero: Successful

    • Non-zero: Failed, see error code for  details

  • Requirement

    • Header: mi_gfx.h

    • Library: libmi_gfx.a/libmi_gfx.so

  • Note

    • Before calling this interface, make sure to call MI_GFX_Open to open the GFX device.

    • This interface is a blocking interface which will block operations until all the GFX tasks are completed.


2.4. MI_GFX_QuickFill

  • Function

    Fill in the color of u32ColorVal to the target area pstDstRect in the target bitmap pstDst to realize the function of color filling.

  • Syntax

    MI_S32 MI_GFX_QuickFill(MI_GFX_Surface_t *pstDst, MI_GFX_Rect_t *pstDstRect, MI_U32 u32ColorVal, MI_U16 *pu16Fence);
    
  • Parameter

    Parameter Name Description Input/Output
    pstDst Destination bitmap Input
    pstDstRect Operating area in destination bitmap Input
    u32ColorVal Color fill value Input
    pu16Fence Returned fence pointer Output
  • Return Value

    • Zero: Successful

    • Non-zero: Failed, see error code for details

  • Requirement

    • Header: mi_gfx.h

    • Library: libmi_gfx.a/libmi_gfx.so

  • Note

    • Before calling this interface, make sure to call MI_GFX_Open to open the GFX device.

    • The target bitmap operation area cannot exceed the size of the target bitmap.

    • If the pixel format of the target bitmap is RGB or ARGB, u32ColorVal from high to low is A8: R8: G8: B8. If the pixel format of the target bitmap is YUYV422, A8 is invalid, and R corresponds to Y, G Corresponds to U, B corresponds to V.

  • Example

    1.  FILE *fp = NULL;    
    2.  MI_PHY phyAddr;  
    3.  void *pVirAddr;  
    4.  MI_GFX_Surface_t stDst;  
    5.  MI_GFX_Rect stDstRect;  
    6.  MI_U32 u32ColorVal = 0xfffff00;  
    7.  MI_U16 u16TargetFence;  
    8.    
    9.  fp = fopen(SRC_FILE_NAME, "wb");    
    10.   
    11. ExecFunc(MI_SYS_Init(), MI_SUCCESS);    
    12. ExecFunc(MI_SYS_MMA_Alloc("mma_heap_name0", SRC_WIDTH*SRC_HEIGHT*2, &phyAddr), MI_SUCCESS);    
    13.   
    14. //MI_U32 phySrcAddr, phyDstAddr;    
    15. ExecFunc(MI_GFX_Open(), MI_SUCCESS);    
    16. ExecFunc(MI_SYS_Mmap(phyAddr, SRC_WIDTH*SRC_HEIGHT*2, &pVirAddr , FALSE), MI_SUCCESS);    
    17. memset(pVirAddr, 0x22, SRC_WIDTH*SRC_HEIGHT*2);    
    18.   
    19. //fillrect    
    20. memset(&stDst, 0x0, sizeof(stDst));  
    21. stDst.eColorFmt = E_MI_GFX_FMT_ARGB1555;    
    22. stDst.u32Width = SRC_WIDTH;    
    23. stDst.u32Height = SRC_HEIGHT;    
    24. stDst.u32Stride = SRC_WIDTH * 2;    
    25. stDst.phyAddr = phyAddr;    
    26.   
    27. memset(&stDstRect, 0x0, sizeof(stDstRect));  
    28. stDstRect.s32Xpos = 100;    
    29. stDstRect.s32Ypos = 100;    
    30. stDstRect.u32Width = 100;    
    31. stDstRect.u32Height = 100;    
    32.   
    33. ExecFunc(MI_GFX_QuickFill(&stDst, &stDstRect, u32ColorVal, &u16TargetFence), MI_SUCCESS);    
    34. ExecFunc(MI_GFX_WaitAllDone(FALSE, u16TargetFence), MI_SUCCESS);    
    35. if (NULL != fp)    
    36. {    
    37.     fwrite(pVirAddr, 1, SRC_WIDTH*SRC_HEIGHT*2, fp);    
    38.     fclose(fp);    
    39.     fp = NULL;    
    40. }    
    41. ExecFunc(MI_SYS_Munmap(pVirAddr, SRC_WIDTH*SRC_HEIGHT*2), MI_SUCCESS);    
    42. ExecFunc(MI_SYS_MMA_Free(phyAddr), MI_SUCCESS);    
    43.   
    44. ExecFunc(MI_GFX_Close(), MI_SUCCESS);    
    45. ExecFunc(MI_SYS_Exit(), MI_SUCCESS);
    

2.5. MI_GFX_GetAlphaThresholdValue

  • Function

    Get alpha threshold value.

    When the source bitmap and the target bitmap do bitblit operations, regardless of the pixel format of the source bitmap and the target bitmap, the hardware will each generate an intermediate bitmap with the pixel format of ARGB8888, and then output the result of the intermediate bitmap operation to the target bitmap. When the pixel format of the target image is ARGB1555, if the alpha value of a pixel after the intermediate bitmap operation is less than this threshold, the alpha bit of the pixel output to the target bitmap is 0; if it is greater than or equal to this threshold, the alpha bit of the pixel is taken 1.

  • Syntax

    MI_S32 MI_GFX_GetAlphaThresholdValue(MI_U8 *pu8ThresholdValue);
    
  • Parameter

    Parameter Name Description Input/Output
    pu8ThresholdValue Pointer to alpha threshold value Output
  • Return Value

    • Zero: Successful

    • Non-zero: Failed, see error code for details

  • Requirement

    • Header: mi_gfx.h

    • Library: libmi_gfx.a/libmi_gfx.so


2.6. MI_GFX_SetAlphaThresholdValue

  • Function

    Set alpha threshold value.

    When the source bitmap and the target bitmap do bitblit operations, regardless of the pixel format of the source bitmap and the target bitmap, the hardware will each generate an intermediate bitmap with the pixel format of ARGB8888, and then output the result of the intermediate bitmap operation to the target bitmap. When the pixel format of the target image is ARGB1555, if the alpha value of a pixel after the intermediate bitmap operation is less than this threshold, the alpha bit of the pixel output to the target bitmap is 0; if it is greater than or equal to this threshold, the alpha bit of the pixel is taken 1.

  • Syntax

    MI_S32 MI_GFX_SetAlphaThresholdValue(MI_U8 u8ThresholdValue);
    
  • Parameter

    Parameter Name Description Input/Output
    u8ThresholdValue Alpha threshold value Input
  • Return Value

    • Zero: Successful

    • Non-zero: Failed, see error code for details

  • Requirement

    • Header: mi_gfx.h

    • Library: libmi_gfx.a/libmi_gfx.so


2.7. MI_GFX_BitBlit

  • Function

    Operate the specified area (pstSrcRect, pstDstRect) of the source bitmap (pstSrc) and the target bitmap (pstDst), and copy the calculated bitmap to the specified area (pstDstRect) of the target bitmap (pstDst).

  • Syntax

    MI_S32 MI_GFX_BitBlit(MI_GFX_DEV GfxDevId, 
    MI_GFX_Surface_t *pstSrc, MI_GFX_Rect_t *pstSrcRect, 
    MI_GFX_Surface_t *pstDst,  MI_GFX_Rect_t *pstDstRect, 
    MI_GFX_Opt_t *pstOpt, MI_U16 *pu16Fence);
    
  • Parameter

    Parameter Name Description Input/Output
    pstSrc Source bitmap Input
    pstSrcRect Source bitmap operation region Input
    pstDst Destination bitmap Input
    pstDstRect Destination bitmap operation region Input
    pstOpt Operating parameter setting structure Input
    pu16Fence Pointer to the returned fence Output
  • Return Value

    • Zero: Successful

    • Non-zero: Failed, see error code for details

  • Requirement

    • Header: mi_gfx.h

    • Library: libmi_gfx.a/libmi_gfx.so

  • Note

    • Before calling this interface, make sure to call MI_GFX_Open to open the GFX device.

    • When the size of the source bitmap operation area is inconsistent with the target bitmap operation area, the source area is scaled according to the target area ratio, and then the operation is performed with the target area.

    • If the clip operation is an in-area clip, the cut area must have a common intersection with the operation area, otherwise an error will be returned.

    • The MI_GFX_Opt_t structure stores the configuration information of the GFX calculation function, such as: whether to use the colorkey and the configuration value of the colorkey; whether to perform clip operation and specify the clip area; whether to mirror or perform alpha blending, etc. The above operations can be enabled at the same time.

  • Example

    1.  FILE *fp = NULL;    
    2.  FILE *dstfp = NULL;    
    3.  MI_PHY phyAddr, phyAddr2;  
    4.  void *pVirAddr = NULL, *pVirAddr2 = NULL;  
    5.  MI_GFX_Surface_t stSrc, stDst;  
    6.  MI_GFX_Rect_t stSrcRect, stDstRect;  
    7.  MI_U16 u16TargetFence;  
    8.    
    9.  fp = fopen(SRC_FILE_NAME, "wb");    
    10. dstfp = fopen(DST_FILE_NAME, "wb");    
    11.   
    12. ExecFunc(MI_SYS_Init(), MI_SUCCESS);    
    13. ExecFunc(MI_SYS_MMA_Alloc("mma_heap_name0", SRC_WIDTH*SRC_HEIGHT*2, &phyAddr), MI_SUCCESS);    
    14. ExecFunc(MI_SYS_MMA_Alloc("mma_heap_name0", DST_WIDTH*360*2, &phyAddr2), MI_SUCCESS);    
    15.   
    16. //MI_U32 phySrcAddr, phyDstAddr;    
    17. ExecFunc(MI_GFX_Open(), MI_SUCCESS);    
    18. ExecFunc(MI_SYS_Mmap(phyAddr, SRC_WIDTH*SRC_HEIGHT*2, &pVirAddr , FALSE), MI_SUCCESS);    
    19. memset(pVirAddr, 0x22, SRC_WIDTH*SRC_HEIGHT*2);    
    20.   
    21. ExecFunc(MI_SYS_Mmap(phyAddr2, DST_WIDTH*DST_HEIGHT*2, &pVirAddr2 , FALSE), MI_SUCCESS);    
    22. memset(pVirAddr2, 0x0F, DST_WIDTH*DST_HEIGHT*2);    
    23.   
    24. //bitblit    
    25. memset(&stSrc, 0x0, sizeof(stSrc));  
    26. stSrc.eColorFmt = E_MI_GFX_FMT_ARGB1555;    
    27. stSrc.u32Width = SRC_WIDTH;    
    28. stSrc.u32Height = SRC_HEIGHT;    
    29. stSrc.u32Stride = SRC_WIDTH * 2;    
    30. stSrc.phyAddr = phyAddr;    
    31.   
    32. memset(&stSrcRect, 0x0, sizeof(stSrcRect));  
    33. stSrcRect.s32Xpos = 100;    
    34. stSrcRect.s32Ypos = 100;    
    35. stSrcRect.u32Width = 300;    
    36. stSrcRect.u32Height = 300;    
    37.   
    38. memset(&stDst, 0x0, sizeof(stDst));  
    39. stDst.eColorFmt = E_MI_GFX_FMT_ARGB1555;    
    40. stDst.u32Width = DST_WIDTH;    
    41. stDst.u32Height = DST_HEIGHT;    
    42. stDst.u32Stride = DST_WIDTH * 2;    
    43. stDst.phyAddr = phyAddr2;    
    44.   
    45. memset(&stDstRect, 0x0, sizeof(stDstRect));  
    46. stDstRect.s32Xpos = 200;    
    47. stDstRect.s32Ypos = 100;    
    48. stDstRect.u32Width = 200;    
    49. stDstRect.u32Height = 100;    
    50.   
    51. ExecFunc(MI_GFX_BitBlit(&stSrc, &stSrcRect, &stDst, &stDstRect, NULL, &u16TargetFence), MI_SUCCESS);    
    52. ExecFunc(MI_GFX_WaitAllDone(FALSE, u16TargetFence), MI_SUCCESS);    
    53. if (NULL != dstfp)    
    54. {    
    55.     fwrite(pVirAddr2, 1, DST_WIDTH*DST_HEIGHT*2, dstfp);    
    56.     fclose(dstfp);    
    57.     dstfp = NULL;    
    58. }    
    59.   
    60. ExecFunc(MI_SYS_Munmap(pVirAddr, SRC_WIDTH*SRC_HEIGHT*2), MI_SUCCESS);    
    61. ExecFunc(MI_SYS_MMA_Free(phyAddr), MI_SUCCESS);    
    62.   
    63. ExecFunc(MI_SYS_Munmap(pVirAddr2, DST_WIDTH*DST_HEIGHT*2), MI_SUCCESS);    
    64. ExecFunc(MI_SYS_MMA_Free(phyAddr2), MI_SUCCESS);    
    65.   
    66. ExecFunc(MI_GFX_Close(), MI_SUCCESS);    
    67. ExecFunc(MI_SYS_Exit(), MI_SUCCESS);
    

2.8. MI_GFX_SetPalette

  • Function

    Set Palette for Index Color (I2/I4/I8).

  • Syntax

    MI_S32 MI_GFX_SetPalette(MI_GFX_ColorFmt_e eColorFmt, 
    MI_GFX_Palette_t * pstPalette);
    
  • Parameter

    Parameter Name Description Input/Output
    eColorFmt The color format corresponding to the palette. Input
    pstPalette Palette data. Input
  • Return Value

    • Zero: Successful

    • Non-zero: Failed, see error code for details

  • Requirement

    • Header: mi_gfx.h

    • Library: libmi_gfx.a/libmi_gfx.so

  • Note

    • Before calling this interface, make sure to call MI_GFX_Open to open the GFX device.

    • pstPalette is an array of MI_GFX_PaletteEntry_t with a capacity of 256. Each MI_GFX_PaletteEntry_t represents a color, and the corresponding subscript in the array represents the index of the color.

  • Example

    1.  MI_GFX_Palette_t myPal;  
    2.  MI_GFX_PaletteEntry_t index_0; 
    3.  MI_GFX_PaletteEntry_t index_1;
    4.  index_0.RGB.u8A = 0x40;
    5.  index_0.RGB.u8R = 0xFF;  
    6.  index_0.RGB.u8G = 0; 
    7.  index_0.RGB.u8B = 0;
    8.  index_1.RGB.u8A = 0x40;
    9.  index_1.RGB.u8R = 0; 
    10. index_1.RGB.u8G = 0xFF;
    11. index_1.RGB.u8B = 0;
    12. 
    13. myPal.aunPalette[0] = index_0; 
    14. myPal.aunPalette[1] = index_1; 
    15. myPal.u16PalStart = 0
    16. myPal.u16PalEnd = 1;
    17. MI_GFX_SetPalette(E_MI_GFX_FMT_I8, &myPal);
    

2.9. MI_GFX_InitDev

  • Function

    Initialize GFX device.

  • Syntax

    MI_S32 MI_GFX_InitDev(MI_GFX_InitParam_t *pstInitParam);
    
  • Parameters

    Parameter Name Description Input/Output
    pstInitParam Initialization Parameter Input
  • Return Value

    • Zero: Successful

    • Non-zero: Failed, see error code for details

  • Requirement

    • Header: mi_gfx.h

    • Library: libmi_gfx.a/libmi_gfx.so


2.10. MI_GFX_DeInitDev

  • Function

    De-initialize GFX device.

  • Syntax

    MI_S32 MI_GFX_DeInitDev(void);
    
  • Return Value

    • Zero: Successful

    • Non-zero: Failed, see error code for details

  • Requirement

    • Header: mi_gfx.h

    • Library: libmi_gfx.a/libmi_gfx.so

  • Note

    • This interface should be called after the device has been initialized; otherwise, a failed message will be returned.

    • If this interface is not called after the app exited, the GFX device will be auto de-initialized.

2.11. MI_GFX_DrawLine

  • Function

    Add line drawing operations to the task.

  • Syntax

    MI_S32 MI_GFX_DrawLine(MI_GFX_Surface_t *pstDst, 
    MI_GFX_Line_t *pstLine, MI_U16 *pu16Fence);
    
  • Parameters

    Parameter Name Description Input/Output
    pstDst Target bitmap Input
    pstLine Line attributes Input
    pu16Fence Return pointer to Fence Output
  • Return Value

    • Zero: Successful

    • Non-zero: Failed, see error code for details

  • Requirement

    • Header: mi_gfx.h

    • Library: libmi_gfx.a/libmi_gfx.so

  • Note

    • Before calling this interface, make sure to call MI_GFX_Open to open the GFX device.

    • The line drawing area cannot exceed the size of the target bitmap.

    • The end point of the straight line will not be drawn.

    • If the pixel format of the target bitmap is RGB or ARGB, u32ColorFrom/u32ColorFrom from high to low is A8: R8: G8: B8. If the pixel format of the target bitmap is YUYV422, A8 is invalid, and R corresponds to Y, G corresponds to U, B corresponds to V.

  • Example

    1.  FILE *fp = NULL;  
    2.  MI_GFX_Surface_t stDst;  
    3.  MI_GFX_Line_t stLine;  
    4.  MI_U16 u16TargetFence;  
    5.  MI_PHY phyAddr;  
    6.  void *VirAddr;  
    7.    
    8.  ExecFunc(MI_SYS_Init(), MI_SUCCESS);   
    9.  fp = fopen(SRC_FILE_NAME, "wb");   
    10. ExecFunc(MI_SYS_MMA_Alloc("mma_heap_name0", SRC_WIDTH*SRC_HEIGHT*2, &phyAddr), MI_SUCCESS);   
    11.   
    12. //MI_U32 phySrcAddr, phyDstAddr;   
    13. ExecFunc(MI_GFX_Open(), MI_SUCCESS);   
    14. ExecFunc(MI_SYS_Mmap(phyAddr, SRC_WIDTH*SRC_HEIGHT*2, &pVirAddr , FALSE), MI_SUCCESS);   
    15. memset(pVirAddr, 0x22, SRC_WIDTH*SRC_HEIGHT*2);   
    16.   
    17. //draw line  
    18. memset(&stDst, 0x0, sizeof(stDst));  
    19. stDst.eColorFmt = E_MI_GFX_FMT_ARGB1555;   
    20. stDst.u32Width = SRC_WIDTH;   
    21. stDst.u32Height = SRC_HEIGHT;   
    22. stDst.u32Stride = SRC_WIDTH * 2;   
    23. stDst.phyAddr = phyAddr;   
    24.   
    25. memset(&stLine, 0x0, sizeof(stLine));  
    26. stLine.stPointFrom.s16x = 0;  
    27. stLine.stPointFrom.s16y = 0;  
    28. stLine.stPointTo.s16x = 100;  
    29. stLine.stPointTo.s16y = 100;  
    30. stLine.u16Width = 1;  
    31. stLine.bColorGradient = TRUE;  
    32. stLine.bColorFrom = 0xffff0000;  
    33. stLine.bColorTo = 0xffff00ff;  
    34.   
    35. ExecFunc(MI_GFX_DrawLine(&stDst, &stLine, &u16TargetFence), MI_SUCCESS);   
    36. ExecFunc(MI_GFX_WaitAllDone(FALSE, u16TargetFence), MI_SUCCESS);   
    37. if (NULL != fp)   
    38. {   
    39.     fwrite(pVirAddr, 1, SRC_WIDTH*SRC_HEIGHT*2, fp);   
    40.     fclose(fp);   
    41.     fp = NULL;   
    42. }   
    43. ExecFunc(MI_SYS_Munmap(pVirAddr, SRC_WIDTH*SRC_HEIGHT*2), MI_SUCCESS);   
    44. ExecFunc(MI_SYS_MMA_Free(phyAddr), MI_SUCCESS);   
    45.   
    46. ExecFunc(MI_GFX_Close(), MI_SUCCESS);   
    47. ExecFunc(MI_SYS_Exit(), MI_SUCCESS);
    

3. GFX DATA TYPE

The GFX related data types are defined in the table below:

Function Description
MI_GFX_ColorFmt_e Define pixel color format
MI_GFX_Surface_t Define bitmap attribute structure
MI_GFX_Rect_t Define the attribute structure of the operating area
MI_GFX_ColorKeyOp_e Define Colorkey operation mode
MI_GFX_ColorKeyValue_t Define the Colorkey color attribute structure
MI_GFX_ColorKeyInfo_t Define the Colorkey attribute structure
MI_GFX_Rotate_e Define the image rotation angle
MI_GFX_Mirror_e Define image mirror mode
MI_GFX_DfbBldOp_e Define Alpha Blending mode
MI_Gfx_DfbBlendFlags_e Define Alpha Blending flag
MI_GFX_BitBltMode_e Define Bitblt interpolation mode
MI_GFX_Opt_t Define optional attribute structure for Bitblit operation
MI_GFX_PaletteEntry_t Define palette color structure
MI_GFX_Palette_t Define palette structure
MI_GFX_InitParam_t Define GFX device initialization parameters
MI_GFX_Point_t Define point attribute structure
MI_GFX_Line_t Define line attribute structure

3.1. MI_GFX_ColorFmt_e

  • Description

    Define pixel color format.

  • Definition

    typedef enum
    
    {
    
        E_MI_GFX_FMT_I1 = 0, /* MS_ColorFormat */
    
        E_MI_GFX_FMT_I2,
    
        E_MI_GFX_FMT_I4,
    
        E_MI_GFX_FMT_I8,
    
        E_MI_GFX_FMT_FABAFGBG2266,
    
        E_MI_GFX_FMT_1ABFGBG12355,
    
        E_MI_GFX_FMT_RGB565,
    
        E_MI_GFX_FMT_ARGB1555,
    
        E_MI_GFX_FMT_ARGB4444,
    
        E_MI_GFX_FMT_ARGB1555_DST,
    
        E_MI_GFX_FMT_YUV422,
    
        E_MI_GFX_FMT_ARGB8888,
    
        E_MI_GFX_FMT_RGBA5551,
    
        E_MI_GFX_FMT_RGBA4444,
    
        E_MI_GFX_FMT_ABGR8888,
    
        E_MI_GFX_FMT_BGRA5551,
    
        E_MI_GFX_FMT_ABGR1555,
    
        E_MI_GFX_FMT_ABGR4444,
    
        E_MI_GFX_FMT_BGRA4444,
    
        E_MI_GFX_FMT_BGR565,
    
        E_MI_GFX_FMT_RGBA8888,
    
        E_MI_GFX_FMT_BGRA8888,
    
        E_MI_GFX_FMT_MAX
    
    } MI_GFX_ColorFmt_e;
    
  • Note

    Color format supported by corresponding surface, which, during bitblt operation, corresponds to SrcSurface, DstSurface color format.


3.2. MI_GFX_Surface_t

  • Description

    Define bitmap attribute structure.

  • Definition

    typedef struct MI_GFX_Surface_s
    
    {
    
        MI_PHY phyAddr;
    
        MI_GFX_ColorFmt_e eColorFmt;
    
        MI_U32 u32Width;
    
        MI_U32 u32Height;
    
        MI_U32 u32Stride;
    
    } MI_GFX_Surface_t;
    
  • Member

    Member Description
    u32PhyAddr The bitmap corresponds to the physical address of the memory.
    eColorFmt Bitmap pixel color format.
    u32Height The height of the bitmap.
    u32Width The width of the bitmap.
    u32Stride The stride of the bitmap.
  • Note

    • When the pixel format size of the bitmap is greater than or equal to 1Byte, the physical address of the memory corresponding to the bitmap and Stride must be aligned according to the pixel format size; when the pixel format size of the bitmap is less than 1Byte, the physical address of the memory corresponding to the bitmap and Stride need to be aligned according to 1Byte.

    • The horizontal starting position and width of the bitmap in YUYV422 format must be even numbers.

  • Related Data Type and Interface

    MI_GFX_QuickFill

    MI_GFX_DrawLine

    MI_GFX_Bitblit


3.3. MI_GFX_Rect_t

  • Description

    Define the attribute structure of the operating area.

  • Definition

    typedef struct MI_GFX_Rect_s
    
    {
    
        MI_S32 s32Xpos;
    
        MI_S32 s32Ypos;
    
        MI_U32 u32Width;
    
        MI_U32 u32Height;
    
    } MI_GFX_Rect_t;
    
  • Member

    Member Description
    s32Xpos The starting abscissa of the operation region, in pixels. Valid range: [0, bitmap width).
    s32Ypos The starting ordinate of the operation region, in pixels. Valid range: [0, bitmap height).
    u32Width Width of the operation region, in pixels.
    u32Height Height of the operation region, in pixels.
  • Note

    The operating range must be within the range of the bitmap.

  • Related Data Type and Interface

    MI_GFX_Opt_t

    MI_GFX_QuickFill

    MI_GFX_Bitblit


3.3. MI_GFX_ColorKeyOp_e

  • Description

    Define Colorkey operation mode.

  • Definition

    typedef enum
    
    {
    
        E_MI_GFX_RGB_OP_EQUAL = 0,
    
        E_MI_GFX_RGB_OP_NOT_EQUAL,
    
        E_MI_GFX_ALPHA_OP_EQUAL,
    
        E_MI_GFX_ALPHA_OP_NOT_EQUAL,
    
        E_MI_GFX_ARGB_OP_EQUAL,
    
        E_MI_GFX_ARGB_OP_NOT_EQUAL,
    
        E_MI_GFX_CKEY_OP_BUTT,
    
    } MI_GFX_ColorKey_e;
    
  • Member

    Member Description
    E_MI_GFX_RGB_OP_EQUAL RGB equal colorkey operation
    E_MI_GFX_RGB_OP_NOT_EQUAL RGB unequal colorkey operation
    E_MI_GFX_ ALPHA_OP_EQUAL ALPHA equal colorkey operation
    E_MI_GFX_ ALPHA_OP_NOT_EQUAL ALPHA unequal colorkey operation
    E_MI_GFX_ ARGB_OP_EQUAL ARGB equal colorkey operation
    E_MI_GFX_ARGB_OP_NOT_EQUAL ARGB unequal colorkey operation
    E_MI_GFX_CKEY_OP_BUTT Invalid colorkey operation
  • Related Data Type and Interface

    MI_GFX_ColorKeyInfo_t


3.5. MI_GFX_ColorKeyValue_t

  • Description

    Define the Colorkey color attribute structure.

  • Definition

    typedef struct MI_GFX_ColorKey_s
    
    {
    
        MI_U32 u32ColorStart;
    
        MI_U32 u32ColorEnd;
    
    } MI_GFX_ColorKeyValue_t;
    
  • Member

    Member Description
    u32ColorStart ColorKey start color
    u32ColorEnd ColorKey end color
  • Note

    When only one single color value is to go through colorkey operation, set u32ColorStart = u32ColorEnd = colorVal.

  • Related Data Type and Interface

    MI_GFX_ColorKeyInfo_t


3.6. MI_GFX_ColorKeyInfo_t

  • Description

    Define the Colorkey attribute structure.

  • Definition

    typedef struct MI_GFX_ColorKeyInfo_s
    
    {
    
        MI_BOOL bEnColorKey;
    
        MI_GFX_ColorKeyOp_e eCKeyOp;
    
        MI_GFX_ColorFmt_e eCKeyFmt;
    
        MI_GFX_ColorKeyValue_t stCKeyVal;
    
    } MI_GFX_ColorKeyInfo_t;
    
  • Member

    Member Description
    bEnColorKey ColorKey operation enable
    eCKeyOp ColorKey operation mode
    stCKeyVal ColorKey color range
    eCKeyFmt ColorKey color format
  • Related Data Type and Interface

    MI_GFX_Opt_t


3.7. MI_GFX_Rotate_e

  • Description

    Define the image rotation angle.

  • Definition

    typedef enum
    
    {
    
        E_MI_GFX_ROTATE_0 = 0,
    
        E_MI_GFX_ROTATE_90,
    
        E_MI_GFX_ROTATE_180,
    
        E_MI_GFX_ROTATE_270
    
    } MI_GFX_Rotate_e;
    
  • Related Data Type and Interface

    MI_GFX_Opt_t


3.8. MI_GFX_Mirror_e

  • Description

    Define image mirror mode.

  • Definition

    typedef enum
    
    {
    
        E_MI_GFX_MIRROR_NONE = 0,
    
        E_MI_GFX_MIRROR_HORIZONTAL,
    
        E_MI_GFX_MIRROR_VERTICAL,
    
        E_MI_GFX_MIRROR_BOTH,
    
        E_MI_GFX_MIRROR_MAX
    
    } MI_GFX_Mirror_e;
    
  • Member

    Member Description
    E_MI_GFX_MIRROR_NONE Output image mirror operation disabled
    E_MI_GFX_MIRROR_HORIZONTAL Output image horizontal mirror
    E_MI_GFX_MIRROR_VERTICAL Output image vertical mirror
    E_MI_GFX_MIRROR_BOTH Output image horizontal + vertical mirror
    E_MI_GFX_MIRROR_MAX Invalid mirror type
  • Related Data Type and Interface

    MI_GFX_Opt_t


3.9. MI_GFX_DfbBldOp_e

  • Description

    Define Alpha Blending mode.

  • Definition

    typedef enum
    {
        E_MI_GFX_DFB_BLD_ZERO = 0,
        E_MI_GFX_DFB_BLD_ONE,
        E_MI_GFX_DFB_BLD_SRCCOLOR,
        E_MI_GFX_DFB_BLD_INVSRCCOLOR,
        E_MI_GFX_DFB_BLD_SRCALPHA,
        E_MI_GFX_DFB_BLD_INVSRCALPHA,
        E_MI_GFX_DFB_BLD_DESTALPHA,
        E_MI_GFX_DFB_BLD_INVDESTALPHA,
        E_MI_GFX_DFB_BLD_DESTCOLOR,
        E_MI_GFX_DFB_BLD_INVDESTCOLOR,
        E_MI_GFX_DFB_BLD_SRCALPHASAT,
        E_MI_GFX_DFB_BLD_NONE,
        E_MI_GFX_DFB_BLD_MAX,
    } MI_GFX_DfbBldOp_e;
    
  • Member

    Member Description
    E_MI_GFX_DFB_BLD_OP_ZERO argb *= 0.0
    Same as directfb DSBF_ZERO
    E_MI_GFX_DFB_BLD_OP_ONE argb *= 1.0
    Same as directfb DSBF_ONE
    E_MI_GFX_DFB_BLD_OP_SRCCOLOR argb *= Sargb
    Same as directfb DSBF_SRCCOLOR
    E_MI_GFX_DFB_BLD_OP_INVSRCCOLOR argb *= 1.0 - Sargb
    Same as directfb DSBF_INVSRCCOLOR
    E_MI_GFX_DFB_BLD_OP_SRCALPHA argb *= Saaaa
    Same as directfb DSBF_SRCALPHA
    E_MI_GFX_DFB_BLD_OP_INVSRCALPHA argb *= 1.0 – Saaaa
    Same as directfb DSBF_INVSRCALPHA
    E_MI_GFX_DFB_BLD_OP_DESTCOLOR argb *= Dargb
    Same as directfb DSBF_DESTCOLOR
    E_MI_GFX_DFB_BLD_OP_INVDESTCOLOR argb *= 1.0 – Dargb
    Same as directfb DSBF_INVDESTCOLOR
    E_MI_GFX_DFB_BLD_OP_DESTALPHA argb *= Daaaa Same as directfb DSBF_DESTALPHA
    E_MI_GFX_DFB_BLD_OP_INVDESTALPHA argb *= 1.0 – Daaaa
    Same as directfb DSBF_INVDESTALPHA
    E_MI_GFX_DFB_BLD_OP_SRCALPHASAT rgb *= min(Sa, 1-Da)
    Same as directfb DSBF_SRCALPHASAT
    E_MI_GFX_BLD_MAX Invalid alpha blending mode
  • Note

    When the source bitmap and target bitmap are superimposed, you can set the superimposition mode of Src channel and Dst channel respectively. Now supports 11 overlay modes. Use MI_GFX_DfbBldOp_e to set the mode.

  • Related Data Type and Interface

    MI_GFX_Opt_t


3.10. MI_Gfx_DfbBlendFlags_e

  • Description

    Define Alpha Blending flag.

  • Definition

    typedef enum
    {
        E_MI_GFX_DFB_BLEND_NOFX = 0x00000000,
        E_MI_GFX_DFB_BLEND_COLORALPHA = 0x00000001,
        E_MI_GFX_DFB_BLEND_ALPHACHANNEL = 0x00000002,
        E_MI_GFX_DFB_BLEND_COLORIZE = 0x00000004,
        E_MI_GFX_DFB_BLEND_SRC_PREMULTIPLY = 0x00000008,
        E_MI_GFX_DFB_BLEND_SRC_PREMULTCOLOR = 0x00000010,
        E_MI_GFX_DFB_BLEND_DST_PREMULTIPLY = 0x00000020,
        E_MI_GFX_DFB_BLEND_XOR = 0x00000040,
        E_MI_GFX_DFB_BLEND_DEMULTIPLY = 0x00000080,
        E_MI_GFX_DFB_BLEND_SRC_COLORKEY = 0x00000100,
        E_MI_GFX_DFB_BLEND_DST_COLORKEY = 0x00000200,
        E_MI_GFX_DFB_BLEND_MAX = 0x3FF
    } MI_Gfx_DfbBlendFlags_e;
    
  • Member

    Member Description
    E_MI_GFX_DFB_BLEND_NOFX No BLD operation
    E_MI_GFX_DFB_BLEND_COLORALPHA src alpha will operate src.a = const color.a according to const color value;
    Same as directfb DSBLIT_BLEND_COLORALPHA
    E_MI_GFX_DFB_BLEND_ALPHACHANNEL src alpha will operate src.a = src.a * const color.a according to const color value;
    Same as directfb DSBLIT_BLEND_ALPHACHANNEL
    E_MI_GFX_DFB_BLEND_COLORIZE Use const color as the global color, adjust the source color;
    Same as directfb DSBLIT_COLORIZE
    E_MI_GFX_DFB_BLEND_SRC_PREMULTIPLY Use the source alpha to pre-multiply the source color src.r = src.r * src.a;
    Same as directfb DSBLIT_SRC_PREMULTIPLY
    E_MI_GFX_DFB_BLEND_SRC_PREMULTCOLOR Use const alpha to premultiply the source color src.r = src.r * const.a;
    Same as directfb DSBLIT_SRC_PREMULTCOLOR
    E_MI_GFX_DFB_BLEND_DST_PREMULTIPLY Use destination alpha to premultiply destination color dst.r = dst.r * dst.a;
    Same as directfb DSBLIT_DST_PREMULTIPLY
    E_MI_GFX_DFB_BLEND_XOR Adjust and premultiply alpha src.a ^= dst.a;
    Same as directfb DSBLIT_XOR
    E_MI_GFX_DFB_BLEND_DEMULTIPLY For conversion from premultiplied to non-premultiplied, it is best not to use such an operation x.r = ((int)x.r << 8) / ((int)x.a + 1);
    Same as directfb DSBLIT_DEMULTIPLY
    E_MI_GFX_DFB_BLEND_SRC_COLORKEY If the color of src is equal to const color, it will be keyed off
    E_MI_GFX_DFB_BLEND_DST_COLORKEY If the color of dst is equal to const color, it will be keyed off
    E_MI_GFX_DFB_BLEND_MAX All the above actions will be enabled
  • Related Data Type and Interface

    MI_GFX_Opt_t

3.11. MI_Gfx_BitBltMode_e

  • Description

    Define Bitblt interpolation mode.

  • Definition

    typedef enum
    
    {
    
        E_MI_GFX_BITBLT_MODE_BILINEAR,
    
        E_MI_GFX_BITBLT_MODE_NEAREST,
    
    } MI_GFX_BitBltMode_e;
    
  • Member

    Member Description
    E_MI_GFX_BITBLT_MODE_BILINEAR Bilinear interpolation mode
    E_MI_GFX_BITBLT_MODE_NEAREST Nearest interpolation mode
  • Related Data Type and Interface

    MI_GFX_Opt_t


3.12. MI_GFX_Opt_t

  • Description

    Define optional attribute structure for Bitblit operation.

  • Definition

    typedef struct MI_GFX_Opt_s
    {
        MI_GFX_Rect_t stClipRect;
        MI_GFX_ColorKeyInfo_t stSrcColorKeyInfo;
        MI_GFX_ColorKeyInfo_t stDstColorKeyInfo;
        MI_GFX_DfbBldOp_e eSrcDfbBldOp;
        MI_GFX_DfbBldOp_e eDstDfbBldOp;
        MI_GFX_Mirror_e eMirror;
        MI_GFX_Rotate_e eRotate;
        MI_Gfx_DfbBlendFlags_e eDFBBlendFlag;
        MI_GFX_BitBltMode_e eMode;
        MI_U32 u32GlobalSrcConstColor;
        MI_U32 u32GlobalDstConstColor;
    } MI_GFX_Opt_t;
    
  • Member

    Member Description
    eDFBBlendFlag Dfb blending operation flags
    stSrcColorKeyInfo Source surface colorkey operation
    stDstColorKeyInfo Destination surface colorkey operation
    stClipRect Clip region definition
    eMirror Image mirror type
    eSrcDfbBldOp Source surface BLEND operation mode
    eDstDfbBldOp Destination surface BLEND operation mode
    eRotate Image rotation angle: 0, 90, 180, 270°
    eDFBBlendFlag Blending related operations, such as XOR, AlphaBlending, Colorize, etc.
    eMode BitBlt interpolation mode
    u32GlobalSrcConstColor const color for dfb blending operation
    u32GlobalDstConstColor const color for dfb blending operation
  • Note

    Currently only u32GlobalSrcConstColor is valid.

  • Related Data Type and Interface

    MI_GFX_Bitblit


3.13. MI_GFX_PaletteEntry_t

  • Description

    Define palette color structure.

  • Definition

    typedef union
    
    {
    
        /// ARGB8888 byte order
    
        struct
    
        {
    
            MI_U8 u8A;
    
            MI_U8 u8R;
    
            MI_U8 u8G;
    
            MI_U8 u8B;
    
        } RGB;
    
        // u8Data[0] = u8A
    
        // u8Data[1] = u8R
    
        // u8Data[2] = u8G
    
        // u8Data[3] = u8B
    
        MI_U8 u8Data[4];
    
    } MI_GFX_PaletteEntry_t;
    
  • Member

    Member Description
    RGB Color component structure for an Index Color
    u8Data Byte order RGB data for an Index Color
  • Note

    Please pay attention to the remark in the definition, which will help you understand the color value’s memory layout.

  • Related Data Type and Interface

    MI_GFX_Palette_t


3.14. MI_GFX_Palette_t

  • Description

    Define palette structure.

  • Definition

    typedef struct MI_GFX_Palette_s
    
    {
    
        MI_GFX_PaletteEntry_t aunPalette[256];
    
        MI_U16 u16PalStart;
    
        MI_U16 u16PalEnd;
    
    }MI_GFX_Palette_t;
    
  • Member

    Member Description
    aunPalette Array of RGB colors
    u16PalStart Starting index
    u16PalEnd Ending index
  • Related Data Type and Interface

    MI_GFX_PaletteEntry_t


3.15. MI_GFX_InitParam_t

  • Description

    Define GFX device initialization parameters.

  • Definition

    typedef struct MI_GFX_InitParam_s
    
    {
    
        MI_U32 u32DevId;
    
        MI_U8 *u8Data;
    
    } MI_GFX_InitParam_t;
    
  • Member

    Member Description
    u32DevId Device ID
    u8Data Data pointer buffer
  • Related Data Type and Interface

    MI_GFX_InitDev

3.16. MI_GFX_Point_t

  • Description

    Define point attribute structure.

  • Definition

    typedef struct MI_GFX_Point_s
    {
        MI_S16 s16x;
        MI_S16 s16y;
    } MI_GFX_Point_t;
    
  • Member

    Member Description
    s16x X coordinate
    S16y Y coordinate
  • Related Data Type and Interface

    MI_GFX_Line_t

3.17. MI_GFX_Line_t

  • Description

    Define line attribute structure.

  • Definition

    typedef struct MI_GFX_Line_s
    {
        MI_GFX_Point_t stPointFrom;
        MI_GFX_Point_t srPointTo;
        MI_U16 u16Width;
        MI_BOOL bColorGradient;
        MI_U32 u32ColorFrom;
        MI_U32 u32ColorTo;
    } MI_GFX_Line_t;
    
  • Member

    Member Description
    stPointFrom Start point of the straight line
    srPointTo The end of the straight line
    u16Width Straight line width
    bColorGradient Whether the color gradient
    u32ColorFrom Gradient start color
    u32ColorTo Gradient end color
  • Related Data Type and Interface

    MI_GFX_DrawLine


4. GFX ERROR CODE

The GFX API error codes are as listed in the table below:

Error Code Macro Definition Description
0xA00D2003 MI_ERR_GFX_INVALID_PARAM Invalid parameter
0xA00D2002 MI_ERR_GFX_DEV_BUSY GFX device busy
0xA00D2220 MI_ERR_GFX_NOT_INIT Device not initialized
0xA00D2221 MI_ERR_GFX_DRV_NOT_SUPPORT Unsupported operation
0xA00D2222 MI_ERR_GFX_DRV_FAIL_FORMAT Unsupported format
0xA00D2223 MI_ERR_GFX_NON_ALIGN_ADDRESS Address not aligned
0xA00D2224 MI_ERR_GFX_NON_ALIGN_PITCH Pitch not aligned
0xA00D2225 MI_ERR_GFX_DRV_FAIL_OVERLAP Overlap region found in Option
0xA00D2226 MI_ERR_GFX_DRV_FAIL_STRETCH Stretch failed
0xA00D2228 MI_ERR_GFX_DRV_FAIL_LOCKED Device locked by other use
0xA00D2229 MI_ERR_GFX_DRV_FAIL_BLTADDR Bitblit start address error

5. PROCFS INTRODUCTION

5.1. cat

  • Debug info

    # cat /proc/mi_modules/mi_gfx/mi_gfx0
    

  • Debug info analysis

    Record GFX current usage status and device attribute which can be dynamically got to debug and test.

  • Parameter Description

    Parameter Description
    device info
    module init count
    Device opened times. Since GFX will be called by multiple modules, and it is not certain which module will call GFX initialization first, the device can be opened multiple times. The opened times will be recorded to determine whether the device is required to be closed.
    Device id GFX device ID
    ARGB1555 alpha threshold Convert ARGB8888 to ARGB1555. If the alpha threshold in GFX is greater than N, then alpha is 1, otherwise, alpha is 0.
    ARGB1555 To ARGB8888 alpha value Convert ARGB1555 to ARGB8888, GFX converts the pixel alpha whose alpha bit of ARGB1555 is 1 to ARGB8888 Alpha Value
    Scaling coefficient Image geometric center offset