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

📄 tmicp.c

📁 用于TM1300/PNX1300系列DSP(主要用于视频处理)的设备库的源码
💻 C
📖 第 1 页 / 共 4 页
字号:

    if (image->inFormat == vdfYUV411Planar) {
        tmp = (UInt32) (65536.0 * 0.25 * 
              (Float) image->inputWidth / (Float) image->outputWidth);
        blk3.uFracInc = ((tmp << 16) & 0xffff0000) + ((tmp >> 16) & 0x0000ffff);
    }
    else {
        tmp = (UInt32) (65536.0 * 0.5 * 
              (Float) image->inputWidth / (Float) image->outputWidth);
        blk3.uFracInc = ((tmp << 16) & 0xffff0000) + ((tmp >> 16) & 0x0000ffff);
    }

    if (image->inFormat == vdfYUV420Planar)
        blk3.uHeightIn = image->inputHeight >> 1;
    else
        blk3.uHeightIn = image->inputHeight;    /* if yuv420 then 
                                                 * UHeight=srcHeight/2; */

    blk3.uWidthIn = (UInt16) (image->inputWidth >> 1);
    if (image->inFormat == vdfYUV411Planar)
        blk3.uWidthIn = (UInt16) (image->inputWidth >> 2);

    blk3.vCntStFrac = blk3.uCntStFrac;
    blk3.vFracInc   = blk3.uFracInc;
    blk3.vHeightIn  = blk3.uHeightIn;
    blk3.vWidthIn   = blk3.uWidthIn;  /* Assuming U and V are similarly 
                                       * structured */

    blk3.control &= 0xffef;
    if (image->littleEndian == True)
        blk3.control |= 0x0010;

    blk3.control &= 0xfff8;           /* Clear any previously stored  
                                       * information about output format */

    if (image->outFormat == vdfRGB16)           /* vifRGB 16 */
        blk3.control |= (UInt16) 0x0007;
    else if (image->outFormat == vdfRGB24)      /* vifRGB 24 packed */
        blk3.control |= (UInt16) 0x0003;
    else if (image->outFormat == vdfRGB8A_233)  /* vifRGB 8A */
        blk3.control |= (UInt16) 0x0004;
    else if (image->outFormat == vdfRGB8R_332)  /* vifRGB 8R */
        blk3.control |= (UInt16) 0x0005;
    else if (image->outFormat == vdfRGB24Alpha) /* vifRGB 24+alpha */
        blk3.control |= (UInt16) 0x0002;
    else if (image->outFormat == vdfRGB15Alpha) /* vifRGB 15+alpha */
        blk3.control |= (UInt16) 0x0006;
    else if (image->outFormat == vdfYUV422SequenceAlpha)/* YUV 422 + alpha */
        blk3.control |= (UInt16) 0x0000;
    else if (image->outFormat == vdfYUV422Sequence) /* YUV 422 sequence */
        blk3.control |= (UInt16) 0x0001;


    if (image->alpha1 == 0)
        blk3.alpha = 0x0000;
    else if (image->alpha1 > 0 && image->alpha1 <= 0.25)
        blk3.alpha = 0x2000;
    else if (image->alpha1 > 0.25 && image->alpha1 <= 0.5)
        blk3.alpha = 0x4000;
    else if (image->alpha1 > 0.5 && image->alpha1 <= 0.75)
        blk3.alpha = 0x6000;
    else if (image->alpha1 > 0.75 && image->alpha1 <= 1.0)
        blk3.alpha = 0x8000;
    else if (image->overlayEnable) {
      if (image->alpha1 < 0.0) {
	tmAssert(!(image->alpha1 < 0.0), ICP_ERR_INVALID_ALPHA);
	blk3.alpha = 0x0000;
      } 
      else if (image->alpha1 > 1.0) {
	tmAssert(!(image->alpha1 > 1.0), ICP_ERR_INVALID_ALPHA);
	blk3.alpha = 0x8000;
      }
    }

    if (image->alpha0 == 0)
        blk3.alpha |= 0x0000;
    else if (image->alpha0 > 0 && image->alpha0 <= 0.25)
        blk3.alpha |= 0x0020;
    else if (image->alpha0 > 0.25 && image->alpha0 <= 0.5)
        blk3.alpha |= 0x0040;
    else if (image->alpha0 > 0.5 && image->alpha0 <= 0.75)
        blk3.alpha |= 0x0060;
    else if (image->alpha0 > 0.75 && image->alpha0 <= 1.0)
        blk3.alpha |= 0x0080;
    else if (image->overlayEnable) {
      if (image->alpha0 < 0.0) {
	tmAssert(!(image->alpha0 < 0.0), ICP_ERR_INVALID_ALPHA);
	blk3.alpha &= 0xFF00;
      } 
      else if (image->alpha0 > 1.0) {
	tmAssert(!(image->alpha0 > 1.0), ICP_ERR_INVALID_ALPHA);
	blk3.alpha |= 0x0080;
      }
    }

    blk3.control &= 0xf7ff; /* Clear previous information */
    blk3.control |= (UInt16) ((image->outputDestination == icpPCI) ? 0x0800 : 0x0000);

    blk3.control &= 0xdfff;
    if (image->inFormat == vdfYUV420Planar)
        blk3.control |= 0x2000;
    else;

    blk3.heightOut = blk3.yHeightIn;
    blk3.widthOut = image->outputWidth;

    blk3.control &= 0xefff;
    if (image->overlayEnable)
        blk3.control |= 0x1000;

    blk3.control &= 0xfbff;
    if (image->bitMaskEnable)
        blk3.control |= 0x0400;

    err = TMLIBDEV_OK;
    if (image->outputDestination == icpPCI)
        err = icpEnableBIU();
    if (err != TMLIBDEV_OK)
        return (ICP_ERR_CANT_WRITE_TO_BIUCTRL);

    /*
     * Write parameter block back to memory param3 block size is 84
     * bytes.
     */

    _cache_copyback((UInt8 *) & blk3, sizeof(icpParamTableConvert_t));

    /*
     * Start ICP and return.
     */
    /* Load the ICP registers */
    icpSetReg(ICP_MPC, (UInt32) & aligned_ucode[3]);
    icpSetReg(ICP_DP, (UInt32) & blk3);
    icpStart();

    return (TMLIBDEV_OK);
}

/*****************************************************************************/

/*
 * Function     : icpGetCapabilities
 *            Return a pointer to the capabilities of the ICP.
 *            Please see the standard capabilities structure for details.
 * Parameters       : 1. Instance
 *            2. Pointer to icpCapabilities_t.
 * Function Result  : Return TMLIBDEV_OK on success.
 *
 */

tmLibdevErr_t 
icpGetCapabilities(picpCapabilities_t * icpCap)
{
    tmAssert(icpCap != NULL, TMLIBDEV_ERR_NULL_PARAMETER);
    *icpCap = &capabilities;
    return (TMLIBDEV_OK);

}

/*****************************************************************************/

/*
 * Function       : icpCheckFillParameters
 *                  Performs checking and fills the parameter table
 *                  structure for horizontal and vertical filters.
 *                  This is used for three functions.
 *                  1. icpMove
 *                  2. icpHorzFilter and
 *                  3. icpVertFilter,
 *                  since the parameter table expected by these filters
 *                  is identical.
 *                  Called internally by icpMove(), icpHorzFilter(), and
 *                  icpVertFilter().
 * Parameters      : 1. Instance
 *                   2. Pointer to icpImageHorzVert_t
 * Function Result : Return TMLIBDEV_OK on success.
 *                   ICP_ERR_DEVICE_IN_USE; Incorrect owner.
 *                   ICP_ERR_SETUP_REQUIRED; ICP has not been setup.
 *                                           Use icpSetup().
 *                   ICP_ERR_INVALID_HEIGHT; Source height <= 0.
 *                   ICP_ERR_INVALID_WIDTH;  Source width <=0.
 *                   ICP_ERR_INVALID_STRIDE; Source or destination stride <= 0.
 *                   ICP_ERR_ADDRESS_NOT_64_ALIGNED; Address pointer must be
 *                                         aligned at a 64 byte block boundary.
 *                   ICP_ERR_BUSY; Attempt to call icpMove while ICP is
 *                                            busy processing
 *
 */

tmLibdevErr_t 
icpCheckFillParameters(Int instance, icpImageHorzVert_t * image)
{
    /* Error processing */
    tmAssert(icp_instance == instance, TMLIBDEV_ERR_NOT_OWNER);

    tmAssert(!icpCheckBUSY(), ICP_ERR_BUSY);
    tmAssert(image->inputHeight > 0, ICP_ERR_INVALID_HEIGHT);
    tmAssert(image->inputWidth > 0, ICP_ERR_INVALID_WIDTH);

    /* Write to the parameter block */
    blk.image_in = (UInt32) image->imageBase;
    if (image->filterBypass)
        blk.control = 0x8000;
    else
        blk.control = 0x0000;

    blk.image_out     = (UInt32) image->outputImage;
    blk.lineOffset    = (UInt16) image->inputStride;
    blk.yCntStFrac    = (Int16) (image->outputPixelOffset * 65536);
    blk.widthIn       = (UInt16) image->inputWidth;
    blk.heightIn      = (UInt16) image->inputHeight;
    blk.lineOffsetOut = (UInt16) image->outputStride;
    blk.widthOut      = (UInt16) image->outputWidth;
    blk.heightOut     = (UInt16) image->outputHeight;

    return (TMLIBDEV_OK);

}

/*****************************************************************************/

/*
 * Function         : icpOverlaySetup
 *                    Sets up an overlay image. If an image overlay is desired
 *                    then icpSetupOverlay() must be called before calling the
 *                    icpColorConversion() routine and set the overlayEnable to
 *                    1. However, icpSetupOverlay() can be called anytime and
 *                    display of the overlay image can be suppressed by turning
 *                    off the OverlayFlag (=0).
 * Parameters       : 1. Instance
 *                    2. Pointer to icpSetupOverlay_t.
 * Function Result  : Return TMLIBDEV_OK on success
 *                    ICP_ERR_DEVICE_IN_USE; Incorrect instance
 *                    ICP_ERR_BUSY; ICP is still processing some previous job
 *                    ICP_ERR_SETUP_REQUIRED; ICP has not been setup
 *                    ICP_ERR_INVALID_START_VALUE; startCol or startRow 
 *                                                 is negative.
 *                    ICP_ERR_OVERLAY_MODE; Requested mode is not supported.
 */

tmLibdevErr_t 
icpOverlaySetup(Int instance, icpOverlaySetup_t * overlay)
{
    /*
     * Error processing
     */
    tmAssert(icp_instance == instance, TMLIBDEV_ERR_NOT_OWNER);
    tmAssert(icp_setup != Null, TMLIBDEV_ERR_NULL_PARAMETER);

    tmAssert(!icpCheckBUSY(), ICP_ERR_BUSY);
    tmAssert(overlay->startX >= 0, ICP_ERR_INVALID_START_VALUE);
    tmAssert(overlay->startY >= 0, ICP_ERR_INVALID_START_VALUE);
    tmAssert((overlay->overlayBase) && ((overlay->format == vdfRGB24Alpha)
          || (overlay->format == vdfRGB15Alpha) 
          || (overlay->format == vdfYUV422SequenceAlpha)), 
          ICP_ERR_INCORRECT_OVERLAY_TYPE);
    tmAssert(overlay->width >= 1, ICP_ERR_INVALID_WIDTH);
    tmAssert(overlay->height >= 1, ICP_ERR_INVALID_HEIGHT);
    

    overlay_used = 1;

    if (overlay->littleEndian == True) {
        if (overlay->format == vdfRGB24Alpha)
            blk3.control = 0x1100;  /* RGB 24+alpha */
        else if (overlay->format == vdfRGB15Alpha)
            blk3.control = 0x1140;  /* RGB 15+alpha */
        else if (overlay->format == vdfYUV422SequenceAlpha)
            blk3.control = 0x1180;  /* YUV 422 + alpha */
    }
    else {
        if (overlay->format == vdfRGB24Alpha)
            blk3.control = 0x1000;  /* RGB 24+Alpha */
        else if (overlay->format == vdfRGB15Alpha)
            blk3.control = 0x1040;  /* RGB 15+Alpha */
        else if (overlay->format == vdfYUV422SequenceAlpha)
            blk3.control = 0x1080;  /* YUV 422 + Alpha */
    }

    /* Fill up the parameter block */

    blk3.rgbAddress = (UInt32) overlay->overlayBase;
    blk3.rgbLineOffset = (UInt16) overlay->stride;
    blk3.overStartPix = (UInt16) overlay->startX;
    blk3.overEndPix = (UInt16) (overlay->startX + overlay->width - 1);
    blk3.overStartLine = (UInt16) overlay->startY;
    blk3.overEndLine = (UInt16) (overlay->startY + overlay->height - 1);

    return (TMLIBDEV_OK);

}               /* icpOverlaySetup */

/*****************************************************************************/
/*
 * Function         : icpBitMaskSetup
 *                    Sets up a bitmask image. If an image bitmask is desired
 *                    then icpSetupBitMask() must be called before calling the
 *                    icpColorConversion() routine and set the bitmaskEnable to
 *                    1. However, icpSetupBitMask() can be called anytime and
 *                    display of the bitmask image can be suppressed by turning
 *                    off the bitmask flag (=0).
 * Parameters       : 1. Instance
 *                    2. Pointer to icpSetupBitMask_t.
 * Function Result  : Return TMLIBDEV_OK on success
 *                    ICP_ERR_DEVICE_IN_USE; Incorrect instance
 *                    ICP_ERR_BUSY; ICP is still processing some previous job
 *                    ICP_ERR_SETUP_REQUIRED; ICP has not been setup
 */

tmLibdevErr_t 
icpBitMaskSetup(Int instance, icpBitMaskSetup_t * bitmask)
{
    /*
     * Error processing
     */
    tmAssert(icp_instance == instance, TMLIBDEV_ERR_NOT_OWNER);
    tmAssert(bitmask != Null, TMLIBDEV_ERR_NULL_PARAMETER);
    tmAssert(!icpCheckBUSY(), ICP_ERR_BUSY);

    bitmask_used = 1;

    /* Fill up the parameter block */

    blk3.bmpAddress = (UInt32) bitmask->bitMaskBase;
    blk3.bmpLineOffset = (UInt16) bitmask->stride;

    return (TMLIBDEV_OK);

}               /* end icpBitMaskSetup */


/*****************************************************************************/









⌨️ 快捷键说明

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