37 #ifndef VIGRA_RGBVALUE_HXX
38 #define VIGRA_RGBVALUE_HXX
43 #include "numerictraits.hxx"
44 #include "accessor.hxx"
45 #include "tinyvector.hxx"
46 #include "static_assert.hxx"
52 template <
unsigned int I,
unsigned int R,
unsigned int G,
unsigned int B>
53 struct SelectColorIndexRHS;
55 template <
unsigned int R,
unsigned int G,
unsigned int B>
56 struct SelectColorIndexRHS<0, R, G, B>
61 template <
unsigned int R,
unsigned int G,
unsigned int B>
62 struct SelectColorIndexRHS<1, R, G, B>
67 template <
unsigned int R,
unsigned int G,
unsigned int B>
68 struct SelectColorIndexRHS<2, R, G, B>
77 template <
unsigned int R,
unsigned int G,
unsigned int B>
78 struct RGBValue_bad_color_indices
79 : staticAssert::AssertBool<(R < 3 && G < 3 && B < 3 &&
80 ((1 << R) + (1 << G) + (1 << B) == 7))>
125 template <class VALUETYPE, unsigned int RED_IDX = 0, unsigned int GREEN_IDX = 1, unsigned int BLUE_IDX = 2>
127 : public TinyVector<VALUETYPE, 3>
129 typedef TinyVector<VALUETYPE, 3> Base;
133 IDX0 = (RED_IDX == 0) ? 0 : (GREEN_IDX == 0) ? 1 : 2,
134 IDX1 = (RED_IDX == 1) ? 0 : (GREEN_IDX == 1) ? 1 : 2,
135 IDX2 = (RED_IDX == 2) ? 0 : (GREEN_IDX == 2) ? 1 : 2
141 typedef typename Base::value_type value_type;
144 typedef typename Base::iterator iterator;
147 typedef typename Base::const_iterator const_iterator;
150 typedef typename Base::SquaredNormType SquaredNormType;
153 typedef typename Base::NormType NormType;
155 typedef typename Base::reference reference;
156 typedef typename Base::const_reference const_reference;
157 typedef typename Base::pointer pointer;
158 typedef typename Base::const_pointer const_pointer;
159 typedef typename Base::size_type size_type;
160 typedef typename Base::difference_type difference_type;
161 typedef typename Base::scalar_multiplier scalar_multiplier;
162 typedef typename Base::ReverseCopyTag ReverseCopyTag;
169 GreenIdx = GREEN_IDX,
177 RGBValue(value_type first, value_type second, value_type third)
178 : Base(first, second, third)
180 VIGRA_STATIC_ASSERT((RGBValue_bad_color_indices<RED_IDX, GREEN_IDX, BLUE_IDX>));
185 RGBValue(value_type gray)
186 : Base(gray, gray, gray)
188 VIGRA_STATIC_ASSERT((RGBValue_bad_color_indices<RED_IDX, GREEN_IDX, BLUE_IDX>));
194 explicit RGBValue(const_pointer i)
197 VIGRA_STATIC_ASSERT((RGBValue_bad_color_indices<RED_IDX, GREEN_IDX, BLUE_IDX>));
202 RGBValue(const_pointer i, ReverseCopyTag reverse)
205 VIGRA_STATIC_ASSERT((RGBValue_bad_color_indices<RED_IDX, GREEN_IDX, BLUE_IDX>));
213 VIGRA_STATIC_ASSERT((RGBValue_bad_color_indices<RED_IDX, GREEN_IDX, BLUE_IDX>));
216 #if !defined(TEMPLATE_COPY_CONSTRUCTOR_BUG)
218 RGBValue(RGBValue const & r)
219 : Base((Base const &)r)
221 VIGRA_STATIC_ASSERT((RGBValue_bad_color_indices<RED_IDX, GREEN_IDX, BLUE_IDX>));
224 RGBValue & operator=(RGBValue const & r)
234 template <class U, unsigned int R, unsigned int G, unsigned int B>
235 RGBValue(RGBValue<U, R, G, B> const & r)
236 : Base(detail::RequiresExplicitCast<value_type>::cast(r[detail::SelectColorIndexRHS<IDX0, R, G, B>::res]),
237 detail::RequiresExplicitCast<value_type>::cast(r[detail::SelectColorIndexRHS<IDX1, R, G, B>::res]),
238 detail::RequiresExplicitCast<value_type>::cast(r[detail::SelectColorIndexRHS<IDX2, R, G, B>::res]))
240 VIGRA_STATIC_ASSERT((RGBValue_bad_color_indices<RED_IDX, GREEN_IDX, BLUE_IDX>));
245 template <class U, unsigned int R, unsigned int G, unsigned int B>
246 RGBValue & operator=(RGBValue<U, R, G, B> const & r)
248 setRed(detail::RequiresExplicitCast<value_type>::cast(r.red()));
249 setGreen(detail::RequiresExplicitCast<value_type>::cast(r.green()));
250 setBlue(detail::RequiresExplicitCast<value_type>::cast(r.blue()));
256 RGBValue(TinyVector<value_type, 3> const & r)
259 VIGRA_STATIC_ASSERT((RGBValue_bad_color_indices<RED_IDX, GREEN_IDX, BLUE_IDX>));
264 RGBValue & operator=(TinyVector<value_type, 3> const & r)
272 RGBValue operator-() const
274 return RGBValue(-(*this)[0], -(*this)[1], -(*this)[2]);
279 value_type & red() { return (*this)[RED_IDX]; }
283 value_type & green() { return (*this)[GREEN_IDX]; }
287 value_type & blue() { return (*this)[BLUE_IDX]; }
291 value_type const & red() const { return (*this)[RED_IDX]; }
295 value_type const & green() const { return (*this)[GREEN_IDX]; }
299 value_type const & blue() const { return (*this)[BLUE_IDX]; }
303 value_type luminance() const {
304 return detail::RequiresExplicitCast<value_type>::cast(0.3*red() + 0.59*green() + 0.11*blue()); }
308 NormType magnitude() const {
309 return Base::magnitude();
314 SquaredNormType squaredMagnitude() const {
315 return Base::squaredMagnitude();
322 void setRed(V value) { (*this)[RED_IDX] = detail::RequiresExplicitCast<value_type>::cast(value); }
328 void setGreen(V value) { (*this)[GREEN_IDX] = detail::RequiresExplicitCast<value_type>::cast(value); }
334 void setBlue(V value) { (*this)[BLUE_IDX] = detail::RequiresExplicitCast<value_type>::cast(value); }
338 void setRGB(V r, V g, V b)
340 (*this)[RED_IDX] = detail::RequiresExplicitCast<value_type>::cast(r);
341 (*this)[GREEN_IDX] = detail::RequiresExplicitCast<value_type>::cast(g);
342 (*this)[BLUE_IDX] = detail::RequiresExplicitCast<value_type>::cast(b);
366 template <class V1, unsigned int RIDX1, unsigned int GIDX1, unsigned int BIDX1,
367 class V2, unsigned int RIDX2, unsigned int GIDX2, unsigned int BIDX2>
370 operator==(RGBValue<V1, RIDX1, GIDX1, BIDX1> const & l,
371 RGBValue<V2, RIDX2, GIDX2, BIDX2> const & r)
373 return (l.red() == r.red()) &&
374 (l.green() == r.green()) &&
375 (l.blue() == r.blue());
379 template <class V1, unsigned int RIDX1, unsigned int GIDX1, unsigned int BIDX1,
380 class V2, unsigned int RIDX2, unsigned int GIDX2, unsigned int BIDX2>
383 operator!=(RGBValue<V1, RIDX1, GIDX1, BIDX1> const & l,
384 RGBValue<V2, RIDX2, GIDX2, BIDX2> const & r)
386 return (l.red() != r.red()) ||
387 (l.green() != r.green()) ||
388 (l.blue() != r.blue());
457 #if !defined(NO_PARTIAL_TEMPLATE_SPECIALIZATION)
459 template <class T, unsigned int R, unsigned int G, unsigned int B>
460 struct NumericTraits<RGBValue<T, R, G, B> >
462 typedef RGBValue<T, R, G, B> Type;
463 typedef RGBValue<typename NumericTraits<T>::Promote, R, G, B> Promote;
464 typedef RGBValue<typename NumericTraits<T>::RealPromote, R, G, B> RealPromote;
465 typedef RGBValue<typename NumericTraits<T>::ComplexPromote, R, G, B> ComplexPromote;
468 typedef typename NumericTraits<T>::isIntegral isIntegral;
469 typedef VigraFalseType isScalar;
470 typedef typename NumericTraits<T>::isSigned isSigned;
471 typedef VigraTrueType isOrdered;
472 typedef VigraFalseType isComplex;
476 return Type(NumericTraits<T>::zero());
480 return Type(NumericTraits<T>::one());
482 static Type nonZero()
484 return Type(NumericTraits<T>::nonZero());
489 return Type(NumericTraits<T>::min());
493 return Type(NumericTraits<T>::max());
496 static Promote toPromote(Type const & v)
500 static RealPromote toRealPromote(Type const & v)
502 return RealPromote(v);
504 static Type fromPromote(Promote const & v)
506 return Type(NumericTraits<T>::fromPromote(v.red()),
507 NumericTraits<T>::fromPromote(v.green()),
508 NumericTraits<T>::fromPromote(v.blue()));
510 static Type fromRealPromote(RealPromote const & v)
512 return Type(NumericTraits<T>::fromRealPromote(v.red()),
513 NumericTraits<T>::fromRealPromote(v.green()),
514 NumericTraits<T>::fromRealPromote(v.blue()));
518 template <class T, unsigned int R, unsigned int G, unsigned int B>
519 struct NormTraits<RGBValue<T, R, G, B> >
521 typedef RGBValue<T, R, G, B> Type;
522 typedef typename Type::SquaredNormType SquaredNormType;
523 typedef typename Type::NormType NormType;
526 template <class T1, unsigned int R, unsigned int G, unsigned int B, class T2>
527 struct PromoteTraits<RGBValue<T1, R, G, B>, RGBValue<T2, R, G, B> >
529 typedef RGBValue<typename PromoteTraits<T1, T2>::Promote, R, G, B> Promote;
532 template <class T, unsigned int R, unsigned int G, unsigned int B>
533 struct PromoteTraits<RGBValue<T, R, G, B>, double >
535 typedef RGBValue<typename NumericTraits<T>::RealPromote, R, G, B> Promote;
538 template <class T, unsigned int R, unsigned int G, unsigned int B>
539 struct PromoteTraits<double, RGBValue<T, R, G, B> >
541 typedef RGBValue<typename NumericTraits<T>::RealPromote, R, G, B> Promote;
544 template<class T, unsigned int R, unsigned int G, unsigned int B>
545 struct CanSkipInitialization<RGBValue<T, R, G, B> >
547 typedef typename CanSkipInitialization<T>::type type;
548 static const bool value = type::asBool;
554 #define RGBVALUE_NUMTRAITS(T) \
556 struct NumericTraits<RGBValue<T, 0, 1, 2> >\
558 typedef RGBValue<T> Type; \
559 typedef RGBValue<NumericTraits<T>::Promote> Promote; \
560 typedef RGBValue<NumericTraits<T>::RealPromote> RealPromote; \
561 typedef RGBValue<NumericTraits<T>::ComplexPromote> ComplexPromote; \
562 typedef T ValueType; \
564 typedef NumericTraits<T>::isIntegral isIntegral; \
565 typedef VigraFalseType isScalar; \
566 typedef NumericTraits<T>::isSigned isSigned; \
567 typedef VigraFalseType isOrdered; \
568 typedef VigraFalseType isComplex; \
570 static RGBValue<T> zero() { \
571 return RGBValue<T>(NumericTraits<T>::zero()); \
573 static RGBValue<T> one() { \
574 return RGBValue<T>(NumericTraits<T>::one()); \
576 static RGBValue<T> nonZero() { \
577 return RGBValue<T>(NumericTraits<T>::nonZero()); \
580 static Promote toPromote(RGBValue<T> const & v) { \
583 static RealPromote toRealPromote(RGBValue<T> const & v) { \
584 return RealPromote(v); \
586 static RGBValue<T> fromPromote(Promote const & v) { \
588 RGBValue<T>::iterator d = res.begin();\
589 Promote::const_iterator s = v.begin();\
590 for(; d != res.end(); ++d, ++s)\
591 *d = NumericTraits<T>::fromPromote(*s);\
594 static RGBValue<T> fromRealPromote(RealPromote const & v) {\
596 RGBValue<T>::iterator d = res.begin();\
597 RealPromote::const_iterator s = v.begin();\
598 for(; d != res.end(); ++d, ++s)\
599 *d = NumericTraits<T>::fromRealPromote(*s);\
604 struct NormTraits<RGBValue<T, 0, 1, 2> >\
606 typedef RGBValue<T> Type;\
607 typedef Type::SquaredNormType SquaredNormType; \
608 typedef Type::NormType NormType; \
611 #define RGBVALUE_PROMTRAITS1(type1) \
613 struct PromoteTraits<RGBValue<type1, 0, 1, 2>, RGBValue<type1, 0, 1, 2> > \
615 typedef RGBValue<PromoteTraits<type1, type1>::Promote> Promote; \
616 static Promote toPromote(RGBValue<type1> const & v) { \
617 return static_cast<Promote>(v); } \
620 struct PromoteTraits<RGBValue<type1, 0, 1, 2>, double > \
622 typedef RGBValue<typename NumericTraits<type1>::RealPromote> Promote; \
625 struct PromoteTraits<double, RGBValue<type1, 0, 1, 2> > \
627 typedef RGBValue<typename NumericTraits<type1>::RealPromote> Promote; \
630 #define RGBVALUE_PROMTRAITS2(type1, type2) \
632 struct PromoteTraits<RGBValue<type1, 0, 1, 2>, RGBValue<type2, 0, 1, 2> > \
634 typedef RGBValue<PromoteTraits<type1, type2>::Promote> Promote; \
635 static Promote toPromote(RGBValue<type1> const & v) { \
636 return static_cast<Promote>(v); } \
637 static Promote toPromote(RGBValue<type2> const & v) { \
638 return static_cast<Promote>(v); } \
641 RGBVALUE_NUMTRAITS(unsigned char)
642 RGBVALUE_NUMTRAITS(int)
643 RGBVALUE_NUMTRAITS(float)
644 RGBVALUE_NUMTRAITS(double)
645 RGBVALUE_PROMTRAITS1(unsigned char)
646 RGBVALUE_PROMTRAITS1(int)
647 RGBVALUE_PROMTRAITS1(float)
648 RGBVALUE_PROMTRAITS1(double)
649 RGBVALUE_PROMTRAITS2(float, unsigned char)
650 RGBVALUE_PROMTRAITS2(unsigned char, float)
651 RGBVALUE_PROMTRAITS2(int, unsigned char)
652 RGBVALUE_PROMTRAITS2(unsigned char, int)
653 RGBVALUE_PROMTRAITS2(int, float)
654 RGBVALUE_PROMTRAITS2(float, int)
655 RGBVALUE_PROMTRAITS2(double, unsigned char)
656 RGBVALUE_PROMTRAITS2(unsigned char, double)
657 RGBVALUE_PROMTRAITS2(int, double)
658 RGBVALUE_PROMTRAITS2(double, int)
659 RGBVALUE_PROMTRAITS2(double, float)
660 RGBVALUE_PROMTRAITS2(float, double)
662 #undef RGBVALUE_NUMTRAITS
663 #undef RGBVALUE_PROMTRAITS1
664 #undef RGBVALUE_PROMTRAITS2
679 template <class V1, unsigned int RIDX1, unsigned int GIDX1, unsigned int BIDX1,
680 class V2, unsigned int RIDX2, unsigned int GIDX2, unsigned int BIDX2>
682 RGBValue<V1, RIDX1, GIDX1, BIDX1> &
683 operator+=(RGBValue<V1, RIDX1, GIDX1, BIDX1> & l,
684 RGBValue<V2, RIDX2, GIDX2, BIDX2> const & r)
687 l.green() += r.green();
688 l.blue() += r.blue();
693 template <class V1, unsigned int RIDX1, unsigned int GIDX1, unsigned int BIDX1,
694 class V2, unsigned int RIDX2, unsigned int GIDX2, unsigned int BIDX2>
696 RGBValue<V1, RIDX1, GIDX1, BIDX1> &
697 operator-=(RGBValue<V1, RIDX1, GIDX1, BIDX1> & l,
698 RGBValue<V2, RIDX2, GIDX2, BIDX2> const & r)
701 l.green() -= r.green();
702 l.blue() -= r.blue();
707 template <class V1, unsigned int RIDX1, unsigned int GIDX1, unsigned int BIDX1,
708 class V2, unsigned int RIDX2, unsigned int GIDX2, unsigned int BIDX2>
710 RGBValue<V1, RIDX1, GIDX1, BIDX1> &
711 operator*=(RGBValue<V1, RIDX1, GIDX1, BIDX1> & l,
712 RGBValue<V2, RIDX2, GIDX2, BIDX2> const & r)
714 l.red() = V1(l.red() * r.red());
715 l.green() = V1(l.green() * r.green());
716 l.blue() = V1(l.blue() * r.blue());
721 template <class V, unsigned int RIDX, unsigned int GIDX, unsigned int BIDX>
723 RGBValue<V, RIDX, GIDX, BIDX> &
724 operator*=(RGBValue<V, RIDX, GIDX, BIDX> & l, double r)
726 l.red() = V(l.red() * r);
727 l.green() = V(l.green() * r);
728 l.blue() = V(l.blue() * r);
733 template <class V1, unsigned int RIDX1, unsigned int GIDX1, unsigned int BIDX1,
734 class V2, unsigned int RIDX2, unsigned int GIDX2, unsigned int BIDX2>
736 RGBValue<V1, RIDX1, GIDX1, BIDX1> &
737 operator/=(RGBValue<V1, RIDX1, GIDX1, BIDX1> & l,
738 RGBValue<V2, RIDX2, GIDX2, BIDX2> const & r)
740 l.red() = V1(l.red() / r.red());
741 l.green() = V1(l.green() / r.green());
742 l.blue() = V1(l.blue() / r.blue());
747 template <class V, unsigned int RIDX, unsigned int GIDX, unsigned int BIDX>
749 RGBValue<V, RIDX, GIDX, BIDX> &
750 operator/=(RGBValue<V, RIDX, GIDX, BIDX> & l, double r)
752 l.red() = V(l.red() / r);
753 l.green() = V(l.green() / r);
754 l.blue() = V(l.blue() / r);
758 using VIGRA_CSTD::abs;
761 template <class T, unsigned int RIDX, unsigned int GIDX, unsigned int BIDX>
763 RGBValue<T, RIDX, GIDX, BIDX>
764 abs(RGBValue<T, RIDX, GIDX, BIDX> const & v)
766 return RGBValue<T, RIDX, GIDX, BIDX>(abs(v.red()), abs(v.green()), abs(v.blue()));
770 template <class V1, unsigned int R, unsigned int G, unsigned int B, class V2>
772 typename PromoteTraits<RGBValue<V1, R, G, B>,
773 RGBValue<V2, R, G, B> >::Promote
774 operator+(RGBValue<V1, R, G, B> const & r1,
775 RGBValue<V2, R, G, B> const & r2)
777 typename PromoteTraits<RGBValue<V1, R, G, B>,
778 RGBValue<V2, R, G, B> >::Promote res(r1);
786 template <class V1, unsigned int R, unsigned int G, unsigned int B, class V2>
788 typename PromoteTraits<RGBValue<V1, R, G, B>,
789 RGBValue<V2, R, G, B> >::Promote
790 operator-(RGBValue<V1, R, G, B> const & r1,
791 RGBValue<V2, R, G, B> const & r2)
793 typename PromoteTraits<RGBValue<V1, R, G, B>,
794 RGBValue<V2, R, G, B> >::Promote res(r1);
802 template <class V1, unsigned int R, unsigned int G, unsigned int B, class V2>
804 typename PromoteTraits<RGBValue<V1, R, G, B>,
805 RGBValue<V2, R, G, B> >::Promote
806 operator*(RGBValue<V1, R, G, B> const & r1,
807 RGBValue<V2, R, G, B> const & r2)
809 typename PromoteTraits<RGBValue<V1, R, G, B>,
810 RGBValue<V2, R, G, B> >::Promote res(r1);
818 template <class V, unsigned int R, unsigned int G, unsigned int B>
820 typename NumericTraits<RGBValue<V, R, G, B> >::RealPromote
821 operator*(double v, RGBValue<V, R, G, B> const & r)
823 typename NumericTraits<RGBValue<V, R, G, B> >::RealPromote res(r);
831 template <class V, unsigned int R, unsigned int G, unsigned int B>
833 typename NumericTraits<RGBValue<V, R, G, B> >::RealPromote
834 operator*(RGBValue<V, R, G, B> const & r, double v)
836 typename NumericTraits<RGBValue<V, R, G, B> >::RealPromote res(r);
844 template <class V1, unsigned int R, unsigned int G, unsigned int B, class V2>
846 typename PromoteTraits<RGBValue<V1, R, G, B>,
847 RGBValue<V2, R, G, B> >::Promote
848 operator/(RGBValue<V1, R, G, B> const & r1,
849 RGBValue<V2, R, G, B> const & r2)
851 typename PromoteTraits<RGBValue<V1, R, G, B>,
852 RGBValue<V2, R, G, B> >::Promote res(r1);
860 template <class V, unsigned int R, unsigned int G, unsigned int B>
862 typename NumericTraits<RGBValue<V, R, G, B> >::RealPromote
863 operator/(RGBValue<V, R, G, B> const & r, double v)
865 typename NumericTraits<RGBValue<V, R, G, B> >::RealPromote res(r);
873 template <class V1, unsigned int R, unsigned int G, unsigned int B, class V2>
875 typename PromoteTraits<RGBValue<V1, R, G, B>,
876 RGBValue<V2, R, G, B> >::Promote
877 cross(RGBValue<V1, R, G, B> const & r1,
878 RGBValue<V2, R, G, B> const & r2)
880 typedef typename PromoteTraits<RGBValue<V1, R, G, B>,
881 RGBValue<V2, R, G, B> >::Promote
884 return Res(r1.green()*r2.blue() - r1.blue()*r2.green(),
885 r1.blue()*r2.red() - r1.red()*r2.blue(),
886 r1.red()*r2.green() - r1.green()*r2.red());
890 template <class V1, unsigned int RIDX1, unsigned int GIDX1, unsigned int BIDX1,
891 class V2, unsigned int RIDX2, unsigned int GIDX2, unsigned int BIDX2>
893 typename PromoteTraits<V1, V2>::Promote
894 dot(RGBValue<V1, RIDX1, GIDX1, BIDX1> const & r1,
895 RGBValue<V2, RIDX2, GIDX2, BIDX2> const & r2)
897 return r1.red()*r2.red() + r1.green()*r2.green() + r1.blue()*r2.blue();
900 using VIGRA_CSTD::ceil;
904 template <class V, unsigned int RIDX, unsigned int GIDX, unsigned int BIDX>
906 RGBValue<V, RIDX, GIDX, BIDX>
907 ceil(RGBValue<V, RIDX, GIDX, BIDX> const & r)
909 return RGBValue<V, RIDX, GIDX, BIDX>(ceil(r.red()),
914 using VIGRA_CSTD::floor;
918 template <class V, unsigned int RIDX, unsigned int GIDX, unsigned int BIDX>
920 RGBValue<V, RIDX, GIDX, BIDX>
921 floor(RGBValue<V, RIDX, GIDX, BIDX> const & r)
923 return RGBValue<V, RIDX, GIDX, BIDX>(floor(r.red()),
929 template <class V, unsigned int RIDX, unsigned int GIDX, unsigned int BIDX>
931 RGBValue<V, RIDX, GIDX, BIDX>
932 min(RGBValue<V, RIDX, GIDX, BIDX> const & l,
933 RGBValue<V, RIDX, GIDX, BIDX> const & r)
935 typedef typename detail::LoopType<3>::type ltype;
936 RGBValue<V, RIDX, GIDX, BIDX> res(l);
937 ltype::min(res.begin(), r.begin());
941 template <class V, unsigned int RIDX, unsigned int GIDX, unsigned int BIDX>
943 RGBValue<V, RIDX, GIDX, BIDX>
944 max(RGBValue<V, RIDX, GIDX, BIDX> const & l,
945 RGBValue<V, RIDX, GIDX, BIDX> const & r)
947 typedef typename detail::LoopType<3>::type ltype;
948 RGBValue<V, RIDX, GIDX, BIDX> res(l);
949 ltype::max(res.begin(), r.begin());
972 template <class RGBVALUE>
974 : public VectorAccessor<RGBVALUE>
978 typedef typename RGBVALUE::value_type component_type;
982 template <class RGBIterator>
983 component_type const & red(RGBIterator const & rgb) const
988 template <class V, class RGBIterator>
989 void setRGB(V r, V g, V b, RGBIterator const & rgb) const
991 (*rgb).setRGB( r, g, b );
998 template <class V, class RGBIterator>
999 void setRed(V value, RGBIterator const & rgb) const
1001 (*rgb).setRed(value);
1006 template <class RGBIterator, class DIFFERENCE>
1007 component_type const & red(RGBIterator const & rgb, DIFFERENCE diff) const
1009 return rgb[diff].red();
1015 template <class V, class RGBIterator, class DIFFERENCE>
1016 void setRed(V value, RGBIterator const & rgb, DIFFERENCE diff) const
1018 rgb[diff].setRed(value);
1023 template <class RGBIterator>
1024 component_type const & green(RGBIterator const & rgb) const
1026 return (*rgb).green();
1032 template <class V, class RGBIterator>
1033 void setGreen(V value, RGBIterator const & rgb) const
1035 (*rgb).setGreen(value);
1040 template <class RGBIterator, class DIFFERENCE>
1041 component_type const & green(RGBIterator const & rgb, DIFFERENCE d) const
1043 return rgb[d].green();
1049 template <class V, class RGBIterator, class DIFFERENCE>
1050 void setGreen(V value, RGBIterator const & rgb, DIFFERENCE d) const
1052 rgb[d].setGreen(value);
1057 template <class RGBIterator>
1058 component_type const & blue(RGBIterator const & rgb) const
1060 return (*rgb).blue();
1066 template <class V, class RGBIterator>
1067 void setBlue(V value, RGBIterator const & rgb) const
1069 (*rgb).setBlue(value);
1074 template <class RGBIterator, class DIFFERENCE>
1075 component_type const & blue(RGBIterator const & rgb, DIFFERENCE d) const
1077 return rgb[d].blue();
1083 template <class V, class RGBIterator, class DIFFERENCE>
1084 void setBlue(V value, RGBIterator const & rgb, DIFFERENCE d) const
1086 rgb[d].setBlue(value);
1103 template <class RGBVALUE>
1107 typedef typename RGBVALUE::value_type value_type;
1111 template <class ITERATOR>
1112 value_type const & operator()(ITERATOR const & i) const {
1118 template <class ITERATOR, class DIFFERENCE>
1119 value_type const & operator()(ITERATOR const & i, DIFFERENCE d) const
1127 template <class V, class ITERATOR>
1128 void set(V value, ITERATOR const & i) const {
1136 template <class V, class ITERATOR, class DIFFERENCE>
1137 void set(V value, ITERATOR const & i, DIFFERENCE d) const
1154 template <class RGBVALUE>
1158 typedef typename RGBVALUE::value_type value_type;
1162 template <class ITERATOR>
1163 value_type const & operator()(ITERATOR const & i) const {
1164 return (*i).green();
1169 template <class ITERATOR, class DIFFERENCE>
1170 value_type const & operator()(ITERATOR const & i, DIFFERENCE d) const
1172 return i[d].green();
1178 template <class V, class ITERATOR>
1179 void set(V value, ITERATOR const & i) const {
1180 (*i).setGreen(value);
1187 template <class V, class ITERATOR, class DIFFERENCE>
1188 void set(V value, ITERATOR const & i, DIFFERENCE d) const
1190 i[d].setGreen(value);
1205 template <class RGBVALUE>
1209 typedef typename RGBVALUE::value_type value_type;
1213 template <class ITERATOR>
1214 value_type const & operator()(ITERATOR const & i) const {
1220 template <class ITERATOR, class DIFFERENCE>
1221 value_type const & operator()(ITERATOR const & i, DIFFERENCE d) const
1229 template <class V, class ITERATOR>
1230 void set(V value, ITERATOR const & i) const {
1231 (*i).setBlue(value);
1238 template <class V, class ITERATOR, class DIFFERENCE>
1239 void set(V value, ITERATOR const & i, DIFFERENCE d) const
1241 i[d].setBlue(value);
1256 template <class RGBVALUE>
1257 class RGBToGrayAccessor
1260 typedef typename RGBVALUE::value_type value_type;
1264 template <class ITERATOR>
1265 value_type operator()(ITERATOR const & i) const {
1266 return (*i).luminance(); }
1270 template <class ITERATOR, class DIFFERENCE>
1271 value_type operator()(ITERATOR const & i, DIFFERENCE d) const
1273 return i[d].luminance();
1290 template <class VALUETYPE>
1291 class GrayToRGBAccessor
1294 typedef typename vigra::RGBValue<VALUETYPE> value_type;
1298 template <class ITERATOR>
1299 value_type operator()(ITERATOR const & i) const {
1300 return value_type(*i,*i,*i); }
1304 template <class ITERATOR, class DIFFERENCE>
1305 value_type operator()(ITERATOR const & i, DIFFERENCE d) const
1307 return value_type(i[d],i[d],i[d]);