diff options
Diffstat (limited to 'basebmp/test')
-rw-r--r-- | basebmp/test/basictest.cxx | 293 | ||||
-rw-r--r-- | basebmp/test/bmpdemo.cxx | 1253 | ||||
-rw-r--r-- | basebmp/test/bmpmasktest.cxx | 173 | ||||
-rw-r--r-- | basebmp/test/bmptest.cxx | 200 | ||||
-rw-r--r-- | basebmp/test/cliptest.cxx | 268 | ||||
-rw-r--r-- | basebmp/test/export.map | 34 | ||||
-rw-r--r-- | basebmp/test/filltest.cxx | 263 | ||||
-rw-r--r-- | basebmp/test/linetest.cxx | 212 | ||||
-rw-r--r-- | basebmp/test/makefile.mk | 113 | ||||
-rw-r--r-- | basebmp/test/masktest.cxx | 161 | ||||
-rw-r--r-- | basebmp/test/polytest.cxx | 284 | ||||
-rw-r--r-- | basebmp/test/tools.cxx | 52 | ||||
-rw-r--r-- | basebmp/test/tools.hxx | 34 |
13 files changed, 3340 insertions, 0 deletions
diff --git a/basebmp/test/basictest.cxx b/basebmp/test/basictest.cxx new file mode 100644 index 000000000000..d953095585fa --- /dev/null +++ b/basebmp/test/basictest.cxx @@ -0,0 +1,293 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// autogenerated file with codegen.pl + +#include "cppunit/TestAssert.h" +#include "cppunit/TestFixture.h" +#include "cppunit/extensions/HelperMacros.h" +#include "cppunit/plugin/TestPlugIn.h" + +#include <basegfx/vector/b2isize.hxx> +#include <basegfx/point/b2ipoint.hxx> + +#include <basebmp/color.hxx> +#include <basebmp/scanlineformats.hxx> +#include <basebmp/bitmapdevice.hxx> +#include "tools.hxx" + +using namespace ::basebmp; + +namespace +{ +class BasicTest : public CppUnit::TestFixture +{ +public: + void colorTest() + { + Color aTestColor; + + aTestColor = Color(0xDEADBEEF); + CPPUNIT_ASSERT_MESSAGE("unary constructor", + aTestColor.toInt32() == 0xDEADBEEF ); + + aTestColor = Color( 0x10, 0x20, 0xFF ); + CPPUNIT_ASSERT_MESSAGE("ternary constructor", + aTestColor.toInt32() == 0x001020FF ); + + aTestColor.setRed( 0x0F ); + CPPUNIT_ASSERT_MESSAGE("setRed()", + aTestColor.toInt32() == 0x00F20FF ); + + aTestColor.setGreen( 0x0F ); + CPPUNIT_ASSERT_MESSAGE("setGreen()", + aTestColor.toInt32() == 0x00F0FFF ); + + aTestColor.setBlue( 0x10 ); + CPPUNIT_ASSERT_MESSAGE("setBlue()", + aTestColor.toInt32() == 0x00F0F10 ); + + aTestColor.setGrey( 0x13 ); + CPPUNIT_ASSERT_MESSAGE("setGrey()", + aTestColor.toInt32() == 0x00131313 ); + + aTestColor = Color( 0x10, 0x20, 0xFF ); + CPPUNIT_ASSERT_MESSAGE("getRed()", + aTestColor.getRed() == 0x10 ); + CPPUNIT_ASSERT_MESSAGE("getGreen()", + aTestColor.getGreen() == 0x20 ); + CPPUNIT_ASSERT_MESSAGE("getBlue()", + aTestColor.getBlue() == 0xFF ); + + } + + void testConstruction() + { + const basegfx::B2ISize aSize(101,101); + basegfx::B2ISize aSize2(aSize); + BitmapDeviceSharedPtr pDevice( createBitmapDevice( aSize, + true, + Format::ONE_BIT_MSB_PAL )); + CPPUNIT_ASSERT_MESSAGE("right size", + pDevice->getSize() == aSize2 ); + CPPUNIT_ASSERT_MESSAGE("Top down format", + pDevice->isTopDown() == true ); + CPPUNIT_ASSERT_MESSAGE("Scanline format", + pDevice->getScanlineFormat() == Format::ONE_BIT_MSB_PAL ); + CPPUNIT_ASSERT_MESSAGE("Scanline len", + pDevice->getScanlineStride() == (aSize2.getY() + 7)/8 ); + CPPUNIT_ASSERT_MESSAGE("Palette existence", + pDevice->getPalette() ); + CPPUNIT_ASSERT_MESSAGE("Palette entry 0 is black", + (*pDevice->getPalette())[0] == Color(0) ); + CPPUNIT_ASSERT_MESSAGE("Palette entry 1 is white", + (*pDevice->getPalette())[1] == Color(0xFFFFFFFF) ); + } + + void testPixelFuncs() + { + // 1bpp + const basegfx::B2ISize aSize(64,64); + BitmapDeviceSharedPtr pDevice( createBitmapDevice( aSize, + true, + Format::ONE_BIT_MSB_PAL )); + + const basegfx::B2IPoint aPt(3,3); + const Color aCol(0xFFFFFFFF); + pDevice->setPixel( aPt, aCol, DrawMode_PAINT ); + CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #1", + pDevice->getPixel(aPt) == aCol); + + const basegfx::B2IPoint aPt2(0,0); + const Color aCol2(0xFFFFFFFF); + pDevice->setPixel( aPt2, aCol2, DrawMode_PAINT ); + CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #2", + pDevice->getPixel(aPt2) == aCol2); + + const basegfx::B2IPoint aPt3(aSize.getX()-1,aSize.getY()-1); + const Color aCol3(0x00000000); + pDevice->setPixel( aPt3, aCol3, DrawMode_PAINT ); + CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #3", + pDevice->getPixel(aPt3) == aCol3); + + pDevice->setPixel( aPt3, aCol2, DrawMode_PAINT ); + CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #3.5", + pDevice->getPixel(aPt3) == aCol2); + + const basegfx::B2IPoint aPt4(-100000,-100000); + pDevice->setPixel( aPt4, aCol3, DrawMode_PAINT ); + const basegfx::B2IPoint aPt5(100000,100000); + pDevice->setPixel( aPt5, aCol3, DrawMode_PAINT ); + + sal_Int32 nPixel(countPixel(pDevice, aCol2)); + const basegfx::B2IPoint aPt6(aSize.getX(),aSize.getY()); + pDevice->setPixel( aPt6, aCol2, DrawMode_PAINT ); + CPPUNIT_ASSERT_MESSAGE("setPixel clipping", + countPixel(pDevice, aCol2) == nPixel); + + CPPUNIT_ASSERT_MESSAGE("raw pixel value #1", + pDevice->getBuffer()[0] == 0x80); + + // 1bit LSB + { + pDevice = createBitmapDevice( aSize, + true, + Format::ONE_BIT_LSB_PAL ); + + pDevice->setPixel( aPt2, aCol, DrawMode_PAINT ); + CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #4", + pDevice->getPixel(aPt2) == aCol); + + const basegfx::B2IPoint aPt222(1,1); + pDevice->setPixel( aPt222, aCol, DrawMode_PAINT ); + CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #5", + pDevice->getPixel(aPt222) == aCol); + + pDevice->setPixel( aPt3, aCol, DrawMode_PAINT ); + CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #6", + pDevice->getPixel(aPt3) == aCol); + + CPPUNIT_ASSERT_MESSAGE("raw pixel value #2", + pDevice->getBuffer()[0] == 0x01); + CPPUNIT_ASSERT_MESSAGE("raw pixel value #3", + pDevice->getBuffer()[8] == 0x02); + } + + // 8bit alpha + { + pDevice = createBitmapDevice( aSize, + true, + Format::EIGHT_BIT_GREY ); + + const Color aCol4(0x010101); + pDevice->setPixel( aPt, aCol4, DrawMode_PAINT ); + CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #4", + pDevice->getPixel(aPt) == aCol4); + + const Color aCol5(0x0F0F0F); + pDevice->setPixel( aPt2, aCol5, DrawMode_PAINT ); + CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #5", + pDevice->getPixel(aPt2) == aCol5); + + const Color aCol6(0xFFFFFF); + pDevice->setPixel( aPt3, aCol6, DrawMode_PAINT ); + CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #6", + pDevice->getPixel(aPt3) == aCol6); + } + + // 16bpp + { + pDevice = createBitmapDevice( aSize, + true, + Format::SIXTEEN_BIT_LSB_TC_MASK ); + const Color aCol7(0); + pDevice->clear( aCol7 ); + + const Color aCol4(0x00101010); + pDevice->setPixel( aPt, aCol4, DrawMode_PAINT ); + CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #7", + pDevice->getPixel(aPt) == aCol4); + + const Color aCol5(0x00F0F0F0); + pDevice->setPixel( aPt2, aCol5, DrawMode_PAINT ); + CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #8", + pDevice->getPixel(aPt2) != aCol7); + + const Color aCol6(0x00FFFFFF); + pDevice->setPixel( aPt3, aCol6, DrawMode_PAINT ); + CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #9", + pDevice->getPixel(aPt3) == aCol6); + } + + // 24bpp + { + pDevice = createBitmapDevice( aSize, + true, + Format::TWENTYFOUR_BIT_TC_MASK ); + + const Color aCol4(0x01010101); + pDevice->setPixel( aPt, aCol4, DrawMode_PAINT ); + CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #10", + pDevice->getPixel(aPt) == aCol4); + + const Color aCol5(0x0F3F2F1F); + pDevice->setPixel( aPt2, aCol5, DrawMode_PAINT ); + CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #11", + pDevice->getPixel(aPt2) == aCol5); + + const Color aCol6(0xFFFFFFFF); + pDevice->setPixel( aPt3, aCol6, DrawMode_PAINT ); + CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #12", + pDevice->getPixel(aPt3) == aCol6); + + CPPUNIT_ASSERT_MESSAGE("raw pixel value #4", + pDevice->getBuffer()[2] == 0x3F + && pDevice->getBuffer()[1] == 0x2F + && pDevice->getBuffer()[0] == 0x1F); + } + + // 32bpp + { + pDevice = createBitmapDevice( aSize, + true, + Format::THIRTYTWO_BIT_TC_MASK ); + + const Color aCol4(0x01010101); + pDevice->setPixel( aPt, aCol4, DrawMode_PAINT ); + CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #13", + pDevice->getPixel(aPt) == aCol4); + + const Color aCol5(0x0F0F0F0F); + pDevice->setPixel( aPt2, aCol5, DrawMode_PAINT ); + CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #14", + pDevice->getPixel(aPt2) == aCol5); + + const Color aCol6(0xFFFFFFFF); + pDevice->setPixel( aPt3, aCol6, DrawMode_PAINT ); + CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #15", + pDevice->getPixel(aPt3) == aCol6); + } + } + + // Change the following lines only, if you add, remove or rename + // member functions of the current class, + // because these macros are need by auto register mechanism. + + CPPUNIT_TEST_SUITE(BasicTest); + CPPUNIT_TEST(colorTest); + CPPUNIT_TEST(testConstruction); + CPPUNIT_TEST(testPixelFuncs); + CPPUNIT_TEST_SUITE_END(); +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(BasicTest); +} + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/basebmp/test/bmpdemo.cxx b/basebmp/test/bmpdemo.cxx new file mode 100644 index 000000000000..ab260655d968 --- /dev/null +++ b/basebmp/test/bmpdemo.cxx @@ -0,0 +1,1253 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _USE_MATH_DEFINES +#define _USE_MATH_DEFINES // needed by Visual C++ for math constants +#endif +#include <math.h> + +#include <comphelper/processfactory.hxx> +#include <comphelper/regpathhelper.hxx> +#include <cppuhelper/servicefactory.hxx> +#include <cppuhelper/bootstrap.hxx> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/lang/XInitialization.hpp> +#include <com/sun/star/registry/XSimpleRegistry.hpp> + +#include <ucbhelper/contentbroker.hxx> +#include <ucbhelper/configurationkeys.hxx> + +#include <vcl/window.hxx> +#include <vcl/svapp.hxx> +#include <vcl/msgbox.hxx> +#include <vcl/unowrap.hxx> +#include <vcl/bitmap.hxx> +#include <vcl/bmpacc.hxx> + +#include <basegfx/polygon/b2dlinegeometry.hxx> +#include <basegfx/polygon/b2dpolypolygon.hxx> +#include <basegfx/polygon/b2dpolypolygontools.hxx> +#include <basegfx/polygon/b2dpolypolygonrasterconverter.hxx> +#include <basegfx/polygon/b2dpolygontools.hxx> +#include <basegfx/polygon/b2dpolygon.hxx> +#include <basegfx/numeric/ftools.hxx> +#include <basegfx/range/b2irange.hxx> +#include <basegfx/vector/b2isize.hxx> +#include <basegfx/vector/b2enums.hxx> +#include <basegfx/point/b2ipoint.hxx> + +#include <basebmp/color.hxx> +#include <basebmp/scanlineformats.hxx> +#include <basebmp/bitmapdevice.hxx> +#include <basebmp/debug.hxx> + +#include <rtl/bootstrap.hxx> + +#include <vigra/metaprogramming.hxx> +#include <vigra/static_assert.hxx> +#include <vigra/basicimageview.hxx> + +#include <boost/static_assert.hpp> +#include <algorithm> + +using namespace ::com::sun::star; + + +namespace +{ + +/// template meta function: add const qualifier, if given 2nd type has it +template<typename A, typename B> struct clone_const +{ + typedef B type; +}; +template<typename A, typename B> struct clone_const<const A,B> +{ + typedef const B type; +}; + +template< class DestIterator, class DestAccessor > class Renderer : + public basegfx::B2DPolyPolygonRasterConverter +{ +private: + typename DestIterator::value_type fillColor_; + typename DestIterator::value_type clearColor_; + DestIterator begin_; + DestAccessor accessor_; + +public: + Renderer(const basegfx::B2DPolyPolygon& rPolyPolyRaster, + typename DestIterator::value_type fillColor, + typename DestIterator::value_type clearColor, + DestIterator begin, + DestIterator end, + DestAccessor accessor ) : + B2DPolyPolygonRasterConverter(rPolyPolyRaster, + basegfx::B2DRange(0,0, + end.x - end.x, + begin.y - begin.y )), + fillColor_( fillColor ), + clearColor_( clearColor ), + begin_( begin ), + accessor_( accessor ) + { + } + + virtual void span(const double& rfXLeft, + const double& rfXRight, + sal_Int32 nY, + bool bOn ) + { + DestIterator currIter( begin_ + vigra::Diff2D(0,nY) ); + typename DestIterator::row_iterator rowIter( currIter.rowIterator() + + basegfx::fround(rfXLeft) ); + typename DestIterator::row_iterator rowEnd( currIter.rowIterator() + + basegfx::fround(rfXRight) ); + if( bOn ) + while( rowIter != rowEnd ) + { + accessor_.set(fillColor_, rowIter); + ++rowIter; + } + else + while( rowIter != rowEnd ) + { + accessor_.set(accessor_(rowIter)*clearColor_, rowIter); + ++rowIter; + } + } +}; + +template< class DestIterator, class DestAccessor > + std::auto_ptr< Renderer< DestIterator, DestAccessor > > makeRenderer( + const basegfx::B2DPolyPolygon& rPolyPolyRaster, + typename DestIterator::value_type fillColor, + typename DestIterator::value_type clearColor, + vigra::triple<DestIterator, DestIterator, DestAccessor> dest ) +{ + return std::auto_ptr< Renderer< DestIterator, DestAccessor > >( + new Renderer< DestIterator, DestAccessor >(rPolyPolyRaster, + fillColor, + clearColor, + dest.first, + dest.second, + dest.third)); +} + + +// changed semantics re. DirectionSelector<StridedArrayTag>: stride +// now counts in <em>raw</em> bytes! +template< typename T > class StridedArrayIterator +{ +public: + typedef typename clone_const<T, unsigned char>::type internal_type; + + StridedArrayIterator(int stride, T* ptr = 0) : + stride_(stride), + current_(reinterpret_cast<internal_type*>(ptr)) + {} + + /// Copy from other StridedArrayIterator, plus given offset + StridedArrayIterator( StridedArrayIterator const& rSrc, + int offset ) : + stride_(rSrc.stride_), + current_(reinterpret_cast<internal_type*>( + reinterpret_cast<T*>(rSrc.current_)+offset)) + {} + + void operator++() {current_ += stride_; } + void operator++(int) {current_ += stride_; } + void operator--() {current_ -= stride_; } + void operator--(int) {current_ -= stride_; } + void operator+=(int dy) {current_ += dy*stride_; } + void operator-=(int dy) {current_ -= dy*stride_; } + + bool operator==(StridedArrayIterator const & rhs) const + { return (current_ == rhs.current_); } + + bool operator!=(StridedArrayIterator const & rhs) const + { return (current_ != rhs.current_); } + + bool operator<(StridedArrayIterator const & rhs) const + { return (current_ < rhs.current_); } + + bool operator<=(StridedArrayIterator const & rhs) const + { return (current_ <= rhs.current_); } + + bool operator>(StridedArrayIterator const & rhs) const + { return (current_ > rhs.current_); } + + bool operator>=(StridedArrayIterator const & rhs) const + { return (current_ >= rhs.current_); } + + int operator-(StridedArrayIterator const & rhs) const + { return (current_ - rhs.current_) / stride_; } + + T* operator()() const + { return reinterpret_cast<T*>(current_); } + + T* operator()(int d) const + { return reinterpret_cast<T*>(current_ + d*stride_); } + + int stride_; + internal_type* current_; +}; + +/// template meta function: remove const qualifier from plain type +template <typename T> struct remove_const +{ + typedef T type; +}; +template <typename T> struct remove_const<const T> +{ + typedef T type; +}; + +/// returns true, if given number is strictly less than 0 +template< typename T > inline bool is_negative( T x ) +{ + return x < 0; +} + +/// Overload for ints (branch-free) +inline bool is_negative( int x ) +{ + // force logic shift (result for signed shift right is undefined) + return static_cast<unsigned int>(x) >> (sizeof(int)*8-1); +} + +/// Get bitmask for data at given intra-word position, for given bit depth +template< typename data_type, int bits_per_pixel, bool MsbFirst, typename difference_type > inline data_type get_mask( difference_type d ) +{ + BOOST_STATIC_ASSERT(bits_per_pixel > 0); + BOOST_STATIC_ASSERT(sizeof(data_type)*8 % bits_per_pixel == 0); + BOOST_STATIC_ASSERT(sizeof(data_type)*8 / bits_per_pixel > 1); + BOOST_STATIC_ASSERT(vigra::TypeTraits<data_type>::isPOD::asBool); + + const unsigned int nIntraWordPositions( sizeof(data_type)*8 / bits_per_pixel ); + + // create bits_per_pixel 1s shift to intra-word position + return ((~(~0 << bits_per_pixel)) << bits_per_pixel*(MsbFirst ? + (nIntraWordPositions-1 - (d % nIntraWordPositions)) : + (d % nIntraWordPositions))); +} + +template< int num_intraword_positions, int bits_per_pixel, bool MsbFirst, typename difference_type > inline difference_type get_shift( difference_type remainder ) +{ + return bits_per_pixel*(MsbFirst ? + (num_intraword_positions - 1 - remainder) : + remainder); +} + +template< typename Datatype, + typename Valuetype, + int bits_per_pixel, + bool MsbFirst > class PackedPixelColumnIterator +{ +public: + // no reference, no index_reference type here + typedef Datatype data_type; + typedef Valuetype value_type; + typedef int difference_type; + typedef image_traverser_tag iterator_category; + + typedef typename remove_const<data_type>::type mask_type; + typedef data_type* pointer; + typedef StridedArrayIterator< data_type > MoveY; + + enum { + /** The number of pixel within a single data_type value + */ + num_intraword_positions=sizeof(data_type)*8/bits_per_pixel, + /** Bit mask for one pixel (least significant bits) + */ + bit_mask=~(~0 << bits_per_pixel) + }; + +private: + MoveY y; + mask_type mask_; + difference_type shift_; + + void inc() + { + ++y; + } + + void dec() + { + --y; + } + + bool equal( PackedPixelColumnIterator const & rhs ) const + { + return rhs.y == y; + } + + bool less( PackedPixelColumnIterator const & rhs ) const + { + return y < rhs.y; + } + +public: + PackedPixelColumnIterator() : + y(0), + mask_( get_mask<data_type, bits_per_pixel, MsbFirst, difference_type>(0) ), + shift_( get_shift<num_intraword_positions, bits_per_pixel, MsbFirst, difference_type>(0) ) + {} + + PackedPixelColumnIterator( const MoveY& base, difference_type remainder ) : + y(base), + mask_( get_mask<data_type, bits_per_pixel, MsbFirst>(remainder) ), + shift_( get_shift<num_intraword_positions, bits_per_pixel, MsbFirst>(remainder) ) + {} + + PackedPixelColumnIterator& operator+=( difference_type d ) + { + y += d; + return *this; + } + + PackedPixelColumnIterator& operator-=( difference_type d ) + { + y -= d; + return *this; + } + + PackedPixelColumnIterator operator+( difference_type d ) + { + PackedPixelColumnIterator res(*this); + res += d; + return res; + } + + PackedPixelColumnIterator operator-( difference_type d ) + { + PackedPixelColumnIterator res(*this); + res -= d; + return res; + } + + PackedPixelColumnIterator& operator++() + { + inc(); + return *this; + } + + PackedPixelColumnIterator& operator--() + { + dec(); + return *this; + } + + PackedPixelColumnIterator operator++(int) + { + PackedPixelColumnIterator res(*this); + res.inc(); + return res; + } + + PackedPixelColumnIterator operator--(int) + { + PackedPixelColumnIterator res(*this); + res.dec(); + return res; + } + + bool operator==(PackedPixelColumnIterator const & rhs) const + { + return equal( rhs ); + } + + bool operator!=(PackedPixelColumnIterator const & rhs) const + { + return !equal( rhs ); + } + + bool operator<(PackedPixelColumnIterator const & rhs) const + { + return less(rhs); + } + + bool operator<=(PackedPixelColumnIterator const & rhs) const + { + return !less(rhs); + } + + bool operator>(PackedPixelColumnIterator const & rhs) const + { + return rhs.less(*this); + } + + bool operator>=(PackedPixelColumnIterator const & rhs) const + { + return !rhs.less(*this); + } + + difference_type operator-(PackedPixelColumnIterator const & rhs) const + { + return y - rhs.y; + } + + value_type get() const + { + // TODO(Q3): use traits to get unsigned type for data_type (if + // not already) + return static_cast<unsigned int>(*y() & mask_) >> shift_; + } + + value_type get(difference_type d) const + { + // TODO(Q3): use traits to get unsigned type for data_type (if + // not already) + return static_cast<unsigned int>(*y(d) & mask_) >> shift_; + } + + void set( value_type v ) const + { + const value_type pixel_value( (v << shift_) & mask_ ); + *y() = (*y() & ~mask_) | pixel_value; + } + + void set( value_type v, difference_type d ) const + { + const value_type pixel_value( (v << shift_) & mask_ ); + *y(d) = (*y(d) & ~mask_) | pixel_value; + } +}; + +template< typename Datatype, + typename Valuetype, + int bits_per_pixel, + bool MsbFirst > class PackedPixelRowIterator +{ +public: + // no reference, no index_reference type here + typedef Datatype data_type; + typedef Valuetype value_type; + typedef int difference_type; + typedef image_traverser_tag iterator_category; + + typedef typename remove_const<data_type>::type mask_type; + typedef data_type* pointer; + + enum { + /** The number of pixel within a single data_type value + */ + num_intraword_positions=sizeof(data_type)*8/bits_per_pixel, + /** Bit mask for one pixel (least significant bits) + */ + bit_mask=~(~0 << bits_per_pixel) + }; + +private: + pointer data_; + mask_type mask_; + difference_type remainder_; + + void update_mask() + { + mask_ = get_mask<data_type, bits_per_pixel, MsbFirst>(remainder_); + } + + void inc() + { + const difference_type newValue( remainder_ + 1 ); + const difference_type data_offset( newValue / num_intraword_positions ); + + data_ += data_offset; + remainder_ = newValue % num_intraword_positions; + + const mask_type shifted_mask( + MsbFirst ? + // TODO(Q3): use traits to get unsigned type for data_type + // (if not already) + static_cast<unsigned int>(mask_) >> bits_per_pixel : + mask_ << bits_per_pixel ); + + // data_offset is 0 for shifted mask, and 1 for wrapped-around mask + mask_ = (1-data_offset)*shifted_mask + data_offset*(MsbFirst ? + bit_mask << bits_per_pixel*(num_intraword_positions-1) : + bit_mask); + } + + void dec() + { + const difference_type newValue( remainder_ - 1 ); + const bool isNegative( is_negative(newValue) ); + const difference_type newRemainder( newValue % num_intraword_positions ); + + // calc data_ += newValue / num_intraword_positions; + // remainder_ = newRemainder; + // for newValue >= 0, and + // data_ += newValue / num_intraword_positions - 1; + // remainder_ = num_intraword_positions - newRemainder; + // (to force remainder_ to be positive). + // This is branch-free, if is_negative() is branch-free + const difference_type data_offset( newValue / num_intraword_positions - isNegative ); + data_ += data_offset; + remainder_ = newRemainder + isNegative*num_intraword_positions; + + const mask_type shifted_mask( + MsbFirst ? + mask_ << bits_per_pixel : + // TODO(Q3): use traits to get unsigned type for data_type + // (if not already) + static_cast<unsigned int>(mask_) >> bits_per_pixel ); + + // data_offset is 0 for shifted mask, and 1 for wrapped-around mask + mask_ = (1-data_offset)*shifted_mask + data_offset*(MsbFirst ? + bit_mask : + bit_mask << bits_per_pixel*(num_intraword_positions-1)); + } + + bool equal( PackedPixelRowIterator const & rhs ) const + { + return rhs.data_ == data_ && rhs.remainder_ == remainder_; + } + + bool less( PackedPixelRowIterator const & rhs ) const + { + return data_ == rhs.data_ ? + (remainder_ < rhs.remainder_) : + (data_ < rhs.data_); + } + +public: + PackedPixelRowIterator() : + data_(0), + mask_( get_mask<data_type, bits_per_pixel, MsbFirst, difference_type>(0) ), + remainder_(0) + {} + + explicit PackedPixelRowIterator( pointer base ) : + data_(base), + mask_( get_mask<data_type, bits_per_pixel, MsbFirst, difference_type>(0) ), + remainder_(0) + {} + + PackedPixelRowIterator& operator+=( difference_type d ) + { + const difference_type newValue( remainder_ + d ); + + data_ += newValue / num_intraword_positions; + remainder_ = newValue % num_intraword_positions; + update_mask(); + + return *this; + } + + PackedPixelRowIterator& operator-=( difference_type d ) + { + const difference_type newValue( remainder_ - d ); + const bool isNegative( is_negative(newValue) ); + const difference_type newRemainder( newValue % num_intraword_positions ); + + // calc data_ += newValue / num_intraword_positions; + // remainder_ = newRemainder; + // for newValue >= 0, and + // data_ += newValue / num_intraword_positions - 1; + // remainder_ = num_intraword_positions - newRemainder; + // (to force remainder_ to be positive). + // This is branch-free, if is_negative() is branch-free + data_ += newValue / num_intraword_positions - isNegative; + remainder_ = newRemainder + isNegative*(num_intraword_positions - 2*newRemainder); + update_mask(); + + return *this; + } + + PackedPixelRowIterator operator+( difference_type d ) + { + PackedPixelRowIterator res(*this); + res += d; + return res; + } + + PackedPixelRowIterator operator-( difference_type d ) + { + PackedPixelRowIterator res(*this); + res -= d; + return res; + } + + PackedPixelRowIterator& operator++() + { + inc(); + return *this; + } + + PackedPixelRowIterator& operator--() + { + dec(); + return *this; + } + + PackedPixelRowIterator operator++(int) + { + PackedPixelRowIterator res(*this); + res.inc(); + return res; + } + + PackedPixelRowIterator operator--(int) + { + PackedPixelRowIterator res(*this); + res.dec(); + return res; + } + + bool operator==(PackedPixelRowIterator const & rhs) const + { + return equal( rhs ); + } + + bool operator!=(PackedPixelRowIterator const & rhs) const + { + return !equal( rhs ); + } + + bool operator<(PackedPixelRowIterator const & rhs) const + { + return less(rhs); + } + + bool operator<=(PackedPixelRowIterator const & rhs) const + { + return !less(rhs); + } + + bool operator>(PackedPixelRowIterator const & rhs) const + { + return rhs.less(*this); + } + + bool operator>=(PackedPixelRowIterator const & rhs) const + { + return !rhs.less(*this); + } + + difference_type operator-(PackedPixelRowIterator const & rhs) const + { + return (data_ - rhs.data_)*num_intraword_positions + (remainder_ - rhs.remainder_); + } + + value_type get() const + { + // TODO(Q3): use traits to get unsigned type for data_type (if + // not already) + return static_cast<unsigned int>(*data_ & mask_) >> + get_shift<num_intraword_positions, bits_per_pixel, MsbFirst>(remainder_); + } + + value_type get(difference_type d) const + { + PackedPixelRowIterator tmp(*this); + tmp += d; + return tmp.get(); + } + + void set( value_type v ) const + { + const value_type pixel_value( + (v << + get_shift<num_intraword_positions, bits_per_pixel, MsbFirst>(remainder_)) + & mask_ ); + *data_ = (*data_ & ~mask_) | pixel_value; + } + + void set( value_type v, difference_type d ) const + { + PackedPixelRowIterator tmp(*this); + tmp += d; + tmp.set(v); + } +}; + +template< typename Datatype, + typename Valuetype, + int bits_per_pixel, + bool MsbFirst > class PackedPixelIterator +{ +public: + // no reference, no index_reference type here + typedef Datatype data_type; + typedef Valuetype value_type; + typedef vigra::Diff2D difference_type; + typedef image_traverser_tag iterator_category; + typedef PackedPixelRowIterator<data_type, + value_type, + bits_per_pixel, + MsbFirst> row_iterator; + typedef PackedPixelColumnIterator<data_type, + value_type, + bits_per_pixel, + MsbFirst> column_iterator; + + typedef data_type* pointer; + typedef int MoveX; + typedef StridedArrayIterator< data_type > MoveY; + + enum { + /** The number of pixel within a single data_type value + */ + num_intraword_positions=sizeof(data_type)*8/bits_per_pixel, + /** Bit mask for one pixel (least significant bits) + */ + bit_mask=~(~0 << bits_per_pixel) + }; + + // TODO(F2): direction of iteration (ImageIterator can be made to + // run backwards) + +private: + pointer current() const + { + return y() + (x / num_intraword_positions); + } + + pointer current(int dx, int dy) const + { + return y(dy) + ((x+dx)/num_intraword_positions); + } + + bool equal(PackedPixelIterator const & rhs) const + { + return (x == rhs.x) && (y == rhs.y); + } + +public: + PackedPixelIterator() : + x(0), + y(0) + {} + + PackedPixelIterator(pointer base, int ystride) : + x(0), + y(ystride,base) + {} + + bool operator==(PackedPixelIterator const & rhs) const + { + return equal(rhs); + } + + bool operator!=(PackedPixelIterator const & rhs) const + { + return !equal(rhs); + } + + difference_type operator-(PackedPixelIterator const & rhs) const + { + return difference_type(x - rhs.x, y - rhs.y); + } + + MoveX x; + MoveY y; + + PackedPixelIterator & operator+=(difference_type const & s) + { + x += s.x; + y += s.y; + return *this; + } + + PackedPixelIterator & operator-=(difference_type const & s) + { + x -= s.x; + y -= s.y; + return *this; + } + + PackedPixelIterator operator+(difference_type const & s) const + { + PackedPixelIterator ret(*this); + ret += s; + return ret; + } + + PackedPixelIterator operator-(difference_type const & s) const + { + PackedPixelIterator ret(*this); + ret -= s; + return ret; + } + + row_iterator rowIterator() const + { + return row_iterator(current()); + } + + column_iterator columnIterator() const + { + return column_iterator(MoveY(y, + x / num_intraword_positions), + x % num_intraword_positions); + } + + value_type get() const + { + const int remainder( x() % num_intraword_positions ); + + // TODO(Q3): use traits to get unsigned type for data_type (if + // not already) + return (static_cast<unsigned int>(*current() & + get_mask<data_type, bits_per_pixel, MsbFirst>(remainder)) + >> (MsbFirst ? + (num_intraword_positions - remainder) : + remainder)); + } + + value_type get(difference_type const & d) const + { + const int remainder( x(d.x) % num_intraword_positions ); + + // TODO(Q3): use traits to get unsigned type for data_type (if + // not already) + return (static_cast<unsigned int>(*current(d.x,d.y) & + get_mask<data_type, bits_per_pixel, MsbFirst>(remainder)) + >> get_shift<num_intraword_positions, bits_per_pixel, MsbFirst>(remainder)); + } + + void set( value_type v ) const + { + const int remainder( x() % num_intraword_positions ); + const int mask( get_mask<data_type, bits_per_pixel, MsbFirst>(remainder) ); + const value_type pixel_value( + (v << + get_shift<num_intraword_positions, bits_per_pixel, MsbFirst>(remainder)) + & mask ); + pointer p = current(); + *p = (*p & ~mask) | pixel_value; + } + + void set( value_type v, difference_type const & d ) const + { + const int remainder( x(d.x) % num_intraword_positions ); + const int mask( get_mask<data_type, bits_per_pixel, MsbFirst>(remainder) ); + const value_type pixel_value( + (v << + get_shift<num_intraword_positions, bits_per_pixel, MsbFirst>(remainder)) + & mask ); + pointer p = current(d.x,d.y); + *p = (*p & ~mask) | pixel_value; + } +}; + + +/** Access (possibly packed-pixel) data via palette indirection + */ +template< typename Valuetype, typename Datatype > class PaletteImageAccessor +{ + public: + typedef Valuetype value_type; + typedef Datatype data_type; + typedef typename remove_const<data_type>::type count_type; + + +private: + const BitmapColor* palette; + count_type num_entries; + + double norm( BitmapColor const& rLHS, + BitmapColor const& rRHS ) const + { + // convert RGBValue's linear space to a normed linear space + return sqrt( + vigra::sq(rLHS.GetRed()-rRHS.GetRed()) + + vigra::sq(rLHS.GetGreen()-rRHS.GetGreen()) + + vigra::sq(rLHS.GetBlue()-rRHS.GetBlue()) ); + } + + data_type find_best_match(value_type const& v) const + { + // TODO(F3): not generic!!! + const BitmapColor aTmpCol(v.red(), + v.green(), + v.blue()); + + // TODO(P3): use table-based/octree approach here! + const BitmapColor* best_entry; + const BitmapColor* palette_end( palette+num_entries ); + if( (best_entry=std::find( palette, palette_end, aTmpCol)) != palette_end ) + return best_entry-palette; + + // TODO(F3): HACK. Need palette traits, and an error function + // here. We blatantly assume value_type is a normed linear + // space. + const BitmapColor* curr_entry( palette ); + best_entry = curr_entry; + while( curr_entry != palette_end ) + { + if( norm(*curr_entry,*best_entry) > norm(*curr_entry,aTmpCol) ) + best_entry = curr_entry; + + ++curr_entry; + } + + return best_entry-palette; + } + + value_type toCol( BitmapColor const& rCol ) const + { + return value_type(rCol.GetRed(),rCol.GetGreen(),rCol.GetBlue()); + } + +public: + PaletteImageAccessor() : + palette(0), + num_entries(0) + {} + + PaletteImageAccessor( const BitmapColor* pPalette, + data_type entries ) : + palette(pPalette), + num_entries(entries) + {} + + template< class Iterator > + value_type operator()(Iterator const& i) const { return toCol(palette[i.get()]); } + value_type operator()(data_type const* i) const { return toCol(palette[*i]); } + + template< class Iterator, class Difference > + value_type operator()(Iterator const& i, Difference const& diff) const + { + return toCol(palette[i.get(diff)]); + } + + template< typename V, class Iterator > + void set(V const& value, Iterator const& i) const + { + i.set( + find_best_match( + vigra::detail::RequiresExplicitCast<value_type>::cast(value) )); + } + + template< typename V, class Iterator, class Difference > + void set(V const& value, Iterator const& i, Difference const& diff) const + { + i.set( + find_best_match( + vigra::detail::RequiresExplicitCast<value_type>::cast(value)), + diff ); + } +}; + +} + + +class TestApp : public Application +{ +public: + virtual void Main(); + virtual USHORT Exception( USHORT nError ); +}; + +class TestWindow : public Dialog +{ + public: + TestWindow() : Dialog( (Window *) NULL ) + { + SetText( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "VIGRA test" )) ); + SetSizePixel( Size( 1024, 1024 ) ); + EnablePaint( true ); + Show(); + } + virtual ~TestWindow() {} + virtual void MouseButtonUp( const MouseEvent& /*rMEvt*/ ) + { + //TODO: do something cool + EndDialog(); + } + virtual void Paint( const Rectangle& rRect ); +}; + + +static basegfx::B2IPoint project( const basegfx::B2IPoint& rPoint ) +{ + const double angle_x = M_PI / 6.0; + const double angle_z = M_PI / 6.0; + + // transform planar coordinates to 3d + double x = rPoint.getX(); + double y = rPoint.getY(); + //double z = 0; + + // rotate around X axis + double x1 = x; + double y1 = y * cos( angle_x ); + double z1 = y * sin( angle_x ); + + // rotate around Z axis + double x2 = x1 * cos( angle_z ) + y1 * sin( angle_z ); + //double y2 = y1 * cos( angle_z ) - x1 * sin( angle_z ); + double z2 = z1; + + //return basegfx::B2IPoint( (sal_Int32)3*x2, (sal_Int32)3*z2 ); + return basegfx::B2IPoint( (sal_Int32)(6*x2), (sal_Int32)(6*z2) ); +} + +static basebmp::Color approachColor( const basebmp::Color& rFrom, const basebmp::Color& rTo ) +{ + basebmp::Color aColor; + UINT8 nDiff; + // approach red + if( rFrom.getRed() < rTo.getRed() ) + { + nDiff = rTo.getRed() - rFrom.getRed(); + aColor.setRed( rFrom.getRed() + ( nDiff < 10 ? nDiff : 10 ) ); + } + else if( rFrom.getRed() > rTo.getRed() ) + { + nDiff = rFrom.getRed() - rTo.getRed(); + aColor.setRed( rFrom.getRed() - ( nDiff < 10 ? nDiff : 10 ) ); + } + else + aColor.setRed( rFrom.getRed() ); + + // approach Green + if( rFrom.getGreen() < rTo.getGreen() ) + { + nDiff = rTo.getGreen() - rFrom.getGreen(); + aColor.setGreen( rFrom.getGreen() + ( nDiff < 10 ? nDiff : 10 ) ); + } + else if( rFrom.getGreen() > rTo.getGreen() ) + { + nDiff = rFrom.getGreen() - rTo.getGreen(); + aColor.setGreen( rFrom.getGreen() - ( nDiff < 10 ? nDiff : 10 ) ); + } + else + aColor.setGreen( rFrom.getGreen() ); + + // approach blue + if( rFrom.getBlue() < rTo.getBlue() ) + { + nDiff = rTo.getBlue() - rFrom.getBlue(); + aColor.setBlue( rFrom.getBlue() + ( nDiff < 10 ? nDiff : 10 ) ); + } + else if( rFrom.getBlue() > rTo.getBlue() ) + { + nDiff = rFrom.getBlue() - rTo.getBlue(); + aColor.setBlue( rFrom.getBlue() - ( nDiff < 10 ? nDiff : 10 ) ); + } + else + aColor.setBlue( rFrom.getBlue() ); + + return aColor; +} + +#define DELTA 5.0 + + + +void TestWindow::Paint( const Rectangle& /*rRect*/ ) +{ + basegfx::B2ISize aTestSize(1000,1000); + basebmp::BitmapDeviceSharedPtr pDevice( basebmp::createBitmapDevice( aTestSize, + false, + basebmp::Format::THIRTYTWO_BIT_TC_MASK )); + + { + ::rtl::OUString aSvg; + basegfx::B2DPolyPolygon aPoly; + + basegfx::tools::importFromSvgD( aPoly, + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "m0 0 h7 v7 h-7 z" )) ); + basegfx::tools::importFromSvgD( aPoly, + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "m2 2 h3 v3 h-3 z" )) ); + + pDevice->fillPolyPolygon( + aPoly, + basebmp::Color(0xFFFFFFFF), + basebmp::DrawMode_PAINT ); + } + + { + basebmp::BitmapDeviceSharedPtr pMask( basebmp::createBitmapDevice( aTestSize, + false, + basebmp::Format::ONE_BIT_MSB_GREY )); + + const basegfx::B2IPoint aPt111(10,10); + const basegfx::B2IPoint aPt222(0,10); + const basebmp::Color aCol333(0xFFFFFFFF); + pMask->drawLine( aPt111, aPt222, aCol333, basebmp::DrawMode_PAINT ); + + + ::rtl::OUString aSvg( RTL_CONSTASCII_USTRINGPARAM( "m 0 0 h5 l5 5 v5 h-5 l-5-5 z" )); + basegfx::B2DPolyPolygon aPoly; + basegfx::tools::importFromSvgD( aPoly, aSvg ); + pMask->clear(basebmp::Color(0xFFFFFFFF)); + pMask->drawPolygon( + aPoly.getB2DPolygon(0), + basebmp::Color(0), + basebmp::DrawMode_PAINT ); + + basebmp::BitmapDeviceSharedPtr pSubsetDevice = + basebmp::subsetBitmapDevice( pDevice, + basegfx::B2IRange(3,3,7,7) ); + + const basegfx::B2IPoint aPt1(0,0); + const basegfx::B2IPoint aPt2(1,9); + const basebmp::Color aCol(0xFFFFFFFF); + pDevice->drawLine( aPt1, aPt2, aCol, basebmp::DrawMode_PAINT, pMask ); + } + + { + const basebmp::Color aCol(0xFFFFFFFF); + basegfx::B2DPolygon aRect = basegfx::tools::createPolygonFromRect( + basegfx::B2DRange( 0,0,1001,1001 )); + pDevice->drawPolygon( aRect, aCol, basebmp::DrawMode_PAINT ); + + const basegfx::B2IPoint aPt1(0,0); + const basegfx::B2IPoint aPt2(0,800); + pDevice->drawLine( aPt1, aPt2, aCol, basebmp::DrawMode_PAINT ); + + const basegfx::B2IPoint aPt3(0,1001); + pDevice->drawLine( aPt1, aPt3, aCol, basebmp::DrawMode_PAINT ); + } + + { + pDevice->clear(basebmp::Color(0)); + + basegfx::B2IPoint aCenter( aTestSize.getX()/2, + aTestSize.getY()/2 ); + //basegfx::B2IPoint aP1( aTestSize.getX()/48, 0), aP2( aTestSize.getX()/40, 0 ), aPoint; + //basegfx::B2IPoint aP1( aTestSize.getX()/7, 0), aP2( aTestSize.getX()/6, 0 ), aPoint; + //basegfx::B2IPoint aP1( aTestSize.getX()/5, 0), aP2( aTestSize.getX()/4, 0 ), aPoint; + basegfx::B2IPoint aP1( aTestSize.getX()/12, 0), aP2( aTestSize.getX()/11, 0 ), aPoint; + + double sind = sin( DELTA*M_PI/180.0 ); + double cosd = cos( DELTA*M_PI/180.0 ); + double factor = 1 + (DELTA/1000.0); + int n=0; + basebmp::Color aLineColor( 0, 0, 0 ); + basebmp::Color aApproachColor( 0, 0, 200 ); + while ( aP2.getX() < aCenter.getX() && n++ < 680 ) + { + aLineColor = approachColor( aLineColor, aApproachColor ); + + // switch aproach color + if( aApproachColor == aLineColor ) + { + if( aApproachColor.getRed() ) + aApproachColor = basebmp::Color( 0, 0, 200 ); + else if( aApproachColor.getGreen() ) + aApproachColor = basebmp::Color( 200, 0, 0 ); + else + aApproachColor = basebmp::Color( 0, 200, 0 ); + } + + basegfx::B2DPolygon aPoly; + aPoly.append( basegfx::B2DPoint(project( aP1 ) + aCenter) ); + aPoly.append( basegfx::B2DPoint(project( aP2 ) + aCenter) ); + pDevice->fillPolyPolygon( + basegfx::tools::createAreaGeometry( + aPoly, +// std::max(1,n/30), +// std::max(1,n/60), + std::max(1,n/30), + basegfx::B2DLINEJOIN_NONE), + aLineColor, + basebmp::DrawMode_PAINT); + + aPoint.setX( (int)((((double)aP1.getX())*cosd - ((double)aP1.getY())*sind)*factor) ); + aPoint.setY( (int)((((double)aP1.getY())*cosd + ((double)aP1.getX())*sind)*factor) ); + aP1 = aPoint; + aPoint.setX( (int)((((double)aP2.getX())*cosd - ((double)aP2.getY())*sind)*factor) ); + aPoint.setY( (int)((((double)aP2.getY())*cosd + ((double)aP2.getX())*sind)*factor) ); + aP2 = aPoint; + } + } + + Bitmap aBitmap( Size(aTestSize.getX(), + aTestSize.getY()), 24 ); + + // Fill bitmap with generated content + { + ScopedBitmapWriteAccess pWriteAccess( aBitmap.AcquireWriteAccess(), + aBitmap ); + for( int y=0; y<aTestSize.getY(); ++y ) + for( int x=0; x<aTestSize.getX(); ++x ) + pWriteAccess->SetPixel(y,x, + Color(pDevice->getPixelData(basegfx::B2IPoint(x,y))) ); + } + + DrawBitmap( Point(), aBitmap ); +} + +USHORT TestApp::Exception( USHORT nError ) +{ + switch( nError & EXC_MAJORTYPE ) + { + case EXC_RSCNOTLOADED: + Abort( String::CreateFromAscii( "Error: could not load language resources.\nPlease check your installation.\n" ) ); + break; + } + return 0; +} + +void TestApp::Main() +{ + //------------------------------------------------- + // create the global service-manager + //------------------------------------------------- + uno::Reference< lang::XMultiServiceFactory > xFactory; + try + { + uno::Reference< uno::XComponentContext > xCtx = ::cppu::defaultBootstrap_InitialComponentContext(); + xFactory = uno::Reference< lang::XMultiServiceFactory >( xCtx->getServiceManager(), + uno::UNO_QUERY ); + if( xFactory.is() ) + ::comphelper::setProcessServiceFactory( xFactory ); + } + catch( uno::Exception& ) + { + } + + if( !xFactory.is() ) + { + OSL_TRACE( "Could not bootstrap UNO, installation must be in disorder. Exiting.\n" ); + exit( 1 ); + } + + // Create UCB. + uno::Sequence< uno::Any > aArgs( 2 ); + aArgs[ 0 ] <<= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( UCB_CONFIGURATION_KEY1_LOCAL )); + aArgs[ 1 ] <<= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( UCB_CONFIGURATION_KEY2_OFFICE )); + ::ucbhelper::ContentBroker::initialize( xFactory, aArgs ); + + TestWindow pWindow; + pWindow.Execute(); + + // clean up UCB + ::ucbhelper::ContentBroker::deinitialize(); +} + +TestApp aDemoApp; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/basebmp/test/bmpmasktest.cxx b/basebmp/test/bmpmasktest.cxx new file mode 100644 index 000000000000..5ba477484903 --- /dev/null +++ b/basebmp/test/bmpmasktest.cxx @@ -0,0 +1,173 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// autogenerated file with codegen.pl + +#include "cppunit/TestAssert.h" +#include "cppunit/TestFixture.h" +#include "cppunit/extensions/HelperMacros.h" + +#include <basegfx/vector/b2isize.hxx> +#include <basegfx/range/b2irange.hxx> +#include <basegfx/point/b2ipoint.hxx> +#include <basegfx/polygon/b2dpolygon.hxx> +#include <basegfx/polygon/b2dpolygontools.hxx> +#include <basegfx/polygon/b2dpolypolygon.hxx> +#include <basegfx/polygon/b2dpolypolygontools.hxx> + +#include <basebmp/color.hxx> +#include <basebmp/scanlineformats.hxx> +#include <basebmp/bitmapdevice.hxx> +#include "tools.hxx" + +using namespace ::basebmp; + +namespace +{ +class BmpMaskTest : public CppUnit::TestFixture +{ +private: + BitmapDeviceSharedPtr mpDevice1bpp; + BitmapDeviceSharedPtr mpMaskBmp1bpp; + BitmapDeviceSharedPtr mpBmp1bpp; + BitmapDeviceSharedPtr mpDevice32bpp; + BitmapDeviceSharedPtr mpBmp32bpp; + + void implTestBmpBasics(const BitmapDeviceSharedPtr& rDevice, + const BitmapDeviceSharedPtr& rBmp) + { + rDevice->clear(Color(0)); + const Color aCol(0xFFFFFFFF); + + const basegfx::B2IRange aSourceRect(0,0,10,10); + const basegfx::B2IRange aDestAll(0,0,10,10); + + rDevice->drawMaskedBitmap( + rBmp, + mpMaskBmp1bpp, + aSourceRect, + aDestAll, + DrawMode_PAINT ); + CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 30", + countPixel( rDevice, aCol ) == 30); + } + + void implTestBmpScaledClip(const BitmapDeviceSharedPtr& rDevice, + const BitmapDeviceSharedPtr& rBmp) + { + rDevice->clear(Color(0)); + const Color aCol(0xFFFFFFFF); + + const basegfx::B2IRange aSourceRect(0,0,10,10); + const basegfx::B2IRange aDestLeftTop(0,0,6,6); + + rDevice->drawMaskedBitmap( + rBmp, + mpMaskBmp1bpp, + aSourceRect, + aDestLeftTop, + DrawMode_PAINT ); + CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 12", + countPixel( rDevice, aCol ) == 12); + } + +public: + void setUp() + { + const basegfx::B2ISize aSize(10,10); + mpDevice1bpp = createBitmapDevice( aSize, + true, + Format::ONE_BIT_MSB_PAL ); + mpDevice32bpp = createBitmapDevice( aSize, + true, + Format::THIRTYTWO_BIT_TC_MASK ); + + mpMaskBmp1bpp = createBitmapDevice( aSize, + true, + Format::ONE_BIT_MSB_GREY ); + + mpBmp1bpp = createBitmapDevice( aSize, + true, + Format::ONE_BIT_MSB_PAL ); + mpBmp32bpp = createBitmapDevice( aSize, + true, + Format::THIRTYTWO_BIT_TC_MASK ); + + ::rtl::OUString aSvg( RTL_CONSTASCII_USTRINGPARAM( "m 0 0h5v10h5v-5h-10z" )); + + basegfx::B2DPolyPolygon aPoly; + basegfx::tools::importFromSvgD( aPoly, aSvg ); + const Color aColWhite(0xFFFFFFFF); + const Color aColBlack(0); + mpBmp1bpp->fillPolyPolygon( + aPoly, + aColWhite, + DrawMode_PAINT ); + mpBmp32bpp->fillPolyPolygon( + aPoly, + aColWhite, + DrawMode_PAINT ); + + aSvg = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( + "m 0 0 h6 v10 h-6z" )); + + aPoly.clear(); + basegfx::tools::importFromSvgD( aPoly, aSvg ); + mpMaskBmp1bpp->clear(aColWhite); + mpMaskBmp1bpp->fillPolyPolygon( + aPoly, + aColBlack, + DrawMode_PAINT ); + } + + void testBmpBasics() + { + implTestBmpBasics( mpDevice1bpp, mpBmp1bpp ); + implTestBmpBasics( mpDevice32bpp, mpBmp32bpp ); + } + + void testBmpClip() + { + implTestBmpScaledClip( mpDevice1bpp, mpBmp1bpp ); + implTestBmpScaledClip( mpDevice32bpp, mpBmp32bpp ); + } + + // Change the following lines only, if you add, remove or rename + // member functions of the current class, + // because these macros are need by auto register mechanism. + + CPPUNIT_TEST_SUITE(BmpMaskTest); + CPPUNIT_TEST(testBmpBasics); + CPPUNIT_TEST(testBmpClip); + CPPUNIT_TEST_SUITE_END(); +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(BmpMaskTest); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/basebmp/test/bmptest.cxx b/basebmp/test/bmptest.cxx new file mode 100644 index 000000000000..7b3a2cbcb18f --- /dev/null +++ b/basebmp/test/bmptest.cxx @@ -0,0 +1,200 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// autogenerated file with codegen.pl + +#include "cppunit/TestAssert.h" +#include "cppunit/TestFixture.h" +#include "cppunit/extensions/HelperMacros.h" + +#include <basegfx/vector/b2isize.hxx> +#include <basegfx/range/b2irange.hxx> +#include <basegfx/point/b2ipoint.hxx> +#include <basegfx/polygon/b2dpolygon.hxx> +#include <basegfx/polygon/b2dpolygontools.hxx> +#include <basegfx/polygon/b2dpolypolygon.hxx> +#include <basegfx/polygon/b2dpolypolygontools.hxx> + +#include <basebmp/color.hxx> +#include <basebmp/scanlineformats.hxx> +#include <basebmp/bitmapdevice.hxx> +#include "tools.hxx" + +using namespace ::basebmp; + +namespace +{ +class BmpTest : public CppUnit::TestFixture +{ +private: + BitmapDeviceSharedPtr mpDevice1bpp; + BitmapDeviceSharedPtr mpBmp1bpp; + BitmapDeviceSharedPtr mpDevice32bpp; + BitmapDeviceSharedPtr mpBmp32bpp; + + void implTestBmpBasics(const BitmapDeviceSharedPtr& rDevice, + const BitmapDeviceSharedPtr& rBmp) + { + rDevice->clear(Color(0)); + const Color aCol(0xFFFFFFFF); + + const basegfx::B2IRange aSourceRect(0,0,10,10); + const basegfx::B2IRange aDestLeftTop(0,0,4,4); + const basegfx::B2IRange aDestRightTop(6,0,10,4); + const basegfx::B2IRange aDestLeftBottom(0,6,4,10); + const basegfx::B2IRange aDestRightBottom(6,6,10,10); + + rDevice->drawBitmap( + rBmp, + aSourceRect, + aDestLeftTop, + DrawMode_PAINT ); + CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 8", + countPixel( rDevice, aCol ) == 8); + + rDevice->drawBitmap( + rBmp, + aSourceRect, + aDestRightTop, + DrawMode_PAINT ); + CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 16", + countPixel( rDevice, aCol ) == 16); + + rDevice->drawBitmap( + rBmp, + aSourceRect, + aDestLeftBottom, + DrawMode_PAINT ); + CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 24", + countPixel( rDevice, aCol ) == 24); + + rDevice->drawBitmap( + rBmp, + aSourceRect, + aDestRightBottom, + DrawMode_PAINT ); + CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 32", + countPixel( rDevice, aCol ) == 32); + } + + void implTestBmpClip(const BitmapDeviceSharedPtr& rDevice, + const BitmapDeviceSharedPtr& rBmp) + { + rDevice->clear(Color(0)); + const Color aCol(0xFFFFFFFF); + + const basegfx::B2IRange aSourceRect(0,0,10,10); + const basegfx::B2IRange aDestLeftTop(-2,-2,2,2); + const basegfx::B2IRange aDestRightTop(8,-2,12,2); + const basegfx::B2IRange aDestLeftBottom(-2,8,2,12); + const basegfx::B2IRange aDestRightBottom(8,8,12,12); + + rDevice->drawBitmap( + rBmp, + aSourceRect, + aDestLeftTop, + DrawMode_PAINT ); + CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 4", + countPixel( rDevice, aCol ) == 4); + + rDevice->drawBitmap( + rBmp, + aSourceRect, + aDestLeftBottom, + DrawMode_PAINT ); + CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 4(c)", + countPixel( rDevice, aCol ) == 4); + + rDevice->drawBitmap( + rBmp, + aSourceRect, + aDestRightBottom, + DrawMode_PAINT ); + CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 8", + countPixel( rDevice, aCol ) == 8); + } + +public: + void setUp() + { + const basegfx::B2ISize aSize(10,10); + mpDevice1bpp = createBitmapDevice( aSize, + true, + Format::ONE_BIT_MSB_PAL ); + mpDevice32bpp = createBitmapDevice( aSize, + true, + Format::THIRTYTWO_BIT_TC_MASK ); + + mpBmp1bpp = createBitmapDevice( aSize, + true, + Format::ONE_BIT_MSB_PAL ); + mpBmp32bpp = createBitmapDevice( aSize, + true, + Format::THIRTYTWO_BIT_TC_MASK ); + + ::rtl::OUString aSvg( RTL_CONSTASCII_USTRINGPARAM( "m 0 0h5v10h5v-5h-10z" )); + + basegfx::B2DPolyPolygon aPoly; + basegfx::tools::importFromSvgD( aPoly, aSvg ); + const Color aCol(0xFFFFFFFF); + mpBmp1bpp->fillPolyPolygon( + aPoly, + aCol, + DrawMode_PAINT ); + mpBmp32bpp->fillPolyPolygon( + aPoly, + aCol, + DrawMode_PAINT ); + } + + void testBmpBasics() + { + implTestBmpBasics( mpDevice1bpp, mpBmp1bpp ); + implTestBmpBasics( mpDevice32bpp, mpBmp32bpp ); + } + + void testBmpClip() + { + implTestBmpClip( mpDevice1bpp, mpBmp1bpp ); + implTestBmpClip( mpDevice32bpp, mpBmp32bpp ); + } + + // Change the following lines only, if you add, remove or rename + // member functions of the current class, + // because these macros are need by auto register mechanism. + + CPPUNIT_TEST_SUITE(BmpTest); + CPPUNIT_TEST(testBmpBasics); + CPPUNIT_TEST(testBmpClip); + CPPUNIT_TEST_SUITE_END(); +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(BmpTest); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/basebmp/test/cliptest.cxx b/basebmp/test/cliptest.cxx new file mode 100644 index 000000000000..c41edf3e28a8 --- /dev/null +++ b/basebmp/test/cliptest.cxx @@ -0,0 +1,268 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// autogenerated file with codegen.pl + +#include "cppunit/TestAssert.h" +#include "cppunit/TestFixture.h" +#include "cppunit/extensions/HelperMacros.h" + +#include <basegfx/vector/b2isize.hxx> +#include <basegfx/point/b2ipoint.hxx> +#include <basegfx/range/b2drange.hxx> +#include <basegfx/range/b2irange.hxx> +#include <basegfx/polygon/b2dpolygon.hxx> +#include <basegfx/polygon/b2dpolygontools.hxx> +#include <basegfx/polygon/b2dpolypolygon.hxx> +#include <basegfx/polygon/b2dpolypolygontools.hxx> + +#include <basebmp/color.hxx> +#include <basebmp/scanlineformats.hxx> +#include <basebmp/bitmapdevice.hxx> +#include "tools.hxx" + +using namespace ::basebmp; + +namespace +{ +class ClipTest : public CppUnit::TestFixture +{ +private: + BitmapDeviceSharedPtr mpClipMask; + BitmapDeviceSharedPtr mpDevice1bpp; + BitmapDeviceSharedPtr mpDevice32bpp; + + void implTestPixelClip(const BitmapDeviceSharedPtr& rDevice) + { + const Color aBgCol(0); + rDevice->clear(aBgCol); + + const basegfx::B2IPoint aPt(0,0); + const Color aCol(0xFFFFFFFF); + rDevice->setPixel( aPt, aCol, DrawMode_PAINT, mpClipMask ); + CPPUNIT_ASSERT_MESSAGE("get/setPixel clip #1", + rDevice->getPixel(aPt) == aBgCol); + + const basegfx::B2IPoint aPt2(10,10); + rDevice->setPixel( aPt2, aCol, DrawMode_PAINT, mpClipMask ); + CPPUNIT_ASSERT_MESSAGE("get/setPixel clip #2", + rDevice->getPixel(aPt2) == aBgCol); + + const basegfx::B2IPoint aPt1(10,0); + rDevice->setPixel( aPt1, aCol, DrawMode_PAINT, mpClipMask ); + CPPUNIT_ASSERT_MESSAGE("get/setPixel clip #3", + rDevice->getPixel(aPt1) != aBgCol); + + const basegfx::B2IPoint aPt3(0,10); + rDevice->setPixel( aPt3, aCol, DrawMode_PAINT, mpClipMask ); + CPPUNIT_ASSERT_MESSAGE("get/setPixel clip #4", + rDevice->getPixel(aPt3) != aBgCol); + } + + void implTestLineClip(const BitmapDeviceSharedPtr& rDevice) + { + const Color aBgCol(0); + rDevice->clear(aBgCol); + + const basegfx::B2IPoint aPt1(0,0); + const basegfx::B2IPoint aPt2(1,9); + const Color aCol(0xFFFFFFFF); + rDevice->drawLine( aPt1, aPt2, aCol, DrawMode_PAINT, mpClipMask ); + + const basegfx::B2IPoint aPt3(1,5); + CPPUNIT_ASSERT_MESSAGE("get line pixel", + rDevice->getPixel(aPt3) != aBgCol); + CPPUNIT_ASSERT_MESSAGE("number of rendered line pixel is not 4", + countPixel( rDevice, + rDevice->getPixel(aPt3) ) == 4); + + rDevice->drawLine( aPt1, aPt2, aCol, DrawMode_XOR, mpClipMask ); + CPPUNIT_ASSERT_MESSAGE("number of xor-rendered line pixel is not 0", + countPixel( rDevice, + rDevice->getPixel(aPt3) ) == 121); + } + + void implTestFillClip(const BitmapDeviceSharedPtr& rDevice) + { + rDevice->clear(Color(0)); + + const basegfx::B2DRange aAllOver(-10,-10,20,20); + const Color aCol(0xFFFFFFFF); + rDevice->fillPolyPolygon( basegfx::B2DPolyPolygon( + basegfx::tools::createPolygonFromRect(aAllOver)), + aCol, + DrawMode_PAINT, + mpClipMask ); + const basegfx::B2IPoint aPt(0,10); + CPPUNIT_ASSERT_MESSAGE("number of clipped pixel is not 30", + countPixel( rDevice, rDevice->getPixel(aPt) ) == 121-30); + + rDevice->fillPolyPolygon( basegfx::B2DPolyPolygon( + basegfx::tools::createPolygonFromRect(aAllOver)), + aCol, + DrawMode_PAINT ); + CPPUNIT_ASSERT_MESSAGE("number of filled pixel is not 121", + countPixel( rDevice, rDevice->getPixel(aPt) ) == 121); + + rDevice->fillPolyPolygon( basegfx::B2DPolyPolygon( + basegfx::tools::createPolygonFromRect(aAllOver)), + aCol, + DrawMode_XOR, + mpClipMask ); + CPPUNIT_ASSERT_MESSAGE("number of xor-cleared pixel is not 91", + countPixel( rDevice, rDevice->getPixel(aPt) ) == 121-30); + } + + void implTestBmpClip(const BitmapDeviceSharedPtr& rDevice) + { + BitmapDeviceSharedPtr pBmp( cloneBitmapDevice( + basegfx::B2IVector(3,3), + rDevice )); + Color aCol1(0); + Color aCol2(0xFFFFFFFF); + pBmp->clear(aCol1); + pBmp->setPixel(basegfx::B2IPoint(0,0),aCol2,DrawMode_PAINT); + pBmp->setPixel(basegfx::B2IPoint(1,1),aCol2,DrawMode_PAINT); + pBmp->setPixel(basegfx::B2IPoint(2,2),aCol2,basebmp::DrawMode_PAINT); + + rDevice->clear(aCol1); + rDevice->drawBitmap(pBmp, + basegfx::B2IRange(0,0,3,3), + basegfx::B2IRange(-1,-1,4,4), + DrawMode_PAINT, + mpClipMask); + + const basegfx::B2IPoint aPt(1,1); + CPPUNIT_ASSERT_MESSAGE("number of clipped pixel is not 5", + countPixel( rDevice, + rDevice->getPixel(aPt) ) == 5); + } + + void implTestMaskColorClip(const BitmapDeviceSharedPtr& rDevice) + { + BitmapDeviceSharedPtr pBmp( createBitmapDevice( rDevice->getSize(), + true, + Format::EIGHT_BIT_GREY )); + + ::rtl::OUString aSvg( RTL_CONSTASCII_USTRINGPARAM( "m 0 0h5v10h5v-5h-10z" )); + + basegfx::B2DPolyPolygon aPoly; + basegfx::tools::importFromSvgD( aPoly, aSvg ); + const basebmp::Color aCol(0xFF); + pBmp->clear( basebmp::Color(0) ); + pBmp->fillPolyPolygon( + aPoly, + aCol, + basebmp::DrawMode_PAINT ); + + const basegfx::B2IRange aSourceRect(0,0,10,10); + const basegfx::B2IPoint aDestLeftTop(0,0); + const Color aCol2(0xF0F0F0F0); + rDevice->drawMaskedColor( + aCol2, + pBmp, + aSourceRect, + aDestLeftTop, + mpClipMask ); + const basegfx::B2IPoint aPt(1,1); + CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 41", + countPixel( rDevice, rDevice->getPixel(aPt) ) == 41); + + } + +public: + void setUp() + { + const basegfx::B2ISize aSize(11,11); + mpClipMask = createBitmapDevice( aSize, + true, + Format::ONE_BIT_MSB_GREY ); + mpDevice1bpp = createBitmapDevice( aSize, + true, + Format::ONE_BIT_MSB_PAL ); + mpDevice32bpp = createBitmapDevice( aSize, + true, + Format::THIRTYTWO_BIT_TC_MASK ); + + ::rtl::OUString aSvg( RTL_CONSTASCII_USTRINGPARAM( "m 0 0 h5 l5 5 v5 h-5 l-5-5 z" )); + basegfx::B2DPolyPolygon aPoly; + basegfx::tools::importFromSvgD( aPoly, aSvg ); + mpClipMask->clear(Color(0)); + mpClipMask->drawPolygon( + aPoly.getB2DPolygon(0), + Color(0xFFFFFFFF), + DrawMode_PAINT ); + } + + void testPixelClip() + { + implTestPixelClip( mpDevice1bpp ); + implTestPixelClip( mpDevice32bpp ); + } + + void testLineClip() + { + implTestLineClip( mpDevice1bpp ); + implTestLineClip( mpDevice32bpp ); + } + + void testFillClip() + { + implTestFillClip( mpDevice1bpp ); + implTestFillClip( mpDevice32bpp ); + } + + void testBmpClip() + { + implTestBmpClip( mpDevice1bpp ); + implTestBmpClip( mpDevice32bpp ); + } + + void testMaskColorClip() + { + implTestMaskColorClip( mpDevice1bpp ); + implTestMaskColorClip( mpDevice32bpp ); + } + + // Change the following lines only, if you add, remove or rename + // member functions of the current class, + // because these macros are need by auto register mechanism. + + CPPUNIT_TEST_SUITE(ClipTest); + CPPUNIT_TEST(testPixelClip); + CPPUNIT_TEST(testLineClip); + CPPUNIT_TEST(testFillClip); + CPPUNIT_TEST(testBmpClip); + CPPUNIT_TEST(testMaskColorClip); + CPPUNIT_TEST_SUITE_END(); +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(ClipTest); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/basebmp/test/export.map b/basebmp/test/export.map new file mode 100644 index 000000000000..3308588ef6f8 --- /dev/null +++ b/basebmp/test/export.map @@ -0,0 +1,34 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +UDK_3_0_0 { + global: + cppunitTestPlugIn; + + local: + *; +}; diff --git a/basebmp/test/filltest.cxx b/basebmp/test/filltest.cxx new file mode 100644 index 000000000000..d15fa1010050 --- /dev/null +++ b/basebmp/test/filltest.cxx @@ -0,0 +1,263 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// autogenerated file with codegen.pl + +#include "cppunit/TestAssert.h" +#include "cppunit/TestFixture.h" +#include "cppunit/extensions/HelperMacros.h" + +#include <basegfx/vector/b2isize.hxx> +#include <basegfx/range/b2drange.hxx> +#include <basegfx/point/b2ipoint.hxx> +#include <basegfx/polygon/b2dpolygon.hxx> +#include <basegfx/polygon/b2dpolygontools.hxx> +#include <basegfx/polygon/b2dpolypolygon.hxx> +#include <basegfx/polygon/b2dpolypolygontools.hxx> + +#include <basebmp/color.hxx> +#include <basebmp/scanlineformats.hxx> +#include <basebmp/bitmapdevice.hxx> +#include "tools.hxx" + +using namespace ::basebmp; + +namespace +{ +class FillTest : public CppUnit::TestFixture +{ +private: + BitmapDeviceSharedPtr mpDevice1bpp; + BitmapDeviceSharedPtr mpDevice32bpp; + + void implTestRectFill(const BitmapDeviceSharedPtr& rDevice) + { + rDevice->clear(Color(0)); + + const basegfx::B2DRange aRect(1,1,10,10); + + const Color aCol(0xFFFFFFFF); + rDevice->fillPolyPolygon( + basegfx::B2DPolyPolygon( + basegfx::tools::createPolygonFromRect( aRect )), + aCol, + DrawMode_PAINT ); + + const basegfx::B2IPoint aPt1(1,1); + CPPUNIT_ASSERT_MESSAGE("first pixel set", + rDevice->getPixel(aPt1) == aCol); + const basegfx::B2IPoint aPt2(9,9); + CPPUNIT_ASSERT_MESSAGE("last pixel set", + rDevice->getPixel(aPt2) == aCol); + const basegfx::B2IPoint aPt3(0,0); + CPPUNIT_ASSERT_MESSAGE("topmost pixel not set", + rDevice->getPixel(aPt3) != aCol); + const basegfx::B2IPoint aPt4(10,10); + CPPUNIT_ASSERT_MESSAGE("bottommost pixel not set", + rDevice->getPixel(aPt4) != aCol); + + CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 81", + countPixel( rDevice, aCol ) == 81); + } + + void implTestCornerCases(const BitmapDeviceSharedPtr& rDevice) + { + rDevice->clear(Color(0)); + + const basegfx::B2DRange aEmpty1(0,0,0,11); + const basegfx::B2DRange aEmpty2(0,0,11,0); + const basegfx::B2DRange aVertLineLeft(0,0,1,11); + const basegfx::B2DRange aVertLineRight(10,0,11,11); + const basegfx::B2DRange aHorzLineTop(0,0,11,1); + const basegfx::B2DRange aHorzLineBottom(0,10,11,11); + + const Color aCol(0xFFFFFFFF); + rDevice->fillPolyPolygon( + basegfx::B2DPolyPolygon( + basegfx::tools::createPolygonFromRect( aEmpty1 )), + aCol, + DrawMode_PAINT ); + CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 0", + countPixel( rDevice, aCol ) == 0); + + rDevice->fillPolyPolygon( + basegfx::B2DPolyPolygon( + basegfx::tools::createPolygonFromRect( aEmpty2 )), + aCol, + DrawMode_PAINT ); + CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 0", + countPixel( rDevice, aCol ) == 0); + + rDevice->fillPolyPolygon( + basegfx::B2DPolyPolygon( + basegfx::tools::createPolygonFromRect( aVertLineLeft )), + aCol, + DrawMode_PAINT ); + CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 11", + countPixel( rDevice, aCol ) == 11); + const basegfx::B2IPoint aPt1(0,0); + CPPUNIT_ASSERT_MESSAGE("first pixel set", + rDevice->getPixel(aPt1) == aCol); + + rDevice->fillPolyPolygon( + basegfx::B2DPolyPolygon( + basegfx::tools::createPolygonFromRect( aVertLineRight )), + aCol, + DrawMode_PAINT ); + CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 22", + countPixel( rDevice, aCol ) == 22); + const basegfx::B2IPoint aPt2(10,10); + CPPUNIT_ASSERT_MESSAGE("last pixel set", + rDevice->getPixel(aPt2) == aCol); + + rDevice->fillPolyPolygon( + basegfx::B2DPolyPolygon( + basegfx::tools::createPolygonFromRect( aHorzLineTop )), + aCol, + DrawMode_PAINT ); + CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 31", + countPixel( rDevice, aCol ) == 31); + const basegfx::B2IPoint aPt3(5,0); + CPPUNIT_ASSERT_MESSAGE("top-middle pixel set", + rDevice->getPixel(aPt3) == aCol); + + rDevice->fillPolyPolygon( + basegfx::B2DPolyPolygon( + basegfx::tools::createPolygonFromRect( aHorzLineBottom )), + aCol, + DrawMode_PAINT ); + CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 40", + countPixel( rDevice, aCol ) == 40); + const basegfx::B2IPoint aPt4(5,10); + CPPUNIT_ASSERT_MESSAGE("bottom-middle pixel set", + rDevice->getPixel(aPt4) == aCol); + + ::rtl::OUString aSvg( RTL_CONSTASCII_USTRINGPARAM( "m 0 0l7 7h-1z" )); + + basegfx::B2DPolyPolygon aPoly; + basegfx::tools::importFromSvgD( aPoly, aSvg ); + rDevice->fillPolyPolygon( + aPoly, + aCol, + DrawMode_PAINT ); + CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 43", + countPixel( rDevice, aCol ) == 43); + } + + void implTestClipping(const BitmapDeviceSharedPtr& rDevice) + { + rDevice->clear(Color(0)); + + const basegfx::B2DRange aLeftTop(-10,-10,1,1); + const basegfx::B2DRange aRightTop(10,-10,20,1); + const basegfx::B2DRange aLeftBottom(-10,10,1,20); + const basegfx::B2DRange aRightBottom(10,10,20,20); + const basegfx::B2DRange aAllOver(-10,-10,20,20); + + const Color aCol(0xFFFFFFFF); + rDevice->fillPolyPolygon( basegfx::B2DPolyPolygon( + basegfx::tools::createPolygonFromRect(aLeftTop)), + aCol, + DrawMode_PAINT ); + CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 1", + countPixel( rDevice, aCol ) == 1); + + rDevice->fillPolyPolygon( basegfx::B2DPolyPolygon( + basegfx::tools::createPolygonFromRect(aRightTop)), + aCol, + DrawMode_PAINT ); + CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 2", + countPixel( rDevice, aCol ) == 2); + + rDevice->fillPolyPolygon( basegfx::B2DPolyPolygon( + basegfx::tools::createPolygonFromRect(aLeftBottom)), + aCol, + DrawMode_PAINT ); + CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 3", + countPixel( rDevice, aCol ) == 3); + + rDevice->fillPolyPolygon( basegfx::B2DPolyPolygon( + basegfx::tools::createPolygonFromRect(aRightBottom)), + aCol, + DrawMode_PAINT ); + CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 4", + countPixel( rDevice, aCol ) == 4); + + rDevice->fillPolyPolygon( basegfx::B2DPolyPolygon( + basegfx::tools::createPolygonFromRect(aAllOver)), + aCol, + DrawMode_PAINT ); + CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 121", + countPixel( rDevice, aCol ) == 121); + } + +public: + void setUp() + { + const basegfx::B2ISize aSize(11,11); + mpDevice1bpp = createBitmapDevice( aSize, + true, + Format::ONE_BIT_MSB_PAL ); + mpDevice32bpp = createBitmapDevice( aSize, + true, + Format::THIRTYTWO_BIT_TC_MASK ); + } + + void testRectFill() + { + implTestRectFill( mpDevice1bpp ); + implTestRectFill( mpDevice32bpp ); + } + + void testClipping() + { + implTestClipping( mpDevice1bpp ); + implTestClipping( mpDevice32bpp ); + } + + void testCornerCases() + { + implTestCornerCases( mpDevice1bpp ); + implTestCornerCases( mpDevice32bpp ); + } + + // Change the following lines only, if you add, remove or rename + // member functions of the current class, + // because these macros are need by auto register mechanism. + + CPPUNIT_TEST_SUITE(FillTest); + CPPUNIT_TEST(testRectFill); + CPPUNIT_TEST(testClipping); + CPPUNIT_TEST(testCornerCases); + CPPUNIT_TEST_SUITE_END(); +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(FillTest); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/basebmp/test/linetest.cxx b/basebmp/test/linetest.cxx new file mode 100644 index 000000000000..cee66f4d709b --- /dev/null +++ b/basebmp/test/linetest.cxx @@ -0,0 +1,212 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// autogenerated file with codegen.pl + +#include "cppunit/TestAssert.h" +#include "cppunit/TestFixture.h" +#include "cppunit/extensions/HelperMacros.h" + +#include <basegfx/vector/b2isize.hxx> +#include <basegfx/point/b2ipoint.hxx> + +#include <basebmp/color.hxx> +#include <basebmp/scanlineformats.hxx> +#include <basebmp/bitmapdevice.hxx> +#include "tools.hxx" + +using namespace ::basebmp; + +namespace +{ +class LineTest : public CppUnit::TestFixture +{ +private: + BitmapDeviceSharedPtr mpDevice1bpp; + BitmapDeviceSharedPtr mpDevice32bpp; + + void implTestBasicDiagonalLines(const BitmapDeviceSharedPtr& rDevice) + { + rDevice->clear(Color(0)); + + const basegfx::B2IPoint aPt1(1,1); + const basegfx::B2IPoint aPt2(9,9); + const Color aCol(0xFFFFFFFF); + rDevice->drawLine( aPt1, aPt2, aCol, DrawMode_PAINT ); + CPPUNIT_ASSERT_MESSAGE("first pixel set", + rDevice->getPixel(aPt1) == aCol); + CPPUNIT_ASSERT_MESSAGE("last pixel set", + rDevice->getPixel(aPt2) == aCol); + const basegfx::B2IPoint aPt3(0,0); + CPPUNIT_ASSERT_MESSAGE("topmost pixel not set", + rDevice->getPixel(aPt3) != aCol); + const basegfx::B2IPoint aPt4(10,10); + CPPUNIT_ASSERT_MESSAGE("bottommost pixel not set", + rDevice->getPixel(aPt4) != aCol); + + CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 9", + countPixel( rDevice, aCol ) == 9); + + rDevice->drawLine( aPt2, aPt1, aCol, DrawMode_PAINT ); + + CPPUNIT_ASSERT_MESSAGE("number of rendered pixel after " + "reversed paint is not 9", + countPixel( rDevice, aCol ) == 9); + } + + void implTestBasicHorizontalLines(const BitmapDeviceSharedPtr& rDevice) + { + rDevice->clear(Color(0)); + + const basegfx::B2IPoint aPt1(10,10); + const basegfx::B2IPoint aPt2(0,10); + const Color aCol(0xFFFFFFFF); + rDevice->drawLine( aPt1, aPt2, aCol, DrawMode_PAINT ); + CPPUNIT_ASSERT_MESSAGE("first pixel set", + rDevice->getPixel(aPt1) == aCol); + CPPUNIT_ASSERT_MESSAGE("last pixel set", + rDevice->getPixel(aPt2) == aCol); + CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 11", + countPixel( rDevice, aCol ) == 11); + + rDevice->clear(Color(0)); + rDevice->drawLine( aPt2, aPt1, aCol, DrawMode_PAINT ); + CPPUNIT_ASSERT_MESSAGE("first pixel set", + rDevice->getPixel(aPt1) == aCol); + CPPUNIT_ASSERT_MESSAGE("last pixel set", + rDevice->getPixel(aPt2) == aCol); + CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 11", + countPixel( rDevice, aCol ) == 11); + } + + void implTestBasicVerticalLines(const BitmapDeviceSharedPtr& rDevice) + { + rDevice->clear(Color(0)); + + const basegfx::B2IPoint aPt1(1,1); + const basegfx::B2IPoint aPt2(1,9); + const Color aCol(0xFFFFFFFF); + rDevice->drawLine( aPt1, aPt2, aCol, DrawMode_PAINT ); + CPPUNIT_ASSERT_MESSAGE("first pixel set", + rDevice->getPixel(aPt1) == aCol); + CPPUNIT_ASSERT_MESSAGE("last pixel set", + rDevice->getPixel(aPt2) == aCol); + const basegfx::B2IPoint aPt3(0,0); + CPPUNIT_ASSERT_MESSAGE("topmost pixel not set", + rDevice->getPixel(aPt3) != aCol); + const basegfx::B2IPoint aPt4(0,10); + CPPUNIT_ASSERT_MESSAGE("bottommost pixel not set", + rDevice->getPixel(aPt4) != aCol); + + CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 9", + countPixel( rDevice, aCol ) == 9); + } + + // test pixel rounding (should always tend towards start point of + // the line) + void implTestTieBreaking(const BitmapDeviceSharedPtr& rDevice) + { + rDevice->clear(Color(0)); + + const basegfx::B2IPoint aPt1(1,1); + const basegfx::B2IPoint aPt2(3,2); + const Color aCol(0xFFFFFFFF); + rDevice->drawLine( aPt1, aPt2, aCol, DrawMode_PAINT ); + CPPUNIT_ASSERT_MESSAGE("first pixel set", + rDevice->getPixel(aPt1) == aCol); + CPPUNIT_ASSERT_MESSAGE("second pixel set", + rDevice->getPixel(basegfx::B2IPoint(2,1)) == aCol); + CPPUNIT_ASSERT_MESSAGE("last pixel set", + rDevice->getPixel(aPt2) == aCol); + CPPUNIT_ASSERT_MESSAGE("number of rendered pixel after " + "reversed paint is not 3", + countPixel( rDevice, aCol ) == 3); + + rDevice->drawLine( aPt2, aPt1, aCol, DrawMode_PAINT ); + CPPUNIT_ASSERT_MESSAGE("alternate second pixel set", + rDevice->getPixel(basegfx::B2IPoint(2,2)) == aCol); + + CPPUNIT_ASSERT_MESSAGE("number of rendered pixel after " + "reversed paint is not 4", + countPixel( rDevice, aCol ) == 4); + } + +public: + void setUp() + { + const basegfx::B2ISize aSize(11,11); + mpDevice1bpp = createBitmapDevice( aSize, + true, + Format::ONE_BIT_MSB_PAL ); + mpDevice32bpp = createBitmapDevice( aSize, + true, + Format::THIRTYTWO_BIT_TC_MASK ); + } + + void testBasicDiagonalLines() + { + implTestBasicDiagonalLines( mpDevice1bpp ); + implTestBasicDiagonalLines( mpDevice32bpp ); + } + + void testBasicHorizontalLines() + { + implTestBasicHorizontalLines( mpDevice1bpp ); + implTestBasicHorizontalLines( mpDevice32bpp ); + } + + void testBasicVerticalLines() + { + implTestBasicVerticalLines( mpDevice1bpp ); + implTestBasicVerticalLines( mpDevice32bpp ); + } + + // test pixel rounding (should always tend towards start point of + // the line) + void testTieBreaking() + { + implTestTieBreaking( mpDevice1bpp ); + implTestTieBreaking( mpDevice32bpp ); + } + + // Change the following lines only, if you add, remove or rename + // member functions of the current class, + // because these macros are need by auto register mechanism. + + CPPUNIT_TEST_SUITE(LineTest); + CPPUNIT_TEST(testBasicDiagonalLines); + CPPUNIT_TEST(testBasicHorizontalLines); + CPPUNIT_TEST(testBasicVerticalLines); + CPPUNIT_TEST(testTieBreaking); + CPPUNIT_TEST_SUITE_END(); +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(LineTest); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/basebmp/test/makefile.mk b/basebmp/test/makefile.mk new file mode 100644 index 000000000000..4fdc39bb6fd4 --- /dev/null +++ b/basebmp/test/makefile.mk @@ -0,0 +1,113 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +PRJ=.. + +PRJNAME=basebmp +TARGET=tests +TARGETTYPE=GUI + +ENABLE_EXCEPTIONS=TRUE + +# --- Settings ----------------------------------------------------- + +.INCLUDE : settings.mk + +.IF "$(debug)"!="" || "$(DEBUG)"!="" + +.IF "$(COM)"=="MSC" +# disable inlining for MSVC +CFLAGS += -Ob0 +.ENDIF + +.IF "$(COM)"=="GCC" +# disable inlining for gcc +CFLAGS += -fno-inline +.ENDIF + +.ENDIF + +# SunStudio 12 (-m64 and -m32 modes): three test cases of the unit tests fail +# if compiled with default -xalias_level (and optimization level -xO3) +.IF "$(OS)"=="SOLARIS" +# For Sun Studio 8 this switch does not work: compilation fails on bitmapdevice.cxx +.IF "$(CCNUMVER)"!="00050005" +CDEFS+=-xalias_level=compatible +.ENDIF +.ENDIF + +#building with stlport, but cppunit was not built with stlport +.IF "$(USE_SYSTEM_STL)"!="YES" +.IF "$(SYSTEM_CPPUNIT)"=="YES" +CFLAGSCXX+=-DADAPT_EXT_STL +.ENDIF +.ENDIF + +CFLAGSCXX += $(CPPUNIT_CFLAGS) + +# --- Common ---------------------------------------------------------- +.IF "$(L10N_framework)"=="" + +# BEGIN ---------------------------------------------------------------- +# auto generated Target:tests by codegen.pl +SHL1OBJS= \ + $(SLO)$/basictest.obj \ + $(SLO)$/bmpmasktest.obj \ + $(SLO)$/bmptest.obj \ + $(SLO)$/cliptest.obj \ + $(SLO)$/filltest.obj \ + $(SLO)$/linetest.obj \ + $(SLO)$/masktest.obj \ + $(SLO)$/polytest.obj \ + $(SLO)$/tools.obj +SHL1TARGET= tests +SHL1STDLIBS= $(BASEBMPLIB) \ + $(SALLIB) \ + $(CPPUNITLIB) \ + $(BASEGFXLIB) + +SHL1IMPLIB= i$(SHL1TARGET) + +DEF1NAME =$(SHL1TARGET) +SHL1VERSIONMAP = export.map +SHL1RPATH = NONE + +.ENDIF +# END ------------------------------------------------------------------ + +#------------------------------- All object files ------------------------------- +# do this here, so we get right dependencies +SLOFILES=$(SHL1OBJS) + +# --- Targets ------------------------------------------------------ + +.INCLUDE : target.mk + +# --- Enable test execution in normal build ------------------------ +.IF "$(L10N_framework)"=="" +.INCLUDE : _cppunit.mk +.ENDIF diff --git a/basebmp/test/masktest.cxx b/basebmp/test/masktest.cxx new file mode 100644 index 000000000000..239a069bf564 --- /dev/null +++ b/basebmp/test/masktest.cxx @@ -0,0 +1,161 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// autogenerated file with codegen.pl + +#include "cppunit/TestAssert.h" +#include "cppunit/TestFixture.h" +#include "cppunit/extensions/HelperMacros.h" + +#include <basegfx/vector/b2isize.hxx> +#include <basegfx/range/b2irange.hxx> +#include <basegfx/point/b2ipoint.hxx> +#include <basegfx/polygon/b2dpolygon.hxx> +#include <basegfx/polygon/b2dpolygontools.hxx> +#include <basegfx/polygon/b2dpolypolygon.hxx> +#include <basegfx/polygon/b2dpolypolygontools.hxx> + +#include <basebmp/color.hxx> +#include <basebmp/scanlineformats.hxx> +#include <basebmp/bitmapdevice.hxx> +#include "tools.hxx" + +using namespace ::basebmp; + +namespace +{ +class MaskTest : public CppUnit::TestFixture +{ +private: + BitmapDeviceSharedPtr mpDevice1bpp; + BitmapDeviceSharedPtr mpDevice32bpp; + BitmapDeviceSharedPtr mpMask; + + void implTestMaskBasics(const BitmapDeviceSharedPtr& rDevice, + const BitmapDeviceSharedPtr& rBmp) + { + const Color aCol(0); + const Color aCol2(0xF0F0F0F0); + + const basegfx::B2IRange aSourceRect(0,0,10,10); + const basegfx::B2IPoint aDestLeftTop(0,0); + const basegfx::B2IPoint aDestRightTop(5,0); + const basegfx::B2IPoint aDestLeftBottom(0,5); + const basegfx::B2IPoint aDestRightBottom(5,5); + + rDevice->clear(aCol); + rDevice->setPixel( + basegfx::B2IPoint(1,1), + aCol2, + DrawMode_PAINT); + rDevice->drawMaskedColor( + aCol2, + rBmp, + aSourceRect, + aDestLeftTop ); + CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 50", + countPixel( rDevice, aCol ) == 100-50); + + rDevice->clear(aCol); + rDevice->drawMaskedColor( + aCol2, + rBmp, + aSourceRect, + aDestRightTop ); + CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 25", + countPixel( rDevice, aCol ) == 100-25); + + rDevice->clear(aCol); + rDevice->drawMaskedColor( + aCol2, + rBmp, + aSourceRect, + aDestLeftBottom ); + CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 25(b)", + countPixel( rDevice, aCol ) == 100-25); + + rDevice->clear(aCol); + rDevice->drawMaskedColor( + aCol2, + rBmp, + aSourceRect, + aDestRightBottom ); + CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 25(c)", + countPixel( rDevice, aCol ) == 100-25); + } + +public: + void setUp() + { + const basegfx::B2ISize aSize(10,10); + mpDevice1bpp = createBitmapDevice( aSize, + true, + Format::ONE_BIT_MSB_PAL ); + mpDevice32bpp = createBitmapDevice( aSize, + true, + Format::THIRTYTWO_BIT_TC_MASK ); + + mpMask = createBitmapDevice( aSize, + true, + Format::EIGHT_BIT_GREY ); + + ::rtl::OUString aSvg( RTL_CONSTASCII_USTRINGPARAM( "m 0 0h5v10h5v-5h-10z" )); + + basegfx::B2DPolyPolygon aPoly; + basegfx::tools::importFromSvgD( aPoly, aSvg ); + const Color aCol(0xFF); + mpMask->fillPolyPolygon( + aPoly, + aCol, + DrawMode_PAINT ); + } + + void testMaskBasics() + { + implTestMaskBasics( mpDevice32bpp, mpMask ); + implTestMaskBasics( mpDevice1bpp, mpMask ); + } + + void testMaskClip() + { + } + + // Change the following lines only, if you add, remove or rename + // member functions of the current class, + // because these macros are need by auto register mechanism. + + CPPUNIT_TEST_SUITE(MaskTest); + CPPUNIT_TEST(testMaskBasics); + CPPUNIT_TEST(testMaskClip); + CPPUNIT_TEST_SUITE_END(); +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(MaskTest); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/basebmp/test/polytest.cxx b/basebmp/test/polytest.cxx new file mode 100644 index 000000000000..99aba1a06fc4 --- /dev/null +++ b/basebmp/test/polytest.cxx @@ -0,0 +1,284 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// autogenerated file with codegen.pl + +#include "cppunit/TestAssert.h" +#include "cppunit/TestFixture.h" +#include "cppunit/extensions/HelperMacros.h" + +#include <basegfx/vector/b2isize.hxx> +#include <basegfx/range/b2irange.hxx> +#include <basegfx/point/b2ipoint.hxx> +#include <basegfx/matrix/b2dhommatrix.hxx> +#include <basegfx/polygon/b2dpolygon.hxx> +#include <basegfx/polygon/b2dpolygontools.hxx> +#include <basegfx/polygon/b2dpolypolygon.hxx> +#include <basegfx/polygon/b2dpolypolygontools.hxx> + +#include <basebmp/color.hxx> +#include <basebmp/scanlineformats.hxx> +#include <basebmp/bitmapdevice.hxx> +#include "tools.hxx" + +using namespace ::basebmp; + +namespace +{ +class PolyTest : public CppUnit::TestFixture +{ +private: + BitmapDeviceSharedPtr mpDevice1bpp; + BitmapDeviceSharedPtr mpDevice32bpp; + + void implTestEmpty(const BitmapDeviceSharedPtr& rDevice) + { + const Color aCol(0xFFFFFFFF); + const Color aBgCol(0); + rDevice->clear(aBgCol); + basegfx::B2DPolyPolygon aPoly; + ::rtl::OUString aSvg; + + basegfx::tools::importFromSvgD( + aPoly, + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( + "M2 2 l7 7 z" )) ); + rDevice->fillPolyPolygon( + aPoly, + aCol, + DrawMode_PAINT ); + CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 0", + countPixel( rDevice, aCol ) == 0); + + // -------------------------------------------------- + + rDevice->clear(aBgCol); + aPoly.clear(); + basegfx::tools::importFromSvgD( + aPoly, + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( + "M7 2 l-6 6 z" )) ); + rDevice->fillPolyPolygon( + aPoly, + aCol, + DrawMode_PAINT ); + CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 0(b)", + countPixel( rDevice, aCol ) == 0); + } + + void implTestHairline(const BitmapDeviceSharedPtr& rDevice) + { + const Color aCol(0xFFFFFFFF); + const Color aBgCol(0); + rDevice->clear(aBgCol); + basegfx::B2DPolyPolygon aPoly; + ::rtl::OUString aSvg; + + basegfx::tools::importFromSvgD( + aPoly, + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( + "M2 2 h1 l7 7 h-1 z" )) ); + rDevice->fillPolyPolygon( + aPoly, + aCol, + DrawMode_PAINT ); + CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 7", + countPixel( rDevice, aCol ) == 7); + + // -------------------------------------------------- + + rDevice->clear(aBgCol); + aPoly.clear(); + basegfx::tools::importFromSvgD( + aPoly, + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( + "M7 2 h-1 l-6 6 h1 z" )) ); + rDevice->fillPolyPolygon( + aPoly, + aCol, + DrawMode_PAINT ); + CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 6", + countPixel( rDevice, aCol ) == 6); + + // -------------------------------------------------- + + rDevice->clear(aBgCol); + aPoly.clear(); + basegfx::tools::importFromSvgD( + aPoly, + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( + "M0 0 l7 7 h-1 l-5-7 z" )) ); + rDevice->fillPolyPolygon( + aPoly, + aCol, + DrawMode_PAINT ); + CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 3", + countPixel( rDevice, aCol ) == 3); + } + + void implTestPolyPoly(const BitmapDeviceSharedPtr& rDevice) + { + const Color aCol(0xFFFFFFFF); + const Color aBgCol(0); + rDevice->clear(aBgCol); + basegfx::B2DPolyPolygon aPoly; + ::rtl::OUString aSvg; + + basegfx::tools::importFromSvgD( aPoly, + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( + "M0 0 h7 v7 h-7 z M2 2 v3 h3 v-3 z" )) ); + + rDevice->fillPolyPolygon( + aPoly, + aCol, + DrawMode_PAINT ); + CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 40", + countPixel( rDevice, aCol ) == 40); + } + + void implTestPolyPolyClip(const BitmapDeviceSharedPtr& rDevice) + { + const Color aCol(0xFFFFFFFF); + const Color aBgCol(0); + rDevice->clear(aBgCol); + basegfx::B2DPolyPolygon aPoly; + ::rtl::OUString aSvg; + + basegfx::tools::importFromSvgD( aPoly, + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( + "M0 0 h7 v7 h-7 z M2 2 v3 h3 v-3 z" )) ); + basegfx::B2DHomMatrix aMat; + aMat.translate(-3,-3); + aMat.rotate( 1.7 ); + aMat.translate(6,5); + aPoly.transform(aMat); + + rDevice->fillPolyPolygon( + aPoly, + aCol, + DrawMode_PAINT ); + + CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 39", + countPixel( rDevice, aCol ) == 39); + + BitmapDeviceSharedPtr pClippedDevice( + subsetBitmapDevice( rDevice, + basegfx::B2IRange(3,3,5,8) )); + + rDevice->clear(aBgCol); + pClippedDevice->fillPolyPolygon( + aPoly, + aCol, + DrawMode_PAINT ); + CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 7", + countPixel( rDevice, aCol ) == 7); + } + + void implTestPolyPolyCrissCross(const BitmapDeviceSharedPtr& rDevice) + { + const Color aCol(0xFFFFFFFF); + const Color aBgCol(0); + rDevice->clear(aBgCol); + basegfx::B2DPolyPolygon aPoly; + ::rtl::OUString aSvg; + + basegfx::tools::importFromSvgD( aPoly, + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( + "M0 0 v2 l10 2 v-2 z" + "M10 6 v-2 l-10 2 v2 z" + "M1 0 h1 v10 h-1 z" + "M4 0 h1 v10 h-1 z" + "M8 0 h1 v10 h-1 z" )) ); + rDevice->fillPolyPolygon( + aPoly, + aCol, + DrawMode_PAINT ); + CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 46", + countPixel( rDevice, aCol ) == 46); + } + + +public: + void setUp() + { + const basegfx::B2ISize aSize(10,10); + mpDevice1bpp = createBitmapDevice( aSize, + true, + Format::ONE_BIT_MSB_PAL ); + mpDevice32bpp = createBitmapDevice( aSize, + true, + Format::THIRTYTWO_BIT_TC_MASK ); + } + + void testEmpty() + { + implTestEmpty( mpDevice1bpp ); + implTestEmpty( mpDevice32bpp ); + } + + void testHairline() + { + implTestHairline( mpDevice1bpp ); + implTestHairline( mpDevice32bpp ); + } + + void testPolyPoly() + { + implTestPolyPoly( mpDevice1bpp ); + implTestPolyPoly( mpDevice32bpp ); + } + + void testPolyPolyClip() + { + implTestPolyPolyClip(mpDevice1bpp); + implTestPolyPolyClip(mpDevice32bpp); + } + + void testPolyPolyCrissCross() + { + implTestPolyPolyCrissCross(mpDevice1bpp); + implTestPolyPolyCrissCross(mpDevice32bpp); + } + + // Change the following lines only, if you add, remove or rename + // member functions of the current class, + // because these macros are need by auto register mechanism. + + CPPUNIT_TEST_SUITE(PolyTest); + CPPUNIT_TEST(testEmpty); + CPPUNIT_TEST(testHairline); + CPPUNIT_TEST(testPolyPoly); + CPPUNIT_TEST(testPolyPolyClip); + CPPUNIT_TEST(testPolyPolyCrissCross); + CPPUNIT_TEST_SUITE_END(); +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(PolyTest); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/basebmp/test/tools.cxx b/basebmp/test/tools.cxx new file mode 100644 index 000000000000..ab7219ec32af --- /dev/null +++ b/basebmp/test/tools.cxx @@ -0,0 +1,52 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// autogenerated file with codegen.pl + +#include <basegfx/vector/b2isize.hxx> +#include <basegfx/point/b2ipoint.hxx> + +#include <basebmp/color.hxx> +#include <basebmp/bitmapdevice.hxx> + +using namespace ::basebmp; + +int countPixel( const BitmapDeviceSharedPtr& rDevice, + Color checkColor ) +{ + int count(0); + const basegfx::B2ISize& rSize( rDevice->getSize() ); + for( sal_Int32 y=0; y<rSize.getY(); ++y ) + for( sal_Int32 x=0; x<rSize.getX(); ++x ) + if( rDevice->getPixel( basegfx::B2IPoint(x,y) ) == checkColor ) + ++count; + + return count; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/basebmp/test/tools.hxx b/basebmp/test/tools.hxx new file mode 100644 index 000000000000..57668e55a741 --- /dev/null +++ b/basebmp/test/tools.hxx @@ -0,0 +1,34 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "basebmp/bitmapdevice.hxx" + +int countPixel( const basebmp::BitmapDeviceSharedPtr& rDevice, + basebmp::Color checkColor ); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |