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

📄 pximage.cpp

📁 linux下的一款播放器
💻 CPP
📖 第 1 页 / 共 5 页
字号:
                    UINT32* pSrcRow = (UINT32*) GetPixel(rSrcRect.GetX(), rSrcRect.GetY() + rSrcRect.GetHeight() - 1);                    UINT32* pDstRow = (UINT32*) GetPixel(rDstRect.GetX(), rDstRect.GetY() + rDstRect.GetHeight() - 1);                    INT32   lJump   = m_lRowJump >> 2;                    for (UINT32 ulY = rSrcRect.GetHeight(); ulY; ulY--)                    {                        UINT32* pSrcPixel = pSrcRow;                        UINT32* pDstPixel = pDstRow;                        for (UINT32 ulX = rSrcRect.GetWidth(); ulX; ulX--)                        {                            *pDstPixel++ = *pSrcPixel++;                        }                        pSrcRow -= lJump;                        pDstRow -= lJump;                    }                }            }            else            {                // This is a right-ward copy                if (bUpCopy)                {                    // This is an up-right copy, so we do R->L, T->B                    UINT32* pSrcRow = (UINT32*) GetPixel(rSrcRect.GetX() + rSrcRect.GetWidth() - 1, rSrcRect.GetY());                    UINT32* pDstRow = (UINT32*) GetPixel(rDstRect.GetX() + rDstRect.GetWidth() - 1, rDstRect.GetY());                    INT32   lJump   = m_lRowJump >> 2;                    for (UINT32 ulY = rSrcRect.GetHeight(); ulY; ulY--)                    {                        UINT32* pSrcPixel = pSrcRow;                        UINT32* pDstPixel = pDstRow;                        for (UINT32 ulX = rSrcRect.GetWidth(); ulX; ulX--)                        {                            *pDstPixel-- = *pSrcPixel--;                        }                        pSrcRow += lJump;                        pDstRow += lJump;                    }                }                else                {                    // This is a down-right copy, so we do R->L, B->T                    UINT32* pSrcRow = (UINT32*) GetPixel(rSrcRect.GetX() + rSrcRect.GetWidth()  - 1,                                                         rSrcRect.GetY() + rSrcRect.GetHeight() - 1);                    UINT32* pDstRow = (UINT32*) GetPixel(rDstRect.GetX() + rDstRect.GetWidth()  - 1,                                                         rDstRect.GetY() + rDstRect.GetHeight() - 1);                    INT32   lJump   = m_lRowJump >> 2;                    for (UINT32 ulY = rSrcRect.GetHeight(); ulY; ulY--)                    {                        UINT32* pSrcPixel = pSrcRow;                        UINT32* pDstPixel = pDstRow;                        for (UINT32 ulX = rSrcRect.GetWidth(); ulX; ulX--)                        {                            *pDstPixel-- = *pSrcPixel--;                        }                        pSrcRow -= lJump;                        pDstRow -= lJump;                    }                }            }        }    }    else    {        retVal = HXR_INVALID_PARAMETER;    }    return retVal;}HX_RESULT PXImage::DrawToHXSurface(IHXVideoSurface* pSurface, HXxRect& rDstRect){    if (!m_bInitialized || !pSurface)    {        HX_ASSERT(FALSE);        return HXR_FAIL;    }    // If the image has alpha, then we need to    // blt a different colorspace    UINT32 ulFormat = m_cBitmapInfo.biCompression;    if (m_bHasAlpha)    {        m_cBitmapInfo.biCompression = HX_ARGB;    }    // Do the blt    pSurface->AddRef();    HX_RESULT retVal = pSurface->Blt(m_pImageStore->GetBuffer(), &m_cBitmapInfo, rDstRect, m_cSubImageRect);    pSurface->Release();    // Restore the old colorspace    if (m_bHasAlpha)    {        m_cBitmapInfo.biCompression = ulFormat;    }    return retVal;}HX_RESULT PXImage::DrawToHXSurface(IHXVideoSurface* pSurface, HXxRect& rSrcRect, HXxRect& rDstRect){    HX_RESULT retVal = HXR_OK;    if (pSurface)    {        if (m_bInitialized)        {            // If the image has alpha, then we need to            // blt a different colorspace            UINT32 ulFormat = m_cBitmapInfo.biCompression;            if (m_bHasAlpha)            {                m_cBitmapInfo.biCompression = HX_ARGB;            }            // Do the blt            pSurface->AddRef();            retVal = pSurface->Blt(m_pImageStore->GetBuffer(), &m_cBitmapInfo, rDstRect, rSrcRect);            pSurface->Release();            // Restore the old colorspace            if (m_bHasAlpha)            {                m_cBitmapInfo.biCompression = ulFormat;            }        }        else        {            retVal = HXR_UNEXPECTED;        }    }    else    {        retVal = HXR_INVALID_PARAMETER;    }    return retVal;}HX_RESULT PXImage::GetPixel(INT32 lX, INT32 lY, BYTE** ppPixel){    *ppPixel = GetPixel(lX, lY);    return (*ppPixel ? HXR_OK : HXR_FAIL);}BYTE* PXImage::GetPixel(INT32 lX, INT32 lY){    BYTE* pRet = NULL;    if (m_bInitialized)    {        if (lX >= 0 && lX < m_lSubImageWidth &&            lY >= 0 && lY < m_lSubImageHeight)        {            pRet = m_pImageBuffer + lY * m_lRowJump + lX * m_ulBytesPerPixel;        }    }    return pRet;}HX_RESULT PXImage::GetImageStore(IHXBuffer** ppBuffer){    HX_RESULT retVal = HXR_OK;    if (ppBuffer && m_bInitialized)    {        m_pImageStore->AddRef();        *ppBuffer = m_pImageStore;    }    else    {        retVal = HXR_FAIL;    }    return retVal;}void PXImage::ConvertToRGBOrder(INT32 lScanline, BYTE* pLine){    if (lScanline >= 0 && lScanline < m_lSubImageHeight)    {        UINT32* pPixel = (UINT32*) GetPixel(0, lScanline);        for (INT32 lX = m_lSubImageWidth; lX; lX--)        {            UINT32 ulPixel = *pPixel++;            *pLine++ = (BYTE) ((ulPixel & 0x00FF0000) >> 16); // R            *pLine++ = (BYTE) ((ulPixel & 0x0000FF00) >>  8); // G            *pLine++ = (BYTE)  (ulPixel & 0x000000FF);        // B        }    }}void PXImage::ConvertFromRGBOrder(INT32 lScanline, BYTE* pLine){    if (lScanline >= 0 && lScanline < m_lSubImageHeight)    {        UINT32* pPixel = (UINT32*) GetPixel(0, lScanline);        for (INT32 lX = m_lSubImageWidth; lX; lX--)        {            UINT32 ulRed   = *pLine++;            UINT32 ulGreen = *pLine++;            UINT32 ulBlue  = *pLine++;            *pPixel++      = (ulRed << 16) | (ulGreen << 8) | ulBlue;        }    }}void PXImage::GetSubRect(PXRect& rRect) const{    rRect.Set(m_cSubImageRect.left,              m_cSubImageRect.top,              HXxRECT_WIDTH(m_cSubImageRect),              HXxRECT_HEIGHT(m_cSubImageRect));}BOOL PXImage::SameSize(PXImage* pImg) const{    if (pImg                                         &&        m_lSubImageWidth  == pImg->m_lSubImageWidth  &&        m_lSubImageHeight == pImg->m_lSubImageHeight)    {        return TRUE;    }    else    {        return FALSE;    }}BOOL PXImage::Compatible(PXImage* pImg) const{    if (pImg                                                          &&        m_cBitmapInfo.biBitCount    == pImg->m_cBitmapInfo.biBitCount &&        m_cBitmapInfo.biCompression == pImg->m_cBitmapInfo.biCompression)    {        return TRUE;    }    else    {        return FALSE;    }}void PXImage::Copy32(UINT32* pSrc, UINT32* pDst, INT32 lSrcJump, INT32 lDstJump, BOOL bUseAlpha){    for (INT32 lY = m_lSubImageHeight; lY; lY--)    {        UINT32* pSrcPix = pSrc;        UINT32* pDstPix = pDst;        if (bUseAlpha)        {            for (INT32 lX = m_lSubImageWidth; lX; lX--)            {                UINT32 ulA = GETALPHA32(*pSrcPix);                ulA        = (ulA < 128 ? ulA : ulA + 1);                *pDstPix   = MAKE_RGB32(ALPHABLEND(GETRED32(*pDstPix),   GETRED32(*pSrcPix),   ulA),                                        ALPHABLEND(GETGREEN32(*pDstPix), GETGREEN32(*pSrcPix), ulA),                                        ALPHABLEND(GETBLUE32(*pDstPix),  GETBLUE32(*pSrcPix),  ulA));                pSrcPix++;                pDstPix++;            }        }        else        {            for (INT32 lX = m_lSubImageWidth; lX; lX--)            {                *pDstPix++ = *pSrcPix++;            }        }        pSrc += lSrcJump;        pDst += lDstJump;    }}void PXImage::CopyTransparent32(UINT32* pSrc, UINT32* pDst, INT32 lSrcJump, INT32 lDstJump){    for (INT32 lY = m_lSubImageHeight; lY; lY--)    {        UINT32* pSrcPix = pSrc;        UINT32* pDstPix = pDst;        for (INT32 lX = m_lSubImageWidth; lX; lX--)        {            if (!(*pSrcPix & 0xFF000000))            {                *pDstPix = *pSrcPix;            }            pSrcPix++;            pDstPix++;        }        pSrc += lSrcJump;        pDst += lDstJump;    }}void PXImage::CopyAlpha32(UINT32* pSrc, UINT32* pDst, INT32 lSrcJump, INT32 lDstJump, BYTE* pLUT){    if (pLUT)    {        for (INT32 lY = m_lSubImageHeight; lY; lY--)        {            UINT32* pSrcPix = pSrc;            UINT32* pDstPix = pDst;            for (INT32 lX = m_lSubImageWidth; lX; lX--)            {                UINT32 ulAlpha = GETALPHA32(*pSrcPix);                BYTE*  pAlp    = &pLUT[ulAlpha << 8];                BYTE*  pInv    = &pLUT[(255 - ulAlpha) << 8];                *pDstPix       = MAKE_RGB32(pAlp[GETRED32(*pDstPix)]   + pInv[GETRED32(*pSrcPix)],                                            pAlp[GETGREEN32(*pDstPix)] + pInv[GETGREEN32(*pSrcPix)],                                            pAlp[GETBLUE32(*pDstPix)]  + pInv[GETBLUE32(*pSrcPix)]);                pSrcPix++;                pDstPix++;            }            pSrc += lSrcJump;            pDst += lDstJump;        }    }    else    {        for (INT32 lY = m_lSubImageHeight; lY; lY--)        {            UINT32* pSrcPix = pSrc;            UINT32* pDstPix = pDst;            for (INT32 lX = m_lSubImageWidth; lX; lX--)            {                UINT32 ulAlpha = GETALPHA32(*pSrcPix);                *pDstPix       = MAKE_RGB32(BLENDMULT(GETRED32(*pDstPix),   GETRED32(*pSrcPix),   ulAlpha),                                            BLENDMULT(GETGREEN32(*pDstPix), GETGREEN32(*pSrcPix), ulAlpha),                                            BLENDMULT(GETBLUE32(*pDstPix),  GETBLUE32(*pSrcPix),  ulAlpha));                pSrcPix++;                pDstPix++;            }            pSrc += lSrcJump;            pDst += lDstJump;        }    }}HX_RESULT PXImage::ChangeSize32NN(UINT32* pSrc, INT32 lSrcW, INT32 lSrcH, INT32 lSrcJump,                                  UINT32* pDst, INT32 lDstW, INT32 lDstH, INT32 lDstJump){    // Allocate the divide LUT    INT32* pSrcX = new INT32 [lDstW];    if (!pSrcX)    {        return HXR_OUTOFMEMORY;    }    // Build the divide LUT    INT32 lDstX;    INT32 lDstWDiv2 = lDstW >> 1;    for (lDstX = 0; lDstX < lDstW; lDstX++)    {        INT32 lSrcX = (lDstX * lSrcW + lDstWDiv2) / lDstW;        if (lSrcX >= lSrcW)        {            lSrcX = lSrcW - 1;        }        pSrcX[lDstX] = lSrcX;    }    // Now run through the output image, doing nearest neighbor resampling    INT32   lSrcY     = 0;    INT32   lDstY     = 0;    INT32   lLastSrcY = -1;    UINT32* pDstRow   = pDst;    INT32   lDstHDiv2 = lDstH >> 1;    for (lDstY = 0; lDstY < lDstH; lDstY++)    {        lSrcY = (lDstY * lSrcH + lDstHDiv2) / lDstH;        if (lSrcY >= lSrcH)        {            lSrcY = lSrcH - 1;        }        UINT32* pSrcRow = pSrc + lSrcY * lSrcJump;        if (lSrcY == lLastSrcY)        {            // We're getting this resampled row from the same source row,            // so just copy the last row.            UINT32* pDstLastRow = pDstRow - lDstJump;            for (lDstX = 0; lDstX < lDstW; lDstX++)            {                pDstRow[lDstX] = pDstLastRow[lDstX];            }        }        else        {            // New row, we must do the work            for (lDstX = 0; lDstX < lDstW; lDstX++)            {                pDstRow[lDstX] = pSrcRow[pSrcX[lDstX]];            }        }        lLastSrcY = lSrcY;        pDstRow  += lDstJump;    }    HX_VECTOR_DELETE(pSrcX);    return HXR_OK;}HX_RESULT PXImage::ChangeSize32NNTransparent(UINT32* pSrc, INT32 lSrcW, INT32 lSrcH, INT32 lSrcJump,                                             UINT32* pDst, INT32 lDstW, INT32 lDstH, INT32 lDstJump){    // Allocate the divide LU

⌨️ 快捷键说明

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