Redesigned work with the alpha mask

This commit is contained in:
Kirill Polyakov
2023-12-04 19:37:38 +03:00
parent 09ab798f0d
commit a0d3d402a3
13 changed files with 188 additions and 467 deletions

View File

@ -22,6 +22,7 @@ namespace Aggplus
BYTE* GetBuffer();
void SetDefaultSettings();
void ClearBuffer(bool bDeleteData = true);
void SetSettings(const TGraphicsLayerSettings& oSettings);
const TGraphicsLayerSettings& GetSettings() const;
@ -31,7 +32,7 @@ namespace Aggplus
template <class SrcPixelFormatRenderer>
void BlendTo(SrcPixelFormatRenderer& oSrc)
{
if (NULL == m_pBuffer)
if (NULL == m_pBuffer || 0 == oSrc.width() || 0 == oSrc.height())
return;
typedef typename SrcPixelFormatRenderer::order_type order_type;
@ -71,6 +72,40 @@ namespace Aggplus
}
}
}
template <class AlphaMaskFunction, class SrcPixelFormatRenderer>
void BlendTo(SrcPixelFormatRenderer& oSrc, BYTE* pAlphaMaskBuffer, UINT unAlphaMaskStep)
{
if (NULL == m_pBuffer || 0 == oSrc.width() || 0 == oSrc.height())
return;
typedef typename SrcPixelFormatRenderer::order_type order_type;
typedef typename SrcPixelFormatRenderer::value_type value_type;
int nStep = 4;
BYTE* pSrcBuffer = m_pBuffer;
value_type* pDstBuffer = NULL;
BYTE* pSrcAlphaMaskBuffer = pAlphaMaskBuffer;
unsigned int unSrcW = oSrc.width();
unsigned int unSrcH = oSrc.height();
for (unsigned int unY = 0; unY < unSrcH; ++unY)
{
pDstBuffer = oSrc.row_ptr(unY);
for (unsigned int unX = 0; unX < unSrcW; ++unX)
{
pDstBuffer[order_type::R] = pSrcBuffer[order_type::R];
pDstBuffer[order_type::G] = pSrcBuffer[order_type::G];
pDstBuffer[order_type::B] = pSrcBuffer[order_type::B];
pDstBuffer[order_type::A] = ((SrcPixelFormatRenderer::base_mask + (value_type)m_oSettings.m_dOpacity * pSrcBuffer[order_type::A] * AlphaMaskFunction::calculate(pSrcAlphaMaskBuffer)) >> 8);;
pSrcBuffer += nStep;
pDstBuffer += nStep;
pSrcAlphaMaskBuffer += unAlphaMaskStep;
}
}
}
private:
BYTE* m_pBuffer;
bool m_bExternalBuffer;