summaryrefslogtreecommitdiff
path: root/vcl/qa/cppunit
diff options
context:
space:
mode:
authorNoel Grandin <noelgrandin@gmail.com>2024-09-24 16:18:11 +0200
committerNoel Grandin <noelgrandin@gmail.com>2025-07-21 10:49:25 +0200
commit088a7c7c451321a800ca8d3523a18b6bb93239b7 (patch)
treed40008befeb9f0c1be149a5cbc559cf0e8accb1c /vcl/qa/cppunit
parent3b22e7c3aa0e601e5fae4716e4e354f07e07b05f (diff)
remove alpha device from OutputDevice
and render to a combined color+alpha bitmap The strategy is to remove the mpAlphaVDev from OutputDevice, and have the OutputDevice create 32-bit SalBitmap's and then have the various backends correctly render to those 32-bit bitmaps. However, whenever we extract a BitmapEx from OutputDevice (e.g. via VirtualDevice) and hand it to the rest of the system, we split the color and alpha information. So the rest of the codebase doesn't have to deal with this yet. We have some major problems to overcome here: (*) Cairo uses 32-bit data, even if we ask for 24-bit color with no alpha. This is because the current version of cairo does not support RGB 24-bit data. (*) Sometimes we want the bitmap to be initialised with an opaque white background, sometimes we want it to be transparent. (*) Sometimes when we extract a bitmap from a device, we want the alpha channel, sometimes not. (*) There are lots of left-over bits of previous attempts of this change lying around, e.g. in skia. Notes (*) we allow Bitmap (ie. SalBitmap) to hold color+alpha (*) The BitmapEx(Bitmap) constructor checks if the incoming Bitmap is color+alpha, and if so, splits into a color bitmap and an alpha bitmap (*) Because the underlying image data is stored pre-multipled, if we write a transparent pixel with color, and then read the pixel value back, we might lose the color information. Change-Id: I0fc0042d6e5be5edd99b320892fb00a8eb2842fe Reviewed-on: https://gerrit.libreoffice.org/c/core/+/173937 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'vcl/qa/cppunit')
-rw-r--r--vcl/qa/cppunit/BackendTest.cxx12
-rw-r--r--vcl/qa/cppunit/BitmapExTest.cxx5
-rw-r--r--vcl/qa/cppunit/BitmapTest.cxx7
-rw-r--r--vcl/qa/cppunit/animationrenderer.cxx1
-rw-r--r--vcl/qa/cppunit/bitmaprender/BitmapRenderTest.cxx22
-rw-r--r--vcl/qa/cppunit/outdev.cxx1
-rw-r--r--vcl/qa/cppunit/skia/skia.cxx4
7 files changed, 19 insertions, 33 deletions
diff --git a/vcl/qa/cppunit/BackendTest.cxx b/vcl/qa/cppunit/BackendTest.cxx
index 4c2ae7cfcfd7..d26248151fb7 100644
--- a/vcl/qa/cppunit/BackendTest.cxx
+++ b/vcl/qa/cppunit/BackendTest.cxx
@@ -61,8 +61,6 @@ class BackendTest : public test::BootstrapFixture
}
}
- bool is32bppSupported() { return ImplGetSVData()->mpDefInst->supportsBitmap32(); }
-
public:
BackendTest()
: BootstrapFixture(true, false)
@@ -543,7 +541,7 @@ public:
Bitmap aBitmap = aOutDevTest.setupDrawBitmap(vcl::PixelFormat::N32_BPP);
exportImage(u"09-01_bitmap_test_32bpp.png"_ustr, aBitmap);
auto eResult = vcl::test::OutputDeviceTestBitmap::checkTransformedBitmap(aBitmap);
- if (SHOULD_ASSERT && is32bppSupported())
+ if (SHOULD_ASSERT)
CPPUNIT_ASSERT(eResult != vcl::test::TestResult::Failed);
}
@@ -555,7 +553,7 @@ public:
Bitmap aBitmap = aOutDevTest.setupDrawTransformedBitmap(vcl::PixelFormat::N32_BPP);
auto eResult = vcl::test::OutputDeviceTestBitmap::checkTransformedBitmap(aBitmap);
exportImage(u"09-02_transformed_bitmap_test_32bpp.png"_ustr, aBitmap);
- if (SHOULD_ASSERT && is32bppSupported())
+ if (SHOULD_ASSERT)
CPPUNIT_ASSERT(eResult != vcl::test::TestResult::Failed);
}
@@ -567,7 +565,7 @@ public:
Bitmap aBitmap = aOutDevTest.setupDrawBitmapExWithAlpha(vcl::PixelFormat::N32_BPP);
auto eResult = vcl::test::OutputDeviceTestBitmap::checkBitmapExWithAlpha(aBitmap);
exportImage(u"09-03_bitmapex_with_alpha_test_32bpp.png"_ustr, aBitmap);
- if (SHOULD_ASSERT && is32bppSupported())
+ if (SHOULD_ASSERT)
CPPUNIT_ASSERT(eResult != vcl::test::TestResult::Failed);
}
@@ -579,7 +577,7 @@ public:
Bitmap aBitmap = aOutDevTest.setupDrawMask(vcl::PixelFormat::N32_BPP);
auto eResult = vcl::test::OutputDeviceTestBitmap::checkMask(aBitmap);
exportImage(u"09-04_mask_test_32bpp.png"_ustr, aBitmap);
- if (SHOULD_ASSERT && is32bppSupported())
+ if (SHOULD_ASSERT)
CPPUNIT_ASSERT(eResult != vcl::test::TestResult::Failed);
}
@@ -591,7 +589,7 @@ public:
BitmapEx aBitmapEx = aOutDevTest.setupDrawBlend(vcl::PixelFormat::N32_BPP);
auto eResult = vcl::test::OutputDeviceTestBitmap::checkBlend(aBitmapEx);
exportImage(u"09-05_blend_test_32bpp.png"_ustr, aBitmapEx);
- if (SHOULD_ASSERT && is32bppSupported())
+ if (SHOULD_ASSERT)
CPPUNIT_ASSERT(eResult != vcl::test::TestResult::Failed);
}
diff --git a/vcl/qa/cppunit/BitmapExTest.cxx b/vcl/qa/cppunit/BitmapExTest.cxx
index 56b91afe5049..517d7574accf 100644
--- a/vcl/qa/cppunit/BitmapExTest.cxx
+++ b/vcl/qa/cppunit/BitmapExTest.cxx
@@ -58,11 +58,6 @@ void BitmapExTest::testGetPixelColor24_8()
void BitmapExTest::testGetPixelColor32()
{
- // Check backend capabilities and return from the test successfully
- // if the backend doesn't support 32-bit bitmap
- if (!ImplGetSVData()->mpDefInst->supportsBitmap32())
- return;
-
Bitmap aBitmap(Size(3, 3), vcl::PixelFormat::N32_BPP);
{
BitmapScopedWriteAccess pWriteAccess(aBitmap);
diff --git a/vcl/qa/cppunit/BitmapTest.cxx b/vcl/qa/cppunit/BitmapTest.cxx
index 0534718ed14b..f280ed05f3ba 100644
--- a/vcl/qa/cppunit/BitmapTest.cxx
+++ b/vcl/qa/cppunit/BitmapTest.cxx
@@ -115,8 +115,6 @@ void BitmapTest::testCreation()
}
// Check backend capabilities and return from the test successfully
- // if the backend doesn't support 32-bit bitmap
- if (ImplGetSVData()->mpDefInst->supportsBitmap32())
{
Bitmap aBmp(Size(10, 10), vcl::PixelFormat::N32_BPP);
Size aSize = aBmp.GetSizePixel();
@@ -482,11 +480,6 @@ void BitmapTest::testErase()
void BitmapTest::testBitmap32()
{
- // Check backend capabilities and return from the test successfully
- // if the backend doesn't support 32-bit bitmap
- if (!ImplGetSVData()->mpDefInst->supportsBitmap32())
- return;
-
Bitmap aBitmap(Size(3, 3), vcl::PixelFormat::N32_BPP);
{
BitmapScopedWriteAccess pWriteAccess(aBitmap);
diff --git a/vcl/qa/cppunit/animationrenderer.cxx b/vcl/qa/cppunit/animationrenderer.cxx
index aa5edcc5dff2..b6f0b53dd249 100644
--- a/vcl/qa/cppunit/animationrenderer.cxx
+++ b/vcl/qa/cppunit/animationrenderer.cxx
@@ -31,6 +31,7 @@ public:
void ReleaseGraphics(bool) override {}
bool UsePolyPolygonForComplexGradient() override { return false; }
bool CanAnimate() const override { return false; }
+ virtual bool HasAlpha() const override { return false; }
};
Animation createAnimation()
diff --git a/vcl/qa/cppunit/bitmaprender/BitmapRenderTest.cxx b/vcl/qa/cppunit/bitmaprender/BitmapRenderTest.cxx
index 4ec0e62527d5..65e0db417084 100644
--- a/vcl/qa/cppunit/bitmaprender/BitmapRenderTest.cxx
+++ b/vcl/qa/cppunit/bitmaprender/BitmapRenderTest.cxx
@@ -146,17 +146,9 @@ void BitmapRenderTest::testDrawAlphaBitmapEx()
BitmapEx aBitmapEx;
aPngReader.read(aBitmapEx);
- // Check backend capabilities, if the backend support 32-bit bitmap
- if (ImplGetSVData()->mpDefInst->supportsBitmap32())
- {
- CPPUNIT_ASSERT_EQUAL(vcl::PixelFormat::N32_BPP, aBitmapEx.GetBitmap().getPixelFormat());
- }
- else
- {
- CPPUNIT_ASSERT_EQUAL(vcl::PixelFormat::N24_BPP, aBitmapEx.GetBitmap().getPixelFormat());
- CPPUNIT_ASSERT_EQUAL(true, aBitmapEx.IsAlpha());
- CPPUNIT_ASSERT_EQUAL(vcl::PixelFormat::N8_BPP, aBitmapEx.GetAlphaMask().getPixelFormat());
- }
+ CPPUNIT_ASSERT_EQUAL(vcl::PixelFormat::N24_BPP, aBitmapEx.GetBitmap().getPixelFormat());
+ CPPUNIT_ASSERT_EQUAL(true, aBitmapEx.IsAlpha());
+ CPPUNIT_ASSERT_EQUAL(vcl::PixelFormat::N8_BPP, aBitmapEx.GetAlphaMask().getPixelFormat());
// Check the bitmap has pixels we expect
CPPUNIT_ASSERT_EQUAL(Color(ColorTransparency, 0xFF, 0x00, 0x00, 0x00),
@@ -190,15 +182,21 @@ void BitmapRenderTest::testAlphaVirtualDevice()
// Set it up
pAlphaVirtualDevice->SetOutputSizePixel(Size(4, 4));
+ CPPUNIT_ASSERT_EQUAL(Color(ColorAlpha, 0xff, 0xff, 0xff, 0xff),
+ pAlphaVirtualDevice->GetPixel(Point(1, 1)));
pAlphaVirtualDevice->SetBackground(Wallpaper(COL_TRANSPARENT));
pAlphaVirtualDevice->Erase();
+ // the backends use pre-multipled alpha, so pure transparency does not round-trip properly
+ CPPUNIT_ASSERT_EQUAL(Color(ColorAlpha, 0x00, 0x00, 0x00, 0x00),
+ pAlphaVirtualDevice->GetPixel(Point(1, 1)));
// Get a BitmapEx from the VirDev -> Colors should have alpha
BitmapEx aBitmap = pAlphaVirtualDevice->GetBitmapEx(Point(), Size(4, 4));
CPPUNIT_ASSERT_EQUAL(tools::Long(4), aBitmap.GetSizePixel().Width());
CPPUNIT_ASSERT_EQUAL(tools::Long(4), aBitmap.GetSizePixel().Height());
Color aColor = aBitmap.GetPixelColor(1, 1);
- CPPUNIT_ASSERT_EQUAL(COL_TRANSPARENT, aColor);
+ // the backends use pre-multipled alpha, so pure transparency does not round-trip properly
+ CPPUNIT_ASSERT_EQUAL(Color(ColorAlpha, 0x00, 0x00, 0x00, 0x00), aColor);
// Draw an opaque pixel to the VirDev
pAlphaVirtualDevice->DrawPixel(Point(1, 1), Color(0x0022ff55));
diff --git a/vcl/qa/cppunit/outdev.cxx b/vcl/qa/cppunit/outdev.cxx
index d0cb54376728..82972b64e6cc 100644
--- a/vcl/qa/cppunit/outdev.cxx
+++ b/vcl/qa/cppunit/outdev.cxx
@@ -890,6 +890,7 @@ public:
void ReleaseGraphics(bool) override {}
bool UsePolyPolygonForComplexGradient() override { return false; }
bool CanAnimate() const override { return false; }
+ virtual bool HasAlpha() const override { return false; }
bool testShouldDrawWavePixelAsRect(tools::Long nLineWidth)
{
diff --git a/vcl/qa/cppunit/skia/skia.cxx b/vcl/qa/cppunit/skia/skia.cxx
index fbe3899cb4f8..bb40421f5df5 100644
--- a/vcl/qa/cppunit/skia/skia.cxx
+++ b/vcl/qa/cppunit/skia/skia.cxx
@@ -365,7 +365,7 @@ void SkiaTest::testDelayedScale()
CPPUNIT_ASSERT_EQUAL(tools::Long(20), buffer1->mnHeight);
skiaBitmap1->ReleaseBuffer(buffer1, BitmapAccessMode::Read);
// Do scaling based on mImage.
- SkiaSalBitmap skiaBitmap2(skiaBitmap1->GetSkImage());
+ SkiaSalBitmap skiaBitmap2(skiaBitmap1->GetSkImage(), /*bWithoutAlpha*/ false);
CPPUNIT_ASSERT(!skiaBitmap2.unittestHasBuffer());
CPPUNIT_ASSERT(skiaBitmap2.unittestHasImage());
CPPUNIT_ASSERT(skiaBitmap2.Scale(2, 3, BmpScaleFlag::Default));
@@ -388,7 +388,7 @@ void SkiaTest::testDelayedScaleAlphaImage()
CPPUNIT_ASSERT(bitmapTmp->Create(Size(10, 10), vcl::PixelFormat::N24_BPP, BitmapPalette()));
bitmapTmp->Erase(COL_RED);
// Create a bitmap that has only an image, not a pixel buffer.
- SkiaSalBitmap bitmap(bitmapTmp->GetSkImage());
+ SkiaSalBitmap bitmap(bitmapTmp->GetSkImage(), /*bWithoutAlpha*/ false);
bitmapTmp.release();
CPPUNIT_ASSERT(!bitmap.unittestHasBuffer());
CPPUNIT_ASSERT(bitmap.unittestHasImage());