/* param blendedAlpha The desired blended alpha value, alpha range 0~255. param globalAlpha Calculated global alpha set to each layer register. param layerCount Total layer count. retval kStatus_Success Get successfully. retval kStatus_InvalidArgument The argument is invalid.  */
status_t LCDIFV2_GetMultiLayerGlobalAlpha(const uint8_t blendedAlpha[], uint8_t globalAlpha[], uint8_t layerCount)
/* param blendedAlpha The desired blended alpha value, alpha range 0~255. param globalAlpha Calculated global alpha set to each layer register. param layerCount Total layer count. retval kStatus_Success Get successfully. retval kStatus_InvalidArgument The argument is invalid.  */
status_t LCDIFV2_GetMultiLayerGlobalAlpha(const uint8_t blendedAlpha[], uint8_t globalAlpha[], uint8_t layerCount)
{
    status_t status  = kStatus_Success;
    int16_t curLayer = (int16_t)layerCount - 1;
    int left         = 255;
    int tmpAlpha;
    assert((layerCount > 1U) && (layerCount <= (uint8_t)LCDIFV2_LAYER_COUNT));
    globalAlpha[0] = 255U;
    while (curLayer > 0)
    {
        tmpAlpha = (int)blendedAlpha[curLayer] * 255 / left;
        if (tmpAlpha > 255)
        {
            status = kStatus_InvalidArgument;
            break;
        }
        globalAlpha[curLayer] = (uint8_t)tmpAlpha;
        left -= (int)blendedAlpha[curLayer];
        if (left <= 0)
        {
            status = kStatus_InvalidArgument;
            break;
        }
        curLayer--;
    }
    return status;
}