diff options
author | Noel Grandin <noelgrandin@gmail.com> | 2021-04-16 20:33:10 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2023-07-25 08:38:12 +0200 |
commit | 81994cb2b8b32453a92bcb011830fcb884f22ff3 (patch) | |
tree | ae1750e92421ad2e0ec3f50351c3be6581841598 /vcl/qa | |
parent | dabedcaf27b0af1e38a611b8d8e48444f848e01d (diff) |
Convert internal vcl bitmap formats transparency->alpha (II)
(Second attempt at landing this)
Image formats and graphics APIs use alpha, not transparency,
so change our internal formats and data structures to work directly
with alpha, so we don't need to modify data before we push it to
graphics APIs.
Add a couple of new Color constants to make the intention
of the vcl code clearer.
Notes
(*) On macOS, tweaking the logic in CreateWithSalBitmapAndMask
to more accurately reflect the requirements of the
CGImageCreateWithMask function seems to fix some
tests.
(*) The vcl code does not properly support gradients
with transparency. So the previous code was wrong, and this
change is going to result in slightly different wrongness.
Change-Id: I9e21c2e98d88ecfdc5f75db13bd1ffff7c38db98
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/114168
Tested-by: Jenkins
Reviewed-by: Patrick Luby <plubius@neooffice.org>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'vcl/qa')
-rw-r--r-- | vcl/qa/cppunit/BackendTest.cxx | 2 | ||||
-rw-r--r-- | vcl/qa/cppunit/BitmapExTest.cxx | 3 | ||||
-rw-r--r-- | vcl/qa/cppunit/ScanlineToolsTest.cxx | 10 | ||||
-rw-r--r-- | vcl/qa/cppunit/canvasbitmaptest.cxx | 28 | ||||
-rw-r--r-- | vcl/qa/cppunit/png/PngFilterTest.cxx | 32 | ||||
-rw-r--r-- | vcl/qa/cppunit/skia/skia.cxx | 6 | ||||
-rw-r--r-- | vcl/qa/cppunit/svm/svmtest.cxx | 21 |
7 files changed, 50 insertions, 52 deletions
diff --git a/vcl/qa/cppunit/BackendTest.cxx b/vcl/qa/cppunit/BackendTest.cxx index 2c85be06e66d..e5013d244335 100644 --- a/vcl/qa/cppunit/BackendTest.cxx +++ b/vcl/qa/cppunit/BackendTest.cxx @@ -1181,7 +1181,7 @@ public: device->Erase(); alpha.Erase(255); // transparent BitmapWriteAccess* alphaWrite = alpha.AcquireAlphaWriteAccess(); - alphaWrite->SetPixelIndex(0, 0, 0); // opaque + alphaWrite->SetPixelIndex(0, 0, 255); // opaque alpha.ReleaseAccess(alphaWrite); device->DrawBitmapEx(Point(2, 2), BitmapEx(bitmap, alpha)); exportDevice("blend_extended_04.png", device); diff --git a/vcl/qa/cppunit/BitmapExTest.cxx b/vcl/qa/cppunit/BitmapExTest.cxx index a0a6b3096f53..a8f1e5a9cda5 100644 --- a/vcl/qa/cppunit/BitmapExTest.cxx +++ b/vcl/qa/cppunit/BitmapExTest.cxx @@ -47,8 +47,7 @@ void BitmapExTest::testGetPixelColor24_8() BitmapEx aBitmapEx(aBitmap, aMask); - CPPUNIT_ASSERT_EQUAL(Color(ColorTransparency, 0xAA, 0x00, 0xFF, 0x00), - aBitmapEx.GetPixelColor(0, 0)); + CPPUNIT_ASSERT_EQUAL(Color(ColorAlpha, 0xAA, 0x00, 0xFF, 0x00), aBitmapEx.GetPixelColor(0, 0)); } void BitmapExTest::testGetPixelColor32() diff --git a/vcl/qa/cppunit/ScanlineToolsTest.cxx b/vcl/qa/cppunit/ScanlineToolsTest.cxx index 8b8a9088a1ea..97233f2692af 100644 --- a/vcl/qa/cppunit/ScanlineToolsTest.cxx +++ b/vcl/qa/cppunit/ScanlineToolsTest.cxx @@ -42,9 +42,9 @@ void ScanlineToolsTest::ScanlineTransformer_32_ARGB() pScanlineTransformer->startLine(aScanLine.data()); std::vector<Color> aColors{ - Color(ColorTransparency, 0, 10, 250, 120), Color(ColorTransparency, 50, 30, 230, 110), - Color(ColorTransparency, 100, 50, 210, 100), Color(ColorTransparency, 150, 70, 190, 90), - Color(ColorTransparency, 200, 90, 170, 80), + Color(ColorAlpha, 255, 10, 250, 120), Color(ColorAlpha, 205, 30, 230, 110), + Color(ColorAlpha, 155, 50, 210, 100), Color(ColorAlpha, 105, 70, 190, 90), + Color(ColorAlpha, 55, 90, 170, 80), }; for (Color const& aColor : aColors) @@ -52,8 +52,8 @@ void ScanlineToolsTest::ScanlineTransformer_32_ARGB() pScanlineTransformer->writePixel(aColor); } - std::vector<sal_uInt8> aExpectedBytes{ 0, 10, 250, 120, 50, 30, 230, 110, 100, 50, - 210, 100, 150, 70, 190, 90, 200, 90, 170, 80 }; + std::vector<sal_uInt8> aExpectedBytes{ 255, 10, 250, 120, 205, 30, 230, 110, 155, 50, + 210, 100, 105, 70, 190, 90, 55, 90, 170, 80 }; for (size_t i = 0; i < aScanLine.size(); ++i) { diff --git a/vcl/qa/cppunit/canvasbitmaptest.cxx b/vcl/qa/cppunit/canvasbitmaptest.cxx index 27ac06d0d9de..78eb033f90b0 100644 --- a/vcl/qa/cppunit/canvasbitmaptest.cxx +++ b/vcl/qa/cppunit/canvasbitmaptest.cxx @@ -672,17 +672,17 @@ void CanvasBitmapTest::runTest() checkCanvasBitmap( xBmp, "single bitmap", nDepth ); - Bitmap aMask(Size(200,200), vcl::PixelFormat::N8_BPP, &Bitmap::GetGreyPalette(256)); - aMask.Erase(COL_WHITE); + AlphaMask aMask(Size(200,200)); + aMask.Erase(255); { BitmapScopedWriteAccess pAcc(aMask); if( pAcc.get() ) { - pAcc->SetFillColor(COL_BLACK); + pAcc->SetFillColor(COL_ALPHA_OPAQUE); pAcc->FillRect(tools::Rectangle(0,0,100,100)); - pAcc->SetPixel(0,0,BitmapColor(255)); - pAcc->SetPixel(0,1,BitmapColor(0)); - pAcc->SetPixel(0,2,BitmapColor(255)); + pAcc->SetPixel(0,0,BitmapColor(0)); + pAcc->SetPixel(0,1,BitmapColor(255)); + pAcc->SetPixel(0,2,BitmapColor(0)); } } @@ -691,16 +691,16 @@ void CanvasBitmapTest::runTest() checkCanvasBitmap( xBmp, "masked bitmap", nDepth ); AlphaMask aAlpha(Size(200,200)); - aAlpha.Erase(255); + aAlpha.Erase(0); { BitmapWriteAccess* pAcc = aAlpha.AcquireWriteAccess(); if( pAcc ) { - pAcc->SetFillColor(COL_BLACK); + pAcc->SetFillColor(COL_ALPHA_OPAQUE); pAcc->FillRect(tools::Rectangle(0,0,100,100)); - pAcc->SetPixel(0,0,BitmapColor(255)); - pAcc->SetPixel(0,1,BitmapColor(0)); - pAcc->SetPixel(0,2,BitmapColor(255)); + pAcc->SetPixel(0,0,BitmapColor(0)); + pAcc->SetPixel(0,1,BitmapColor(255)); + pAcc->SetPixel(0,2,BitmapColor(0)); aAlpha.ReleaseAccess(pAcc); } } @@ -762,15 +762,15 @@ void CanvasBitmapTest::runTest() CPPUNIT_ASSERT_EQUAL_MESSAGE("(0,0) incorrect content", BitmapColor(0,1,0), pBmpAcc->GetPixel(0,0)); CPPUNIT_ASSERT_EQUAL_MESSAGE("(0,0) incorrect alpha content", - BitmapColor(255), pAlphaAcc->GetPixel(0,0)); + BitmapColor(0), pAlphaAcc->GetPixel(0,0)); CPPUNIT_ASSERT_EQUAL_MESSAGE("(2,2) incorrect content", BitmapColor(0,3,2), pBmpAcc->GetPixel(2,2)); CPPUNIT_ASSERT_EQUAL_MESSAGE("(2,2) incorrect alpha content", - BitmapColor(253), pAlphaAcc->GetPixel(2,2)); + BitmapColor(2), pAlphaAcc->GetPixel(2,2)); CPPUNIT_ASSERT_EQUAL_MESSAGE("(9,2) incorrect content", BitmapColor(0,3,9), pBmpAcc->GetPixel(2,9)); CPPUNIT_ASSERT_EQUAL_MESSAGE("(9,2) correct alpha content", - BitmapColor(253), pAlphaAcc->GetPixel(2,9)); + BitmapColor(2), pAlphaAcc->GetPixel(2,9)); aBitmapAlpha.ReleaseAccess(pAlphaAcc); Bitmap::ReleaseAccess(pBmpAcc); diff --git a/vcl/qa/cppunit/png/PngFilterTest.cxx b/vcl/qa/cppunit/png/PngFilterTest.cxx index 760e12f8b3fc..8e9c15e6dd49 100644 --- a/vcl/qa/cppunit/png/PngFilterTest.cxx +++ b/vcl/qa/cppunit/png/PngFilterTest.cxx @@ -325,22 +325,22 @@ void PngFilterTest::testPng() CPPUNIT_ASSERT_EQUAL(tools::Long(4), pAlphaAccess->Width()); CPPUNIT_ASSERT_EQUAL(tools::Long(4), pAlphaAccess->Height()); - CPPUNIT_ASSERT_EQUAL(BitmapColor(ColorTransparency, 0x00, 0x00, 0x80, 0x00), + CPPUNIT_ASSERT_EQUAL(BitmapColor(ColorTransparency, 0x00, 0x00, 0x7F, 0x00), pAlphaAccess->GetPixel(0, 0)); - CPPUNIT_ASSERT_EQUAL(BitmapColor(ColorTransparency, 0x00, 0x00, 0x80, 0x00), + CPPUNIT_ASSERT_EQUAL(BitmapColor(ColorTransparency, 0x00, 0x00, 0x7F, 0x00), pAlphaAccess->GetPixel(3, 3)); - CPPUNIT_ASSERT_EQUAL(BitmapColor(ColorTransparency, 0x00, 0x00, 0x80, 0x00), + CPPUNIT_ASSERT_EQUAL(BitmapColor(ColorTransparency, 0x00, 0x00, 0x7F, 0x00), pAlphaAccess->GetPixel(3, 0)); - CPPUNIT_ASSERT_EQUAL(BitmapColor(ColorTransparency, 0x00, 0x00, 0x80, 0x00), + CPPUNIT_ASSERT_EQUAL(BitmapColor(ColorTransparency, 0x00, 0x00, 0x7F, 0x00), pAlphaAccess->GetPixel(0, 3)); - CPPUNIT_ASSERT_EQUAL(BitmapColor(ColorTransparency, 0x00, 0x00, 0x40, 0x00), + CPPUNIT_ASSERT_EQUAL(BitmapColor(ColorTransparency, 0x00, 0x00, 0xBF, 0x00), pAlphaAccess->GetPixel(1, 1)); - CPPUNIT_ASSERT_EQUAL(BitmapColor(ColorTransparency, 0x00, 0x00, 0xC0, 0x00), + CPPUNIT_ASSERT_EQUAL(BitmapColor(ColorTransparency, 0x00, 0x00, 0x3F, 0x00), pAlphaAccess->GetPixel(1, 2)); - CPPUNIT_ASSERT_EQUAL(BitmapColor(ColorTransparency, 0x00, 0x00, 0xC0, 0x00), + CPPUNIT_ASSERT_EQUAL(BitmapColor(ColorTransparency, 0x00, 0x00, 0x3F, 0x00), pAlphaAccess->GetPixel(2, 1)); - CPPUNIT_ASSERT_EQUAL(BitmapColor(ColorTransparency, 0x00, 0x00, 0x40, 0x00), + CPPUNIT_ASSERT_EQUAL(BitmapColor(ColorTransparency, 0x00, 0x00, 0xBF, 0x00), pAlphaAccess->GetPixel(2, 2)); } } @@ -1887,15 +1887,14 @@ void PngFilterTest::testPngRoundtrip24_8() { BitmapScopedWriteAccess pWriteAccessBitmap(aBitmap); AlphaScopedWriteAccess pWriteAccessAlpha(aAlpha); - pWriteAccessAlpha->Erase(Color(ColorTransparency, 0x00, 0xAA, 0xAA, 0xAA)); + pWriteAccessAlpha->Erase(Color(0xAA, 0xAA, 0xAA)); pWriteAccessBitmap->Erase(COL_BLACK); for (int i = 0; i < 8; ++i) { for (int j = 0; j < 8; ++j) { pWriteAccessBitmap->SetPixel(i, j, COL_LIGHTRED); - pWriteAccessAlpha->SetPixel(i, j, - Color(ColorTransparency, 0x00, 0xBB, 0xBB, 0xBB)); + pWriteAccessAlpha->SetPixel(i, j, Color(0xBB, 0xBB, 0xBB)); } } for (int i = 8; i < 16; ++i) @@ -1903,8 +1902,7 @@ void PngFilterTest::testPngRoundtrip24_8() for (int j = 8; j < 16; ++j) { pWriteAccessBitmap->SetPixel(i, j, COL_LIGHTBLUE); - pWriteAccessAlpha->SetPixel(i, j, - Color(ColorTransparency, 0x00, 0xCC, 0xCC, 0xCC)); + pWriteAccessAlpha->SetPixel(i, j, Color(0xCC, 0xCC, 0xCC)); } } } @@ -1922,13 +1920,13 @@ void PngFilterTest::testPngRoundtrip24_8() CPPUNIT_ASSERT_EQUAL(Size(16, 16), aBitmapEx.GetSizePixel()); - CPPUNIT_ASSERT_EQUAL(Color(ColorTransparency, 0xBB, 0xFF, 0x00, 0x00), + CPPUNIT_ASSERT_EQUAL(Color(ColorAlpha, 0xBB, 0xFF, 0x00, 0x00), aBitmapEx.GetPixelColor(0, 0)); - CPPUNIT_ASSERT_EQUAL(Color(ColorTransparency, 0xCC, 0x00, 0x00, 0xFF), + CPPUNIT_ASSERT_EQUAL(Color(ColorAlpha, 0xCC, 0x00, 0x00, 0xFF), aBitmapEx.GetPixelColor(15, 15)); - CPPUNIT_ASSERT_EQUAL(Color(ColorTransparency, 0xAA, 0x00, 0x00, 0x00), + CPPUNIT_ASSERT_EQUAL(Color(ColorAlpha, 0xAA, 0x00, 0x00, 0x00), aBitmapEx.GetPixelColor(15, 0)); - CPPUNIT_ASSERT_EQUAL(Color(ColorTransparency, 0xAA, 0x00, 0x00, 0x00), + CPPUNIT_ASSERT_EQUAL(Color(ColorAlpha, 0xAA, 0x00, 0x00, 0x00), aBitmapEx.GetPixelColor(0, 15)); } } diff --git a/vcl/qa/cppunit/skia/skia.cxx b/vcl/qa/cppunit/skia/skia.cxx index 5d81e39f587a..b90b915e17ea 100644 --- a/vcl/qa/cppunit/skia/skia.cxx +++ b/vcl/qa/cppunit/skia/skia.cxx @@ -244,7 +244,7 @@ void SkiaTest::testAlphaBlendWith() skiaAlpha = dynamic_cast<SkiaSalBitmap*>(alpha.ImplGetSalBitmap().get()); CPPUNIT_ASSERT(skiaAlpha->unittestHasEraseColor()); CPPUNIT_ASSERT_EQUAL(vcl::PixelFormat::N8_BPP, alpha.getPixelFormat()); - CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt8>(112), + CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt8>(208), AlphaMask::ScopedReadAccess(alpha)->GetPixelIndex(0, 0)); // Test with images set. @@ -264,7 +264,7 @@ void SkiaTest::testAlphaBlendWith() skiaAlpha = dynamic_cast<SkiaSalBitmap*>(alpha.ImplGetSalBitmap().get()); CPPUNIT_ASSERT(skiaAlpha->unittestHasImage()); CPPUNIT_ASSERT_EQUAL(vcl::PixelFormat::N8_BPP, alpha.getPixelFormat()); - CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt8>(112), + CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt8>(207), AlphaMask::ScopedReadAccess(alpha)->GetPixelIndex(0, 0)); // Test with erase color for alpha and image for other bitmap. @@ -281,7 +281,7 @@ void SkiaTest::testAlphaBlendWith() skiaAlpha = dynamic_cast<SkiaSalBitmap*>(alpha.ImplGetSalBitmap().get()); CPPUNIT_ASSERT(skiaAlpha->unittestHasImage()); CPPUNIT_ASSERT_EQUAL(vcl::PixelFormat::N8_BPP, alpha.getPixelFormat()); - CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt8>(112), + CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt8>(207), AlphaMask::ScopedReadAccess(alpha)->GetPixelIndex(0, 0)); } diff --git a/vcl/qa/cppunit/svm/svmtest.cxx b/vcl/qa/cppunit/svm/svmtest.cxx index fcf863e7664a..5161f4cce960 100644 --- a/vcl/qa/cppunit/svm/svmtest.cxx +++ b/vcl/qa/cppunit/svm/svmtest.cxx @@ -26,6 +26,7 @@ #include <vcl/filter/SvmReader.hxx> #include <vcl/filter/SvmWriter.hxx> #include <salhelper/simplereferenceobject.hxx> +#include <sal/log.hxx> #include <bitmap/BitmapWriteAccess.hxx> @@ -46,7 +47,7 @@ class SvmTest : public test::BootstrapFixture, public XmlTestTools return m_directories.getURLFromSrc(maDataUrl) + sFileName; } - void checkRendering(ScopedVclPtrInstance<VirtualDevice> const & pVirtualDev, const GDIMetaFile& rMetaFile); + void checkRendering(ScopedVclPtrInstance<VirtualDevice> const & pVirtualDev, const GDIMetaFile& rMetaFile, const char * where); // write GDI Metafile to a file in data directory // only use this for new tests to create the svm file @@ -268,7 +269,7 @@ static void setupBaseVirtualDevice(VirtualDevice& rDevice, GDIMetaFile& rMeta) rDevice.Erase(); } -void SvmTest::checkRendering(ScopedVclPtrInstance<VirtualDevice> const & pVirtualDev, const GDIMetaFile& rMetaFile) +void SvmTest::checkRendering(ScopedVclPtrInstance<VirtualDevice> const & pVirtualDev, const GDIMetaFile& rMetaFile, const char * where) { BitmapEx aSourceBitmapEx = pVirtualDev->GetBitmapEx(Point(), Size(10, 10)); ScopedVclPtrInstance<VirtualDevice> pVirtualDevResult; @@ -294,7 +295,7 @@ void SvmTest::checkRendering(ScopedVclPtrInstance<VirtualDevice> const & pVirtua aPNGWriter.write(aResultBitmapEx); } } - CPPUNIT_ASSERT_EQUAL(aSourceBitmapEx.GetChecksum(), aResultBitmapEx.GetChecksum()); + CPPUNIT_ASSERT_EQUAL_MESSAGE(where, aSourceBitmapEx.GetChecksum(), aResultBitmapEx.GetChecksum()); } static GDIMetaFile readMetafile(const OUString& rUrl) @@ -989,12 +990,12 @@ void SvmTest::testBitmaps() { GDIMetaFile aReloadedGDIMetaFile = writeAndReadStream(aGDIMetaFile); checkBitmaps(aReloadedGDIMetaFile); - checkRendering(pVirtualDev, aReloadedGDIMetaFile); + checkRendering(pVirtualDev, aReloadedGDIMetaFile, SAL_WHERE); } { GDIMetaFile aFileGDIMetaFile = readFile(u"bitmaps.svm"); checkBitmaps(aFileGDIMetaFile); - checkRendering(pVirtualDev, aFileGDIMetaFile); + checkRendering(pVirtualDev, aFileGDIMetaFile, SAL_WHERE); } } @@ -1005,7 +1006,7 @@ void SvmTest::checkBitmapExs(const GDIMetaFile& rMetaFile, bool bIsSvmFile) if (SkiaHelper::isVCLSkiaEnabled()) return; // TODO SKIA using CRCs is broken (the idea of it) - std::array<OUString, 8> aExpectedCRC + static const std::vector<OUString> aExpectedCRC { #if defined OSL_BIGENDIAN "08feb5d3", @@ -1028,7 +1029,7 @@ void SvmTest::checkBitmapExs(const GDIMetaFile& rMetaFile, bool bIsSvmFile) #endif }; - std::array<OUString, 8> aExpectedContentChecksum + static const std::array<OUString, 8> aExpectedContentChecksum { "26bdebd04e5b18d685cea04982179e273ee3b659", "f4f52df6ef965a2f0fbccbe6aca35ba3457cf9d5", @@ -1126,7 +1127,7 @@ void SvmTest::testBitmapExs() pAccess->Erase(COL_MAGENTA); AlphaScopedWriteAccess pAlphaAccess(aAlpha); - pAlphaAccess->Erase(Color(128, 128, 128)); + pAlphaAccess->Erase(Color(127, 127, 127)); } pVirtualDev->DrawBitmapEx(Point(6, 6), BitmapEx(aBitmap, aAlpha)); } @@ -1178,12 +1179,12 @@ void SvmTest::testBitmapExs() { GDIMetaFile aReloadedGDIMetaFile = writeAndReadStream(aGDIMetaFile); checkBitmapExs(aReloadedGDIMetaFile, /*bIsSvmFile*/false); - checkRendering(pVirtualDev, aReloadedGDIMetaFile); + checkRendering(pVirtualDev, aReloadedGDIMetaFile, SAL_WHERE); } { GDIMetaFile aFileGDIMetaFile = readFile(u"bitmapexs.svm"); checkBitmapExs(aFileGDIMetaFile, /*bIsSvmFile*/true); - checkRendering(pVirtualDev, aFileGDIMetaFile); + checkRendering(pVirtualDev, aFileGDIMetaFile, SAL_WHERE); } } |