Kaydet (Commit) ba9e513e authored tarafından Tomaž Vajngerl's avatar Tomaž Vajngerl Kaydeden (comit) Tomaž Vajngerl

Test an alpha VirtualDevice and fix GetPixel and DrawPixel

This adds an test for a VirtualDevice with an alpha channel,
which checks that getting a BitmapEx from the alpha VirtualDevice
is has a alpha channel properly set.

Test that using GetPixel and DrawPixel properly handle an alpha
based Color, which they didn't, so this also includes the fix for
thouse 2 methods.

Change-Id: I419b8e0f66ab5f8266c6129e501ed75ef517fd44
Reviewed-on: https://gerrit.libreoffice.org/70805
Tested-by: Jenkins
Reviewed-by: 's avatarTomaž Vajngerl <quikee@gmail.com>
üst 6fd7495b
...@@ -42,12 +42,14 @@ public: ...@@ -42,12 +42,14 @@ public:
void testTdf104141(); void testTdf104141();
void testTdf113918(); void testTdf113918();
void testDrawAlphaBitmapEx(); void testDrawAlphaBitmapEx();
void testAlphaVirtualDevice();
void testTdf116888(); void testTdf116888();
CPPUNIT_TEST_SUITE(BitmapRenderTest); CPPUNIT_TEST_SUITE(BitmapRenderTest);
CPPUNIT_TEST(testTdf104141); CPPUNIT_TEST(testTdf104141);
CPPUNIT_TEST(testTdf113918); CPPUNIT_TEST(testTdf113918);
CPPUNIT_TEST(testDrawAlphaBitmapEx); CPPUNIT_TEST(testDrawAlphaBitmapEx);
CPPUNIT_TEST(testAlphaVirtualDevice);
CPPUNIT_TEST(testTdf116888); CPPUNIT_TEST(testTdf116888);
CPPUNIT_TEST_SUITE_END(); CPPUNIT_TEST_SUITE_END();
...@@ -150,6 +152,73 @@ void BitmapRenderTest::testDrawAlphaBitmapEx() ...@@ -150,6 +152,73 @@ void BitmapRenderTest::testDrawAlphaBitmapEx()
#endif #endif
} }
void BitmapRenderTest::testAlphaVirtualDevice()
{
// Create an alpha virtual device
ScopedVclPtr<VirtualDevice> pAlphaVirtualDevice(VclPtr<VirtualDevice>::Create(
*Application::GetDefaultDevice(), DeviceFormat::DEFAULT, DeviceFormat::DEFAULT));
// Set it up
pAlphaVirtualDevice->SetOutputSizePixel(Size(4, 4));
pAlphaVirtualDevice->SetBackground(Wallpaper(COL_TRANSPARENT));
pAlphaVirtualDevice->Erase();
// Get a BitmapEx from the VirDev -> Colors should have alpha
BitmapEx aBitmap = pAlphaVirtualDevice->GetBitmapEx(Point(), Size(4, 4));
CPPUNIT_ASSERT_EQUAL(long(4), aBitmap.GetSizePixel().Width());
CPPUNIT_ASSERT_EQUAL(long(4), aBitmap.GetSizePixel().Height());
Color aColor = aBitmap.GetPixelColor(1, 1);
CPPUNIT_ASSERT_EQUAL(Color(0xff, 0xff, 0xff, 0xff), aColor);
// Draw an opaque pixel to the VirDev
pAlphaVirtualDevice->DrawPixel(Point(1, 1), Color(0x00, 0x22, 0xff, 0x55));
// Read back the opaque pixel
#ifdef MACOSX
// Oh no.. what we input is not the same as what we get out!
CPPUNIT_ASSERT_EQUAL(Color(0x00, 0x2C, 0xff, 0x44), pAlphaVirtualDevice->GetPixel(Point(1, 1)));
#else
CPPUNIT_ASSERT_EQUAL(Color(0x00, 0x22, 0xff, 0x55), pAlphaVirtualDevice->GetPixel(Point(1, 1)));
#endif
// Read back the BitmapEx and check the opaque pixel
aBitmap = pAlphaVirtualDevice->GetBitmapEx(Point(), Size(4, 4));
CPPUNIT_ASSERT_EQUAL(long(4), aBitmap.GetSizePixel().Width());
CPPUNIT_ASSERT_EQUAL(long(4), aBitmap.GetSizePixel().Height());
aColor = aBitmap.GetPixelColor(1, 1);
#ifdef MACOSX
// Oh no.. what we input is not the same as what we get out!
CPPUNIT_ASSERT_EQUAL(Color(0x00, 0x2C, 0xff, 0x44), aColor);
#else
CPPUNIT_ASSERT_EQUAL(Color(0x00, 0x22, 0xff, 0x55), aColor);
#endif
// Draw an semi-transparent pixel
pAlphaVirtualDevice->DrawPixel(Point(0, 0), Color(0x44, 0x22, 0xff, 0x55));
// Read back the semi-transparent pixel
#ifdef MACOSX
// Oh no.. what we input is not the same as what we get out!
CPPUNIT_ASSERT_EQUAL(Color(0x34, 0x2C, 0xFF, 0x44), pAlphaVirtualDevice->GetPixel(Point(0, 0)));
#else
CPPUNIT_ASSERT_EQUAL(Color(0x44, 0x22, 0xFF, 0x55), pAlphaVirtualDevice->GetPixel(Point(0, 0)));
#endif
// Read back the BitmapEx and check the semi-transparent pixel
aBitmap = pAlphaVirtualDevice->GetBitmapEx(Point(), Size(4, 4));
CPPUNIT_ASSERT_EQUAL(long(4), aBitmap.GetSizePixel().Width());
CPPUNIT_ASSERT_EQUAL(long(4), aBitmap.GetSizePixel().Height());
aColor = aBitmap.GetPixelColor(0, 0);
#ifdef MACOSX
// Oh no.. what we input is not the same as what we get out!
CPPUNIT_ASSERT_EQUAL(Color(0x34, 0x2C, 0xFF, 0x44), aColor);
#else
CPPUNIT_ASSERT_EQUAL(Color(0x44, 0x22, 0xFF, 0x55), aColor);
#endif
}
void BitmapRenderTest::testTdf116888() void BitmapRenderTest::testTdf116888()
{ {
// The image is a 8bit image with a non-grayscale palette. In OpenGL mode // The image is a 8bit image with a non-grayscale palette. In OpenGL mode
......
...@@ -32,20 +32,26 @@ ...@@ -32,20 +32,26 @@
#include <outdata.hxx> #include <outdata.hxx>
#include <salgdi.hxx> #include <salgdi.hxx>
Color OutputDevice::GetPixel( const Point& rPt ) const Color OutputDevice::GetPixel(const Point& rPoint) const
{ {
Color aColor; Color aColor;
if ( mpGraphics || AcquireGraphics() ) if (mpGraphics || AcquireGraphics())
{ {
if ( mbInitClipRegion ) if (mbInitClipRegion)
const_cast<OutputDevice*>(this)->InitClipRegion(); const_cast<OutputDevice*>(this)->InitClipRegion();
if ( !mbOutputClipped ) if (!mbOutputClipped)
{ {
const long nX = ImplLogicXToDevicePixel( rPt.X() ); const long nX = ImplLogicXToDevicePixel(rPoint.X());
const long nY = ImplLogicYToDevicePixel( rPt.Y() ); const long nY = ImplLogicYToDevicePixel(rPoint.Y());
aColor = mpGraphics->GetPixel( nX, nY, this ); aColor = mpGraphics->GetPixel(nX, nY, this);
if (mpAlphaVDev)
{
Color aAlphaColor = mpAlphaVDev->GetPixel(rPoint);
aColor.SetTransparency(aAlphaColor.GetBlue());
}
} }
} }
return aColor; return aColor;
...@@ -90,7 +96,7 @@ void OutputDevice::DrawPixel( const Point& rPt, const Color& rColor ) ...@@ -90,7 +96,7 @@ void OutputDevice::DrawPixel( const Point& rPt, const Color& rColor )
if ( mpMetaFile ) if ( mpMetaFile )
mpMetaFile->AddAction( new MetaPixelAction( rPt, aColor ) ); mpMetaFile->AddAction( new MetaPixelAction( rPt, aColor ) );
if ( !IsDeviceOutputNecessary() || ImplIsColorTransparent( aColor ) || ImplIsRecordLayout() ) if ( !IsDeviceOutputNecessary() || ImplIsRecordLayout() )
return; return;
Point aPt = ImplLogicToDevicePixel( rPt ); Point aPt = ImplLogicToDevicePixel( rPt );
...@@ -106,8 +112,11 @@ void OutputDevice::DrawPixel( const Point& rPt, const Color& rColor ) ...@@ -106,8 +112,11 @@ void OutputDevice::DrawPixel( const Point& rPt, const Color& rColor )
mpGraphics->DrawPixel( aPt.X(), aPt.Y(), aColor, this ); mpGraphics->DrawPixel( aPt.X(), aPt.Y(), aColor, this );
if( mpAlphaVDev ) if (mpAlphaVDev)
mpAlphaVDev->DrawPixel( rPt ); {
Color aAlphaColor(rColor.GetTransparency(), rColor.GetTransparency(), rColor.GetTransparency());
mpAlphaVDev->DrawPixel(rPt, aAlphaColor);
}
} }
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment