[Libreoffice-commits] core.git: Branch 'feature/drawinglayercore' - include/vcl vcl/CppunitTest_vcl_graphic_test.mk vcl/qa vcl/source

Tomaž Vajngerl (via logerrit) logerrit at kemper.freedesktop.org
Thu Apr 23 14:35:13 UTC 2020


 include/vcl/GraphicNativeMetadata.hxx        |    4 +
 vcl/CppunitTest_vcl_graphic_test.mk          |    1 
 vcl/qa/cppunit/GraphicNativeMetadataTest.cxx |  101 +++++++++++++++++++++++++++
 vcl/qa/cppunit/data/Exif1.jpg                |binary
 vcl/qa/cppunit/data/Exif1_090CW.jpg          |binary
 vcl/qa/cppunit/data/Exif1_180.jpg            |binary
 vcl/qa/cppunit/data/Exif1_270CW.jpg          |binary
 vcl/source/filter/GraphicNativeMetadata.cxx  |   12 ++-
 8 files changed, 114 insertions(+), 4 deletions(-)

New commits:
commit a5ff67f7fb286485e49c04b302cef3400cadcd6c
Author:     Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
AuthorDate: Thu Apr 23 16:22:26 2020 +0200
Commit:     Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
CommitDate: Thu Apr 23 16:34:10 2020 +0200

    vcl: add tests for GraphicNativeMetadata
    
    Test the rotation in JPEG metadata is what we expect.
    
    Change-Id: I5ee2d646a5257d5695c51f37fb6fe795dcb9af50

diff --git a/include/vcl/GraphicNativeMetadata.hxx b/include/vcl/GraphicNativeMetadata.hxx
index 318fb724bf25..3dbd7ff8a7d2 100644
--- a/include/vcl/GraphicNativeMetadata.hxx
+++ b/include/vcl/GraphicNativeMetadata.hxx
@@ -20,6 +20,7 @@
 #pragma once
 
 #include <vcl/graph.hxx>
+#include <tools/stream.hxx>
 
 class VCL_DLLPUBLIC GraphicNativeMetadata final
 {
@@ -30,6 +31,9 @@ public:
     ~GraphicNativeMetadata();
 
     bool read(Graphic const& rGraphic);
+    bool read(SvStream& rStream);
+
+    // counter-clock-wise rotation in permille
     sal_uInt16 getRotation() const { return mRotation; }
 };
 
diff --git a/vcl/CppunitTest_vcl_graphic_test.mk b/vcl/CppunitTest_vcl_graphic_test.mk
index fd5c7aeb039b..a1649124133f 100644
--- a/vcl/CppunitTest_vcl_graphic_test.mk
+++ b/vcl/CppunitTest_vcl_graphic_test.mk
@@ -13,6 +13,7 @@ $(eval $(call gb_CppunitTest_add_exception_objects,vcl_graphic_test, \
     vcl/qa/cppunit/GraphicTest \
     vcl/qa/cppunit/GraphicDescriptorTest \
     vcl/qa/cppunit/GraphicFormatDetectorTest \
+    vcl/qa/cppunit/GraphicNativeMetadataTest \
 ))
 
 $(eval $(call gb_CppunitTest_use_externals,vcl_graphic_test,\
diff --git a/vcl/qa/cppunit/GraphicNativeMetadataTest.cxx b/vcl/qa/cppunit/GraphicNativeMetadataTest.cxx
new file mode 100644
index 000000000000..4fde27f53354
--- /dev/null
+++ b/vcl/qa/cppunit/GraphicNativeMetadataTest.cxx
@@ -0,0 +1,101 @@
+/* -*- 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/extensions/HelperMacros.h>
+#include <unotest/bootstrapfixturebase.hxx>
+
+#include <vcl/GraphicNativeMetadata.hxx>
+#include <vcl/graphicfilter.hxx>
+#include <tools/stream.hxx>
+
+using namespace css;
+
+namespace
+{
+class GraphicNativeMetadataTest : public test::BootstrapFixtureBase
+{
+    OUString getFullUrl(const OUString& sFileName)
+    {
+        return m_directories.getURLFromSrc("/vcl/qa/cppunit/data/") + sFileName;
+    }
+
+    void testReadFromGraphic();
+    void testExifRotationJpeg();
+
+    CPPUNIT_TEST_SUITE(GraphicNativeMetadataTest);
+    CPPUNIT_TEST(testReadFromGraphic);
+    CPPUNIT_TEST(testExifRotationJpeg);
+    CPPUNIT_TEST_SUITE_END();
+};
+
+void GraphicNativeMetadataTest::testReadFromGraphic()
+{
+    SvFileStream aFileStream(getFullUrl("Exif1_180.jpg"), StreamMode::READ);
+    GraphicFilter& rGraphicFilter = GraphicFilter::GetGraphicFilter();
+
+    // don't load the grpahic, but try to get the metadata
+    Graphic aGraphic = rGraphicFilter.ImportUnloadedGraphic(aFileStream);
+
+    {
+        GraphicNativeMetadata aMetadata;
+        aMetadata.read(aFileStream);
+        CPPUNIT_ASSERT_EQUAL(sal_uInt16(1800), aMetadata.getRotation());
+        // just the metadata shouldn't make the graphic available
+        CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable());
+    }
+
+    // now load, and it should still work the same
+    {
+        aGraphic.makeAvailable();
+        CPPUNIT_ASSERT_EQUAL(true, aGraphic.isAvailable());
+
+        GraphicNativeMetadata aMetadata;
+        aMetadata.read(aFileStream);
+        CPPUNIT_ASSERT_EQUAL(sal_uInt16(1800), aMetadata.getRotation());
+    }
+}
+
+void GraphicNativeMetadataTest::testExifRotationJpeg()
+{
+    {
+        // No rotation in metadata
+        SvFileStream aFileStream(getFullUrl("Exif1.jpg"), StreamMode::READ);
+        GraphicNativeMetadata aMetadata;
+        aMetadata.read(aFileStream);
+        CPPUNIT_ASSERT_EQUAL(sal_uInt16(0), aMetadata.getRotation());
+    }
+    {
+        // Rotation 90 degree clock-wise = 270 degree counter-clock-wise
+        SvFileStream aFileStream(getFullUrl("Exif1_090CW.jpg"), StreamMode::READ);
+        GraphicNativeMetadata aMetadata;
+        aMetadata.read(aFileStream);
+        CPPUNIT_ASSERT_EQUAL(sal_uInt16(2700), aMetadata.getRotation());
+    }
+    {
+        // Rotation 180 degree
+        SvFileStream aFileStream(getFullUrl("Exif1_180.jpg"), StreamMode::READ);
+        GraphicNativeMetadata aMetadata;
+        aMetadata.read(aFileStream);
+        CPPUNIT_ASSERT_EQUAL(sal_uInt16(1800), aMetadata.getRotation());
+    }
+    {
+        // Rotation 270 degree clock-wise = 90 degree counter-clock-wise
+        SvFileStream aFileStream(getFullUrl("Exif1_270CW.jpg"), StreamMode::READ);
+        GraphicNativeMetadata aMetadata;
+        aMetadata.read(aFileStream);
+        CPPUNIT_ASSERT_EQUAL(sal_uInt16(900), aMetadata.getRotation());
+    }
+}
+
+} // anonymous namespace
+
+CPPUNIT_TEST_SUITE_REGISTRATION(GraphicNativeMetadataTest);
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/qa/cppunit/data/Exif1.jpg b/vcl/qa/cppunit/data/Exif1.jpg
new file mode 100644
index 000000000000..e2aace2daafb
Binary files /dev/null and b/vcl/qa/cppunit/data/Exif1.jpg differ
diff --git a/vcl/qa/cppunit/data/Exif1_090CW.jpg b/vcl/qa/cppunit/data/Exif1_090CW.jpg
new file mode 100644
index 000000000000..dd13dba4c9e0
Binary files /dev/null and b/vcl/qa/cppunit/data/Exif1_090CW.jpg differ
diff --git a/vcl/qa/cppunit/data/Exif1_180.jpg b/vcl/qa/cppunit/data/Exif1_180.jpg
new file mode 100644
index 000000000000..ba4dfc3796a9
Binary files /dev/null and b/vcl/qa/cppunit/data/Exif1_180.jpg differ
diff --git a/vcl/qa/cppunit/data/Exif1_270CW.jpg b/vcl/qa/cppunit/data/Exif1_270CW.jpg
new file mode 100644
index 000000000000..7f7cdfb909bb
Binary files /dev/null and b/vcl/qa/cppunit/data/Exif1_270CW.jpg differ
diff --git a/vcl/source/filter/GraphicNativeMetadata.cxx b/vcl/source/filter/GraphicNativeMetadata.cxx
index 132a51a52391..6eb60cd67374 100644
--- a/vcl/source/filter/GraphicNativeMetadata.cxx
+++ b/vcl/source/filter/GraphicNativeMetadata.cxx
@@ -18,10 +18,7 @@
  */
 
 #include <vcl/GraphicNativeMetadata.hxx>
-
 #include <vcl/gfxlink.hxx>
-#include <tools/stream.hxx>
-
 #include "jpeg/Exif.hxx"
 #include <memory>
 
@@ -47,8 +44,15 @@ bool GraphicNativeMetadata::read(Graphic const& rGraphic)
     memcpy(aBuffer.get(), aLink.GetData(), aDataSize);
     SvMemoryStream aMemoryStream(aBuffer.get(), aDataSize, StreamMode::READ);
 
+    read(aMemoryStream);
+
+    return true;
+}
+
+bool GraphicNativeMetadata::read(SvStream& rStream)
+{
     Exif aExif;
-    aExif.read(aMemoryStream);
+    aExif.read(rStream);
     mRotation = aExif.getRotation();
 
     return true;


More information about the Libreoffice-commits mailing list