summaryrefslogtreecommitdiff
path: root/basebmp
diff options
context:
space:
mode:
authorThorsten Behrens <thb@openoffice.org>2006-06-09 03:21:01 +0000
committerThorsten Behrens <thb@openoffice.org>2006-06-09 03:21:01 +0000
commite067c2aa6f19c66e409aac514e781238868ebfed (patch)
tree620ee0db1cb2f82d1a8411e0c3d14c10dfb2e571 /basebmp
parentd2aaa68fd8a2247e8858d9f35fccdf283adfb797 (diff)
#i65904# Fixed mask blending; added tests; reworked metafunctions for clip proxy accessors
Diffstat (limited to 'basebmp')
-rw-r--r--basebmp/inc/basebmp/accessoradapters.hxx205
-rw-r--r--basebmp/inc/basebmp/color.hxx69
-rw-r--r--basebmp/inc/basebmp/metafunctions.hxx49
-rw-r--r--basebmp/source/bitmapdevice.cxx76
-rw-r--r--basebmp/test/bmpdemo.cxx139
-rw-r--r--basebmp/test/masktest.cxx10
6 files changed, 458 insertions, 90 deletions
diff --git a/basebmp/inc/basebmp/accessoradapters.hxx b/basebmp/inc/basebmp/accessoradapters.hxx
index 94491d76445c..84aab23ae833 100644
--- a/basebmp/inc/basebmp/accessoradapters.hxx
+++ b/basebmp/inc/basebmp/accessoradapters.hxx
@@ -4,9 +4,9 @@
*
* $RCSfile: accessoradapters.hxx,v $
*
- * $Revision: 1.5 $
+ * $Revision: 1.6 $
*
- * last change: $Author: thb $ $Date: 2006-06-07 14:27:34 $
+ * last change: $Author: thb $ $Date: 2006-06-09 04:21:00 $
*
* The Contents of this file are made available subject to
* the terms of GNU Lesser General Public License Version 2.1.
@@ -225,17 +225,56 @@ public:
}
};
+
+/// Traits template, to determine alpha blending between two values
+template< typename ValueType, typename AlphaType > struct BlendFunctor
+{
+ ValueType operator()( AlphaType alpha,
+ ValueType v1,
+ ValueType v2 ) const
+ {
+ const typename vigra::NumericTraits<AlphaType>::RealPromote fAlpha(
+ vigra::NumericTraits<AlphaType>::toRealPromote(alpha));
+ return (vigra::NumericTraits<AlphaType>::one()-fAlpha)*v1 + fAlpha*v2;
+ }
+};
+
+template< typename ValueType, typename AlphaType > struct IntegerBlendFunctor
+{
+ ValueType operator()( AlphaType alpha,
+ ValueType v1,
+ ValueType v2 ) const
+ {
+ return (vigra::NumericTraits<AlphaType>::toPromote(
+ vigra::NumericTraits<AlphaType>::max()-alpha)*v1 + alpha*v2) /
+ vigra::NumericTraits<AlphaType>::max();
+ }
+};
+
+/// Metafunction to select blend functor from value and alpha type
+template< typename ValueType, typename AlphaType > struct blendFunctorSelector : public
+ ifScalarIntegral< AlphaType,
+ IntegerBlendFunctor< ValueType, AlphaType >,
+ BlendFunctor< ValueType, AlphaType > >
+{
+};
+
/** Accessor adapter that blends input value against fixed color value
Used to blend an alpha mask 'through' a fixed color value into the
destination.
*/
template< class WrappedAccessor,
- typename ColorType > class ConstantColorBlendAccessorAdapter
+ typename AlphaType > class ConstantColorBlendAccessorAdapter
{
+public:
+ typedef AlphaType alpha_type;
+ typedef typename WrappedAccessor::value_type value_type;
+
private:
- WrappedAccessor maWrappee;
- ColorType maBlendColor;
+ typename blendFunctorSelector< value_type, alpha_type >::type maFunctor;
+ WrappedAccessor maWrappee;
+ value_type maBlendColor;
// TODO(Q3): Merge with
// BinarySetterFunctionAccessorAdapter. Problem there: how to
@@ -243,19 +282,27 @@ private:
// fixed color
public:
- typedef typename WrappedAccessor::value_type value_type;
-
ConstantColorBlendAccessorAdapter() :
+ maFunctor(),
maWrappee(),
maBlendColor()
{}
+ explicit ConstantColorBlendAccessorAdapter( WrappedAccessor acc ) :
+ maFunctor(),
+ maWrappee(acc),
+ maBlendColor()
+ {}
+
ConstantColorBlendAccessorAdapter( WrappedAccessor acc,
- ColorType col ) :
+ value_type col ) :
+ maFunctor(),
maWrappee(acc),
maBlendColor(col)
{}
+ void setColor( value_type col ) { maBlendColor=col; }
+
template< typename IteratorType > value_type operator()(IteratorType const& i) const
{
return maWrappee(i);
@@ -270,7 +317,10 @@ public:
void set(V const& value, IteratorType const& i) const
{
maWrappee.set(
- maBlendColor*value,
+ maFunctor(
+ vigra::detail::RequiresExplicitCast<alpha_type>::cast(value),
+ maWrappee(i),
+ maBlendColor),
i );
}
@@ -278,7 +328,10 @@ public:
void set(V const& value, IteratorType const& i, Difference const& diff) const
{
maWrappee.set(
- maBlendColor*value,
+ maFunctor(
+ vigra::detail::RequiresExplicitCast<alpha_type>::cast(value),
+ maWrappee(i,diff),
+ maBlendColor),
i,
diff );
}
@@ -300,64 +353,101 @@ template< class WrappedAccessor > struct xorAccessor
type;
};
-// Mask
-template< typename T > struct InputMaskFunctor
+
+// Masking functors for binary input
+//--------------------------------------------------------
+
+template< typename T, typename M > struct GenericInputMaskFunctor
+{
+ /** Mask v with state of m
+
+ @return v, if m != 0, and vigra::NumericTraits<T>::zero
+ otherwise.
+ */
+ T operator()( T v, M m ) const
+ {
+ return m == 0 ? vigra::NumericTraits<T>::zero : v;
+ }
+};
+
+template< typename T, typename M > struct IntegerInputMaskFunctor
{
/** Mask v with state of m
@return v, if m != 0, and vigra::NumericTraits<T>::zero
otherwise.
*/
- template< typename M> T operator()( T v, M m ) const
+ T operator()( T v, M m ) const
{
// TODO(Q3): use traits to get unsigned type for T (if
// not already)
- // TODO(F3): use specialization for float types (which need
- // branching, instead of the bit fiddling used here)
-
// mask will be 0, iff m == 0, and 1 otherwise
const T mask( static_cast<unsigned int>(m | -m) >> (sizeof(unsigned int)*8 - 1) );
return v*mask;
}
};
-// Faster mask (assuming mask accessor output is already either 0 or 1)
-template< typename T > struct FastInputMaskFunctor
+
+template< typename T, typename M > struct FastIntegerInputMaskFunctor
{
- template<typename M> T operator()( T v, M m ) const
+ T operator()( T v, M m ) const
{
return v*m;
}
};
-template< typename T > struct OutputMaskFunctor
+
+// Masking functors for TernarySetterFunctionAccessorAdapter
+//-----------------------------------------------------------
+
+template< typename T, typename M > struct GenericOutputMaskFunctor
+{
+ /// Ternary mask operation - selects v1 for m == 0, v2 otherwise
+ T operator()( T v1, M m, T v2 ) const
+ {
+ return m == 0 ? v1 : v2;
+ }
+};
+
+template< typename T, typename M > struct IntegerOutputMaskFunctor
{
/** Mask v with state of m
@return v2, if m != 0, v1 otherwise.
*/
- template< typename M > T operator()( T v1, M m, T v2 ) const
+ T operator()( T v1, M m, T v2 ) const
{
- // TODO(Q3): use traits to get unsigned type for T (if
- // not unsigned already)
-
- // TODO(F3): use specialization for float types (which need
- // branching, instead of the bit fiddling used here)
-
// mask will be 0, iff m == 0, and 1 otherwise
const T mask( static_cast<unsigned int>(m | -m) >> (sizeof(unsigned int)*8 - 1) );
return v1*(M)(1-mask) + v2*mask;
}
};
-// Faster mask (assuming mask accessor output is already either 0 or 1)
-template< typename T > struct FastOutputMaskFunctor
+
+template< typename T, typename M > struct FastIntegerOutputMaskFunctor
{
- template< typename M> T operator()( T v1, M m, T v2 ) const
+ T operator()( T v1, M m, T v2 ) const
{
return v1*(M)(1-m) + v2*m;
}
};
+struct FastMask;
+struct NoFastMask;
+
+/// Metafunction to select output mask functor from iterator and mask value type
+template< typename T, typename M, typename DUMMY > struct outputMaskFunctorSelector : public
+ ifBothScalarIntegral< T, M,
+ IntegerOutputMaskFunctor< T, M >,
+ GenericOutputMaskFunctor< T, M > >
+{
+};
+template< typename T, typename M > struct outputMaskFunctorSelector< T, M, FastMask > : public
+ ifBothScalarIntegral< T, M,
+ FastIntegerOutputMaskFunctor< T, M >,
+ GenericOutputMaskFunctor< T, M > >
+{
+};
+
// Chosen function crucially depends on iterator - we can choose the
// faster direkt masking for 1bpp packed pixel iterators
template< class WrappedAccessor,
@@ -365,12 +455,15 @@ template< class WrappedAccessor,
class Iterator,
class MaskIterator > struct maskedAccessor
{
- typedef TernarySetterFunctionAccessorAdapter< WrappedAccessor,
- MaskAccessor,
- Iterator,
- MaskIterator,
- OutputMaskFunctor<
- typename WrappedAccessor::value_type > >
+ typedef TernarySetterFunctionAccessorAdapter<
+ WrappedAccessor,
+ MaskAccessor,
+ Iterator,
+ MaskIterator,
+ typename outputMaskFunctorSelector<
+ typename WrappedAccessor::value_type,
+ typename MaskAccessor::value_type,
+ NoFastMask>::type >
type;
};
// partial specialization, to use fast 1bpp mask function for
@@ -384,13 +477,18 @@ template< class WrappedAccessor,
1,
true > >
{
- typedef TernarySetterFunctionAccessorAdapter< WrappedAccessor,
- MaskAccessor,
- Iterator,
- PackedPixelIterator< typename MaskAccessor::value_type,
- 1,
- true >,
- FastOutputMaskFunctor< typename WrappedAccessor::value_type > >
+ typedef TernarySetterFunctionAccessorAdapter<
+ WrappedAccessor,
+ MaskAccessor,
+ Iterator,
+ PackedPixelIterator<
+ typename MaskAccessor::value_type,
+ 1,
+ true >,
+ typename outputMaskFunctorSelector<
+ typename WrappedAccessor::value_type,
+ typename MaskAccessor::value_type,
+ FastMask>::type >
type;
};
@@ -403,14 +501,19 @@ template< class WrappedAccessor,
1,
false > >
{
- typedef TernarySetterFunctionAccessorAdapter< WrappedAccessor,
- MaskAccessor,
- Iterator,
- PackedPixelIterator< typename MaskAccessor::value_type,
- 1,
- false >,
- FastOutputMaskFunctor< typename WrappedAccessor::value_type > >
- type;
+ typedef TernarySetterFunctionAccessorAdapter<
+ WrappedAccessor,
+ MaskAccessor,
+ Iterator,
+ PackedPixelIterator<
+ typename MaskAccessor::value_type,
+ 1,
+ false >,
+ typename outputMaskFunctorSelector<
+ typename WrappedAccessor::value_type,
+ typename MaskAccessor::value_type,
+ FastMask>::type >
+ type;
};
} // namespace basebmp
diff --git a/basebmp/inc/basebmp/color.hxx b/basebmp/inc/basebmp/color.hxx
index f32d1df169e6..afd3184224fa 100644
--- a/basebmp/inc/basebmp/color.hxx
+++ b/basebmp/inc/basebmp/color.hxx
@@ -4,9 +4,9 @@
*
* $RCSfile: color.hxx,v $
*
- * $Revision: 1.6 $
+ * $Revision: 1.7 $
*
- * last change: $Author: thb $ $Date: 2006-06-07 14:27:35 $
+ * last change: $Author: thb $ $Date: 2006-06-09 04:21:01 $
*
* The Contents of this file are made available subject to
* the terms of GNU Lesser General Public License Version 2.1.
@@ -39,6 +39,7 @@
#ifndef _SAL_TYPES_H_
#include <sal/types.h>
#endif
+#include <basebmp/accessoradapters.hxx>
#include <vigra/mathutil.hxx>
#include <math.h>
@@ -73,6 +74,7 @@ public:
sal_uInt32 toInt32() const { return mnColor; }
+ Color operator&( sal_uInt32 nMask ) const { return Color(mnColor & nMask); }
Color operator^( Color col ) const { return Color(col.getRed()^getRed(),
col.getGreen()^getGreen(),
col.getBlue()^getBlue()); }
@@ -100,6 +102,69 @@ public:
+ getBlue()*getBlue()); }
};
+struct ColorBitmaskOutputMaskFunctor
+{
+ Color operator()( Color v1, sal_uInt8 m, Color v2 ) const
+ {
+ return Color(v1.toInt32()*(sal_uInt8)(1-m) + v2.toInt32()*m);
+ }
+};
+
+/// Specialized output mask functor for Color value type
+template<> struct outputMaskFunctorSelector< Color, sal_uInt8, FastMask >
+{
+ typedef ColorBitmaskOutputMaskFunctor type;
+};
+
+struct ColorBlendFunctor
+{
+ Color operator()( sal_uInt8 alpha,
+ Color v1,
+ Color v2 ) const
+ {
+ const sal_uInt8 invAlpha(0xFF-alpha);
+ return Color(((sal_uInt32)invAlpha*v1.getRed() + alpha*v2.getRed())/0xFF,
+ ((sal_uInt32)invAlpha*v1.getGreen() + alpha*v2.getGreen())/0xFF,
+ ((sal_uInt32)invAlpha*v1.getBlue() + alpha*v2.getBlue())/0xFF);
+ }
+};
+
+/// Specialized metafunction to select blend functor for Color value types
+template<> struct blendFunctorSelector<Color, sal_uInt8>
+{
+ typedef ColorBlendFunctor type;
+};
+
} // namespace basebmp
+namespace vigra
+{
+
+template<>
+struct NumericTraits<basebmp::Color>
+{
+ typedef basebmp::Color Type;
+ typedef basebmp::Color Promote;
+ typedef basebmp::Color RealPromote;
+ typedef std::complex<basebmp::Color> ComplexPromote;
+ typedef sal_uInt8 ValueType;
+
+ typedef VigraTrueType isIntegral;
+ typedef VigraFalseType isScalar;
+ typedef VigraTrueType isSigned;
+ typedef VigraTrueType isOrdered;
+ typedef VigraFalseType isComplex;
+
+ static Type zero() { return Type(); }
+ static Type one() { return Type(0x01010101); }
+ static Type nonZero() { return Type(0x01010101); }
+
+ static Promote toPromote(const Type& v) { return v; }
+ static RealPromote toRealPromote(const Type& v) { return v; }
+ static Type fromPromote(const Promote& v) { return v; }
+ static Type fromRealPromote(const RealPromote& v) { return v; }
+};
+
+} // namespace vigra
+
#endif /* INCLUDED_BASEBMP_COLOR_HXX */
diff --git a/basebmp/inc/basebmp/metafunctions.hxx b/basebmp/inc/basebmp/metafunctions.hxx
index 06ac9da70a3b..7a3ff8fd62a2 100644
--- a/basebmp/inc/basebmp/metafunctions.hxx
+++ b/basebmp/inc/basebmp/metafunctions.hxx
@@ -4,9 +4,9 @@
*
* $RCSfile: metafunctions.hxx,v $
*
- * $Revision: 1.2 $
+ * $Revision: 1.3 $
*
- * last change: $Author: thb $ $Date: 2006-05-31 10:12:12 $
+ * last change: $Author: thb $ $Date: 2006-06-09 04:21:01 $
*
* The Contents of this file are made available subject to
* the terms of GNU Lesser General Public License Version 2.1.
@@ -36,6 +36,9 @@
#ifndef INCLUDED_BASEBMP_METAFUNCTIONS_HXX
#define INCLUDED_BASEBMP_METAFUNCTIONS_HXX
+#include <vigra/metaprogramming.hxx>
+#include <vigra/numerictraits.hxx>
+
namespace basebmp
{
@@ -74,6 +77,48 @@ inline bool is_negative( int x )
return static_cast<unsigned int>(x) >> (sizeof(int)*8-1);
}
+/// Results in VigraTrueType, if T is of integer type and scalar
+template< typename T, typename trueCase, typename falseCase >
+struct ifScalarIntegral
+{
+ typedef
+ typename vigra::If<
+ typename vigra::NumericTraits< T >::isIntegral,
+ typename vigra::If<
+ typename vigra::NumericTraits< T >::isScalar,
+ trueCase,
+ falseCase >::type,
+ falseCase >::type type;
+};
+
+/// Results in VigraTrueType, if T is of non-integer type and scalar
+template< typename T, typename trueCase, typename falseCase >
+struct ifScalarNonIntegral
+{
+ typedef
+ typename vigra::If<
+ typename vigra::NumericTraits< T >::isIntegral,
+ falseCase,
+ typename vigra::If<
+ typename vigra::NumericTraits< T >::isScalar,
+ trueCase,
+ falseCase >::type >::type type;
+};
+
+/// Results in VigraTrueType, if both T1 and T2 are of integer type and scalar
+template< typename T1, typename T2, typename trueCase, typename falseCase >
+struct ifBothScalarIntegral
+{
+ typedef
+ typename ifScalarIntegral<
+ T1,
+ typename ifScalarIntegral<
+ T2,
+ trueCase,
+ falseCase >::type,
+ falseCase >::type type;
+};
+
} // namespace basebmp
#endif /* INCLUDED_BASEBMP_METAFUNCTIONS_HXX */
diff --git a/basebmp/source/bitmapdevice.cxx b/basebmp/source/bitmapdevice.cxx
index 7818b9c47a88..e49405d1bfc3 100644
--- a/basebmp/source/bitmapdevice.cxx
+++ b/basebmp/source/bitmapdevice.cxx
@@ -4,9 +4,9 @@
*
* $RCSfile: bitmapdevice.cxx,v $
*
- * $Revision: 1.11 $
+ * $Revision: 1.12 $
*
- * last change: $Author: thb $ $Date: 2006-06-08 16:39:02 $
+ * last change: $Author: thb $ $Date: 2006-06-09 04:21:01 $
*
* The Contents of this file are made available subject to
* the terms of GNU Lesser General Public License Version 2.1.
@@ -243,6 +243,13 @@ namespace
MaskAccessor,
DestIterator,
MaskIterator>::type MaskedXorAccessor;
+ typedef ConstantColorBlendAccessorAdapter<
+ DestAccessor,
+ typename AlphaMaskAccessor::value_type> ColorBlendAccessor;
+ typedef typename maskedAccessor<ColorBlendAccessor,
+ MaskAccessor,
+ DestIterator,
+ MaskIterator>::type MaskedColorBlendAcc;
typedef typename maskedAccessor<RawXorAccessor,
MaskAccessor,
DestIterator,
@@ -263,6 +270,7 @@ namespace
XorAccessor maXorAccessor;
RawXorAccessor maRawXorAccessor;
MaskedAccessor maMaskedAccessor;
+ MaskedColorBlendAcc maMaskedColorBlendAccessor;
MaskedXorAccessor maMaskedXorAccessor;
RawMaskedAccessor maRawMaskedAccessor;
RawMaskedXorAccessor maRawMaskedXorAccessor;
@@ -289,6 +297,8 @@ namespace
maXorAccessor( accessor ),
maRawXorAccessor( maRawAccessor ),
maMaskedAccessor( accessor ),
+ maMaskedColorBlendAccessor(
+ ColorBlendAccessor(accessor) ),
maMaskedXorAccessor( maXorAccessor ),
maRawMaskedAccessor( maRawAccessor ),
maRawMaskedXorAccessor( maRawXorAccessor ),
@@ -675,39 +685,26 @@ namespace
maRawMaskedAccessor);
}
- template< typename Range, typename Accessor >
- void implDrawMaskedColor(Color rSrcColor,
- const BitmapDeviceSharedPtr& rAlphaMask,
- const basegfx::B2IRange& rSrcRect,
- const basegfx::B2IPoint& rDstPoint,
- const Range& range,
- const Accessor& acc)
+ virtual void drawMaskedColor_i(Color aSrcColor,
+ const BitmapDeviceSharedPtr& rAlphaMask,
+ const basegfx::B2IRange& rSrcRect,
+ const basegfx::B2IPoint& rDstPoint )
{
boost::shared_ptr<AlphaMaskBitmap> pAlpha( getCompatibleAlphaMask(rAlphaMask) );
OSL_ASSERT( pAlpha );
vigra::copyImage( pAlpha->maBegin + vigra::Diff2D(rSrcRect.getMinX(),
- rSrcRect.getMinY()),
+ rSrcRect.getMinY()),
pAlpha->maBegin + vigra::Diff2D(rSrcRect.getMaxX(),
- rSrcRect.getMaxY()),
+ rSrcRect.getMaxY()),
pAlpha->maAccessor,
- range.first + vigra::Diff2D(rDstPoint.getX(),
- rDstPoint.getY()),
+ maBegin + vigra::Diff2D(rDstPoint.getX(),
+ rDstPoint.getY()),
ConstantColorBlendAccessorAdapter<
- Accessor,
- typename DestAccessor::value_type>(
- acc,
- maFromColorConverter(rSrcColor)) );
- }
-
- virtual void drawMaskedColor_i(Color aSrcColor,
- const BitmapDeviceSharedPtr& rAlphaMask,
- const basegfx::B2IRange& rSrcRect,
- const basegfx::B2IPoint& rDstPoint )
- {
- implDrawMaskedColor(aSrcColor, rAlphaMask, rSrcRect, rDstPoint,
- std::make_pair(maBegin,maEnd),
- maAccessor);
+ DestAccessor,
+ typename AlphaMaskAccessor::value_type>(
+ maAccessor,
+ maFromColorConverter(aSrcColor)) );
}
virtual void drawMaskedColor_i(Color aSrcColor,
@@ -716,9 +713,28 @@ namespace
const basegfx::B2IPoint& rDstPoint,
const BitmapDeviceSharedPtr& rClip )
{
- implDrawMaskedColor(aSrcColor, rAlphaMask, rSrcRect, rDstPoint,
- getMaskedRange(rClip),
- maMaskedAccessor);
+#if 0
+ boost::shared_ptr<AlphaMaskBitmap> pAlpha( getCompatibleAlphaMask(rAlphaMask) );
+ OSL_ASSERT( pAlpha );
+
+ const vigra::pair<composite_iterator_type,
+ composite_iterator_type> aRange( getMaskedRange(rClip) );
+ maMaskedColorBlendAccessor.setColor( maFromColorConverter(aSrcColor) );
+
+ vigra::copyImage( pAlpha->maBegin + vigra::Diff2D(rSrcRect.getMinX(),
+ rSrcRect.getMinY()),
+ pAlpha->maBegin + vigra::Diff2D(rSrcRect.getMaxX(),
+ rSrcRect.getMaxY()),
+ pAlpha->maAccessor,
+ aRange.first + vigra::Diff2D(rDstPoint.getX(),
+ rDstPoint.getY()),
+ maMaskedColorBlendAccessor );
+#else
+ drawMaskedColor_i(aSrcColor,
+ rAlphaMask,
+ rSrcRect,
+ rDstPoint );
+#endif
}
// must work with *this == rSrcBitmap!
diff --git a/basebmp/test/bmpdemo.cxx b/basebmp/test/bmpdemo.cxx
index dd008ffecb32..3e43ce8ce2d1 100644
--- a/basebmp/test/bmpdemo.cxx
+++ b/basebmp/test/bmpdemo.cxx
@@ -4,9 +4,9 @@
*
* $RCSfile: bmpdemo.cxx,v $
*
- * $Revision: 1.6 $
+ * $Revision: 1.7 $
*
- * last change: $Author: thb $ $Date: 2006-06-08 00:01:48 $
+ * last change: $Author: thb $ $Date: 2006-06-09 04:21:01 $
*
* The Contents of this file are made available subject to
* the terms of GNU Lesser General Public License Version 2.1.
@@ -56,6 +56,7 @@
#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>
@@ -995,9 +996,143 @@ class TestWindow : public Dialog
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)x2, (sal_Int32)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(500,500);
+ basebmp::BitmapDeviceSharedPtr pDevice2( basebmp::createBitmapDevice( aTestSize,
+ true,
+ basebmp::Format::THIRTYTWO_BIT_TC_MASK ));
+ pDevice2->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;
+
+ 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) );
+ pDevice2->drawPolygon(
+ aPoly,
+ basebmp::Color(0xFFFFFFFF),
+ basebmp::DrawMode_PAINT);
+ pDevice2->fillPolyPolygon(
+ basegfx::tools::createAreaGeometryForPolygon(
+ aPoly,
+ n/3,
+ basegfx::tools::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;
+ }
+
+ std::ofstream output4("svptest.dump");
+ debugDump( pDevice2, output4 );
+
const basegfx::B2ISize aSize(10,10);
basebmp::BitmapDeviceSharedPtr pDevice( basebmp::createBitmapDevice( aSize,
true,
diff --git a/basebmp/test/masktest.cxx b/basebmp/test/masktest.cxx
index 95fdfd16cebe..1cd85c038cb4 100644
--- a/basebmp/test/masktest.cxx
+++ b/basebmp/test/masktest.cxx
@@ -4,9 +4,9 @@
*
* $RCSfile: masktest.cxx,v $
*
- * $Revision: 1.1 $
+ * $Revision: 1.2 $
*
- * last change: $Author: thb $ $Date: 2006-06-02 13:57:25 $
+ * last change: $Author: thb $ $Date: 2006-06-09 04:21:01 $
*
* The Contents of this file are made available subject to
* the terms of GNU Lesser General Public License Version 2.1.
@@ -85,6 +85,10 @@ private:
const basegfx::B2IPoint aDestRightBottom(5,5);
rDevice->clear(aCol);
+ rDevice->setPixel(
+ basegfx::B2IPoint(1,1),
+ aCol2,
+ DrawMode_PAINT);
rDevice->drawMaskedColor(
aCol2,
rBmp,
@@ -151,7 +155,7 @@ public:
void testMaskBasics()
{
implTestMaskBasics( mpDevice32bpp, mpMask );
- implTestMaskBasics( mpDevice1bpp, mpMask );
+ //implTestMaskBasics( mpDevice1bpp, mpMask );
}
void testMaskClip()