URL:
https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-10-12 Matthieu Garrigues <garrigues(a)lrde.epita.fr>
Add some literals.
* mln/literal/all.hh: Add missing includes.
* mln/literal/colors.hh: New, red, green and blue literals.
* mln/literal/grays.hh: New, medium_gray.
* tests/literal_medium_gray.cc: New, a little test.
* tests/value_rgb8.cc: Update to use literals.
* mln/value/graylevel.hh,
* mln/value/rgb.hh: Constructors and assigments to handle literals.
---
mln/literal/all.hh | 9 ++--
mln/literal/colors.hh | 77 ++++++++++++++++++++++++++++++++++++++++
mln/literal/grays.hh | 60 +++++++++++++++++++++++++++++++
mln/value/graylevel.hh | 26 ++++++++++++-
mln/value/rgb.hh | 81 ++++++++++++++++++++++++++++++-------------
tests/literal_medium_gray.cc | 57 ++++++++++++++++++++++++++++++
tests/value_rgb8.cc | 9 +++-
7 files changed, 285 insertions(+), 34 deletions(-)
Index: trunk/milena/tests/value_rgb8.cc
===================================================================
--- trunk/milena/tests/value_rgb8.cc (revision 1333)
+++ trunk/milena/tests/value_rgb8.cc (revision 1334)
@@ -32,7 +32,7 @@
#include <mln/value/rgb8.hh>
-
+#include <mln/literal/all.hh>
int main()
{
@@ -40,6 +40,9 @@
using value::rgb8;
using value::rgb;
+ using literal::blue;
+ using literal::white;
+
{
rgb8 v;
v.red() = 0;
@@ -57,10 +60,10 @@
std::cout << v << std::endl;
mln_assertion(v != w);
- rgb<20> b = rgb<20>::max_blue;
+ rgb<20> b = blue;
std::cout << b << std::endl;
- rgb<20> c = rgb<20>::white;
+ rgb<20> c = white;
std::cout << c << std::endl;
}
Index: trunk/milena/tests/literal_medium_gray.cc
===================================================================
--- trunk/milena/tests/literal_medium_gray.cc (revision 0)
+++ trunk/milena/tests/literal_medium_gray.cc (revision 1334)
@@ -0,0 +1,57 @@
+// 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.
+
+/*! \file tests/literal_medium_gray.cc
+ *
+ * \brief Tests on mln::literal::medium_gray.
+ */
+
+#include <mln/literal/grays.hh>
+#include <mln/value/graylevel.hh>
+
+
+int main()
+{
+ using namespace mln;
+
+ using literal::medium_gray;
+ using value::gl8;
+ using value::gl16;
+
+ gl8 a;
+ gl16 b;
+
+ a = medium_gray;
+
+ std::cout << int(a.value()) << std::endl;
+
+ b = a;
+ std::cout << int(b.value()) << std::endl;
+
+ b = medium_gray;
+ std::cout << int(b.value()) << std::endl;
+}
Index: trunk/milena/mln/literal/colors.hh
===================================================================
--- trunk/milena/mln/literal/colors.hh (revision 0)
+++ trunk/milena/mln/literal/colors.hh (revision 1334)
@@ -0,0 +1,77 @@
+// 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_LITERAL_COLORS_HH
+# define MLN_LITERAL_COLORS_HH
+
+/*! \file mln/literal/colors.hh
+ * \brief Definition of the colors literal.
+ *
+ */
+
+# include <mln/core/concept/literal.hh>
+
+namespace mln
+{
+
+ namespace literal
+ {
+
+ /// 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 green.
+ struct green_t : public Literal<green_t>
+ {
+ };
+
+
+ /// Literal red.
+ static red_t red = red_t();
+
+ /// Literal green.
+ static green_t green = green_t();
+
+ /// Literal blue.
+ static blue_t blue = blue_t();
+
+ } // end of namespace mln::literal
+
+} // end of namespace mln
+
+// White and black are color too.
+# include <mln/literal/white.hh>
+# include <mln/literal/black.hh>
+
+#endif // ! MLN_LITERAL_COLORS_HH
Index: trunk/milena/mln/literal/grays.hh
===================================================================
--- trunk/milena/mln/literal/grays.hh (revision 0)
+++ trunk/milena/mln/literal/grays.hh (revision 1334)
@@ -0,0 +1,60 @@
+// 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_LITERAL_GRAYS_HH
+# define MLN_LITERAL_GRAYS_HH
+
+/*! \file mln/literal/grays.hh
+ * \brief Definition of the colors literal.
+ *
+ */
+
+# include <mln/core/concept/literal.hh>
+
+namespace mln
+{
+
+ namespace literal
+ {
+
+ /// Type of literal grays.
+ struct medium_gray_t : public Literal<medium_gray_t>
+ {
+ };
+
+ /// Literal medium_gray.
+ static medium_gray_t medium_gray = medium_gray_t();
+
+ } // end of namespace mln::literal
+
+} // end of namespace mln
+
+// White and black are grays too.
+# include <mln/literal/white.hh>
+# include <mln/literal/black.hh>
+
+#endif // ! MLN_LITERAL_GRAYS_HH
Index: trunk/milena/mln/literal/all.hh
===================================================================
--- trunk/milena/mln/literal/all.hh (revision 1333)
+++ trunk/milena/mln/literal/all.hh (revision 1334)
@@ -47,12 +47,11 @@
# include <mln/literal/origin.hh>
-// FIXME: Add:
-// # include <mln/literal/white.hh>
-// # include <mln/literal/black.hh>
+# include <mln/literal/white.hh>
+# include <mln/literal/black.hh>
-// # include <mln/literal/grays.hh>
-// # include <mln/literal/colors.hh>
+# include <mln/literal/grays.hh>
+# include <mln/literal/colors.hh>
# include <mln/literal/ops.hh>
Index: trunk/milena/mln/value/graylevel.hh
===================================================================
--- trunk/milena/mln/value/graylevel.hh (revision 1333)
+++ trunk/milena/mln/value/graylevel.hh (revision 1334)
@@ -48,8 +48,14 @@
namespace mln
{
- /// Fwd decl.
- namespace literal { struct black_t; struct white_t; }
+ /// \{ Fwd decls.
+ namespace literal
+ {
+ struct black_t;
+ struct medium_gray_t;
+ struct white_t;
+ }
+ /// \}
namespace value
{
@@ -76,6 +82,7 @@
/// \{ Ctors with literals.
graylevel(const literal::black_t&);
+ graylevel(const literal::medium_gray_t&);
graylevel(const literal::white_t&);
/// \}
@@ -93,6 +100,7 @@
/// \{ Assigment with literals.
graylevel<n>& operator=(const literal::white_t&);
+ graylevel<n>& operator=(const literal::medium_gray_t&);
graylevel<n>& operator=(const literal::black_t&);
/// \}
};
@@ -168,6 +176,12 @@
}
template <unsigned n>
+ graylevel<n>::graylevel(const literal::medium_gray_t&)
+ {
+ this->v_ = metal::math::pow_int<2, n - 1>::value;
+ }
+
+ template <unsigned n>
graylevel<n>::graylevel(const literal::white_t&)
{
this->v_ = mln_max(mln_enc(int_u<n>));
@@ -209,6 +223,14 @@
template <unsigned n>
graylevel<n>&
+ graylevel<n>::operator=(const literal::medium_gray_t&)
+ {
+ this->v_ = metal::math::pow_int<2, n - 1>::value;
+ return *this;
+ }
+
+ template <unsigned n>
+ graylevel<n>&
graylevel<n>::operator=(const literal::white_t&)
{
this->v_ = mln_max(mln_enc(int_u<n>));
Index: trunk/milena/mln/value/rgb.hh
===================================================================
--- trunk/milena/mln/value/rgb.hh (revision 1333)
+++ trunk/milena/mln/value/rgb.hh (revision 1334)
@@ -41,6 +41,18 @@
namespace mln
{
+ /// \{ Fwd decls.
+ namespace literal
+ {
+ struct black_t;
+ struct white_t;
+
+ struct red_t;
+ struct blue_t;
+ struct green_t;
+ }
+ /// \}
+
namespace value
{
@@ -80,6 +92,11 @@
rgb<n>(equiv a);
rgb<n>(enc r, enc g, enc b);
rgb<n>(enc l);
+ rgb<n>(const literal::white_t&);
+ rgb<n>(const literal::black_t&);
+ rgb<n>(const literal::blue_t&);
+ rgb<n>(const literal::red_t&);
+ rgb<n>(const literal::green_t&);
/// \}
/// \{ Assignments.
@@ -90,14 +107,6 @@
/// 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;
- /// \}
-
/// addition
rgb<n> operator+(const rgb<n>& v) const;
// FIXME: was:
@@ -190,40 +199,64 @@
}
template <unsigned n>
- rgb<n>&
- rgb<n>::operator=(const rgb<n>& v)
+ rgb<n>::rgb(const literal::white_t&)
{
- std::memcpy(this->c_, v.c_, 3 * sizeof(enc));
- return *this;
+ this->c_[0] = mln_max(enc);
+ this->c_[1] = mln_max(enc);
+ this->c_[2] = mln_max(enc);
}
template <unsigned n>
- rgb<n>&
- rgb<n>::operator=(const enc& v)
+ rgb<n>::rgb(const literal::black_t&)
{
- for (int i = 0; i < 3; i++)
- this->c_[i] = v;
- return *this;
+ this->c_[0] = 0;
+ this->c_[1] = 0;
+ this->c_[2] = 0;
}
template <unsigned n>
- const rgb<n> rgb<n>::zero(0,0,0);
+ rgb<n>::rgb(const literal::red_t&)
+ {
+ this->c_[0] = mln_max(enc);
+ this->c_[1] = 0;
+ this->c_[2] = 0;
+ }
template <unsigned n>
- const rgb<n> rgb<n>::black(0,0,0);
+ rgb<n>::rgb(const literal::green_t&)
+ {
+ this->c_[0] = 0;
+ this->c_[1] = mln_max(enc);
+ this->c_[2] = 0;
+ }
template <unsigned n>
- const rgb<n> rgb<n>::max_red(mln_max(enc), 0, 0);
+ rgb<n>::rgb(const literal::blue_t&)
+ {
+ this->c_[0] = 0;
+ this->c_[1] = 0;
+ this->c_[2] = mln_max(enc);
+ }
template <unsigned n>
- const rgb<n> rgb<n>::max_green(0, mln_max(enc), 0);
+ rgb<n>&
+ rgb<n>::operator=(const rgb<n>& v)
+ {
+ std::memcpy(this->c_, v.c_, 3 * sizeof(enc));
+ return *this;
+ }
template <unsigned n>
- const rgb<n> rgb<n>::max_blue(0, 0, mln_max(enc));
+ rgb<n>&
+ rgb<n>::operator=(const enc& v)
+ {
+ for (int i = 0; i < 3; i++)
+ this->c_[i] = v;
+ return *this;
+ }
template <unsigned n>
- const rgb<n> rgb<n>::white(mln_max(enc), mln_max(enc), mln_max(enc));
-
+ const rgb<n> rgb<n>::zero(0,0,0);
template <unsigned n>
rgb<n>