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

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Wed Feb 13 21:39:58 UTC 2019


 vcl/qa/cppunit/BitmapProcessorTest.cxx          |   51 ++++++++++++---
 vcl/source/bitmap/BitmapDisabledImageFilter.cxx |   78 +++++-------------------
 2 files changed, 58 insertions(+), 71 deletions(-)

New commits:
commit b43976324f4f8e003b80ce422eb393010d8a101e
Author:     Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
AuthorDate: Wed Feb 13 21:26:18 2019 +0100
Commit:     Tomaž Vajngerl <quikee at gmail.com>
CommitDate: Wed Feb 13 22:39:28 2019 +0100

    Improve the algorithm of disabled image creation
    
    Main change is to not change alpha channel at all. For RGB
    channels, calculate the luma value and map the value into 160-224
    range. Much simpler and better result.
    
    Change-Id: Ied108c2135f98d78f230a2c0b305bd3396d9ccfd
    Reviewed-on: https://gerrit.libreoffice.org/67791
    Tested-by: Jenkins
    Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>

diff --git a/vcl/qa/cppunit/BitmapProcessorTest.cxx b/vcl/qa/cppunit/BitmapProcessorTest.cxx
index fe49184c3302..fa0ccc5fc638 100644
--- a/vcl/qa/cppunit/BitmapProcessorTest.cxx
+++ b/vcl/qa/cppunit/BitmapProcessorTest.cxx
@@ -39,20 +39,51 @@ class BitmapProcessorTest : public CppUnit::TestFixture
 
 void BitmapProcessorTest::testDisabledImage()
 {
-    Bitmap aBitmap(Size(3, 3), 24);
     {
-        BitmapScopedWriteAccess pWriteAccess(aBitmap);
-        pWriteAccess->Erase(Color(0x00, 0x11, 0x22, 0x33));
+        Bitmap aBitmap(Size(3, 3), 24);
+        {
+            BitmapScopedWriteAccess pWriteAccess(aBitmap);
+            pWriteAccess->Erase(Color(0x00, 0x00, 0xFF, 0x00));
+        }
+        BitmapEx aBitmapEx(aBitmap);
+        BitmapDisabledImageFilter aDisabledImageFilter;
+        BitmapEx aDisabledBitmapEx(aDisabledImageFilter.execute(aBitmapEx));
+        Bitmap aDisabledBitmap(aDisabledBitmapEx.GetBitmap());
+        {
+            Bitmap::ScopedReadAccess pReadAccess(aDisabledBitmap);
+            Color aColor(pReadAccess->GetPixel(0, 0).GetColor());
+            CPPUNIT_ASSERT_EQUAL(Color(0x00C5C5C5), aColor);
+        }
     }
-    BitmapEx aBitmapEx(aBitmap);
-    BitmapDisabledImageFilter aDisabledImageFilter;
-    BitmapEx aDisabledBitmapEx(aDisabledImageFilter.execute(aBitmapEx));
-    Bitmap aDisabledBitmap(aDisabledBitmapEx.GetBitmap());
 
     {
-        Bitmap::ScopedReadAccess pReadAccess(aDisabledBitmap);
-        Color aColor(pReadAccess->GetPixel(0, 0).GetColor());
-        CPPUNIT_ASSERT_EQUAL(Color(0x001E1E1E), aColor);
+        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);
+        BitmapDisabledImageFilter aDisabledImageFilter;
+        BitmapEx aDisabledBitmapEx(aDisabledImageFilter.execute(aBitmapEx));
+
+        Bitmap aDisabledBitmap(aDisabledBitmapEx.GetBitmap());
+        {
+            Bitmap::ScopedReadAccess pReadAccess(aDisabledBitmap);
+            Color aColor(pReadAccess->GetPixel(0, 0).GetColor());
+            CPPUNIT_ASSERT_EQUAL(Color(0x00C5C5C5), aColor);
+        }
+        AlphaMask aDisabledAlphaMask(aDisabledBitmapEx.GetAlpha());
+        {
+            AlphaMask::ScopedReadAccess pReadAccess(aDisabledAlphaMask);
+            Color aColor(pReadAccess->GetPixel(0, 0).GetColor());
+            CPPUNIT_ASSERT_EQUAL(Color(0x0000AA), aColor);
+        }
     }
 }
 
diff --git a/vcl/source/bitmap/BitmapDisabledImageFilter.cxx b/vcl/source/bitmap/BitmapDisabledImageFilter.cxx
index 3529f7e67dc2..56f46b313159 100644
--- a/vcl/source/bitmap/BitmapDisabledImageFilter.cxx
+++ b/vcl/source/bitmap/BitmapDisabledImageFilter.cxx
@@ -24,82 +24,38 @@ BitmapEx BitmapDisabledImageFilter::execute(BitmapEx const& rBitmapEx) const
     sal_uInt16 nBitCount = rBitmapEx.GetBitCount();
     if (nBitCount < 8)
         nBitCount = 8;
+
     const BitmapPalette* pPal = nBitCount == 8 ? &Bitmap::GetGreyPalette(256) : nullptr;
     Bitmap aGrey(aSize, nBitCount, pPal);
-
-    AlphaMask aGreyAlpha(aSize);
-
-    Bitmap aBitmap(rBitmapEx.GetBitmap());
-    Bitmap::ScopedReadAccess pRead(aBitmap);
-
     BitmapScopedWriteAccess pGrey(aGrey);
-    AlphaScopedWriteAccess pGreyAlpha(aGreyAlpha);
 
     BitmapEx aReturnBitmap;
-
-    if (rBitmapEx.IsTransparent())
+    Bitmap aReadBitmap(rBitmapEx.GetBitmap());
+    Bitmap::ScopedReadAccess pRead(aReadBitmap);
+    if (pRead && pGrey)
     {
-        AlphaMask aBitmapAlpha(rBitmapEx.GetAlpha());
-        AlphaMask::ScopedReadAccess pReadAlpha(aBitmapAlpha);
-
-        if (pRead && pReadAlpha && pGrey && pGreyAlpha)
+        for (long nY = 0; nY < aSize.Height(); ++nY)
         {
-            BitmapColor aGreyAlphaValue(0);
+            Scanline pGreyScan = pGrey->GetScanline(nY);
+            Scanline pReadScan = pRead->GetScanline(nY);
 
-            for (long nY = 0; nY < aSize.Height(); ++nY)
+            for (long nX = 0; nX < aSize.Width(); ++nX)
             {
-                Scanline pScanAlpha = pGreyAlpha->GetScanline(nY);
-                Scanline pScanline = pGrey->GetScanline(nY);
-                Scanline pScanReadAlpha = pReadAlpha->GetScanline(nY);
-
-                for (long nX = 0; nX < aSize.Width(); ++nX)
-                {
-                    const sal_uInt8 nLum(pRead->GetLuminance(nY, nX));
-                    BitmapColor aGreyValue(nLum, nLum, nLum);
-                    pGrey->SetPixelOnData(pScanline, nX, aGreyValue);
-
-                    const BitmapColor aBitmapAlphaValue(
-                        pReadAlpha->GetPixelFromData(pScanReadAlpha, nX));
-
-                    aGreyAlphaValue.SetIndex(
-                        sal_uInt8(std::min(aBitmapAlphaValue.GetIndex() + 178ul, 255ul)));
-                    pGreyAlpha->SetPixelOnData(pScanAlpha, nX, aGreyAlphaValue);
-                }
+                // Get the luminance from RGB color and remap the value from 0-255 to 160-224
+                const BitmapColor aColor = pRead->GetPixelFromData(pReadScan, nX);
+                sal_uInt8 nLum(aColor.GetLuminance() / 4 + 160);
+                BitmapColor aGreyValue(nLum, nLum, nLum);
+                pGrey->SetPixelOnData(pGreyScan, nX, aGreyValue);
             }
         }
+    }
 
-        pReadAlpha.reset();
-        aReturnBitmap = BitmapEx(aGrey, aGreyAlpha);
+    if (rBitmapEx.IsTransparent())
+    {
+        aReturnBitmap = BitmapEx(aGrey, rBitmapEx.GetAlpha());
     }
     else
-    {
-        if (pRead && pGrey && pGreyAlpha)
-        {
-            BitmapColor aGreyAlphaValue(0);
-
-            for (long nY = 0; nY < aSize.Height(); ++nY)
-            {
-                Scanline pScanAlpha = pGreyAlpha->GetScanline(nY);
-                Scanline pScanline = pGrey->GetScanline(nY);
-
-                for (long nX = 0; nX < aSize.Width(); ++nX)
-                {
-                    const sal_uInt8 nLum(pRead->GetLuminance(nY, nX));
-                    BitmapColor aGreyValue(nLum, nLum, nLum);
-                    pGrey->SetPixelOnData(pScanline, nX, aGreyValue);
-
-                    aGreyAlphaValue.SetIndex(128);
-                    pGreyAlpha->SetPixelOnData(pScanAlpha, nX, aGreyAlphaValue);
-                }
-            }
-        }
-
         aReturnBitmap = BitmapEx(aGrey);
-    }
-
-    pRead.reset();
-    pGrey.reset();
-    pGreyAlpha.reset();
 
     return aReturnBitmap;
 }


More information about the Libreoffice-commits mailing list