$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
rgb_full.cc
1 // Copyright (C) 2007, 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/rgb.hh>
27 #include <mln/value/rgb8.hh>
28 #include <mln/value/int_u8.hh>
29 #include <mln/literal/all.hh>
30 
31 
32 #define sym_compare_assert(V1, OP, V2) \
33  \
34  mln_assertion(V1 OP V2);
35 
36 #define compute_rgb(T, V1, OP, V2) \
37  \
38  T( \
39  V1.red() OP V2.red() , \
40  V1.green() OP V2.green() , \
41  V1.blue() OP V2.blue() \
42  )
43 
44 #define compute_rgb_sc(T, V1, OP, V2) \
45  \
46  T( \
47  V1.red() OP V2 , \
48  V1.green() OP V2 , \
49  V1.blue() OP V2 \
50  )
51 
52 // Interop between 2 rgbs.
53 #define test_interop(T1, T2, OP, V1, V2) \
54 { \
55  T1 i = V1; \
56  T2 j = V2; \
57  \
58  i = i OP j; \
59  sym_compare_assert(i, ==, compute_rgb(T1, V1, OP, V2)); \
60  sym_compare_assert(j, ==, V2); \
61  \
62  i = V1; \
63  j = V2; \
64  \
65  j = i OP j; \
66  sym_compare_assert(j, ==, compute_rgb(T1,V1, OP, V2)); \
67  sym_compare_assert(i, ==, V1); \
68  \
69  i = V1; \
70  i OP##= i; \
71  sym_compare_assert(i, ==, compute_rgb(T1,V1, OP, V1)); \
72  \
73  i = V1; \
74  j = V2; \
75  i OP##= j; \
76  sym_compare_assert(i, ==, compute_rgb(T1,V1, OP, V2)); \
77  \
78  j OP##= j; \
79  sym_compare_assert(j, ==, compute_rgb(T1,V2, OP, V2)); \
80  \
81  i = V1; \
82  j = V2; \
83  j OP##= i; \
84  sym_compare_assert(j, ==, compute_rgb(T1,V2, OP, V1)); \
85  \
86  i = V1; \
87  i OP##= i; \
88  sym_compare_assert(i, ==, compute_rgb(T1,V1, OP, V1)); \
89 }
90 
91 
92 // T1 is rgb, T2 is scalar
93 #define test_interop_sc(T1, T2, OP, V1, V2) \
94 { \
95  T1 i = V1; \
96  T2 j = V2; \
97  \
98  i = i OP j; \
99  sym_compare_assert(i, ==, compute_rgb_sc(T1,V1, OP, V2)); \
100  sym_compare_assert(j, ==, V2); \
101  \
102  i = V1; \
103  j = V2; \
104  i OP##= j; \
105  sym_compare_assert(i, ==, compute_rgb_sc(T1, V1, OP, V2)); \
106 }
107 
108 int main()
109 {
110  using namespace mln;
111  using value::rgb;
112  using value::rgb8;
113  using value::int_u8;
114  using value::int_u;
115 
116  using literal::blue;
117  using literal::white;
118 
119  {
120  test_interop(rgb8, rgb8, +, rgb8(4,5,6), rgb8(1,2,3));
121  test_interop(rgb8, rgb8, -, rgb8(4,5,6), rgb8(1,2,3));
122 
123  test_interop(rgb<10>, rgb<10>, +, rgb<10>(4,5,6), rgb<10>(1,2,3));
124  test_interop(rgb<10>, rgb<10>, -, rgb<10>(4,5,6), rgb<10>(1,2,3));
125 
126  test_interop(rgb<16>, rgb<16>, +, rgb<16>(4,5,6), rgb<16>(1,2,3));
127  test_interop(rgb<16>, rgb<16>, -, rgb<16>(4,5,6), rgb<16>(1,2,3));
128 
129  test_interop_sc(rgb8, int, *, rgb8(4,5,6), 4);
130  test_interop_sc(rgb8, int, /, rgb8(40,50,60), 10);
131 
132  test_interop_sc(rgb8, unsigned, *, rgb8(4,5,6), 4);
133  test_interop_sc(rgb8, unsigned, /, rgb8(40,50,60), 10);
134 
135  // FIXME : operators *,/ are ambiguous for (rgb8, float)...
136  // test_interop_sc(rgb8, float, *, rgb8(4,5,6), 4);
137  // test_interop_sc(rgb8, float, /, rgb8(40,50,60), 10);
138 
139  test_interop_sc(rgb8, char, *, rgb8(4,5,6), 4);
140  test_interop_sc(rgb8, char, /, rgb8(40,50,60), 10);
141 
142  test_interop_sc(rgb8, int_u8, *, rgb8(4,5,6), 4);
143  test_interop_sc(rgb8, int_u8, /, rgb8(40,50,60), 10);
144 
145  test_interop_sc(rgb8, int_u<7>, *, rgb8(4,5,6), 4);
146  test_interop_sc(rgb8, int_u<7>, /, rgb8(40,50,60), 10);
147  }
148 }