summaryrefslogtreecommitdiff
path: root/vcl
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2015-03-25 11:35:55 +0900
committerTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2015-03-27 10:45:15 +0900
commit44c6c4da9545d69ad02f5e8ea1314388e1eacec7 (patch)
treea5dd6a504abf7ae9374df22692d7357c2b8b7ce4 /vcl
parent389bf9e196aa7b783a325d7c00d41d943511d5ba (diff)
vcl: tests for Bitmap, check for symmetry when scaling bitmaps
Change-Id: I53d6e70018477abb9f98140a52697c1de0f90934
Diffstat (limited to 'vcl')
-rw-r--r--vcl/CppunitTest_vcl_bitmap_test.mk56
-rw-r--r--vcl/Library_vcl.mk1
-rw-r--r--vcl/Module_vcl.mk1
-rw-r--r--vcl/inc/BitmapSymmetryCheck.hxx31
-rw-r--r--vcl/qa/cppunit/BitmapTest.cxx88
-rw-r--r--vcl/source/bitmap/BitmapSymmetryCheck.cxx81
6 files changed, 258 insertions, 0 deletions
diff --git a/vcl/CppunitTest_vcl_bitmap_test.mk b/vcl/CppunitTest_vcl_bitmap_test.mk
new file mode 100644
index 000000000000..527f5efe421e
--- /dev/null
+++ b/vcl/CppunitTest_vcl_bitmap_test.mk
@@ -0,0 +1,56 @@
+# -*- 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_bitmap_test))
+
+$(eval $(call gb_CppunitTest_add_exception_objects,vcl_bitmap_test, \
+ vcl/qa/cppunit/BitmapTest \
+))
+
+$(eval $(call gb_CppunitTest_use_externals,vcl_bitmap_test,\
+ boost_headers \
+))
+
+$(eval $(call gb_CppunitTest_set_include,vcl_bitmap_test,\
+ $$(INCLUDE) \
+ -I$(SRCDIR)/vcl/inc \
+))
+
+$(eval $(call gb_CppunitTest_use_libraries,vcl_bitmap_test, \
+ comphelper \
+ cppu \
+ cppuhelper \
+ sal \
+ svt \
+ test \
+ tl \
+ unotest \
+ vcl \
+ utl \
+ $(gb_UWINAPI) \
+))
+
+$(eval $(call gb_CppunitTest_use_api,vcl_bitmap_test,\
+ udkapi \
+ offapi \
+))
+
+$(eval $(call gb_CppunitTest_use_ure,vcl_bitmap_test))
+$(eval $(call gb_CppunitTest_use_vcl,vcl_bitmap_test))
+
+$(eval $(call gb_CppunitTest_use_components,vcl_bitmap_test,\
+ configmgr/source/configmgr \
+ i18npool/util/i18npool \
+ ucb/source/core/ucb1 \
+ unotools/util/utl \
+))
+
+$(eval $(call gb_CppunitTest_use_configuration,vcl_bitmap_test))
+
+# vim: set noet sw=4 ts=4:
diff --git a/vcl/Library_vcl.mk b/vcl/Library_vcl.mk
index 4eaca9a3ad64..4507f5ea427f 100644
--- a/vcl/Library_vcl.mk
+++ b/vcl/Library_vcl.mk
@@ -315,6 +315,7 @@ $(eval $(call gb_Library_add_exception_objects,vcl,\
vcl/source/gdi/wall \
vcl/source/bitmap/bitmapfilter \
vcl/source/bitmap/bitmapscalesuper \
+ vcl/source/bitmap/BitmapSymmetryCheck \
vcl/source/helper/canvasbitmap \
vcl/source/helper/canvastools \
vcl/source/helper/evntpost \
diff --git a/vcl/Module_vcl.mk b/vcl/Module_vcl.mk
index 2cee4380c86c..f5be45ec10c8 100644
--- a/vcl/Module_vcl.mk
+++ b/vcl/Module_vcl.mk
@@ -99,6 +99,7 @@ $(eval $(call gb_Module_add_targets,vcl,\
endif
$(eval $(call gb_Module_add_check_targets,vcl,\
+ CppunitTest_vcl_bitmap_test \
CppunitTest_vcl_fontcharmap \
CppunitTest_vcl_complextext \
CppunitTest_vcl_filters_test \
diff --git a/vcl/inc/BitmapSymmetryCheck.hxx b/vcl/inc/BitmapSymmetryCheck.hxx
new file mode 100644
index 000000000000..576a61c2156a
--- /dev/null
+++ b/vcl/inc/BitmapSymmetryCheck.hxx
@@ -0,0 +1,31 @@
+/* -*- 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/.
+ *
+ */
+
+#ifndef INCLUDED_VCL_INC_BITMAPSYMMETRYCHECK_HXX
+#define INCLUDED_VCL_INC_BITMAPSYMMETRYCHECK_HXX
+
+#include <vcl/bitmap.hxx>
+#include <vcl/bmpacc.hxx>
+
+class VCL_DLLPUBLIC BitmapSymmetryCheck
+{
+public:
+ BitmapSymmetryCheck();
+ virtual ~BitmapSymmetryCheck();
+
+ bool check(Bitmap& rBitmap);
+
+protected:
+ virtual bool checkImpl(BitmapReadAccess* pReadAccess);
+};
+
+#endif // INCLUDED_VCL_INC_BITMAPSYMMETRYCHECK_HXX
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/qa/cppunit/BitmapTest.cxx b/vcl/qa/cppunit/BitmapTest.cxx
new file mode 100644
index 000000000000..cc8534f22a6a
--- /dev/null
+++ b/vcl/qa/cppunit/BitmapTest.cxx
@@ -0,0 +1,88 @@
+/* -*- 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/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/plugin/TestPlugIn.h>
+
+#include <vcl/bitmap.hxx>
+#include <vcl/bmpacc.hxx>
+
+#include <tools/stream.hxx>
+#include <vcl/graphicfilter.hxx>
+
+#include "BitmapSymmetryCheck.hxx"
+
+namespace
+{
+
+class BitmapTest : public CppUnit::TestFixture
+{
+ void testScale();
+
+ CPPUNIT_TEST_SUITE(BitmapTest);
+ CPPUNIT_TEST(testScale);
+ CPPUNIT_TEST_SUITE_END();
+};
+
+void BitmapTest::testScale()
+{
+ bool bExportBitmap(false);
+
+ Bitmap aBitmap24Bit(Size(10, 10), 24);
+ CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(24), aBitmap24Bit.GetBitCount());
+
+ {
+ Bitmap::ScopedWriteAccess aWriteAccess(aBitmap24Bit);
+ aWriteAccess->Erase(COL_WHITE);
+ aWriteAccess->SetLineColor(COL_BLACK);
+ aWriteAccess->DrawRect(Rectangle(1, 1, 8, 8));
+ aWriteAccess->DrawRect(Rectangle(3, 3, 6, 6));
+ }
+
+ BitmapSymmetryCheck aBitmapSymmetryCheck;
+
+ CPPUNIT_ASSERT_EQUAL(static_cast<long>(10), aBitmap24Bit.GetSizePixel().Width());
+ CPPUNIT_ASSERT_EQUAL(static_cast<long>(10), aBitmap24Bit.GetSizePixel().Height());
+
+ // Check symmetry of the bitmap
+ CPPUNIT_ASSERT(aBitmapSymmetryCheck.check(aBitmap24Bit));
+
+ if (bExportBitmap)
+ {
+ SvFileStream aStream(OUString("~/scale_before.png"), StreamMode::WRITE | StreamMode::TRUNC);
+ GraphicFilter& rFilter = GraphicFilter::GetGraphicFilter();
+ rFilter.compressAsPNG(aBitmap24Bit, aStream, 9);
+ }
+
+ aBitmap24Bit.Scale(2, 2, BMP_SCALE_FAST);
+
+ CPPUNIT_ASSERT_EQUAL(static_cast<long>(20), aBitmap24Bit.GetSizePixel().Width());
+ CPPUNIT_ASSERT_EQUAL(static_cast<long>(20), aBitmap24Bit.GetSizePixel().Height());
+
+ // After scaling the bitmap should still be symmetrical. This check guarantees that
+ // scaling doesn't misalign the bitmap.
+ CPPUNIT_ASSERT(aBitmapSymmetryCheck.check(aBitmap24Bit));
+
+ if (bExportBitmap)
+ {
+ SvFileStream aStream(OUString("~/scale_after.png"), StreamMode::WRITE | StreamMode::TRUNC);
+ GraphicFilter& rFilter = GraphicFilter::GetGraphicFilter();
+ rFilter.compressAsPNG(aBitmap24Bit, aStream, 9);
+ }
+}
+
+} // namespace
+
+CPPUNIT_TEST_SUITE_REGISTRATION(BitmapTest);
+
+CPPUNIT_PLUGIN_IMPLEMENT();
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/source/bitmap/BitmapSymmetryCheck.cxx b/vcl/source/bitmap/BitmapSymmetryCheck.cxx
new file mode 100644
index 000000000000..ad96a09f2c7b
--- /dev/null
+++ b/vcl/source/bitmap/BitmapSymmetryCheck.cxx
@@ -0,0 +1,81 @@
+/* -*- 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 <BitmapSymmetryCheck.hxx>
+
+BitmapSymmetryCheck::BitmapSymmetryCheck()
+{}
+
+BitmapSymmetryCheck::~BitmapSymmetryCheck()
+{}
+
+bool BitmapSymmetryCheck::check(Bitmap& rBitmap)
+{
+ Bitmap::ScopedReadAccess aReadAccess(rBitmap);
+ return checkImpl(aReadAccess.get());
+}
+
+bool BitmapSymmetryCheck::checkImpl(BitmapReadAccess* pReadAccess)
+{
+ long nHeight = pReadAccess->Height();
+ long nWidth = pReadAccess->Width();
+
+ long nHeightHalf = nHeight / 2;
+ long nWidthHalf = nWidth / 2;
+
+ bool nHeightEven = (nHeight % 2) == 0;
+ bool nWidthEven = (nWidth % 2) == 0;
+
+ for (long y = 0; y < nHeightHalf; ++y)
+ {
+ for (long x = 0; x < nWidthHalf; ++x)
+ {
+ if (pReadAccess->GetPixel(y, x) != pReadAccess->GetPixel(nHeight - y - 1, x))
+ {
+ return false;
+ }
+ if (pReadAccess->GetPixel(y, x) != pReadAccess->GetPixel(y, nWidth - x - 1))
+ {
+ return false;
+ }
+ if (pReadAccess->GetPixel(y, x) != pReadAccess->GetPixel(nHeight - y - 1, nWidth - x - 1))
+ {
+ return false;
+ }
+ }
+ }
+
+ if (nWidthEven)
+ {
+ for (long y = 0; y < nHeightHalf; ++y)
+ {
+ if (pReadAccess->GetPixel(y, nWidthHalf) != pReadAccess->GetPixel(nHeight - y - 1, nWidthHalf))
+ {
+ return false;
+ }
+ }
+ }
+
+ if (nHeightEven)
+ {
+ for (long x = 0; x < nWidthHalf; ++x)
+ {
+ if (pReadAccess->GetPixel(nHeightHalf, x) != pReadAccess->GetPixel(nHeightHalf, nWidth - x - 1))
+ {
+ return false;
+ }
+ }
+ }
+
+ return true;
+}
+
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */