2786: Add more colors and fix global constants initialization in mln/values.
* mln/literal/colors.hh, * mln/literal/grays.hh: Add various new colors. * mln/literal/black.hh, * mln/literal/colors.hh, * mln/literal/grays.hh, * mln/literal/one.hh, * mln/literal/origin.hh, * mln/literal/white.hh, * mln/literal/zero.hh: Fix the initialization of all the global constants in literal::* according to ticket #43. * mln/value/rgb.hh: Add new constructors. --- milena/ChangeLog | 19 +++++ milena/mln/literal/black.hh | 11 ++- milena/mln/literal/colors.hh | 140 +++++++++++++++++++++++++++++----- milena/mln/literal/grays.hh | 27 ++++++- milena/mln/literal/one.hh | 6 +- milena/mln/literal/origin.hh | 9 ++- milena/mln/literal/white.hh | 8 ++- milena/mln/literal/zero.hh | 7 +- milena/mln/value/rgb.hh | 173 +++++++++++++++++++++++++++++++++++++----- 9 files changed, 344 insertions(+), 56 deletions(-) diff --git a/milena/ChangeLog b/milena/ChangeLog index 91eba76..ffec9ad 100644 --- a/milena/ChangeLog +++ b/milena/ChangeLog @@ -1,3 +1,22 @@ +2008-10-30 Guillaume Lazzara <z@lrde.epita.fr> + + Add more colors and fix global constants initialization in mln/values + + * mln/literal/colors.hh, + * mln/literal/grays.hh: Add various new colors. + + * mln/literal/black.hh, + * mln/literal/colors.hh, + * mln/literal/grays.hh, + * mln/literal/one.hh, + * mln/literal/origin.hh, + * mln/literal/white.hh, + * mln/literal/zero.hh: Fix the initialization of all the global + constants in literal::* according to ticket #43. + + * mln/value/rgb.hh: Add new constructors. + + 2008-11-04 Nicolas Ballas <ballas@lrde.epita.fr> Use memcpy_ in level::paste. diff --git a/milena/mln/literal/black.hh b/milena/mln/literal/black.hh index 7307420..59e1973 100644 --- a/milena/mln/literal/black.hh +++ b/milena/mln/literal/black.hh @@ -1,4 +1,4 @@ -// Copyright (C) 2007 EPITA Research and Development Laboratory +// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory // // This file is part of the Olena Library. This library is free // software; you can redistribute it and/or modify it under the terms @@ -48,8 +48,13 @@ namespace mln /// Literal black. - // FIXME: Make this a proper global (issue #43). - static const black_t black = black_t(); + extern const black_t& black; + +# ifndef MLN_INCLUDE_ONLY + + const black_t& black = black_t(); + +# endif } // end of namespace mln::literal diff --git a/milena/mln/literal/colors.hh b/milena/mln/literal/colors.hh index 069ae59..8e1c135 100644 --- a/milena/mln/literal/colors.hh +++ b/milena/mln/literal/colors.hh @@ -1,4 +1,4 @@ -// Copyright (C) 2007 EPITA Research and Development Laboratory +// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory // // This file is part of the Olena Library. This library is free // software; you can redistribute it and/or modify it under the terms @@ -41,51 +41,149 @@ namespace mln namespace literal { + /// Type of literal red. + struct red_t : public Literal<red_t> + { + }; + + /// Type of literal green. + struct green_t : public Literal<green_t> + { + }; + /// Type of literal blue. struct blue_t : public Literal<blue_t> { }; - /// Type of literal red. - struct red_t : public Literal<red_t> + /// Type of literal brown. + struct brown_t : public Literal<brown_t> { }; - /// Type of literal dark red. - struct dark_red_t : public Literal<dark_red_t> + /// Type of literal lime. + struct lime_t : public Literal<lime_t> { }; - /// Type of literal dark orange. - struct dark_orange_t : public Literal<dark_orange_t> + /// Type of literal orange. + struct orange_t : public Literal<orange_t> { }; - /// Type of literal green. - struct green_t : public Literal<green_t> + /// Type of literal pink. + struct pink_t : public Literal<pink_t> + { + }; + + /// Type of literal purple. + struct purple_t : public Literal<purple_t> + { + }; + + /// Type of literal teal. + struct teal_t : public Literal<teal_t> { }; + /// Type of literal violet. + struct violet_t : public Literal<violet_t> + { + }; - /// Literal red. - // FIXME: Make this a proper global (issue #43). - static const red_t red = red_t(); + /// Type of literal cyan. + struct cyan_t : public Literal<cyan_t> + { + }; + + /// Type of literal magenta. + struct magenta_t : public Literal<magenta_t> + { + }; + + /// Type of literal yellow. + struct yellow_t : public Literal<yellow_t> + { + }; - /// Literal dark red. - // FIXME: Make this a proper global (issue #43). - static const dark_red_t dark_red = dark_red_t(); + /// Type of literal olive. + struct olive_t : public Literal<olive_t> + { + }; /// Literal red. - // FIXME: Make this a proper global (issue #43). - static const dark_orange_t dark_orange = dark_orange_t(); + extern const red_t& red; /// Literal green. - // FIXME: Make this a proper global (issue #43). - static const green_t green = green_t(); + extern const green_t& green; /// Literal blue. - // FIXME: Make this a proper global (issue #43). - static const blue_t blue = blue_t(); + extern const blue_t& blue; + + /// Literal brown. + extern const brown_t& brown; + + /// Literal lime. + extern const lime_t& lime; + + /// Literal orange. + extern const orange_t& orange; + + /// Literal pink. + extern const pink_t& pink; + + /// Literal purple. + extern const purple_t& purple; + + /// Literal teal. + extern const teal_t& teal; + + /// Literal violet. + extern const violet_t& violet; + + /// Literal cyan. + extern const cyan_t& cyan; + + /// Literal magenta. + extern const magenta_t& magenta; + + /// Literal yellow. + extern const yellow_t& yellow; + + /// Literal olive. + extern const olive_t& olive; + +# ifndef MLN_INCLUDE_ONLY + + const red_t& red = red_t(); + + const green_t& green = green_t(); + + const blue_t& blue = blue_t(); + + const brown_t& brown = brown_t(); + + const lime_t& lime = lime_t(); + + const orange_t& orange = orange_t(); + + const pink_t& pink = pink_t(); + + const purple_t& purple = purple_t(); + + const teal_t& teal = teal_t(); + + const violet_t& violet = violet_t(); + + const cyan_t& cyan = cyan_t(); + + const magenta_t& magenta = magenta_t(); + + const yellow_t& yellow = yellow_t(); + + const olive_t& olive = olive_t(); + +# endif } // end of namespace mln::literal diff --git a/milena/mln/literal/grays.hh b/milena/mln/literal/grays.hh index b9a6ad6..ba10145 100644 --- a/milena/mln/literal/grays.hh +++ b/milena/mln/literal/grays.hh @@ -42,13 +42,36 @@ namespace mln { /// Type of literal grays. + struct light_gray_t : public Literal<light_gray_t> + { + }; + struct medium_gray_t : public Literal<medium_gray_t> { }; + struct dark_gray_t : public Literal<dark_gray_t> + { + }; + + /// Literal light gray. + extern const light_gray_t& light_gray; + /// Literal medium_gray. - // FIXME: Make this a proper global (issue #43). - static const medium_gray_t medium_gray = medium_gray_t(); + extern const medium_gray_t& medium_gray; + + /// Literal dark gray. + extern const dark_gray_t& dark_gray; + +# ifndef MLN_INCLUDE_ONLY + + const light_gray_t& light_gray = light_gray_t(); + + const medium_gray_t& medium_gray = medium_gray_t(); + + const dark_gray_t& dark_gray = dark_gray_t(); + +# endif // !MLN_INCLUDE_ONLY } // end of namespace mln::literal diff --git a/milena/mln/literal/one.hh b/milena/mln/literal/one.hh index 699819f..8176ce2 100644 --- a/milena/mln/literal/one.hh +++ b/milena/mln/literal/one.hh @@ -54,8 +54,7 @@ namespace mln /// Literal one. - // FIXME: Make this a proper global (issue #43). - static const one_t one = one_t(); + extern const one_t& one; # ifndef MLN_INCLUDE_ONLY @@ -68,6 +67,9 @@ namespace mln return 1; } + + const one_t& one = one_t(); + # endif // ! MLN_INCLUDE_ONLY } // end of namespace mln::literal diff --git a/milena/mln/literal/origin.hh b/milena/mln/literal/origin.hh index 5f64726..f4dd1be 100644 --- a/milena/mln/literal/origin.hh +++ b/milena/mln/literal/origin.hh @@ -48,8 +48,13 @@ namespace mln }; /// Literal origin. - // FIXME: Make this a proper global (issue #43). - static const origin_t origin = origin_t(); + extern const origin_t& origin; + +# ifndef MLN_INCLUDE_ONLY + + const origin_t& origin = origin_t(); + +# endif } // end of namespace mln::literal diff --git a/milena/mln/literal/white.hh b/milena/mln/literal/white.hh index c8c5bf8..f0e5a52 100644 --- a/milena/mln/literal/white.hh +++ b/milena/mln/literal/white.hh @@ -48,9 +48,13 @@ namespace mln /// Literal white. - // FIXME: Make this a proper global (issue #43). - static const white_t white = white_t(); + extern const white_t& white; +# ifndef MLN_INCLUDE_ONLY + + const white_t& white = white_t(); + +# endif } // end of namespace mln::literal diff --git a/milena/mln/literal/zero.hh b/milena/mln/literal/zero.hh index f35f8a3..8762ec1 100644 --- a/milena/mln/literal/zero.hh +++ b/milena/mln/literal/zero.hh @@ -54,11 +54,8 @@ namespace mln operator T () const; }; - /// Literal zero. - // FIXME: Make this a proper global (issue #43). - static const zero_t zero = zero_t(); - + extern const zero_t& zero; # ifndef MLN_INCLUDE_ONLY @@ -70,6 +67,8 @@ namespace mln return 0; } + const zero_t& zero = zero_t(); + # endif // ! MLN_INCLUDE_ONLY } // end of namespace mln::literal diff --git a/milena/mln/value/rgb.hh b/milena/mln/value/rgb.hh index 1e3d7ca..fabcf8d 100644 --- a/milena/mln/value/rgb.hh +++ b/milena/mln/value/rgb.hh @@ -55,11 +55,24 @@ namespace mln struct black_t; struct white_t; + struct light_gray_t; + struct medium_gray_t; + struct dark_gray_t; + struct red_t; - struct dark_red_t; - struct dark_orange_t; - struct blue_t; struct green_t; + struct blue_t; + struct brown_t; + struct lime_t; + struct orange_t; + struct pink_t; + struct purple_t; + struct teal_t; + struct violet_t; + struct cyan_t; + struct magenta_t; + struct yellow_t; + struct olive_t; /// \} } @@ -154,9 +167,8 @@ namespace mln namespace value { - /*! \brief Color class for red-green-blue where every component is - * n-bit encoded. - */ + /// \brief Color class for red-green-blue where every component is + /// n-bit encoded. template <unsigned n> struct rgb : @@ -165,7 +177,7 @@ namespace mln public internal::value_like_< algebra::vec< 3, int_u<n> >, // Equivalent. algebra::vec< 3, int_u<n> >, // Encoding. algebra::vec< 3, int >, // Interoperation. - rgb<n> > // Exact. + rgb<n> > // Exact. { public: @@ -204,11 +216,24 @@ namespace mln rgb<n>(const mln::literal::white_t&); rgb<n>(const mln::literal::black_t&); - rgb<n>(const mln::literal::blue_t&); + rgb<n>(const mln::literal::light_gray_t&); + rgb<n>(const mln::literal::medium_gray_t&); + rgb<n>(const mln::literal::dark_gray_t&); + rgb<n>(const mln::literal::red_t&); - rgb<n>(const mln::literal::dark_red_t&); - rgb<n>(const mln::literal::dark_orange_t&); + rgb<n>(const mln::literal::blue_t&); rgb<n>(const mln::literal::green_t&); + rgb<n>(const mln::literal::brown_t&); + rgb<n>(const mln::literal::lime_t&); + rgb<n>(const mln::literal::orange_t&); + rgb<n>(const mln::literal::pink_t&); + rgb<n>(const mln::literal::purple_t&); + rgb<n>(const mln::literal::teal_t&); + rgb<n>(const mln::literal::violet_t&); + rgb<n>(const mln::literal::cyan_t&); + rgb<n>(const mln::literal::magenta_t&); + rgb<n>(const mln::literal::yellow_t&); + rgb<n>(const mln::literal::olive_t&); /// \} /// Assignment. @@ -292,7 +317,7 @@ namespace mln operator/(const rgb<n>& lhs, const mln::value::scalar_<S>& s); /// \} - + # ifndef MLN_INCLUDE_ONLY /*---------------. @@ -361,6 +386,33 @@ namespace mln template <unsigned n> inline + rgb<n>::rgb(const mln::literal::light_gray_t&) + { + this->v_[0] = mln_max(int_u<n>) * 0.75; + this->v_[1] = mln_max(int_u<n>) * 0.75; + this->v_[2] = mln_max(int_u<n>) * 0.75; + } + + template <unsigned n> + inline + rgb<n>::rgb(const mln::literal::medium_gray_t&) + { + this->v_[0] = mln_max(int_u<n>) * 0.50; + this->v_[1] = mln_max(int_u<n>) * 0.50; + this->v_[2] = mln_max(int_u<n>) * 0.50; + } + + template <unsigned n> + inline + rgb<n>::rgb(const mln::literal::dark_gray_t&) + { + this->v_[0] = mln_max(int_u<n>) * 0.25; + this->v_[1] = mln_max(int_u<n>) * 0.25; + this->v_[2] = mln_max(int_u<n>) * 0.25; + } + + template <unsigned n> + inline rgb<n>::rgb(const mln::literal::red_t&) { this->v_[0] = mln_max(int_u<n>); @@ -370,42 +422,123 @@ namespace mln template <unsigned n> inline - rgb<n>::rgb(const mln::literal::dark_red_t&) + rgb<n>::rgb(const mln::literal::green_t&) + { + this->v_[0] = 0; + this->v_[1] = mln_max(int_u<n>); + this->v_[2] = 0; + } + + template <unsigned n> + inline + rgb<n>::rgb(const mln::literal::blue_t&) { - this->v_[0] = mln_max(int_u<n>) / 3; + this->v_[0] = 0; this->v_[1] = 0; + this->v_[2] = mln_max(int_u<n>); + } + + template <unsigned n> + inline + rgb<n>::rgb(const mln::literal::brown_t&) + { + this->v_[0] = mln_max(int_u<n>) * 0.75; + this->v_[1] = mln_max(int_u<n>) * 0.50; + this->v_[2] = mln_max(int_u<n>) * 0.25; + } + + template <unsigned n> + inline + rgb<n>::rgb(const mln::literal::lime_t&) + { + this->v_[0] = mln_max(int_u<n>) * 0.75; + this->v_[1] = mln_max(int_u<n>); this->v_[2] = 0; } template <unsigned n> inline - rgb<n>::rgb(const mln::literal::dark_orange_t&) + rgb<n>::rgb(const mln::literal::orange_t&) { - this->v_[0] = mln_max(int_u<n>) / 3; - this->v_[1] = mln_max(int_u<n>) / 3; + this->v_[0] = mln_max(int_u<n>); + this->v_[1] = mln_max(int_u<n>) * 0.50; this->v_[2] = 0; } template <unsigned n> inline - rgb<n>::rgb(const mln::literal::green_t&) + rgb<n>::rgb(const mln::literal::pink_t&) + { + this->v_[0] = mln_max(int_u<n>); + this->v_[1] = mln_max(int_u<n>) * 0.75; + this->v_[2] = mln_max(int_u<n>) * 0.75; + } + + template <unsigned n> + inline + rgb<n>::rgb(const mln::literal::purple_t&) + { + this->v_[0] = mln_max(int_u<n>) * 0.75; + this->v_[1] = 0; + this->v_[2] = mln_max(int_u<n>) * 0.25; + } + + template <unsigned n> + inline + rgb<n>::rgb(const mln::literal::teal_t&) { this->v_[0] = 0; - this->v_[1] = mln_max(int_u<n>); - this->v_[2] = 0; + this->v_[1] = mln_max(int_u<n>) * 0.50; + this->v_[2] = mln_max(int_u<n>) * 0.50; } template <unsigned n> inline - rgb<n>::rgb(const mln::literal::blue_t&) + rgb<n>::rgb(const mln::literal::violet_t&) + { + this->v_[0] = mln_max(int_u<n>) * 0.50; + this->v_[1] = 0; + this->v_[2] = mln_max(int_u<n>) * 0.50; + } + + template <unsigned n> + inline + rgb<n>::rgb(const mln::literal::cyan_t&) { this->v_[0] = 0; + this->v_[1] = mln_max(int_u<n>); + this->v_[2] = mln_max(int_u<n>); + } + + template <unsigned n> + inline + rgb<n>::rgb(const mln::literal::magenta_t&) + { + this->v_[0] = mln_max(int_u<n>); this->v_[1] = 0; this->v_[2] = mln_max(int_u<n>); } template <unsigned n> inline + rgb<n>::rgb(const mln::literal::yellow_t&) + { + this->v_[0] = mln_max(int_u<n>); + this->v_[1] = mln_max(int_u<n>); + this->v_[2] = 0; + } + + template <unsigned n> + inline + rgb<n>::rgb(const mln::literal::olive_t&) + { + this->v_[0] = mln_max(int_u<n>) * 0.50; + this->v_[1] = mln_max(int_u<n>) * 0.50; + this->v_[2] = 0; + } + + template <unsigned n> + inline rgb<n>& rgb<n>::operator=(const rgb<n>& rhs) { -- 1.5.6.5
participants (1)
-
Guillaume Lazzara