Milena (Olena)
User documentation 2.0a Id
Main Page
Related Pages
Modules
Namespaces
Classes
All
Classes
Namespaces
Functions
Variables
Typedefs
Enumerator
Groups
Pages
graylevel_full.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/int_u8.hh>
29
30
#include <mln/literal/black.hh>
31
#include <mln/literal/white.hh>
32
33
34
35
int
main()
36
{
37
using namespace
mln::value;
38
39
using
mln::literal::white
;
40
using
mln::literal::black
;
41
42
gl8
a = 255;
43
gl8
b = 255;
44
45
// Constructions
46
{
47
// With int
48
gl8
x;
49
gl8
a = 12;
50
gl8
b(12);
51
mln_assertion(a == b);
52
53
{
54
gl16
c = 2335;
55
gl8
d = c;
56
mln_assertion(c == d);
57
}
58
59
gl8
d = 250;
60
gl16
c = d;
61
mln_assertion(c == d);
62
63
gl8
e =
white
;
64
65
mln_assertion(e ==
gl8
(white));
66
67
gl8
f = 12;
68
gl8
g = f;
69
gl8
h(f);
70
71
mln_assertion(f == g);
72
mln_assertion(h == g);
73
74
// FIXME: Make the following tests compile.
75
{
76
// With gray_f.
77
//gl8 a = mln::value::internal::gray_f(12.5);
78
79
}
80
}
81
82
// Literals
83
// {
84
// gl8 a(white);
85
// gl16 b(white);
86
87
// a = white;
88
// b = white;
89
90
// mln_assertion(a == b);
91
// mln_assertion(a.value() == float(255));
92
// mln_assertion(b.value() == float(65535));
93
// mln_assertion(a == white);
94
// mln_assertion(b == white);
95
96
// gl8 c(white);
97
// mln_assertion(c == white);
98
// mln_assertion(c.value() == float(255));
99
100
// a = black;
101
// b = black;
102
103
// mln_assertion(a == b);
104
// mln_assertion(a.value() == float(0));
105
// mln_assertion(b.value() == float(0));
106
// }
107
108
// // Assigment
109
// {
110
// gl8 a;
111
// gl16 b;
112
113
// a = white;
114
// mln_assertion(a == white);
115
// mln_assertion(a.value() == float(255));
116
117
// a = 23;
118
// mln_assertion(a != white);
119
// mln_assertion(a != black);
120
// mln_assertion(a.value() == float(23));
121
122
// b = 2;
123
// mln_assertion(b != white);
124
// mln_assertion(b != black);
125
// mln_assertion(b.value() == float(2));
126
127
// a = b;
128
// mln_assertion(a.value() == float(2 / 256));
129
130
// signed char c = 51;
131
// a = c;
132
// mln_assertion(a.value() == float(51));
133
134
// // bounds
135
// a = 255;
136
// mln_assertion(a.value() == float(255));
137
// a = 0;
138
// mln_assertion(a.value() == float(0));
139
// }
140
141
// Addition
142
{
143
// gl8 a;
144
// gl16 b;
145
146
// // gl8 <- gl8 + gl8
147
// a = 42;
148
// a += a;
149
// mln_assertion(a.value() == float(84));
150
151
// a = 42;
152
// a = a + a;
153
// mln_assertion(a.value() == float(84));
154
155
// // gl8 <- gl8 + gl16
156
// a = 42;
157
// b = 16969;
158
// a = a + b;
159
// mln_assertion(a.value() == float((42 + b.value() / 257) ));
160
// a = 42;
161
// b = 16969;
162
// a += b;
163
// mln_assertion(a.value() == float((42 + b.value() / 256) ));
164
165
166
// // gl16 <- gl8 + gl16
167
// a = 42;
168
// b = 16969;
169
// b += a;
170
// mln_assertion(b.value() == float((42 * 256 + 16969) ));
171
172
// a = 42;
173
// b = 16969;
174
// b = b + a;
175
176
// mln_assertion(b.value() == float((42 * 256 + 16969) ));
177
178
// a = 42;
179
// b = 16969;
180
// b = a + b;
181
// mln_assertion(b.value() == float((42 * 256 + 16969) ));
182
183
// // misc
184
// a = 255;
185
// b = 0;
186
// a = a + b;
187
// mln_assertion(a.value() == float(255));
188
189
// a = 0;
190
// b = 65535;
191
// a = a + b;
192
// mln_assertion(a.value() == float(255));
193
}
194
195
196
// // Soustraction
197
// {
198
// gl8 a;
199
// gl16 b;
200
201
// // gl8 <- gl8 - gl8
202
// a = 42;
203
// a -= a;
204
// mln_assertion(a == black);
205
206
// a = 42;
207
// a = a - a;
208
// mln_assertion(a == black);
209
210
// // gl8 <- gl8 - gl16
211
// a = 42;
212
// b = 5969;
213
214
// a = b;
215
216
// {
217
// a = 42;
218
// gl16 t;
219
220
// t = a - b;
221
// t = t + b;
222
// mln_assertion(a == t);
223
// }
224
225
// a = 42;
226
// a = a - b;
227
// mln_assertion(a.value() == (42 * 256 - b.value()) / 256 );
228
// a = 42;
229
// b = 9969;
230
// a -= b;
231
// mln_assertion(a.value() == (42 * 256 - b.value()) / 256 );
232
233
234
// // gl16 <- gl8 - gl16
235
// a = 100;
236
// b = 30969;
237
// b -= a;
238
// mln_assertion(b.value() == float(30969 - 100 * 256));
239
240
// a = 100;
241
// b = 20969;
242
// b = a - b;
243
// mln_assertion(b.value() == float((100 * 256 - 20969) ));
244
245
// // misc
246
// a = 255;
247
// b = 0;
248
// a = a - b;
249
// mln_assertion(a.value() == float(255));
250
251
// gl8(255) - gl16(65535);
252
// mln_assertion( gl8(255) == gl16(65535) );
253
// a = 255;
254
// b = 65535;
255
// a = a - b;
256
// mln_assertion(a.value() == float(0));
257
258
// // ...
259
// {
260
// graylevel<2> a = 1;
261
// graylevel<3> b = 5;
262
// graylevel<2> c;
263
// graylevel<3> d;
264
265
// c = b - a;
266
// d = b - a;
267
// mln_assertion(c == d);
268
// }
269
270
// }
271
272
// // Multiplication
273
// {
274
// gl8 a;
275
// gl16 b;
276
277
// // gl8 <- gl8 * gl8
278
// a = 8;
279
// a *= a;
280
// mln_assertion(a.value() == 64);
281
282
// a = 7;
283
// a = a * a;
284
// mln_assertion(a.value() == 49);
285
286
// // gl8 <- gl8 * gl16
287
// a = 10;
288
// b = 20;
289
// a = a * b;
290
// mln_assertion(a.value() == float((10 * 256* b.value())/256));
291
292
// a = 10;
293
// b = 16;
294
// a *= b;
295
// mln_assertion(a.value() == float((10 * 256* b.value())/256));
296
297
// mln_assertion((gl8(12) * gl16(12345)).to_enc() == float((12 * 256* 12345)));
298
299
300
// // gl16 <- gl8 * gl16
301
// a = 10;
302
// b = 24;
303
// b *= a;
304
// mln_assertion(b.value() == float((10 * 256 * 24) ));
305
306
// a = 10;
307
// b = 24;
308
// b = a * b;
309
// mln_assertion(b.value() == float((10 * 256 * 24) ));
310
311
// // misc
312
// a = 255;
313
// b = 0;
314
// a = a * b;
315
// mln_assertion(a == black);
316
317
// a = 0;
318
// b = 65535;
319
// a = a * b;
320
// mln_assertion(a == black);
321
322
323
// // With Floating.
324
// // a = 8;
325
// // a = a * 0.5;
326
// // mln_assertion(a.value() == 4.f);
327
328
// // a = 8;
329
// // a *= 0.5;
330
// // mln_assertion(a.value() == 4.f);
331
332
// // ...
333
// {
334
// graylevel<2> a = 1;
335
// graylevel<3> b = 2;
336
// graylevel<2> c;
337
// graylevel<3> d;
338
339
// c = a * b;
340
// d = a * b;
341
// mln_assertion(c == d);
342
// }
343
344
// {
345
346
// // ...
347
// gl8 a = 7;
348
// gl16 b = 596;
349
350
// gl8 p;
351
// p = b;
352
353
// gl8 q;
354
// gl8 r;
355
356
// q = a * p;
357
// r = a * b / 256;
358
// }
359
360
// }
361
// // division
362
// {
363
// // gl8 a = 2;
364
// // a = a / 2;
365
// // mln_assertion(a.value() == 1);
366
367
// // a = 6;
368
// // a = a / 1.5;
369
// // mln_assertion(a.value() == 4.f);
370
371
// }
372
373
// {
374
// gl8 a = 1;
375
// int_u8 b = 1;
376
// float01_f c = 0.5;
377
378
// // Theses lines are forbidden. Since we can't add or substract
379
// // graylevel with int or float.
380
// // a + b;
381
// // a - b;
382
// // a + c;
383
// // a - c;
384
// }
385
386
}
tests
value
graylevel_full.cc
Generated on Thu Nov 8 2012 10:58:06 for Milena (Olena) by
1.8.2-20120930