[Libreoffice-commits] core.git: vcl/CppunitTest_vcl_bitmap_test.mk vcl/qa vcl/source

Tomaž Vajngerl (via logerrit) logerrit at kemper.freedesktop.org
Tue Apr 16 04:53:19 UTC 2019


 vcl/CppunitTest_vcl_bitmap_test.mk |    1 
 vcl/qa/cppunit/BitmapExTest.cxx    |   74 +++++++++++++++++++++++++++++++++++++
 vcl/source/gdi/bitmapex.cxx        |   17 +++++---
 3 files changed, 85 insertions(+), 7 deletions(-)

New commits:
commit 8d65b2bafa1ee000b2722c3c5e6d45a62b74c196
Author:     Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
AuthorDate: Tue Apr 16 12:06:09 2019 +0900
Commit:     Tomaž Vajngerl <quikee at gmail.com>
CommitDate: Tue Apr 16 06:52:47 2019 +0200

    Add test for BitmapEx GetPixelColor for 24+8 and 32bit Bitmaps
    
    Change-Id: I0c1b8447acd6681d8731c35412b90a00741274fa
    Reviewed-on: https://gerrit.libreoffice.org/70803
    Tested-by: Jenkins
    Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>

diff --git a/vcl/CppunitTest_vcl_bitmap_test.mk b/vcl/CppunitTest_vcl_bitmap_test.mk
index bae00152c77d..3bb293cfc66d 100644
--- a/vcl/CppunitTest_vcl_bitmap_test.mk
+++ b/vcl/CppunitTest_vcl_bitmap_test.mk
@@ -11,6 +11,7 @@ $(eval $(call gb_CppunitTest_CppunitTest,vcl_bitmap_test))
 
 $(eval $(call gb_CppunitTest_add_exception_objects,vcl_bitmap_test, \
     vcl/qa/cppunit/BitmapTest \
+    vcl/qa/cppunit/BitmapExTest \
     vcl/qa/cppunit/bitmapcolor \
 ))
 
diff --git a/vcl/qa/cppunit/BitmapExTest.cxx b/vcl/qa/cppunit/BitmapExTest.cxx
new file mode 100644
index 000000000000..4b45a3e88972
--- /dev/null
+++ b/vcl/qa/cppunit/BitmapExTest.cxx
@@ -0,0 +1,74 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <cppunit/TestAssert.h>
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/plugin/TestPlugIn.h>
+
+#include <vcl/bitmapex.hxx>
+#include <bitmapwriteaccess.hxx>
+#include <svdata.hxx>
+#include <salinst.hxx>
+
+namespace
+{
+class BitmapExTest : public CppUnit::TestFixture
+{
+    void testGetPixelColor24_8();
+    void testGetPixelColor32();
+
+    CPPUNIT_TEST_SUITE(BitmapExTest);
+    CPPUNIT_TEST(testGetPixelColor24_8);
+    CPPUNIT_TEST(testGetPixelColor32);
+    CPPUNIT_TEST_SUITE_END();
+};
+
+void BitmapExTest::testGetPixelColor24_8()
+{
+    Bitmap aBitmap(Size(3, 3), 24);
+    {
+        BitmapScopedWriteAccess pWriteAccess(aBitmap);
+        pWriteAccess->Erase(Color(0x00, 0x00, 0xFF, 0x00));
+    }
+    AlphaMask aMask(Size(3, 3));
+    {
+        AlphaScopedWriteAccess pWriteAccess(aMask);
+        pWriteAccess->Erase(Color(0x00, 0xAA, 0xAA, 0xAA));
+    }
+
+    BitmapEx aBitmapEx(aBitmap, aMask);
+
+    CPPUNIT_ASSERT_EQUAL(Color(0xAA, 0x00, 0xFF, 0x00), aBitmapEx.GetPixelColor(0, 0));
+}
+
+void BitmapExTest::testGetPixelColor32()
+{
+    // Check backend capabilities and return from the test successfully
+    // if the backend doesn't support 32-bit bitmap
+    auto pBackendCapabilities = ImplGetSVData()->mpDefInst->GetBackendCapabilities();
+    if (!pBackendCapabilities->mbSupportsBitmap32)
+        return;
+
+    Bitmap aBitmap(Size(3, 3), 32);
+    {
+        BitmapScopedWriteAccess pWriteAccess(aBitmap);
+        pWriteAccess->Erase(Color(0xAA, 0x00, 0xFF, 0x00));
+    }
+
+    BitmapEx aBitmapEx(aBitmap);
+
+    CPPUNIT_ASSERT_EQUAL(Color(0xAA, 0x00, 0xFF, 0x00), aBitmapEx.GetPixelColor(0, 0));
+}
+
+} // namespace
+
+CPPUNIT_TEST_SUITE_REGISTRATION(BitmapExTest);
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/source/gdi/bitmapex.cxx b/vcl/source/gdi/bitmapex.cxx
index a6820872578e..3c0df290b217 100644
--- a/vcl/source/gdi/bitmapex.cxx
+++ b/vcl/source/gdi/bitmapex.cxx
@@ -748,17 +748,20 @@ sal_uInt8 BitmapEx::GetTransparency(sal_Int32 nX, sal_Int32 nY) const
 Color BitmapEx::GetPixelColor(sal_Int32 nX, sal_Int32 nY) const
 {
     Bitmap::ScopedReadAccess pReadAccess( const_cast<Bitmap&>(maBitmap) );
-    assert( pReadAccess );
+    assert(pReadAccess);
 
-    Color aColor = pReadAccess->GetColor( nY, nX ).GetColor();
+    Color aColor = pReadAccess->GetColor(nY, nX).GetColor();
 
-    if( IsAlpha() )
+    if (IsAlpha())
     {
-        Bitmap::ScopedReadAccess pAlphaReadAccess( const_cast<Bitmap&>(maMask).AcquireReadAccess(), const_cast<Bitmap&>(maMask) );
-        aColor.SetTransparency( pAlphaReadAccess->GetPixel( nY, nX ).GetIndex() );
+        AlphaMask aAlpha = GetAlpha();
+        AlphaMask::ScopedReadAccess pAlphaReadAccess(aAlpha);
+        aColor.SetTransparency(pAlphaReadAccess->GetPixel(nY, nX).GetIndex());
+    }
+    else if (maBitmap.GetBitCount() != 32)
+    {
+        aColor.SetTransparency(0);
     }
-    else
-        aColor.SetTransparency( 0 );
     return aColor;
 }
 


More information about the Libreoffice-commits mailing list