⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ppclass.cpp

📁 freescale i.mx31 BSP CE5.0全部源码
💻 CPP
📖 第 1 页 / 共 5 页
字号:


//-----------------------------------------------------------------------------
//
// Function: PpInitDisplayCharacteristics
//
// This function initializes the display characteristics by
// retrieving them from the display driver.
//
// Parameters:
//      None.
//
// Returns:
//      TRUE if success, FALSE if failure.
//
//-----------------------------------------------------------------------------
BOOL PpClass::PpInitDisplayCharacteristics(void)
{
    PP_FUNCTION_ENTRY();

    m_hDisplay = CreateDC(TEXT("DISPLAY"), NULL, NULL, NULL);

    // Get Display Type from Display driver
    if (ExtEscape(m_hDisplay, VF_GET_DISPLAY_INFO, NULL, NULL,
        sizeof(DISPLAY_CHARACTERISTIC), (LPSTR) &m_displayCharacteristics) < 0)
    {
        DEBUGMSG(ZONE_ERROR,  (TEXT("%s: Unable to get display characteristics! \r\n"), __WFUNCTION__));
        return FALSE;
    }

    PP_FUNCTION_EXIT();

    return TRUE;
}


//-----------------------------------------------------------------------------
//
// Function: PpConfigureInput
//
// This function configures the IC registers and IDMAC
// channels for the postprocessor input source.
//
// Parameters:
//      pPpConfigureData_t
//          [in] Pointer to configuration data structure
//
// Returns:
//      TRUE if success
//      FALSE if failure
//
//-----------------------------------------------------------------------------
BOOL PpClass::PpConfigureInput(pPpConfigData pConfigData)
{
    BOOL result = TRUE;
    UINT16 iInputWidth, iInputHeight;
    UINT32 iInputStride;
    ppIDMACChannelParams channelParams;
    ppFormat iFormat = pConfigData->inputFormat;

    PP_FUNCTION_ENTRY();

    // Configure rotation BAM parameter
    channelParams.iBAM = 0;

    // Pixel Burst rate always 16 unless we are using a rotation channel
//    channelParams.iPixelBurstCode = IDMAC_PIXEL_BURST_CODE_16;
    channelParams.iPixelBurstCode = IDMAC_PIXEL_BURST_CODE_8;

    // Set these variables to reduce pointer computations,
    // as these will be referenced several times.
    iInputWidth = pConfigData->inputSize.width;
    iInputHeight = pConfigData->inputSize.height;
    iInputStride = pConfigData->inputStride;

    // This is FALSE as default, and will be set TURE if a 
    // planar format is found
    m_bInputPlanar = FALSE;

    //-----------------------------------------------------------------
    // Setup input format
    //-----------------------------------------------------------------

    switch(iFormat)
    {
        case ppFormat_YUV444:
            channelParams.bInterleaved = FALSE;
            channelParams.iFormatCode = IDMAC_NON_INTERLEAVED_FORMAT_CODE_YUV444;
            channelParams.iBitsPerPixelCode = IDMAC_BPP_CODE_8; // required for planar formats
            m_bInputPlanar = TRUE;

            break;

        case ppFormat_YUV422:
            channelParams.bInterleaved = FALSE;
            channelParams.iFormatCode = IDMAC_NON_INTERLEAVED_FORMAT_CODE_YUV422;
            channelParams.iBitsPerPixelCode = IDMAC_BPP_CODE_8; // required for planar formats
            m_bInputPlanar = TRUE;

            break;

        case ppFormat_YUV420:
            channelParams.bInterleaved = FALSE;
            channelParams.iFormatCode = IDMAC_NON_INTERLEAVED_FORMAT_CODE_YUV420;
            channelParams.iBitsPerPixelCode = IDMAC_BPP_CODE_8; // required for planar formats
            m_bInputPlanar = TRUE;

            break;

        case ppFormat_YUV444IL:
            channelParams.pixelFormat.component0_offset = 0;
            channelParams.pixelFormat.component1_offset = 8;
            channelParams.pixelFormat.component2_offset = 16;
            channelParams.pixelFormat.component0_width = 7;
            channelParams.pixelFormat.component1_width = 7;
            channelParams.pixelFormat.component2_width = 7;

            channelParams.iBitsPerPixelCode = IDMAC_BPP_CODE_24; // Code for 24BPP
            channelParams.bInterleaved = TRUE;
            channelParams.iFormatCode = IDMAC_INTERLEAVED_FORMAT_CODE_YUV444;

            break;

        case ppFormat_YUYV422:
            channelParams.pixelFormat.component0_offset = 0;
            channelParams.pixelFormat.component1_offset = 8;
            channelParams.pixelFormat.component2_offset = 24;
            channelParams.pixelFormat.component0_width = 7;
            channelParams.pixelFormat.component1_width = 7;
            channelParams.pixelFormat.component2_width = 7;

            channelParams.iBitsPerPixelCode = IDMAC_BPP_CODE_16; // Code for 16BPP
            channelParams.bInterleaved = TRUE;
            channelParams.iFormatCode = IDMAC_INTERLEAVED_FORMAT_CODE_YUV422;

            break;

        case ppFormat_YVYU422:
            channelParams.pixelFormat.component0_offset = 0;
            channelParams.pixelFormat.component1_offset = 24;
            channelParams.pixelFormat.component2_offset = 8;
            channelParams.pixelFormat.component0_width = 7;
            channelParams.pixelFormat.component1_width = 7;
            channelParams.pixelFormat.component2_width = 7;

            channelParams.iBitsPerPixelCode = IDMAC_BPP_CODE_16; // Code for 16BPP
            channelParams.bInterleaved = TRUE;
            channelParams.iFormatCode = IDMAC_INTERLEAVED_FORMAT_CODE_YUV422;

            break;

        case ppFormat_UYVY422:
            channelParams.pixelFormat.component0_offset = 8;
            channelParams.pixelFormat.component1_offset = 0;
            channelParams.pixelFormat.component2_offset = 16;
            channelParams.pixelFormat.component0_width = 7;
            channelParams.pixelFormat.component1_width = 7;
            channelParams.pixelFormat.component2_width = 7;

            channelParams.iBitsPerPixelCode = IDMAC_BPP_CODE_16; // Code for 16BPP
            channelParams.bInterleaved = TRUE;
            channelParams.iFormatCode = IDMAC_INTERLEAVED_FORMAT_CODE_YUV422;

            break;

        case ppFormat_VYUY422:
            channelParams.pixelFormat.component0_offset = 8;
            channelParams.pixelFormat.component1_offset = 16;
            channelParams.pixelFormat.component2_offset = 0;
            channelParams.pixelFormat.component0_width = 7;
            channelParams.pixelFormat.component1_width = 7;
            channelParams.pixelFormat.component2_width = 7;

            channelParams.iBitsPerPixelCode = IDMAC_BPP_CODE_16; // Code for 16BPP
            channelParams.bInterleaved = TRUE;
            channelParams.iFormatCode = IDMAC_INTERLEAVED_FORMAT_CODE_YUV422;

            break;

        case ppFormat_RGB:
            channelParams.pixelFormat.component0_offset = pConfigData->inputRGBPixelFormat.component0_offset;
            channelParams.pixelFormat.component1_offset = pConfigData->inputRGBPixelFormat.component1_offset;
            channelParams.pixelFormat.component2_offset = pConfigData->inputRGBPixelFormat.component2_offset;
            channelParams.pixelFormat.component3_offset = 0;
            channelParams.pixelFormat.component0_width = pConfigData->inputRGBPixelFormat.component0_width-1;
            channelParams.pixelFormat.component1_width = pConfigData->inputRGBPixelFormat.component1_width-1;
            channelParams.pixelFormat.component2_width = pConfigData->inputRGBPixelFormat.component2_width-1;
            channelParams.pixelFormat.component3_width = 0;

            switch (pConfigData->inputDataWidth)
            {
                case ppDataWidth_8BPP:
                    channelParams.iBitsPerPixelCode = IDMAC_BPP_CODE_8;
                    break;

                case ppDataWidth_16BPP:
                    channelParams.iBitsPerPixelCode = IDMAC_BPP_CODE_16;
                    break;

                case ppDataWidth_24BPP:
                    channelParams.iBitsPerPixelCode = IDMAC_BPP_CODE_24;
                    break;

                case ppDataWidth_32BPP:
                    channelParams.iBitsPerPixelCode = IDMAC_BPP_CODE_32;
                    break;

                default:
                    DEBUGMSG(ZONE_ERROR,  (TEXT("%s: Error PP data width, %d !! \r\n"), __WFUNCTION__, pConfigData->inputDataWidth));
                    result =  FALSE;
                    goto _inputDone;
            }

            channelParams.bInterleaved = TRUE;
            channelParams.iFormatCode = IDMAC_INTERLEAVED_FORMAT_CODE_RGB;

            break;

        case ppFormat_RGBA:
            // TODO: Add support for RGBA, and find out data path and use cases for RGBA
            channelParams.pixelFormat.component0_offset = 0;
            channelParams.pixelFormat.component1_offset = 8;
            channelParams.pixelFormat.component2_offset = 16;
            channelParams.pixelFormat.component3_offset = 24;
            channelParams.pixelFormat.component0_width = 7;
            channelParams.pixelFormat.component1_width = 7;
            channelParams.pixelFormat.component2_width = 7;
            channelParams.pixelFormat.component3_width = 7;

            // 32 bits per pixel for RGB data
            channelParams.bInterleaved = TRUE;
            channelParams.iFormatCode = IDMAC_INTERLEAVED_FORMAT_CODE_RGB;

            break;

        default:
            DEBUGMSG(ZONE_ERROR,  (TEXT("%s: Invalid PP input format, %d !! \r\n"), __WFUNCTION__, pConfigData->inputFormat));
            result =  FALSE;
            goto _inputDone;
    }


    //-----------------------------------------------------------------
    // Image size validity check
    // Setup input image size
    //-----------------------------------------------------------------

    // Boundary check
    if((iInputWidth  > PP_MAX_INPUT_WIDTH) ||
        (iInputHeight > PP_MAX_INPUT_HEIGHT) ||
        (iInputWidth  < PP_MIN_INPUT_WIDTH) ||
        (iInputHeight < PP_MIN_INPUT_HEIGHT))
    {
        DEBUGMSG(ZONE_ERROR, (TEXT("%s: Error input size: \r\n"), __WFUNCTION__));
        DEBUGMSG(ZONE_ERROR,
                (TEXT("\t Input Size: width (%d), height (%d)\r\n"),
                iInputWidth, iInputHeight));
        result = FALSE;
        goto _inputDone;
    }

    // Alignment check
    if(pConfigData->inputFormat == ppFormat_YUV420)
    {
        if((iInputWidth & 0x07) ||
            (iInputHeight & 0x01))
        {
            DEBUGMSG(ZONE_ERROR,
                    (TEXT("%s: Error input size, w (%d), h (%d)! \r\n"), __WFUNCTION__,
                    iInputWidth, iInputHeight));
            result = FALSE;
            goto _inputDone;
        }
    }
    else
    {
        if(iInputWidth & 0x03)
        {
            DEBUGMSG(ZONE_ERROR,
                    (TEXT("%s: Error input size, w (%d), h (%d)! \r\n"), __WFUNCTION__,
                    iInputWidth, iInputHeight));
            result = FALSE;
            goto _inputDone;
        }
    }

    // Set channel parameters for frame height and width
    channelParams.iHeight = iInputHeight;
    channelParams.iWidth = iInputWidth;
    channelParams.iLineStride = iInputStride;

    // Configure Channel 5 (Mem->IC for Post-processing)
    PpIDMACChannelConfig(PP_MEM_TO_IC_DMA_CHANNEL, &channelParams);

_inputDone:
    PP_FUNCTION_EXIT();
    return result;
}


//-----------------------------------------------------------------------------
//
// Function: PpConfigureOutput
//
// This function configures the IC registers and IDMAC
// channels for the post-processor output.
//
// Parameters:
//      pPpConfigureData
//          [in] Pointer to configuration data structure
//
// Returns:
//      TRUE if success
//      FALSE if failure
//
//-----------------------------------------------------------------------------
BOOL PpClass::PpConfigureOutput(pPpConfigData pConfigData)
{
    BOOL result = TRUE;
    UINT16 iOutputWidth, iOutputHeight, tempWidth;
    UINT32 iOutputBufSize;
    UINT32 iOutputStride;
    ppIDMACChannelParams channelParams;
    DISPLAY_SDC_FG_CONFIG_DATA displayConfig;
    ppFormat iFormat = pConfigData->outputFormat;
    UINT32 oldVal, newVal, iMask, iBitval;
    UINT32 iRotatedStride;

    PP_FUNCTION_ENTRY();

    // Configure rotation BAM parameter
    channelParams.iBAM = (pConfigData->flipRot.verticalFlip ? 1 : 0) |
        (pConfigData->flipRot.horizontalFlip ? 1 : 0) << 1  |
        (pConfigData->flipRot.rotate90 ? 1 : 0) << 2;

    m_bFlipRot = (channelParams.iBAM == 0) ? 0 : 1;

    // Set these variables to reduce pointer computations,
    // as these will be referenced several times.
    iOutputWidth = pConfigData->outputSize.width;
    iOutputHeight = pConfigData->outputSize.height;
    iOutputStride = pConfigData->outputStride;

    g_iOutputWidth = iOutputWidth;
    g_iOutputHeight = iOutputHeight;

    // This is FALSE as default, and will be set TURE if a 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -