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

📄 gdi_drv.cpp

📁 audio-video-codecs.rar语音编解码器
💻 CPP
📖 第 1 页 / 共 2 页
字号:
            dst.right  += point.x;
            dst.top    += point.y;
            dst.bottom += point.y;
        }
        if (!(drv->win_full_screen))
        {
            dst.left    = static_cast<Ipp16s>(dst.left   - point.x);
            dst.right   = static_cast<Ipp16s>(dst.right  - point.x);
            dst.top     = static_cast<Ipp16s>(dst.top    - point.y);
            dst.bottom  = static_cast<Ipp16s>(dst.bottom - point.y);
        }
        BITMAPINFOHEADER    BmpHdr  = {0};
        BmpHdr.biSize       = sizeof(BmpHdr);
        BmpHdr.biWidth      = driver->img_width;
        if (drv->gdi_in_color_format != drv->gdi_out_color_format)
            BmpHdr.biHeight     = -((Ipp32s) driver->img_height);
        else
            BmpHdr.biHeight     = ((Ipp32s) driver->img_height);
        BmpHdr.biPlanes     = 1;
        BmpHdr.biBitCount   = static_cast<Ipp16u>(drv->gdi_bpp_DC << 3);
        BmpHdr.biCompression = BI_RGB;

        iRes = ::StretchDIBits(
            hDC,                    // handle to DC
            dst.left,               // x-coord of destination upper-left corner
            dst.top,                // y-coord of destination upper-left corner
            dst.right  - dst.left,  // width of destination rectangle
            dst.bottom - dst.top,   // height of destination rectangle
            0,                      // x-coord of source upper-left corner
            0,                      // y-coord of source upper-left corner
            driver->img_width,      // width of source rectangle
            driver->img_height,     // height of source rectangle
            frame,                  // bitmap bits
            (BITMAPINFO*)&BmpHdr,   // bitmap data
            DIB_RGB_COLORS,         // usage options
            SRCCOPY                 // raster operation code
            );
        if (GDI_ERROR == iRes)
        {
            ERR_SET(VM_OPERATION_FAILED, "StretchDIBits");
        }
    }
    if (VM_OK == result)
    {
        if (1 != ::ReleaseDC(drv->win, hDC))
        {
            ERR_SET(VM_OPERATION_FAILED, "ReleaseDC");
        }
    }
    DBG_SET("-");
    return result;
}

/* -------------------------------------------------------------------------- */

/* void* */
VIDEO_DRV_GET_WINDOW_FUNC(umc_gdi_GetWindow, driver)
{
#undef  FUNCTION
#define FUNCTION "umc_gdi_GetWindow"
    void*   win;
    GDIDrv*  drv = (GDIDrv*)((NULL != driver)? driver->m_pDrv: NULL);

    DBG_SET("+");
    if (NULL == drv)
    {
        win = NULL;
        DBG_SET("null ptr");
    }
    else
    {
        win = drv->win;
    }
    DBG_SET("-");
    return win;
}

/* -------------------------------------------------------------------------- */

// define internal type(s)
struct YUY2QUAD
{
  Ipp8u Y1;
  Ipp8u V;
  Ipp8u Y2;
  Ipp8u U;
};

struct RGB24T
{
    Ipp8u rgbRed;
    Ipp8u rgbGreen;
    Ipp8u rgbBlue;
};

inline Ipp8u umc_gdi_Saturate(Ipp32s iY, Ipp32s iC)
{
    iC = (iY + iC) >> 4;
    iC = IPP_MIN(255, IPP_MAX(0, iC));

    return static_cast<Ipp8u>(iC);

}

inline void umc_gdi_CookUXV(Ipp32s U, Ipp32s V, Ipp32s& iU, Ipp32s& iV, Ipp32s& iG)
{
    iU = (U - 128) << 7;
    iV = (V - 128) << 7;
    iG = ((0x1A04 * iU) >> 16) + ((0x0C8B * iV) >> 16);
    iU = (0x3312 * iU) >> 16;
    iV = (0x408b * iV) >> 16;
}

void umc_gdi_YUY2_to_RGB32(Ipp8u *pucSrc, Ipp8u *pucDst,
                           Ipp32u uiWidth,Ipp32u uiHeight)
{
#undef  FUNCTION
#define FUNCTION "umc_gdi_YUY2_to_RGB32"
    DBG_SET("+");
    YUY2QUAD*   pYUV = (YUY2QUAD *)pucSrc;
    RGBQUAD*    pRGB = (RGBQUAD *)pucDst;

    for (Ipp32u i = 0; i < uiWidth * uiHeight; i += 2)
    {
        YUY2QUAD YUV = pYUV[i >> 1];

        register Ipp32s iU;
        register Ipp32s iV;
        register Ipp32s iG;
        umc_gdi_CookUXV(YUV.U, YUV.V, iU, iV, iG);

        register Ipp32s iY = YUV.Y1 - 16;
        iY = ((iY << 7) * 0x253f) >> 16;
        pRGB[i].rgbRed      = umc_gdi_Saturate(iY, iU);
        pRGB[i].rgbGreen    = umc_gdi_Saturate(iY, -iG);
        pRGB[i].rgbBlue     = umc_gdi_Saturate(iY, iV);

        iY = YUV.Y2 - 16;
        iY = ((iY << 7) * 0x253f) >> 16;
        pRGB[i+1].rgbRed    = umc_gdi_Saturate(iY, iU);
        pRGB[i+1].rgbGreen  = umc_gdi_Saturate(iY, -iG);
        pRGB[i+1].rgbBlue   = umc_gdi_Saturate(iY, iV);
    }
    DBG_SET("-");
}

void umc_gdi_YUY2_to_RGB24(Ipp8u *pucSrc,
                           Ipp8u *pucDst,
                           Ipp32u uiWidth,
                           Ipp32u uiHeight)
{
#undef  FUNCTION
#define FUNCTION "umc_gdi_YUY2_to_RGB24"
    DBG_SET("+");
    YUY2QUAD *pYUV = (YUY2QUAD *)pucSrc;
    RGB24T *pRGB = (RGB24T *)pucDst;

    for (Ipp32u i = 0; i < uiWidth * uiHeight; i += 2)
    {
        YUY2QUAD YUV = pYUV[i >> 1];

        register Ipp32s iU;
        register Ipp32s iV;
        register Ipp32s iG;
        umc_gdi_CookUXV(YUV.U, YUV.V, iU, iV, iG);

        register Ipp32s iY = YUV.Y1 - 16;
        iY = ((iY << 7) * 0x253f) >> 16;
        pRGB[i].rgbRed      = umc_gdi_Saturate(iY, iU);
        pRGB[i].rgbGreen    = umc_gdi_Saturate(iY, -iG);
        pRGB[i].rgbBlue     = umc_gdi_Saturate(iY, iV);

        iY = YUV.Y2 - 16;
        iY = ((iY << 7) * 0x253f) >> 16;
        pRGB[i+1].rgbRed    = umc_gdi_Saturate(iY, iU);
        pRGB[i+1].rgbGreen  = umc_gdi_Saturate(iY, -iG);
        pRGB[i+1].rgbBlue   = umc_gdi_Saturate(iY, iV);
    }
    DBG_SET("-");
}

void umc_gdi_YUY2_to_RGB555(Ipp8u *pucSrc,
                            Ipp8u *pucDst,
                            Ipp32u uiWidth,
                            Ipp32u uiHeight)
{
#undef  FUNCTION
#define FUNCTION "umc_gdi_YUY2_to_RGB555"
    DBG_SET("+");
    YUY2QUAD *pYUV = (YUY2QUAD *)pucSrc;
    Ipp16u *pRGB = (Ipp16u *)pucDst;

    for (Ipp32u i = 0; i < uiWidth * uiHeight; i += 2)
    {
        YUY2QUAD YUV = pYUV[i >> 1];

        register Ipp32s iU;
        register Ipp32s iV;
        register Ipp32s iG;
        umc_gdi_CookUXV(YUV.U, YUV.V, iU, iV, iG);

        register Ipp32s iY = YUV.Y1 - 16;
        iY = ((iY << 7) * 0x253f) >> 16;
        pRGB[i] = static_cast<Ipp16u>((umc_gdi_Saturate(iY, iV) >> 3) |
                                     ((umc_gdi_Saturate(iY, -iG) >> 3) << 5) |
                                     ((umc_gdi_Saturate(iY, iU) >> 3) << 10));

        iY = YUV.Y2 - 16;
        iY = ((iY << 7) * 0x253f) >> 16;
        pRGB[i+1] = static_cast<Ipp16u> ((umc_gdi_Saturate(iY, iV) >> 3) |
                                        ((umc_gdi_Saturate(iY, -iG) >> 3) << 5) |
                                        ((umc_gdi_Saturate(iY, iU) >> 3) << 10));
    }
    DBG_SET("-");
}

inline void umc_gdi_PutYUV2RGB32(Ipp8u* pY,
                                 Ipp32s iU, Ipp32s iV, Ipp32s iG,
                                 RGBQUAD* pRGB,
                                 Ipp32u uiLpos)
{
    register Ipp32s iY = pY[uiLpos] - 16;

    iY = ((iY << 7) * 0x253f) >> 16;
    pRGB[uiLpos].rgbRed     = umc_gdi_Saturate(iY, iU);
    pRGB[uiLpos].rgbBlue    = umc_gdi_Saturate(iY, iV);
    pRGB[uiLpos].rgbGreen   = umc_gdi_Saturate(iY, -iG);
    pRGB[uiLpos].rgbReserved = 0;

}

void umc_gdi_YV12_to_RGB32(Ipp8u* pucSrc, Ipp8u* pucDst,
                           Ipp32u uiWidth,Ipp32u uiHeight)
{
#undef  FUNCTION
#define FUNCTION "umc_gdi_YV12_to_RGB32"
    DBG_SET("+");
    Ipp8u* pY = pucSrc;
    Ipp8u* pU = pucSrc + uiWidth * uiHeight;
    Ipp8u* pV = pU + uiWidth * uiHeight / 4;
    RGBQUAD* pRGB = (RGBQUAD*)pucDst;

    for (Ipp32u y = 0; y < uiHeight / 2; y++)
    {
        Ipp32u uiLPos1 = 2 * y * uiWidth;
        Ipp32u uiLPos2 = uiLPos1 + uiWidth;
        for (Ipp32u x = 0; x < uiWidth / 2; x++)
        {
            Ipp32u uiCPos = y * uiWidth / 2 + x; // Chroma pos in buffer

            register Ipp32s iU;
            register Ipp32s iV;
            register Ipp32s iG;
            umc_gdi_CookUXV(pU[uiCPos], pV[uiCPos], iU, iV, iG);

            umc_gdi_PutYUV2RGB32(pY, iU, iV, iG, pRGB, uiLPos1++);
            umc_gdi_PutYUV2RGB32(pY, iU, iV, iG, pRGB, uiLPos1++);
            umc_gdi_PutYUV2RGB32(pY, iU, iV, iG, pRGB, uiLPos2++);
            umc_gdi_PutYUV2RGB32(pY, iU, iV, iG, pRGB, uiLPos2++);
        }
    }
    DBG_SET("-");
}

inline void umc_gdi_PutYUV2RGB24(Ipp8u* pY,
                         Ipp32s iU, Ipp32s iV, Ipp32s iG,
                         RGB24T* pRGB,
                         Ipp32u uiLpos)
{
    register Ipp32s iY = pY[uiLpos] - 16;

    iY = ((iY << 7) * 0x253f) >> 16;
    pRGB[uiLpos].rgbRed     = umc_gdi_Saturate(iY, iU);
    pRGB[uiLpos].rgbBlue    = umc_gdi_Saturate(iY, iV);
    pRGB[uiLpos].rgbGreen   = umc_gdi_Saturate(iY, -iG);

}

void umc_gdi_YV12_to_RGB24(Ipp8u* pucSrc, Ipp8u* pucDst,
                           Ipp32u uiWidth,Ipp32u uiHeight)
{
#undef  FUNCTION
#define FUNCTION "umc_gdi_YV12_to_RGB24"
    DBG_SET("+");
    Ipp8u* pY = pucSrc;
    Ipp8u* pU = pucSrc + uiWidth * uiHeight;
    Ipp8u* pV = pU + uiWidth * uiHeight / 4;
    RGB24T* pRGB = (RGB24T*)pucDst;

    for (Ipp32u y = 0; y < uiHeight / 2; y++)
    {
        for (Ipp32u x = 0; x < uiWidth / 2; x++)
        {
            Ipp32u uiCPos = y * uiWidth / 2 + x; // Chroma pos in buffer
            Ipp32u uiLpos = y * 2 * uiWidth + 2 * x; // Luma pos in buffer

            register Ipp32s iU;
            register Ipp32s iV;
            register Ipp32s iG;
            umc_gdi_CookUXV(pU[uiCPos], pV[uiCPos], iU, iV, iG);

            umc_gdi_PutYUV2RGB24(pY, iU, iV, iG, pRGB, uiLpos);
            uiLpos++;
            umc_gdi_PutYUV2RGB24(pY, iU, iV, iG, pRGB, uiLpos);
            uiLpos += uiWidth - 1;
            umc_gdi_PutYUV2RGB24(pY, iU, iV, iG, pRGB, uiLpos);
            uiLpos++;
            umc_gdi_PutYUV2RGB24(pY, iU, iV, iG, pRGB, uiLpos);
        }
    }
    DBG_SET("-");
}

inline void umc_gdi_PutYUV2RGB555(Ipp8u* pY,
                                  Ipp32s iU, Ipp32s iV, Ipp32s iG,
                                  Ipp16u* pRGB,
                                  Ipp32u uiLpos)
{
    register Ipp32s iY = pY[uiLpos] - 16;

    iY = ((iY << 7) * 0x253f) >> 16;
    pRGB[uiLpos] = static_cast<Ipp16u>((umc_gdi_Saturate(iY, iV) >> 3) |
                                      ((umc_gdi_Saturate(iY, -iG) >> 3) << 5) |
                                      ((umc_gdi_Saturate(iY, iU) >> 3) << 10));

}

void umc_gdi_YV12_to_RGB555(Ipp8u* pucSrc, Ipp8u* pucDst,
                            Ipp32u uiWidth,Ipp32u uiHeight)
{
#undef  FUNCTION
#define FUNCTION "umc_gdi_YV12_to_RGB555"
    DBG_SET("+");
    Ipp8u* pY = pucSrc;
    Ipp8u* pU = pucSrc + uiWidth * uiHeight;
    Ipp8u* pV = pU + uiWidth * uiHeight / 4;
    Ipp16u* pRGB = (Ipp16u*)pucDst;

    for (Ipp32u y = 0; y < uiHeight / 2; y++)
    {
        for (Ipp32u x = 0; x < uiWidth / 2; x++)
        {
            Ipp32u uiCPos = y * uiWidth / 2 + x; // Chroma pos in buffer
            Ipp32u uiLpos = y * 2 * uiWidth + 2 * x; // Luma pos in buffer

            register Ipp32s iU;
            register Ipp32s iV;
            register Ipp32s iG;
            umc_gdi_CookUXV(pU[uiCPos], pV[uiCPos], iU, iV, iG);

            umc_gdi_PutYUV2RGB555(pY, iU, iV, iG, pRGB, uiLpos);
            uiLpos++;
            umc_gdi_PutYUV2RGB555(pY, iU, iV, iG, pRGB, uiLpos);
            uiLpos += uiWidth - 1;
            umc_gdi_PutYUV2RGB555(pY, iU, iV, iG, pRGB, uiLpos);
            uiLpos++;
            umc_gdi_PutYUV2RGB555(pY, iU, iV, iG, pRGB, uiLpos);
        }
    }
    DBG_SET("-");
}

#endif // defined(UMC_ENABLE_GDI_VIDEO_RENDER)

⌨️ 快捷键说明

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