/************************************************************************/ /* */ /* Copyright 1998-2002 by Ullrich Koethe */ /* Cognitive Systems Group, University of Hamburg, Germany */ /* */ /* This file is part of the VIGRA computer vision library. */ /* 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. */ /* */ /************************************************************************/ #ifndef VIGRA_RGBVALUE_HXX #define VIGRA_RGBVALUE_HXX #include // abs(double) #include // abs(int) #include "vigra/config.hxx" #include "vigra/numerictraits.hxx" #include "vigra/accessor.hxx" #include "vigra/tinyvector.hxx" #include "vigra/static_assert.hxx" namespace vigra { namespace detail { template struct SelectColorIndexRHS; template struct SelectColorIndexRHS<0, R, G, B> { enum { res = R }; }; template struct SelectColorIndexRHS<1, R, G, B> { enum { res = G }; }; template struct SelectColorIndexRHS<2, R, G, B> { enum { res = B }; }; } // namespace detail #ifndef DOXYGEN template struct RGBValue_bad_color_indices : staticAssert::AssertBool<(R < 3 && G < 3 && B < 3 && ((1 << R) + (1 << G) + (1 << B) == 7))> {}; #endif /* DOXYGEN */ /********************************************************/ /* */ /* RGBValue */ /* */ /********************************************************/ /** \brief Class for a single RGB value. This class contains three values (of the specified type) that represent red, green, and blue color channels. By means of the template parameters RED_IDX, GREEN_IDX, BLUE_IDX, the indices 0, 1, 2 can be assigned to the three colors arbitrarily, so that, for example, a BGR type can be created as \code typedef RGBValue BGRValue; \endcode The standard order red=0, green=1, blue=2 is the default. There are three possibilities to access the color values: accessor functions (\ref red(), \ref green(), \ref blue()), index operator (operator[](dx), where the rgb[RED_IDX] returns red etc.) and iterator (STL-compatible random access iterator that references the three colors in turn). The latter two methods, together with the necessary embedded typedefs, ensure compatibility of a RGBValue with a STL vector. \ref RGBValueOperators "Arithmetic operations" are defined as component-wise applications of these operations. Addition, subtraction, and multiplication of two RGBValues (+=, -=, *=, +, -, *, unary -), multiplication and division of an RGBValue with a double, and NumericTraits/PromoteTraits are defined, so that RGBValue fulfills the requirements of a \ref LinearAlgebra. A number of \ref RGBValueAccessors "accessors" are provided that support access to RGBValues as a whole, to a selected color component, or to the luminance value. \#include "vigra/rgbvalue.hxx"
Namespace: vigra */ template class RGBValue : public TinyVector { typedef TinyVector Base; // inverse mapping from index to color enum { IDX0 = (RED_IDX == 0) ? 0 : (GREEN_IDX == 0) ? 1 : 2, IDX1 = (RED_IDX == 1) ? 0 : (GREEN_IDX == 1) ? 1 : 2, IDX2 = (RED_IDX == 2) ? 0 : (GREEN_IDX == 2) ? 1 : 2 }; public: /** STL-compatible definition of valuetype */ typedef typename Base::value_type value_type; /** STL-compatible definition of iterator */ typedef typename Base::iterator iterator; /** STL-compatible definition of const iterator */ typedef typename Base::const_iterator const_iterator; /** squared norm type (result of squaredManitude()) */ typedef typename Base::SquaredNormType SquaredNormType; /** norm type (result of magnitude()) */ typedef typename Base::NormType NormType; /** Color index positions */ enum { RedIdx = RED_IDX, GreenIdx = GREEN_IDX, BlueIdx = BLUE_IDX }; /** Construct from explicit color values. \a first, \a second, \a third are written in this order, irrespective of how the color indices are specified. */ RGBValue(value_type first, value_type second, value_type third) : Base(first, second, third) { VIGRA_STATIC_ASSERT((RGBValue_bad_color_indices)); } /** Construct gray value */ RGBValue(value_type gray) : Base(gray, gray, gray) { VIGRA_STATIC_ASSERT((RGBValue_bad_color_indices)); } /** Construct from another sequence (must have length 3!) */ template RGBValue(Iterator i, Iterator end) : Base(i[0], i[1], i[2]) { VIGRA_STATIC_ASSERT((RGBValue_bad_color_indices)); } /** Default constructor (sets all components to 0) */ RGBValue() : Base(0, 0, 0) { VIGRA_STATIC_ASSERT((RGBValue_bad_color_indices)); } #if !defined(TEMPLATE_COPY_CONSTRUCTOR_BUG) RGBValue(RGBValue const & r) : Base(r) { VIGRA_STATIC_ASSERT((RGBValue_bad_color_indices)); } RGBValue & operator=(RGBValue const & r) { Base::operator=(r); return *this; } #endif // TEMPLATE_COPY_CONSTRUCTOR_BUG /** Copy constructor. */ template RGBValue(RGBValue const & r) : Base(detail::RequiresExplicitCast::cast(r[detail::SelectColorIndexRHS::res]), detail::RequiresExplicitCast::cast(r[detail::SelectColorIndexRHS::res]), detail::RequiresExplicitCast::cast(r[detail::SelectColorIndexRHS::res])) { VIGRA_STATIC_ASSERT((RGBValue_bad_color_indices)); } /** Copy assignment. */ template RGBValue & operator=(RGBValue const & r) { setRed(detail::RequiresExplicitCast::cast(r.red())); setGreen(detail::RequiresExplicitCast::cast(r.green())); setBlue(detail::RequiresExplicitCast::cast(r.blue())); return *this; } /** construct from TinyVector */ RGBValue(TinyVector const & r) : Base(r) { VIGRA_STATIC_ASSERT((RGBValue_bad_color_indices)); } /** assign TinyVector. */ RGBValue & operator=(TinyVector const & r) { Base::operator=(r); return *this; } /** Unary negation (construct RGBValue with negative values) */ RGBValue operator-() const { return RGBValue(-red(), -green(), -blue()); } /** Access red component. */ value_type & red() { return (*this)[RED_IDX]; } /** Access green component. */ value_type & green() { return (*this)[GREEN_IDX]; } /** Access blue component. */ value_type & blue() { return (*this)[BLUE_IDX]; } /** Get red component. */ value_type const & red() const { return (*this)[RED_IDX]; } /** Get green component. */ value_type const & green() const { return (*this)[GREEN_IDX]; } /** Get blue component. */ value_type const & blue() const { return (*this)[BLUE_IDX]; } /** Calculate luminance. */ value_type luminance() const { return detail::RequiresExplicitCast::cast(0.3*red() + 0.59*green() + 0.11*blue()); } // mihal 20061017 quick-and-dirty hue calculation value_type hue() const { value_type max = std::max(red(), std::max(green(), blue())); value_type min = std::min(red(), std::min(green(), blue())); value_type delta = (max - min) * 6; typename NumericTraits::RealPromote rdelta = NumericTraits::toRealPromote(delta); typename NumericTraits::RealPromote h = 0.0; if (red() == max) h = (green() - blue()) / rdelta; else if (green() == max) h = (1/3) + ((blue() - red()) / rdelta); else h = (2/3) + ((red() - green()) / rdelta); if (h < 0.0) h += 1.0; return NumericTraits::fromRealPromote(h * NumericTraits::max()); } /** Calculate magnitude. */ NormType magnitude() const { return Base::magnitude(); } /** Calculate squared magnitude. */ SquaredNormType squaredMagnitude() const { return Base::squaredMagnitude(); } /** Set red component. The type V of the passed in value is automatically converted to VALUETYPE. */ template void setRed(V value) { (*this)[RED_IDX] = detail::RequiresExplicitCast::cast(value); } /** Set green component.The type V of the passed in value is automatically converted to VALUETYPE. */ template void setGreen(V value) { (*this)[GREEN_IDX] = detail::RequiresExplicitCast::cast(value); } /** Set blue component.The type V of the passed in value is automatically converted to VALUETYPE. */ template void setBlue(V value) { (*this)[BLUE_IDX] = detail::RequiresExplicitCast::cast(value); } template void setRGB(V r, V g, V b) { (*this)[RED_IDX] = detail::RequiresExplicitCast::cast(r); (*this)[GREEN_IDX] = detail::RequiresExplicitCast::cast(g); (*this)[BLUE_IDX] = detail::RequiresExplicitCast::cast(b); } }; /********************************************************/ /* */ /* RGBValue Comparison */ /* */ /********************************************************/ /** \addtogroup RGBValueOperators Functions for RGBValue \brief \#include "vigra/rgbvalue.hxx These functions fulfill the requirements of a Linear Algebra. Return types are determined according to \ref RGBValueTraits. Namespace: vigra

*/ //@{ /// component-wise equal template inline bool operator==(RGBValue const & l, RGBValue const & r) { return (l.red() == r.red()) && (l.green() == r.green()) && (l.blue() == r.blue()); } /// component-wise not equal template inline bool operator!=(RGBValue const & l, RGBValue const & r) { return (l.red() != r.red()) || (l.green() != r.green()) || (l.blue() != r.blue()); } //@} /********************************************************/ /* */ /* RGBValue-Traits */ /* */ /********************************************************/ /** \page RGBValueTraits Numeric and Promote Traits of RGBValue The numeric and promote traits for RGBValues follow the general specifications for \ref NumericPromotionTraits. They are implemented in terms of the traits of the basic types by partial template specialization. Note that PromoteTraits are only defined for the case that the color indices are the same in both RGBValues. \code template struct NumericTraits > { typedef RGBValue Type; typedef RGBValue::Promote, R, G, B> Promote; typedef RGBValue::RealPromote, R, G, B> RealPromote; typedef RGBValue::ComplexPromote, R, G, B> ComplexPromote; typedef T ValueType; typedef typename NumericTraits::isIntegral isIntegral; typedef VigraFalseType isScalar; typedef typename NumericTraits::isSigned isSigned; // etc. }; template struct NormTraits > { typedef RGBValue Type; typedef typename Type::SquaredNormType SquaredNormType; typedef typename Type::NormType NormType; }; template struct PromoteTraits, RGBValue > { typedef RGBValue::Promote, R, G, B> Promote; }; template struct PromoteTraits, double > { typedef RGBValue::RealPromote, R, G, B> Promote; }; template struct PromoteTraits > { typedef RGBValue::RealPromote, R, G, B> Promote; }; \endcode \#include "vigra/rgbvalue.hxx"
Namespace: vigra */ #if !defined(NO_PARTIAL_TEMPLATE_SPECIALIZATION) template struct NumericTraits > { typedef RGBValue Type; typedef RGBValue::Promote, R, G, B> Promote; typedef RGBValue::RealPromote, R, G, B> RealPromote; typedef RGBValue::ComplexPromote, R, G, B> ComplexPromote; typedef T ValueType; typedef typename NumericTraits::isIntegral isIntegral; typedef VigraFalseType isScalar; typedef typename NumericTraits::isSigned isSigned; typedef VigraFalseType isOrdered; typedef VigraFalseType isComplex; static Type zero() { return Type(NumericTraits::zero()); } static Type one() { return Type(NumericTraits::one()); } static Type nonZero() { return Type(NumericTraits::nonZero()); } static Promote toPromote(Type const & v) { return Promote(v); } static RealPromote toRealPromote(Type const & v) { return RealPromote(v); } static Type fromPromote(Promote const & v) { return Type(NumericTraits::fromPromote(v.red()), NumericTraits::fromPromote(v.green()), NumericTraits::fromPromote(v.blue())); } static Type fromRealPromote(RealPromote const & v) { return Type(NumericTraits::fromRealPromote(v.red()), NumericTraits::fromRealPromote(v.green()), NumericTraits::fromRealPromote(v.blue())); } }; template struct NormTraits > { typedef RGBValue Type; typedef typename Type::SquaredNormType SquaredNormType; typedef typename Type::NormType NormType; }; template struct PromoteTraits, RGBValue > { typedef RGBValue::Promote, R, G, B> Promote; }; template struct PromoteTraits, double > { typedef RGBValue::RealPromote, R, G, B> Promote; }; template struct PromoteTraits > { typedef RGBValue::RealPromote, R, G, B> Promote; }; #else // NO_PARTIAL_TEMPLATE_SPECIALIZATION #define RGBVALUE_NUMTRAITS(T) \ template<>\ struct NumericTraits >\ {\ typedef RGBValue Type; \ typedef RGBValue::Promote> Promote; \ typedef RGBValue::RealPromote> RealPromote; \ typedef RGBValue::ComplexPromote> ComplexPromote; \ typedef T ValueType; \ \ typedef NumericTraits::isIntegral isIntegral; \ typedef VigraFalseType isScalar; \ typedef NumericTraits::isSigned isSigned; \ typedef VigraFalseType isOrdered; \ typedef VigraFalseType isComplex; \ \ static RGBValue zero() { \ return RGBValue(NumericTraits::zero()); \ }\ static RGBValue one() { \ return RGBValue(NumericTraits::one()); \ }\ static RGBValue nonZero() { \ return RGBValue(NumericTraits::nonZero()); \ }\ \ static Promote toPromote(RGBValue const & v) { \ return Promote(v); \ }\ static RealPromote toRealPromote(RGBValue const & v) { \ return RealPromote(v); \ }\ static RGBValue fromPromote(Promote const & v) { \ RGBValue res;\ RGBValue::iterator d = res.begin();\ Promote::const_iterator s = v.begin();\ for(; d != res.end(); ++d, ++s)\ *d = NumericTraits::fromPromote(*s);\ return res;\ }\ static RGBValue fromRealPromote(RealPromote const & v) {\ RGBValue res;\ RGBValue::iterator d = res.begin();\ RealPromote::const_iterator s = v.begin();\ for(; d != res.end(); ++d, ++s)\ *d = NumericTraits::fromRealPromote(*s);\ return res;\ }\ }; \ template<>\ struct NormTraits >\ {\ typedef RGBValue Type;\ typedef Type::SquaredNormType SquaredNormType; \ typedef Type::NormType NormType; \ }; #define RGBVALUE_PROMTRAITS1(type1) \ template<> \ struct PromoteTraits, RGBValue > \ { \ typedef RGBValue::Promote> Promote; \ static Promote toPromote(RGBValue const & v) { \ return static_cast(v); } \ }; \ template <> \ struct PromoteTraits, double > \ { \ typedef RGBValue::RealPromote> Promote; \ }; \ template <> \ struct PromoteTraits > \ { \ typedef RGBValue::RealPromote> Promote; \ }; #define RGBVALUE_PROMTRAITS2(type1, type2) \ template<> \ struct PromoteTraits, RGBValue > \ { \ typedef RGBValue::Promote> Promote; \ static Promote toPromote(RGBValue const & v) { \ return static_cast(v); } \ static Promote toPromote(RGBValue const & v) { \ return static_cast(v); } \ }; RGBVALUE_NUMTRAITS(unsigned char) RGBVALUE_NUMTRAITS(int) RGBVALUE_NUMTRAITS(float) RGBVALUE_NUMTRAITS(double) RGBVALUE_PROMTRAITS1(unsigned char) RGBVALUE_PROMTRAITS1(int) RGBVALUE_PROMTRAITS1(float) RGBVALUE_PROMTRAITS1(double) RGBVALUE_PROMTRAITS2(float, unsigned char) RGBVALUE_PROMTRAITS2(unsigned char, float) RGBVALUE_PROMTRAITS2(int, unsigned char) RGBVALUE_PROMTRAITS2(unsigned char, int) RGBVALUE_PROMTRAITS2(int, float) RGBVALUE_PROMTRAITS2(float, int) RGBVALUE_PROMTRAITS2(double, unsigned char) RGBVALUE_PROMTRAITS2(unsigned char, double) RGBVALUE_PROMTRAITS2(int, double) RGBVALUE_PROMTRAITS2(double, int) RGBVALUE_PROMTRAITS2(double, float) RGBVALUE_PROMTRAITS2(float, double) #undef RGBVALUE_NUMTRAITS #undef RGBVALUE_PROMTRAITS1 #undef RGBVALUE_PROMTRAITS2 #endif // NO_PARTIAL_TEMPLATE_SPECIALIZATION /********************************************************/ /* */ /* RGBValue-Arithmetic */ /* */ /********************************************************/ /** \addtogroup RGBValueOperators */ //@{ /// componentwise add-assignment template inline RGBValue & operator+=(RGBValue & l, RGBValue const & r) { l.red() += r.red(); l.green() += r.green(); l.blue() += r.blue(); return l; } /// componentwise subtract-assignment template inline RGBValue & operator-=(RGBValue & l, RGBValue const & r) { l.red() -= r.red(); l.green() -= r.green(); l.blue() -= r.blue(); return l; } /// componentwise multiply-assignment template inline RGBValue & operator*=(RGBValue & l, RGBValue const & r) { l.red() *= r.red(); l.green() *= r.green(); l.blue() *= r.blue(); return l; } /// componentwise divide-assignment // mihal 20060909 template inline RGBValue & operator/=(RGBValue & l, RGBValue const & r) { l.red() /= r.red(); l.green() /= r.green(); l.blue() /= r.blue(); return l; } /// componentwise scalar multiply-assignment template inline RGBValue & operator*=(RGBValue & l, RV r) { l.red() *= r; l.green() *= r; l.blue() *= r; return l; } /// componentwise scalar divide-assignment template inline RGBValue & operator/=(RGBValue & l, RV r) { l.red() /= r; l.green() /= r; l.blue() /= r; return l; } /// component-wise right shift assignment // mihal 20050724 template inline RGBValue & operator>>=(RGBValue & l, const unsigned int s) { l.red() >>= s; l.green() >>= s; l.blue() >>= s; return l; } template inline RGBValue & operator>>=(RGBValue & l, const unsigned int s) { double scale = (double)(1 << s); l.red() /= scale; l.green() /= scale; l.blue() /= scale; return l; } template inline RGBValue & operator>>=(RGBValue & l, const unsigned int s) { float scale = (float)(1 << s); l.red() /= scale; l.green() /= scale; l.blue() /= scale; return l; } /// component-wise left shift assignment // mihal 20050724 template inline RGBValue & operator<<=(RGBValue & l, const unsigned int s) { l.red() <<= s; l.green() <<= s; l.blue() <<= s; return l; } template inline RGBValue & operator<<=(RGBValue & l, const unsigned int s) { double scale = (double)(1 << s); //exp2(s); l.red() *= scale; l.green() *= scale; l.blue() *= scale; return l; } template inline RGBValue & operator<<=(RGBValue & l, const unsigned int s) { float scale = (float)(1 << s); //exp2(s); l.red() *= scale; l.green() *= scale; l.blue() *= scale; return l; } using VIGRA_CSTD::abs; /// component-wise absolute value template inline RGBValue abs(RGBValue const & v) { return RGBValue(abs(v.red()), abs(v.green()), abs(v.blue())); } /// component-wise addition template inline typename PromoteTraits, RGBValue >::Promote operator+(RGBValue const & r1, RGBValue const & r2) { typename PromoteTraits, RGBValue >::Promote res(r1); res += r2; return res; } /// component-wise subtraction template inline typename PromoteTraits, RGBValue >::Promote operator-(RGBValue const & r1, RGBValue const & r2) { typename PromoteTraits, RGBValue >::Promote res(r1); res -= r2; return res; } /// component-wise multiplication template inline typename PromoteTraits, RGBValue >::Promote operator*(RGBValue const & r1, RGBValue const & r2) { typename PromoteTraits, RGBValue >::Promote res(r1); res *= r2; return res; } /// component-wise division // mihal 20060909 template inline typename PromoteTraits, RGBValue >::Promote operator/(RGBValue const & r1, RGBValue const & r2) { typename PromoteTraits, RGBValue >::Promote res(r1); res /= r2; return res; } /// component-wise left scalar multiplication template inline typename PromoteTraits, RGBValue >::Promote operator*(RV v, RGBValue const & r) { return r * RGBValue(v); } /// component-wise right scalar multiplication template inline typename PromoteTraits, RGBValue >::Promote operator*(RGBValue const & r, RV v) { return r * RGBValue(v); } // /// component-wise scalar division template inline typename PromoteTraits, RGBValue >::Promote operator/(RGBValue const & r, RV v) { return r / RGBValue(v); } // /// component-wise left scalar multiplication //template //inline //typename NumericTraits >::RealPromote //operator*(double v, RGBValue const & r) //{ // typename NumericTraits >::RealPromote res(r); // // res *= v; // // return res; //} // /// component-wise right scalar multiplication //template //inline //typename NumericTraits >::RealPromote //operator*(RGBValue const & r, double v) //{ // typename NumericTraits >::RealPromote res(r); // // res *= v; // // return res; //} // /// component-wise scalar division //template //inline //typename NumericTraits >::RealPromote //operator/(RGBValue const & r, double v) //{ // typename NumericTraits >::RealPromote res(r); // // res /= v; // // return res; //} /// bit-wise and // mihal 20050724 template inline RGBValue operator&(RGBValue const & r1, RGBValue const & r2) { RGBValue res(r1.red() & r2.red(), r1.green() & r2.green(), r1.blue() & r2.blue()); return res; } /// component-wise right shift // mihal 20050712 template inline RGBValue operator>>(RGBValue const & r, int rs) { RGBValue res(r.red() >> rs, r.green() >> rs, r.blue() >> rs); return res; } template inline RGBValue operator>>(RGBValue const & r, int rs) { double scale = (double)(1 << rs); //exp2(rs); RGBValue res(r.red() / scale, r.green() / scale, r.blue() / scale); return res; } template inline RGBValue operator>>(RGBValue const & r, int rs) { float scale = (float)(1 << rs); //exp2(rs); RGBValue res(r.red() / scale, r.green() / scale, r.blue() / scale); return res; } /// component-wise left shift // mihal 20050714 template inline RGBValue operator<<(RGBValue const & r, int ls) { RGBValue res(r.red() << ls, r.green() << ls, r.blue() << ls); return res; } template inline RGBValue operator<<(RGBValue const & r, int ls) { double scale = (double)(1 << ls); //exp2(ls); RGBValue res(r.red() * scale, r.green() * scale, r.blue() * scale); return res; } template inline RGBValue operator<<(RGBValue const & r, int ls) { float scale = (float)(1 << ls); //exp2(ls); RGBValue res(r.red() * scale, r.green() * scale, r.blue() * scale); return res; } /// cross product template inline typename PromoteTraits, RGBValue >::Promote cross(RGBValue const & r1, RGBValue const & r2) { typedef typename PromoteTraits, RGBValue >::Promote Res; return Res(r1.green()*r2.blue() - r1.blue()*r2.green(), r1.blue()*r2.red() - r1.red()*r2.blue(), r1.red()*r2.green() - r1.green()*r2.red()); } /// dot product template inline typename PromoteTraits::Promote dot(RGBValue const & r1, RGBValue const & r2) { return r1.red()*r2.red() + r1.green()*r2.green() + r1.blue()*r2.blue(); } using VIGRA_CSTD::ceil; /** Apply ceil() function to each RGB component. */ template inline RGBValue ceil(RGBValue const & r) { return RGBValue(ceil(r.red()), ceil(r.green()), ceil(r.blue())); } using VIGRA_CSTD::floor; /** Apply floor() function to each RGB component. */ template inline RGBValue floor(RGBValue const & r) { return RGBValue(floor(r.red()), floor(r.green()), floor(r.blue())); } //@} /********************************************************/ /* */ /* RGBValue-Accessors */ /* */ /********************************************************/ /** \addtogroup DataAccessors */ //@{ /** \defgroup RGBValueAccessors Accessors for RGBValue */ //@{ /** Encapsulate access to rgb values. \#include "vigra/rgbvalue.hxx"
Namespace: vigra */ template class RGBAccessor : public VectorAccessor { public: typedef typename RGBVALUE::value_type component_type; /** Get value of the red component */ template component_type const & red(RGBIterator const & rgb) const { return (*rgb).red(); } template void setRGB(V r, V g, V b, RGBIterator const & rgb) const { (*rgb).setRGB( r, g, b ); } /** Set value of the red component. The type V of the passed in value is automatically converted to component_type. */ template void setRed(V value, RGBIterator const & rgb) const { (*rgb).setRed(value); } /** Get value of the red component at an offset */ template component_type const & red(RGBIterator const & rgb, DIFFERENCE diff) const { return rgb[diff].red(); } /** Set value of the red component at an offset. The type V of the passed in value is automatically converted to component_type. */ template void setRed(V value, RGBIterator const & rgb, DIFFERENCE diff) const { rgb[diff].setRed(value); } /** Get value of the green component */ template component_type const & green(RGBIterator const & rgb) const { return (*rgb).green(); } /** Set value of the green component. The type V of the passed in value is automatically converted to component_type. */ template void setGreen(V value, RGBIterator const & rgb) const { (*rgb).setGreen(value); } /** Get value of the green component at an offset */ template component_type const & green(RGBIterator const & rgb, DIFFERENCE d) const { return rgb[d].green(); } /** Set value of the green component at an offset. The type V of the passed in value is automatically converted to component_type. */ template void setGreen(V value, RGBIterator const & rgb, DIFFERENCE d) const { rgb[d].setGreen(value); } /** Get value of the blue component */ template component_type const & blue(RGBIterator const & rgb) const { return (*rgb).blue(); } /** Set value of the blue component. The type V of the passed in value is automatically converted to component_type. */ template void setBlue(V value, RGBIterator const & rgb) const { (*rgb).setBlue(value); } /** Get value of the blue component at an offset */ template component_type const & blue(RGBIterator const & rgb, DIFFERENCE d) const { return rgb[d].blue(); } /** Set value of the blue component at an offset. The type V of the passed in value is automatically converted to component_type. */ template void setBlue(V value, RGBIterator const & rgb, DIFFERENCE d) const { rgb[d].setBlue(value); } }; /********************************************************/ /* */ /* RedAccessor */ /* */ /********************************************************/ /** Encapsulate access to red band of an rgb value. \#include "vigra/rgbvalue.hxx"
Namespace: vigra */ template class RedAccessor { public: typedef typename RGBVALUE::value_type value_type; /** Get value of the red component */ template value_type const & operator()(ITERATOR const & i) const { return (*i).red(); } /** Get value of the red component at an offset */ template value_type const & operator()(ITERATOR const & i, DIFFERENCE d) const { return i[d].red(); } /** Set value of the red component. The type V of the passed in value is automatically converted to value_type. */ template void set(V value, ITERATOR const & i) const { (*i).setRed(value); } /** Set value of the red component at an offset. The type V of the passed in value is automatically converted to value_type. */ template void set(V value, ITERATOR const & i, DIFFERENCE d) const { i[d].setRed(value); } }; /********************************************************/ /* */ /* GreenAccessor */ /* */ /********************************************************/ /** Encapsulate access to green band of an rgb value. \#include "vigra/rgbvalue.hxx"
Namespace: vigra */ template class GreenAccessor { public: typedef typename RGBVALUE::value_type value_type; /** Get value of the green component */ template value_type const & operator()(ITERATOR const & i) const { return (*i).green(); } /** Get value of the green component at an offset */ template value_type const & operator()(ITERATOR const & i, DIFFERENCE d) const { return i[d].green(); } /** Set value of the green component. The type V of the passed in value is automatically converted to value_type. */ template void set(V value, ITERATOR const & i) const { (*i).setGreen(value); } /** Set value of the green component at an offset. The type V of the passed in value is automatically converted to value_type. */ template void set(V value, ITERATOR const & i, DIFFERENCE d) const { i[d].setGreen(value); } }; /********************************************************/ /* */ /* BlueAccessor */ /* */ /********************************************************/ /** Encapsulate access to blue band of an rgb value. \#include "vigra/rgbvalue.hxx"
Namespace: vigra */ template class BlueAccessor { public: typedef typename RGBVALUE::value_type value_type; /** Get value of the blue component */ template value_type const & operator()(ITERATOR const & i) const { return (*i).blue(); } /** Get value of the blue component at an offset */ template value_type const & operator()(ITERATOR const & i, DIFFERENCE d) const { return i[d].blue(); } /** Set value of the blue component. The type V of the passed in value is automatically converted to value_type. */ template void set(V value, ITERATOR const & i) const { (*i).setBlue(value); } /** Set value of the blue component at an offset. The type V of the passed in value is automatically converted to value_type. */ template void set(V value, ITERATOR const & i, DIFFERENCE d) const { i[d].setBlue(value); } }; /********************************************************/ /* */ /* RGBToGrayAccessor */ /* */ /********************************************************/ /** Encapsulate access to luminance of an rgb value. \#include "vigra/rgbvalue.hxx"
Namespace: vigra */ template class RGBToGrayAccessor { public: typedef typename RGBVALUE::value_type value_type; /** Get value of the luminance */ template value_type operator()(ITERATOR const & i) const { return (*i).luminance(); } /** Get value of the luminance at an offset */ template value_type operator()(ITERATOR const & i, DIFFERENCE d) const { return i[d].luminance(); } }; /********************************************************/ /* */ /* GrayToRGBAccessor */ /* */ /********************************************************/ /** Create an RGB view for a grayscale image by making all three channels equal. \#include "vigra/rgbvalue.hxx"
Namespace: vigra */ template class GrayToRGBAccessor { public: typedef typename vigra::RGBValue value_type; /** Get RGB value for the given pixel. */ template value_type operator()(ITERATOR const & i) const { return value_type(*i,*i,*i); } /** Get RGB value at an offset */ template value_type operator()(ITERATOR const & i, DIFFERENCE d) const { return value_type(i[d],i[d],i[d]); } }; //@} //@} } // namespace vigra #endif // VIGRA_RGBVALUE_HXX