Kaydet (Commit) 44c6c4da authored tarafından Tomaž Vajngerl's avatar Tomaž Vajngerl

vcl: tests for Bitmap, check for symmetry when scaling bitmaps

Change-Id: I53d6e70018477abb9f98140a52697c1de0f90934
üst 389bf9e1
# -*- 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:
......@@ -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 \
......
......@@ -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 \
......
/* -*- 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: */
/* -*- 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: */
/* -*- 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: */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment