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

Tomaž Vajngerl (via logerrit) logerrit at kemper.freedesktop.org
Fri Apr 19 02:40:37 UTC 2019


 vcl/qa/cppunit/svm/svmtest.cxx |  192 +++++++++++++++++++++++++++++++++++------
 1 file changed, 164 insertions(+), 28 deletions(-)

New commits:
commit 68bc7b4795d72e9e099219d1e933e6843b7813d1
Author:     Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
AuthorDate: Thu Apr 18 19:25:03 2019 +0900
Commit:     Tomaž Vajngerl <quikee at gmail.com>
CommitDate: Fri Apr 19 04:40:00 2019 +0200

    vcl: extend SVM (MetaFile) BitmapEx tests
    
    Change-Id: I92ce3bbcd7e7d52c53b70a1b9339c2e110c2ccbb
    Reviewed-on: https://gerrit.libreoffice.org/70926
    Tested-by: Jenkins
    Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>

diff --git a/vcl/qa/cppunit/svm/svmtest.cxx b/vcl/qa/cppunit/svm/svmtest.cxx
index 37a6d36ab67d..f1347447c227 100644
--- a/vcl/qa/cppunit/svm/svmtest.cxx
+++ b/vcl/qa/cppunit/svm/svmtest.cxx
@@ -14,6 +14,7 @@
 #include <vcl/virdev.hxx>
 #include <vcl/bitmapaccess.hxx>
 #include <bitmapwriteaccess.hxx>
+#include <vcl/pngwrite.hxx>
 
 #include <config_features.h>
 #if HAVE_FEATURE_OPENGL
@@ -31,6 +32,8 @@ class SvmTest : public test::BootstrapFixture, public XmlTestTools
         return m_directories.getURLFromSrc(maDataUrl) + sFileName;
     }*/
 
+    void checkRendering(ScopedVclPtrInstance<VirtualDevice> const & pVirtualDev, const GDIMetaFile& rMetaFile);
+
     xmlDocPtr dumpMeta(const GDIMetaFile& rMetaFile);
 
     void checkVirtualDevice(xmlDocPtr pDoc);
@@ -155,6 +158,34 @@ static void setupBaseVirtualDevice(VirtualDevice& rDevice, GDIMetaFile& rMeta)
     rDevice.Erase();
 }
 
+void SvmTest::checkRendering(ScopedVclPtrInstance<VirtualDevice> const & pVirtualDev, const GDIMetaFile& rMetaFile)
+{
+    BitmapEx aSourceBitmapEx = pVirtualDev->GetBitmapEx(Point(), Size(10, 10));
+    ScopedVclPtrInstance<VirtualDevice> pVirtualDevResult;
+    const_cast<GDIMetaFile&>(rMetaFile).Play(pVirtualDevResult.get());
+    BitmapEx aResultBitmapEx = pVirtualDev->GetBitmapEx(Point(), Size(10, 10));
+
+    const bool bWriteCompareBitmap = false;
+
+    if (bWriteCompareBitmap)
+    {
+        utl::TempFile aTempFile;
+        aTempFile.EnableKillingFile();
+
+        {
+            SvFileStream aStream(aTempFile.GetURL() + ".source.png", StreamMode::WRITE | StreamMode::TRUNC);
+            vcl::PNGWriter aPNGWriter(aSourceBitmapEx);
+            aPNGWriter.Write(aStream);
+        }
+        {
+            SvFileStream aStream(aTempFile.GetURL() + ".result.png", StreamMode::WRITE | StreamMode::TRUNC);
+            vcl::PNGWriter aPNGWriter(aResultBitmapEx);
+            aPNGWriter.Write(aStream);
+        }
+    }
+    CPPUNIT_ASSERT_EQUAL(aSourceBitmapEx.GetChecksum(), aResultBitmapEx.GetChecksum());
+}
+
 static GDIMetaFile readMetafile(const OUString& rUrl)
 {
     SvFileStream aFileStream(rUrl, StreamMode::READ);
@@ -823,30 +854,69 @@ void SvmTest::checkBitmapExs(const GDIMetaFile& rMetaFile)
 {
     xmlDocPtr pDoc = dumpMeta(rMetaFile);
 
-    OUString crc1 = "b8dee5da";
-    OUString crc2 = "281fc589";
-    OUString crc3 = "5e01ddcc";
+    std::vector<OUString> aExpectedCRC;
+
 #if HAVE_FEATURE_OPENGL
     if (OpenGLHelper::isVCLOpenGLEnabled())
     {
-        crc1 = "5e01ddcc";
-        crc2 = "281fc589";
-        crc3 = "b8dee5da";
+        aExpectedCRC.insert(aExpectedCRC.end(),
+        {
+            "08feb5d3",
+            "281fc589",
+            "b8dee5da",
+            "4df0e464",
+            "7d3a8da3",
+            "1426653b",
+            "4fd547df",
+            "71efc447",
+        });
     }
+    else
 #endif
+    {
+        aExpectedCRC.insert(aExpectedCRC.end(),
+        {
+            "d8377d4f",
+            "281fc589",
+            "5e01ddcc",
+            "4df0e464",
+            "34434a50",
+            "d1736327",
+            "b37875c2",
+            "a85d44b8",
+        });
+    }
 
     assertXPathAttrs(pDoc, "/metafile/bmpex[1]", {
-        {"x", "1"}, {"y", "2"}, {"crc", crc1}, {"transparenttype", "bitmap"}
+        {"x", "1"}, {"y", "1"}, {"crc", aExpectedCRC[0]}, {"transparenttype", "bitmap"}
     });
     assertXPathAttrs(pDoc, "/metafile/bmpexscale[1]", {
-        {"x", "1"}, {"y", "2"}, {"width", "3"}, {"height", "4"},
-        {"crc", crc2}, {"transparenttype", "bitmap"}
+        {"x", "5"}, {"y", "0"}, {"width", "2"}, {"height", "3"},
+        {"crc", aExpectedCRC[1]}, {"transparenttype", "bitmap"}
     });
     assertXPathAttrs(pDoc, "/metafile/bmpexscalepart[1]", {
-        {"destx", "1"}, {"desty", "2"}, {"destwidth", "3"}, {"destheight", "4"},
-        {"srcx", "2"},  {"srcy", "1"},  {"srcwidth", "4"},  {"srcheight", "3"},
-        {"crc", crc3}, {"transparenttype", "bitmap"}
+        {"destx", "7"}, {"desty", "1"}, {"destwidth", "2"}, {"destheight", "2"},
+        {"srcx", "0"},  {"srcy", "0"},  {"srcwidth", "3"},  {"srcheight", "4"},
+        {"crc", aExpectedCRC[2]}, {"transparenttype", "bitmap"}
+    });
+
+#ifndef MACOSX
+    assertXPathAttrs(pDoc, "/metafile/bmpex[2]", {
+        {"x", "6"}, {"y", "6"}, {"crc", aExpectedCRC[3]}, {"transparenttype", "bitmap"}
+    });
+    assertXPathAttrs(pDoc, "/metafile/bmpex[3]", {
+        {"x", "0"}, {"y", "6"}, {"crc", aExpectedCRC[4]}, {"transparenttype", "bitmap"}
+    });
+    assertXPathAttrs(pDoc, "/metafile/bmpex[4]", {
+        {"x", "2"}, {"y", "6"}, {"crc", aExpectedCRC[5]}, {"transparenttype", "bitmap"}
+    });
+    assertXPathAttrs(pDoc, "/metafile/bmpex[5]", {
+        {"x", "0"}, {"y", "8"}, {"crc", aExpectedCRC[6]}, {"transparenttype", "bitmap"}
     });
+    assertXPathAttrs(pDoc, "/metafile/bmpex[6]", {
+        {"x", "2"}, {"y", "8"}, {"crc", aExpectedCRC[7]}, {"transparenttype", "bitmap"}
+    });
+#endif
 }
 
 void SvmTest::testBitmapExs()
@@ -855,32 +925,98 @@ void SvmTest::testBitmapExs()
     ScopedVclPtrInstance<VirtualDevice> pVirtualDev;
     setupBaseVirtualDevice(*pVirtualDev, aGDIMetaFile);
 
-    Bitmap aBitmap1(Size(4,4), 24);
+    // DrawBitmapEx
     {
-        BitmapScopedWriteAccess pAccess(aBitmap1);
-        pAccess->Erase(COL_RED);
+        Bitmap aBitmap(Size(4,4), 24);
+        {
+            BitmapScopedWriteAccess pAccess(aBitmap);
+            pAccess->Erase(COL_YELLOW);
+        }
+
+        pVirtualDev->DrawBitmapEx(Point(1, 1), BitmapEx(aBitmap, COL_WHITE));
     }
-    BitmapEx aBitmapEx1(aBitmap1, COL_YELLOW);
 
-    Bitmap aBitmap2(Size(4,4), 24);
+    // DrawBitmapEx - Scale
     {
-        BitmapScopedWriteAccess pAccess(aBitmap2);
-        pAccess->Erase(COL_GREEN);
+        Bitmap aBitmap(Size(4,4), 24);
+        {
+            BitmapScopedWriteAccess pAccess(aBitmap);
+            pAccess->Erase(COL_GREEN);
+        }
+        pVirtualDev->DrawBitmapEx(Point(5, 0), Size(2, 3), BitmapEx(aBitmap, COL_WHITE));
     }
-    BitmapEx aBitmapEx2(aBitmap2, COL_YELLOW);
 
-    Bitmap aBitmap3(Size(4,4), 24);
+    // DrawBitmapEx - Scale - Part
     {
-        BitmapScopedWriteAccess pAccess(aBitmap3);
-        pAccess->Erase(COL_BLUE);
+        Bitmap aBitmap(Size(4,4), 24);
+        {
+            BitmapScopedWriteAccess pAccess(aBitmap);
+            pAccess->Erase(COL_BLUE);
+        }
+        pVirtualDev->DrawBitmapEx(Point(7, 1), Size(2, 2), Point(0, 0), Size(3, 4), BitmapEx(aBitmap, COL_WHITE));
+    }
+
+    // DrawBitmapEx - 50% transparent
+    {
+        Bitmap aBitmap(Size(4, 4), 24);
+        AlphaMask aAlpha(Size(4, 4));
+        {
+            BitmapScopedWriteAccess pAccess(aBitmap);
+            pAccess->Erase(COL_MAGENTA);
+
+            AlphaScopedWriteAccess pAlphaAccess(aAlpha);
+            pAlphaAccess->Erase(Color(128, 128, 128));
+        }
+        pVirtualDev->DrawBitmapEx(Point(6, 6), BitmapEx(aBitmap, aAlpha));
     }
-    BitmapEx aBitmapEx3(aBitmap3, COL_YELLOW);
 
-    pVirtualDev->DrawBitmapEx(Point(1, 2), aBitmapEx1);
-    pVirtualDev->DrawBitmapEx(Point(1, 2), Size(3, 4), aBitmapEx2);
-    pVirtualDev->DrawBitmapEx(Point(1, 2), Size(3, 4), Point(2, 1), Size(4, 3), aBitmapEx3);
+    // DrawBitmapEx - 1-bit
+    {
+        Bitmap aBitmap(Size(2, 2), 24);
+        {
+            BitmapScopedWriteAccess pAccess(aBitmap);
+            pAccess->Erase(COL_MAGENTA);
+        }
+        aBitmap.Convert(BmpConversion::N1BitThreshold);
+        pVirtualDev->DrawBitmapEx(Point(0, 6), BitmapEx(aBitmap, COL_WHITE));
+    }
+
+    // DrawBitmapEx - 4-bit
+    {
+        Bitmap aBitmap(Size(2, 2), 24);
+        {
+            BitmapScopedWriteAccess pAccess(aBitmap);
+            pAccess->Erase(COL_MAGENTA);
+        }
+        aBitmap.Convert(BmpConversion::N4BitColors);
+        pVirtualDev->DrawBitmapEx(Point(2, 6), BitmapEx(aBitmap, COL_WHITE));
+    }
+
+    // DrawBitmapEx - 8-bit Color
+    {
+        Bitmap aBitmap(Size(2, 2), 24);
+        {
+            BitmapScopedWriteAccess pAccess(aBitmap);
+            pAccess->Erase(COL_MAGENTA);
+        }
+        aBitmap.Convert(BmpConversion::N8BitColors);
+        pVirtualDev->DrawBitmapEx(Point(0, 8), BitmapEx(aBitmap, COL_WHITE));
+    }
+
+    // DrawBitmapEx - 8-bit Grey
+    {
+        Bitmap aBitmap(Size(2, 2), 24);
+        {
+            BitmapScopedWriteAccess pAccess(aBitmap);
+            pAccess->Erase(COL_MAGENTA);
+        }
+        aBitmap.Convert(BmpConversion::N8BitGreys);
+        pVirtualDev->DrawBitmapEx(Point(2, 8), BitmapEx(aBitmap, COL_WHITE));
+    }
 
-    checkBitmapExs(writeAndRead(aGDIMetaFile, "bitmapexs.svm"));
+    GDIMetaFile aReloadedGDIMetaFile = writeAndRead(aGDIMetaFile, "bitmapexs.svm");
+    checkBitmapExs(aReloadedGDIMetaFile);
+    checkRendering(pVirtualDev, aReloadedGDIMetaFile);
 }
 
 void SvmTest::checkMasks(const GDIMetaFile& rMetaFile)


More information about the Libreoffice-commits mailing list