URL:
https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-09-10 Matthieu Garrigues <garrigues(a)lrde.epita.fr>
add rgb value type and separate prinln and println_with_border
* mln/debug/println.hh: Splitted
* mln/debug/println_with_border.hh: New.
* mln/value/rgb.hh: templated value rgb<n>
* mln/value/rgb8.hh: just a typedef
* mln/value/rgb8_non_templated.hh: the old version without template
(to delete)
* tests/debug_println_with_border.cc: (uplate includes)
* tests/value_rgb8.cc: tests rgb operation
---
mln/debug/println.hh | 30 ----
mln/debug/println_with_border.hh | 102 ++++++++++++++++
mln/value/rgb.hh | 224 +++++++++++++++++++++++++++++++++++++
mln/value/rgb8.hh | 63 ----------
mln/value/rgb8_non_templated.hh | 191 +++++++++++++++++++++++++++++++
tests/debug_println_with_border.cc | 1
tests/value_rgb8.cc | 25 +++-
7 files changed, 543 insertions(+), 93 deletions(-)
Index: trunk/milena/tests/debug_println_with_border.cc
===================================================================
--- trunk/milena/tests/debug_println_with_border.cc (revision 1097)
+++ trunk/milena/tests/debug_println_with_border.cc (revision 1098)
@@ -34,6 +34,7 @@
#include <mln/core/image1d_b.hh>
#include <mln/level/fill.hh>
#include <mln/debug/println.hh>
+#include <mln/debug/println_with_border.hh>
using namespace mln;
Index: trunk/milena/tests/value_rgb8.cc
===================================================================
--- trunk/milena/tests/value_rgb8.cc (revision 1097)
+++ trunk/milena/tests/value_rgb8.cc (revision 1098)
@@ -38,9 +38,30 @@
{
using namespace mln;
using value::rgb8;
+ using value::rgb;
{
- rgb8 c;
- // todo matthieu
+ rgb8 v;
+ v.red() = 0;
+ v.green() = 1;
+ v.blue() = 2;
+ value::int_u8_x3_t t = {0,1,2};
+ rgb8 w( t );
+
+ std::cout << w << std::endl;
+ std::cout << v << std::endl;
+
+ mln_assertion(w == w);
+ mln_assertion(w == v);
+ v.green () = 255;
+ std::cout << v << std::endl;
+ mln_assertion(v != w);
+
+ rgb<20> b = rgb<20>::max_blue;
+ std::cout << b << std::endl;
+
+ rgb<20> c = rgb<20>::white;
+ std::cout << c << std::endl;
+
}
}
Index: trunk/milena/mln/debug/println.hh
===================================================================
--- trunk/milena/mln/debug/println.hh (revision 1097)
+++ trunk/milena/mln/debug/println.hh (revision 1098)
@@ -67,15 +67,6 @@
std::cout << std::endl;
}
- template <typename S, typename I>
- void println_with_border(const S&, const Fast_Image<I>& input_)
- {
- const I& input = exact(input_);
- for (int i = 0; i < input.ncells(); i++)
- std::cout << format( input.buffer()[i] ) << ' ';
- std::cout << std::endl;
- }
-
// 2D version
template <typename I>
void println(const box2d& b, const I& input)
@@ -97,38 +88,17 @@
std::cout << std::endl;
}
- template <typename I>
- void println_with_border(const box2d& b, const Fast_Image<I>&
input_)
- {
- const I& input = exact(input_);
- const std::size_t ncols = b.ncols() + 2 * input.border();
- for (size_t i = 0; i < input.ncells(); i++)
- {
- std::cout << format( input.buffer()[i] ) << ' ';
- if (((i+1) % ncols) == 0)
- std::cout << std::endl;
- }
- std::cout << std::endl;
- }
-
} // end of namespace mln::debug::impl
// facade
-
template <typename I>
void println(const Image<I>& input)
{
impl::println(exact(input).bbox(), exact(input));
}
- template <typename I>
- void println_with_border(const Fast_Image<I>& input)
- {
- impl::println_with_border(exact(input).bbox(), exact(input));
- }
-
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln::debug
Index: trunk/milena/mln/debug/println_with_border.hh
===================================================================
--- trunk/milena/mln/debug/println_with_border.hh (revision 0)
+++ trunk/milena/mln/debug/println_with_border.hh (revision 1098)
@@ -0,0 +1,102 @@
+// Copyright (C) 2007 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
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef MLN_DEBUG_PRINTLN_WITH_BORDER_HH
+# define MLN_DEBUG_PRINTLN_WITH_BORDER_HH
+
+/*! \file mln/debug/println_with_border.hh
+ *
+ * \brief Print an image on the standard output.
+ */
+
+# include <mln/core/concept/image.hh>
+# include <mln/core/concept/window.hh>
+# include <mln/debug/format.hh>
+
+# include <mln/core/box2d.hh>
+
+
+namespace mln
+{
+
+ namespace debug
+ {
+
+ /// Print the image \p input on the standard output.
+ template <typename I>
+ void println_with_border(const Fast_Image<I>& input);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ // generic version
+ template <typename S, typename I>
+ void println_with_border(const S&, const Fast_Image<I>& input_)
+ {
+ const I& input = exact(input_);
+ for (size_t i = 0; i < input.ncells(); i++)
+ std::cout << format( input.buffer()[i] ) << ' ';
+ std::cout << std::endl;
+ }
+
+ // 2D version
+ template <typename I>
+ void println_with_border(const box2d& b, const Fast_Image<I>&
input_)
+ {
+ const I& input = exact(input_);
+ const std::size_t ncols = b.ncols() + 2 * input.border();
+ for (size_t i = 0; i < input.ncells(); i++)
+ {
+ std::cout << format( input.buffer()[i] ) << ' ';
+ if (((i+1) % ncols) == 0)
+ std::cout << std::endl;
+ }
+ std::cout << std::endl;
+ }
+
+ } // end of namespace mln::debug::impl
+
+
+
+ // facade
+ template <typename I>
+ void println_with_border(const Fast_Image<I>& input)
+ {
+ impl::println_with_border(exact(input).bbox(), exact(input));
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::debug
+
+} // end of namespace mln
+
+
+#endif // ! MLN_DEBUG_PRINTLN_WITH_BORDER_HH
Index: trunk/milena/mln/value/rgb8.hh
===================================================================
--- trunk/milena/mln/value/rgb8.hh (revision 1097)
+++ trunk/milena/mln/value/rgb8.hh (revision 1098)
@@ -34,8 +34,7 @@
* 8-bit encoded.
*/
-# include <mln/core/concept/value.hh>
-# include <mln/value/int_u8.hh>
+# include <mln/value/rgb.hh>
namespace mln
@@ -44,68 +43,10 @@
namespace value
{
-
- typedef int_u8 int_u8_x3_t[3];
- typedef unsigned char uchar_x3_t[3];
- typedef float float_x3_t[3];
-
-
/*! \brief Color class for red-green-blue where every component is
* 8-bit encoded.
*/
- class rgb8 : public Value< rgb8 >
- {
- public:
-
- /// Encoding associated type.
- typedef int_u8_x3_t enc;
-
- /// Equivalent associated type.
- typedef int_u8_x3_t equiv;
-
- int_u8 red() const { return c_[0]; }
- int_u8& red() { return c_[0]; }
-
- int_u8 green() const { return c_[1]; }
- int_u8& green() { return c_[1]; }
-
- int_u8 blue() const { return c_[2]; }
- int_u8& blue() { return c_[2]; }
-
- // todo matthieu
-
- private:
- int_u8_x3_t c_;
- };
-
-
- struct props< rgb8 >
- {
- static const unsigned nbits = 24;
- static const std::size_t card_ = metal::pow<2, nbits>::value;
- typedef color_kind kind;
- typedef float_x3_t sum;
- typedef uchar_x3_t interop;
- };
-
-
-
- /*! \brief Print an rgb8 \p c into the output stream \p ostr.
- *
- * \param[in,out] ostr An output stream.
- * \param[in] c An rgb8.
- *
- * \return The modified output stream \p ostr.
- */
- std::ostream& operator<<(std::ostream& ostr, const rgb8& c);
-
-
-# ifndef MLN_INCLUDE_ONLY
-
- // todo matthieu
-
-# endif // ! MLN_INCLUDE_ONLY
-
+ typedef rgb<8> rgb8;
} // end of namespace mln::value
} // end of namespace mln
Index: trunk/milena/mln/value/rgb.hh
===================================================================
--- trunk/milena/mln/value/rgb.hh (revision 0)
+++ trunk/milena/mln/value/rgb.hh (revision 1098)
@@ -0,0 +1,224 @@
+// Copyright (C) 2007 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
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef MLN_VALUE_RGB_HH
+# define MLN_VALUE_RGB_HH
+
+/*! \file mln/value/rgb8.hh
+ *
+ * \brief Color class for red-green-blue where every component is
+ * 8-bit encoded.
+ */
+
+# include <mln/core/concept/value.hh>
+# include <mln/value/int_u8.hh>
+
+
+namespace mln
+{
+
+ namespace value
+ {
+
+
+ typedef int_u8 int_u8_x3_t[3];
+ typedef unsigned char uchar_x3_t[3];
+ typedef float float_x3_t[3];
+
+
+ /*! \brief Color class for red-green-blue where every component is
+ * 8-bit encoded.
+ */
+ template <unsigned n>
+ struct rgb : public Value< rgb<n> >
+ {
+ public:
+
+ /// Encoding associated type.
+ typedef int_u<n> enc;
+
+ /// Equivalent associated type.
+ typedef int_u<n> equiv[3];
+
+ int_u<n> red() const { return c_[0]; }
+ int_u<n>& red() { return c_[0]; }
+
+ int_u<n> green() const { return c_[1]; }
+ int_u<n>& green() { return c_[1]; }
+
+ int_u<n> blue() const { return c_[2]; }
+ int_u<n>& blue() { return c_[2]; }
+
+ rgb<n>();
+ rgb<n>(equiv a);
+ rgb<n>(enc r, enc g, enc b);
+
+ rgb<n>& operator=(rgb<n>& v);
+
+ /// Zero value.
+ static const rgb<n> zero;
+
+ /// Colors.
+ static const rgb<n> black;
+ static const rgb<n> max_red;
+ static const rgb<n> max_green;
+ static const rgb<n> max_blue;
+ static const rgb<n> white;
+
+ /// Self addition
+ rgb<n>& operator+=(rgb<n>& v);
+
+ /// Self subtraction.
+ rgb<n>& operator-=(rgb<n>& v);
+
+ /// Comparaison.
+ bool operator==(rgb<n>& v);
+ bool operator!=(rgb<n>& v);
+
+
+ private:
+ equiv c_;
+ };
+
+ template <unsigned n>
+ struct props< rgb<n> >
+ {
+ static const unsigned nbits = 24;
+ static const std::size_t card_ = metal::pow<2, nbits>::value;
+ typedef color_kind kind;
+ typedef float_x3_t sum;
+ typedef uchar_x3_t interop;
+ };
+
+
+
+ /*! \brief Print an rgb \p c into the output stream \p ostr.
+ *
+ * \param[in,out] ostr An output stream.
+ * \param[in] c An rgb.
+ *
+ * \return The modified output stream \p ostr.
+ */
+ template <unsigned n>
+ std::ostream& operator<<(std::ostream& ostr, const rgb<n>&
c);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <unsigned n>
+ rgb<n>::rgb()
+ {
+ }
+
+ template <unsigned n>
+ rgb<n>::rgb(equiv a)
+ {
+ std::memcpy(this->c_, a, 3);
+ }
+
+ template <unsigned n>
+ rgb<n>::rgb(enc r, enc g, enc b)
+ {
+ this->c_[0] = r;
+ this->c_[1] = g;
+ this->c_[2] = b;
+ }
+
+ template <unsigned n>
+ rgb<n>&
+ rgb<n>::operator=(rgb<n>& v)
+ {
+ std::memcpy(this->c_, v.c_, 3);
+ return *this;
+ }
+
+ template <unsigned n>
+ const rgb<n> rgb<n>::zero(0,0,0);
+
+ template <unsigned n>
+ const rgb<n> rgb<n>::black(0,0,0);
+
+ template <unsigned n>
+ const rgb<n> rgb<n>::max_red(mln_max(enc), 0, 0);
+
+ template <unsigned n>
+ const rgb<n> rgb<n>::max_green(0, mln_max(enc), 0);
+
+ template <unsigned n>
+ const rgb<n> rgb<n>::max_blue(0, 0, mln_max(enc));
+
+ template <unsigned n>
+ const rgb<n> rgb<n>::white(mln_max(enc), mln_max(enc), mln_max(enc));
+
+ template <unsigned n>
+ rgb<n>&
+ rgb<n>::operator+=(rgb<n>& v)
+ {
+ for (int i = 0; i < 3; i++)
+ this->c_[i] += v.c_[i];
+ }
+
+ template <unsigned n>
+ rgb<n>&
+ rgb<n>::operator-=(rgb<n>& v)
+ {
+ for (int i = 0; i < 3; i++)
+ this->c_[i] += v.c_[i];
+ }
+
+ template <unsigned n>
+ std::ostream& operator<<(std::ostream& ostr, const rgb<n>&
v)
+ {
+ return ostr << "(R:" << debug::format(v.red())
+ << ", G:" << debug::format(v.green())
+ << ", B:" << debug::format(v.blue())
+ << ")";
+ }
+
+ template <unsigned n>
+ bool
+ rgb<n>::operator==(rgb<n>& v)
+ {
+ return (this->green() == v.green() &&
+ this->red() == v.red() &&
+ this->blue() == v.blue());
+ }
+
+ template <unsigned n>
+ bool
+ rgb<n>::operator!=(rgb<n>& v)
+ {
+ return (!(*this == v));
+ }
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::value
+
+} // end of namespace mln
+
+
+#endif // ! MLN_VALUE_RGB_HH
Index: trunk/milena/mln/value/rgb8_non_templated.hh
===================================================================
--- trunk/milena/mln/value/rgb8_non_templated.hh (revision 0)
+++ trunk/milena/mln/value/rgb8_non_templated.hh (revision 1098)
@@ -0,0 +1,191 @@
+// Copyright (C) 2007 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
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef MLN_VALUE_RGB8_HH
+# define MLN_VALUE_RGB8_HH
+
+/*! \file mln/value/rgb8.hh
+ *
+ * \brief Color class for red-green-blue where every component is
+ * 8-bit encoded.
+ */
+
+# include <mln/core/concept/value.hh>
+# include <mln/value/int_u8.hh>
+
+
+namespace mln
+{
+
+ namespace value
+ {
+
+
+ typedef int_u8 int_u8_x3_t[3];
+ typedef unsigned char uchar_x3_t[3];
+ typedef float float_x3_t[3];
+
+
+ /*! \brief Color class for red-green-blue where every component is
+ * 8-bit encoded.
+ */
+ class rgb8 : public Value< rgb8 >
+ {
+ public:
+
+ /// Encoding associated type.
+ typedef int_u8 enc;
+
+ /// Equivalent associated type.
+ typedef int_u8_x3_t equiv;
+
+ int_u8 red() const { return c_[0]; }
+ int_u8& red() { return c_[0]; }
+
+ int_u8 green() const { return c_[1]; }
+ int_u8& green() { return c_[1]; }
+
+ int_u8 blue() const { return c_[2]; }
+ int_u8& blue() { return c_[2]; }
+
+ // todo matthieu
+ rgb8();
+ rgb8(int_u8_x3_t a);
+
+ rgb8& operator=(rgb8& v);
+
+ /// Zero value.
+ static const rgb8 zero;
+
+ /// Unit values.
+ static const rgb8 max_red;
+ static const rgb8 max_green;
+ static const rgb8 max_blue;
+
+ /// Self addition
+ rgb8& operator+=(rgb8& v);
+
+ /// Self subtraction.
+ rgb8& operator-=(rgb8& v);
+
+ /// Comparaison.
+ bool operator==(rgb8& v);
+ bool operator!=(rgb8& v);
+
+
+ private:
+ int_u8_x3_t c_;
+ };
+
+ template <>
+ struct props< rgb8 >
+ {
+ static const unsigned nbits = 24;
+ static const std::size_t card_ = metal::pow<2, nbits>::value;
+ typedef color_kind kind;
+ typedef float_x3_t sum;
+ typedef uchar_x3_t interop;
+ };
+
+
+
+ /*! \brief Print an rgb8 \p c into the output stream \p ostr.
+ *
+ * \param[in,out] ostr An output stream.
+ * \param[in] c An rgb8.
+ *
+ * \return The modified output stream \p ostr.
+ */
+ std::ostream& operator<<(std::ostream& ostr, const rgb8& c);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ // todo matthieu
+ rgb8::rgb8()
+ {
+ }
+
+ rgb8::rgb8(int_u8_x3_t a)
+ {
+ std::memcpy(this->c_, a, 3);
+ }
+
+ rgb8&
+ rgb8::operator=(rgb8& v)
+ {
+ std::memcpy(this->c_, v.c_, 3);
+ return *this;
+ }
+
+// const rgb8 rgb8::zero = rgb8({0,0,0});
+// const rgb8 rgb8::max_red = {mln_max(enc), 0, 0};
+// const rgb8 rgb8::max_green = {0, mln_max(enc), 0};
+// const rgb8 rgb8::max_blue = {0, 0, mln_max(enc)};
+
+ rgb8&
+ rgb8::operator+=(rgb8& v)
+ {
+ for (int i = 0; i < 3; i++)
+ this->c_[i] += v.c_[i];
+ }
+ rgb8&
+ rgb8::operator-=(rgb8& v)
+ {
+ for (int i = 0; i < 3; i++)
+ this->c_[i] += v.c_[i];
+ }
+
+ std::ostream& operator<<(std::ostream& ostr, const rgb8& v)
+ {
+ return ostr << "(R:" << debug::format(v.red())
+ << ", G:" << debug::format(v.green())
+ << ", B:" << debug::format(v.blue())
+ << ")";
+ }
+
+ bool
+ rgb8::operator==(rgb8& v)
+ {
+ return (this->green() == v.green() &&
+ this->red() == v.red() &&
+ this->blue() == v.blue());
+ }
+
+ bool
+ rgb8::operator!=(rgb8& v)
+ {
+ return (!(*this == v));
+ }
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::value
+
+} // end of namespace mln
+
+
+#endif // ! MLN_VALUE_RGB8_HH