$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
graylevel.cc
1 // Copyright (C) 2007, 2008, 2009, 2013 EPITA Research and Development
2 // Laboratory (LRDE)
3 //
4 // This file is part of Olena.
5 //
6 // Olena is free software: you can redistribute it and/or modify it under
7 // the terms of the GNU General Public License as published by the Free
8 // Software Foundation, version 2 of the License.
9 //
10 // Olena is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with Olena. If not, see <http://www.gnu.org/licenses/>.
17 //
18 // As a special exception, you may use this file as part of a free
19 // software project without restriction. Specifically, if other files
20 // instantiate templates or use macros or inline functions from this
21 // file, or you compile this file and link it with other files to produce
22 // an executable, this file does not by itself cause the resulting
23 // executable to be covered by the GNU General Public License. This
24 // exception does not however invalidate any other reasons why the
25 // executable file might be covered by the GNU General Public License.
26 
27 #include <mln/value/gl8.hh>
28 #include <mln/value/gl16.hh>
29 #include <mln/value/glf.hh>
30 
31 #include <mln/value/int_u8.hh>
32 #include <mln/value/int_s8.hh>
33 #include <mln/value/float01_f.hh>
34 #include <mln/value/float01_.hh>
35 
36 #include <mln/literal/black.hh>
37 #include <mln/literal/white.hh>
38 
39 
40 template<typename From, typename To, typename T>
41 void
42 test_conversion (const T& val)
43 {
44  (void)(To)(From) val;
45  To test = (From)(val);
46  test = (From)(val);
47 }
48 
49 
50 int main()
51 {
52  using namespace mln::value;
53  using namespace mln::value::internal;
54 
55  using mln::literal::white;
56  using mln::literal::black;
57 
58 
59  gl8 a(white);
60  gl8 b(white);
61 
62  a = b;
63  mln_assertion(a == b);
64 
65  {
66  gl8 a(10);
67  gl8 b(10);
68 
69  gl8 c = a + b;
70  (void) c;
71  }
72 
73  {
74  gl8 a(white);
75  gl8 b(white);
76  gl8 c;
77 
78  // gl8 * int
79  a * 2;
80  2 * a;
81 
82 
83  // gl8 * double
84  a * 2.0;
85  2.0 * a;
86 
87  // gl8 * bool
88  a * false;
89  false * a;
90 
91  // gl8 * Integer
92  a * int_u8(23);
93  int_u8(23) * a;
94 
95  // gl8 * Floating
96  a * float01_f(.23);
97  float01_f(.23) * a;
98 
99  float01_<16>(.23) * a;
100  a * float01_<16>(.23);
101 
102 
103  // gl8 / int
104  a / 1.5;
105 
106  // gl8 / double
107  mln_assertion(a / 2.0 == glf(0.5));
108 
109  // gl8 / bool
110  mln_assertion(a / true == a);
111 
112  // gl8 / Integer
113  /* FIXME: The compiler emits a warning about a comparison between
114  signed and unsigned for the first line, but not for the second.
115  This behavior is strange, since
116 
117  a * int_u(23);
118 
119  triggers no warning. See whether traits and conversions are
120  handled symmetrically for `*' and `/'. */
121  a / int_u8(23);
122  a / int_s8(23);
123 
124  // gl8 / Floating
125  a / float01_f(.23);
126  a / float01_<16>(.23);
127  }
128 
129  {
130  // Conversions.
131 
132  typedef mln::value::internal::gray_<8> i_gray_8;
133 
134  // gray_<n> -> graylevel<n>
135  test_conversion<i_gray_8, gl8>(255);
136 
137  // gray_f -> graylevel<n>
138  test_conversion<gray_f, gl8>(0.4);
139  // graylevel_f -> graylevel<n>
140  test_conversion<glf, gl8>(0.4);
141 
142  // gray_<n> -> graylevel_f
143  test_conversion<i_gray_8, glf>(255);
144  // gray_f -> graylevel_f
145  test_conversion<gray_f, glf>(0.4);
146  // graylevel<n> -> graylevel_f
147  test_conversion<gl8, glf>(142);
148 
149  // gray_<n> -> gray_f
150  test_conversion<i_gray_8, gray_f>(4);
151 
152 
153  // gray_f -> gray_<n>
154  test_conversion<gray_f, i_gray_8>(0.4);
155 
156  // graylevel_f -> gray_f
157  test_conversion<glf, gray_f>(0.4);
158 
159  // graylevel<n> -> gray_<n>
160  test_conversion<gl8, i_gray_8>(142);
161  }
162 }