diff options
Diffstat (limited to 'basebmp/inc')
-rw-r--r-- | basebmp/inc/basebmp/accessor.hxx | 74 | ||||
-rw-r--r-- | basebmp/inc/basebmp/accessoradapters.hxx | 271 | ||||
-rw-r--r-- | basebmp/inc/basebmp/bitmapdevice.hxx | 381 | ||||
-rw-r--r-- | basebmp/inc/basebmp/clippedlinerenderer.hxx | 370 | ||||
-rw-r--r-- | basebmp/inc/basebmp/color.hxx | 80 | ||||
-rw-r--r-- | basebmp/inc/basebmp/debug.hxx | 58 | ||||
-rw-r--r-- | basebmp/inc/basebmp/drawmodes.hxx | 76 | ||||
-rw-r--r-- | basebmp/inc/basebmp/linerenderer.hxx | 186 | ||||
-rw-r--r-- | basebmp/inc/basebmp/metafunctions.hxx | 79 | ||||
-rw-r--r-- | basebmp/inc/basebmp/packedpixeliterator.hxx | 676 | ||||
-rw-r--r-- | basebmp/inc/basebmp/paletteimageaccessor.hxx | 141 | ||||
-rw-r--r-- | basebmp/inc/basebmp/pixeliterator.hxx | 362 | ||||
-rw-r--r-- | basebmp/inc/basebmp/scanlineformats.hxx | 82 | ||||
-rw-r--r-- | basebmp/inc/basebmp/stridedarrayiterator.hxx | 102 |
14 files changed, 2938 insertions, 0 deletions
diff --git a/basebmp/inc/basebmp/accessor.hxx b/basebmp/inc/basebmp/accessor.hxx new file mode 100644 index 000000000000..2718ad1bf5e9 --- /dev/null +++ b/basebmp/inc/basebmp/accessor.hxx @@ -0,0 +1,74 @@ +/************************************************************************* + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: accessor.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: thb $ $Date: 2006-05-31 09:49: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_ACCESSOR_HXX +#define INCLUDED_BASEBMP_ACCESSOR_HXX + +namespace basebmp +{ + +template<typename ValueType> class StandardAccessor +{ +public: + typedef ValueType value_type; + typedef ValueType data_type; + + template< class Iterator > + value_type operator()(Iterator const& i) const { return i.get(); } + value_type operator()(value_type const* i) const { return *i; } + + template< class Iterator, class Difference > + value_type operator()(Iterator const& i, Difference const& diff) const + { + return i.get(diff); + } + + template< typename V, class Iterator > + void set(V const& value, Iterator const& i) const + { + i.set( vigra::detail::RequiresExplicitCast<value_type>::cast(value) ); + } + + template< typename V, class Iterator, class Difference > + void set(V const& value, Iterator const& i, Difference const& diff) const + { + i.set( vigra::detail::RequiresExplicitCast<value_type>::cast(value), + diff ); + } +}; + +} // namespace basebmp + +#endif /* INCLUDED_BASEBMP_ACCESSOR_HXX */ diff --git a/basebmp/inc/basebmp/accessoradapters.hxx b/basebmp/inc/basebmp/accessoradapters.hxx new file mode 100644 index 000000000000..63c7e2ad25bc --- /dev/null +++ b/basebmp/inc/basebmp/accessoradapters.hxx @@ -0,0 +1,271 @@ +/************************************************************************* + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: accessoradapters.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: thb $ $Date: 2006-05-31 09:49: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_ACCESSORADAPTERS_HXX +#define INCLUDED_BASEBMP_ACCESSORADAPTERS_HXX + +#include "metafunctions.hxx" +#include "packedpixeliterator.hxx" +#include "paletteimageaccessor.hxx" + +namespace basebmp +{ + +/** Interpose given accessor's set methods with a binary function, + taking both old and new value. + */ +template< class WrappedAccessor, typename Functor > class BinarySetterFunctionAccessorAdapter : + public WrappedAccessor +{ +private: + Functor maFunctor; + +public: + BinarySetterFunctionAccessorAdapter() : + WrappedAccessor(), + maFunctor() + {} + + explicit BinarySetterFunctionAccessorAdapter( WrappedAccessor accessor ) : + WrappedAccessor( accessor ), + maFunctor() + {} + + BinarySetterFunctionAccessorAdapter( WrappedAccessor accessor, + Functor functor ) : + WrappedAccessor( accessor ), + maFunctor( functor ) + {} + + template< typename V, class Iterator > + void set(V const& value, Iterator const& i) const + { + WrappedAccessor::set( + maFunctor(WrappedAccessor::operator()(i), + value), + i ); + } + + template< typename V, class Iterator, class Difference > + void set(V const& value, Iterator const& i, Difference const& diff) const + { + WrappedAccessor::set( + maFunctor(WrappedAccessor::operator()(i,diff), + value), + i, + diff ); + } +}; + +/** Read from two input iterators, pipe that through given functor, and write result + to the first iterator + + Note: iterator type is fixed, to facilitate type-safe mask + optimizations (see below) + */ +template< class WrappedAccessor1, + class WrappedAccessor2, + class Iterator1, + class Iterator2, + typename Functor > class BinaryInputAccessorAdapter +{ +private: + WrappedAccessor1 ma1stAccessor; + WrappedAccessor2 ma2ndAccessor; + Functor maFunctor; + +public: + typedef typename WrappedAccessor1::value_type value_type; + + BinaryInputAccessorAdapter() : + ma1stAccessor(), + ma2ndAccessor(), + maFunctor() + {} + + explicit BinaryInputAccessorAdapter( WrappedAccessor1 accessor1 ) : + ma1stAccessor( accessor1 ), + ma2ndAccessor(), + maFunctor() + {} + + BinaryInputAccessorAdapter( WrappedAccessor1 accessor1, + WrappedAccessor2 accessor2 ) : + ma1stAccessor( accessor1 ), + ma2ndAccessor( accessor2 ), + maFunctor() + {} + + BinaryInputAccessorAdapter( WrappedAccessor1 accessor1, + WrappedAccessor2 accessor2, + Functor func ) : + ma1stAccessor( accessor1 ), + ma2ndAccessor( accessor2 ), + maFunctor( func ) + {} + + value_type operator()(Iterator1 const& i, Iterator2 const& j) const + { + return maFunctor(ma1stAccessor(i), + ma2ndAccessor(j)); + } + template< class Difference > + value_type operator()(Iterator1 const& i, Iterator2 const& j, Difference const& diff) const + { + return maFunctor(ma1stAccessor(i,diff), + ma2ndAccessor(j,diff)); + } + + template< typename V > + void set(V const& value, Iterator1 const& i, Iterator2 const& j) const + { + ma1stAccessor.set( + maFunctor(ma1stAccessor(i), + ma2ndAccessor(j)), + i ); + } + + template< typename V, class Difference > + void set(V const& value, Iterator1 const& i, Iterator2 const& j, Difference const& diff) const + { + ma1stAccessor.set( + maFunctor(ma1stAccessor(i,diff), + ma2ndAccessor(j,diff)), + i, + diff ); + } +}; + +// Some common accessor wrappers +// ------------------------------------------------------------ + +// XOR +template< typename T > struct XorFunctor +{ + T operator()( T v1, T v2 ) const { return v1 ^ v2; } +}; +template< class WrappedAccessor > struct xorAccessor +{ + typedef BinarySetterFunctionAccessorAdapter< WrappedAccessor, + XorFunctor< typename WrappedAccessor::value_type > > + type; +}; + +// Mask +template< typename T > struct MaskFunctor +{ + /** Mask v with state of m + + @return v, if m != 0, and vigra::NumericTraits<T>::zero + otherwise. + */ + T operator()( T v, T m ) const + { + // TODO(Q3): use traits to get unsigned type for T (if + // not already) + + // mask will be 0, iff m == 0, and 1 otherwise + const T mask( static_cast<unsigned int>(m | -m) >> (sizeof(unsigned int)*8 - 1) ); + return mask*v; + } +}; +// Faster mask (assuming mask accessor output is already either 0 or 1) +template< typename T > struct FastMaskFunctor +{ + T operator()( T v, T m ) const + { + return m*v; + } +}; +// Chosen function crucially depends on iterator - we can choose the +// faster direkt masking for 1bpp packed pixel iterators +template< class WrappedAccessor, + class MaskAccessor, + class Iterator, + class MaskIterator > struct maskedAccessor +{ + typedef BinaryInputAccessorAdapter< WrappedAccessor, + MaskAccessor, + Iterator, + MaskIterator, + MaskFunctor< typename WrappedAccessor::value_type > > + type; +}; +// partial specialization, to use fast 1bpp mask function for +// corresponding iterator type +template< class WrappedAccessor, + class MaskAccessor, + class Iterator > struct maskedAccessor< WrappedAccessor, + MaskAccessor, + Iterator, + PackedPixelIterator< typename MaskAccessor::data_type, + typename MaskAccessor::value_type, + 1, + true > > +{ + typedef BinaryInputAccessorAdapter< WrappedAccessor, + MaskAccessor, + Iterator, + PackedPixelIterator< typename MaskAccessor::data_type, + typename MaskAccessor::value_type, + 1, + true >, + FastMaskFunctor< typename WrappedAccessor::value_type > > + type; +}; +template< class WrappedAccessor, + class MaskAccessor, + class Iterator > struct maskedAccessor< WrappedAccessor, + MaskAccessor, + Iterator, + PackedPixelIterator< typename MaskAccessor::data_type, + typename MaskAccessor::value_type, + 1, + false > > +{ + typedef BinaryInputAccessorAdapter< WrappedAccessor, + MaskAccessor, + Iterator, + PackedPixelIterator< typename MaskAccessor::data_type, + typename MaskAccessor::value_type, + 1, + false >, + FastMaskFunctor< typename WrappedAccessor::value_type > > + type; +}; + +} // namespace basebmp + +#endif /* INCLUDED_BASEBMP_ACCESSORADAPTERS_HXX */ diff --git a/basebmp/inc/basebmp/bitmapdevice.hxx b/basebmp/inc/basebmp/bitmapdevice.hxx new file mode 100644 index 000000000000..3fd6401a6be6 --- /dev/null +++ b/basebmp/inc/basebmp/bitmapdevice.hxx @@ -0,0 +1,381 @@ +/************************************************************************* + * + * $RCSfile: bitmapdevice.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: thb $ $Date: 2006-05-31 09:49:41 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 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_BITMAPDEVICE_HXX +#define INCLUDED_BASEBMP_BITMAPDEVICE_HXX + +#ifndef _SAL_TYPES_H_ +#include <sal/types.h> +#endif +#ifndef INCLUDED_BASEBMP_DRAWMODES_HXX +#include "drawmodes.hxx" +#endif + +#include <boost/scoped_ptr.hpp> +#include <boost/shared_ptr.hpp> +#include <boost/noncopyable.hpp> + + +/* What to do first: + + 1,8,24 bpp, with blt, fill/drawPolygon, drawLine & get/setPixel + + Then: + + all other formats, top down vs. bottom up + + Last: + + Modulation, clip + + */ + +namespace basegfx +{ + class B2IPoint; + class B2DPoint; + class B2IVector; + class B2IRange; + class B2DPolygon; + class B2DPolyPolygon; +} + +namespace basebmp +{ + +// Temporary. Use like the tools color object +class Color; +typedef boost::shared_ptr< class BitmapDevice > BitmapDeviceSharedPtr; +typedef boost::shared_ptr< sal_uInt8 > RawMemorySharedPtr; + +struct ImplBitmapDevice; + +/** Definition of BitmapDevice interface + + Use createBitmapDevice() factory method to create one instance. + + Implementation note: the clip mask and bitmap parameter instances + of BitmapDevice that are passed to individual BitmapDevice + instances work best with 1 bit MSB masks for the clip and a format + matching that of the target BitmapDevice for the other + parameters. Everything else is accepted, but potentially slow. + */ +class BitmapDevice : private boost::noncopyable +{ +public: + /** Query size of device in pixel + */ + basegfx::B2IVector getSize() const; + + /** Query whether buffer starts with 0th scanline + + @return true, if the buffer memory starts with the 0th + scanline, and false if it starts with the last + */ + bool isTopDown() const; + + /** Query type of scanline memory format + */ + sal_Int32 getScanlineFormat() const; + + /** Query byte offset to get from scanline n to scanline n+1 + + @return the scanline stride in bytes. In the case of + bottom-first formats, this offset will be negative. + */ + sal_Int32 getScanlineStride() const; + + /** Get pointer to frame buffer + */ + RawMemorySharedPtr getBuffer() const; + + /** Get pointer to palette + + @return pointer to array of getPaletteEntryCount() Color + entries, if this is a palette format. If not, NULL is + returned. + */ + const Color* getPalette() const; + + /** Query number of palette entries + */ + const sal_Int32 getPaletteEntryCount() const; + + /** Clear whole device with given color + */ + void clear( Color fillColor ); + + /** Set given pixel to specified color + + @param rPt + Pixel to set + + @param pixelColor + Color value to set the pixel to + + @param drawMode + Draw mode to use when changing the pixel value + */ + void setPixel( const basegfx::B2IPoint& rPt, + Color pixelColor, + DrawMode drawMode ); + + /** Set given pixel to specified color + + @param rPt + Pixel to set + + @param pixelColor + Color value to set the pixel to + + @param drawMode + Draw mode to use when changing the pixel value + + @param rClip + Clip mask to use. If the clip mask is 0 at the given pixel + position, no change will happen. + */ + void setPixel( const basegfx::B2IPoint& rPt, + Color pixelColor, + DrawMode drawMode, + const BitmapDeviceSharedPtr& rClip ); + + /** Get color value at given pixel + */ + Color getPixel( const basegfx::B2IPoint& rPt ); + + /** Draw a line + + @param rPt1 + Start point of the line + + @param rPt2 + End point of the line. If the analytical line from rP1 to rPt2 + (with the actual pixel positions are assumed to be the center + of the pixel) is exactly in the middle between two pixel, this + method always selects the pixel closer to rPt1. + + @param lineColor + Color value to draw the line with + + @param drawMode + Draw mode to use when changing the pixel value + */ + void drawLine( const basegfx::B2IPoint& rPt1, + const basegfx::B2IPoint& rPt2, + Color lineColor, + DrawMode drawMode ); + + /** Draw a line + + @param rPt1 + Start point of the line + + @param rPt2 + End point of the line. If the analytical line from rP1 to rPt2 + (with the actual pixel positions are assumed to be the center + of the pixel) is exactly in the middle between two pixel, this + method always selects the pixel closer to rPt1. + + @param lineColor + Color value to draw the line with + + @param drawMode + Draw mode to use when changing the pixel value + + @param rClip + Clip mask to use. Pixel where the corresponding clip mask + pixel is 0 will not be touched. + */ + void drawLine( const basegfx::B2IPoint& rPt1, + const basegfx::B2IPoint& rPt2, + Color lineColor, + DrawMode drawMode, + const BitmapDeviceSharedPtr& rClip ); + + void drawPolygon( const basegfx::B2DPolygon& rPoly, + Color lineColor, + DrawMode drawMode ); + void drawPolygon( const basegfx::B2DPolygon& rPoly, + Color lineColor, + DrawMode drawMode, + const BitmapDeviceSharedPtr& rClip ); + + void fillPolyPolygon( const basegfx::B2DPolyPolygon& rPoly, + Color fillColor, + DrawMode drawMode ); + void fillPolyPolygon( const basegfx::B2DPolyPolygon& rPoly, + Color fillColor, + DrawMode drawMode, + const BitmapDeviceSharedPtr& rClip ); + + void drawBitmap( const BitmapDeviceSharedPtr& rSrcBitmap, + const basegfx::B2IRange& rSrcRect, + const basegfx::B2IRange& rDstRect, + DrawMode drawMode ); + void drawBitmap( const BitmapDeviceSharedPtr& rSrcBitmap, + const basegfx::B2IRange& rSrcRect, + const basegfx::B2IRange& rDstRect, + DrawMode drawMode, + const BitmapDeviceSharedPtr& rClip ); + + void drawMaskedColor( Color rSrcColor, + const BitmapDeviceSharedPtr& rAlphaMask, + const basegfx::B2IRange& rSrcRect, + const basegfx::B2IPoint& rDstPoint ); + void drawMaskedColor( Color rSrcColor, + const BitmapDeviceSharedPtr& rAlphaMask, + const basegfx::B2IRange& rSrcRect, + const basegfx::B2IPoint& rDstPoint, + const BitmapDeviceSharedPtr& rClip ); + + void drawMaskedBitmap( const BitmapDeviceSharedPtr& rSrcBitmap, + const BitmapDeviceSharedPtr& rMask, + const basegfx::B2IRange& rSrcRect, + const basegfx::B2IRange& rDstRect, + DrawMode drawMode ); + void drawMaskedBitmap( const BitmapDeviceSharedPtr& rSrcBitmap, + const BitmapDeviceSharedPtr& rMask, + const basegfx::B2IRange& rSrcRect, + const basegfx::B2IRange& rDstRect, + DrawMode drawMode, + const BitmapDeviceSharedPtr& rClip ); + +protected: + BitmapDevice( const basegfx::B2IVector& rSize, + bool bTopDown, + sal_Int32 nScanlineFormat, + sal_Int32 nScanlineStride, + const RawMemorySharedPtr& rMem ); + + virtual ~BitmapDevice(); + +private: + virtual bool isCompatibleBitmap( const BitmapDeviceSharedPtr& bmp ) const = 0; + virtual bool isCompatibleClipMask( const BitmapDeviceSharedPtr& bmp ) const = 0; + virtual bool isCompatibleAlphaMask( const BitmapDeviceSharedPtr& bmp ) const = 0; + + virtual const Color* getPalette_i() const = 0; + virtual const sal_Int32 getPaletteEntryCount_i() const = 0; + + virtual void clear_i( Color fillColor ) = 0; + + virtual void setPixel_i( const basegfx::B2IPoint& rPt, + Color lineColor, + DrawMode drawMode ) = 0; + virtual void setPixel_i( const basegfx::B2IPoint& rPt, + Color lineColor, + DrawMode drawMode, + const BitmapDeviceSharedPtr& rClip ) = 0; + + virtual Color getPixel_i( const basegfx::B2IPoint& rPt ) = 0; + + virtual void drawLine_i( const basegfx::B2DPoint& rPt1, + const basegfx::B2DPoint& rPt2, + Color lineColor, + DrawMode drawMode ) = 0; + virtual void drawLine_i( const basegfx::B2DPoint& rPt1, + const basegfx::B2DPoint& rPt2, + Color lineColor, + DrawMode drawMode, + const BitmapDeviceSharedPtr& rClip ) = 0; + + virtual void drawPolygon_i( const basegfx::B2DPolygon& rPoly, + Color lineColor, + DrawMode drawMode ) = 0; + virtual void drawPolygon_i( const basegfx::B2DPolygon& rPoly, + Color lineColor, + DrawMode drawMode, + const BitmapDeviceSharedPtr& rClip ) = 0; + + virtual void fillPolyPolygon_i( const basegfx::B2DPolyPolygon& rPoly, + Color fillColor, + DrawMode drawMode, + const basegfx::B2IRange& rBounds ) = 0; + virtual void fillPolyPolygon_i( const basegfx::B2DPolyPolygon& rPoly, + Color fillColor, + DrawMode drawMode, + const basegfx::B2IRange& rBounds, + const BitmapDeviceSharedPtr& rClip ) = 0; + + // must work with *this == rSrcBitmap! + virtual void drawBitmap_i( const BitmapDeviceSharedPtr& rSrcBitmap, + const basegfx::B2IRange& rSrcRect, + const basegfx::B2IRange& rDstRect, + DrawMode drawMode ) = 0; + virtual void drawBitmap_i( const BitmapDeviceSharedPtr& rSrcBitmap, + const basegfx::B2IRange& rSrcRect, + const basegfx::B2IRange& rDstRect, + DrawMode drawMode, + const BitmapDeviceSharedPtr& rClip ) = 0; + + // must work with *this == rSrcBitmap! + virtual void drawMaskedColor_i( Color rSrcColor, + const BitmapDeviceSharedPtr& rAlphaMask, + const basegfx::B2IRange& rSrcRect, + const basegfx::B2IPoint& rDstPoint ) = 0; + virtual void drawMaskedColor_i( Color rSrcColor, + const BitmapDeviceSharedPtr& rAlphaMask, + const basegfx::B2IRange& rSrcRect, + const basegfx::B2IPoint& rDstPoint, + const BitmapDeviceSharedPtr& rClip ) = 0; + + // must work with *this == rSrcBitmap! + virtual void drawMaskedBitmap_i( const BitmapDeviceSharedPtr& rSrcBitmap, + const BitmapDeviceSharedPtr& rMask, + const basegfx::B2IRange& rSrcRect, + const basegfx::B2IRange& rDstRect, + DrawMode drawMode ) = 0; + virtual void drawMaskedBitmap_i( const BitmapDeviceSharedPtr& rSrcBitmap, + const BitmapDeviceSharedPtr& rMask, + const basegfx::B2IRange& rSrcRect, + const basegfx::B2IRange& rDstRect, + DrawMode drawMode, + const BitmapDeviceSharedPtr& rClip ) = 0; + + boost::scoped_ptr< ImplBitmapDevice > mpImpl; +}; + +/** Factory method to create a BitmapDevice for given scanline format + */ +BitmapDeviceSharedPtr createBitmapDevice( const basegfx::B2IVector& rSize, + bool bTopDown, + sal_Int32 nScanlineFormat ); + +} + +#endif /* INCLUDED_BASEBMP_BITMAPDEVICE_HXX */ diff --git a/basebmp/inc/basebmp/clippedlinerenderer.hxx b/basebmp/inc/basebmp/clippedlinerenderer.hxx new file mode 100644 index 000000000000..92be0308a5c7 --- /dev/null +++ b/basebmp/inc/basebmp/clippedlinerenderer.hxx @@ -0,0 +1,370 @@ +/************************************************************************* + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: clippedlinerenderer.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: thb $ $Date: 2006-05-31 09:49: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_CLIPPEDLINERENDERER_HXX +#define INCLUDED_BASEBMP_CLIPPEDLINERENDERER_HXX + +#include <basegfx/tools/rectcliptools.hxx> + +namespace basebmp +{ + +// factored-out bresenham setup code, which is used from two different +// places in renderClippedLine() below. Admittedly messy for the long +// parameter list... +inline bool prepareClip( sal_Int32 a1, + sal_Int32 a2, + sal_Int32 b1, + sal_Int32 da, + sal_Int32 db, + sal_Int32& o_as, + sal_Int32& o_bs, + int sa, + int sb, + sal_Int32& io_rem, + int& o_n, + sal_uInt32 clipCode1, + sal_uInt32 clipCount1, + sal_uInt32 clipCode2, + sal_uInt32 clipCount2, + sal_Int32 aMin, + sal_uInt32 aMinFlag, + sal_Int32 aMax, + sal_uInt32 aMaxFlag, + sal_Int32 bMin, + sal_uInt32 bMinFlag, + sal_Int32 bMax, + sal_uInt32 bMaxFlag, + bool bRoundTowardsPt2 ) +{ + int ca, cb; + if( clipCode1 ) + { + if( clipCode1 & aMinFlag ) + { + ca = 2*db*(aMin - a1); + o_as = aMin; + } + else if( clipCode1 & aMaxFlag ) + { + ca = 2*db*(a1 - aMax); + o_as = aMax; + } + + if( clipCode1 & bMinFlag ) + { + cb = 2*da*(bMin - b1); + o_bs = bMin; + } + else if( clipCode1 & bMaxFlag ) + { + cb = 2*da*(b1 - bMax); + o_bs = bMax; + } + + if( clipCount1 == 2 ) + clipCode1 &= (ca + da < cb + !bRoundTowardsPt2) ? ~(aMin|aMax) : ~(bMin|bMax); + + if( clipCode1 & (aMin|aMax) ) + { + cb = (ca + da - !bRoundTowardsPt2) / (2*da); + + if( sb >= 0 ) + { + o_bs = b1 + cb; + if( o_bs > bMax ) + return; + } + else + { + o_bs = b1 - cb; + if( o_bs < bMin ) + return; + } + + io_rem += ca - 2*da*cb; + } + else + { + ca = (cb - da + 2*db - bRoundTowardsPt2) / (2*db); + if( sa >= 0 ) + { + o_as = a1 + ca; + if( o_as > aMax ) + return; + } + else + { + o_as = a1 - ca; + if( o_as < aMin ) + return; + } + + io_rem += 2*db*ca - cb; + } + } + else + { + o_as = a1; o_bs = b1; + } + + bool bRetVal = false; + if( clipCode2 ) + { + if( clipCount2 == 2 ) + { + ca = 2*db*((clipCode2 & aMin) ? a1 - aMin : aMax - a1); + cb = 2*da*((clipCode2 & bMin) ? b1 - bMin : bMax - b1); + clipCode2 &= (cb + da < ca + bRoundTowardsPt2) ? ~(aMin|aMax) : ~(bMin|bMax); + } + + if( clipCode2 & (aMin|aMax) ) + o_n = (clipCode2 & aMin) ? o_as - aMin : aMax - o_as; + else + { + o_n = (clipCode2 & bMin) ? o_bs - bMin : bMax - o_bs; + bRetVal = true; + } + } + else + o_n = (a2 >= o_as) ? a2 - o_as : o_as - a2; + + return bRetVal; +} + + +/** Render line to image iterators, clip against given rectangle + + This method renders a line from aPt1 to aPt2, clipped against + rClipRect (the clipping will take place pixel-perfect, i.e. as if + the original bresenham-rendered line would have been clipped each + pixel individually. No slight shifts compared to unclipped lines). + + @param aPt1 + Start point of the line + + @param aPt2 + End point of the line + + @param rClipRect + Rectangle to clip against + + @param color + Color value to render the line with + + @param begin + left-top image iterator + + @param end + right-bottom image iterator + + @param acc + Image accessor + + @param bRoundTowardsPt2 + Rounding mode to use. Giving false here results in line pixel tend + towards pt1, i.e. when a pixel exactly hits the middle between two + pixel, the pixel closer to pt1 will be chosen. Giving true here + makes renderClippedLine() choose pt2 in those cases. + */ +template< class Iterator, class Accessor > +void renderClippedLine( basegfx::B2IPoint aPt1, + basegfx::B2IPoint aPt2, + const basegfx::B2IRange& rClipRect, + typename Accessor::value_type color, + Iterator begin, + Iterator end, + Accessor acc, + bool bRoundTowardsPt2=false ) +{ + // Algorithm according to Steven Eker's 'Pixel-perfect line clipping', + // Graphics Gems V, pp. 314-322 + sal_uInt32 clipCode1 = basegfx::tools::getCohenSutherlandClipFlags(aPt1, + rClipRect); + sal_uInt32 clipCode2 = basegfx::tools::getCohenSutherlandClipFlags(aPt2, + rClipRect); + + if( clipCode1 & clipCode2 ) + return; // line fully clipped away + + sal_uInt32 clipCount1 = basegfx::tools::getNumberOfClipPlanes(clipCode1); + sal_uInt32 clipCount2 = basegfx::tools::getNumberOfClipPlanes(clipCode2); + + if( (clipCode1 != 0 && clipCode2 == 0) + || (clipCount1 == 2 && clipCount2 == 1) ) + { + std::swap(clipCount2,clipCount1); + std::swap(clipCode2,clipCode1); + std::swap(aPt1,aPt2); + bRoundTowardsPt2 = !bRoundTowardsPt2; + } + + const sal_Int32 x1 = aPt1.getX(); + const sal_Int32 x2 = aPt2.getX(); + const sal_Int32 y1 = aPt1.getY(); + const sal_Int32 y2 = aPt2.getY(); + + // TODO(E1): This might overflow + sal_Int32 adx = x2 - x1; + int sx = 1; + if( adx < 0 ) + { + adx *= -1; + sx = -1; + } + + // TODO(E1): This might overflow + sal_Int32 ady = y2 - y1; + int sy = 1; + if( ady < 0 ) + { + ady *= -1; + sy = -1; + } + + int n = 0; + sal_Int32 xs = x1; + sal_Int32 ys = y1; + if( adx >= ady ) + { + // semi-horizontal line + sal_Int32 rem = 2*ady - adx - !bRoundTowardsPt2; + + const bool bUseAlternateBresenham( + prepareClip(x1, x2, y1, adx, ady, xs, ys, sx, sy, + rem, n, clipCode1, clipCount1, clipCode1, clipCount2, + rClipRect.getMinX(), basegfx::tools::RectClipFlags::LEFT, + rClipRect.getMaxX(), basegfx::tools::RectClipFlags::RIGHT, + rClipRect.getMinY(), basegfx::tools::RectClipFlags::TOP, + rClipRect.getMaxY(), basegfx::tools::RectClipFlags::BOTTOM, + bRoundTowardsPt2 )); + const sal_Int32 diff = 2*(ady - adx); + if( bUseAlternateBresenham ) + { + while(true) + { + plot(xs,ys); + + if( rem >= 0 ) + { + if( --n < 0 ) + break; + rem += diff; + ys += sy; + } + else + rem += 2*ady; + + xs += sx; + } + } + else + { + while(true) + { + plot(xs,ys); + + if( --n < 0 ) + break; + if( rem >= 0 ) + { + rem += diff; + ys += sy; + } + else + rem += 2*ady; + + xs += sx; + } + } + } + else + { + // semi-vertical line + sal_Int32 rem = 2*adx - ady - !bRoundTowardsPt2; + + const bool bUseAlternateBresenham( + prepareClip(y1, y2, x1, ady, adx, ys, xs, sy, sx, + rem, clipCode1, clipCount1, clipCode1, clipCount2, + rClipRect.getMinY(), basegfx::tools::RectClipFlags::TOP, + rClipRect.getMaxY(), basegfx::tools::RectClipFlags::BOTTOM, + rClipRect.getMinX(), basegfx::tools::RectClipFlags::LEFT, + rClipRect.getMaxX(), basegfx::tools::RectClipFlags::RIGHT, + bRoundTowardsPt2 )); + const sal_Int32 diff = 2*(ady - adx); + if( bUseAlternateBresenham ) + { + while(true) + { + plot(xy,ys); + + if( rem >= 0 ) + { + if( --n < 0 ) + break; + rem += diff; + xs += sx; + } + else + rem += 2*adx; + + ys += sy; + } + } + else + { + while(true) + { + plot(xs,ys); + + if( --n < 0 ) + break; + if( rem >= 0 ) + { + rem += diff; + xs += sx; + } + else + rem += 2*adx; + + ys += sy; + } + } + } +} + +} // namespace basebmp + +#endif /* INCLUDED_BASEBMP_CLIPPEDLINERENDERER_HXX */ diff --git a/basebmp/inc/basebmp/color.hxx b/basebmp/inc/basebmp/color.hxx new file mode 100644 index 000000000000..21ae86e897dd --- /dev/null +++ b/basebmp/inc/basebmp/color.hxx @@ -0,0 +1,80 @@ +/************************************************************************* + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: color.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: thb $ $Date: 2006-05-31 09:49: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_COLOR_HXX +#define INCLUDED_BASEBMP_COLOR_HXX + +#ifndef _SAL_TYPES_H_ +#include <sal/types.h> +#endif +#include <math.h> + +namespace basebmp +{ + +class Color +{ +private: + sal_uInt32 mnColor; + +public: + Color() : mnColor(0) {} + Color( sal_uInt32 nVal ) : mnColor(nVal) {} + Color( sal_uInt8 nRed, sal_uInt8 nGreen, sal_uInt8 nBlue ) : + mnColor( (nRed << 16) | (nGreen << 8) | nBlue ) + {} + + void setRed( sal_uInt8 nRed ) { mnColor |= nRed << 16; mnColor &= ~((sal_uInt32)nRed << 16); } + void setGreen( sal_uInt8 nGreen ) { mnColor |= nGreen << 8; mnColor &= ~((sal_uInt32)nGreen << 8); } + void setBlue( sal_uInt8 nBlue ) { mnColor |= nBlue; mnColor &= ~(sal_uInt32)nBlue; } + + sal_uInt8 getRed() const { return (mnColor & 0x00FF0000U) >> 16; } + sal_uInt8 getGreen() const { return (mnColor & 0x0000FF00U) >> 8; } + sal_uInt8 getBlue() const { return mnColor & 0x000000FFU; } + + sal_uInt32 getValue() const { return mnColor; } + operator sal_uInt32() const { return mnColor; } + + Color operator-( Color col ) const { return Color(getRed()-col.getRed(), + getGreen()-col.getGreen(), + getBlue()-col.getBlue()); } + double magnitude() const { return sqrt(getRed()*getRed() + + getGreen()*getGreen() + + getBlue()*getBlue()); } +}; + +} // namespace basebmp + +#endif /* INCLUDED_BASEBMP_COLOR_HXX */ diff --git a/basebmp/inc/basebmp/debug.hxx b/basebmp/inc/basebmp/debug.hxx new file mode 100644 index 000000000000..62cc8eaeb646 --- /dev/null +++ b/basebmp/inc/basebmp/debug.hxx @@ -0,0 +1,58 @@ +/************************************************************************* + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: debug.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: thb $ $Date: 2006-05-31 09:49:42 $ + * + * 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_DEBUG_HXX +#define INCLUDED_BASEBMP_DEBUG_HXX + +#include <iostream> +#include <boost/shared_ptr.hpp> + +namespace basebmp +{ + class BitmapDevice; + + /** Dump content of BitmapDevice to given output stream. + + @param rDevice + Device whose content should be dumped. + + @param rOutputStream + Stream to write output to. + */ + void debugDump( const boost::shared_ptr< BitmapDevice >& rDevice, + ::std::ostream& rOutputStream ); +} + +#endif /* INCLUDED_BASEBMP_DEBUG_HXX */ diff --git a/basebmp/inc/basebmp/drawmodes.hxx b/basebmp/inc/basebmp/drawmodes.hxx new file mode 100644 index 000000000000..f09d5c221383 --- /dev/null +++ b/basebmp/inc/basebmp/drawmodes.hxx @@ -0,0 +1,76 @@ +/************************************************************************* + * + * $RCSfile: drawmodes.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: thb $ $Date: 2006-05-31 09:49:42 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 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 + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef INCLUDED_BASEBMP_DRAWMODES_HXX +#define INCLUDED_BASEBMP_DRAWMODES_HXX + +/* Definition of Draw modes */ + +namespace basebmp +{ + enum DrawMode + { + DrawMode_PAINT, + DrawMode_XOR + }; +} + +#endif /* INCLUDED_BASEBMP_DRAWMODES_HXX */ diff --git a/basebmp/inc/basebmp/linerenderer.hxx b/basebmp/inc/basebmp/linerenderer.hxx new file mode 100644 index 000000000000..0493e9571b8a --- /dev/null +++ b/basebmp/inc/basebmp/linerenderer.hxx @@ -0,0 +1,186 @@ +/************************************************************************* + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: linerenderer.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: thb $ $Date: 2006-05-31 09:49:42 $ + * + * 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_LINERENDERER_HXX +#define INCLUDED_BASEBMP_LINERENDERER_HXX + +#ifndef _BGFX_POINT_B2IPOINT_HXX +#include <basegfx/point/b2ipoint.hxx> +#endif + +/* Scan-converting lines */ + +namespace basebmp +{ + +/** Render line with Bresenham + + This function renders the line given by rPt1 and rPt2 using the + Bresenham algorithm with the specified color value. Make sure rPt1 + and rPt1 are valid coordinates in the image given by begin and + end, since no clipping takes place. + + @param aPt1 + Start point of the line + + @param aPt2 + End point of the line + + @param color + Color value to render the line with + + @param begin + left-top image iterator + + @param end + right-bottom image iterator + + @param acc + Image accessor + + @param bRoundTowardsPt2 + Rounding mode to use. Giving false here results in line pixel tend + towards pt1, i.e. when a pixel exactly hits the middle between two + pixel, the pixel closer to pt1 will be chosen. Giving true here + makes renderClippedLine() choose pt2 in those cases. + */ +template< class Iterator, class Accessor > +void renderLine( const basegfx::B2IPoint& rPt1, + const basegfx::B2IPoint& rPt2, + typename Accessor::value_type color, + Iterator begin, + Iterator end, + Accessor acc, + bool bRoundTowardsPt2=false ) +{ + // code inspired by Paul Heckbert's Digital Line Drawing + // (Graphics Gems, Academic Press 1990) + const sal_Int32 x1 = rPt1.getX(); + const sal_Int32 x2 = rPt2.getX(); + const sal_Int32 y1 = rPt1.getY(); + const sal_Int32 y2 = rPt2.getY(); + + // TODO(E1): This might overflow + sal_Int32 adx = x2 - x1; + int sx = 1; + if( adx < 0 ) + { + adx *= -1; + sx = -1; + } + + // TODO(E1): This might overflow + sal_Int32 ady = y2 - y1; + int sy = 1; + if( ady < 0 ) + { + ady *= -1; + sy = -1; + } + + // TODO(P3): handle horizontal and vertical lines specially + sal_Int32 xs = x1; + sal_Int32 ys = y1; + if( adx >= ady ) + { + // semi-horizontal line + sal_Int32 rem = 2*ady - adx - !bRoundTowardsPt2; + adx *= 2; + ady *= 2; + + Iterator currIter( begin + vigra::Diff2D(0,ys) ); + typename Iterator::row_iterator rowIter( currIter.rowIterator() + xs ); + while(true) + { + acc.set(color, rowIter); + + if( xs == x2 ) + return; + + if( rem >= 0 ) + { + ys += sy; + xs += sx; + currIter.y += sy; + rowIter = currIter.rowIterator() + xs; + rem -= adx; + } + else + { + xs += sx; + rowIter += sx; + } + + rem += ady; + } + } + else + { + // semi-vertical line + sal_Int32 rem = 2*adx - ady - !bRoundTowardsPt2; + adx *= 2; + ady *= 2; + + Iterator currIter( begin + vigra::Diff2D(xs,0) ); + typename Iterator::column_iterator colIter( currIter.columnIterator() + ys ); + while(true) + { + acc.set(color, colIter); + + if( ys == y2 ) + return; + + if( rem >= 0 ) + { + xs += sx; + ys += sy; + currIter.x += sx; + colIter = currIter.columnIterator() + ys; + rem -= ady; + } + else + { + ys += sy; + colIter += sy; + } + + rem += adx; + } + } +} + +} // namespace basebmp + +#endif /* INCLUDED_BASEBMP_LINERENDERER_HXX */ diff --git a/basebmp/inc/basebmp/metafunctions.hxx b/basebmp/inc/basebmp/metafunctions.hxx new file mode 100644 index 000000000000..cdef37548e7b --- /dev/null +++ b/basebmp/inc/basebmp/metafunctions.hxx @@ -0,0 +1,79 @@ +/************************************************************************* + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: metafunctions.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: thb $ $Date: 2006-05-31 09:49:42 $ + * + * 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_METAFUNCTIONS_HXX +#define INCLUDED_BASEBMP_METAFUNCTIONS_HXX + +namespace basebmp +{ + +// TODO(Q3): move to generic place (o3tl?) + +/// template meta function: add const qualifier, if given 2nd type has it +template<typename A, typename B> struct clone_const +{ + typedef B type; +}; +template<typename A, typename B> struct clone_const<const A,B> +{ + typedef const B type; +}; + +/// template meta function: remove const qualifier from plain type +template <typename T> struct remove_const +{ + typedef T type; +}; +template <typename T> struct remove_const<const T> +{ + typedef T type; +}; + +/// returns true, if given number is strictly less than 0 +template< typename T > inline bool is_negative( T x ) +{ + return x < 0; +} + +/// Overload for ints (branch-free) +inline bool is_negative( int x ) +{ + // force logic shift (result for signed shift right is undefined) + return static_cast<unsigned int>(x) >> (sizeof(int)*8-1); +} + +} // namespace basebmp + +#endif /* INCLUDED_BASEBMP_METAFUNCTIONS_HXX */ diff --git a/basebmp/inc/basebmp/packedpixeliterator.hxx b/basebmp/inc/basebmp/packedpixeliterator.hxx new file mode 100644 index 000000000000..48330d5c27ad --- /dev/null +++ b/basebmp/inc/basebmp/packedpixeliterator.hxx @@ -0,0 +1,676 @@ +/************************************************************************* + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: packedpixeliterator.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: thb $ $Date: 2006-05-31 09:49:42 $ + * + * 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_PACKEDPIXELITERATOR_HXX +#define INCLUDED_BASEBMP_PACKEDPIXELITERATOR_HXX + +#include "metafunctions.hxx" +#include "stridedarrayiterator.hxx" + +#include <boost/static_assert.hpp> +#include <vigra/metaprogramming.hxx> +#include <vigra/diff2d.hxx> + +namespace basebmp +{ + +/// Get bitmask for data at given intra-word position, for given bit depth +template< typename data_type, int bits_per_pixel, bool MsbFirst, typename difference_type > inline data_type get_mask( difference_type d ) +{ + BOOST_STATIC_ASSERT(bits_per_pixel > 0); + BOOST_STATIC_ASSERT(sizeof(data_type)*8 % bits_per_pixel == 0); + BOOST_STATIC_ASSERT(sizeof(data_type)*8 / bits_per_pixel > 1); + BOOST_STATIC_ASSERT(vigra::TypeTraits<data_type>::isPOD::asBool); + + const unsigned int nIntraWordPositions( sizeof(data_type)*8 / bits_per_pixel ); + + // create bits_per_pixel 1s shift to intra-word position + return ((~(~0 << bits_per_pixel)) << bits_per_pixel*(MsbFirst ? + (nIntraWordPositions-1 - (d % nIntraWordPositions)) : + (d % nIntraWordPositions))); +} + +template< int num_intraword_positions, int bits_per_pixel, bool MsbFirst, typename difference_type > inline difference_type get_shift( difference_type remainder ) +{ + return bits_per_pixel*(MsbFirst ? + (num_intraword_positions - 1 - remainder) : + remainder); +} + +template< typename Datatype, + typename Valuetype, + int bits_per_pixel, + bool MsbFirst > class PackedPixelColumnIterator +{ +public: + // no reference, no index_reference type here + typedef Datatype data_type; + typedef Valuetype value_type; + typedef int difference_type; + typedef image_traverser_tag iterator_category; + + typedef typename remove_const<data_type>::type mask_type; + typedef data_type* pointer; + typedef StridedArrayIterator< data_type > MoveY; + + enum { + /** The number of pixel within a single data_type value + */ + num_intraword_positions=sizeof(data_type)*8/bits_per_pixel, + /** Bit mask for one pixel (least significant bits) + */ + bit_mask=~(~0 << bits_per_pixel) + }; + +private: + MoveY y; + mask_type mask_; + difference_type shift_; + + void inc() + { + ++y; + } + + void dec() + { + --y; + } + + bool equal( PackedPixelColumnIterator const & rhs ) const + { + return rhs.y == y; + } + + bool less( PackedPixelColumnIterator const & rhs ) const + { + return y < rhs.y; + } + +public: + PackedPixelColumnIterator() : + y(0), + mask_( get_mask<data_type, bits_per_pixel, MsbFirst, difference_type>(0) ), + shift_( get_shift<num_intraword_positions, bits_per_pixel, MsbFirst, difference_type>(0) ) + {} + + PackedPixelColumnIterator( const MoveY& base, difference_type remainder ) : + y(base), + mask_( get_mask<data_type, bits_per_pixel, MsbFirst>(remainder) ), + shift_( get_shift<num_intraword_positions, bits_per_pixel, MsbFirst>(remainder) ) + {} + + PackedPixelColumnIterator& operator+=( difference_type d ) + { + y += d; + return *this; + } + + PackedPixelColumnIterator& operator-=( difference_type d ) + { + y -= d; + return *this; + } + + PackedPixelColumnIterator operator+( difference_type d ) + { + PackedPixelColumnIterator res(*this); + res += d; + return res; + } + + PackedPixelColumnIterator operator-( difference_type d ) + { + PackedPixelColumnIterator res(*this); + res -= d; + return res; + } + + PackedPixelColumnIterator& operator++() + { + inc(); + return *this; + } + + PackedPixelColumnIterator& operator--() + { + dec(); + return *this; + } + + PackedPixelColumnIterator operator++(int) + { + PackedPixelColumnIterator res(*this); + inc(); + return res; + } + + PackedPixelColumnIterator operator--(int) + { + PackedPixelColumnIterator res(*this); + dec(); + return res; + } + + bool operator==(PackedPixelColumnIterator const & rhs) const + { + return equal( rhs ); + } + + bool operator!=(PackedPixelColumnIterator const & rhs) const + { + return !equal( rhs ); + } + + bool operator<(PackedPixelColumnIterator const & rhs) const + { + return less(rhs); + } + + bool operator<=(PackedPixelColumnIterator const & rhs) const + { + return !less(rhs); + } + + bool operator>(PackedPixelColumnIterator const & rhs) const + { + return rhs.less(*this); + } + + bool operator>=(PackedPixelColumnIterator const & rhs) const + { + return !rhs.less(*this); + } + + difference_type operator-(PackedPixelColumnIterator const & rhs) const + { + return y - rhs.y; + } + + value_type get() const + { + // TODO(Q3): use traits to get unsigned type for data_type (if + // not already) + return static_cast<unsigned int>(*y() & mask_) >> shift_; + } + + value_type get(difference_type d) const + { + // TODO(Q3): use traits to get unsigned type for data_type (if + // not already) + return static_cast<unsigned int>(*y(d) & mask_) >> shift_; + } + + void set( value_type v ) const + { + const value_type pixel_value( (v << shift_) & mask_ ); + *y() = (*y() & ~mask_) | pixel_value; + } + + void set( value_type v, difference_type d ) const + { + const value_type pixel_value( (v << shift_) & mask_ ); + *y(d) = (*y(d) & ~mask_) | pixel_value; + } +}; + +template< typename Datatype, + typename Valuetype, + int bits_per_pixel, + bool MsbFirst > class PackedPixelRowIterator +{ +public: + // no reference, no index_reference type here + typedef Datatype data_type; + typedef Valuetype value_type; + typedef int difference_type; + typedef image_traverser_tag iterator_category; + + typedef typename remove_const<data_type>::type mask_type; + typedef data_type* pointer; + + enum { + /** The number of pixel within a single data_type value + */ + num_intraword_positions=sizeof(data_type)*8/bits_per_pixel, + /** Bit mask for one pixel (least significant bits) + */ + bit_mask=~(~0 << bits_per_pixel) + }; + +private: + pointer data_; + mask_type mask_; + difference_type remainder_; + + void update_mask() + { + mask_ = get_mask<data_type, bits_per_pixel, MsbFirst>(remainder_); + } + + void inc() + { + const difference_type newValue( remainder_ + 1 ); + const difference_type data_offset( newValue / num_intraword_positions ); + + data_ += data_offset; + remainder_ = newValue % num_intraword_positions; + + const mask_type shifted_mask( + MsbFirst ? + // TODO(Q3): use traits to get unsigned type for data_type + // (if not already) + static_cast<unsigned int>(mask_) >> bits_per_pixel : + mask_ << bits_per_pixel ); + + // data_offset is 0 for shifted mask, and 1 for wrapped-around mask + mask_ = (1-data_offset)*shifted_mask + data_offset*(MsbFirst ? + bit_mask << bits_per_pixel*(num_intraword_positions-1) : + bit_mask); + } + + void dec() + { + const difference_type newValue( remainder_ - 1 ); + const bool isNegative( is_negative(newValue) ); + const difference_type newRemainder( newValue % num_intraword_positions ); + + // calc data_ += newValue / num_intraword_positions; + // remainder_ = newRemainder; + // for newValue >= 0, and + // data_ += newValue / num_intraword_positions - 1; + // remainder_ = num_intraword_positions - newRemainder; + // (to force remainder_ to be positive). + // This is branch-free, if is_negative() is branch-free + const difference_type data_offset( newValue / num_intraword_positions - isNegative ); + data_ += data_offset; + remainder_ = newRemainder + isNegative*num_intraword_positions; + + const mask_type shifted_mask( + MsbFirst ? + mask_ << bits_per_pixel : + // TODO(Q3): use traits to get unsigned type for data_type + // (if not already) + static_cast<unsigned int>(mask_) >> bits_per_pixel ); + + // data_offset is 0 for shifted mask, and 1 for wrapped-around mask + mask_ = (1-data_offset)*shifted_mask + data_offset*(MsbFirst ? + bit_mask : + bit_mask << bits_per_pixel*(num_intraword_positions-1)); + } + + bool equal( PackedPixelRowIterator const & rhs ) const + { + return rhs.data_ == data_ && rhs.remainder_ == remainder_; + } + + bool less( PackedPixelRowIterator const & rhs ) const + { + return data_ == rhs.data_ ? + (remainder_ < rhs.remainder_) : + (data_ < rhs.data_); + } + +public: + PackedPixelRowIterator() : + data_(0), + mask_( get_mask<data_type, bits_per_pixel, MsbFirst, difference_type>(0) ), + remainder_(0) + {} + + explicit PackedPixelRowIterator( pointer base, int x ) : + data_(base), + mask_(0), + remainder_(x % num_intraword_positions) + { + update_mask(); + } + + PackedPixelRowIterator& operator+=( difference_type d ) + { + const difference_type newValue( remainder_ + d ); + + data_ += newValue / num_intraword_positions; + remainder_ = newValue % num_intraword_positions; + update_mask(); + + return *this; + } + + PackedPixelRowIterator& operator-=( difference_type d ) + { + const difference_type newValue( remainder_ - d ); + const bool isNegative( is_negative(newValue) ); + const difference_type newRemainder( newValue % num_intraword_positions ); + + // calc data_ += newValue / num_intraword_positions; + // remainder_ = newRemainder; + // for newValue >= 0, and + // data_ += newValue / num_intraword_positions - 1; + // remainder_ = num_intraword_positions - newRemainder; + // (to force remainder_ to be positive). + // This is branch-free, if is_negative() is branch-free + data_ += newValue / num_intraword_positions - isNegative; + remainder_ = newRemainder + isNegative*(num_intraword_positions - 2*newRemainder); + update_mask(); + + return *this; + } + + PackedPixelRowIterator operator+( difference_type d ) + { + PackedPixelRowIterator res(*this); + res += d; + return res; + } + + PackedPixelRowIterator operator-( difference_type d ) + { + PackedPixelRowIterator res(*this); + res -= d; + return res; + } + + PackedPixelRowIterator& operator++() + { + inc(); + return *this; + } + + PackedPixelRowIterator& operator--() + { + dec(); + return *this; + } + + PackedPixelRowIterator operator++(int) + { + PackedPixelRowIterator res(*this); + inc(); + return res; + } + + PackedPixelRowIterator operator--(int) + { + PackedPixelRowIterator res(*this); + dec(); + return res; + } + + bool operator==(PackedPixelRowIterator const & rhs) const + { + return equal( rhs ); + } + + bool operator!=(PackedPixelRowIterator const & rhs) const + { + return !equal( rhs ); + } + + bool operator<(PackedPixelRowIterator const & rhs) const + { + return less(rhs); + } + + bool operator<=(PackedPixelRowIterator const & rhs) const + { + return !less(rhs); + } + + bool operator>(PackedPixelRowIterator const & rhs) const + { + return rhs.less(*this); + } + + bool operator>=(PackedPixelRowIterator const & rhs) const + { + return !rhs.less(*this); + } + + difference_type operator-(PackedPixelRowIterator const & rhs) const + { + return (data_ - rhs.data_)*num_intraword_positions + (remainder_ - rhs.remainder_); + } + + value_type get() const + { + // TODO(Q3): use traits to get unsigned type for data_type (if + // not already) + return static_cast<unsigned int>(*data_ & mask_) >> + get_shift<num_intraword_positions, bits_per_pixel, MsbFirst>(remainder_); + } + + value_type get(difference_type d) const + { + PackedPixelRowIterator tmp(*this); + tmp += d; + return tmp.get(); + } + + void set( value_type v ) const + { + const value_type pixel_value( + (v << + get_shift<num_intraword_positions, bits_per_pixel, MsbFirst>(remainder_)) + & mask_ ); + *data_ = (*data_ & ~mask_) | pixel_value; + } + + void set( value_type v, difference_type d ) const + { + PackedPixelRowIterator tmp(*this); + tmp += d; + tmp.set(v); + } +}; + +template< typename Datatype, + typename Valuetype, + int bits_per_pixel, + bool MsbFirst > class PackedPixelIterator +{ +public: + // no reference, no index_reference type here + typedef Datatype data_type; + typedef Valuetype value_type; + typedef vigra::Diff2D difference_type; + typedef image_traverser_tag iterator_category; + typedef PackedPixelRowIterator<data_type, + value_type, + bits_per_pixel, + MsbFirst> row_iterator; + typedef PackedPixelColumnIterator<data_type, + value_type, + bits_per_pixel, + MsbFirst> column_iterator; + + typedef data_type* pointer; + typedef int MoveX; + typedef StridedArrayIterator< data_type > MoveY; + + enum { + /** The number of pixel within a single data_type value + */ + num_intraword_positions=sizeof(data_type)*8/bits_per_pixel, + /** Bit mask for one pixel (least significant bits) + */ + bit_mask=~(~0 << bits_per_pixel) + }; + + // TODO(F2): direction of iteration (ImageIterator can be made to + // run backwards) + +private: + pointer current() const + { + return y() + (x / num_intraword_positions); + } + + pointer current(int dx, int dy) const + { + return y(dy) + ((x+dx)/num_intraword_positions); + } + + bool equal(PackedPixelIterator const & rhs) const + { + return (x == rhs.x) && (y == rhs.y); + } + +public: + PackedPixelIterator() : + x(0), + y(0) + {} + + PackedPixelIterator(pointer base, int ystride) : + x(0), + y(ystride,base) + {} + + bool operator==(PackedPixelIterator const & rhs) const + { + return equal(rhs); + } + + bool operator!=(PackedPixelIterator const & rhs) const + { + return !equal(rhs); + } + + difference_type operator-(PackedPixelIterator const & rhs) const + { + return difference_type(x - rhs.x, y - rhs.y); + } + + MoveX x; + MoveY y; + + PackedPixelIterator & operator+=(difference_type const & s) + { + x += s.x; + y += s.y; + return *this; + } + + PackedPixelIterator & operator-=(difference_type const & s) + { + x -= s.x; + y -= s.y; + return *this; + } + + PackedPixelIterator operator+(difference_type const & s) const + { + PackedPixelIterator ret(*this); + ret += s; + return ret; + } + + PackedPixelIterator operator-(difference_type const & s) const + { + PackedPixelIterator ret(*this); + ret -= s; + return ret; + } + + row_iterator rowIterator() const + { + return row_iterator(current(),x); + } + + column_iterator columnIterator() const + { + return column_iterator(MoveY(y, + x / num_intraword_positions), + x % num_intraword_positions); + } + + value_type get() const + { + const int remainder( x % num_intraword_positions ); + + // TODO(Q3): use traits to get unsigned type for data_type (if + // not already) + value_type nTmp0( *current() ); + unsigned int nTmp1(static_cast<unsigned int>(*current() & + get_mask<data_type, bits_per_pixel, MsbFirst>(remainder))); + unsigned int nTmp2( (static_cast<unsigned int>(*current() & + get_mask<data_type, bits_per_pixel, MsbFirst>(remainder)) + >> get_shift<num_intraword_positions, bits_per_pixel, MsbFirst>(remainder))); + + return (static_cast<unsigned int>(*current() & + get_mask<data_type, bits_per_pixel, MsbFirst>(remainder)) + >> get_shift<num_intraword_positions, bits_per_pixel, MsbFirst>(remainder)); + } + + value_type get(difference_type const & d) const + { + const int remainder( x(d.x) % num_intraword_positions ); + + // TODO(Q3): use traits to get unsigned type for data_type (if + // not already) + return (static_cast<unsigned int>(*current(d.x,d.y) & + get_mask<data_type, bits_per_pixel, MsbFirst>(remainder)) + >> get_shift<num_intraword_positions, bits_per_pixel, MsbFirst>(remainder)); + } + + void set( value_type v ) const + { + const int remainder( x % num_intraword_positions ); + const int mask( get_mask<data_type, bits_per_pixel, MsbFirst>(remainder) ); + const value_type pixel_value( + (v << + get_shift<num_intraword_positions, bits_per_pixel, MsbFirst>(remainder)) + & mask ); + pointer p = current(); + *p = (*p & ~mask) | pixel_value; + } + + void set( value_type v, difference_type const & d ) const + { + const int remainder( (x + d.x) % num_intraword_positions ); + const int mask( get_mask<data_type, bits_per_pixel, MsbFirst>(remainder) ); + const value_type pixel_value( + (v << + get_shift<num_intraword_positions, bits_per_pixel, MsbFirst>(remainder)) + & mask ); + pointer p = current(d.x,d.y); + *p = (*p & ~mask) | pixel_value; + } +}; + +} // namespace basebmp + +#endif /* INCLUDED_BASEBMP_PACKEDPIXELITERATOR_HXX */ diff --git a/basebmp/inc/basebmp/paletteimageaccessor.hxx b/basebmp/inc/basebmp/paletteimageaccessor.hxx new file mode 100644 index 000000000000..848ea59d7a50 --- /dev/null +++ b/basebmp/inc/basebmp/paletteimageaccessor.hxx @@ -0,0 +1,141 @@ +/************************************************************************* + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: paletteimageaccessor.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: thb $ $Date: 2006-05-31 09:49:42 $ + * + * 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_PALETTEIMAGEACCESSOR_HXX +#define INCLUDED_BASEBMP_PALETTEIMAGEACCESSOR_HXX + +#include "metafunctions.hxx" + +#include <vigra/numerictraits.hxx> +#include <vigra/mathutil.hxx> + +#include <algorithm> + + +namespace basebmp +{ + +/** Access (possibly packed-pixel) data via palette indirection + */ +template< typename Valuetype, typename Datatype > class PaletteImageAccessor +{ +public: + typedef Valuetype value_type; + typedef Datatype data_type; + typedef typename remove_const<data_type>::type count_type; + + +private: + const value_type* palette; + count_type num_entries; + + double norm( value_type const& rLHS, + value_type const& rRHS ) const + { + return (rRHS - rLHS).magnitude(); + } + + data_type find_best_match(value_type const& v) const + { + // TODO(P3): use table-based/octree approach here! + const value_type* best_entry; + const value_type* palette_end( palette+num_entries ); + if( (best_entry=std::find( palette, palette_end, v)) != palette_end ) + return best_entry-palette; + + // TODO(F3): HACK. Need palette traits, and an error function + // here. We blatantly assume value_type is a normed linear + // space. + const value_type* curr_entry( palette ); + best_entry = curr_entry; + while( curr_entry != palette_end ) + { + if( norm(*curr_entry,*best_entry) > norm(*curr_entry,v) ) + best_entry = curr_entry; + + ++curr_entry; + } + + return best_entry-palette; + } + + value_type toCol( value_type const& rCol ) const + { + return rCol; + } + +public: + PaletteImageAccessor() : + palette(0), + num_entries(0) + {} + + PaletteImageAccessor( const value_type* pPalette, + data_type entries ) : + palette(pPalette), + num_entries(entries) + {} + + template< class Iterator > + value_type operator()(Iterator const& i) const { return toCol(palette[i.get()]); } + value_type operator()(data_type const* i) const { return toCol(palette[*i]); } + + template< class Iterator, class Difference > + value_type operator()(Iterator const& i, Difference const& diff) const + { + return toCol(palette[i.get(diff)]); + } + + template< typename V, class Iterator > + void set(V const& value, Iterator const& i) const + { + i.set( + find_best_match( + vigra::detail::RequiresExplicitCast<value_type>::cast(value) )); + } + + template< typename V, class Iterator, class Difference > + void set(V const& value, Iterator const& i, Difference const& diff) const + { + i.set( + find_best_match( + vigra::detail::RequiresExplicitCast<value_type>::cast(value)), + diff ); + } +}; + +} // namespace basebmp + +#endif /* INCLUDED_BASEBMP_PALETTEIMAGEACCESSOR_HXX */ diff --git a/basebmp/inc/basebmp/pixeliterator.hxx b/basebmp/inc/basebmp/pixeliterator.hxx new file mode 100644 index 000000000000..9f1f3c997ea2 --- /dev/null +++ b/basebmp/inc/basebmp/pixeliterator.hxx @@ -0,0 +1,362 @@ +/************************************************************************* + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: pixeliterator.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: thb $ $Date: 2006-05-31 09:49:43 $ + * + * 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_PIXELITERATOR_HXX +#define INCLUDED_BASEBMP_PIXELITERATOR_HXX + +#include "metafunctions.hxx" +#include "stridedarrayiterator.hxx" + +#include <boost/static_assert.hpp> +#include <vigra/metaprogramming.hxx> +#include <vigra/diff2d.hxx> + +namespace basebmp +{ + +template< typename Valuetype > class PixelColumnIterator +{ +public: + typedef Valuetype value_type; + typedef Valuetype& reference; + typedef Valuetype* pointer; + typedef int difference_type; + typedef image_traverser_tag iterator_category; + + typedef StridedArrayIterator< value_type > MoveY; + +private: + MoveY y; + + bool equal( PixelColumnIterator const & rhs ) const + { + return rhs.y == y; + } + + bool less( PixelColumnIterator const & rhs ) const + { + return y < rhs.y; + } + +public: + PixelColumnIterator() : + y(0) + {} + + explicit PixelColumnIterator( const MoveY& pos ) : + y(pos) + {} + + PixelColumnIterator( const MoveY& pos, int x ) : + y(pos,x) + {} + + PixelColumnIterator& operator+=( difference_type d ) + { + y += d; + return *this; + } + + PixelColumnIterator& operator-=( difference_type d ) + { + y -= d; + return *this; + } + + PixelColumnIterator operator+( difference_type d ) + { + PixelColumnIterator res(*this); + res += d; + return res; + } + + PixelColumnIterator operator-( difference_type d ) + { + PixelColumnIterator res(*this); + res -= d; + return res; + } + + PixelColumnIterator& operator++() + { + ++y; + return *this; + } + + PixelColumnIterator& operator--() + { + --y; + return *this; + } + + PixelColumnIterator operator++(int) + { + PixelColumnIterator res(*this); + ++y; + return res; + } + + PixelColumnIterator operator--(int) + { + PixelColumnIterator res(*this); + --y; + return res; + } + + bool operator==(PixelColumnIterator const & rhs) const + { + return equal( rhs ); + } + + bool operator!=(PixelColumnIterator const & rhs) const + { + return !equal( rhs ); + } + + bool operator<(PixelColumnIterator const & rhs) const + { + return less(rhs); + } + + bool operator<=(PixelColumnIterator const & rhs) const + { + return !less(rhs); + } + + bool operator>(PixelColumnIterator const & rhs) const + { + return rhs.less(*this); + } + + bool operator>=(PixelColumnIterator const & rhs) const + { + return !rhs.less(*this); + } + + difference_type operator-(PixelColumnIterator const & rhs) const + { + return y - rhs.y; + } + + value_type get() const + { + return *y(); + } + + value_type get(difference_type d) const + { + return *y(d); + } + + void set( value_type v ) const + { + *y() = v; + } + + void set( value_type v, difference_type d ) const + { + *y(d) = v; + } + + reference operator*() const + { + return *y(); + } + + pointer operator->() const + { + return y(); + } + + reference operator[](difference_type d) const + { + return *y(d); + } + + reference operator()(int dy) const + { + return *y(dy); + } +}; + +template< typename Valuetype > class PixelIterator +{ +public: + typedef Valuetype value_type; + typedef Valuetype& reference; + typedef Valuetype* pointer; + typedef vigra::Diff2D difference_type; + typedef image_traverser_tag iterator_category; + typedef pointer row_iterator; + typedef PixelColumnIterator<value_type> column_iterator; + + typedef int MoveX; + typedef StridedArrayIterator< value_type > MoveY; + + // TODO(F2): direction of iteration (ImageIterator can be made to + // run backwards) + +private: + bool equal(PixelIterator const & rhs) const + { + return (x == rhs.x) && (y == rhs.y); + } + + pointer current() const + { + return y() + x; + } + + pointer current(int dx, int dy) const + { + return y(dy) + x+dy; + } + +public: + PixelIterator() : + x(0), + y(0) + {} + + PixelIterator(pointer base, int ystride) : + x(0), + y(ystride,base) + {} + + bool operator==(PixelIterator const & rhs) const + { + return equal(rhs); + } + + bool operator!=(PixelIterator const & rhs) const + { + return !equal(rhs); + } + + difference_type operator-(PixelIterator const & rhs) const + { + return difference_type(x - rhs.x, y - rhs.y); + } + + MoveX x; + MoveY y; + + PixelIterator & operator+=(difference_type const & s) + { + x += s.x; + y += s.y; + return *this; + } + + PixelIterator & operator-=(difference_type const & s) + { + x -= s.x; + y -= s.y; + return *this; + } + + PixelIterator operator+(difference_type const & s) const + { + PixelIterator ret(*this); + ret += s; + return ret; + } + + PixelIterator operator-(difference_type const & s) const + { + PixelIterator ret(*this); + ret -= s; + return ret; + } + + row_iterator rowIterator() const + { + return row_iterator(y()+x); + } + + column_iterator columnIterator() const + { + return column_iterator(y,x); + } + + value_type get() const + { + return *current(); + } + + value_type get(difference_type const & d) const + { + return *current(d.y, d.x); + } + + void set( value_type v ) const + { + *current() = v; + } + + void set( value_type v, difference_type const & d ) const + { + *current(d.y,d.x) = v; + } + + reference operator*() const + { + return *current(); + } + + pointer operator->() const + { + return current(); + } + + reference operator[]( const vigra::Diff2D& d ) const + { + return *current(d.x,d.y); + } + + reference operator()(int dx, int dy) const + { + return *current(dx,dy); + } + + pointer operator[](int dy) const + { + return y(dy) + x; + } +}; + +} // namespace basebmp + +#endif /* INCLUDED_BASEBMP_PIXELITERATOR_HXX */ diff --git a/basebmp/inc/basebmp/scanlineformats.hxx b/basebmp/inc/basebmp/scanlineformats.hxx new file mode 100644 index 000000000000..c0aef970c1a8 --- /dev/null +++ b/basebmp/inc/basebmp/scanlineformats.hxx @@ -0,0 +1,82 @@ +/************************************************************************* + * + * $RCSfile: scanlineformats.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: thb $ $Date: 2006-05-31 09:49:43 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 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 + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef INCLUDED_BASEBMP_SCANLINEFORMATS_HXX +#define INCLUDED_BASEBMP_SCANLINEFORMATS_HXX + +/* Definition of Scanline formats */ + +namespace basebmp { namespace Format +{ + static const sal_Int32 ONE_BIT_MSB_PAL = (sal_Int32)0x01; + static const sal_Int32 ONE_BIT_LSB_PAL = (sal_Int32)0x02; + static const sal_Int32 TWO_BIT_MSB_PAL = (sal_Int32)0x03; + static const sal_Int32 TWO_BIT_LSB_PAL = (sal_Int32)0x04; + static const sal_Int32 FOUR_BIT_MSB_PAL = (sal_Int32)0x05; + static const sal_Int32 FOUR_BIT_LSB_PAL = (sal_Int32)0x06; + static const sal_Int32 EIGHT_BIT_PAL = (sal_Int32)0x07; + static const sal_Int32 EIGHT_BIT_TC_MASK = (sal_Int32)0x0A; + static const sal_Int32 SIXTEEN_BIT_TC_MASK = (sal_Int32)0x0B; + static const sal_Int32 TWENTYFOUR_BIT_TC_MASK = (sal_Int32)0x0C; + static const sal_Int32 THIRTYTWO_BIT_TC_MASK = (sal_Int32)0x0D; +} } + +#endif /* INCLUDED_BASEBMP_SCANLINEFORMATS_HXX */ diff --git a/basebmp/inc/basebmp/stridedarrayiterator.hxx b/basebmp/inc/basebmp/stridedarrayiterator.hxx new file mode 100644 index 000000000000..bcff5a21c518 --- /dev/null +++ b/basebmp/inc/basebmp/stridedarrayiterator.hxx @@ -0,0 +1,102 @@ +/************************************************************************* + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: stridedarrayiterator.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: thb $ $Date: 2006-05-31 09:49:43 $ + * + * 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_STRIDEDARRAYITERATOR_HXX +#define INCLUDED_BASEBMP_STRIDEDARRAYITERATOR_HXX + +namespace basebmp +{ + +// changed semantics re. DirectionSelector<StridedArrayTag>: stride +// now counts in <em>raw</em> bytes! +template< typename T > class StridedArrayIterator +{ +public: + typedef typename clone_const<T, unsigned char>::type internal_type; + + StridedArrayIterator(int stride, T* ptr = 0) : + stride_(stride), + current_(reinterpret_cast<internal_type*>(ptr)) + {} + + /// Copy from other StridedArrayIterator, plus given offset + StridedArrayIterator( StridedArrayIterator const& rSrc, + int offset ) : + stride_(rSrc.stride_), + current_(reinterpret_cast<internal_type*>( + reinterpret_cast<T*>(rSrc.current_)+offset)) + {} + + void operator++() {current_ += stride_; } + void operator++(int) {current_ += stride_; } + void operator--() {current_ -= stride_; } + void operator--(int) {current_ -= stride_; } + void operator+=(int dy) {current_ += dy*stride_; } + void operator-=(int dy) {current_ -= dy*stride_; } + + bool operator==(StridedArrayIterator const & rhs) const + { return (current_ == rhs.current_); } + + bool operator!=(StridedArrayIterator const & rhs) const + { return (current_ != rhs.current_); } + + bool operator<(StridedArrayIterator const & rhs) const + { return (current_ < rhs.current_); } + + bool operator<=(StridedArrayIterator const & rhs) const + { return (current_ <= rhs.current_); } + + bool operator>(StridedArrayIterator const & rhs) const + { return (current_ > rhs.current_); } + + bool operator>=(StridedArrayIterator const & rhs) const + { return (current_ >= rhs.current_); } + + int operator-(StridedArrayIterator const & rhs) const + { return (current_ - rhs.current_) / stride_; } + + T* operator()() const + { return reinterpret_cast<T*>(current_); } + + T* operator()(int d) const + { return reinterpret_cast<T*>(current_ + d*stride_); } + + int stride_; + internal_type* current_; +}; + +} // namespace basebmp + +#endif /* INCLUDED_BASEBMP_STRIDEDARRAYITERATOR_HXX */ |