diff options
author | Thorsten Behrens <thb@openoffice.org> | 2006-07-11 10:39:41 +0000 |
---|---|---|
committer | Thorsten Behrens <thb@openoffice.org> | 2006-07-11 10:39:41 +0000 |
commit | 01878a9bddbb00b89876d89537ec6ba8ded33a65 (patch) | |
tree | 7ac690e7f97cfa03d974246ff4243fdbe84a71bf | |
parent | 6822a05136317f4fdd155055fc10feefe7c44832 (diff) |
#i65904# Consistently named constants; added rectangular device subsetting to BitmapDevice; moved spreaded pixel format configuration points into a single traits template (per format); slightly improved cross-format support
25 files changed, 1935 insertions, 860 deletions
diff --git a/basebmp/inc/basebmp/accessoradapters.hxx b/basebmp/inc/basebmp/accessoradapters.hxx index e8586f99181e..73d8b4d0ae47 100644 --- a/basebmp/inc/basebmp/accessoradapters.hxx +++ b/basebmp/inc/basebmp/accessoradapters.hxx @@ -4,9 +4,9 @@ * * $RCSfile: accessoradapters.hxx,v $ * - * $Revision: 1.8 $ + * $Revision: 1.9 $ * - * last change: $Author: thb $ $Date: 2006-07-06 10:00:39 $ + * last change: $Author: thb $ $Date: 2006-07-11 11:38:54 $ * * The Contents of this file are made available subject to * the terms of GNU Lesser General Public License Version 2.1. @@ -47,14 +47,26 @@ namespace basebmp @tpl WrappedAccessor Wrapped type must provide the usual get and set accessor methods, with the usual signatures (see StandardAccessor for a conforming - example). Furthermore, the type must provide a wrapped typedef - value_type + example). + + @tpl GetterFunctor + An Adaptable Unary Function (i.e. providing result_type and + argument_type typedefs) + + @tpl SetterFunctor + An Adaptable Unary Function (i.e. providing result_type and + argument_type typedefs) */ template< class WrappedAccessor, typename GetterFunctor, typename SetterFunctor > class UnaryFunctionAccessorAdapter { +#ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS +// making all members public, if no member template friends private: + template<class A, typename G, typename S> friend class UnaryFunctionAccessorAdapter; +#endif + // we don't derive from wrapped type, to avoid ambiguities // regarding templatized getter/setter methods. WrappedAccessor maAccessor; @@ -62,7 +74,8 @@ private: SetterFunctor maSetterFunctor; public: - typedef typename WrappedAccessor::value_type value_type; + typedef typename GetterFunctor::result_type value_type; + typedef typename SetterFunctor::argument_type argument_type; UnaryFunctionAccessorAdapter() : maAccessor(), @@ -70,6 +83,15 @@ public: maSetterFunctor() {} + template< class A > explicit + UnaryFunctionAccessorAdapter( UnaryFunctionAccessorAdapter< A, + GetterFunctor, + SetterFunctor > const& rSrc ) : + maAccessor( rSrc.maAccessor ), + maGetterFunctor( rSrc.maGetterFunctor ), + maSetterFunctor( rSrc.maSetterFunctor ) + {} + template< class T > explicit UnaryFunctionAccessorAdapter( T accessor ) : maAccessor( accessor ), maGetterFunctor(), @@ -91,6 +113,17 @@ public: // ------------------------------------------------------- + value_type getter(typename GetterFunctor::argument_type v) const + { + return maGetterFunctor(v); + } + typename SetterFunctor::result_type setter(argument_type v) const + { + return maSetterFunctor(v); + } + + // ------------------------------------------------------- + template< class Iterator > value_type operator()(Iterator const& i) const { @@ -110,7 +143,8 @@ public: { maAccessor.set( maSetterFunctor( - vigra::detail::RequiresExplicitCast<value_type>::cast(value) )); + vigra::detail::RequiresExplicitCast<argument_type>::cast(value) ), + i ); } template< typename V, class Iterator, class Difference > @@ -118,7 +152,9 @@ public: { maAccessor.set( maSetterFunctor( - vigra::detail::RequiresExplicitCast<value_type>::cast(value) )); + vigra::detail::RequiresExplicitCast<argument_type>::cast(value) ), + i, + diff ); } }; @@ -133,24 +169,41 @@ public: @tpl WrappedAccessor Wrapped type must provide the usual get and set accessor methods, with the usual signatures (see StandardAccessor for a conforming - example). Furthermore, the type must provide a wrapped typedef - value_type + example). Furthermore, must provide a nested typedef value_type. + + @tpl SetterFunctor + An adaptable binary function (i.e. providing nested typedefs for + result_type and first and second argument type) */ template< class WrappedAccessor, typename SetterFunctor > class BinarySetterFunctionAccessorAdapter { +#ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS +// making all members public, if no member template friends private: + template<class A, typename S> friend class BinarySetterFunctionAccessorAdapter; +#endif + WrappedAccessor maAccessor; SetterFunctor maFunctor; public: - typedef typename WrappedAccessor::value_type value_type; + typedef typename WrappedAccessor::value_type value_type; + typedef typename SetterFunctor::second_argument_type argument_type; BinarySetterFunctionAccessorAdapter() : maAccessor(), maFunctor() {} + template< class A > explicit + BinarySetterFunctionAccessorAdapter( + BinarySetterFunctionAccessorAdapter< A, + SetterFunctor > const& rSrc ) : + maAccessor( rSrc.maAccessor ), + maFunctor( rSrc.maFunctor ) + {} + template< class T > explicit BinarySetterFunctionAccessorAdapter( T accessor ) : maAccessor( accessor ), maFunctor() @@ -169,6 +222,15 @@ public: // ------------------------------------------------------- + typename SetterFunctor::result_type setter( + typename SetterFunctor::first_argument_type v1, + argument_type v2 ) const + { + return maSetterFunctor(v1,v2); + } + + // ------------------------------------------------------- + template< class Iterator > value_type operator()(Iterator const& i) const { @@ -188,7 +250,7 @@ public: { maAccessor.set( maFunctor(maAccessor(i), - vigra::detail::RequiresExplicitCast<value_type>::cast(value)), + vigra::detail::RequiresExplicitCast<argument_type>::cast(value)), i ); } @@ -197,7 +259,7 @@ public: { maAccessor.set( maFunctor(maAccessor(i,diff), - vigra::detail::RequiresExplicitCast<value_type>::cast(value)), + vigra::detail::RequiresExplicitCast<argument_type>::cast(value)), i, diff ); } @@ -218,20 +280,32 @@ public: @tpl WrappedAccessor1 Wrapped type must provide the usual get and set accessor methods, with the usual signatures (see StandardAccessor for a conforming - example). Furthermore, the type must provide a wrapped typedef - value_type + example). Furthermore, the type must provide a nested typedef + value_type (the selection of WrappedAccessor1 as the provider for + that typedef is rather arbitrary. Could have been + WrappedAccessor2, too. So sue me) + + @tpl Functor + An adaptable ternary function (i.e. providing nested typedefs for + result_type and first, second and third argument type) */ template< class WrappedAccessor1, class WrappedAccessor2, typename Functor > class TernarySetterFunctionAccessorAdapter { +#ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS +// making all members public, if no member template friends private: + template<class A1, class A2, typename F> friend class TernarySetterFunctionAccessorAdapter; +#endif + WrappedAccessor1 ma1stAccessor; WrappedAccessor2 ma2ndAccessor; Functor maFunctor; public: typedef typename WrappedAccessor1::value_type value_type; + typedef typename Functor::third_argument_type argument_type; TernarySetterFunctionAccessorAdapter() : ma1stAccessor(), @@ -245,6 +319,16 @@ public: maFunctor() {} + template< class A1, class A2 > + TernarySetterFunctionAccessorAdapter( + TernarySetterFunctionAccessorAdapter< A1, + A2, + Functor > const& rSrc ) : + ma1stAccessor( rSrc.ma1stAccessor ), + ma2ndAccessor( rSrc.ma2ndAccessor ), + maFunctor( rSrc.maFunctor ) + {} + template< class T1, class T2 > TernarySetterFunctionAccessorAdapter( T1 accessor1, T2 accessor2 ) : @@ -272,6 +356,16 @@ public: // ------------------------------------------------------- + typename Functor::result_type setter( + typename Functor::first_argument_type v1, + typename Functor::second_argument_type v2, + argument_type v3 ) const + { + return maSetterFunctor(v1,v2,v3); + } + + // ------------------------------------------------------- + template< class Iterator > value_type operator()(Iterator const& i) const { @@ -292,7 +386,7 @@ public: ma1stAccessor.set( maFunctor(ma1stAccessor(i.first()), ma2ndAccessor(i.second()), - vigra::detail::RequiresExplicitCast<value_type>::cast(value)), + vigra::detail::RequiresExplicitCast<argument_type>::cast(value)), i.first() ); } @@ -302,7 +396,7 @@ public: ma1stAccessor.set( maFunctor(ma1stAccessor(i.first(), diff), ma2ndAccessor(i.second(),diff), - vigra::detail::RequiresExplicitCast<value_type>::cast(value)), + vigra::detail::RequiresExplicitCast<argument_type>::cast(value)), i.first(), diff ); } diff --git a/basebmp/inc/basebmp/accessortraits.hxx b/basebmp/inc/basebmp/accessortraits.hxx index 581337acfcc0..8478718376f2 100644 --- a/basebmp/inc/basebmp/accessortraits.hxx +++ b/basebmp/inc/basebmp/accessortraits.hxx @@ -4,9 +4,9 @@ * * $RCSfile: accessortraits.hxx,v $ * - * $Revision: 1.1 $ + * $Revision: 1.2 $ * - * last change: $Author: thb $ $Date: 2006-07-06 10:02:07 $ + * last change: $Author: thb $ $Date: 2006-07-11 11:38:54 $ * * The Contents of this file are made available subject to * the terms of GNU Lesser General Public License Version 2.1. @@ -38,6 +38,7 @@ #include <osl/diagnose.h> #include <basebmp/accessoradapters.hxx> +#include <basebmp/metafunctions.hxx> #include <functional> @@ -51,7 +52,7 @@ namespace basebmp //----------------------------------------------------------------------------- // XOR -template< typename T > struct XorFunctor +template< typename T > struct XorFunctor : public std::binary_function<T,T,T> { T operator()( T v1, T v2 ) const { return v1 ^ v2; } }; @@ -59,7 +60,17 @@ template< typename T > struct XorFunctor //----------------------------------------------------------------------------- // Mask -template< typename T, typename M > struct GenericOutputMaskFunctor +template< typename T, typename M > struct MaskFunctorBase +{ + typedef T first_argument_type; + typedef M second_argument_type; + typedef T third_argument_type; + typedef T result_type; +}; + + +// Mask +template< typename T, typename M > struct GenericOutputMaskFunctor : MaskFunctorBase<T,M> { /// Ternary mask operation - selects v1 for m == 0, v2 otherwise T operator()( T v1, M m, T v2 ) const @@ -68,7 +79,7 @@ template< typename T, typename M > struct GenericOutputMaskFunctor } }; -template< typename T, typename M > struct IntegerOutputMaskFunctor +template< typename T, typename M > struct IntegerOutputMaskFunctor : MaskFunctorBase<T,M> { /** Mask v with state of m @@ -84,7 +95,7 @@ template< typename T, typename M > struct IntegerOutputMaskFunctor } }; -template< typename T, typename M > struct FastIntegerOutputMaskFunctor +template< typename T, typename M > struct FastIntegerOutputMaskFunctor : MaskFunctorBase<T,M> { /// Specialization, only valid if mask can only attain 0 or 1 T operator()( T v1, M m, T v2 ) const diff --git a/basebmp/inc/basebmp/bitmapdevice.hxx b/basebmp/inc/basebmp/bitmapdevice.hxx index 080f2a475e49..37bb0e04dfd4 100644 --- a/basebmp/inc/basebmp/bitmapdevice.hxx +++ b/basebmp/inc/basebmp/bitmapdevice.hxx @@ -2,9 +2,9 @@ * * $RCSfile: bitmapdevice.hxx,v $ * - * $Revision: 1.5 $ + * $Revision: 1.6 $ * - * last change: $Author: thb $ $Date: 2006-06-28 16:50:18 $ + * last change: $Author: thb $ $Date: 2006-07-11 11:38:54 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -48,6 +48,7 @@ #include <boost/scoped_ptr.hpp> #include <boost/shared_ptr.hpp> #include <boost/shared_array.hpp> +#include <boost/enable_shared_from_this.hpp> #include <boost/noncopyable.hpp> #include <vector> @@ -78,13 +79,14 @@ struct ImplBitmapDevice; Implementation note: the clip mask and bitmap parameter instances of BitmapDevice that are passed to individual BitmapDevice - instances work best with 1 bit gray masks for the clip and a + instances work best with 1 bit grey masks for the clip and a format matching that of the target BitmapDevice for the other parameters. The alpha mask passed to the drawMaskedColor() methods - works best when given as an eight bit gray bitmap. Everything else + works best when given as an eight bit grey bitmap. Everything else is accepted, but potentially slow. */ -class BitmapDevice : private boost::noncopyable +class BitmapDevice : public boost::enable_shared_from_this<BitmapDevice>, + private boost::noncopyable { public: /** Query size of device in pixel @@ -547,10 +549,11 @@ public: const BitmapDeviceSharedPtr& rClip ); protected: - BitmapDevice( const basegfx::B2IVector& rSize, + BitmapDevice( const basegfx::B2IRange& rBounds, bool bTopDown, sal_Int32 nScanlineFormat, sal_Int32 nScanlineStride, + sal_uInt8* pFirstScanline, const RawMemorySharedArray& rMem, const PaletteMemorySharedVector& rPalette ); @@ -561,7 +564,8 @@ private: virtual bool isCompatibleClipMask( const BitmapDeviceSharedPtr& bmp ) const = 0; virtual bool isCompatibleAlphaMask( const BitmapDeviceSharedPtr& bmp ) const = 0; - virtual void clear_i( Color fillColor ) = 0; + virtual void clear_i( Color fillColor, + const basegfx::B2IRange& rBounds ) = 0; virtual void setPixel_i( const basegfx::B2IPoint& rPt, Color lineColor, @@ -642,6 +646,8 @@ private: DrawMode drawMode, const BitmapDeviceSharedPtr& rClip ) = 0; + BitmapDeviceSharedPtr getGenericRenderer() const; + boost::scoped_ptr< ImplBitmapDevice > mpImpl; }; @@ -652,7 +658,19 @@ BitmapDeviceSharedPtr createBitmapDevice( const basegfx::B2IVector& rSize, sal_Int32 nScanlineFormat ); /** Factory method to create a BitmapDevice for given scanline format - from the given piece of raw memory + with the given palette + + Note: the provided palette must have sufficient size, to satisfy + lookups for the whole range of pixel values from the specified + format. + */ +BitmapDeviceSharedPtr createBitmapDevice( const basegfx::B2IVector& rSize, + bool bTopDown, + sal_Int32 nScanlineFormat, + const PaletteMemorySharedVector& rPalette ); + +/** Factory method to create a BitmapDevice for given scanline format + from the given piece of raw memory and palette Note: the provided memory must have sufficient size, to store the image of the specified area and format. @@ -664,6 +682,17 @@ BitmapDeviceSharedPtr createBitmapDevice( const basegfx::B2IVector& rSize const PaletteMemorySharedVector& rPalette ); +/** Factory method to retrieve a subsetted BitmapDevice to the same + memory. + + This method creates a second bitmap device instance, which renders + to the same memory as the original, but to a limited, rectangular + area. Useful to implement rectangular clips (usually faster than + setting up a 1bpp clip mask). + */ +BitmapDeviceSharedPtr subsetBitmapDevice( const BitmapDeviceSharedPtr& rProto, + const basegfx::B2IRange& rSubset ); + /** Factory method to clone a BitmapDevice from a given prototype. All attributes (like scanline format and top-down state) are diff --git a/basebmp/inc/basebmp/clippedlinerenderer.hxx b/basebmp/inc/basebmp/clippedlinerenderer.hxx index 1488dfe57329..72b768f66fef 100644 --- a/basebmp/inc/basebmp/clippedlinerenderer.hxx +++ b/basebmp/inc/basebmp/clippedlinerenderer.hxx @@ -4,9 +4,9 @@ * * $RCSfile: clippedlinerenderer.hxx,v $ * - * $Revision: 1.5 $ + * $Revision: 1.6 $ * - * last change: $Author: thb $ $Date: 2006-06-30 11:05:21 $ + * last change: $Author: thb $ $Date: 2006-07-11 11:38:54 $ * * The Contents of this file are made available subject to * the terms of GNU Lesser General Public License Version 2.1. @@ -46,6 +46,8 @@ #include <basegfx/range/b2irange.hxx> #endif +#include <vigra/iteratortraits.hxx> + namespace basebmp { @@ -278,8 +280,9 @@ void renderClippedLine( basegfx::B2IPoint aPt1, rClipRect.getMaxY(), basegfx::tools::RectClipFlags::BOTTOM, bRoundTowardsPt2 )); - Iterator currIter( begin + vigra::Diff2D(0,ys) ); - typename Iterator::row_iterator rowIter( currIter.rowIterator() + xs ); + Iterator currIter( begin + vigra::Diff2D(0,ys) ); + typename vigra::IteratorTraits<Iterator>::row_iterator + rowIter( currIter.rowIterator() + xs ); adx *= 2; ady *= 2; @@ -353,8 +356,9 @@ void renderClippedLine( basegfx::B2IPoint aPt1, rClipRect.getMaxX(), basegfx::tools::RectClipFlags::RIGHT, bRoundTowardsPt2 )); - Iterator currIter( begin + vigra::Diff2D(xs,0) ); - typename Iterator::column_iterator colIter( currIter.columnIterator() + ys ); + Iterator currIter( begin + vigra::Diff2D(xs,0) ); + typename vigra::IteratorTraits<Iterator>::column_iterator + colIter( currIter.columnIterator() + ys ); adx *= 2; ady *= 2; diff --git a/basebmp/inc/basebmp/color.hxx b/basebmp/inc/basebmp/color.hxx index e469a68aba4e..d4df6839d4af 100644 --- a/basebmp/inc/basebmp/color.hxx +++ b/basebmp/inc/basebmp/color.hxx @@ -4,9 +4,9 @@ * * $RCSfile: color.hxx,v $ * - * $Revision: 1.11 $ + * $Revision: 1.12 $ * - * last change: $Author: thb $ $Date: 2006-07-06 10:00:39 $ + * last change: $Author: thb $ $Date: 2006-07-11 11:38:54 $ * * The Contents of this file are made available subject to * the terms of GNU Lesser General Public License Version 2.1. @@ -63,13 +63,13 @@ public: void setGreen( sal_uInt8 nGreen ) { mnColor &= ~0x0000FF00UL; mnColor |= (sal_uInt32)nGreen << 8; } void setBlue( sal_uInt8 nBlue ) { mnColor &= ~0x000000FFUL; mnColor |= nBlue; } - void setGray( sal_uInt8 nGrayVal ) { mnColor = (sal_uInt32)nGrayVal << 16 | (sal_uInt32)nGrayVal << 8 | nGrayVal; } + void setGrey( sal_uInt8 nGreyVal ) { mnColor = (sal_uInt32)nGreyVal << 16 | (sal_uInt32)nGreyVal << 8 | nGreyVal; } sal_uInt8 getRed() const { return 0xFF & (mnColor >> 16); } sal_uInt8 getGreen() const { return 0xFF & (mnColor >> 8); } sal_uInt8 getBlue() const { return 0xFF & mnColor; } - sal_uInt8 getGrayscale() const { return (sal_uInt8)((getBlue()*28UL + + sal_uInt8 getGreyscale() const { return (sal_uInt8)((getBlue()*28UL + getGreen()*151 + getRed()*77) / 256); } diff --git a/basebmp/inc/basebmp/colormisc.hxx b/basebmp/inc/basebmp/colormisc.hxx index dbb61900cdb9..8cdf665c6145 100644 --- a/basebmp/inc/basebmp/colormisc.hxx +++ b/basebmp/inc/basebmp/colormisc.hxx @@ -4,9 +4,9 @@ * * $RCSfile: colormisc.hxx,v $ * - * $Revision: 1.2 $ + * $Revision: 1.3 $ * - * last change: $Author: thb $ $Date: 2006-07-06 10:00:39 $ + * last change: $Author: thb $ $Date: 2006-07-11 11:38:55 $ * * The Contents of this file are made available subject to * the terms of GNU Lesser General Public License Version 2.1. @@ -38,7 +38,8 @@ #include <osl/diagnose.h> #include <basebmp/color.hxx> -#include <basebmp/accessoradapters.hxx> +#include <basebmp/colortraits.hxx> +#include <basebmp/accessortraits.hxx> #include <vigra/mathutil.hxx> // Contents of this header moved out of color.hxx, as it is not useful @@ -49,7 +50,7 @@ namespace basebmp { -struct ColorBitmaskOutputMaskFunctor +struct ColorBitmaskOutputMaskFunctor : MaskFunctorBase<Color,sal_uInt8> { Color operator()( Color v1, sal_uInt8 m, Color v2 ) const { @@ -65,7 +66,7 @@ template<> struct outputMaskFunctorSelector< Color, sal_uInt8, FastMask > typedef ColorBitmaskOutputMaskFunctor type; }; -struct ColorBlendFunctor +struct ColorBlendFunctor : public BlendFunctorBase<Color,sal_uInt8> { Color operator()( sal_uInt8 alpha, Color v1, @@ -98,11 +99,21 @@ template<> struct ColorTraits< Color > template< typename AlphaType > struct blend_functor; /// Calculate normalized distance between color c1 and c2 - static double distance( const Color& c1, - const Color& c2 ) + static inline double distance( const Color& c1, + const Color& c2 ) { return (c1 - c2).magnitude(); } + + static inline component_type toGreyscale( const Color& c ) + { + return c.getGreyscale(); + } + + static inline Color fromGreyscale( component_type c ) + { + return Color(c,c,c); + } }; /// Only defined for 8 bit alpha, currently diff --git a/basebmp/inc/basebmp/colortraits.hxx b/basebmp/inc/basebmp/colortraits.hxx index 21706a9a72de..53e2902c004b 100644 --- a/basebmp/inc/basebmp/colortraits.hxx +++ b/basebmp/inc/basebmp/colortraits.hxx @@ -4,9 +4,9 @@ * * $RCSfile: colortraits.hxx,v $ * - * $Revision: 1.1 $ + * $Revision: 1.2 $ * - * last change: $Author: thb $ $Date: 2006-07-06 10:00:40 $ + * last change: $Author: thb $ $Date: 2006-07-11 11:38:55 $ * * The Contents of this file are made available subject to * the terms of GNU Lesser General Public License Version 2.1. @@ -44,8 +44,17 @@ namespace basebmp { +template< typename ValueType, typename AlphaType > struct BlendFunctorBase +{ + typedef AlphaType first_argument_type; + typedef ValueType second_argument_type; + typedef ValueType third_argument_type; + typedef ValueType result_type; +}; + /// Functor template, to calculate alpha blending between two values. Float case. -template< typename ValueType, typename AlphaType > struct BlendFunctor +template< typename ValueType, typename AlphaType > struct BlendFunctor : + public BlendFunctorBase<ValueType,AlphaType> { ValueType operator()( AlphaType alpha, ValueType v1, @@ -87,11 +96,21 @@ template< typename ColorType > struct ColorTraits typedef ColorType component_type; /// Calculate normalized distance between color c1 and c2 - static vigra::NormTraits<ColorType> distance( ColorType c1, - ColorType c2 ) + static inline vigra::NormTraits<ColorType> distance( ColorType c1, + ColorType c2 ) { return vigra::norm(c1 - c2); } + + static inline component_type toGreyscale( ColorType c ) + { + return c; + } + + static inline ColorType fromGreyscale( component_type c ) + { + return c; + } }; } // namespace basebmp diff --git a/basebmp/inc/basebmp/fillimage.hxx b/basebmp/inc/basebmp/fillimage.hxx new file mode 100644 index 000000000000..4ab6c97b1582 --- /dev/null +++ b/basebmp/inc/basebmp/fillimage.hxx @@ -0,0 +1,69 @@ +/************************************************************************* + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: fillimage.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: thb $ $Date: 2006-07-11 11:38:55 $ + * + * The Contents of this file are made available subject to + * the terms of GNU Lesser General Public License Version 2.1. + * + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2005 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + ************************************************************************/ + +#ifndef INCLUDED_BASEBMP_FILLIMAGE_HXX +#define INCLUDED_BASEBMP_FILLIMAGE_HXX + +#include <vigra/iteratortraits.hxx> + +namespace basebmp +{ + +template< class DestIterator, class DestAccessor, typename T > +void fillImage( DestIterator begin, + DestIterator end, + DestAccessor ad, + T fillVal ) +{ + const int width ( end.x - begin.x ); + const int height( end.y - begin.y ); + + for( int y=0; y<height; ++y, ++begin.y ) + { + typename vigra::IteratorTraits<DestIterator>::row_iterator + rowIter( begin.rowIterator() ); + const typename vigra::IteratorTraits<DestIterator>::row_iterator + rowEnd( rowIter + width ); + + // TODO(P2): Provide specialized span fill methods on the + // iterator/accessor + while( rowIter != rowEnd ) + ad.set(fillVal, rowIter++); + } +} + +} // namespace basebmp + +#endif /* INCLUDED_BASEBMP_FILLIMAGE_HXX */ diff --git a/basebmp/inc/basebmp/greylevelformats.hxx b/basebmp/inc/basebmp/greylevelformats.hxx new file mode 100644 index 000000000000..6678426ed703 --- /dev/null +++ b/basebmp/inc/basebmp/greylevelformats.hxx @@ -0,0 +1,143 @@ +/************************************************************************* + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: greylevelformats.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: thb $ $Date: 2006-07-11 11:39:41 $ + * + * The Contents of this file are made available subject to + * the terms of GNU Lesser General Public License Version 2.1. + * + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2005 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + ************************************************************************/ + +#ifndef INCLUDED_BASEBMP_GREYLEVELFORMATS_HXX +#define INCLUDED_BASEBMP_GREYLEVELFORMATS_HXX + +#include <basebmp/color.hxx> +#include <basebmp/colortraits.hxx> +#include <basebmp/accessor.hxx> +#include <basebmp/pixeliterator.hxx> +#include <basebmp/packedpixeliterator.hxx> +#include <basebmp/pixelformatadapters.hxx> +#include <basebmp/metafunctions.hxx> + +#include <vigra/numerictraits.hxx> +#include <vigra/metaprogramming.hxx> + +#include <functional> + +namespace basebmp +{ + +template< typename PixelType, + typename ColorType, + int UsedRange > struct GreylevelGetter : + public std::unary_function<PixelType, ColorType> +{ + ColorType operator()( PixelType const& c ) const + { + return ColorTraits<ColorType>::fromGreyscale( + vigra::NumericTraits<PixelType>::toPromote(c) * + vigra::NumericTraits<PixelType>::maxConst / UsedRange ); + } +}; + +template< typename PixelType, + typename ColorType, + int UsedRange > struct GreylevelSetter : + public std::unary_function<ColorType, PixelType> +{ + PixelType operator()( ColorType const& c ) const + { + return vigra::NumericTraits<PixelType>::toPromote( + ColorTraits<ColorType>::toGreyscale(c)) * + UsedRange / + vigra::NumericTraits<PixelType>::maxConst; + } +}; + +//----------------------------------------------------------------------------- + +template< class Iterator, + class Accessor, + int UsedRange > struct PixelFormatTraitsTemplate_Greylevel +{ + typedef typename Iterator::value_type pixel_type; + + typedef GreylevelGetter<pixel_type, + Color, + UsedRange> getter_type; + typedef GreylevelSetter<pixel_type, + Color, + UsedRange> setter_type; + + typedef Iterator iterator_type; + typedef Accessor raw_accessor_type; + typedef AccessorSelector< + getter_type, + setter_type > accessor_selector; +}; + +template< int BitsPerPixel, + bool MsbFirst > struct PixelFormatTraitsTemplate_PackedGreylevel : + public PixelFormatTraitsTemplate_Greylevel< + PackedPixelIterator< sal_uInt8, + BitsPerPixel, + true >, + NonStandardAccessor< sal_uInt8 >, + (1UL << BitsPerPixel)-1 > +{}; + +//----------------------------------------------------------------------------- + +// 1bpp MSB +typedef PixelFormatTraitsTemplate_PackedGreylevel<1, true> PixelFormatTraits_GREY1_MSB; + +// 1bpp LSB +typedef PixelFormatTraitsTemplate_PackedGreylevel<1, false> PixelFormatTraits_GREY1_LSB; +BASEBMP_SPECIALIZE_ACCESSORTRAITS(PixelFormatTraits_GREY1_MSB::getter_type, + PixelFormatTraits_GREY1_MSB::setter_type); + + +// 4bpp MSB +typedef PixelFormatTraitsTemplate_PackedGreylevel<4, true> PixelFormatTraits_GREY4_MSB; + +// 4bpp LSB +typedef PixelFormatTraitsTemplate_PackedGreylevel<4, false> PixelFormatTraits_GREY4_LSB; +BASEBMP_SPECIALIZE_ACCESSORTRAITS(PixelFormatTraits_GREY4_MSB::getter_type, + PixelFormatTraits_GREY4_MSB::setter_type); + +// 8bpp +typedef PixelFormatTraitsTemplate_Greylevel< + PixelIterator< sal_uInt8 >, + StandardAccessor< sal_uInt8 >, + 255 > PixelFormatTraits_GREY8; +BASEBMP_SPECIALIZE_ACCESSORTRAITS(PixelFormatTraits_GREY8::getter_type, + PixelFormatTraits_GREY8::setter_type); + +} // namespace basebmp + +#endif /* INCLUDED_BASEBMP_GREYLEVELFORMATS_HXX */ diff --git a/basebmp/inc/basebmp/linerenderer.hxx b/basebmp/inc/basebmp/linerenderer.hxx index 9e06d0c33bb6..c151c0d1010b 100644 --- a/basebmp/inc/basebmp/linerenderer.hxx +++ b/basebmp/inc/basebmp/linerenderer.hxx @@ -4,9 +4,9 @@ * * $RCSfile: linerenderer.hxx,v $ * - * $Revision: 1.3 $ + * $Revision: 1.4 $ * - * last change: $Author: thb $ $Date: 2006-06-28 16:50:19 $ + * last change: $Author: thb $ $Date: 2006-07-11 11:38:55 $ * * The Contents of this file are made available subject to * the terms of GNU Lesser General Public License Version 2.1. @@ -40,6 +40,9 @@ #include <basegfx/point/b2ipoint.hxx> #endif +#include <vigra/iteratortraits.hxx> + + /* Scan-converting lines */ namespace basebmp @@ -120,7 +123,8 @@ void renderLine( const basegfx::B2IPoint& rPt1, ady *= 2; Iterator currIter( begin + vigra::Diff2D(0,ys) ); - typename Iterator::row_iterator rowIter( currIter.rowIterator() + xs ); + typename vigra::IteratorTraits<Iterator>::row_iterator + rowIter( currIter.rowIterator() + xs ); while(true) { acc.set(color, rowIter); @@ -153,7 +157,8 @@ void renderLine( const basegfx::B2IPoint& rPt1, ady *= 2; Iterator currIter( begin + vigra::Diff2D(xs,0) ); - typename Iterator::column_iterator colIter( currIter.columnIterator() + ys ); + typename vigra::IteratorTraits<Iterator>::column_iterator + colIter( currIter.columnIterator() + ys ); while(true) { acc.set(color, colIter); diff --git a/basebmp/inc/basebmp/metafunctions.hxx b/basebmp/inc/basebmp/metafunctions.hxx index 42e887bd9cbe..8004906174f1 100644 --- a/basebmp/inc/basebmp/metafunctions.hxx +++ b/basebmp/inc/basebmp/metafunctions.hxx @@ -4,9 +4,9 @@ * * $RCSfile: metafunctions.hxx,v $ * - * $Revision: 1.5 $ + * $Revision: 1.6 $ * - * last change: $Author: thb $ $Date: 2006-07-06 10:00:40 $ + * last change: $Author: thb $ $Date: 2006-07-11 11:38:55 $ * * The Contents of this file are made available subject to * the terms of GNU Lesser General Public License Version 2.1. @@ -199,6 +199,20 @@ template<> struct bitcount<0> enum { value = 0 }; }; +//-------------------------------------------------------------- + +/// Shift left for positive shift value, and right otherwise +template< typename T > inline T shiftLeft( T v, int shift ) +{ + return shift > 0 ? v << shift : v >> (-shift); +} + +/// Shift right for positive shift value, and left otherwise +template< typename T > inline T shiftRight( T v, int shift ) +{ + return shift > 0 ? v >> shift : v << (-shift); +} + } // namespace basebmp diff --git a/basebmp/inc/basebmp/paletteformats.hxx b/basebmp/inc/basebmp/paletteformats.hxx new file mode 100644 index 000000000000..41ab730f1ed0 --- /dev/null +++ b/basebmp/inc/basebmp/paletteformats.hxx @@ -0,0 +1,155 @@ +/************************************************************************* + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: paletteformats.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: thb $ $Date: 2006-07-11 11:39:41 $ + * + * The Contents of this file are made available subject to + * the terms of GNU Lesser General Public License Version 2.1. + * + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2005 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + ************************************************************************/ + +#ifndef INCLUDED_BASEBMP_PACKEDPIXELFORMATS_HXX +#define INCLUDED_BASEBMP_PACKEDPIXELFORMATS_HXX + +#include <basebmp/color.hxx> +#include <basebmp/colortraits.hxx> +#include <basebmp/accessor.hxx> +#include <basebmp/pixeliterator.hxx> +#include <basebmp/packedpixeliterator.hxx> +#include <basebmp/pixelformatadapters.hxx> +#include <basebmp/paletteimageaccessor.hxx> +#include <basebmp/metafunctions.hxx> + +#include <vigra/numerictraits.hxx> +#include <vigra/metaprogramming.hxx> + +#include <functional> + +namespace basebmp +{ + +//----------------------------------------------------------------------------- + +/** Lookup index value for given color value in a PaletteImageAccessor + */ +template< class Accessor > struct ColorLookup +{ + typename Accessor::data_type operator()( const Accessor& acc, + typename Accessor::value_type v ) const + { + return acc.lookup(v); + } +}; + +//----------------------------------------------------------------------------- + +// partial specialization of AccessorTraits for PaletteAccessor +template< class Accessor, typename ColorType > struct AccessorTraits< + PaletteImageAccessor< Accessor, ColorType > > +{ + /// value type of described accessor + typedef typename PaletteImageAccessor< Accessor, ColorType >::value_type value_type; + + /// Retrieve stand-alone color lookup function for given Accessor type + typedef ColorLookup< PaletteImageAccessor< Accessor, ColorType > > color_lookup; + + /// Retrieve raw pixel data accessor for given Accessor type + typedef Accessor raw_accessor; + + /** accessor for XOR setter access is disabled, since the results + * are usually completely unintended - you'll usually want to + * wrap an xor_accessor with a PaletteAccessor, not the other way + * around. + */ + typedef vigra::VigraFalseType xor_accessor; + + /** accessor for masked setter access is disabled, since the + * results are usually completely unintended - you'll usually + * want to wrap a masked_accessor with a PaletteAccessor, not the + * other way around. + */ + template< class MaskAccessor, + class Iterator, + class MaskIterator > struct masked_accessor + { + typedef vigra::VigraFalseType type; + }; +}; + +//----------------------------------------------------------------------------- + +template< typename ColorType > struct PaletteAccessorSelector +{ + template< class Accessor > struct wrap_accessor + { + typedef PaletteImageAccessor< Accessor, ColorType > type; + }; +}; + +//----------------------------------------------------------------------------- + +template< class Iterator, + class Accessor > struct PixelFormatTraitsTemplate_Palette +{ + typedef typename Iterator::value_type pixel_type; + typedef Iterator iterator_type; + typedef Accessor raw_accessor_type; + typedef PaletteAccessorSelector<Color> accessor_selector; +}; + +template< int BitsPerPixel, + bool MsbFirst > struct PixelFormatTraitsTemplate_PackedPalette : + public PixelFormatTraitsTemplate_Palette< + PackedPixelIterator< sal_uInt8, + BitsPerPixel, + true >, + NonStandardAccessor< sal_uInt8 > > +{}; + +//----------------------------------------------------------------------------- + +// 1bpp MSB +typedef PixelFormatTraitsTemplate_PackedPalette<1, true> PixelFormatTraits_PAL1_MSB; + +// 1bpp LSB +typedef PixelFormatTraitsTemplate_PackedPalette<1, false> PixelFormatTraits_PAL1_LSB; + +// 4bpp MSB +typedef PixelFormatTraitsTemplate_PackedPalette<4, true> PixelFormatTraits_PAL4_MSB; + +// 4bpp LSB +typedef PixelFormatTraitsTemplate_PackedPalette<4, false> PixelFormatTraits_PAL4_LSB; + +// 8bpp +typedef PixelFormatTraitsTemplate_Palette< + PixelIterator< sal_uInt8 >, + StandardAccessor< sal_uInt8 > > PixelFormatTraits_PAL8; + +} // namespace basebmp + +#endif /* INCLUDED_BASEBMP_PACKEDPIXELFORMATS_HXX */ diff --git a/basebmp/inc/basebmp/paletteimageaccessor.hxx b/basebmp/inc/basebmp/paletteimageaccessor.hxx index 84039879ed55..97243b0a764f 100644 --- a/basebmp/inc/basebmp/paletteimageaccessor.hxx +++ b/basebmp/inc/basebmp/paletteimageaccessor.hxx @@ -4,9 +4,9 @@ * * $RCSfile: paletteimageaccessor.hxx,v $ * - * $Revision: 1.7 $ + * $Revision: 1.8 $ * - * last change: $Author: thb $ $Date: 2006-07-06 10:00:40 $ + * last change: $Author: thb $ $Date: 2006-07-11 11:38:55 $ * * The Contents of this file are made available subject to * the terms of GNU Lesser General Public License Version 2.1. @@ -171,54 +171,6 @@ public: } }; -//----------------------------------------------------------------------------- - -/** Lookup index value for given Color value in PaletteImageAccessor - */ -template< class Accessor > struct ColorLookup -{ - typename Accessor::data_type operator()( const Accessor& acc, - typename Accessor::value_type v ) - { - return acc.lookup(v); - } -}; - -//----------------------------------------------------------------------------- - -// partial specialization for PaletteAccessor -template< class Accessor, typename ColorType > struct AccessorTraits< - PaletteImageAccessor< Accessor, ColorType > > -{ - /// value type of described accessor - typedef typename PaletteImageAccessor< Accessor, ColorType >::value_type value_type; - - /// Retrieve stand-alone color lookup function for given Accessor type - typedef ColorLookup< PaletteImageAccessor< Accessor, ColorType > > color_lookup; - - /// Retrieve raw pixel data accessor for given Accessor type - typedef Accessor raw_accessor; - - /** accessor for XOR setter access is disabled, since the results - * are usually completely unintended - you'll usually want to - * wrap an xor_accessor with a PaletteAccessor, not the other way - * around. - */ - typedef vigra::VigraFalseType xor_accessor; - - /** accessor for masked setter access is disabled, since the - * results are usually completely unintended - you'll usually - * want to wrap a masked_accessor with a PaletteAccessor, not the - * other way around. - */ - template< class MaskAccessor, - class Iterator, - class MaskIterator > struct masked_accessor - { - typedef vigra::VigraFalseType type; - }; -}; - } // namespace basebmp #endif /* INCLUDED_BASEBMP_PALETTEIMAGEACCESSOR_HXX */ diff --git a/basebmp/inc/basebmp/pixelformatadapters.hxx b/basebmp/inc/basebmp/pixelformatadapters.hxx new file mode 100644 index 000000000000..3f0447bb4e5a --- /dev/null +++ b/basebmp/inc/basebmp/pixelformatadapters.hxx @@ -0,0 +1,116 @@ +/************************************************************************* + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: pixelformatadapters.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: thb $ $Date: 2006-07-11 11:38:55 $ + * + * The Contents of this file are made available subject to + * the terms of GNU Lesser General Public License Version 2.1. + * + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2005 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + ************************************************************************/ + +#ifndef INCLUDED_BASEBMP_PIXELFORMATADAPTERS_HXX +#define INCLUDED_BASEBMP_PIXELFORMATADAPTERS_HXX + +#include <basebmp/accessortraits.hxx> +#include <basebmp/accessoradapters.hxx> + +#include <vigra/metaprogramming.hxx> + +namespace basebmp +{ + +// convenience functionality, providing everything necessary for a new +// pixel format. simply plug in two conversion functors from/to a +// common color format. + +/** Accessor selection metafunction, used to wrap a given accessor + with one converting between the pixel and color types + + Use the nested template's typedef type, to retrieve an + AccessorAdapter which operates on a pixel value accessor, and + provides color values to the outside. + + Nested like this, to avoid template template parameters at other + places: an instantiated version of AccessorSelector can be passed + to other templates, which in turn can invoke the nested meta + function. + */ +template< typename Getter, + typename Setter > struct AccessorSelector +{ + template< typename Accessor > struct wrap_accessor + { + typedef UnaryFunctionAccessorAdapter< Accessor, + Getter, + Setter > type; + }; +}; + +//----------------------------------------------------------------------------- + +/** Convert color value to pixel data type + */ +template< class Accessor, typename DataType > struct ColorConvert +{ + DataType operator()( const Accessor& acc, + typename Accessor::value_type v ) const + { + return acc.setter(v); + } +}; + +//----------------------------------------------------------------------------- + +/** Macro generates partial specialization for color-conversion + UnaryFunctionAccessorAdapter, and the given getter/setter functors + */ +#define BASEBMP_SPECIALIZE_ACCESSORTRAITS(Getter,Setter) \ +template< class Accessor > struct AccessorTraits< \ + UnaryFunctionAccessorAdapter< Accessor, \ + Getter, \ + Setter > > \ +{ \ + typedef typename Accessor::value_type data_type; \ + typedef UnaryFunctionAccessorAdapter< \ + Accessor, \ + Getter, \ + Setter > accessor_type; \ + typedef typename accessor_type::value_type value_type; \ + typedef ColorConvert< accessor_type, \ + data_type > color_lookup; \ + typedef Accessor raw_accessor; \ + typedef vigra::VigraFalseType xor_accessor; \ + template< class MaskAccessor, \ + class Iterator, \ + class MaskIterator > struct masked_accessor\ + { typedef vigra::VigraFalseType type; }; \ +} + +} // namespace basebmp + +#endif /* INCLUDED_BASEBMP_PIXELFORMATADAPTERS_HXX */ diff --git a/basebmp/inc/basebmp/rgb24pixelformats.hxx b/basebmp/inc/basebmp/rgb24pixelformats.hxx new file mode 100644 index 000000000000..08464be0197f --- /dev/null +++ b/basebmp/inc/basebmp/rgb24pixelformats.hxx @@ -0,0 +1,106 @@ +/************************************************************************* + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: rgb24pixelformats.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: thb $ $Date: 2006-07-11 11:38:55 $ + * + * The Contents of this file are made available subject to + * the terms of GNU Lesser General Public License Version 2.1. + * + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2005 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + ************************************************************************/ + +#ifndef INCLUDED_BASEBMP_RGB24PIXELFORMATS_HXX +#define INCLUDED_BASEBMP_RGB24PIXELFORMATS_HXX + +#include <basebmp/color.hxx> +#include <basebmp/accessor.hxx> +#include <basebmp/pixeliterator.hxx> +#include <basebmp/pixelformatadapters.hxx> + +#include <vigra/rgbvalue.hxx> + +#include <functional> + +namespace basebmp +{ + +template< typename PixelType, typename ColorType > struct RGBValueGetter : + public std::unary_function<PixelType, ColorType> +{ + ColorType operator()( PixelType const& c ) const + { + return ColorType(c.red(),c.green(),c.blue()); + } +}; + +template< typename PixelType, typename ColorType > struct RGBValueSetter : + public std::unary_function<ColorType, PixelType> +{ + PixelType operator()( ColorType const& c ) const + { + PixelType res; + res.setRed(c.getRed()); + res.setGreen(c.getGreen()); + res.setBlue(c.getBlue()); + return res; + } +}; + +//----------------------------------------------------------------------------- + +template< typename PixelType > struct PixelFormatTraitsTemplate_RGBValue +{ + typedef PixelType pixel_type; + + typedef RGBValueGetter<pixel_type, + Color> getter_type; + typedef RGBValueSetter<pixel_type, + Color> setter_type; + + typedef PixelIterator<pixel_type> iterator_type; + typedef StandardAccessor<pixel_type> raw_accessor_type; + typedef AccessorSelector< + getter_type, setter_type> accessor_selector; +}; + +//----------------------------------------------------------------------------- + +// 24bpp RGB +typedef PixelFormatTraitsTemplate_RGBValue< + vigra::RGBValue<sal_uInt8> > PixelFormatTraits_RGB24; +BASEBMP_SPECIALIZE_ACCESSORTRAITS(PixelFormatTraits_RGB24::getter_type, + PixelFormatTraits_RGB24::setter_type); + +// 24bpp BGR +typedef PixelFormatTraitsTemplate_RGBValue< + vigra::RGBValue<sal_uInt8,2,1,0> > PixelFormatTraits_BGR24; +BASEBMP_SPECIALIZE_ACCESSORTRAITS(PixelFormatTraits_BGR24::getter_type, + PixelFormatTraits_BGR24::setter_type); + +} // namespace basebmp + +#endif /* INCLUDED_BASEBMP_RGB24PIXELFORMATS_HXX */ diff --git a/basebmp/inc/basebmp/rgbmaskpixelformats.hxx b/basebmp/inc/basebmp/rgbmaskpixelformats.hxx new file mode 100644 index 000000000000..e0a12e211ddf --- /dev/null +++ b/basebmp/inc/basebmp/rgbmaskpixelformats.hxx @@ -0,0 +1,285 @@ +/************************************************************************* + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: rgbmaskpixelformats.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: thb $ $Date: 2006-07-11 11:38:55 $ + * + * The Contents of this file are made available subject to + * the terms of GNU Lesser General Public License Version 2.1. + * + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2005 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + ************************************************************************/ + +#ifndef INCLUDED_BASEBMP_RGBMASKPIXELFORMATS_HXX +#define INCLUDED_BASEBMP_RGBMASKPIXELFORMATS_HXX + +#include <basebmp/color.hxx> +#include <basebmp/colortraits.hxx> +#include <basebmp/accessor.hxx> +#include <basebmp/pixeliterator.hxx> +#include <basebmp/pixelformatadapters.hxx> +#include <basebmp/metafunctions.hxx> +#include <basebmp/endian.hxx> + +#include <vigra/numerictraits.hxx> +#include <vigra/metaprogramming.hxx> + +#include <functional> + +namespace basebmp +{ + +/** Base class operating on RGB truecolor mask pixel + + Use this template, if you have an (integer) pixel type, and three + bitmasks denoting where the channel bits are. + + @tpl PixelType + Input pixel type to operate on + + @tpl ColorType + Underlying color type, to convert the pixel values into + + @tpl RedMask + Bitmask, to access the red bits in the data type + + @tpl GreenMask + Bitmask, to access the green bits in the data type + + @tpl BlueMask + Bitmask, to access the blue bits in the data type + + @tpl SwapBytes + When true, the final pixel values will be byte-swapped before + passed on. + */ +template< typename PixelType, + typename ColorType, + int RedMask, + int GreenMask, + int BlueMask, + bool SwapBytes > struct RGBMaskFunctorBase +{ + typedef PixelType pixel_type; + typedef ColorType color_type; + typedef typename make_unsigned<pixel_type>::type unsigned_pixel_type; + typedef typename ColorTraits<ColorType>::component_type component_type; + + // calc corrective shifts for all three channels in advance + enum { + red_shift = numberOfTrailingZeros<RedMask>::value, + green_shift = numberOfTrailingZeros<GreenMask>::value, + blue_shift = numberOfTrailingZeros<BlueMask>::value, + + red_bits = bitcount<RedMask>::value, + green_bits = bitcount<GreenMask>::value, + blue_bits = bitcount<BlueMask>::value + }; +}; + +template< typename PixelType, + typename ColorType, + int RedMask, + int GreenMask, + int BlueMask, + bool SwapBytes > struct RGBMaskGetter : + public RGBMaskFunctorBase<PixelType, + ColorType, + RedMask, + GreenMask, + BlueMask, + SwapBytes>, + public std::unary_function<PixelType, ColorType> +{ + typedef RGBMaskFunctorBase<PixelType, + ColorType, + RedMask, + GreenMask, + BlueMask, + SwapBytes> base_type; + + ColorType operator()( PixelType v ) const + { + v = SwapBytes ? byteSwap(v) : v; + + const typename base_type::unsigned_pixel_type red (v & RedMask); + const typename base_type::unsigned_pixel_type green(v & GreenMask); + const typename base_type::unsigned_pixel_type blue (v & BlueMask); + + ColorType res( (shiftRight(red, + base_type::red_shift-8* + sizeof(typename base_type::component_type)+ + base_type::red_bits)) | + (shiftRight(red, + base_type::red_shift-8* + sizeof(typename base_type::component_type)+ + 2*base_type::red_bits)), + + (shiftRight(green, + base_type::green_shift-8* + sizeof(typename base_type::component_type)+ + base_type::green_bits)) | + (shiftRight(green, + base_type::green_shift-8* + sizeof(typename base_type::component_type)+ + 2*base_type::green_bits)), + + (shiftRight(blue, + base_type::blue_shift-8* + sizeof(typename base_type::component_type)+ + base_type::blue_bits)) | + (shiftRight(blue, + base_type::blue_shift-8* + sizeof(typename base_type::component_type)+ + 2*base_type::blue_bits)) ); + return res; + } +}; + +template< typename PixelType, + typename ColorType, + int RedMask, + int GreenMask, + int BlueMask, + bool SwapBytes > struct RGBMaskSetter : + public RGBMaskFunctorBase<PixelType, + ColorType, + RedMask, + GreenMask, + BlueMask, + SwapBytes>, + public std::unary_function<ColorType, PixelType> +{ + typedef RGBMaskFunctorBase<PixelType, + ColorType, + RedMask, + GreenMask, + BlueMask, + SwapBytes> base_type; + + PixelType operator()( ColorType const& c ) const + { + const typename base_type::unsigned_pixel_type red (c.getRed()); + const typename base_type::unsigned_pixel_type green(c.getGreen()); + const typename base_type::unsigned_pixel_type blue (c.getBlue()); + + typename base_type::unsigned_pixel_type res( + (shiftLeft(red, + base_type::red_shift-8* + sizeof(typename base_type::component_type)+ + base_type::red_bits) & RedMask) | + (shiftLeft(green, + base_type::green_shift-8* + sizeof(typename base_type::component_type)+ + base_type::green_bits) & GreenMask) | + (shiftLeft(blue, + base_type::blue_shift-8* + sizeof(typename base_type::component_type)+ + base_type::blue_bits) & BlueMask) ); + + return SwapBytes ? byteSwap(res) : res; + } +}; + +//----------------------------------------------------------------------------- + +template< typename PixelType, + int RedMask, + int GreenMask, + int BlueMask, + bool SwapBytes > struct PixelFormatTraitsTemplate_RGBMask +{ + typedef PixelType pixel_type; + + typedef RGBMaskGetter<pixel_type, + Color, + RedMask, + GreenMask, + BlueMask, + SwapBytes> getter_type; + typedef RGBMaskSetter<pixel_type, + Color, + RedMask, + GreenMask, + BlueMask, + SwapBytes> setter_type; + + typedef PixelIterator<pixel_type> iterator_type; + typedef StandardAccessor<pixel_type> raw_accessor_type; + typedef AccessorSelector< + getter_type, setter_type> accessor_selector; +}; + +//----------------------------------------------------------------------------- + +#ifdef OSL_LITENDIAN +# define BASEBMP_TRUECOLORMASK_LSB_SWAP false +# define BASEBMP_TRUECOLORMASK_MSB_SWAP true +#else +# ifdef OSL_BIGENDIAN +# define BASEBMP_TRUECOLORMASK_LSB_SWAP true +# define BASEBMP_TRUECOLORMASK_MSB_SWAP false +# else +# error Undetermined endianness! +# endif +#endif + +//----------------------------------------------------------------------------- + +// 16bpp MSB RGB +typedef PixelFormatTraitsTemplate_RGBMask< + sal_uInt16, + 0xF800, + 0x07E0, + 0x001F, + BASEBMP_TRUECOLORMASK_MSB_SWAP > PixelFormatTraits_RGB16_565_MSB; +BASEBMP_SPECIALIZE_ACCESSORTRAITS(PixelFormatTraits_RGB16_565_MSB::getter_type, + PixelFormatTraits_RGB16_565_MSB::setter_type); + +// 16bpp LSB RGB +typedef PixelFormatTraitsTemplate_RGBMask< + sal_uInt16, + 0xF800, + 0x07E0, + 0x001F, + BASEBMP_TRUECOLORMASK_LSB_SWAP > PixelFormatTraits_RGB16_565_LSB; +BASEBMP_SPECIALIZE_ACCESSORTRAITS(PixelFormatTraits_RGB16_565_LSB::getter_type, + PixelFormatTraits_RGB16_565_LSB::setter_type); + +// 32bpp endian-sensitive RGB +typedef PixelFormatTraitsTemplate_RGBMask< + sal_uInt32, + 0xFF0000, + 0x00FF00, + 0x0000FF, + false > PixelFormatTraits_RGB32_888; +BASEBMP_SPECIALIZE_ACCESSORTRAITS(PixelFormatTraits_RGB32_888::getter_type, + PixelFormatTraits_RGB32_888::setter_type); + + +} // namespace basebmp + +#endif /* INCLUDED_BASEBMP_RGBMASKPIXELFORMATS_HXX */ diff --git a/basebmp/inc/basebmp/scanlineformats.hxx b/basebmp/inc/basebmp/scanlineformats.hxx index 6e25b565c28a..852eccac09dc 100644 --- a/basebmp/inc/basebmp/scanlineformats.hxx +++ b/basebmp/inc/basebmp/scanlineformats.hxx @@ -2,9 +2,9 @@ * * $RCSfile: scanlineformats.hxx,v $ * - * $Revision: 1.6 $ + * $Revision: 1.7 $ * - * last change: $Author: thb $ $Date: 2006-07-06 10:00:40 $ + * last change: $Author: thb $ $Date: 2006-07-11 11:38:55 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -71,16 +71,16 @@ namespace basebmp { namespace Format { static const sal_Int32 NONE = 0; - static const sal_Int32 ONE_BIT_MSB_GRAY = (sal_Int32)0x01; - static const sal_Int32 ONE_BIT_LSB_GRAY = (sal_Int32)0x02; + static const sal_Int32 ONE_BIT_MSB_GREY = (sal_Int32)0x01; + static const sal_Int32 ONE_BIT_LSB_GREY = (sal_Int32)0x02; static const sal_Int32 ONE_BIT_MSB_PAL = (sal_Int32)0x03; static const sal_Int32 ONE_BIT_LSB_PAL = (sal_Int32)0x04; - static const sal_Int32 FOUR_BIT_MSB_GRAY = (sal_Int32)0x05; - static const sal_Int32 FOUR_BIT_LSB_GRAY = (sal_Int32)0x06; + static const sal_Int32 FOUR_BIT_MSB_GREY = (sal_Int32)0x05; + static const sal_Int32 FOUR_BIT_LSB_GREY = (sal_Int32)0x06; static const sal_Int32 FOUR_BIT_MSB_PAL = (sal_Int32)0x07; static const sal_Int32 FOUR_BIT_LSB_PAL = (sal_Int32)0x08; static const sal_Int32 EIGHT_BIT_PAL = (sal_Int32)0x09; - static const sal_Int32 EIGHT_BIT_GRAY = (sal_Int32)0x0A; + static const sal_Int32 EIGHT_BIT_GREY = (sal_Int32)0x0A; static const sal_Int32 SIXTEEN_BIT_LSB_TC_MASK= (sal_Int32)0x0B; static const sal_Int32 SIXTEEN_BIT_MSB_TC_MASK= (sal_Int32)0x0C; static const sal_Int32 TWENTYFOUR_BIT_TC_MASK = (sal_Int32)0x0D; diff --git a/basebmp/source/bitmapdevice.cxx b/basebmp/source/bitmapdevice.cxx index 03e73525918c..29cf048b03ed 100644 --- a/basebmp/source/bitmapdevice.cxx +++ b/basebmp/source/bitmapdevice.cxx @@ -4,9 +4,9 @@ * * $RCSfile: bitmapdevice.cxx,v $ * - * $Revision: 1.16 $ + * $Revision: 1.17 $ * - * last change: $Author: thb $ $Date: 2006-07-06 10:00:40 $ + * last change: $Author: thb $ $Date: 2006-07-11 11:38:56 $ * * The Contents of this file are made available subject to * the terms of GNU Lesser General Public License Version 2.1. @@ -35,8 +35,6 @@ #include "basebmp/bitmapdevice.hxx" -#include "basebmp/pixeliterator.hxx" -#include "basebmp/packedpixeliterator.hxx" #include "basebmp/compositeiterator.hxx" #include "basebmp/iteratortraits.hxx" @@ -44,15 +42,22 @@ #include "basebmp/accessortraits.hxx" #include "basebmp/accessoradapters.hxx" #include "basebmp/colorblendaccessoradapter.hxx" -#include "basebmp/paletteimageaccessor.hxx" -#include "basebmp/truecolormaskaccessor.hxx" #include "basebmp/color.hxx" #include "basebmp/colormisc.hxx" #include "basebmp/colortraits.hxx" +#include "basebmp/greylevelformats.hxx" +#include "basebmp/paletteformats.hxx" +#include "basebmp/rgbmaskpixelformats.hxx" +#include "basebmp/rgb24pixelformats.hxx" + #include "basebmp/scanlineformats.hxx" +#include "basebmp/fillimage.hxx" #include "basebmp/clippedlinerenderer.hxx" +//#include "basebmp/genericintegerimageaccessor.hxx" + +#include "intconversion.hxx" #include <rtl/alloc.h> #include <rtl/memory.h> @@ -69,6 +74,7 @@ #include <basegfx/point/b2ipoint.hxx> #include <basegfx/vector/b2ivector.hxx> +#include <vigra/iteratortraits.hxx> #include <vigra/rgbvalue.hxx> #include <vigra/resizeimage.hxx> #include <vigra/copyimage.hxx> @@ -97,157 +103,44 @@ namespace basebmp namespace { - // Common accessor and iterator types - //------------------------------------------------------------------------ + // xxx TODO - typedef PackedPixelIterator< sal_uInt8, - 1, - true > MaskIterator; - typedef NonStandardAccessor< sal_uInt8 > MaskAccessor; + // TEMP TEMP TEMP - typedef PixelIterator< sal_uInt8 > AlphaMaskIterator; - typedef StandardAccessor< sal_uInt8 > AlphaMaskAccessor; - - template< class Accessor > struct PaletteAccessorSelector + class GenericImageAccessor { - typedef PaletteImageAccessor< Accessor, Color > type; - }; - - typedef vigra::RGBValue<sal_uInt8> TwentyFourBitPixelRGB; - typedef vigra::RGBValue<sal_uInt8,2,1,0> TwentyFourBitPixelBGR; - - - // metafunctions to retrieve correct POD from/to basebmp::Color - //------------------------------------------------------------------------ - - /// type-safe conversion between color and pod - template< typename DataType > struct GreyScaleFromColor - { - typedef DataType value_type; - DataType operator()( Color c ) { return c.getGrayscale(); } - }; - - /// type-safe conversion between color and RgbValue - template< class RgbVal > struct RgbValueFromColor - { - RgbVal operator()( Color c ) - { - RgbVal res; - res.setRed(c.getRed()); - res.setGreen(c.getGreen()); - res.setBlue(c.getBlue()); - return res; - } - }; - - /// type-safe conversion between pod and color - template< typename DataType > struct ColorFromGreyScale - { - typedef DataType value_type; - Color operator()( DataType c ) { return Color(c,c,c); } - }; - - /// type-safe conversion between RgbValue and color - template< class RgbVal > struct ColorFromRgbValue - { - Color operator()( RgbVal const& c ) - { - return Color(c.red(),c.green(),c.blue()); - } - }; + public: + typedef Color value_type; + BitmapDeviceSharedPtr mpDevice; - /// type-safe conversion from Color to packed int32 - struct UInt32FromColor - { - sal_uInt32 operator()( const Color& c ) { return c.toInt32(); } - }; + explicit GenericImageAccessor( BitmapDeviceSharedPtr const& rTarget ) : + mpDevice(rTarget) + {} - /// type-safe conversion from RgbValue to packed int32 - template< class RgbVal > struct UInt32FromRgbValue - { - sal_uInt32 operator()( RgbVal const& c ) - { - return (c[0] << 16) | (c[1] << 8) | c[2]; - } + template< typename Iterator > + Color operator()( Iterator const& i ) const + { return mpDevice->getPixel( basegfx::B2IPoint( i->x,i->y ) ); } + + template< typename Iterator, typename Difference > + Color operator()( Iterator const& i, Difference const& diff) const + { return mpDevice->getPixel( basegfx::B2IPoint( i[diff]->x, + i[diff]->y ) ); } + + template< typename Iterator > + void set(Color const& value, Iterator const& i) const + { return mpDevice->setPixel( basegfx::B2IPoint( i->x,i->y ), + value, DrawMode_PAINT ); } + + template< class Iterator, class Difference > + void set(value_type const& value, Iterator const& i, Difference const& diff) const + { return mpDevice->setPixel( basegfx::B2IPoint( i[diff]->x, + i[diff]->y ), + value, DrawMode_PAINT ); } }; - /// Get converter from color to given data type - template< typename DataType > struct fromColorConverter; - template<> struct fromColorConverter< sal_uInt8 > - { - typedef GreyScaleFromColor<sal_uInt8> type; - }; - template<> struct fromColorConverter< Color > - { - typedef std::identity<Color> type; - }; - template< unsigned int RedIndex, - unsigned int GreenIndex, - unsigned int BlueIndex > struct fromColorConverter< - vigra::RGBValue< sal_uInt8, - RedIndex, - GreenIndex, - BlueIndex > > - { - typedef RgbValueFromColor< - vigra::RGBValue< sal_uInt8, - RedIndex, - GreenIndex, - BlueIndex > > - type; - }; - /// Get converter from given data type to Color - template< typename DataType > struct toColorConverter; - template<> struct toColorConverter< sal_uInt8 > - { - typedef ColorFromGreyScale<sal_uInt8> type; - }; - template<> struct toColorConverter< Color > - { - typedef std::identity<Color> type; - }; - template< unsigned int RedIndex, - unsigned int GreenIndex, - unsigned int BlueIndex > struct toColorConverter< - vigra::RGBValue< sal_uInt8, - RedIndex, - GreenIndex, - BlueIndex > > - { - typedef ColorFromRgbValue< - vigra::RGBValue< sal_uInt8, - RedIndex, - GreenIndex, - BlueIndex > > - type; - }; - /// Get converter from given data type to sal_uInt32 - template< typename DataType > struct toUInt32Converter - { - typedef std::identity<DataType> type; - }; - template<> struct toUInt32Converter< Color > - { - typedef UInt32FromColor type; - }; - template< unsigned int RedIndex, - unsigned int GreenIndex, - unsigned int BlueIndex > struct toUInt32Converter< - vigra::RGBValue< sal_uInt8, - RedIndex, - GreenIndex, - BlueIndex > > - { - typedef UInt32FromRgbValue< - vigra::RGBValue< sal_uInt8, - RedIndex, - GreenIndex, - BlueIndex > > - type; - }; // Polygon scanline conversion @@ -301,8 +194,10 @@ namespace basegfx::fround( rfXRight )))); DestIterator currIter( begin_ + vigra::Diff2D(0,nY) ); - typename DestIterator::row_iterator rowIter( currIter.rowIterator() + nStartX); - typename DestIterator::row_iterator rowEnd( currIter.rowIterator() + nEndX ); + typename vigra::IteratorTraits<DestIterator>::row_iterator + rowIter( currIter.rowIterator() + nStartX); + typename vigra::IteratorTraits<DestIterator>::row_iterator + rowEnd( currIter.rowIterator() + nEndX ); // TODO(P2): Provide specialized span fill methods on the // iterator/accessor @@ -316,19 +211,15 @@ namespace const basegfx::B2DPolyPolygon& rPolyPolyRaster, typename DestAccessor::value_type fillColor, const basegfx::B2IRange& outRange, - vigra::triple<DestIterator, DestIterator, DestAccessor> dest ) + const DestIterator& begin, + const DestAccessor& acc ) { - basegfx::B2IRange aBmpRange(0,0, - dest.second.x - dest.first.x, - dest.second.y - dest.first.y ); - aBmpRange.intersect( outRange ); - return std::auto_ptr< Renderer< DestIterator, DestAccessor > >( new Renderer< DestIterator, DestAccessor >(rPolyPolyRaster, fillColor, - aBmpRange, - dest.first, - dest.third)); + outRange, + begin, + acc)); } @@ -343,33 +234,37 @@ namespace @tpl RawAccessor Raw accessor, to access pixel values directly - @tpl VanillaAccessorSelector - Accessor adapter selector, which, when applied to one of the - raw bitmap accessors, yields a member type named 'type', which - is a wrapped accessor that map color values. + @tpl AccessorSelector + Accessor adapter selector, which, when applying the nested + template metafunction wrap_accessor to one of the raw bitmap + accessors, yields a member type named 'type', which is a + wrapped accessor that map color values. */ - template< class DestIterator, - class RawAccessor, - template< typename > class VanillaAccessorSelector > class BitmapRenderer : + template< class DestIterator, + class RawAccessor, + class AccessorSelector, + class Masks > class BitmapRenderer : public BitmapDevice { public: - typedef BitmapRenderer<MaskIterator, - MaskAccessor, - boost::mpl::identity> MaskBitmap; - typedef BitmapRenderer<AlphaMaskIterator, - AlphaMaskAccessor, - boost::mpl::identity> AlphaMaskBitmap; + typedef BitmapRenderer<typename Masks::clipmask_format_traits::iterator_type, + typename Masks::clipmask_format_traits::raw_accessor_type, + typename Masks::clipmask_format_traits::accessor_selector, + Masks> MaskBitmap; + typedef BitmapRenderer<typename Masks::alphamask_format_traits::iterator_type, + typename Masks::alphamask_format_traits::raw_accessor_type, + typename Masks::alphamask_format_traits::accessor_selector, + Masks> AlphaMaskBitmap; // ------------------------------------------------------- typedef AccessorTraits< RawAccessor > RawAccessorTraits; - typedef typename toUInt32Converter< - typename RawAccessor::value_type>::type ToUInt32Functor; + typedef typename uInt32Converter< + typename RawAccessor::value_type>::to ToUInt32Functor; // ------------------------------------------------------- - typedef typename VanillaAccessorSelector< + typedef typename AccessorSelector::template wrap_accessor< RawAccessor >::type DestAccessor; typedef AccessorTraits< DestAccessor > AccTraits; @@ -377,55 +272,50 @@ namespace typedef typename RawAccessorTraits::xor_accessor RawXorAccessor; typedef AccessorTraits<RawXorAccessor> RawXorAccessorTraits; - typedef typename VanillaAccessorSelector< + typedef typename AccessorSelector::template wrap_accessor< RawXorAccessor >::type XorAccessor; typedef AccessorTraits<XorAccessor> XorAccessorTraits; // ------------------------------------------------------- typedef typename RawAccessorTraits::template masked_accessor< - MaskAccessor, - DestIterator, - MaskIterator>::type RawMaskedAccessor; - typedef typename VanillaAccessorSelector< + typename Masks::clipmask_format_traits::raw_accessor_type, + DestIterator, + typename Masks::clipmask_format_traits::iterator_type>::type + RawMaskedAccessor; + typedef typename AccessorSelector::template wrap_accessor< RawMaskedAccessor >::type MaskedAccessor; typedef typename RawXorAccessorTraits::template masked_accessor< - MaskAccessor, - DestIterator, - MaskIterator>::type RawMaskedXorAccessor; - typedef typename VanillaAccessorSelector< + typename Masks::clipmask_format_traits::raw_accessor_type, + DestIterator, + typename Masks::clipmask_format_traits::iterator_type>::type + RawMaskedXorAccessor; + typedef typename AccessorSelector::template wrap_accessor< RawMaskedXorAccessor >::type MaskedXorAccessor; // ------------------------------------------------------- typedef ConstantColorBlendSetterAccessorAdapter< DestAccessor, - typename AlphaMaskAccessor::value_type> ColorBlendAccessor; + typename Masks::alphamask_format_traits::raw_accessor_type::value_type> + ColorBlendAccessor; typedef AccessorTraits<ColorBlendAccessor> BlendAccessorTraits; typedef typename BlendAccessorTraits::template masked_accessor< - MaskAccessor, - DestIterator, - MaskIterator>::type MaskedColorBlendAcc; - - // ------------------------------------------------------- - - typedef typename fromColorConverter< - typename AccTraits::value_type>::type FromColorFunctor; - typedef typename toColorConverter< - typename AccTraits::value_type>::type ToColorFunctor; + typename Masks::clipmask_format_traits::raw_accessor_type, + DestIterator, + typename Masks::clipmask_format_traits::iterator_type>::type + MaskedColorBlendAcc; // ------------------------------------------------------- - typedef DestIterator dest_iterator; - typedef DestAccessor dest_accessor; - typedef CompositeIterator2D< DestIterator, - MaskIterator > composite_iterator_type; + typedef DestIterator dest_iterator; + typedef DestAccessor dest_accessor; + typedef CompositeIterator2D< + DestIterator, + typename Masks::clipmask_format_traits::iterator_type> composite_iterator_type; DestIterator maBegin; - DestIterator maEnd; typename AccTraits::color_lookup maColorLookup; - FromColorFunctor maFromColorConverter; - ToColorFunctor maToColorConverter; ToUInt32Functor maToUInt32Converter; DestAccessor maAccessor; ColorBlendAccessor maColorBlendAccessor; @@ -437,24 +327,20 @@ namespace MaskedXorAccessor maMaskedXorAccessor; RawMaskedAccessor maRawMaskedAccessor; RawMaskedXorAccessor maRawMaskedXorAccessor; - int mnWidth; - int mnHeight; - BitmapRenderer( const basegfx::B2IVector& rSize, + BitmapRenderer( const basegfx::B2IRange& rBounds, bool bTopDown, sal_Int32 nScanlineFormat, sal_Int32 nScanlineStride, + sal_uInt8* pFirstScanline, DestIterator begin, - DestIterator end, DestAccessor accessor, const RawMemorySharedArray& rMem, const PaletteMemorySharedVector& rPalette ) : - BitmapDevice( rSize, bTopDown, nScanlineFormat, nScanlineStride, rMem, rPalette ), + BitmapDevice( rBounds, bTopDown, nScanlineFormat, + nScanlineStride, pFirstScanline, rMem, rPalette ), maBegin( begin ), - maEnd( end ), maColorLookup(), - maFromColorConverter(), - maToColorConverter(), maToUInt32Converter(), maAccessor( accessor ), maColorBlendAccessor( accessor ), @@ -465,9 +351,7 @@ namespace maMaskedColorBlendAccessor( maColorBlendAccessor ), maMaskedXorAccessor( accessor ), maRawMaskedAccessor(), - maRawMaskedXorAccessor(), - mnWidth( maEnd.x - maBegin.x ), - mnHeight( maEnd.y - maBegin.y ) + maRawMaskedXorAccessor() {} private: @@ -515,47 +399,36 @@ namespace return getCompatibleAlphaMask( bmp ).get() != NULL; } - virtual void clear_i( Color fillColor ) + virtual void clear_i( Color fillColor, + const basegfx::B2IRange& rBounds ) { - const typename dest_iterator::value_type colorIndex( maColorLookup( - maAccessor, - maFromColorConverter( - fillColor))); - DestIterator currIter( maBegin ); - const DestIterator endIter ( maBegin + vigra::Diff2D(0,mnHeight) ); - while( currIter != endIter ) - { - typename DestIterator::row_iterator rowIter( currIter.rowIterator() ); - const typename DestIterator::row_iterator rowEnd( rowIter + mnWidth ); - - // TODO(P2): Provide specialized span fill methods on the - // iterator/accessor - while( rowIter != rowEnd ) - maRawAccessor.set(colorIndex, rowIter++); - - ++currIter.y; - } + fillImage(maBegin + vigra::Diff2D(rBounds.getMinX(), + rBounds.getMinY()), + maBegin + vigra::Diff2D(rBounds.getMaxX(), + rBounds.getMaxY()), + maRawAccessor, + maColorLookup( + maAccessor, + fillColor) ); } virtual void setPixel_i( const basegfx::B2IPoint& rPt, - Color lineColor, + Color pixelColor, DrawMode drawMode ) { const DestIterator pixel( maBegin + vigra::Diff2D(rPt.getX(), rPt.getY()) ); if( drawMode == DrawMode_XOR ) - maXorAccessor.set( maFromColorConverter( - lineColor), + maXorAccessor.set( pixelColor, pixel ); else - maAccessor.set( maFromColorConverter( - lineColor), + maAccessor.set( pixelColor, pixel ); } virtual void setPixel_i( const basegfx::B2IPoint& rPt, - Color lineColor, + Color pixelColor, DrawMode drawMode, const BitmapDeviceSharedPtr& rClip ) { @@ -570,12 +443,10 @@ namespace pMask->maBegin + offset ); if( drawMode == DrawMode_XOR ) - maMaskedXorAccessor.set( maFromColorConverter( - lineColor), + maMaskedXorAccessor.set( pixelColor, aIter ); else - maMaskedAccessor.set( maFromColorConverter( - lineColor), + maMaskedAccessor.set( pixelColor, aIter ); } @@ -584,7 +455,7 @@ namespace const DestIterator pixel( maBegin + vigra::Diff2D(rPt.getX(), rPt.getY()) ); - return maToColorConverter(maAccessor(pixel)); + return maAccessor(pixel); } virtual sal_uInt32 getPixelData_i( const basegfx::B2IPoint& rPt ) @@ -595,55 +466,54 @@ namespace return maToUInt32Converter(maRawAccessor(pixel)); } - template< typename Range, typename Col, typename RawAcc > + template< typename Iterator, typename Col, typename RawAcc > void implRenderLine2( const basegfx::B2IPoint& rPt1, const basegfx::B2IPoint& rPt2, const basegfx::B2IRange& rBounds, Col col, - const Range& range, + const Iterator& begin, const RawAcc& rawAcc ) { renderClippedLine( rPt1, rPt2, rBounds, col, - range.first, + begin, rawAcc ); } - template< typename Range, typename Accessor, typename RawAcc > + template< typename Iterator, typename Accessor, typename RawAcc > void implRenderLine( const basegfx::B2IPoint& rPt1, const basegfx::B2IPoint& rPt2, const basegfx::B2IRange& rBounds, Color col, - const Range& range, + const Iterator& begin, const Accessor& acc, const RawAcc& rawAcc ) { implRenderLine2( rPt1,rPt2,rBounds, maColorLookup( acc, - maFromColorConverter( - col)), - range, + col ), + begin, rawAcc ); } - template< typename Range, typename RawAcc, typename XorAcc > + template< typename Iterator, typename RawAcc, typename XorAcc > void implDrawLine( const basegfx::B2IPoint& rPt1, const basegfx::B2IPoint& rPt2, const basegfx::B2IRange& rBounds, Color col, - const Range& range, + const Iterator& begin, const RawAcc& rawAcc, const XorAcc& xorAcc, DrawMode drawMode ) { if( drawMode == DrawMode_XOR ) implRenderLine( rPt1, rPt2, rBounds, col, - range, maAccessor, xorAcc ); + begin, maAccessor, xorAcc ); else implRenderLine( rPt1, rPt2, rBounds, col, - range, maAccessor, rawAcc ); + begin, maAccessor, rawAcc ); } virtual void drawLine_i(const basegfx::B2IPoint& rPt1, @@ -653,23 +523,17 @@ namespace DrawMode drawMode ) { implDrawLine(rPt1,rPt2,rBounds,lineColor, - std::make_pair(maBegin,maEnd), + maBegin, maRawAccessor,maRawXorAccessor,drawMode); } - vigra::pair<composite_iterator_type,composite_iterator_type> - getMaskedRange( const BitmapDeviceSharedPtr& rClip ) const + composite_iterator_type getMaskedIter( const BitmapDeviceSharedPtr& rClip ) const { boost::shared_ptr<MaskBitmap> pMask( getCompatibleClipMask(rClip) ); OSL_ASSERT( pMask ); - return std::make_pair( - composite_iterator_type( - maBegin, - pMask->maBegin ), - composite_iterator_type( - maEnd, - pMask->maEnd )); + return composite_iterator_type( maBegin, + pMask->maBegin ); } virtual void drawLine_i(const basegfx::B2IPoint& rPt1, @@ -680,15 +544,16 @@ namespace const BitmapDeviceSharedPtr& rClip ) { implDrawLine(rPt1,rPt2,rBounds,lineColor, - getMaskedRange(rClip), - maRawMaskedAccessor,maRawMaskedXorAccessor,drawMode); + getMaskedIter(rClip), + maRawMaskedAccessor, + maRawMaskedXorAccessor,drawMode); } - template< typename Range, typename RawAcc > + template< typename Iterator, typename RawAcc > void implDrawPolygon( const basegfx::B2DPolygon& rPoly, const basegfx::B2IRange& rBounds, Color col, - const Range& range, + const Iterator& begin, const RawAcc& acc ) { basegfx::B2DPolygon aPoly( rPoly ); @@ -697,15 +562,14 @@ namespace const typename dest_iterator::value_type colorIndex( maColorLookup( maAccessor, - maFromColorConverter( - col))); + col)); const sal_uInt32 nVertices( aPoly.count() ); for( sal_uInt32 i=1; i<nVertices; ++i ) implRenderLine2( basegfx::fround(aPoly.getB2DPoint(i-1)), basegfx::fround(aPoly.getB2DPoint(i)), rBounds, colorIndex, - range, + begin, acc ); if( nVertices > 1 && aPoly.isClosed() ) @@ -713,7 +577,7 @@ namespace basegfx::fround(aPoly.getB2DPoint(0)), rBounds, colorIndex, - range, + begin, acc ); } @@ -724,13 +588,11 @@ namespace { if( drawMode == DrawMode_XOR ) implDrawPolygon( rPoly, rBounds, lineColor, - std::make_pair(maBegin, - maEnd), + maBegin, maRawXorAccessor ); else implDrawPolygon( rPoly, rBounds, lineColor, - std::make_pair(maBegin, - maEnd), + maBegin, maRawAccessor ); } @@ -742,18 +604,18 @@ namespace { if( drawMode == DrawMode_XOR ) implDrawPolygon( rPoly, rBounds, lineColor, - getMaskedRange(rClip), + getMaskedIter(rClip), maRawMaskedXorAccessor ); else implDrawPolygon( rPoly, rBounds, lineColor, - getMaskedRange(rClip), + getMaskedIter(rClip), maRawMaskedAccessor ); } - template< typename Range, typename RawAcc > + template< typename Iterator, typename RawAcc > void implFillPolyPolygon( const basegfx::B2DPolyPolygon& rPoly, Color col, - const Range& range, + const Iterator& begin, const RawAcc& acc, const basegfx::B2IRange& rBounds ) { @@ -763,14 +625,11 @@ namespace makeRenderer( aPoly, maColorLookup( maAccessor, - maFromColorConverter( - col)), + col), rBounds, - vigra::make_triple( - range.first, - range.second, - acc) )->rasterConvert( - basegfx::FillRule_NONZERO_WINDING_NUMBER ); + begin, + acc )->rasterConvert( + basegfx::FillRule_NONZERO_WINDING_NUMBER ); } virtual void fillPolyPolygon_i(const basegfx::B2DPolyPolygon& rPoly, @@ -780,12 +639,12 @@ namespace { if( drawMode == DrawMode_XOR ) implFillPolyPolygon( rPoly, fillColor, - std::make_pair(maBegin,maEnd), + maBegin, maRawXorAccessor, rBounds ); else implFillPolyPolygon( rPoly, fillColor, - std::make_pair(maBegin,maEnd), + maBegin, maRawAccessor, rBounds ); } @@ -798,21 +657,21 @@ namespace { if( drawMode == DrawMode_XOR ) implFillPolyPolygon( rPoly, fillColor, - getMaskedRange(rClip), + getMaskedIter(rClip), maRawMaskedXorAccessor, rBounds ); else implFillPolyPolygon( rPoly, fillColor, - getMaskedRange(rClip), + getMaskedIter(rClip), maRawMaskedAccessor, rBounds ); } - template< typename Range, typename RawAcc > + template< typename Iterator, typename RawAcc > void implDrawBitmap(const BitmapDeviceSharedPtr& rSrcBitmap, const basegfx::B2IRange& rSrcRect, const basegfx::B2IRange& rDstRect, - const Range& range, + const Iterator& begin, const RawAcc& acc) { boost::shared_ptr<BitmapRenderer> pSrcBmp( getCompatibleBitmap(rSrcBitmap) ); @@ -821,18 +680,41 @@ namespace // since resizeImageNoInterpolation() internally copyies // to a temporary buffer, also works with *this == rSrcBitmap vigra::resizeImageNoInterpolation( - vigra::make_triple( - pSrcBmp->maBegin + vigra::Diff2D(rSrcRect.getMinX(), - rSrcRect.getMinY()), - pSrcBmp->maBegin + vigra::Diff2D(rSrcRect.getMaxX(), - rSrcRect.getMaxY()), - pSrcBmp->maRawAccessor), - vigra::make_triple( - range.first + vigra::Diff2D(rDstRect.getMinX(), - rDstRect.getMinY()), - range.first + vigra::Diff2D(rDstRect.getMaxX(), - rDstRect.getMaxY()), - acc)); + pSrcBmp->maBegin + vigra::Diff2D(rSrcRect.getMinX(), + rSrcRect.getMinY()), + pSrcBmp->maBegin + vigra::Diff2D(rSrcRect.getMaxX(), + rSrcRect.getMaxY()), + pSrcBmp->maRawAccessor, + begin + vigra::Diff2D(rDstRect.getMinX(), + rDstRect.getMinY()), + begin + vigra::Diff2D(rDstRect.getMaxX(), + rDstRect.getMaxY()), + acc); + } + + // xxx TODO + template< typename Iterator, typename Acc > + void implDrawBitmapGeneric(const BitmapDeviceSharedPtr& rSrcBitmap, + const basegfx::B2IRange& rSrcRect, + const basegfx::B2IRange& rDstRect, + const Iterator& begin, + const Acc& acc) + { + GenericImageAccessor aSrcAcc( rSrcBitmap ); + + // since resizeImageNoInterpolation() internally copyies + // to a temporary buffer, also works with *this == rSrcBitmap + vigra::resizeImageNoInterpolation( + vigra::Diff2D(rSrcRect.getMinX(), + rSrcRect.getMinY()), + vigra::Diff2D(rSrcRect.getMaxX(), + rSrcRect.getMaxY()), + aSrcAcc, + begin + vigra::Diff2D(rDstRect.getMinX(), + rDstRect.getMinY()), + begin + vigra::Diff2D(rDstRect.getMaxX(), + rDstRect.getMaxY()), + acc); } virtual void drawBitmap_i(const BitmapDeviceSharedPtr& rSrcBitmap, @@ -840,14 +722,29 @@ namespace const basegfx::B2IRange& rDstRect, DrawMode drawMode ) { - if( drawMode == DrawMode_XOR ) - implDrawBitmap(rSrcBitmap, rSrcRect, rDstRect, - std::make_pair(maBegin,maEnd), - maRawXorAccessor); + // xxx TODO + if( isCompatibleBitmap( rSrcBitmap ) ) + { + if( drawMode == DrawMode_XOR ) + implDrawBitmap(rSrcBitmap, rSrcRect, rDstRect, + maBegin, + maRawXorAccessor); + else + implDrawBitmap(rSrcBitmap, rSrcRect, rDstRect, + maBegin, + maRawAccessor); + } else - implDrawBitmap(rSrcBitmap, rSrcRect, rDstRect, - std::make_pair(maBegin,maEnd), - maRawAccessor); + { + if( drawMode == DrawMode_XOR ) + implDrawBitmapGeneric(rSrcBitmap, rSrcRect, rDstRect, + maBegin, + maXorAccessor); + else + implDrawBitmapGeneric(rSrcBitmap, rSrcRect, rDstRect, + maBegin, + maAccessor); + } } virtual void drawBitmap_i(const BitmapDeviceSharedPtr& rSrcBitmap, @@ -856,14 +753,29 @@ namespace DrawMode drawMode, const BitmapDeviceSharedPtr& rClip ) { - if( drawMode == DrawMode_XOR ) - implDrawBitmap(rSrcBitmap, rSrcRect, rDstRect, - getMaskedRange(rClip), - maRawMaskedXorAccessor); + // xxx TODO + if( isCompatibleBitmap( rSrcBitmap ) ) + { + if( drawMode == DrawMode_XOR ) + implDrawBitmap(rSrcBitmap, rSrcRect, rDstRect, + getMaskedIter(rClip), + maRawMaskedXorAccessor); + else + implDrawBitmap(rSrcBitmap, rSrcRect, rDstRect, + getMaskedIter(rClip), + maRawMaskedAccessor); + } else - implDrawBitmap(rSrcBitmap, rSrcRect, rDstRect, - getMaskedRange(rClip), - maRawMaskedAccessor); + { + if( drawMode == DrawMode_XOR ) + implDrawBitmapGeneric(rSrcBitmap, rSrcRect, rDstRect, + getMaskedIter(rClip), + maMaskedXorAccessor); + else + implDrawBitmapGeneric(rSrcBitmap, rSrcRect, rDstRect, + getMaskedIter(rClip), + maMaskedAccessor); + } } virtual void drawMaskedColor_i(Color aSrcColor, @@ -871,18 +783,39 @@ namespace const basegfx::B2IRange& rSrcRect, const basegfx::B2IPoint& rDstPoint ) { + boost::shared_ptr<MaskBitmap> pMask( getCompatibleClipMask(rAlphaMask) ); boost::shared_ptr<AlphaMaskBitmap> pAlpha( getCompatibleAlphaMask(rAlphaMask) ); - OSL_ASSERT( pAlpha ); - maColorBlendAccessor.setColor( maFromColorConverter(aSrcColor) ); - - vigra::copyImage( pAlpha->maBegin + vigra::Diff2D(rSrcRect.getMinX(), - rSrcRect.getMinY()), - pAlpha->maBegin + vigra::Diff2D(rSrcRect.getMaxX(), - rSrcRect.getMaxY()), - pAlpha->maAccessor, - maBegin + vigra::Diff2D(rDstPoint.getX(), - rDstPoint.getY()), - maColorBlendAccessor ); + OSL_ASSERT( pAlpha || pMask ); + + if( pAlpha ) + { + maColorBlendAccessor.setColor( aSrcColor ); + + vigra::copyImage( pAlpha->maBegin + vigra::Diff2D(rSrcRect.getMinX(), + rSrcRect.getMinY()), + pAlpha->maBegin + vigra::Diff2D(rSrcRect.getMaxX(), + rSrcRect.getMaxY()), + pAlpha->maRawAccessor, + maBegin + vigra::Diff2D(rDstPoint.getX(), + rDstPoint.getY()), + maColorBlendAccessor ); + } + else if( pMask ) + { + const composite_iterator_type aBegin( + maBegin + vigra::Diff2D(rDstPoint.getX(), + rDstPoint.getY()), + pMask->maBegin + vigra::Diff2D(rSrcRect.getMinX(), + rSrcRect.getMinY()) ); + + fillImage(aBegin, + aBegin + vigra::Diff2D(rSrcRect.getWidth(), + rSrcRect.getHeight()), + maRawMaskedAccessor, + maColorLookup( + maAccessor, + aSrcColor) ); + } } virtual void drawMaskedColor_i(Color aSrcColor, @@ -891,22 +824,43 @@ namespace const basegfx::B2IPoint& rDstPoint, const BitmapDeviceSharedPtr& rClip ) { + boost::shared_ptr<MaskBitmap> pMask( getCompatibleClipMask(rAlphaMask) ); boost::shared_ptr<AlphaMaskBitmap> pAlpha( getCompatibleAlphaMask(rAlphaMask) ); - OSL_ASSERT( pAlpha ); - - const vigra::pair<composite_iterator_type, - composite_iterator_type> aRange( getMaskedRange(rClip) ); - maMaskedColorBlendAccessor.get1stWrappedAccessor().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 ); + OSL_ASSERT( pAlpha || pMask ); + + if( pAlpha ) + { + const composite_iterator_type aBegin( getMaskedIter(rClip) ); + maMaskedColorBlendAccessor.get1stWrappedAccessor().setColor( + aSrcColor ); + + vigra::copyImage( pAlpha->maBegin + vigra::Diff2D(rSrcRect.getMinX(), + rSrcRect.getMinY()), + pAlpha->maBegin + vigra::Diff2D(rSrcRect.getMaxX(), + rSrcRect.getMaxY()), + pAlpha->maRawAccessor, + aBegin + vigra::Diff2D(rDstPoint.getX(), + rDstPoint.getY()), + maMaskedColorBlendAccessor ); + } + else if( pMask ) + { + // TODO(F3): clip is currently ignored for 1bpp + // drawMaskedColor_i case! + const composite_iterator_type aBegin( + maBegin + vigra::Diff2D(rDstPoint.getX(), + rDstPoint.getY()), + pMask->maBegin + vigra::Diff2D(rSrcRect.getMinX(), + rSrcRect.getMinY()) ); + + fillImage(aBegin, + aBegin + vigra::Diff2D(rSrcRect.getWidth(), + rSrcRect.getHeight()), + maRawMaskedAccessor, + maColorLookup( + maAccessor, + aSrcColor) ); + } } virtual void drawMaskedBitmap_i(const BitmapDeviceSharedPtr& rSrcBitmap, @@ -920,11 +874,11 @@ namespace // translated. Let alone interpolated. if( drawMode == DrawMode_XOR ) implDrawBitmap(rSrcBitmap, rSrcRect, rDstRect, - getMaskedRange(rMask), + getMaskedIter(rMask), maRawMaskedXorAccessor); else implDrawBitmap(rSrcBitmap, rSrcRect, rDstRect, - getMaskedRange(rMask), + getMaskedIter(rMask), maRawMaskedAccessor); } @@ -983,23 +937,37 @@ struct ImplBitmapDevice /// Scanline stride. Negative for bottom-to-top formats sal_Int32 mnScanlineStride; + + /// raw ptr to 0th scanline. used for cloning a generic renderer + sal_uInt8* mpFirstScanline; + + /** (Optional) device sharing the same memory, and used for input + clip masks/alpha masks/bitmaps that don't match our exact + bitmap format. + */ + BitmapDeviceSharedPtr mpGenericRenderer; }; -BitmapDevice::BitmapDevice( const basegfx::B2IVector& rSize, +BitmapDevice::BitmapDevice( const basegfx::B2IRange& rBounds, bool bTopDown, sal_Int32 nScanlineFormat, sal_Int32 nScanlineStride, + sal_uInt8* pFirstScanline, const RawMemorySharedArray& rMem, const PaletteMemorySharedVector& rPalette ) : mpImpl( new ImplBitmapDevice ) { mpImpl->mpMem = rMem; mpImpl->mpPalette = rPalette; - mpImpl->maBounds = basegfx::B2IRange( 0,0,rSize.getX(),rSize.getY() ); - mpImpl->maLineClipRect = basegfx::B2IRange( 0,0,rSize.getX()-1,rSize.getY()-1 ); + mpImpl->maBounds = rBounds; + mpImpl->maLineClipRect = basegfx::B2IRange( rBounds.getMinX(), + rBounds.getMinY(), + rBounds.getMaxX()-1, + rBounds.getMaxY()-1 ); mpImpl->mnScanlineFormat = nScanlineFormat; - mpImpl->mnScanlineStride = bTopDown ? nScanlineStride : -nScanlineStride; + mpImpl->mnScanlineStride = nScanlineStride; + mpImpl->mpFirstScanline = pFirstScanline; } BitmapDevice::~BitmapDevice() @@ -1009,8 +977,10 @@ BitmapDevice::~BitmapDevice() basegfx::B2IVector BitmapDevice::getSize() const { - return basegfx::B2IVector( mpImpl->maBounds.getWidth(), - mpImpl->maBounds.getHeight() ); + + return basegfx::B2IVector( + mpImpl->maBounds.getMaxX() - mpImpl->maBounds.getMinX(), + mpImpl->maBounds.getMaxY() - mpImpl->maBounds.getMinY() ); } bool BitmapDevice::isTopDown() const @@ -1025,7 +995,8 @@ sal_Int32 BitmapDevice::getScanlineFormat() const sal_Int32 BitmapDevice::getScanlineStride() const { - return mpImpl->mnScanlineStride; + return mpImpl->mnScanlineStride < 0 ? + -mpImpl->mnScanlineStride : mpImpl->mnScanlineStride; } RawMemorySharedArray BitmapDevice::getBuffer() const @@ -1045,7 +1016,7 @@ const sal_Int32 BitmapDevice::getPaletteEntryCount() const void BitmapDevice::clear( Color fillColor ) { - clear_i( fillColor ); + clear_i( fillColor, mpImpl->maBounds ); } void BitmapDevice::setPixel( const basegfx::B2IPoint& rPt, @@ -1072,7 +1043,7 @@ void BitmapDevice::setPixel( const basegfx::B2IPoint& rPt, if( isCompatibleClipMask( rClip ) ) setPixel_i(rPt,lineColor,drawMode,rClip); else - OSL_ENSURE( false, "Generic output not yet implemented!" ); + getGenericRenderer()->setPixel( rPt, lineColor, drawMode, rClip ); } } @@ -1124,7 +1095,8 @@ void BitmapDevice::drawLine( const basegfx::B2IPoint& rPt1, drawMode, rClip ); else - OSL_ENSURE( false, "Generic output not yet implemented!" ); + getGenericRenderer()->drawLine( rPt1, rPt2, lineColor, + drawMode, rClip ); } void BitmapDevice::drawPolygon( const basegfx::B2DPolygon& rPoly, @@ -1156,7 +1128,8 @@ void BitmapDevice::drawPolygon( const basegfx::B2DPolygon& rPoly, mpImpl->maLineClipRect, lineColor, drawMode, rClip ); else - OSL_ENSURE( false, "Generic output not yet implemented!" ); + getGenericRenderer()->drawPolygon( rPoly, lineColor, + drawMode, rClip ); } void BitmapDevice::fillPolyPolygon( const basegfx::B2DPolyPolygon& rPoly, @@ -1180,7 +1153,8 @@ void BitmapDevice::fillPolyPolygon( const basegfx::B2DPolyPolygon& rPoly, if( isCompatibleClipMask( rClip ) ) fillPolyPolygon_i( rPoly, fillColor, drawMode, mpImpl->maBounds, rClip ); else - OSL_ENSURE( false, "Generic output not yet implemented!" ); + getGenericRenderer()->fillPolyPolygon( rPoly, fillColor, + drawMode, rClip ); } @@ -1336,10 +1310,15 @@ void BitmapDevice::drawBitmap( const BitmapDeviceSharedPtr& rSrcBitmap, assertImageRange(aDestRange,mpImpl->maBounds); assertImageRange(aSrcRange,aSrcBounds); +#if 0 if( isCompatibleBitmap( rSrcBitmap ) ) drawBitmap_i( rSrcBitmap, aSrcRange, aDestRange, drawMode ); else - OSL_ENSURE( false, "Generic output not yet implemented!" ); + getGenericRenderer()->drawBitmap( rSrcBitmap, rSrcRect, + rDstRect, drawMode ); +#else + drawBitmap_i( rSrcBitmap, aSrcRange, aDestRange, drawMode ); +#endif } } @@ -1368,6 +1347,7 @@ void BitmapDevice::drawBitmap( const BitmapDeviceSharedPtr& rSrcBitmap, assertImageRange(aDestRange,mpImpl->maBounds); assertImageRange(aSrcRange,aSrcBounds); +#if 0 if( isCompatibleBitmap( rSrcBitmap ) && isCompatibleClipMask( rClip ) ) { @@ -1375,8 +1355,20 @@ void BitmapDevice::drawBitmap( const BitmapDeviceSharedPtr& rSrcBitmap, } else { - OSL_ENSURE( false, "Generic output not yet implemented!" ); + getGenericRenderer()->drawBitmap( rSrcBitmap, rSrcRect, + rDstRect, drawMode, rClip ); } +#else + if( isCompatibleClipMask( rClip ) ) + { + drawBitmap_i( rSrcBitmap, aSrcRange, aDestRange, drawMode, rClip ); + } + else + { + getGenericRenderer()->drawBitmap( rSrcBitmap, rSrcRect, + rDstRect, drawMode, rClip ); + } +#endif } } @@ -1390,6 +1382,7 @@ void BitmapDevice::drawMaskedColor( Color rSrcColor, basegfx::B2IRange aSrcRange( rSrcRect ); basegfx::B2IPoint aDestPoint( rDstPoint ); +#if 0 if( clipAreaImpl( aSrcRange, aDestPoint, aSrcBounds, @@ -1398,11 +1391,28 @@ void BitmapDevice::drawMaskedColor( Color rSrcColor, assertImagePoint(aDestPoint,mpImpl->maBounds); assertImageRange(aSrcRange,aSrcBounds); - if( isCompatibleAlphaMask( rAlphaMask ) ) + if( isCompatibleClipMask( rAlphaMask ) || isCompatibleAlphaMask( rAlphaMask ) ) drawMaskedColor_i( rSrcColor, rAlphaMask, aSrcRange, aDestPoint ); else - OSL_ENSURE( false, "Generic output not yet implemented!" ); + getGenericRenderer()->drawMaskedColor( rSrcColor, rAlphaMask, + rSrcRect, rDstPoint ); } +#else + // drawMaskedBitmap is also used for OutputDevice::DrawMask + if( clipAreaImpl( aSrcRange, + aDestPoint, + aSrcBounds, + mpImpl->maBounds )) + { + assertImagePoint(aDestPoint,mpImpl->maBounds); + assertImageRange(aSrcRange,aSrcBounds); + + if( isCompatibleClipMask( rAlphaMask ) || isCompatibleAlphaMask( rAlphaMask ) ) + drawMaskedColor_i( rSrcColor, rAlphaMask, aSrcRange, aDestPoint ); + else + OSL_ENSURE(false, "Generic output not yet implemented!"); + } +#endif } void BitmapDevice::drawMaskedColor( Color aSrcColor, @@ -1430,15 +1440,31 @@ void BitmapDevice::drawMaskedColor( Color aSrcColor, assertImagePoint(aDestPoint,mpImpl->maBounds); assertImageRange(aSrcRange,aSrcBounds); - if( isCompatibleAlphaMask( rAlphaMask ) && +#if 0 + if( (isCompatibleClipMask( rAlphaMask ) || + isCompatibleAlphaMask( rAlphaMask )) && + isCompatibleClipMask( rClip ) ) + { + drawMaskedColor_i( aSrcColor, rAlphaMask, aSrcRange, aDestPoint, rClip ); + } + else + { + getGenericRenderer()->drawMaskedColor( aSrcColor, rAlphaMask, + rSrcRect, rDstPoint, rClip ); + } +#else + // drawMaskedBitmap is also used for OutputDevice::DrawMask + if( (isCompatibleClipMask( rAlphaMask ) || + isCompatibleAlphaMask( rAlphaMask )) && isCompatibleClipMask( rClip ) ) { drawMaskedColor_i( aSrcColor, rAlphaMask, aSrcRange, aDestPoint, rClip ); } else { - OSL_ENSURE( false, "Generic output not yet implemented!" ); + OSL_ENSURE(false, "Generic output not yet implemented!"); } +#endif } } @@ -1463,6 +1489,18 @@ void BitmapDevice::drawMaskedBitmap( const BitmapDeviceSharedPtr& rSrcBitmap, assertImageRange(aDestRange,mpImpl->maBounds); assertImageRange(aSrcRange,aSrcBounds); +#if 0 + if( isCompatibleBitmap( rSrcBitmap ) && + isCompatibleClipMask( rMask ) ) + { + drawMaskedBitmap_i( rSrcBitmap, rMask, aSrcRange, aDestRange, drawMode ); + } + else + { + getGenericRenderer()->drawMaskedBitmap( rSrcBitmap, rMask, + rSrcRect, rDstRect, drawMode ); + } +#else if( isCompatibleBitmap( rSrcBitmap ) && isCompatibleClipMask( rMask ) ) { @@ -1470,8 +1508,9 @@ void BitmapDevice::drawMaskedBitmap( const BitmapDeviceSharedPtr& rSrcBitmap, } else { - OSL_ENSURE( false, "Generic output not yet implemented!" ); + OSL_ENSURE(false, "Generic output not yet implemented!"); } +#endif } } @@ -1503,6 +1542,7 @@ void BitmapDevice::drawMaskedBitmap( const BitmapDeviceSharedPtr& rSrcBitmap, assertImageRange(aDestRange,mpImpl->maBounds); assertImageRange(aSrcRange,aSrcBounds); +#if 0 if( isCompatibleBitmap( rSrcBitmap ) && isCompatibleClipMask( rMask ) && isCompatibleClipMask( rClip ) ) @@ -1511,46 +1551,77 @@ void BitmapDevice::drawMaskedBitmap( const BitmapDeviceSharedPtr& rSrcBitmap, } else { - OSL_ENSURE( false, "Generic output not yet implemented!" ); + getGenericRenderer()->drawMaskedBitmap( rSrcBitmap, rMask, rSrcRect, + rDstRect, drawMode, rClip ); } +#else + if( isCompatibleBitmap( rSrcBitmap ) && + isCompatibleClipMask( rMask ) && + isCompatibleClipMask( rClip ) ) + { + drawMaskedBitmap_i( rSrcBitmap, rMask, aSrcRange, aDestRange, drawMode, rClip ); + } + else + { + OSL_ENSURE(false, "Generic output not yet implemented!"); + } +#endif } } //---------------------------------------------------------------------------------- -/// Produces a specialized renderer for the given packed pixel format -template< int Bits, - bool MsbFirst, - template<typename> class VanillaAccessorSelector, - class Accessor > -BitmapDeviceSharedPtr createPackedPixelRenderer( - const basegfx::B2IVector& rSize, - bool bTopDown, - sal_Int32 nScanlineFormat, - sal_Int32 nScanlineStride, - sal_uInt8* pFirstScanline, - const typename VanillaAccessorSelector< - Accessor>::type & rAccessor, - boost::shared_array< sal_uInt8 > pMem, - const PaletteMemorySharedVector& pPal ) +/** Standard clip and alpha masks + */ +struct StdMasks +{ + typedef PixelFormatTraits_GREY1_MSB clipmask_format_traits; + typedef PixelFormatTraits_GREY8 alphamask_format_traits; +}; + +#if 0 +/** Clip and alpha masks for the generic renderer (of course, those + need to be generic, too) + */ +struct MaskTraitsGeneric +{ + typedef PixelFormatTraits_GenericInteger clipmask_format_traits; + typedef PixelFormatTraits_GenericInteger alphamask_format_traits; +}; +#endif + +//---------------------------------------------------------------------------------- + +/// Produces a specialized renderer for the given pixel format +template< class FormatTraits, class MaskTraits > +BitmapDeviceSharedPtr createRenderer( + const basegfx::B2IRange& rBounds, + bool bTopDown, + sal_Int32 nScanlineFormat, + sal_Int32 nScanlineStride, + sal_uInt8* pFirstScanline, + typename FormatTraits::accessor_selector::template wrap_accessor< + typename FormatTraits::raw_accessor_type>::type const& rAccessor, + boost::shared_array< sal_uInt8 > pMem, + const PaletteMemorySharedVector& pPal ) { - typedef PackedPixelIterator< sal_uInt8,Bits,MsbFirst > Iterator; + typedef typename FormatTraits::iterator_type Iterator; typedef BitmapRenderer< Iterator, - Accessor, - VanillaAccessorSelector > Renderer; + typename FormatTraits::raw_accessor_type, + typename FormatTraits::accessor_selector, + MaskTraits > Renderer; return BitmapDeviceSharedPtr( - new Renderer( rSize, + new Renderer( rBounds, bTopDown, nScanlineFormat, nScanlineStride, - Iterator(pFirstScanline, - nScanlineStride), - Iterator(pFirstScanline, - nScanlineStride) - + vigra::Diff2D(rSize.getX(), - rSize.getY()), + pFirstScanline, + Iterator( + reinterpret_cast<typename Iterator::value_type*>( + pFirstScanline), + nScanlineStride), rAccessor, pMem, pPal )); @@ -1577,6 +1648,59 @@ PaletteMemorySharedVector createStandardPalette( return pLocalPal; } +template< class FormatTraits, class MaskTraits > +BitmapDeviceSharedPtr createRenderer( + const basegfx::B2IRange& rBounds, + bool bTopDown, + sal_Int32 nScanlineFormat, + sal_Int32 nScanlineStride, + sal_uInt8* pFirstScanline, + boost::shared_array< sal_uInt8 > pMem, + const PaletteMemorySharedVector& pPal ) +{ + return createRenderer<FormatTraits, + MaskTraits>(rBounds, + bTopDown, + nScanlineFormat, + nScanlineStride, + pFirstScanline, + typename FormatTraits::accessor_selector::template + wrap_accessor< + typename FormatTraits::raw_accessor_type>::type(), + pMem, + pPal); +} + +template< class FormatTraits, class MaskTraits > +BitmapDeviceSharedPtr createRenderer( + const basegfx::B2IRange& rBounds, + bool bTopDown, + sal_Int32 nScanlineFormat, + sal_Int32 nScanlineStride, + sal_uInt8* pFirstScanline, + boost::shared_array< sal_uInt8 > pMem, + PaletteMemorySharedVector pPal, + int nBitsPerPixel ) +{ + pPal = createStandardPalette(pPal, + 1UL << nBitsPerPixel); + + OSL_ASSERT(pPal); + return createRenderer<FormatTraits, + MaskTraits>(rBounds, + bTopDown, + nScanlineFormat, + nScanlineStride, + pFirstScanline, + typename FormatTraits::accessor_selector::template + wrap_accessor< + typename FormatTraits::raw_accessor_type>::type( + &pPal->at(0), + pPal->size()), + pMem, + pPal); +} + //---------------------------------------------------------------------------------- // TODO(Q3): consolidate with canvas/canvastools.hxx! Best move this @@ -1603,74 +1727,14 @@ inline sal_uInt32 nextPow2( sal_uInt32 x ) //---------------------------------------------------------------------------------- -typedef PaletteImageAccessor< - StandardAccessor<sal_uInt8>,Color> StandardPaletteAccessor; -typedef PaletteImageAccessor< - NonStandardAccessor<sal_uInt8>,Color> NonStandardPaletteAccessor; - -// ------------------------------------------------------- - -#ifdef OSL_LITENDIAN -# define SIXTEENBIT_LSB_SWAP false -# define SIXTEENBIT_MSB_SWAP true -#else -# ifdef OSL_BIGENDIAN -# define SIXTEENBIT_LSB_SWAP true -# define SIXTEENBIT_MSB_SWAP false -# else -# error Undetermined endianness! -# endif -#endif - -typedef PixelIterator<sal_uInt16> SixteenBitPixelIterator; -typedef StandardAccessor<sal_uInt16> SixteenBitRawAccessor; -template< class Accessor > struct TrueColorLsbMaskAccessorSelector -{ - typedef TrueColorMaskAccessor<Accessor, - Color, - 0xF800, - 0x07E0, - 0x001F, - SIXTEENBIT_LSB_SWAP> type; -}; -typedef TrueColorLsbMaskAccessorSelector< - SixteenBitRawAccessor>::type SixteenBitLsbAccessor; - -template< class Accessor > struct TrueColorMsbMaskAccessorSelector -{ - typedef TrueColorMaskAccessor<Accessor, - Color, - 0xF800, - 0x07E0, - 0x001F, - SIXTEENBIT_MSB_SWAP> type; -}; -typedef TrueColorMsbMaskAccessorSelector< - SixteenBitRawAccessor>::type SixteenBitMsbAccessor; - -// ------------------------------------------------------- - -typedef PixelIterator<TwentyFourBitPixelRGB> TwentyFourBitRGBIterator; -typedef StandardAccessor<TwentyFourBitPixelRGB> TwentyFourBitRGBAccessor; - -// ------------------------------------------------------- - -typedef PixelIterator<TwentyFourBitPixelBGR> TwentyFourBitBGRIterator; -typedef StandardAccessor<TwentyFourBitPixelBGR> TwentyFourBitBGRAccessor; - -// ------------------------------------------------------- - -typedef PixelIterator<Color> ThirtyTwoBitPixelIterator; -typedef StandardAccessor<Color> ThirtyTwoBitAccessor; - - namespace { BitmapDeviceSharedPtr createBitmapDeviceImpl( const basegfx::B2IVector& rSize, bool bTopDown, sal_Int32 nScanlineFormat, boost::shared_array< sal_uInt8 > pMem, - PaletteMemorySharedVector pPal ) + PaletteMemorySharedVector pPal, + const basegfx::B2IRange* pSubset ) { if( nScanlineFormat <= Format::NONE || nScanlineFormat > Format::MAX ) @@ -1679,16 +1743,16 @@ BitmapDeviceSharedPtr createBitmapDeviceImpl( const basegfx::B2IVector& r static const sal_uInt8 bitsPerPixel[] = { 0, // NONE - 1, // ONE_BIT_MSB_GRAY - 1, // ONE_BIT_LSB_GRAY + 1, // ONE_BIT_MSB_GREY + 1, // ONE_BIT_LSB_GREY 1, // ONE_BIT_MSB_PAL 1, // ONE_BIT_LSB_PAL - 4, // FOUR_BIT_MSB_GRAY - 4, // FOUR_BIT_LSB_GRAY + 4, // FOUR_BIT_MSB_GREY + 4, // FOUR_BIT_LSB_GREY 4, // FOUR_BIT_MSB_PAL 4, // FOUR_BIT_LSB_PAL 8, // EIGHT_BIT_PAL - 8, // EIGHT_BIT_GRAY + 8, // EIGHT_BIT_GREY 16, // SIXTEEN_BIT_LSB_TC_MASK 16, // SIXTEEN_BIT_MSB_TC_MASK 24, // TWENTYFOUR_BIT_TC_MASK @@ -1724,294 +1788,109 @@ BitmapDeviceSharedPtr createBitmapDeviceImpl( const basegfx::B2IVector& r sal_uInt8* pFirstScanline = nScanlineStride < 0 ? pMem.get() + nMemSize + nScanlineStride : pMem.get(); + // shrink render area to given subset, if given + basegfx::B2IRange aBounds(0,0,rSize.getX(),rSize.getY()); + if( pSubset ) + aBounds.intersect( *pSubset ); + switch( nScanlineFormat ) { // ---------------------------------------------------------------------- // one bit formats - case Format::ONE_BIT_MSB_GRAY: - { - return createPackedPixelRenderer< 1, - true, - boost::mpl::identity, - MaskAccessor >( - rSize, - bTopDown, - nScanlineFormat, - nScanlineStride, - pFirstScanline, - MaskAccessor(), - pMem, - pPal ); - } - case Format::ONE_BIT_LSB_GRAY: - { - return createPackedPixelRenderer< 1, - false, - boost::mpl::identity, - MaskAccessor >( - rSize, - bTopDown, - nScanlineFormat, - nScanlineStride, - pFirstScanline, - MaskAccessor(), - pMem, - pPal ); - } + case Format::ONE_BIT_MSB_GREY: + return createRenderer<PixelFormatTraits_GREY1_MSB,StdMasks>( + aBounds, bTopDown, nScanlineFormat, nScanlineStride, + pFirstScanline, pMem, pPal ); + + case Format::ONE_BIT_LSB_GREY: + return createRenderer<PixelFormatTraits_GREY1_LSB,StdMasks>( + aBounds, bTopDown, nScanlineFormat, nScanlineStride, + pFirstScanline, pMem, pPal ); + case Format::ONE_BIT_MSB_PAL: - { - pPal = createStandardPalette(pPal,2); - return createPackedPixelRenderer< 1, - true, - PaletteAccessorSelector, - MaskAccessor >( - rSize, - bTopDown, - nScanlineFormat, - nScanlineStride, - pFirstScanline, - NonStandardPaletteAccessor( &pPal->at(0), - pPal->size() ), - pMem, - pPal ); - } + return createRenderer<PixelFormatTraits_PAL1_MSB,StdMasks>( + aBounds, bTopDown, nScanlineFormat, nScanlineStride, + pFirstScanline, pMem, pPal, + bitsPerPixel[nScanlineFormat] ); + case Format::ONE_BIT_LSB_PAL: - { - pPal = createStandardPalette(pPal,2); - return createPackedPixelRenderer< 1, - false, - PaletteAccessorSelector, - MaskAccessor >( - rSize, - bTopDown, - nScanlineFormat, - nScanlineStride, - pFirstScanline, - NonStandardPaletteAccessor( &pPal->at(0), - pPal->size() ), - pMem, - pPal ); - } + return createRenderer<PixelFormatTraits_PAL1_LSB,StdMasks>( + aBounds, bTopDown, nScanlineFormat, nScanlineStride, + pFirstScanline, pMem, pPal, + bitsPerPixel[nScanlineFormat] ); // ---------------------------------------------------------------------- // four bit formats - case Format::FOUR_BIT_MSB_GRAY: - { - return createPackedPixelRenderer< 4, - true, - boost::mpl::identity, - MaskAccessor >( - rSize, - bTopDown, - nScanlineFormat, - nScanlineStride, - pFirstScanline, - MaskAccessor(), - pMem, - pPal ); - } - case Format::FOUR_BIT_LSB_GRAY: - { - return createPackedPixelRenderer< 4, - false, - boost::mpl::identity, - MaskAccessor >( - rSize, - bTopDown, - nScanlineFormat, - nScanlineStride, - pFirstScanline, - MaskAccessor(), - pMem, - pPal ); - } + case Format::FOUR_BIT_MSB_GREY: + return createRenderer<PixelFormatTraits_GREY4_MSB,StdMasks>( + aBounds, bTopDown, nScanlineFormat, nScanlineStride, + pFirstScanline, pMem, pPal ); + + case Format::FOUR_BIT_LSB_GREY: + return createRenderer<PixelFormatTraits_GREY4_LSB,StdMasks>( + aBounds, bTopDown, nScanlineFormat, nScanlineStride, + pFirstScanline, pMem, pPal ); + case Format::FOUR_BIT_MSB_PAL: - { - pPal = createStandardPalette(pPal,16); - return createPackedPixelRenderer< 1, - true, - PaletteAccessorSelector, - MaskAccessor >( - rSize, - bTopDown, - nScanlineFormat, - nScanlineStride, - pFirstScanline, - NonStandardPaletteAccessor( &pPal->at(0), - pPal->size() ), - pMem, - pPal ); - } + return createRenderer<PixelFormatTraits_PAL4_MSB,StdMasks>( + aBounds, bTopDown, nScanlineFormat, nScanlineStride, + pFirstScanline, pMem, pPal, + bitsPerPixel[nScanlineFormat] ); + case Format::FOUR_BIT_LSB_PAL: - { - pPal = createStandardPalette(pPal,16); - return createPackedPixelRenderer< 1, - false, - PaletteAccessorSelector, - MaskAccessor >( - rSize, - bTopDown, - nScanlineFormat, - nScanlineStride, - pFirstScanline, - NonStandardPaletteAccessor( &pPal->at(0), - pPal->size() ), - pMem, - pPal ); - } + return createRenderer<PixelFormatTraits_PAL4_LSB,StdMasks>( + aBounds, bTopDown, nScanlineFormat, nScanlineStride, + pFirstScanline, pMem, pPal, + bitsPerPixel[nScanlineFormat] ); // ---------------------------------------------------------------------- // eight bit formats - case Format::EIGHT_BIT_GRAY: - { - return BitmapDeviceSharedPtr( - new BitmapRenderer< AlphaMaskIterator, - AlphaMaskAccessor, - boost::mpl::identity >( - rSize, - bTopDown, - nScanlineFormat, - nScanlineStride, - AlphaMaskIterator(pFirstScanline, - nScanlineStride), - AlphaMaskIterator(pFirstScanline, - nScanlineStride) - + vigra::Diff2D(rSize.getX(), - rSize.getY()), - AlphaMaskAccessor(), - pMem, - pPal )); - } + case Format::EIGHT_BIT_GREY: + return createRenderer<PixelFormatTraits_GREY8,StdMasks>( + aBounds, bTopDown, nScanlineFormat, nScanlineStride, + pFirstScanline, pMem, pPal ); + case Format::EIGHT_BIT_PAL: - { - pPal = createStandardPalette(pPal,256); - return BitmapDeviceSharedPtr( - new BitmapRenderer< AlphaMaskIterator, - AlphaMaskAccessor, - PaletteAccessorSelector >( - rSize, - bTopDown, - nScanlineFormat, - nScanlineStride, - AlphaMaskIterator(pFirstScanline, - nScanlineStride), - AlphaMaskIterator(pFirstScanline, - nScanlineStride) - + vigra::Diff2D(rSize.getX(), - rSize.getY()), - StandardPaletteAccessor( &pPal->at(0), - pPal->size() ), - pMem, - pPal )); - } + return createRenderer<PixelFormatTraits_PAL8,StdMasks>( + aBounds, bTopDown, nScanlineFormat, nScanlineStride, + pFirstScanline, pMem, pPal, + bitsPerPixel[nScanlineFormat] ); // ---------------------------------------------------------------------- // sixteen bit formats case Format::SIXTEEN_BIT_LSB_TC_MASK: - { - return BitmapDeviceSharedPtr( - new BitmapRenderer< SixteenBitPixelIterator, - SixteenBitRawAccessor, - TrueColorLsbMaskAccessorSelector >( - rSize, - bTopDown, - nScanlineFormat, - nScanlineStride, - SixteenBitPixelIterator( - reinterpret_cast<sal_uInt16*>(pFirstScanline), - nScanlineStride), - SixteenBitPixelIterator( - reinterpret_cast<sal_uInt16*>(pFirstScanline), - nScanlineStride) - + vigra::Diff2D(rSize.getX(), - rSize.getY()), - SixteenBitLsbAccessor(), - pMem, - pPal )); - } + return createRenderer<PixelFormatTraits_RGB16_565_LSB,StdMasks>( + aBounds, bTopDown, nScanlineFormat, nScanlineStride, + pFirstScanline, pMem, pPal ); case Format::SIXTEEN_BIT_MSB_TC_MASK: - { - return BitmapDeviceSharedPtr( - new BitmapRenderer< SixteenBitPixelIterator, - SixteenBitRawAccessor, - TrueColorMsbMaskAccessorSelector >( - rSize, - bTopDown, - nScanlineFormat, - nScanlineStride, - SixteenBitPixelIterator( - reinterpret_cast<sal_uInt16*>(pFirstScanline), - nScanlineStride), - SixteenBitPixelIterator( - reinterpret_cast<sal_uInt16*>(pFirstScanline), - nScanlineStride) - + vigra::Diff2D(rSize.getX(), - rSize.getY()), - SixteenBitMsbAccessor(), - pMem, - pPal )); - } + return createRenderer<PixelFormatTraits_RGB16_565_MSB,StdMasks>( + aBounds, bTopDown, nScanlineFormat, nScanlineStride, + pFirstScanline, pMem, pPal ); + // ---------------------------------------------------------------------- // twentyfour bit formats - case Format::TWENTYFOUR_BIT_TC_MASK: - { - return BitmapDeviceSharedPtr( - new BitmapRenderer< TwentyFourBitRGBIterator, - TwentyFourBitRGBAccessor, - boost::mpl::identity >( - rSize, - bTopDown, - nScanlineFormat, - nScanlineStride, - TwentyFourBitRGBIterator( - reinterpret_cast<TwentyFourBitPixelRGB*>(pFirstScanline), - nScanlineStride), - TwentyFourBitRGBIterator( - reinterpret_cast<TwentyFourBitPixelRGB*>(pFirstScanline), - nScanlineStride) - + vigra::Diff2D(rSize.getX(), - rSize.getY()), - TwentyFourBitRGBAccessor(), - pMem, - pPal )); - } + return createRenderer<PixelFormatTraits_RGB24,StdMasks>( + aBounds, bTopDown, nScanlineFormat, nScanlineStride, + pFirstScanline, pMem, pPal ); // ---------------------------------------------------------------------- // thirtytwo bit formats case Format::THIRTYTWO_BIT_TC_MASK: - { - return BitmapDeviceSharedPtr( - new BitmapRenderer< ThirtyTwoBitPixelIterator, - ThirtyTwoBitAccessor, - boost::mpl::identity >( - rSize, - bTopDown, - nScanlineFormat, - nScanlineStride, - ThirtyTwoBitPixelIterator( - reinterpret_cast<Color*>(pFirstScanline), - nScanlineStride), - ThirtyTwoBitPixelIterator( - reinterpret_cast<Color*>(pFirstScanline), - nScanlineStride) - + vigra::Diff2D(rSize.getX(), - rSize.getY()), - ThirtyTwoBitAccessor(), - pMem, - pPal )); - } + return createRenderer<PixelFormatTraits_RGB32_888,StdMasks>( + aBounds, bTopDown, nScanlineFormat, nScanlineStride, + pFirstScanline, pMem, pPal ); } // TODO(F3): other formats not yet implemented @@ -2028,7 +1907,21 @@ BitmapDeviceSharedPtr createBitmapDevice( const basegfx::B2IVector& rSize, bTopDown, nScanlineFormat, boost::shared_array< sal_uInt8 >(), - PaletteMemorySharedVector() ); + PaletteMemorySharedVector(), + NULL ); +} + +BitmapDeviceSharedPtr createBitmapDevice( const basegfx::B2IVector& rSize, + bool bTopDown, + sal_Int32 nScanlineFormat, + const PaletteMemorySharedVector& rPalette ) +{ + return createBitmapDeviceImpl( rSize, + bTopDown, + nScanlineFormat, + boost::shared_array< sal_uInt8 >(), + rPalette, + NULL ); } BitmapDeviceSharedPtr createBitmapDevice( const basegfx::B2IVector& rSize, @@ -2041,7 +1934,19 @@ BitmapDeviceSharedPtr createBitmapDevice( const basegfx::B2IVector& rSize bTopDown, nScanlineFormat, rMem, - rPalette ); + rPalette, + NULL ); +} + +BitmapDeviceSharedPtr subsetBitmapDevice( const BitmapDeviceSharedPtr& rProto, + const basegfx::B2IRange& rSubset ) +{ + return createBitmapDeviceImpl( rProto->getSize(), + rProto->isTopDown(), + rProto->getScanlineFormat(), + rProto->getBuffer(), + rProto->getPalette(), + &rSubset ); } BitmapDeviceSharedPtr cloneBitmapDevice( const basegfx::B2IVector& rSize, @@ -2051,7 +1956,41 @@ BitmapDeviceSharedPtr cloneBitmapDevice( const basegfx::B2IVector& rSize, rProto->isTopDown(), rProto->getScanlineFormat(), boost::shared_array< sal_uInt8 >(), - rProto->getPalette() ); + rProto->getPalette(), + NULL ); +} + +//---------------------------------------------------------------------------------- + +/// Clone our device, with GenericImageAccessor to handle all formats +BitmapDeviceSharedPtr BitmapDevice::getGenericRenderer() const +{ +#if 0 + // xxx TODO + typedef BitmapRenderer< PixelFormatTraits_GenericInteger::iterator_type, + PixelFormatTraits_GenericInteger::raw_accessor_type, + PixelFormatTraits_GenericInteger::accessor_selector, + MaskTraitsGeneric > + Renderer; + + if( !mpImpl->mpGenericRenderer ) + { + mpImpl->mpGenericRenderer.reset( + new Renderer( + mpImpl->maBounds, + isTopDown(), + getScanlineFormat(), + getScanlineStride(), + mpImpl->mpFirstScanline, + PixelFormatTraits_GenericInteger::iterator_type(), + GenericIntegerImageAccessor<Color>( + const_cast<BitmapDevice*>(this)->shared_from_this()), + getBuffer(), + getPalette() )); + } +#endif + + return mpImpl->mpGenericRenderer; } } // namespace basebmp diff --git a/basebmp/source/debug.cxx b/basebmp/source/debug.cxx index 8f3d1c5edcf4..72229d82b38d 100644 --- a/basebmp/source/debug.cxx +++ b/basebmp/source/debug.cxx @@ -2,9 +2,9 @@ * * $RCSfile: debug.cxx,v $ * - * $Revision: 1.5 $ + * $Revision: 1.6 $ * - * last change: $Author: thb $ $Date: 2006-07-06 10:00:41 $ + * last change: $Author: thb $ $Date: 2006-07-11 11:38:56 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -79,26 +79,26 @@ namespace basebmp { switch( nScanlineFormat ) { - case Format::ONE_BIT_MSB_GRAY: - return "ONE_BIT_MSB_GRAY"; - case Format::ONE_BIT_LSB_GRAY: - return "ONE_BIT_LSB_GRAY"; + case Format::ONE_BIT_MSB_GREY: + return "ONE_BIT_MSB_GREY"; + case Format::ONE_BIT_LSB_GREY: + return "ONE_BIT_LSB_GREY"; case Format::ONE_BIT_MSB_PAL: return "ONE_BIT_MSB_PAL"; case Format::ONE_BIT_LSB_PAL: return "ONE_BIT_LSB_PAL"; - case Format::FOUR_BIT_MSB_GRAY: - return "FOUR_BIT_MSB_GRAY"; - case Format::FOUR_BIT_LSB_GRAY: - return "FOUR_BIT_LSB_GRAY"; + case Format::FOUR_BIT_MSB_GREY: + return "FOUR_BIT_MSB_GREY"; + case Format::FOUR_BIT_LSB_GREY: + return "FOUR_BIT_LSB_GREY"; case Format::FOUR_BIT_MSB_PAL: return "FOUR_BIT_MSB_PAL"; case Format::FOUR_BIT_LSB_PAL: return "FOUR_BIT_LSB_PAL"; case Format::EIGHT_BIT_PAL: return "EIGHT_BIT_PAL"; - case Format::EIGHT_BIT_GRAY: - return "EIGHT_BIT_GRAY"; + case Format::EIGHT_BIT_GREY: + return "EIGHT_BIT_GREY"; case Format::SIXTEEN_BIT_LSB_TC_MASK: return "SIXTEEN_BIT_LSB_TC_MASK"; case Format::SIXTEEN_BIT_MSB_TC_MASK: diff --git a/basebmp/source/intconversion.hxx b/basebmp/source/intconversion.hxx new file mode 100644 index 000000000000..dcd525b1d4b9 --- /dev/null +++ b/basebmp/source/intconversion.hxx @@ -0,0 +1,96 @@ +/************************************************************************* + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: intconversion.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: thb $ $Date: 2006-07-11 11:38:56 $ + * + * The Contents of this file are made available subject to + * the terms of GNU Lesser General Public License Version 2.1. + * + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2005 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + ************************************************************************/ + +#ifndef INCLUDED_BASEBMP_INTCONVERSION_HXX +#define INCLUDED_BASEBMP_INTCONVERSION_HXX + +#include <vigra/rgbvalue.hxx> +#include <functional> + +namespace basebmp +{ + // metafunctions to retrieve correct POD from/to basebmp::Color + //------------------------------------------------------------------------ + + /// type-safe conversion from RgbValue to packed int32 + template< class RgbVal > struct UInt32FromRgbValue + { + sal_uInt32 operator()( RgbVal const& c ) const + { + return (c[0] << 16) | (c[1] << 8) | c[2]; + } + }; + + /// type-safe conversion from packed int32 to RgbValue + template< class RgbVal > struct RgbValueFromUInt32 + { + RgbVal operator()( sal_uInt32 c ) const + { + return RgbVal((c >> 16) & 0xFF, + (c >> 8) & 0xFF, + c & 0xFF); + } + }; + + /// Get converter from given data type to sal_uInt32 + template< typename DataType > struct uInt32Converter + { + typedef std::identity<DataType> to; + typedef std::identity<DataType> from; + }; + template< unsigned int RedIndex, + unsigned int GreenIndex, + unsigned int BlueIndex > struct uInt32Converter< + vigra::RGBValue< sal_uInt8, + RedIndex, + GreenIndex, + BlueIndex > > + { + typedef UInt32FromRgbValue< + vigra::RGBValue< sal_uInt8, + RedIndex, + GreenIndex, + BlueIndex > > + to; + typedef RgbValueFromUInt32< + vigra::RGBValue< sal_uInt8, + RedIndex, + GreenIndex, + BlueIndex > > + from; + }; +} + +#endif /* INCLUDED_BASEBMP_INTCONVERSION_HXX */ diff --git a/basebmp/source/makefile.mk b/basebmp/source/makefile.mk index 47c8f60c92ed..3fc5438ccb70 100644 --- a/basebmp/source/makefile.mk +++ b/basebmp/source/makefile.mk @@ -4,9 +4,9 @@ # # $RCSfile: makefile.mk,v $ # -# $Revision: 1.2 $ +# $Revision: 1.3 $ # -# last change: $Author: thb $ $Date: 2006-05-31 10:12:12 $ +# last change: $Author: thb $ $Date: 2006-07-11 11:38:56 $ # # The Contents of this file are made available subject to # the terms of GNU Lesser General Public License Version 2.1. @@ -49,6 +49,8 @@ SLOFILES = \ $(SLO)$/bitmapdevice.obj \ $(SLO)$/debug.obj +# $(SLO)$/genericintegerimageaccessor.obj \ + # ========================================================================== .INCLUDE : target.mk diff --git a/basebmp/test/basictest.cxx b/basebmp/test/basictest.cxx index 33209a81a534..baffe6718ad2 100644 --- a/basebmp/test/basictest.cxx +++ b/basebmp/test/basictest.cxx @@ -4,9 +4,9 @@ * * $RCSfile: basictest.cxx,v $ * - * $Revision: 1.7 $ + * $Revision: 1.8 $ * - * last change: $Author: thb $ $Date: 2006-07-06 10:00:41 $ + * last change: $Author: thb $ $Date: 2006-07-11 11:38:56 $ * * The Contents of this file are made available subject to * the terms of GNU Lesser General Public License Version 2.1. @@ -85,8 +85,8 @@ public: CPPUNIT_ASSERT_MESSAGE("setBlue()", aTestColor.toInt32() == 0x00F0F10 ); - aTestColor.setGray( 0x13 ); - CPPUNIT_ASSERT_MESSAGE("setGray()", + aTestColor.setGrey( 0x13 ); + CPPUNIT_ASSERT_MESSAGE("setGrey()", aTestColor.toInt32() == 0x00131313 ); aTestColor = Color( 0x10, 0x20, 0xFF ); @@ -161,7 +161,7 @@ public: { pDevice = createBitmapDevice( aSize, true, - Format::EIGHT_BIT_GRAY ); + Format::EIGHT_BIT_GREY ); const Color aCol4(0x010101); pDevice->setPixel( aPt, aCol4, DrawMode_PAINT ); @@ -197,12 +197,12 @@ public: pDevice->setPixel( aPt2, aCol5, DrawMode_PAINT ); debugDump( pDevice, output ); CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #8", - pDevice->getPixel(aPt2) == aCol5); + pDevice->getPixel(aPt2) != aCol7); const Color aCol6(0x00FFFFFF); pDevice->setPixel( aPt3, aCol6, DrawMode_PAINT ); CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #9", - pDevice->getPixel(aPt3) != aCol7); + pDevice->getPixel(aPt3) == aCol6); } // 24bpp diff --git a/basebmp/test/bmpdemo.cxx b/basebmp/test/bmpdemo.cxx index 8f699dc05a18..fc5c7752fe06 100644 --- a/basebmp/test/bmpdemo.cxx +++ b/basebmp/test/bmpdemo.cxx @@ -4,9 +4,9 @@ * * $RCSfile: bmpdemo.cxx,v $ * - * $Revision: 1.9 $ + * $Revision: 1.10 $ * - * last change: $Author: thb $ $Date: 2006-06-30 11:05:21 $ + * last change: $Author: thb $ $Date: 2006-07-11 11:38:56 $ * * The Contents of this file are made available subject to * the terms of GNU Lesser General Public License Version 2.1. @@ -1082,6 +1082,31 @@ void TestWindow::Paint( const Rectangle& rRect ) basebmp::Format::THIRTYTWO_BIT_TC_MASK )); { + basebmp::BitmapDeviceSharedPtr pMask( basebmp::createBitmapDevice( aTestSize, + false, + basebmp::Format::ONE_BIT_MSB_GREY )); + + ::rtl::OUString aSvg = ::rtl::OUString::createFromAscii( + "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); #if 0 basegfx::B2DPolygon aRect = basegfx::tools::createPolygonFromRect( diff --git a/basebmp/test/cliptest.cxx b/basebmp/test/cliptest.cxx index bf6dbc3d7376..cdf3fdf2b32f 100644 --- a/basebmp/test/cliptest.cxx +++ b/basebmp/test/cliptest.cxx @@ -4,9 +4,9 @@ * * $RCSfile: cliptest.cxx,v $ * - * $Revision: 1.1 $ + * $Revision: 1.2 $ * - * last change: $Author: thb $ $Date: 2006-06-28 16:50:20 $ + * last change: $Author: thb $ $Date: 2006-07-11 11:38:56 $ * * The Contents of this file are made available subject to * the terms of GNU Lesser General Public License Version 2.1. @@ -108,9 +108,6 @@ private: const Color aCol(0xFFFFFFFF); rDevice->drawLine( aPt1, aPt2, aCol, DrawMode_PAINT, mpClipMask ); - std::ofstream output("32bpp_test.dump"); - debugDump( mpDevice32bpp, output ); - const basegfx::B2IPoint aPt3(1,5); CPPUNIT_ASSERT_MESSAGE("get line pixel", rDevice->getPixel(aPt3) != aBgCol); @@ -164,7 +161,7 @@ private: { BitmapDeviceSharedPtr pBmp( createBitmapDevice( rDevice->getSize(), true, - Format::EIGHT_BIT_GRAY )); + Format::EIGHT_BIT_GREY )); ::rtl::OUString aSvg = ::rtl::OUString::createFromAscii( "m 0 0h5v10h5v-5h-10z" ); @@ -199,7 +196,7 @@ public: const basegfx::B2ISize aSize(11,11); mpClipMask = createBitmapDevice( aSize, true, - Format::ONE_BIT_MSB_GRAY ); + Format::ONE_BIT_MSB_GREY ); mpDevice1bpp = createBitmapDevice( aSize, true, Format::ONE_BIT_MSB_PAL ); @@ -216,6 +213,9 @@ public: aPoly.getB2DPolygon(0), Color(0), DrawMode_PAINT ); + + std::ofstream output("clipmask.dump"); + debugDump( mpClipMask, output ); } void testPixelClip() diff --git a/basebmp/test/masktest.cxx b/basebmp/test/masktest.cxx index 1cd85c038cb4..5976e1325582 100644 --- a/basebmp/test/masktest.cxx +++ b/basebmp/test/masktest.cxx @@ -4,9 +4,9 @@ * * $RCSfile: masktest.cxx,v $ * - * $Revision: 1.2 $ + * $Revision: 1.3 $ * - * last change: $Author: thb $ $Date: 2006-06-09 04:21:01 $ + * last change: $Author: thb $ $Date: 2006-07-11 11:38:56 $ * * The Contents of this file are made available subject to * the terms of GNU Lesser General Public License Version 2.1. @@ -138,7 +138,7 @@ public: mpMask = createBitmapDevice( aSize, true, - Format::EIGHT_BIT_GRAY ); + Format::EIGHT_BIT_GREY ); ::rtl::OUString aSvg = ::rtl::OUString::createFromAscii( "m 0 0h5v10h5v-5h-10z" ); |