diff options
author | Thorsten Behrens <thb@openoffice.org> | 2006-07-13 11:03:26 +0000 |
---|---|---|
committer | Thorsten Behrens <thb@openoffice.org> | 2006-07-13 11:03:26 +0000 |
commit | 0177db3f91a28995ca151b63d054cd539cd27212 (patch) | |
tree | 9df894e22693545534b5941067f821610eb40de2 | |
parent | 3583a216e8101fe4d0f17f913c2efcab58f9b518 (diff) |
#i65904# Swapped mask polarity - now, a zero in the mask denotes opacity; minor code tidying; made drawMaskedBitmap() handle a few more generic cases; switched 24bpp to BGR; adapted tests to modified mask polarity
-rw-r--r-- | basebmp/inc/basebmp/accessorfunctors.hxx | 66 | ||||
-rw-r--r-- | basebmp/inc/basebmp/accessortraits.hxx | 29 | ||||
-rw-r--r-- | basebmp/inc/basebmp/bitmapdevice.hxx | 24 | ||||
-rw-r--r-- | basebmp/inc/basebmp/colorblendaccessoradapter.hxx | 17 | ||||
-rw-r--r-- | basebmp/inc/basebmp/colormisc.hxx | 31 | ||||
-rw-r--r-- | basebmp/inc/basebmp/colortraits.hxx | 76 | ||||
-rw-r--r-- | basebmp/inc/basebmp/metafunctions.hxx | 15 | ||||
-rw-r--r-- | basebmp/inc/basebmp/packedpixeliterator.hxx | 9 | ||||
-rw-r--r-- | basebmp/source/bitmapdevice.cxx | 48 | ||||
-rw-r--r-- | basebmp/test/basictest.cxx | 11 | ||||
-rw-r--r-- | basebmp/test/bmpmasktest.cxx | 14 | ||||
-rw-r--r-- | basebmp/test/cliptest.cxx | 8 |
12 files changed, 245 insertions, 103 deletions
diff --git a/basebmp/inc/basebmp/accessorfunctors.hxx b/basebmp/inc/basebmp/accessorfunctors.hxx index 1d4645fba865..89a30772459c 100644 --- a/basebmp/inc/basebmp/accessorfunctors.hxx +++ b/basebmp/inc/basebmp/accessorfunctors.hxx @@ -4,9 +4,9 @@ * * $RCSfile: accessorfunctors.hxx,v $ * - * $Revision: 1.1 $ + * $Revision: 1.2 $ * - * last change: $Author: thb $ $Date: 2006-07-12 15:09:44 $ + * last change: $Author: thb $ $Date: 2006-07-13 12:03:25 $ * * The Contents of this file are made available subject to * the terms of GNU Lesser General Public License Version 2.1. @@ -56,34 +56,37 @@ template< typename T > struct XorFunctor : public std::binary_function<T,T,T> //----------------------------------------------------------------------------- -/// Base class for an adaptable ternary functor -template< typename A1, typename A2, typename A3, typename R > struct TernaryFunctorBase -{ - typedef A1 first_argument_type; - typedef A2 second_argument_type; - typedef A3 third_argument_type; - typedef R result_type; -}; - /// Base class, passing on the arg types template< typename T, typename M > struct MaskFunctorBase : public TernaryFunctorBase<T,M,T,T> {}; -/// Let a mask flag decide between two values -template< typename T, typename M > struct GenericOutputMaskFunctor : MaskFunctorBase<T,M> +/** Let a mask flag decide between two values + + @tpl polarity + Mask polarity. When true, a false in the mask denotes + transparency, i.e. the original value will display. And vice + versa. + */ +template< typename T, + typename M, + bool polarity > struct GenericOutputMaskFunctor : public MaskFunctorBase<T,M> { - /// Ternary mask operation - selects v1 for !m == true, v2 otherwise + /// Ternary mask operation - selects v1 for !m == polarity, v2 otherwise T operator()( T v1, M m, T v2 ) const { - return !m ? v1 : v2; + return !m == polarity ? v1 : v2; } }; /** Let a mask bit decide between two values (specialization for integer mask types) */ -template< typename T, typename M > struct IntegerOutputMaskFunctor : MaskFunctorBase<T,M> +template< typename T, + typename M, + bool polarity > struct IntegerOutputMaskFunctor; +template< typename T, + typename M > struct IntegerOutputMaskFunctor<T,M,true> : public MaskFunctorBase<T,M> { /** Mask v with state of m @@ -98,11 +101,29 @@ template< typename T, typename M > struct IntegerOutputMaskFunctor : MaskFunctor return v1*(M)(1-mask) + v2*mask; } }; +template< typename T, + typename M > struct IntegerOutputMaskFunctor<T,M,false> : public MaskFunctorBase<T,M> +{ + /** Mask v with state of m + + @return v2, if m != 0, v1 otherwise. + */ + T operator()( T v1, M m, T v2 ) const + { + typedef typename make_unsigned<T>::type unsigned_T; + + // mask will be 0, iff m == 0, and 1 otherwise + const T mask( unsigned_cast<T>(m | -m) >> (sizeof(unsigned_T)*8 - 1) ); + return v1*mask + v2*(M)(1-mask); + } +}; /** Let a mask bit decide between two values (specialization for binary-valued mask types) */ -template< typename T, typename M > struct FastIntegerOutputMaskFunctor : MaskFunctorBase<T,M> +template< typename T, typename M, bool polarity > struct FastIntegerOutputMaskFunctor; +template< typename T, typename M > struct FastIntegerOutputMaskFunctor<T,M,true> : + public MaskFunctorBase<T,M> { /// Specialization, only valid if mask can only attain 0 or 1 T operator()( T v1, M m, T v2 ) const @@ -112,6 +133,17 @@ template< typename T, typename M > struct FastIntegerOutputMaskFunctor : MaskFun return v1*(M)(1-m) + v2*m; } }; +template< typename T, typename M > struct FastIntegerOutputMaskFunctor<T,M,false> : + public MaskFunctorBase<T,M> +{ + /// Specialization, only valid if mask can only attain 0 or 1 + T operator()( T v1, M m, T v2 ) const + { + OSL_ASSERT(m<=1); + + return v1*m + v2*(M)(1-m); + } +}; //----------------------------------------------------------------------------- diff --git a/basebmp/inc/basebmp/accessortraits.hxx b/basebmp/inc/basebmp/accessortraits.hxx index bb30cc310148..918824cb0e81 100644 --- a/basebmp/inc/basebmp/accessortraits.hxx +++ b/basebmp/inc/basebmp/accessortraits.hxx @@ -4,9 +4,9 @@ * * $RCSfile: accessortraits.hxx,v $ * - * $Revision: 1.3 $ + * $Revision: 1.4 $ * - * last change: $Author: thb $ $Date: 2006-07-12 15:09:44 $ + * last change: $Author: thb $ $Date: 2006-07-13 12:03:25 $ * * The Contents of this file are made available subject to * the terms of GNU Lesser General Public License Version 2.1. @@ -49,16 +49,16 @@ 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 +template< typename T, typename M, bool polarity, typename DUMMY > struct outputMaskFunctorSelector : public ifBothScalarIntegral< T, M, - IntegerOutputMaskFunctor< T, M >, - GenericOutputMaskFunctor< T, M > > + IntegerOutputMaskFunctor< T, M, polarity >, + GenericOutputMaskFunctor< T, M, polarity > > { }; -template< typename T, typename M > struct outputMaskFunctorSelector< T, M, FastMask > : public +template< typename T, typename M, bool polarity > struct outputMaskFunctorSelector< T, M, polarity, FastMask > : public ifBothScalarIntegral< T, M, - FastIntegerOutputMaskFunctor< T, M >, - GenericOutputMaskFunctor< T, M > > + FastIntegerOutputMaskFunctor< T, M, polarity >, + GenericOutputMaskFunctor< T, M, polarity > > { }; @@ -71,7 +71,8 @@ template< typename T, typename M > struct outputMaskFunctorSelector< T, M, FastM template< class Accessor, class MaskAccessor, class Iterator, - class MaskIterator > struct maskedAccessorSelector + class MaskIterator, + bool polarity > struct maskedAccessorSelector { typedef TernarySetterFunctionAccessorAdapter< Accessor, @@ -79,6 +80,7 @@ template< class Accessor, typename outputMaskFunctorSelector< typename Accessor::value_type, typename MaskAccessor::value_type, + polarity, NoFastMask > ::type > type; }; @@ -120,8 +122,13 @@ template< class Accessor > struct AccessorTraits */ template< class MaskAccessor, class Iterator, - class MaskIterator > struct masked_accessor : - public maskedAccessorSelector< Accessor,MaskAccessor,Iterator,MaskIterator > + class MaskIterator, + bool polarity > struct masked_accessor : + public maskedAccessorSelector< Accessor, + MaskAccessor, + Iterator, + MaskIterator, + polarity > {}; }; diff --git a/basebmp/inc/basebmp/bitmapdevice.hxx b/basebmp/inc/basebmp/bitmapdevice.hxx index 37bb0e04dfd4..c11a62e5efda 100644 --- a/basebmp/inc/basebmp/bitmapdevice.hxx +++ b/basebmp/inc/basebmp/bitmapdevice.hxx @@ -2,9 +2,9 @@ * * $RCSfile: bitmapdevice.hxx,v $ * - * $Revision: 1.6 $ + * $Revision: 1.7 $ * - * last change: $Author: thb $ $Date: 2006-07-11 11:38:54 $ + * last change: $Author: thb $ $Date: 2006-07-13 12:03:25 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -172,7 +172,7 @@ public: Draw mode to use when changing the pixel value @param rClip - Clip mask to use. If the clip mask is 0 at the given pixel + Clip mask to use. If the clip mask is 1 at the given pixel position, no change will take place. */ void setPixel( const basegfx::B2IPoint& rPt, @@ -233,7 +233,7 @@ public: @param rClip Clip mask to use. Pixel where the corresponding clip mask - pixel is 0 will not be modified. + pixel is 1 will not be modified. */ void drawLine( const basegfx::B2IPoint& rPt1, const basegfx::B2IPoint& rPt2, @@ -273,7 +273,7 @@ public: @param rClip Clip mask to use. Pixel where the corresponding clip mask - pixel is 0 will not be modified. + pixel is 1 will not be modified. */ void drawPolygon( const basegfx::B2DPolygon& rPoly, Color lineColor, @@ -322,7 +322,7 @@ public: @param rClip Clip mask to use. Pixel where the corresponding clip mask - pixel is 0 will not be modified. + pixel is 1 will not be modified. */ void fillPolyPolygon( const basegfx::B2DPolyPolygon& rPoly, Color fillColor, @@ -384,7 +384,7 @@ public: @param rClip Clip mask to use. Pixel where the corresponding clip mask - pixel is 0 will not be modified. + pixel is 1 will not be modified. */ void drawBitmap( const BitmapDeviceSharedPtr& rSrcBitmap, const basegfx::B2IRange& rSrcRect, @@ -453,7 +453,7 @@ public: @param rClip Clip mask to use. Pixel where the corresponding clip mask - pixel is 0 will not be modified. + pixel is 1 will not be modified. */ void drawMaskedColor( Color aSrcColor, const BitmapDeviceSharedPtr& rAlphaMask, @@ -474,7 +474,7 @@ public: and destination bitmap are the same. @param rMask - Bitmap to use as a mask. Pixel with value zero in this mask + Bitmap to use as a mask. Pixel with value != zero in this mask will result in destination pixel not being affected by the blit operation. @@ -507,7 +507,7 @@ public: This method renders a source bitmap into this device, much like the drawBitmap() method. The only difference is the additional mask parameter, which operates much like an - additional clip mask: pixel with value zero in this mask + additional clip mask: pixel with value != zero in this mask result in destination pixel not being modified. @param rSrcBitmap @@ -515,7 +515,7 @@ public: and destination bitmap are the same. @param rMask - Bitmap to use as a mask. Pixel with value zero in this mask + Bitmap to use as a mask. Pixel with value != zero in this mask will result in destination pixel not being affected by the blit operation. @@ -539,7 +539,7 @@ public: @param rClip Clip mask to use. Pixel where the corresponding clip mask - pixel is 0 will not be modified. + pixel is 1 will not be modified. */ void drawMaskedBitmap( const BitmapDeviceSharedPtr& rSrcBitmap, const BitmapDeviceSharedPtr& rMask, diff --git a/basebmp/inc/basebmp/colorblendaccessoradapter.hxx b/basebmp/inc/basebmp/colorblendaccessoradapter.hxx index d86f9efc2876..e318e8579585 100644 --- a/basebmp/inc/basebmp/colorblendaccessoradapter.hxx +++ b/basebmp/inc/basebmp/colorblendaccessoradapter.hxx @@ -4,9 +4,9 @@ * * $RCSfile: colorblendaccessoradapter.hxx,v $ * - * $Revision: 1.2 $ + * $Revision: 1.3 $ * - * last change: $Author: thb $ $Date: 2006-07-12 15:09:44 $ + * last change: $Author: thb $ $Date: 2006-07-13 12:03:25 $ * * The Contents of this file are made available subject to * the terms of GNU Lesser General Public License Version 2.1. @@ -51,8 +51,9 @@ namespace basebmp when blitting through a mask) - there really isn't no other sensible default behaviour for these methods. */ -template< class WrappedAccessor, - typename AlphaType > class ConstantColorBlendSetterAccessorAdapter +template< class WrappedAccessor, + typename AlphaType, + bool polarity > class ConstantColorBlendSetterAccessorAdapter { public: typedef AlphaType alpha_type; @@ -61,10 +62,10 @@ public: private: typename ColorTraits< color_type >:: - template blend_functor<alpha_type>::type maFunctor; - WrappedAccessor maWrappee; - color_type maBlendColor; - value_type maGetterValue; + template blend_functor<alpha_type,polarity>::type maFunctor; + WrappedAccessor maWrappee; + color_type maBlendColor; + value_type maGetterValue; public: ConstantColorBlendSetterAccessorAdapter() : diff --git a/basebmp/inc/basebmp/colormisc.hxx b/basebmp/inc/basebmp/colormisc.hxx index 8cdf665c6145..c4f1ec0126a4 100644 --- a/basebmp/inc/basebmp/colormisc.hxx +++ b/basebmp/inc/basebmp/colormisc.hxx @@ -4,9 +4,9 @@ * * $RCSfile: colormisc.hxx,v $ * - * $Revision: 1.3 $ + * $Revision: 1.4 $ * - * last change: $Author: thb $ $Date: 2006-07-11 11:38:55 $ + * last change: $Author: thb $ $Date: 2006-07-13 12:03:25 $ * * The Contents of this file are made available subject to * the terms of GNU Lesser General Public License Version 2.1. @@ -50,7 +50,8 @@ namespace basebmp { -struct ColorBitmaskOutputMaskFunctor : MaskFunctorBase<Color,sal_uInt8> +template< bool polarity > struct ColorBitmaskOutputMaskFunctor; +template<> struct ColorBitmaskOutputMaskFunctor<true> : MaskFunctorBase<Color,sal_uInt8> { Color operator()( Color v1, sal_uInt8 m, Color v2 ) const { @@ -59,19 +60,31 @@ struct ColorBitmaskOutputMaskFunctor : MaskFunctorBase<Color,sal_uInt8> return Color(v1.toInt32()*(sal_uInt8)(1-m) + v2.toInt32()*m); } }; +template<> struct ColorBitmaskOutputMaskFunctor<false> : MaskFunctorBase<Color,sal_uInt8> +{ + Color operator()( Color v1, sal_uInt8 m, Color v2 ) const + { + OSL_ASSERT(m<=1); + + return Color(v1.toInt32()*m + v2.toInt32()*(sal_uInt8)(1-m)); + } +}; /// Specialized output mask functor for Color value type -template<> struct outputMaskFunctorSelector< Color, sal_uInt8, FastMask > +template<bool polarity> struct outputMaskFunctorSelector< Color, sal_uInt8, polarity, FastMask > { - typedef ColorBitmaskOutputMaskFunctor type; + typedef ColorBitmaskOutputMaskFunctor<polarity> type; }; -struct ColorBlendFunctor : public BlendFunctorBase<Color,sal_uInt8> +template< bool polarity > struct ColorBlendFunctor + : public TernaryFunctorBase<sal_uInt8,Color,Color,Color> { Color operator()( sal_uInt8 alpha, Color v1, Color v2 ) const { + alpha = polarity ? alpha : 255 - alpha; + const sal_uInt8 v1_red( v1.getRed() ); const sal_uInt8 v1_green( v1.getGreen() ); const sal_uInt8 v1_blue( v1.getBlue() ); @@ -96,7 +109,7 @@ template<> struct ColorTraits< Color > typedef sal_uInt8 component_type; /// Metafunction to select blend functor from color and alpha type - template< typename AlphaType > struct blend_functor; + template< typename AlphaType, bool polarity > struct blend_functor; /// Calculate normalized distance between color c1 and c2 static inline double distance( const Color& c1, @@ -117,9 +130,9 @@ template<> struct ColorTraits< Color > }; /// Only defined for 8 bit alpha, currently -template<> template<> struct ColorTraits< Color >::blend_functor< sal_uInt8 > +template<> template<bool polarity> struct ColorTraits< Color >::blend_functor< sal_uInt8, polarity > { - typedef ColorBlendFunctor type; + typedef ColorBlendFunctor<polarity> type; }; } // namespace basebmp diff --git a/basebmp/inc/basebmp/colortraits.hxx b/basebmp/inc/basebmp/colortraits.hxx index 53e2902c004b..0da8425d3a61 100644 --- a/basebmp/inc/basebmp/colortraits.hxx +++ b/basebmp/inc/basebmp/colortraits.hxx @@ -4,9 +4,9 @@ * * $RCSfile: colortraits.hxx,v $ * - * $Revision: 1.2 $ + * $Revision: 1.3 $ * - * last change: $Author: thb $ $Date: 2006-07-11 11:38:55 $ + * last change: $Author: thb $ $Date: 2006-07-13 12:03:25 $ * * The Contents of this file are made available subject to * the terms of GNU Lesser General Public License Version 2.1. @@ -37,24 +37,39 @@ #define INCLUDED_BASEBMP_COLORTRAITS_HXX #include <basebmp/accessoradapters.hxx> -#include <basebmp/colortraits.hxx> +#include <basebmp/metafunctions.hxx> #include <vigra/mathutil.hxx> namespace basebmp { -template< typename ValueType, typename AlphaType > struct BlendFunctorBase +/** Functor template, to calculate alpha blending between two + values. Float case. + + @tpl polarity + When true, 0 means fully transparent, and 1 fully opaque. And vice + versa. + */ +template< typename ValueType, + typename AlphaType, + bool polarity > struct BlendFunctor; +template< typename ValueType, + typename AlphaType > struct BlendFunctor<ValueType,AlphaType,true> + : public TernaryFunctorBase<AlphaType,ValueType,ValueType,ValueType> { - typedef AlphaType first_argument_type; - typedef ValueType second_argument_type; - typedef ValueType third_argument_type; - typedef ValueType result_type; + 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; + } }; - -/// Functor template, to calculate alpha blending between two values. Float case. -template< typename ValueType, typename AlphaType > struct BlendFunctor : - public BlendFunctorBase<ValueType,AlphaType> +template< typename ValueType, + typename AlphaType > struct BlendFunctor<ValueType,AlphaType,false> + : public TernaryFunctorBase<AlphaType,ValueType,ValueType,ValueType> { ValueType operator()( AlphaType alpha, ValueType v1, @@ -62,12 +77,23 @@ template< typename ValueType, typename AlphaType > struct BlendFunctor : { const typename vigra::NumericTraits<AlphaType>::RealPromote fAlpha( vigra::NumericTraits<AlphaType>::toRealPromote(alpha)); - return (vigra::NumericTraits<AlphaType>::one()-fAlpha)*v1 + fAlpha*v2; + return fAlpha*v1 + (vigra::NumericTraits<AlphaType>::one()-fAlpha)*v2; } }; -/// Functor template, to calculate alpha blending between two values. Integer case. -template< typename ValueType, typename AlphaType > struct IntegerBlendFunctor +/** Functor template, to calculate alpha blending between two + values. Integer case. + + @tpl polarity + When true, 0 means fully transparent, and 1 fully opaque. And vice + versa. + */ +template< typename ValueType, + typename AlphaType, + bool polarity > struct IntegerBlendFunctor; +template< typename ValueType, + typename AlphaType > struct IntegerBlendFunctor<ValueType,AlphaType,true> + : public TernaryFunctorBase<AlphaType,ValueType,ValueType,ValueType> { ValueType operator()( AlphaType alpha, ValueType v1, @@ -78,16 +104,30 @@ template< typename ValueType, typename AlphaType > struct IntegerBlendFunctor vigra::NumericTraits<AlphaType>::max(); } }; +template< typename ValueType, + typename AlphaType > struct IntegerBlendFunctor<ValueType,AlphaType,false> + : public TernaryFunctorBase<AlphaType,ValueType,ValueType,ValueType> +{ + ValueType operator()( AlphaType alpha, + ValueType v1, + ValueType v2 ) const + { + return (alpha*v1 + + vigra::NumericTraits<AlphaType>::toPromote( + vigra::NumericTraits<AlphaType>::max()-alpha)*v2) / + vigra::NumericTraits<AlphaType>::max(); + } +}; //----------------------------------------------------------------------------- template< typename ColorType > struct ColorTraits { /// Metafunction to select blend functor from color and alpha type - template< typename AlphaType > struct blend_functor : public + template< typename AlphaType, bool polarity > struct blend_functor : public ifScalarIntegral< AlphaType, - IntegerBlendFunctor< ColorType, AlphaType >, - BlendFunctor< ColorType, AlphaType > > {}; + IntegerBlendFunctor< ColorType, AlphaType, polarity >, + BlendFunctor< ColorType, AlphaType, polarity > > {}; /// @return number of color channels static int numChannels() { return 1; } diff --git a/basebmp/inc/basebmp/metafunctions.hxx b/basebmp/inc/basebmp/metafunctions.hxx index 8004906174f1..8d64fc066543 100644 --- a/basebmp/inc/basebmp/metafunctions.hxx +++ b/basebmp/inc/basebmp/metafunctions.hxx @@ -4,9 +4,9 @@ * * $RCSfile: metafunctions.hxx,v $ * - * $Revision: 1.6 $ + * $Revision: 1.7 $ * - * last change: $Author: thb $ $Date: 2006-07-11 11:38:55 $ + * last change: $Author: thb $ $Date: 2006-07-13 12:03:25 $ * * The Contents of this file are made available subject to * the terms of GNU Lesser General Public License Version 2.1. @@ -81,6 +81,17 @@ template <typename T> struct remove_const<const T> //-------------------------------------------------------------- +/// Base class for an adaptable ternary functor +template< typename A1, typename A2, typename A3, typename R > struct TernaryFunctorBase +{ + typedef A1 first_argument_type; + typedef A2 second_argument_type; + typedef A3 third_argument_type; + typedef R result_type; +}; + +//-------------------------------------------------------------- + /** template meta function: ensure that given integer type is unsigned If given integer type is already unsigned, return as-is - diff --git a/basebmp/inc/basebmp/packedpixeliterator.hxx b/basebmp/inc/basebmp/packedpixeliterator.hxx index 91a048d97ac2..9ee27130fe5f 100644 --- a/basebmp/inc/basebmp/packedpixeliterator.hxx +++ b/basebmp/inc/basebmp/packedpixeliterator.hxx @@ -4,9 +4,9 @@ * * $RCSfile: packedpixeliterator.hxx,v $ * - * $Revision: 1.8 $ + * $Revision: 1.9 $ * - * last change: $Author: thb $ $Date: 2006-07-12 22:47:20 $ + * last change: $Author: thb $ $Date: 2006-07-13 12:03:25 $ * * The Contents of this file are made available subject to * the terms of GNU Lesser General Public License Version 2.1. @@ -660,12 +660,14 @@ public: template< class Accessor, class MaskAccessor, class Iterator, + bool polarity, bool MsbFirst > struct maskedAccessorSelector< Accessor, MaskAccessor, Iterator, PackedPixelIterator< typename MaskAccessor::value_type, 1, - MsbFirst > > + MsbFirst >, + polarity > { typedef TernarySetterFunctionAccessorAdapter< Accessor, @@ -673,6 +675,7 @@ template< class Accessor, typename outputMaskFunctorSelector< typename Accessor::value_type, typename MaskAccessor::value_type, + polarity, FastMask>::type > type; }; diff --git a/basebmp/source/bitmapdevice.cxx b/basebmp/source/bitmapdevice.cxx index 64975d9ca5de..aa6c72348907 100644 --- a/basebmp/source/bitmapdevice.cxx +++ b/basebmp/source/bitmapdevice.cxx @@ -4,9 +4,9 @@ * * $RCSfile: bitmapdevice.cxx,v $ * - * $Revision: 1.20 $ + * $Revision: 1.21 $ * - * last change: $Author: thb $ $Date: 2006-07-12 22:47:21 $ + * last change: $Author: thb $ $Date: 2006-07-13 12:03:26 $ * * The Contents of this file are made available subject to * the terms of GNU Lesser General Public License Version 2.1. @@ -159,6 +159,7 @@ namespace */ template< class DestAccessor, class JoinedAccessor, + bool polarity, typename MaskFunctorMode > struct masked_input_splitting_accessor { typedef BinarySetterFunctionAccessorAdapter< @@ -167,6 +168,7 @@ namespace typename outputMaskFunctorSelector< typename JoinedAccessor::value_type::first_type, typename JoinedAccessor::value_type::second_type, + polarity, MaskFunctorMode >::type > > type; }; @@ -324,13 +326,15 @@ namespace typedef typename raw_accessor_traits::template masked_accessor< mask_rawaccessor_type, dest_iterator_type, - mask_iterator_type>::type raw_maskedaccessor_type; + mask_iterator_type, + Masks::clipmask_polarity>::type raw_maskedaccessor_type; typedef typename accessor_selector::template wrap_accessor< raw_maskedaccessor_type >::type masked_accessor_type; typedef typename raw_xor_accessor_traits::template masked_accessor< mask_rawaccessor_type, dest_iterator_type, - mask_iterator_type>::type raw_maskedxor_accessor_type; + mask_iterator_type, + Masks::clipmask_polarity>::type raw_maskedxor_accessor_type; typedef typename accessor_selector::template wrap_accessor< raw_maskedxor_accessor_type >::type masked_xoraccessor_type; @@ -342,7 +346,8 @@ namespace typedef typename raw_maskedaccessor_traits::template masked_accessor< mask_rawaccessor_type, composite_iterator_type, - mask_iterator_type>::type raw_maskedmask_accessor_type; + mask_iterator_type, + Masks::clipmask_polarity>::type raw_maskedmask_accessor_type; typedef CompositeIterator2D< composite_iterator_type, @@ -352,12 +357,14 @@ namespace typedef ConstantColorBlendSetterAccessorAdapter< dest_accessor_type, - typename alphamask_rawaccessor_type::value_type> colorblend_accessor_type; + typename alphamask_rawaccessor_type::value_type, + Masks::alphamask_polarity> colorblend_accessor_type; typedef AccessorTraits<colorblend_accessor_type> colorblend_accessor_traits; typedef typename colorblend_accessor_traits::template masked_accessor< mask_rawaccessor_type, dest_iterator_type, - mask_iterator_type>::type masked_colorblend_accessor_type; + mask_iterator_type, + Masks::clipmask_polarity>::type masked_colorblend_accessor_type; // ------------------------------------------------------- @@ -936,6 +943,7 @@ namespace typename masked_input_splitting_accessor< Acc, joined_image_accessor_type, + Masks::clipmask_polarity, FastMask >::type(acc), rDstRect)); } @@ -971,6 +979,7 @@ namespace typename masked_input_splitting_accessor< Acc, joined_generic_image_accessor_type, + Masks::clipmask_polarity, NoFastMask >::type(acc), rDstRect)); } @@ -1547,7 +1556,7 @@ void BitmapDevice::drawMaskedColor( Color rSrcColor, rSrcRect, rDstPoint ); } #else - // drawMaskedBitmap is also used for OutputDevice::DrawMask + // drawMaskedColor is also used for OutputDevice::DrawMask if( clipAreaImpl( aSrcRange, aDestPoint, aSrcBounds, @@ -1559,7 +1568,14 @@ void BitmapDevice::drawMaskedColor( Color rSrcColor, if( isCompatibleClipMask( rAlphaMask ) || isCompatibleAlphaMask( rAlphaMask ) ) drawMaskedColor_i( rSrcColor, rAlphaMask, aSrcRange, aDestPoint ); else + { OSL_ENSURE( false, "drawMaskedColor(): Generic output not yet implemented #1!" ); + drawBitmap( rAlphaMask, aSrcRange, basegfx::B2IRange(aDestPoint.getX(), + aDestPoint.getY(), + aDestPoint.getX()+aSrcRange.getWidth(), + aDestPoint.getY()+aSrcRange.getHeight()), + DrawMode_PAINT ); + } } #endif } @@ -1602,7 +1618,7 @@ void BitmapDevice::drawMaskedColor( Color aSrcColor, rSrcRect, rDstPoint, rClip ); } #else - // drawMaskedBitmap is also used for OutputDevice::DrawMask + // drawMaskedColor is also used for OutputDevice::DrawMask if( (isCompatibleClipMask( rAlphaMask ) || isCompatibleAlphaMask( rAlphaMask )) && isCompatibleClipMask( rClip ) ) @@ -1612,6 +1628,12 @@ void BitmapDevice::drawMaskedColor( Color aSrcColor, else { OSL_ENSURE(false, "drawMaskedColor(): Generic output not yet implemented #2!"); + drawBitmap( rAlphaMask, aSrcRange, basegfx::B2IRange(aDestPoint.getX(), + aDestPoint.getY(), + aDestPoint.getX()+aSrcRange.getWidth(), + aDestPoint.getY()+aSrcRange.getHeight()), + DrawMode_PAINT, + rClip ); } #endif } @@ -1717,6 +1739,12 @@ struct StdMasks { typedef PixelFormatTraits_GREY1_MSB clipmask_format_traits; typedef PixelFormatTraits_GREY8 alphamask_format_traits; + + /// Clipmask: 0 means opaque + static const bool clipmask_polarity = false; + + /// Alpha mask: 0 means fully transparent + static const bool alphamask_polarity = true; }; #if 0 @@ -2018,7 +2046,7 @@ BitmapDeviceSharedPtr createBitmapDeviceImpl( const basegfx::B2IVector& r // ---------------------------------------------------------------------- // twentyfour bit formats case Format::TWENTYFOUR_BIT_TC_MASK: - return createRenderer<PixelFormatTraits_RGB24,StdMasks>( + return createRenderer<PixelFormatTraits_BGR24,StdMasks>( aBounds, bTopDown, nScanlineFormat, nScanlineStride, pFirstScanline, pMem, pPal ); diff --git a/basebmp/test/basictest.cxx b/basebmp/test/basictest.cxx index 20a3e09df063..ac0a94c98d9e 100644 --- a/basebmp/test/basictest.cxx +++ b/basebmp/test/basictest.cxx @@ -4,9 +4,9 @@ * * $RCSfile: basictest.cxx,v $ * - * $Revision: 1.10 $ + * $Revision: 1.11 $ * - * last change: $Author: thb $ $Date: 2006-07-12 22:47:21 $ + * last change: $Author: thb $ $Date: 2006-07-13 12:03:26 $ * * The Contents of this file are made available subject to * the terms of GNU Lesser General Public License Version 2.1. @@ -248,7 +248,7 @@ public: CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #10", pDevice->getPixel(aPt) == aCol4); - const Color aCol5(0x0F0F0F0F); + const Color aCol5(0x0F3F2F1F); pDevice->setPixel( aPt2, aCol5, DrawMode_PAINT ); CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #11", pDevice->getPixel(aPt2) == aCol5); @@ -257,6 +257,11 @@ public: 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 diff --git a/basebmp/test/bmpmasktest.cxx b/basebmp/test/bmpmasktest.cxx index a42bb4f82d8e..3b9575979510 100644 --- a/basebmp/test/bmpmasktest.cxx +++ b/basebmp/test/bmpmasktest.cxx @@ -4,9 +4,9 @@ * * $RCSfile: bmpmasktest.cxx,v $ * - * $Revision: 1.1 $ + * $Revision: 1.2 $ * - * last change: $Author: thb $ $Date: 2006-07-12 15:09:45 $ + * last change: $Author: thb $ $Date: 2006-07-13 12:03:26 $ * * The Contents of this file are made available subject to * the terms of GNU Lesser General Public License Version 2.1. @@ -139,14 +139,15 @@ public: basegfx::B2DPolyPolygon aPoly; basegfx::tools::importFromSvgD( aPoly, aSvg ); - const Color aCol(0xFFFFFFFF); + const Color aColWhite(0xFFFFFFFF); + const Color aColBlack(0); mpBmp1bpp->fillPolyPolygon( aPoly, - aCol, + aColWhite, DrawMode_PAINT ); mpBmp32bpp->fillPolyPolygon( aPoly, - aCol, + aColWhite, DrawMode_PAINT ); aSvg = ::rtl::OUString::createFromAscii( @@ -154,9 +155,10 @@ public: aPoly.clear(); basegfx::tools::importFromSvgD( aPoly, aSvg ); + mpMaskBmp1bpp->clear(aColWhite); mpMaskBmp1bpp->fillPolyPolygon( aPoly, - aCol, + aColBlack, DrawMode_PAINT ); } diff --git a/basebmp/test/cliptest.cxx b/basebmp/test/cliptest.cxx index 38e6797c13c1..eec3dd1bf339 100644 --- a/basebmp/test/cliptest.cxx +++ b/basebmp/test/cliptest.cxx @@ -4,9 +4,9 @@ * * $RCSfile: cliptest.cxx,v $ * - * $Revision: 1.3 $ + * $Revision: 1.4 $ * - * last change: $Author: thb $ $Date: 2006-07-12 22:47:21 $ + * last change: $Author: thb $ $Date: 2006-07-13 12:03:26 $ * * The Contents of this file are made available subject to * the terms of GNU Lesser General Public License Version 2.1. @@ -208,10 +208,10 @@ public: "m 0 0 h5 l5 5 v5 h-5 l-5-5 z" ); basegfx::B2DPolyPolygon aPoly; basegfx::tools::importFromSvgD( aPoly, aSvg ); - mpClipMask->clear(Color(0xFFFFFFFF)); + mpClipMask->clear(Color(0)); mpClipMask->drawPolygon( aPoly.getB2DPolygon(0), - Color(0), + Color(0xFFFFFFFF), DrawMode_PAINT ); } |