pximage.cpp
来自「symbian 下的helix player源代码」· C++ 代码 · 共 1,933 行 · 第 1/5 页
CPP
1,933 行
return retVal;
}
HX_RESULT PXImage::IntraCopy(const PXRect& rSrcRect, const PXRect& rDstRect)
{
HX_RESULT retVal = HXR_OK;
if (rSrcRect.GetWidth() == rDstRect.GetWidth() &&
rSrcRect.GetHeight() == rDstRect.GetHeight() &&
rSrcRect.GetWidth() <= (UINT32) m_lSubImageWidth &&
rSrcRect.GetHeight() <= (UINT32) m_lSubImageHeight &&
rSrcRect.GetX() + rSrcRect.GetWidth() <= (UINT32) m_lSubImageWidth &&
rSrcRect.GetY() + rSrcRect.GetHeight() <= (UINT32) m_lSubImageHeight &&
rDstRect.GetX() + rDstRect.GetWidth() <= (UINT32) m_lSubImageWidth &&
rDstRect.GetY() + rDstRect.GetHeight() <= (UINT32) m_lSubImageHeight)
{
// Make sure this is not a null copy
if (rSrcRect.GetX() != rDstRect.GetX() ||
rSrcRect.GetY() != rDstRect.GetY())
{
BOOL bUpCopy = (rDstRect.GetY() <= rSrcRect.GetY() ? TRUE : FALSE);
// if (m_bRowsInverted)
// {
// // If we are row-inverted, then we reverse whatever, operation
// // we were going to do.
// bUpCopy = (bUpCopy ? FALSE : TRUE);
// }
if (rDstRect.GetX() <= rSrcRect.GetX())
{
// This is a left-ward copy
if (bUpCopy)
{
// This is an up-left copy, so we do L->R, T->B
UINT32* pSrcRow = (UINT32*) GetPixel(rSrcRect.GetX(), rSrcRect.GetY());
UINT32* pDstRow = (UINT32*) GetPixel(rDstRect.GetX(), 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-left copy, so we do L->R, B->T
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 lSr
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?