move pixel color extracting from canvas to BitmapEx
part of making GetAlpha/GetMask an internal detail of vcl Change-Id: I874a68f340cd3074cfbeb6303f52adeeb13e56a5 Reviewed-on: https://gerrit.libreoffice.org/51435 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
This commit is contained in:
@@ -194,28 +194,14 @@ namespace vclcanvas
|
|||||||
ENSURE_ARG_OR_THROW( pos.Y >= 0 && pos.Y < aBmpSize.Height(),
|
ENSURE_ARG_OR_THROW( pos.Y >= 0 && pos.Y < aBmpSize.Height(),
|
||||||
"Y coordinate out of bounds" );
|
"Y coordinate out of bounds" );
|
||||||
|
|
||||||
Bitmap aBitmap( mpBackBuffer->getBitmapReference().GetBitmap() );
|
::Color aColor = mpBackBuffer->getBitmapReference().GetPixelColor(pos.X, pos.Y);
|
||||||
Bitmap aAlpha( mpBackBuffer->getBitmapReference().GetAlpha().GetBitmap() );
|
|
||||||
|
|
||||||
Bitmap::ScopedReadAccess pReadAccess( aBitmap );
|
|
||||||
Bitmap::ScopedReadAccess pAlphaReadAccess( aAlpha.IsEmpty() ?
|
|
||||||
nullptr : aAlpha.AcquireReadAccess(),
|
|
||||||
aAlpha );
|
|
||||||
ENSURE_OR_THROW( pReadAccess.get() != nullptr,
|
|
||||||
"Could not acquire read access to bitmap" );
|
|
||||||
|
|
||||||
uno::Sequence< sal_Int8 > aRes( 4 );
|
uno::Sequence< sal_Int8 > aRes( 4 );
|
||||||
sal_Int8* pRes = aRes.getArray();
|
sal_Int8* pRes = aRes.getArray();
|
||||||
|
|
||||||
const BitmapColor aColor( pReadAccess->GetColor( pos.Y, pos.X ) );
|
|
||||||
pRes[ 0 ] = aColor.GetRed();
|
pRes[ 0 ] = aColor.GetRed();
|
||||||
pRes[ 1 ] = aColor.GetGreen();
|
pRes[ 1 ] = aColor.GetGreen();
|
||||||
pRes[ 2 ] = aColor.GetBlue();
|
pRes[ 2 ] = aColor.GetBlue();
|
||||||
|
pRes[ 3 ] = aColor.GetTransparency();
|
||||||
if( pAlphaReadAccess.get() != nullptr )
|
|
||||||
pRes[ 3 ] = pAlphaReadAccess->GetPixel( pos.Y, pos.X ).GetIndex();
|
|
||||||
else
|
|
||||||
pRes[ 3 ] = sal_uInt8(255);
|
|
||||||
|
|
||||||
return aRes;
|
return aRes;
|
||||||
}
|
}
|
||||||
|
@@ -378,6 +378,18 @@ public:
|
|||||||
sal_Int32 nX,
|
sal_Int32 nX,
|
||||||
sal_Int32 nY) const;
|
sal_Int32 nY) const;
|
||||||
|
|
||||||
|
/** Get pixel color (including alpha) at given position
|
||||||
|
|
||||||
|
@param nX
|
||||||
|
integer X-Position in Bitmap
|
||||||
|
|
||||||
|
@param nY
|
||||||
|
integer Y-Position in Bitmap
|
||||||
|
*/
|
||||||
|
::Color GetPixelColor(
|
||||||
|
sal_Int32 nX,
|
||||||
|
sal_Int32 nY) const;
|
||||||
|
|
||||||
/** Create transformed Bitmap
|
/** Create transformed Bitmap
|
||||||
|
|
||||||
@param fWidth
|
@param fWidth
|
||||||
|
@@ -769,6 +769,27 @@ sal_uInt8 BitmapEx::GetTransparency(sal_Int32 nX, sal_Int32 nY) const
|
|||||||
return nTransparency;
|
return nTransparency;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Color BitmapEx::GetPixelColor(sal_Int32 nX, sal_Int32 nY) const
|
||||||
|
{
|
||||||
|
Bitmap aAlpha( GetAlpha().GetBitmap() );
|
||||||
|
|
||||||
|
Bitmap aTestBitmap(maBitmap);
|
||||||
|
Bitmap::ScopedReadAccess pReadAccess( aTestBitmap );
|
||||||
|
assert( pReadAccess );
|
||||||
|
|
||||||
|
Color aColor = pReadAccess->GetColor( nY, nX ).GetColor();
|
||||||
|
|
||||||
|
if (!aAlpha.IsEmpty())
|
||||||
|
{
|
||||||
|
Bitmap::ScopedReadAccess pAlphaReadAccess( aAlpha.AcquireReadAccess(), aAlpha );
|
||||||
|
aColor.SetTransparency( pAlphaReadAccess->GetPixel( nY, nX ).GetIndex() );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
aColor.SetTransparency(255);
|
||||||
|
return aColor;
|
||||||
|
}
|
||||||
|
|
||||||
// Shift alpha transparent pixels between cppcanvas/ implementations
|
// Shift alpha transparent pixels between cppcanvas/ implementations
|
||||||
// and vcl in a generally grotesque and under-performing fashion
|
// and vcl in a generally grotesque and under-performing fashion
|
||||||
bool BitmapEx::Create( const css::uno::Reference< css::rendering::XBitmapCanvas > &xBitmapCanvas,
|
bool BitmapEx::Create( const css::uno::Reference< css::rendering::XBitmapCanvas > &xBitmapCanvas,
|
||||||
|
Reference in New Issue
Block a user