diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2020-04-23 16:22:26 +0200 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2020-04-27 06:57:28 +0200 |
commit | 83cf08b1cb2d493a4c12f88eb6bf0daf25fe5beb (patch) | |
tree | c82da8df4c941e90ccd650d0b5c17c598895a2ee | |
parent | e294e29ab3bcd57c1d5d4f3fe372e26d5677a7ab (diff) |
vcl: add tests for GraphicNativeMetadata
Test the rotation in JPEG metadata is what we expect.
Change-Id: I5ee2d646a5257d5695c51f37fb6fe795dcb9af50
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/92948
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
-rw-r--r-- | include/vcl/GraphicNativeMetadata.hxx | 4 | ||||
-rw-r--r-- | vcl/CppunitTest_vcl_graphic_test.mk | 1 | ||||
-rw-r--r-- | vcl/qa/cppunit/GraphicNativeMetadataTest.cxx | 101 | ||||
-rw-r--r-- | vcl/qa/cppunit/data/Exif1.jpg | bin | 0 -> 11882 bytes | |||
-rw-r--r-- | vcl/qa/cppunit/data/Exif1_090CW.jpg | bin | 0 -> 11894 bytes | |||
-rw-r--r-- | vcl/qa/cppunit/data/Exif1_180.jpg | bin | 0 -> 11894 bytes | |||
-rw-r--r-- | vcl/qa/cppunit/data/Exif1_270CW.jpg | bin | 0 -> 11894 bytes | |||
-rw-r--r-- | vcl/source/filter/GraphicNativeMetadata.cxx | 12 |
8 files changed, 114 insertions, 4 deletions
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 63dea32f9757..7b042f84d7da 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 Binary files differnew file mode 100644 index 000000000000..e2aace2daafb --- /dev/null +++ b/vcl/qa/cppunit/data/Exif1.jpg diff --git a/vcl/qa/cppunit/data/Exif1_090CW.jpg b/vcl/qa/cppunit/data/Exif1_090CW.jpg Binary files differnew file mode 100644 index 000000000000..dd13dba4c9e0 --- /dev/null +++ b/vcl/qa/cppunit/data/Exif1_090CW.jpg diff --git a/vcl/qa/cppunit/data/Exif1_180.jpg b/vcl/qa/cppunit/data/Exif1_180.jpg Binary files differnew file mode 100644 index 000000000000..ba4dfc3796a9 --- /dev/null +++ b/vcl/qa/cppunit/data/Exif1_180.jpg diff --git a/vcl/qa/cppunit/data/Exif1_270CW.jpg b/vcl/qa/cppunit/data/Exif1_270CW.jpg Binary files differnew file mode 100644 index 000000000000..7f7cdfb909bb --- /dev/null +++ b/vcl/qa/cppunit/data/Exif1_270CW.jpg 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; |