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

Noel (via logerrit) logerrit at kemper.freedesktop.org
Wed Mar 31 07:23:07 UTC 2021


 include/vcl/bitmap.hxx                       |    4 -
 include/vcl/bitmap/BitmapTypes.hxx           |    4 -
 vcl/qa/cppunit/BitmapTest.cxx                |   62 ---------------------------
 vcl/qa/cppunit/canvasbitmaptest.cxx          |    1 
 vcl/qa/cppunit/svm/svmtest.cxx               |    4 -
 vcl/source/bitmap/BitmapEmbossGreyFilter.cxx |    2 
 vcl/source/bitmap/BitmapSobelGreyFilter.cxx  |    2 
 vcl/source/bitmap/bitmap.cxx                 |   45 +++----------------
 vcl/source/bitmap/bitmappaint.cxx            |    4 -
 vcl/source/gdi/pdfwriter_impl.cxx            |    5 --
 vcl/source/gdi/pdfwriter_impl2.cxx           |    5 --
 vcl/source/helper/canvastools.cxx            |    1 
 12 files changed, 22 insertions(+), 117 deletions(-)

New commits:
commit a6c6f35ccc78e74cfa76397d649c1b6fc4baad29
Author:     Noel <noel.grandin at collabora.co.uk>
AuthorDate: Mon Mar 29 14:23:16 2021 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Wed Mar 31 09:22:27 2021 +0200

    drop 4bpp image formats
    
    on a path to simplifying our internal bitmap stuff, aiming to
    support a smaller set of image formats, but support them
    in an accelerated fashion.
    
    Change-Id: I5f8bf3cd49abf16ce460771492cdd5f358cb34df
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/113313
    Tested-by: Noel Grandin <noel.grandin at collabora.co.uk>
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/include/vcl/bitmap.hxx b/include/vcl/bitmap.hxx
index 1bfc484fee5b..eaec09ad7037 100644
--- a/include/vcl/bitmap.hxx
+++ b/include/vcl/bitmap.hxx
@@ -72,8 +72,6 @@ enum class BmpConversion
 {
     NNONE,
     N1BitThreshold,
-    N4BitGreys,
-    N4BitColors,
     N8BitGreys,
     N8BitColors,
     N24Bit,
@@ -526,7 +524,7 @@ public:
     const std::shared_ptr<SalBitmap>& ImplGetSalBitmap() const { return mxSalBmp; }
     SAL_DLLPRIVATE void     ImplSetSalBitmap( const std::shared_ptr<SalBitmap>& xImpBmp );
 
-    SAL_DLLPRIVATE bool     ImplMakeGreyscales( sal_uInt16 nGreyscales );
+    SAL_DLLPRIVATE bool     ImplMakeGreyscales();
 
 public:
 
diff --git a/include/vcl/bitmap/BitmapTypes.hxx b/include/vcl/bitmap/BitmapTypes.hxx
index 866cf0b2950e..7ebf9fc8dafc 100644
--- a/include/vcl/bitmap/BitmapTypes.hxx
+++ b/include/vcl/bitmap/BitmapTypes.hxx
@@ -17,7 +17,6 @@ enum class PixelFormat
 {
     INVALID = 0,
     N1_BPP = 1,
-    N4_BPP = 4,
     N8_BPP = 8,
     N24_BPP = 24,
     N32_BPP = 32
@@ -37,7 +36,8 @@ constexpr PixelFormat bitDepthToPixelFormat(sal_uInt16 nBitDepth)
         case 1:
             return PixelFormat::N1_BPP;
         case 4:
-            return PixelFormat::N4_BPP;
+            assert(false);
+            break;
         case 8:
             return PixelFormat::N8_BPP;
         case 24:
diff --git a/vcl/qa/cppunit/BitmapTest.cxx b/vcl/qa/cppunit/BitmapTest.cxx
index 4a7cc5cc0477..655e76dc21fc 100644
--- a/vcl/qa/cppunit/BitmapTest.cxx
+++ b/vcl/qa/cppunit/BitmapTest.cxx
@@ -34,7 +34,6 @@ class BitmapTest : public CppUnit::TestFixture
     void testCreation();
     void testEmpty();
     void testMonochrome();
-    void testN4Greyscale();
     void testN8Greyscale();
     void testConvert();
     void testCRC();
@@ -52,7 +51,6 @@ class BitmapTest : public CppUnit::TestFixture
     CPPUNIT_TEST(testEmpty);
     CPPUNIT_TEST(testMonochrome);
     CPPUNIT_TEST(testConvert);
-    CPPUNIT_TEST(testN4Greyscale);
     CPPUNIT_TEST(testN8Greyscale);
     CPPUNIT_TEST(testCRC);
     CPPUNIT_TEST(testGreyPalette);
@@ -112,20 +110,6 @@ void BitmapTest::testCreation()
                                      aBmp.GetSizeBytes());
     }
 
-    {
-        Bitmap aBmp(Size(10, 10), vcl::PixelFormat::N4_BPP);
-        Size aSize = aBmp.GetSizePixel();
-        CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong width", static_cast<tools::Long>(10), aSize.Width());
-        CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong height", static_cast<tools::Long>(10), aSize.Height());
-        CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong pref size", Size(), aBmp.GetPrefSize());
-        CPPUNIT_ASSERT_MESSAGE("Empty bitmap", !aBmp.IsEmpty());
-        CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong bit count", static_cast<sal_uInt16>(4),
-                                     aBmp.GetBitCount());
-        CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong color count", sal_Int64(16), aBmp.GetColorCount());
-        CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong byte size", static_cast<sal_uLong>(50),
-                                     aBmp.GetSizeBytes());
-    }
-
     {
         Bitmap aBmp(Size(10, 10), vcl::PixelFormat::N8_BPP);
         Size aSize = aBmp.GetSizePixel();
@@ -260,48 +244,6 @@ void BitmapTest::testMonochrome()
                                  aBmpReadAccess.GetColor(3, 3));
 }
 
-void BitmapTest::testN4Greyscale()
-{
-    Bitmap aBmp = createTestBitmap();
-    BitmapPalette aGreyscalePalette = Bitmap::GetGreyPalette(16);
-
-    aBmp.Convert(BmpConversion::N4BitGreys);
-    BitmapReadAccess aBmpReadAccess(aBmp);
-
-    CPPUNIT_ASSERT_EQUAL_MESSAGE("Black pixel wrong 8-bit greyscale value", aGreyscalePalette[0],
-                                 aBmpReadAccess.GetColor(0, 0));
-    CPPUNIT_ASSERT_EQUAL_MESSAGE("Blue pixel wrong 8-bit greyscale value", aGreyscalePalette[0],
-                                 aBmpReadAccess.GetColor(0, 1));
-    CPPUNIT_ASSERT_EQUAL_MESSAGE("Green pixel wrong 8-bit greyscale value", aGreyscalePalette[4],
-                                 aBmpReadAccess.GetColor(0, 2));
-    CPPUNIT_ASSERT_EQUAL_MESSAGE("Cyan pixel wrong 8-bit greyscale value", aGreyscalePalette[5],
-                                 aBmpReadAccess.GetColor(0, 3));
-    CPPUNIT_ASSERT_EQUAL_MESSAGE("Red pixel wrong 8-bit greyscale value", aGreyscalePalette[2],
-                                 aBmpReadAccess.GetColor(1, 0));
-    CPPUNIT_ASSERT_EQUAL_MESSAGE("Magenta pixel wrong 8-bit greyscale value", aGreyscalePalette[3],
-                                 aBmpReadAccess.GetColor(1, 1));
-    CPPUNIT_ASSERT_EQUAL_MESSAGE("Brown pixel wrong 8-bit greyscale value", aGreyscalePalette[7],
-                                 aBmpReadAccess.GetColor(1, 2));
-    CPPUNIT_ASSERT_EQUAL_MESSAGE("Gray pixel wrong 8-bit greyscale value", aGreyscalePalette[8],
-                                 aBmpReadAccess.GetColor(1, 3));
-    CPPUNIT_ASSERT_EQUAL_MESSAGE("Light gray pixel wrong 8-bit greyscale value",
-                                 aGreyscalePalette[12], aBmpReadAccess.GetColor(2, 0));
-    CPPUNIT_ASSERT_EQUAL_MESSAGE("Light blue pixel wrong 8-bit greyscale value",
-                                 aGreyscalePalette[1], aBmpReadAccess.GetColor(2, 1));
-    CPPUNIT_ASSERT_EQUAL_MESSAGE("Light green pixel wrong 8-bit greyscale value",
-                                 aGreyscalePalette[9], aBmpReadAccess.GetColor(2, 2));
-    CPPUNIT_ASSERT_EQUAL_MESSAGE("Light cyan pixel wrong 8-bit greyscale value",
-                                 aGreyscalePalette[11], aBmpReadAccess.GetColor(2, 3));
-    CPPUNIT_ASSERT_EQUAL_MESSAGE("Light red pixel wrong 8-bit greyscale value",
-                                 aGreyscalePalette[4], aBmpReadAccess.GetColor(3, 0));
-    CPPUNIT_ASSERT_EQUAL_MESSAGE("Light magenta pixel wrong 8-bit greyscale value",
-                                 aGreyscalePalette[6], aBmpReadAccess.GetColor(3, 1));
-    CPPUNIT_ASSERT_EQUAL_MESSAGE("Yellow pixel wrong 8-bit greyscale value", aGreyscalePalette[14],
-                                 aBmpReadAccess.GetColor(3, 2));
-    CPPUNIT_ASSERT_EQUAL_MESSAGE("White pixel wrong 8-bit greyscale value", aGreyscalePalette[15],
-                                 aBmpReadAccess.GetColor(3, 3));
-}
-
 void BitmapTest::testN8Greyscale()
 {
     Bitmap aBmp = createTestBitmap();
@@ -686,8 +628,8 @@ void BitmapTest::testDitherSize()
 
 void BitmapTest::testMirror()
 {
-    vcl::PixelFormat bppArray[] = { vcl::PixelFormat::N4_BPP, vcl::PixelFormat::N8_BPP,
-                                    vcl::PixelFormat::N24_BPP, vcl::PixelFormat::N32_BPP };
+    vcl::PixelFormat bppArray[]
+        = { vcl::PixelFormat::N8_BPP, vcl::PixelFormat::N24_BPP, vcl::PixelFormat::N32_BPP };
 
     for (vcl::PixelFormat bpp : bppArray)
     {
diff --git a/vcl/qa/cppunit/canvasbitmaptest.cxx b/vcl/qa/cppunit/canvasbitmaptest.cxx
index a741814adb41..cfa6b418c958 100644
--- a/vcl/qa/cppunit/canvasbitmaptest.cxx
+++ b/vcl/qa/cppunit/canvasbitmaptest.cxx
@@ -636,7 +636,6 @@ void CanvasBitmapTest::runTest()
     static vcl::PixelFormat ePixelFormatArray[] =
     {
         vcl::PixelFormat::N1_BPP,
-        vcl::PixelFormat::N4_BPP,
         vcl::PixelFormat::N8_BPP,
         vcl::PixelFormat::N24_BPP
     };
diff --git a/vcl/qa/cppunit/svm/svmtest.cxx b/vcl/qa/cppunit/svm/svmtest.cxx
index 29254fe9c323..d9687cb135f1 100644
--- a/vcl/qa/cppunit/svm/svmtest.cxx
+++ b/vcl/qa/cppunit/svm/svmtest.cxx
@@ -1084,14 +1084,14 @@ void SvmTest::testBitmapExs()
         pVirtualDev->DrawBitmapEx(Point(0, 6), BitmapEx(aBitmap, COL_WHITE));
     }
 
-    // DrawBitmapEx - 4-bit
+    // DrawBitmapEx - used to be 4-bit
     {
         Bitmap aBitmap(Size(2, 2), vcl::PixelFormat::N24_BPP);
         {
             BitmapScopedWriteAccess pAccess(aBitmap);
             pAccess->Erase(COL_MAGENTA);
         }
-        aBitmap.Convert(BmpConversion::N4BitColors);
+        aBitmap.Convert(BmpConversion::N8BitColors);
         pVirtualDev->DrawBitmapEx(Point(2, 6), BitmapEx(aBitmap, COL_WHITE));
     }
 
diff --git a/vcl/source/bitmap/BitmapEmbossGreyFilter.cxx b/vcl/source/bitmap/BitmapEmbossGreyFilter.cxx
index af8e5e9914ba..0ace97a9b630 100644
--- a/vcl/source/bitmap/BitmapEmbossGreyFilter.cxx
+++ b/vcl/source/bitmap/BitmapEmbossGreyFilter.cxx
@@ -24,7 +24,7 @@ BitmapEx BitmapEmbossGreyFilter::execute(BitmapEx const& rBitmapEx) const
 {
     Bitmap aBitmap(rBitmapEx.GetBitmap());
 
-    bool bRet = aBitmap.ImplMakeGreyscales(256);
+    bool bRet = aBitmap.ImplMakeGreyscales();
 
     if (bRet)
     {
diff --git a/vcl/source/bitmap/BitmapSobelGreyFilter.cxx b/vcl/source/bitmap/BitmapSobelGreyFilter.cxx
index 74e8c233d225..c11fcbd3ad02 100644
--- a/vcl/source/bitmap/BitmapSobelGreyFilter.cxx
+++ b/vcl/source/bitmap/BitmapSobelGreyFilter.cxx
@@ -22,7 +22,7 @@ BitmapEx BitmapSobelGreyFilter::execute(BitmapEx const& rBitmapEx) const
 {
     Bitmap aBitmap(rBitmapEx.GetBitmap());
 
-    bool bRet = aBitmap.ImplMakeGreyscales(256);
+    bool bRet = aBitmap.ImplMakeGreyscales();
 
     if (bRet)
     {
diff --git a/vcl/source/bitmap/bitmap.cxx b/vcl/source/bitmap/bitmap.cxx
index ab83d18bd004..e9bf5554169c 100644
--- a/vcl/source/bitmap/bitmap.cxx
+++ b/vcl/source/bitmap/bitmap.cxx
@@ -92,8 +92,7 @@ Bitmap::Bitmap( const Size& rSizePixel, vcl::PixelFormat ePixelFormat, const Bit
                 aPal[ 0 ] = COL_BLACK;
                 aPal[ 1 ] = COL_WHITE;
             }
-            else if (ePixelFormat == vcl::PixelFormat::N4_BPP ||
-                     ePixelFormat == vcl::PixelFormat::N8_BPP)
+            else if (ePixelFormat == vcl::PixelFormat::N8_BPP)
             {
                 aPal.SetEntryCount(1 << sal_uInt16(ePixelFormat));
                 aPal[ 0 ] = COL_BLACK;
@@ -326,7 +325,7 @@ vcl::PixelFormat Bitmap::getPixelFormat() const
     switch (GetBitCount())
     {
         case 1: return vcl::PixelFormat::N1_BPP;
-        case 4: return vcl::PixelFormat::N4_BPP;
+        case 4: assert(false); break;
         case 8: return vcl::PixelFormat::N8_BPP;
         case 24: return vcl::PixelFormat::N24_BPP;
         case 32: return vcl::PixelFormat::N32_BPP;
@@ -568,8 +567,7 @@ bool Bitmap::CopyPixel( const tools::Rectangle& rRectDst,
                 }
                 else if (nSrcBitCount == 4)
                 {
-                    Convert( BmpConversion::N4BitColors );
-                    nNextIndex = 2;
+                    assert(false);
                 }
 
                 if( nNextIndex )
@@ -998,24 +996,9 @@ bool Bitmap::Convert( BmpConversion eConversion )
         }
         break;
 
-        case BmpConversion::N4BitGreys:
-            bRet = ImplMakeGreyscales( 16 );
-        break;
-
-        case BmpConversion::N4BitColors:
-        {
-            if( nBitCount < 4 )
-                bRet = ImplConvertUp(vcl::PixelFormat::N4_BPP);
-            else if( nBitCount > 4 )
-                bRet = ImplConvertDown(vcl::PixelFormat::N4_BPP);
-            else
-                bRet = true;
-        }
-        break;
-
         case BmpConversion::N8BitGreys:
         case BmpConversion::N8BitNoConversion:
-            bRet = ImplMakeGreyscales( 256 );
+            bRet = ImplMakeGreyscales();
         break;
 
         case BmpConversion::N8BitColors:
@@ -1066,17 +1049,15 @@ bool Bitmap::Convert( BmpConversion eConversion )
     return bRet;
 }
 
-bool Bitmap::ImplMakeGreyscales( sal_uInt16 nGreys )
+bool Bitmap::ImplMakeGreyscales()
 {
-    SAL_WARN_IF( nGreys != 16 && nGreys != 256, "vcl", "Only 16 or 256 greyscales are supported!" );
-
     ScopedReadAccess pReadAcc(*this);
     bool bRet = false;
 
     if( pReadAcc )
     {
-        const BitmapPalette& rPal = GetGreyPalette( nGreys );
-        sal_uLong nShift = ( ( nGreys == 16 ) ? 4UL : 0UL );
+        const BitmapPalette& rPal = GetGreyPalette(256);
+        sal_uLong nShift = 0;
         bool bPalDiffers = !pReadAcc->HasPalette() || ( rPal.GetEntryCount() != pReadAcc->GetPaletteEntryCount() );
 
         if( !bPalDiffers )
@@ -1084,8 +1065,7 @@ bool Bitmap::ImplMakeGreyscales( sal_uInt16 nGreys )
 
         if( bPalDiffers )
         {
-            auto ePixelFormat = nGreys == 16 ? vcl::PixelFormat::N4_BPP
-                                             : vcl::PixelFormat::N8_BPP;
+            const auto ePixelFormat = vcl::PixelFormat::N8_BPP;
             Bitmap aNewBmp(GetSizePixel(), ePixelFormat, &rPal );
             BitmapScopedWriteAccess pWriteAcc(aNewBmp);
 
@@ -1535,14 +1515,7 @@ void Bitmap::AdaptBitCount(Bitmap& rNew) const
         }
         case 4:
         {
-            if(HasGreyPaletteAny())
-            {
-                rNew.Convert(BmpConversion::N4BitGreys);
-            }
-            else
-            {
-                rNew.Convert(BmpConversion::N4BitColors);
-            }
+            assert(false);
             break;
         }
         case 8:
diff --git a/vcl/source/bitmap/bitmappaint.cxx b/vcl/source/bitmap/bitmappaint.cxx
index 6bc60687c164..6acf00fe0cac 100644
--- a/vcl/source/bitmap/bitmappaint.cxx
+++ b/vcl/source/bitmap/bitmappaint.cxx
@@ -933,7 +933,7 @@ bool Bitmap::Replace(const Color& rSearchColor, const Color& rReplaceColor, sal_
     // Bitmaps with 1 bit color depth can cause problems if they have other entries than black/white
     // in their palette
     if (GetBitCount() == 1)
-        Convert(BmpConversion::N4BitColors);
+        Convert(BmpConversion::N8BitColors);
 
     BitmapScopedWriteAccess pAcc(*this);
     bool bRet = false;
@@ -996,7 +996,7 @@ bool Bitmap::Replace(const Color* pSearchColors, const Color* pReplaceColors, si
     // Bitmaps with 1 bit color depth can cause problems if they have other entries than black/white
     // in their palette
     if (GetBitCount() == 1)
-        Convert(BmpConversion::N4BitColors);
+        Convert(BmpConversion::N8BitColors);
 
     BitmapScopedWriteAccess pAcc(*this);
     bool bRet = false;
diff --git a/vcl/source/gdi/pdfwriter_impl.cxx b/vcl/source/gdi/pdfwriter_impl.cxx
index 365204314733..2142aeac8808 100644
--- a/vcl/source/gdi/pdfwriter_impl.cxx
+++ b/vcl/source/gdi/pdfwriter_impl.cxx
@@ -9126,12 +9126,9 @@ const BitmapEmit& PDFWriterImpl::createBitmapEmit( const BitmapEx& i_rBitmap, co
     BitmapEx aBitmap( i_rBitmap );
     if( m_aContext.ColorMode == PDFWriter::DrawGreyscale )
     {
-        BmpConversion eConv = BmpConversion::N8BitGreys;
         int nDepth = aBitmap.GetBitmap().GetBitCount();
-        if( nDepth <= 4 )
-            eConv = BmpConversion::N4BitGreys;
         if( nDepth > 1 )
-            aBitmap.Convert( eConv );
+            aBitmap.Convert( BmpConversion::N8BitGreys );
     }
     BitmapID aID;
     aID.m_aPixelSize        = aBitmap.GetSizePixel();
diff --git a/vcl/source/gdi/pdfwriter_impl2.cxx b/vcl/source/gdi/pdfwriter_impl2.cxx
index 862717adfd4e..1aacbce99934 100644
--- a/vcl/source/gdi/pdfwriter_impl2.cxx
+++ b/vcl/source/gdi/pdfwriter_impl2.cxx
@@ -163,12 +163,9 @@ void PDFWriterImpl::implWriteBitmapEx( const Point& i_rPoint, const Size& i_rSiz
 
     if( m_aContext.ColorMode == PDFWriter::DrawGreyscale )
     {
-        BmpConversion eConv = BmpConversion::N8BitGreys;
         int nDepth = aBitmapEx.GetBitmap().GetBitCount();
-        if( nDepth <= 4 )
-            eConv = BmpConversion::N4BitGreys;
         if( nDepth > 1 )
-            aBitmapEx.Convert( eConv );
+            aBitmapEx.Convert( BmpConversion::N8BitGreys );
     }
     bool bUseJPGCompression = !i_rContext.m_bOnlyLosslessCompression;
     if ( bIsPng || ( aSizePixel.Width() < 32 ) || ( aSizePixel.Height() < 32 ) )
diff --git a/vcl/source/helper/canvastools.cxx b/vcl/source/helper/canvastools.cxx
index 8e837ac069e8..fef5500a8227 100644
--- a/vcl/source/helper/canvastools.cxx
+++ b/vcl/source/helper/canvastools.cxx
@@ -267,7 +267,6 @@ namespace vcl::unotools
                 // normalize bitcount
                 auto ePixelFormat =
                     ( nDepth <= 1 ) ? vcl::PixelFormat::N1_BPP :
-                    ( nDepth <= 4 ) ? vcl::PixelFormat::N4_BPP :
                     ( nDepth <= 8 ) ? vcl::PixelFormat::N8_BPP :
                                       vcl::PixelFormat::N24_BPP;
                 auto eAlphaPixelFormat =


More information about the Libreoffice-commits mailing list