URL:
https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-10-12 Matthieu Garrigues <garrigues(a)lrde.epita.fr>
Augment tests for gray values.
* mln/value/gray.hh: (operator=(graylevel<n>)) New.
* mln/value/graylevel.hh: Add constructors/assigments with gray.
* tests/value_graylevel.cc: Add tests.
---
mln/value/gray.hh | 19 ++-
mln/value/graylevel.hh | 25 ++++
tests/value_graylevel.cc | 252 ++++++++++++++++++++++++++++++++++++++++++-----
3 files changed, 267 insertions(+), 29 deletions(-)
Index: trunk/milena/tests/value_graylevel.cc
===================================================================
--- trunk/milena/tests/value_graylevel.cc (revision 1328)
+++ trunk/milena/tests/value_graylevel.cc (revision 1329)
@@ -47,62 +47,97 @@
using mln::literal::white;
using mln::literal::black;
+ // Constructions
+ {
+ gl8 x;
+
+ gl8 a = 12;
+ gl8 b(12);
+ mln_assertion(a == b);
+
+ gl16 c = 2335;
+ gl8 d = c;
+ mln_assertion(c == d);
+
+ gl8 e = gray(white);
+ mln_assertion(e == white);
+
+ gl8 f = 12;
+ gl8 g = f;
+ gl8 h(f);
+
+ mln_assertion(f == g);
+ mln_assertion(h == g);
+ }
+
// Literals
{
gl8 a = white;
gl16 b = white;
mln_assertion(a == b);
- mln_assertion(a.value() == 255);
- mln_assertion(b.value() == 65535);
+ mln_assertion(a.value() == float(255));
+ mln_assertion(b.value() == float(65535));
+ mln_assertion(a == white);
+ mln_assertion(b == white);
- gl8 c = (white + white) / 2;
+ gl8 c = (gl16(white) + white) / 2;
+ std::cout << "gl8 c = (white + white) / 2; => c.value() == "
+ << int(c.value()) << std::endl;
mln_assertion(c == white);
- mln_assertion(c.value() == 255);
+ mln_assertion(c.value() == float(255));
+
+ c = (gl8(white) + white) / 2;
+ mln_assertion(c == white);
+ mln_assertion(c.value() == float(255));
+
+ c = (gray(white) + white) / 2;
+ mln_assertion(c == white);
+ mln_assertion(c.value() == float(255));
a = black;
b = black;
mln_assertion(a == b);
- mln_assertion(a.value() == 0);
- mln_assertion(b.value() == 0);
+ mln_assertion(a.value() == float(0));
+ mln_assertion(b.value() == float(0));
c = (black + black) / 2;
mln_assertion(c == black);
- mln_assertion(c.value() == 0);
+ mln_assertion(c.value() == float(0));
}
// Assigment
{
gl8 a;
- gl8 b;
+ gl16 b;
a = white;
mln_assertion(a == white);
- mln_assertion(a.value() == 255);
+ mln_assertion(a.value() == float(255));
a = 23;
mln_assertion(a != white);
mln_assertion(a != black);
- mln_assertion(a.value() == 23);
+ mln_assertion(a.value() == float(23));
b = 2;
mln_assertion(b != white);
mln_assertion(b != black);
- mln_assertion(b.value() == 2);
+ mln_assertion(b.value() == float(2));
a = b;
- mln_assertion(a.value() == 2);
+ mln_assertion(a.value() == float(2 / 257));
signed char c = 51;
a = c;
- mln_assertion(a.value() == 51);
+ mln_assertion(a.value() == float(51));
// bounds
a = 255;
- mln_assertion(a.value() == 255);
+ mln_assertion(a.value() == float(255));
a = 0;
- mln_assertion(a.value() == 0);
+ mln_assertion(a.value() == float(0));
}
// Addition
@@ -112,50 +147,215 @@
// gl8 <- gl8 + gl8
a = 42;
- b = 16969;
a += a;
- mln_assertion(a.value() == 84);
+ mln_assertion(a.value() == float(84));
a = 42;
- b = 16969;
a = a + a;
- mln_assertion(a.value() == 84);
+ mln_assertion(a.value() == float(84));
// gl8 <- gl8 + gl16
a = 42;
b = 16969;
a = a + b;
- mln_assertion(a.value() == (42 + b.value() / 257) );
+ mln_assertion(a.value() == float((42 + b.value() / 257) ));
a = 42;
b = 16969;
a += b;
- mln_assertion(a.value() == (42 + b.value() / 257) );
+ mln_assertion(a.value() == float((42 + b.value() / 257) ));
// gl16 <- gl8 + gl16
a = 42;
b = 16969;
b += a;
- mln_assertion(b.value() == (42 * 257 + 16969) );
+ mln_assertion(b.value() == float((42 * 257 + 16969) ));
a = 42;
b = 16969;
b = a + b;
- mln_assertion(b.value() == (42 * 257 + 16969) );
+ mln_assertion(b.value() == float((42 * 257 + 16969) ));
// misc
a = 255;
b = 0;
a = a + b;
- mln_assertion(a.value() == 255);
+ mln_assertion(a.value() == float(255));
a = 0;
b = 65535;
a = a + b;
- mln_assertion(a.value() == 255);
+ mln_assertion(a.value() == float(255));
}
+ // Soustraction
+ {
+ gl8 a;
+ gl16 b;
+
+ // gl8 <- gl8 - gl8
+ a = 42;
+ a -= a;
+ mln_assertion(a == black);
+
+ a = 42;
+ a = a - a;
+ mln_assertion(a == black);
+
+ // gl8 <- gl8 - gl16
+ a = 42;
+ b = 5969;
+
+ a = b;
+ std::cout << "a.value() = " << int(a.value()) <<
std::endl;
+ std::cout << "should be " << (b.value() / 257) <<
std::endl;
+
+ a = 42;
+ a = a - b;
+ std::cout << int(a.value()) << ":" << (42 - b.value() /
257) << std::endl;
+ mln_assertion(a.value() == float((42 - b.value() / 257) ));
+ a = 42;
+ b = 16969;
+ a -= b;
+ mln_assertion(a.value() == float((42 - b.value() / 257) ));
+
+
+ // gl16 <- gl8 - gl16
+ a = 100;
+ b = 16969;
+ b -= a;
+ mln_assertion(b.value() == float((100 * 257 - 16969) ));
+
+ a = 100;
+ b = 16969;
+ b = a - b;
+ mln_assertion(b.value() == float((100 * 257 - 16969) ));
+
+ // misc
+ a = 255;
+ b = 0;
+ a = a - b;
+ mln_assertion(a.value() == float(255));
+
+ a = 0;
+ b = 65535;
+ a = a - b;
+ mln_assertion(a.value() == float(255));
+
+ // ...
+ {
+ graylevel<2> a = 2;
+ graylevel<3> b = 5;
+ graylevel<2> c;
+ graylevel<3> d;
+
+ c = a - b;
+ d = a - b;
+ mln_assertion(c == d);
+ }
+
+ {
+
+ // ...
+ gl8 a = 42;
+ gl16 b = 5969;
+ gl8 p;
+ p = b;
+ gl8 q;
+ gl8 r;
+
+ q = a - p;
+ r = a - b;
+ std::cout << int(q.value()) << " " << int(r.value())
<< std::endl;
+ mln_assertion(q == r);
+
+ }
+
+ }
+
+
+
+ // Multiplication
+ {
+ gl8 a;
+ gl16 b;
+
+ // gl8 <- gl8 * gl8
+ a = 21;
+ a *= a;
+ mln_assertion(a.value() == 42);
+
+ a = 21;
+ a = a * a;
+ mln_assertion(a.value() == 42);
+
+ // gl8 <- gl8 * gl16
+ a = 10;
+ b = 5969;
+ a = a * b;
+ mln_assertion(a.value() == float((10 * b.value() / 257) ));
+
+ a = 10;
+ b = 16969;
+ a *= b;
+ mln_assertion(a.value() == float((10 * b.value() / 257) ));
+
+
+ // gl16 <- gl8 * gl16
+ a = 10;
+ b = 5969;
+ b *= a;
+ mln_assertion(b.value() == float((10 * 257 * 5969) ));
+
+ a = 10;
+ b = 5969;
+ b = a * b;
+ mln_assertion(b.value() == float((10 * 257 * 5969) ));
+
+ // misc
+ a = 255;
+ b = 0;
+ a = a * b;
+ mln_assertion(a == black);
+
+ a = 0;
+ b = 65535;
+ a = a * b;
+ mln_assertion(a == black);
+
+ // ...
+ {
+ graylevel<2> a = 2;
+ graylevel<3> b = 5;
+ graylevel<2> c;
+ graylevel<3> d;
+
+ c = a * b;
+ d = a * b;
+ mln_assertion(c == d);
+ }
+
+ {
+
+ // ...
+ gl8 a = 7;
+ gl16 b = 5969;
+
+ gl8 p;
+ p = b;
+
+ gl8 q;
+ gl8 r;
+
+ q = a * p;
+ r = a * b;
+ std::cout << int(q.value()) << " " << int(r.value())
<< std::endl;
+ mln_assertion(q == r);
+
+ }
+
+ }
// Not exhaustive
@@ -183,7 +383,7 @@
// {
// gl8 c = (white + white) / 2;
// mln_assertion(c == white);
- // mln_assertion(c.value() == 255);
+ // mln_assertion(c.value() == float(255));
// }
// gray g = black;
Index: trunk/milena/mln/value/graylevel.hh
===================================================================
--- trunk/milena/mln/value/graylevel.hh (revision 1328)
+++ trunk/milena/mln/value/graylevel.hh (revision 1329)
@@ -74,12 +74,19 @@
graylevel(const literal::white_t&);
/// \}
+ /// Ctor with gray.
+ graylevel(const gray&);
+
+
/// Access to std type.
mln_enc(int_u<n>) value() const;
/// Assigment with int.
graylevel<n>& operator=(int val);
+ /// Assigment with gray.
+ graylevel<n>& operator=(const gray&);
+
/// \{ Assigment with literals.
graylevel<n>& operator=(const literal::white_t&);
graylevel<n>& operator=(const literal::black_t&);
@@ -120,6 +127,9 @@
template <unsigned n, unsigned m>
gray operator-(const graylevel<n>& lhs, const graylevel<m>&
rhs);
+ template <unsigned n, unsigned m>
+ gray operator*(const graylevel<n>& lhs, const graylevel<m>&
rhs);
+
@@ -140,6 +150,12 @@
this->v_ = val;
}
+ template <unsigned n>
+ graylevel<n>::graylevel(const gray& g)
+ {
+ gray tmp = g.to_nbits(n);
+ this->v_ = tmp.value();
+ }
template <unsigned n>
graylevel<n>::graylevel(const literal::black_t&)
@@ -172,6 +188,15 @@
template <unsigned n>
graylevel<n>&
+ graylevel<n>::operator=(const gray& g)
+ {
+ gray tmp = g.to_nbits(n);
+ this->v_ = tmp.value();
+ return *this;
+ }
+
+ template <unsigned n>
+ graylevel<n>&
graylevel<n>::operator=(const literal::black_t&)
{
this->v_ = 0;
Index: trunk/milena/mln/value/gray.hh
===================================================================
--- trunk/milena/mln/value/gray.hh (revision 1328)
+++ trunk/milena/mln/value/gray.hh (revision 1329)
@@ -71,9 +71,13 @@
/// \}
- /// Ctor.
- template <unsigned N>
- gray(const graylevel<N>& val);
+ /// \{ Constructors/assigments with graylevel.
+ template <unsigned n>
+ gray(const graylevel<n>& val);
+
+ template <unsigned n>
+ gray& operator=(const graylevel<n>& val);
+ /// \}
/// Ctor.
gray(unsigned nbits, unsigned long val);
@@ -169,6 +173,15 @@
{
}
+
+ template <unsigned n>
+ gray& gray::operator=(const graylevel<n>& g)
+ {
+ nbits_ = n;
+ val_ = g.value();
+ return *this;
+ }
+
gray& gray::operator=(const literal::white_t&)
{
// nbits_ is not modified so that precision does not change.