[Libreoffice-commits] core.git: vcl/CppunitTest_vcl_jpeg_read_write_test.mk vcl/Module_vcl.mk vcl/qa
Tomaž Vajngerl
tomaz.vajngerl at collabora.com
Thu Sep 29 09:17:00 UTC 2016
vcl/CppunitTest_vcl_jpeg_read_write_test.mk | 46 ++++++++
vcl/Module_vcl.mk | 1
vcl/qa/cppunit/jpeg/JpegReaderTest.cxx | 151 ++++++++++++++++++++++++++++
vcl/qa/cppunit/jpeg/data/JPEGTestCMYK.jpeg |binary
vcl/qa/cppunit/jpeg/data/JPEGTestGray.jpeg |binary
vcl/qa/cppunit/jpeg/data/JPEGTestRGB.jpeg |binary
6 files changed, 198 insertions(+)
New commits:
commit b052acce562373675209fa9b0b85bbd02fc50999
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.com>
Date: Wed Sep 28 20:22:44 2016 +0200
vcl: test JPEG reading - RGB, CMYK and grayscale
Change-Id: Ice713966b9c721472441478c965212b5c8f74acd
Reviewed-on: https://gerrit.libreoffice.org/29368
Tested-by: Jenkins <ci at libreoffice.org>
Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>
diff --git a/vcl/CppunitTest_vcl_jpeg_read_write_test.mk b/vcl/CppunitTest_vcl_jpeg_read_write_test.mk
new file mode 100644
index 0000000..02958d3
--- /dev/null
+++ b/vcl/CppunitTest_vcl_jpeg_read_write_test.mk
@@ -0,0 +1,46 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
+#
+# 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/.
+#
+
+$(eval $(call gb_CppunitTest_CppunitTest,vcl_jpeg_read_write_test))
+
+$(eval $(call gb_CppunitTest_add_exception_objects,vcl_jpeg_read_write_test, \
+ vcl/qa/cppunit/jpeg/JpegReaderTest \
+))
+
+$(eval $(call gb_CppunitTest_use_external,vcl_jpeg_read_write_test,boost_headers))
+
+$(eval $(call gb_CppunitTest_use_libraries,vcl_jpeg_read_write_test, \
+ comphelper \
+ cppu \
+ cppuhelper \
+ sal \
+ svt \
+ test \
+ tl \
+ unotest \
+ vcl \
+ $(gb_UWINAPI) \
+))
+
+$(eval $(call gb_CppunitTest_use_sdk_api,vcl_jpeg_read_write_test))
+
+$(eval $(call gb_CppunitTest_use_ure,vcl_jpeg_read_write_test))
+$(eval $(call gb_CppunitTest_use_vcl,vcl_jpeg_read_write_test))
+
+$(eval $(call gb_CppunitTest_use_components,vcl_jpeg_read_write_test,\
+ configmgr/source/configmgr \
+ i18npool/util/i18npool \
+ ucb/source/core/ucb1 \
+ ucb/source/ucp/file/ucpfile1 \
+ uui/util/uui \
+))
+
+$(eval $(call gb_CppunitTest_use_configuration,vcl_jpeg_read_write_test))
+
+# vim: set noet sw=4 ts=4:
diff --git a/vcl/Module_vcl.mk b/vcl/Module_vcl.mk
index b1ef05d..97e20f0 100644
--- a/vcl/Module_vcl.mk
+++ b/vcl/Module_vcl.mk
@@ -108,6 +108,7 @@ $(eval $(call gb_Module_add_check_targets,vcl,\
CppunitTest_vcl_outdev \
CppunitTest_vcl_app_test \
$(if $(MERGELIBS),,CppunitTest_vcl_wmf_test) \
+ CppunitTest_vcl_jpeg_read_write_test \
))
diff --git a/vcl/qa/cppunit/jpeg/JpegReaderTest.cxx b/vcl/qa/cppunit/jpeg/JpegReaderTest.cxx
new file mode 100644
index 0000000..99d78e3
--- /dev/null
+++ b/vcl/qa/cppunit/jpeg/JpegReaderTest.cxx
@@ -0,0 +1,151 @@
+/* -*- 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 <test/setupvcl.hxx>
+#include <unotest/bootstrapfixturebase.hxx>
+#include <vcl/graphicfilter.hxx>
+#include <vcl/bitmapaccess.hxx>
+
+class JpegReaderTest : public test::BootstrapFixtureBase
+{
+ OUString maDataUrl;
+
+ OUString getFullUrl(const OUString& sFileName)
+ {
+ return m_directories.getURLFromSrc(maDataUrl) + sFileName;
+ }
+
+ Bitmap loadJPG(const OUString& aURL);
+
+public:
+ JpegReaderTest() :
+ maDataUrl("/vcl/qa/cppunit/jpeg/data/")
+ {}
+
+ void testReadRGB();
+ void testReadGray();
+ void testReadCMYK();
+
+ CPPUNIT_TEST_SUITE(JpegReaderTest);
+ CPPUNIT_TEST(testReadRGB);
+ CPPUNIT_TEST(testReadGray);
+ CPPUNIT_TEST(testReadCMYK);
+ CPPUNIT_TEST_SUITE_END();
+};
+
+int deltaColor(BitmapColor aColor1, BitmapColor aColor2)
+{
+ int deltaR = std::abs(aColor1.GetRed() - aColor2.GetRed());
+ int deltaG = std::abs(aColor1.GetGreen() - aColor2.GetGreen());
+ int deltaB = std::abs(aColor1.GetBlue() - aColor2.GetBlue());
+
+ return std::max(std::max(deltaR, deltaG), deltaB);
+}
+
+bool checkRect(Bitmap& rBitmap, int aLayerNumber, Color aExpectedColor, int nMaxDelta)
+{
+ Bitmap::ScopedWriteAccess pAccess(rBitmap);
+ long nHeight = pAccess->Height();
+ long nWidth = pAccess->Width();
+
+ long firstX = 0 + aLayerNumber;
+ long firstY = 0 + aLayerNumber;
+
+ long lastX = nWidth - 1 - aLayerNumber;
+ long lastY = nHeight - 1 - aLayerNumber;
+
+ int delta;
+
+ for (long y = firstY; y <= lastY; y++)
+ {
+ Color aColorFirst = pAccess->GetPixel(firstX, y);
+ delta = deltaColor(aColorFirst, aExpectedColor);
+ if (delta > nMaxDelta)
+ return false;
+
+ Color aColorLast = pAccess->GetPixel(lastX, y);
+ delta = deltaColor(aColorLast, aExpectedColor);
+ if (delta > nMaxDelta)
+ return false;
+ }
+ for (long x = firstX; x <= lastX; x++)
+ {
+ Color aColorFirst = pAccess->GetPixel(x, firstY);
+ delta = deltaColor(aColorFirst, aExpectedColor);
+ if (delta > nMaxDelta)
+ return false;
+
+ Color aColorLast = pAccess->GetPixel(x, lastY);
+ delta = deltaColor(aColorLast, aExpectedColor);
+ if (delta > nMaxDelta)
+ return false;
+ }
+ return true;
+}
+
+Bitmap JpegReaderTest::loadJPG(const OUString& aURL)
+{
+ GraphicFilter& rFilter = GraphicFilter::GetGraphicFilter();
+ Graphic aGraphic;
+ SvFileStream aFileStream(aURL, StreamMode::READ);
+ bool bResult = rFilter.ImportGraphic(aGraphic, aURL, aFileStream) == 0;
+ CPPUNIT_ASSERT(bResult);
+ return aGraphic.GetBitmapEx().GetBitmap();
+}
+
+void JpegReaderTest::testReadRGB()
+{
+ Bitmap aBitmap = loadJPG(getFullUrl("JPEGTestRGB.jpeg"));
+ Size aSize = aBitmap.GetSizePixel();
+ CPPUNIT_ASSERT_EQUAL(8L, aSize.Width());
+ CPPUNIT_ASSERT_EQUAL(8L, aSize.Height());
+
+ int nMaxDelta = 1; // still acceptable color error
+ CPPUNIT_ASSERT(checkRect(aBitmap, 0, Color(0xff, 0xff, 0xff), nMaxDelta));
+ CPPUNIT_ASSERT(checkRect(aBitmap, 1, Color(0xff, 0x00, 0x00), nMaxDelta));
+ CPPUNIT_ASSERT(checkRect(aBitmap, 2, Color(0x00, 0xff, 0x00), nMaxDelta));
+ CPPUNIT_ASSERT(checkRect(aBitmap, 3, Color(0x00, 0x00, 0xff), nMaxDelta));
+}
+
+void JpegReaderTest::testReadGray()
+{
+ Bitmap aBitmap = loadJPG(getFullUrl("JPEGTestGray.jpeg"));
+ Size aSize = aBitmap.GetSizePixel();
+ CPPUNIT_ASSERT_EQUAL(8L, aSize.Width());
+ CPPUNIT_ASSERT_EQUAL(8L, aSize.Height());
+
+ aBitmap.Convert(BmpConversion::BMP_CONVERSION_24BIT); // convert to 24bit so we don't need to deal with palette
+
+ int nMaxDelta = 3;
+ CPPUNIT_ASSERT(checkRect(aBitmap, 0, Color(0xff, 0xff, 0xff), nMaxDelta));
+ CPPUNIT_ASSERT(checkRect(aBitmap, 1, Color(0x36, 0x36, 0x36), nMaxDelta));
+ CPPUNIT_ASSERT(checkRect(aBitmap, 2, Color(0xb6, 0xb6, 0xb6), nMaxDelta));
+ CPPUNIT_ASSERT(checkRect(aBitmap, 3, Color(0x12, 0x12, 0x12), nMaxDelta));
+}
+
+void JpegReaderTest::testReadCMYK()
+{
+ Bitmap aBitmap = loadJPG(getFullUrl("JPEGTestCMYK.jpeg"));
+ Size aSize = aBitmap.GetSizePixel();
+ CPPUNIT_ASSERT_EQUAL(8L, aSize.Width());
+ CPPUNIT_ASSERT_EQUAL(8L, aSize.Height());
+
+ int maxDelta = 7;
+ CPPUNIT_ASSERT(checkRect(aBitmap, 0, Color(0xff, 0xff, 0xff), maxDelta));
+ CPPUNIT_ASSERT(checkRect(aBitmap, 1, Color(0xff, 0x00, 0x00), maxDelta));
+ CPPUNIT_ASSERT(checkRect(aBitmap, 2, Color(0x00, 0xff, 0x00), maxDelta));
+ CPPUNIT_ASSERT(checkRect(aBitmap, 3, Color(0x00, 0x00, 0xff), maxDelta));
+}
+
+CPPUNIT_TEST_SUITE_REGISTRATION(JpegReaderTest);
+
+CPPUNIT_PLUGIN_IMPLEMENT();
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/qa/cppunit/jpeg/data/JPEGTestCMYK.jpeg b/vcl/qa/cppunit/jpeg/data/JPEGTestCMYK.jpeg
new file mode 100644
index 0000000..5fc0c84
Binary files /dev/null and b/vcl/qa/cppunit/jpeg/data/JPEGTestCMYK.jpeg differ
diff --git a/vcl/qa/cppunit/jpeg/data/JPEGTestGray.jpeg b/vcl/qa/cppunit/jpeg/data/JPEGTestGray.jpeg
new file mode 100644
index 0000000..2836dd9
Binary files /dev/null and b/vcl/qa/cppunit/jpeg/data/JPEGTestGray.jpeg differ
diff --git a/vcl/qa/cppunit/jpeg/data/JPEGTestRGB.jpeg b/vcl/qa/cppunit/jpeg/data/JPEGTestRGB.jpeg
new file mode 100644
index 0000000..8d51035
Binary files /dev/null and b/vcl/qa/cppunit/jpeg/data/JPEGTestRGB.jpeg differ
More information about the Libreoffice-commits
mailing list