Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

Commit [8f0f49] default Maximize Restore History

merged vigra 1.4 version back into HEAD. Everything seems to work well.

dangelo dangelo 2006-03-04

<< < 1 .. 4 5 6 (Page 6 of 6)
added src/foreign/vigra/resampling_convolution.hxx
added src/foreign/vigra/rfftw.hxx
added src/foreign/vigra/splineimageview.hxx
added src/foreign/vigra/splines.hxx
added src/foreign/vigra/static_assert.hxx
added src/foreign/vigra/tensorutilities.hxx
added src/foreign/vigra/watersheds.hxx
added src/foreign/vigra_impex/iccjpeg.c
added src/foreign/vigra_impex/iccjpeg.h
copied src/foreign/vigra/extraimagetraits.hxx -> src/foreign/vigra/sized_int.hxx
copied src/foreign/vigra/impexalpha.hxx -> src/include/vigra_ext/impexalpha.hxx
src/foreign/vigra/resampling_convolution.hxx Diff Switch to side-by-side view
Loading...
src/foreign/vigra/rfftw.hxx Diff Switch to side-by-side view
Loading...
src/foreign/vigra/splineimageview.hxx Diff Switch to side-by-side view
Loading...
src/foreign/vigra/splines.hxx Diff Switch to side-by-side view
Loading...
src/foreign/vigra/static_assert.hxx Diff Switch to side-by-side view
Loading...
src/foreign/vigra/tensorutilities.hxx Diff Switch to side-by-side view
Loading...
src/foreign/vigra/watersheds.hxx Diff Switch to side-by-side view
Loading...
src/foreign/vigra_impex/iccjpeg.c Diff Switch to side-by-side view
Loading...
src/foreign/vigra_impex/iccjpeg.h Diff Switch to side-by-side view
Loading...
src/foreign/vigra/extraimagetraits.hxx to src/foreign/vigra/sized_int.hxx
--- a/src/foreign/vigra/extraimagetraits.hxx
+++ b/src/foreign/vigra/sized_int.hxx
@@ -1,173 +1,163 @@
-
-#ifndef _VIGRA_IMPEX2_EXTRAIMAGETRAITS_HXX
-#define _VIGRA_IMPEX2_EXTRAIMAGETRAITS_HXX
+/************************************************************************/
+/*                                                                      */
+/*               Copyright 1998-2002 by Ullrich Koethe                  */
+/*       Cognitive Systems Group, University of Hamburg, Germany        */
+/*                                                                      */
+/*    This file is part of the VIGRA computer vision library.           */
+/*    ( Version 1.4.0, Dec 21 2005 )                                    */
+/*    The VIGRA Website is                                              */
+/*        http://kogs-www.informatik.uni-hamburg.de/~koethe/vigra/      */
+/*    Please direct questions, bug reports, and contributions to        */
+/*        koethe@informatik.uni-hamburg.de          or                  */
+/*        vigra@kogs1.informatik.uni-hamburg.de                         */
+/*                                                                      */
+/*    Permission is hereby granted, free of charge, to any person       */
+/*    obtaining a copy of this software and associated documentation    */
+/*    files (the "Software"), to deal in the Software without           */
+/*    restriction, including without limitation the rights to use,      */
+/*    copy, modify, merge, publish, distribute, sublicense, and/or      */
+/*    sell copies of the Software, and to permit persons to whom the    */
+/*    Software is furnished to do so, subject to the following          */
+/*    conditions:                                                       */
+/*                                                                      */
+/*    The above copyright notice and this permission notice shall be    */
+/*    included in all copies or substantial portions of the             */
+/*    Software.                                                         */
+/*                                                                      */
+/*    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND    */
+/*    EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES   */
+/*    OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND          */
+/*    NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT       */
+/*    HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,      */
+/*    WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING      */
+/*    FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR     */
+/*    OTHER DEALINGS IN THE SOFTWARE.                                   */                
+/*                                                                      */
+/************************************************************************/
 
 
-#include "vigra/stdimage.hxx"
-#include "vigra/iteratortraits.hxx"
+#ifndef VIGRA_SIZED_INT_HXX
+#define VIGRA_SIZED_INT_HXX
+
+#include "metaprogramming.hxx"
 
 namespace vigra {
 
-#define VIGRA_DEFINE_ITERATORTRAITS(VALUETYPE, ACCESSOR, CONSTACCESSOR) \
-    template<> \
-    struct IteratorTraits< \
-        vigra::BasicImageIterator<VALUETYPE, VALUETYPE **> > \
-    { \
-        typedef vigra::BasicImageIterator<VALUETYPE, VALUETYPE **> \
-                                                     Iterator; \
-        typedef Iterator                             iterator; \
-        typedef iterator::iterator_category          iterator_category; \
-        typedef iterator::value_type                 value_type; \
-        typedef iterator::reference                  reference; \
-        typedef iterator::index_reference            index_reference; \
-        typedef iterator::pointer                    pointer; \
-        typedef iterator::difference_type            difference_type; \
-        typedef iterator::row_iterator               row_iterator; \
-        typedef iterator::column_iterator            column_iterator; \
-        typedef ACCESSOR<VALUETYPE >                 default_accessor; \
-        typedef ACCESSOR<VALUETYPE >                 DefaultAccessor; \
-    }; \
-    template<> \
-    struct IteratorTraits< \
-        ConstBasicImageIterator<VALUETYPE, VALUETYPE **> > \
-    { \
-        typedef \
-          vigra::ConstBasicImageIterator<VALUETYPE, VALUETYPE **> \
-                                                     Iterator; \
-        typedef Iterator                             iterator; \
-        typedef iterator::iterator_category          iterator_category; \
-        typedef iterator::value_type                 value_type; \
-        typedef iterator::reference                  reference; \
-        typedef iterator::index_reference            index_reference; \
-        typedef iterator::pointer                    pointer; \
-        typedef iterator::difference_type            difference_type; \
-        typedef iterator::row_iterator               row_iterator; \
-        typedef iterator::column_iterator            column_iterator; \
-        typedef CONSTACCESSOR<VALUETYPE >            default_accessor; \
-        typedef CONSTACCESSOR<VALUETYPE >            DefaultAccessor; \
-    };
+class Int_type_not_supported_on_this_platform {};
 
-/** \addtogroup StandardImageTypes Additional Standard Image Types
+#ifndef NO_PARTIAL_TEMPLATE_SPECIALIZATION
 
-    \brief Some more common instantiations of the \ref vigra::BasicImage template
+namespace detail {
+
+template<class T, class NEXT>
+struct IntTypeList
+{
+    enum { size = sizeof(T)*8 };
+    typedef T type;
+    typedef NEXT next;
+};
+
+template<int SIZE, class LIST>
+struct SelectIntegerType
+{
+    typedef typename 
+       IfBool<(SIZE == LIST::size), 
+           typename LIST::type,
+           typename SelectIntegerType<SIZE, typename LIST::next>::type >::type
+       type;
+};
+
+template<int SIZE>
+struct SelectIntegerType<SIZE, Int_type_not_supported_on_this_platform>
+{
+    typedef Int_type_not_supported_on_this_platform type;
+};
+
+template<class LIST>
+struct SelectBiggestIntegerType
+{
+    enum { cursize = LIST::size, 
+           nextsize = SelectBiggestIntegerType<typename LIST::next>::size,
+           size = (cursize < nextsize) ? nextsize : cursize };
+    typedef typename 
+       IfBool<(cursize < nextsize), 
+           typename SelectBiggestIntegerType<typename LIST::next>::type,
+           typename LIST::type>::type
+       type;
+};
+
+template<>
+struct SelectBiggestIntegerType<Int_type_not_supported_on_this_platform>
+{
+    enum { size = 0 };
+    typedef Int_type_not_supported_on_this_platform type;
+};
+
+typedef IntTypeList<signed char, 
+        IntTypeList<signed short,
+        IntTypeList<signed int,
+        IntTypeList<signed long,
+        Int_type_not_supported_on_this_platform > > > > SignedIntTypes;
+typedef IntTypeList<unsigned char, 
+        IntTypeList<unsigned short,
+        IntTypeList<unsigned int,
+        IntTypeList<unsigned long,
+        Int_type_not_supported_on_this_platform > > > > UnsignedIntTypes;
+
+} // namespace detail
+
+/** \addtogroup FixedSizeInt Fixed Size Integer Types
+
+    Since the C++ standard does only specifiy minimal sizes for the built-in 
+    integer types, one cannot rely on them have a specific size. But
+    pixel types with a specific size are often required in image processing,
+    especially when reading or writing binary files. The VIGRA typedefs
+    are guaranteed to have exactly the correct size. If the system
+    does not provide a suitable type, the typedef will evaluate to
+    <tt>Int_type_not_supported_on_this_platform</tt>.
 */
 //@{
 
-VIGRA_DEFINE_ITERATORTRAITS(unsigned short, vigra::StandardValueAccessor, vigra::StandardConstValueAccessor)
+    /// 8-bit signed int
+typedef detail::SelectIntegerType<8,  detail::SignedIntTypes>::type Int8;
+    /// 16-bit signed int
+typedef detail::SelectIntegerType<16, detail::SignedIntTypes>::type Int16;
+    /// 32-bit signed int
+typedef detail::SelectIntegerType<32, detail::SignedIntTypes>::type Int32;
+    /// 64-bit signed int
+typedef detail::SelectIntegerType<64, detail::SignedIntTypes>::type Int64;
+    /// 8-bit unsigned int
+typedef detail::SelectIntegerType<8,  detail::UnsignedIntTypes>::type UInt8;
+    /// 16-bit unsigned int
+typedef detail::SelectIntegerType<16, detail::UnsignedIntTypes>::type UInt16;
+    /// 32-bit unsigned int
+typedef detail::SelectIntegerType<32, detail::UnsignedIntTypes>::type UInt32;
+    /// 64-bit unsigned int
+typedef detail::SelectIntegerType<64, detail::UnsignedIntTypes>::type UInt64;
 
-    /** Unsigned Short (16-bit unsigned) image.
-        It uses \ref vigra::BasicImageIterator and \ref vigra::StandardAccessor and
-        their const counterparts to access the data.
+    /// the biggest signed integer type of the system
+typedef detail::SelectBiggestIntegerType<detail::SignedIntTypes>::type   IntBiggest;
+    /// the biggest unsigned integer type of the system
+typedef detail::SelectBiggestIntegerType<detail::UnsignedIntTypes>::type UIntBiggest;
 
-        <b>\#include</b> "<a href="stdimage_8hxx-source.html">vigra/stdimage.hxx</a>"<br>
-        Namespace: vigra
-    */
-typedef BasicImage<unsigned short> USImage;
+//@}
 
-VIGRA_DEFINE_ITERATORTRAITS(unsigned int, StandardValueAccessor, StandardConstValueAccessor)
+#else // NO_PARTIAL_TEMPLATE_SPECIALIZATION
 
-    /** Unsigned Integer (32-bit unsigned) image.
-        It uses \ref vigra::BasicImageIterator and \ref vigra::StandardAccessor and
-        their const counterparts to access the data.
+typedef signed char    Int8;
+typedef signed short   Int16;
+typedef signed int     Int32;
+typedef Int_type_not_supported_on_this_platform Int64;
+typedef unsigned char  UInt8;
+typedef unsigned short UInt16;
+typedef unsigned int   UInt32;
+typedef Int_type_not_supported_on_this_platform UInt64;
 
-        <b>\#include</b> "<a href="stdimage_8hxx-source.html">vigra/stdimage.hxx</a>"<br>
-        Namespace: vigra
-    */
-typedef BasicImage<unsigned int> UIImage;
+typedef Int32  IntBiggest;
+typedef UInt32 UIntBiggest;
 
-VIGRA_DEFINE_ITERATORTRAITS(RGBValue<unsigned short>, RGBAccessor, RGBAccessor)
+#endif // NO_PARTIAL_TEMPLATE_SPECIALIZATION
 
-    /** Unsigned short (3x 16-bit unsigned) RGB image.
-        The pixel type is \ref vigra::RGBValue "vigra::RGBValue<unsigned short>".
-        It uses \ref vigra::BasicImageIterator and \ref vigra::RGBAccessor and
-        their const counterparts to access the data.
+} // namespace vigra
 
-        <b>\#include</b> "<a href="stdimage_8hxx-source.html">vigra/stdimage.hxx</a>"<br>
-        Namespace: vigra
-    */
-typedef BasicImage<RGBValue<unsigned short> > USRGBImage;
-
-VIGRA_DEFINE_ITERATORTRAITS(RGBValue<unsigned int>, RGBAccessor, RGBAccessor)
-
-    /** Unsigned Integer (3x 32-bit unsigned) RGB image.
-        The pixel type is \ref vigra::RGBValue "RGBValue<unsigned int>".
-        It uses \ref vigra::BasicImageIterator and \ref vigra::RGBAccessor and
-        their const counterparts to access the data.
-
-        <b>\#include</b> "<a href="stdimage_8hxx-source.html">vigra/stdimage.hxx</a>"<br>
-        Namespace: vigra
-    */
-typedef BasicImage<RGBValue<unsigned int> > UIRGBImage;
-
-#define VIGRA_PIXELTYPE TinyVector<short, 2>
-VIGRA_DEFINE_ITERATORTRAITS(VIGRA_PIXELTYPE, VectorAccessor, VectorAccessor)
-#undef VIGRA_PIXELTYPE
-#define VIGRA_PIXELTYPE TinyVector<short, 3>
-VIGRA_DEFINE_ITERATORTRAITS(VIGRA_PIXELTYPE, VectorAccessor, VectorAccessor)
-#undef VIGRA_PIXELTYPE
-#define VIGRA_PIXELTYPE TinyVector<short, 4>
-VIGRA_DEFINE_ITERATORTRAITS(VIGRA_PIXELTYPE, VectorAccessor, VectorAccessor)
-#undef VIGRA_PIXELTYPE
-#define VIGRA_PIXELTYPE TinyVector<int, 2>
-VIGRA_DEFINE_ITERATORTRAITS(VIGRA_PIXELTYPE, VectorAccessor, VectorAccessor)
-#undef VIGRA_PIXELTYPE
-#define VIGRA_PIXELTYPE TinyVector<int, 3>
-VIGRA_DEFINE_ITERATORTRAITS(VIGRA_PIXELTYPE, VectorAccessor, VectorAccessor)
-#undef VIGRA_PIXELTYPE
-#define VIGRA_PIXELTYPE TinyVector<int, 4>
-VIGRA_DEFINE_ITERATORTRAITS(VIGRA_PIXELTYPE, VectorAccessor, VectorAccessor)
-#undef VIGRA_PIXELTYPE
-#define VIGRA_PIXELTYPE TinyVector<unsigned int, 2>
-VIGRA_DEFINE_ITERATORTRAITS(VIGRA_PIXELTYPE, VectorAccessor, VectorAccessor)
-#undef VIGRA_PIXELTYPE
-#define VIGRA_PIXELTYPE TinyVector<unsigned int, 3>
-VIGRA_DEFINE_ITERATORTRAITS(VIGRA_PIXELTYPE, VectorAccessor, VectorAccessor)
-#undef VIGRA_PIXELTYPE
-#define VIGRA_PIXELTYPE TinyVector<unsigned int, 4>
-VIGRA_DEFINE_ITERATORTRAITS(VIGRA_PIXELTYPE, VectorAccessor, VectorAccessor)
-#undef VIGRA_PIXELTYPE
-
-#undef VIGRA_DEFINE_ITERATORTRAITS
-
-
-#ifndef NO_PARTIAL_TEMPLATE_SPECIALIZATION
-
-// define traits for BasicImageIterator instanciations that
-// were not explicitly defined above
-template <class T>
-struct IteratorTraits<BasicImageIterator<T, T **> >
-{
-    typedef BasicImageIterator<T, T **>          Iterator;
-    typedef Iterator                             iterator;
-    typedef typename iterator::iterator_category iterator_category;
-    typedef typename iterator::value_type        value_type;
-    typedef typename iterator::reference         reference;
-    typedef typename iterator::index_reference   index_reference;
-    typedef typename iterator::pointer           pointer;
-    typedef typename iterator::difference_type   difference_type;
-    typedef typename iterator::row_iterator      row_iterator;
-    typedef typename iterator::column_iterator   column_iterator;
-    typedef StandardAccessor<T>                  DefaultAccessor;
-    typedef StandardAccessor<T>                  default_accessor;
-};
-
-template <class T>
-struct IteratorTraits<ConstBasicImageIterator<T, T **> >
-{
-    typedef ConstBasicImageIterator<T, T **> Iterator;
-    typedef Iterator                               iterator;
-    typedef typename iterator::iterator_category   iterator_category;
-    typedef typename iterator::value_type          value_type;
-    typedef typename iterator::reference           reference;
-    typedef typename iterator::index_reference     index_reference;
-    typedef typename iterator::pointer             pointer;
-    typedef typename iterator::difference_type     difference_type;
-    typedef typename iterator::row_iterator        row_iterator;
-    typedef typename iterator::column_iterator     column_iterator;
-    typedef StandardConstAccessor<T>               DefaultAccessor;
-    typedef StandardConstAccessor<T>               default_accessor;
-};
-
-#endif
-
-#endif // _VIGRA_IMPEX2_EXTRAIMAGETRAITS_HXX
+#endif /* VIGRA_SIZED_INT_HXX */
src/foreign/vigra/impexalpha.hxx to src/include/vigra_ext/impexalpha.hxx
--- a/src/foreign/vigra/impexalpha.hxx
+++ b/src/include/vigra_ext/impexalpha.hxx
@@ -29,6 +29,7 @@
 #ifndef VIGRA_EXT_IMPEX_ALPHA_IMAGE_H
 #define VIGRA_EXT_IMPEX_ALPHA_IMAGE_H
 
+#include <iostream>
 #include <vigra/imageiterator.hxx>
 #include <vigra/transformimage.hxx>
 #include <vigra/initimage.hxx>
@@ -36,58 +37,244 @@
 
 #include <vigra/impex.hxx>
 
-
-#include "vigra_ext/FunctorAccessor.h"
-
 namespace vigra {
 
 
-template <class T1, class T2>
-struct GetAlphaScaleFactor;
-
-// define the scale factors to map from the alpha channel type (T2)
-// to valid alpha channels in image type (T1)
-// T1: image type
-// T2: alpha type
-//  S: scale factor (given as type of T1).
-#define VIGRA_EXT_GETALPHASCALE(T1,T2, S) \
+/** define values for mask true value. max for integers, 1 for floats
+ */
+template <class T1>
+struct GetMaskTrue;
+
+#define VIGRA_EXT_GETMASKTRUE(T1, S) \
 template<> \
-struct GetAlphaScaleFactor<T1, T2> \
+struct GetMaskTrue<T1> \
 { \
-    static vigra::NumericTraits<T1>::RealPromote get() \
-    { \
+    static T1 get() \
+{ \
 	return S; \
-    } \
+} \
 };
 
-// conversion from/to unsigned char
-VIGRA_EXT_GETALPHASCALE(unsigned char, unsigned char, 1);
-VIGRA_EXT_GETALPHASCALE(short, unsigned char, 128.498);
-VIGRA_EXT_GETALPHASCALE(unsigned short, unsigned char, 257);
-VIGRA_EXT_GETALPHASCALE(int, unsigned char, 8421504.49803922);
-VIGRA_EXT_GETALPHASCALE(unsigned int, unsigned char, 16843009);
-VIGRA_EXT_GETALPHASCALE(float, unsigned char, 1.0/255);
-VIGRA_EXT_GETALPHASCALE(double, unsigned char, 1.0/255);
-
-// conversion from/to unsigned short
-VIGRA_EXT_GETALPHASCALE(unsigned char, unsigned short, 0.00389105058365759);
-VIGRA_EXT_GETALPHASCALE(short, unsigned short, 0.499992370489052);
-VIGRA_EXT_GETALPHASCALE(unsigned short, unsigned short, 1);
-VIGRA_EXT_GETALPHASCALE(int, unsigned short, 32768.4999923705);
-VIGRA_EXT_GETALPHASCALE(unsigned int, unsigned short, 65537);
-VIGRA_EXT_GETALPHASCALE(float, unsigned short, 1.0/65535);
-VIGRA_EXT_GETALPHASCALE(double, unsigned short, 1.0/65535);
-
-// conversion from/to unsigned int
-VIGRA_EXT_GETALPHASCALE(unsigned char,  unsigned int, 5.93718141455603e-08);
-VIGRA_EXT_GETALPHASCALE(short,          unsigned int, 7.62916170238265e-06);
-VIGRA_EXT_GETALPHASCALE(unsigned short, unsigned int, 1.52585562354090e-05);
-VIGRA_EXT_GETALPHASCALE(int,            unsigned int, 0.499999999883585);
-VIGRA_EXT_GETALPHASCALE(unsigned int,   unsigned int, 1);
-VIGRA_EXT_GETALPHASCALE(float,          unsigned int, 1.0/4294967295.0);
-VIGRA_EXT_GETALPHASCALE(double,         unsigned int, 1.0/4294967295.0);
-
-#undef VIGRA_EXT_GETALPHASCALE
+#define VIGRA_EXT_GETMASKMAX(T1) \
+template<> \
+struct GetMaskTrue<T1> \
+{ \
+    static T1 get() \
+{ \
+	return vigra::NumericTraits<T1>::max(); \
+} \
+};
+
+VIGRA_EXT_GETMASKMAX(vigra::UInt8)
+VIGRA_EXT_GETMASKMAX(vigra::Int16)
+VIGRA_EXT_GETMASKMAX(vigra::UInt16)
+VIGRA_EXT_GETMASKMAX(vigra::Int32)
+VIGRA_EXT_GETMASKMAX(vigra::UInt32)
+VIGRA_EXT_GETMASKTRUE(float, 1.0f)
+VIGRA_EXT_GETMASKTRUE(double, 1.0)
+
+template <class Iter1, class Acc1, class Iter2, class Acc2>
+class MultiImageMaskAccessor2
+{
+public:
+        /** The accessors value_type: construct a pair that contains
+            the corresponding image values.
+        */
+    typedef vigra::TinyVector<typename Acc1::value_type, 2> value_type;
+    typedef typename Acc1::value_type component_type;
+    typedef typename Acc2::value_type alpha_type;
+
+        /** Construct from two image iterators and associated accessors.
+        */
+    MultiImageMaskAccessor2(Iter1 i1, Acc1 a1, Iter2 i2, Acc2 a2)
+    : i1_(i1), a1_(a1), i2_(i2), a2_(a2)
+    {}
+
+        /** read the current data item
+        */
+    template <class DIFFERENCE>
+    value_type operator()(DIFFERENCE const & d) const
+    {
+        return value_type(a1_(i1_, d),
+                          a2_(i2_, d)? GetMaskTrue<component_type>::get() : vigra::NumericTraits<component_type>::zero());
+    }
+
+        /** read the data item at an offset
+        */
+    template <class DIFFERENCE1, class DIFFERENCE2>
+    value_type operator()(DIFFERENCE1 d, DIFFERENCE2 const & d2) const
+    {
+        d += d2;
+        return value_type(a1_(i1_, d),
+                          a2_(i2_, d)? GetMaskTrue<component_type>::get() : vigra::NumericTraits<component_type>::zero());
+
+//        return std::make_pair(a1_(i1_, d1), a2_(i2_, d1));
+    }
+
+        /** write the current data item
+         */
+    template <class DIFFERENCE>
+    value_type set(const value_type & vt, DIFFERENCE const & d) const
+    {
+        a1_.set(vt[0], i1_, d);
+        a2_.set(vt[1] ? GetMaskTrue<alpha_type>::get() : vigra::NumericTraits<alpha_type>::zero(), i2_, d);
+    }
+
+    /** scalar & scalar image */
+    template <class V, class ITERATOR>
+    void setComponent( V const & value, ITERATOR const & i, int idx ) const
+    {
+        switch (idx) {
+        case 0:
+            a1_.set(value, i1_, *i);
+            break;
+        case 1:
+            a2_.set(value ? GetMaskTrue<alpha_type>::get() : vigra::NumericTraits<alpha_type>::zero(), i2_, *i);
+            break;
+        default:
+            vigra_fail("too many components in input value");
+        }
+    }
+
+    /** read one component */
+    template <class ITERATOR>
+    component_type getComponent(ITERATOR const & i, int idx) const
+    {
+        switch (idx) {
+            case 0:
+                return a1_( i1_, *i );
+            case 1:
+                return a2_( i2_, *i ) ? GetMaskTrue<component_type>::get() : vigra::NumericTraits<component_type>::zero();
+            default:
+                vigra_fail("too many components in input value");
+            // never reached, but here to silence compiler
+                exit(1);
+        }
+    }
+
+    template <class ITERATOR>
+    unsigned int size ( ITERATOR const & i ) const
+    {
+        return 2;
+    }
+
+private:
+    Iter1 i1_;
+    Acc1 a1_;
+    Iter2 i2_;
+    Acc2 a2_;
+};
+
+
+
+template <class Iter1, class Acc1, class Iter2, class Acc2>
+class MultiImageVectorMaskAccessor4
+{
+public:
+        /** The accessors value_type: construct a pair that contains
+            the corresponding image values.
+        */
+    typedef typename Acc1::value_type VT1;
+    // todo.. check static_size, currently static_size == 4
+    enum { static_size = 4 };
+
+    typedef vigra::TinyVector<typename VT1::value_type, static_size> value_type;
+    typedef typename value_type::value_type component_type;
+
+    typedef typename Acc2::value_type alpha_type;
+
+        /** Construct from two image iterators and associated accessors.
+        */
+    MultiImageVectorMaskAccessor4(Iter1 i1, Acc1 a1, Iter2 i2, Acc2 a2)
+    : i1_(i1), a1_(a1), i2_(i2), a2_(a2)
+    {}
+
+        /** read the current data item
+        */
+    template <class DIFFERENCE>
+    value_type operator()(DIFFERENCE const & d) const
+    {
+        const VT1 & v1 = a1_.get(i1_,d);
+        return value_type(v1[0],
+                          v1[1],
+                          v1[2],
+                          a2_(i2_, d)? GetMaskTrue<component_type>::get() : vigra::NumericTraits<component_type>::zero());
+    }
+
+        /** read the data item at an offset
+        */
+    template <class DIFFERENCE1, class DIFFERENCE2>
+    value_type operator()(DIFFERENCE1 d, DIFFERENCE2 const & d2) const
+    {
+        d += d2;
+        const VT1 & v1 = a1_.get(i1_,d);
+        return value_type(v1[0],
+                          v1[1],
+                          v1[2],
+                          a2_(i2_, d)? GetMaskTrue<component_type>::get() : vigra::NumericTraits<component_type>::zero());
+    }
+
+        /** write the current data item
+         */
+    template <class DIFFERENCE>
+    value_type set(const value_type & vt, DIFFERENCE const & d) const
+    {
+        Iter1 i1(i1_);
+        i1 +=d;
+        a1_.setComponent(vt[0], i1_, 0);
+        a1_.setComponent(vt[1], i1_, 1);
+        a1_.setComponent(vt[2], i1_, 2);
+        a2_.set(vt[3] ? GetMaskTrue<alpha_type>::get() : vigra::NumericTraits<alpha_type>::zero(), i2_, d);
+    }
+
+    /** vector & scalar image */
+    template <class V, class ITERATOR>
+    void setComponent( V const & value, ITERATOR const & i, int idx ) const
+    {
+        if ( idx < static_size - 1 ) {
+            a1_.setComponent(value, i1_, *i, idx);
+        } else if ( idx == static_size - 1 ) {
+            a2_.set(value? GetMaskTrue<alpha_type>::get() : vigra::NumericTraits<alpha_type>::zero(), i2_, *i);
+        } else {
+            vigra_fail("too many components in input value");
+        }
+    }
+
+    /** read one component */
+    template <class ITERATOR>
+    component_type getComponent(ITERATOR const & i, int idx) const
+    {
+        if ( idx < static_size - 1 ) {
+            return a1_.getComponent(i1_, *i, idx);
+        } else 
+#ifndef DEBUG
+            return a2_(i2_, *i)? GetMaskTrue<component_type>::get() : vigra::NumericTraits<component_type>::zero();
+#else
+            if ( idx == static_size - 1 ) {
+                return a2_(i2_, *i)? GetMaskTrue<component_type>::get() : vigra::NumericTraits<component_type>::zero();
+        } else {
+            vigra_fail("too many components in input value");
+            // just to silence the compiler warning. this is
+            // never reached, since vigra_fail will always
+            // throw an exception.
+            throw 0;
+        }
+#endif
+    }
+
+    template <class ITERATOR>
+    unsigned int size ( ITERATOR const & i ) const
+    {
+        return static_size;
+    }
+
+  private:
+    Iter1 i1_;
+    Acc1 a1_;
+    Iter2 i2_;
+    Acc2 a2_;
+};
+
 
 // scalar image
 template<class SrcIterator, class SrcAccessor,
@@ -97,34 +284,12 @@
 		      vigra::ImageExportInfo const & info,
 		      vigra::VigraTrueType)
 {
-    typedef typename SrcAccessor::value_type image_type;
-    typedef typename AlphaAccessor::value_type alpha_type;
-
-    typedef typename vigra::NumericTraits<image_type>::RealPromote ScaleType;
-    ScaleType scale =  GetAlphaScaleFactor<image_type, alpha_type>::get();
-    std::cerr << " export alpha factor: " << scale << std::endl;
-
-    // construct scaling accessor, for reading from the mask image
-    typedef vigra_ext::ReadFunctorAccessor<vigra::ScalarIntensityTransform<image_type>,
-	AlphaAccessor> ScalingAccessor;
-
-    vigra::ScalarIntensityTransform<image_type> scaler(scale);
-    ScalingAccessor scaleA(scaler,
-                           alpha.second);
-
-    // virtually merge image and mask
-    typedef vigra_ext::MergeScalarScalar2VectorAccessor<SrcIterator,
-	SrcAccessor, AlphaIterator, ScalingAccessor> MergeAccessor;
-
-    MergeAccessor mergeA(image.first, image.third, alpha.first, scaleA);
-
-    // do the export.
-    // need to use a Coordinate iterator, because the
-    // MergeAccessor requires coordinates, and not pointers to some memory
-    // of the first image.
+    typedef MultiImageMaskAccessor2<SrcIterator, SrcAccessor, AlphaIterator, AlphaAccessor> MAcc;
+
     exportImage(vigra::CoordinateIterator(),
                 vigra::CoordinateIterator() + (image.second - image.first),
-                mergeA, info);
+                MAcc(image.first, image.third, alpha.first, alpha.second),
+                info);
 }
 
 
@@ -136,37 +301,10 @@
 		      vigra::ImageExportInfo const & info,
 		      vigra::VigraFalseType)
 {
-    typedef typename SrcAccessor::value_type image_type;
-    typedef typename image_type::value_type component_type;
-    typedef typename AlphaAccessor::value_type alpha_type;
-
-    // get the correction factor
-    typedef typename vigra::NumericTraits<component_type>::RealPromote ScaleType;
-    ScaleType scale =  GetAlphaScaleFactor<component_type, alpha_type>::get();
-    std::cerr << " export alpha factor: " << scale << std::endl;
-
-    // construct scaling accessor.
-    typedef vigra_ext::ReadFunctorAccessor<vigra::ScalarIntensityTransform<component_type>,
-	AlphaAccessor> ScalingAccessor;
-
-    vigra::ScalarIntensityTransform<component_type> scaler(scale);
-    ScalingAccessor scaleA(scaler,
-			   alpha.second);
-
-    // virtually merge image and mask
-    // this is a hack! it only works with 3 component images..
-    // don't know how to get the size of a TinyVector at compile time
-    typedef vigra_ext::MergeVectorScalar2VectorAccessor<SrcIterator,
-	SrcAccessor, AlphaIterator, ScalingAccessor, 4> MergeAccessor;
-
-    MergeAccessor mergeA(image.first, image.third, alpha.first, scaleA);
-
-    // do the export.
-    // need to use a Coordinate iterator, because the
-    // MergeAccessor requires coordinates, and not pointers to some memory
-    // of the first image.
+    typedef MultiImageVectorMaskAccessor4<SrcIterator, SrcAccessor, AlphaIterator, AlphaAccessor> MAcc;
+
     exportImage(vigra::CoordinateIterator(), vigra::CoordinateIterator(image.second - image.first),
-		mergeA, info);
+                MAcc(image.first, image.third, alpha.first, alpha.second), info );
 }
 
 
@@ -200,57 +338,13 @@
 		      std::pair<AlphaIterator, AlphaAccessor> alpha,
 		      		      vigra::VigraFalseType)
 {
-    typedef typename DestAccessor::value_type image_type;
-    typedef typename image_type::value_type component_type;
-    typedef typename AlphaAccessor::value_type alpha_type;
-
-    typedef typename vigra::NumericTraits<component_type>::RealPromote ScaleType;
-
-    // get the correction factor
-    ScaleType scale = vigra::NumericTraits<ScaleType>::one()/GetAlphaScaleFactor<component_type, alpha_type>::get();
-    std::cerr << " import alpha factor: " << scale << std::endl;
-
-    // construct scaling accessor.
-    typedef vigra_ext::WriteFunctorAccessor<vigra::ScalarIntensityTransform<ScaleType>,
-	AlphaAccessor> ScalingAccessor;
-
-    vigra::ScalarIntensityTransform<ScaleType> scaler(scale);
-    ScalingAccessor scaleA(scaler,
-			   alpha.second);
-
-    // virtually merge image and mask
-    // this is a hack! it only works with 3 component images..
-    // don't know how to get the size of a TinyVector at compile time
-    typedef vigra_ext::SplitVectorNAccessor<DestIterator,
-	DestAccessor, AlphaIterator, ScalingAccessor, 4> SplitRGBAccessor;
-
-    typedef vigra_ext::SplitVectorNAccessor<DestIterator,
-	DestAccessor, AlphaIterator, ScalingAccessor, 2> SplitAccessor;
-
-    switch (image.second(image.first).size()) {
-    case 1:
-    {
-        vigra_ext::SplitVectorNAccessor<DestIterator, DestAccessor, AlphaIterator, ScalingAccessor, 2>
-            splitA(image.first, image.second, alpha.first, scaleA);
-
-        importImage(info,
-		vigra::CoordinateIterator(),
-		splitA);
-        break;
-    }
-    case 3:
-    {
-        vigra_ext::SplitVectorNAccessor<DestIterator, DestAccessor, AlphaIterator, ScalingAccessor, 4>
-            splitA(image.first, image.second, alpha.first, scaleA);
-
-        importImage(info,
-		vigra::CoordinateIterator(),
-		splitA);
-        break;
-    }
-    default:
-        vigra_fail("only 1 and 3 channel images supported by impexalpha.hxx");
-    }
+    vigra_precondition(image.second(image.first).size() == 3,
+                       "only scalar and 3 channel (vector) images supported by impexalpha.hxx");
+
+    typedef MultiImageVectorMaskAccessor4<DestIterator, DestAccessor, AlphaIterator, AlphaAccessor> MAcc;
+    importImage(info,
+                vigra::CoordinateIterator(),
+                MAcc(image.first, image.second, alpha.first, alpha.second) );
 }
 
 // scalar image
@@ -261,38 +355,10 @@
 		      std::pair<AlphaIterator, AlphaAccessor> alpha,
 		      vigra::VigraTrueType)
 {
-    typedef typename DestAccessor::value_type image_type;
-    typedef typename AlphaAccessor::value_type alpha_type;
-
-    typedef typename vigra::NumericTraits<image_type>::RealPromote ScaleType;
-
-    // get the correction factor
-    ScaleType scale = vigra::NumericTraits<ScaleType>::one()/GetAlphaScaleFactor<image_type, alpha_type>::get();
-
-    std::cerr << " export alpha factor: " << scale << std::endl;
-
-    // construct scaling accessor.
-    typedef vigra_ext::WriteFunctorAccessor<vigra::ScalarIntensityTransform<ScaleType>,
-	AlphaAccessor> ScalingAccessor;
-
-    vigra::ScalarIntensityTransform<ScaleType> scaler(scale);
-    ScalingAccessor scaleA(scaler,
-			   alpha.second);
-
-    // virtually merge image and mask
-    // this is a hack! it only works with 3 component images..
-    // don't know how to get the size of a TinyVector at compile time
-    typedef vigra_ext::SplitVector2Accessor<DestIterator,
-	DestAccessor, AlphaIterator, ScalingAccessor> SplitAccessor;
-
-    SplitAccessor splitA(image.first, image.second, alpha.first, scaleA);
-
-    // do the import
-    // need to use a Coordinate iterator, because the
-    // MergeAccessor requires coordinates, and not pointers to some memory
-    // of the first image.
+    typedef MultiImageMaskAccessor2<DestIterator, DestAccessor, AlphaIterator, AlphaAccessor> MAcc;
+
     importImage(info, vigra::CoordinateIterator(),
-		splitA);
+                MAcc(image.first, image.second, alpha.first, alpha.second) );
 }
 
 
<< < 1 .. 4 5 6 (Page 6 of 6)