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