Milena (Olena)  User documentation 2.0a Id
 All Classes Namespaces Functions Variables Typedefs Enumerator Groups Pages
invert.hh
1 // Copyright (C) 2010 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 #ifndef MLN_WORLD_RGB_INVERT_HH
27 # define MLN_WORLD_RGB_INVERT_HH
28 
34 
35 # include <mln/core/concept/image.hh>
36 # include <mln/trait/value_.hh>
37 # include <mln/value/rgb.hh>
38 
39 // Specializations are in:
40 # include <mln/world/rgb/invert.spe.hh>
41 
42 
43 namespace mln
44 {
45 
46  namespace world
47  {
48 
49  namespace rgb
50  {
51 
53 
67  template <typename I>
68  mln_concrete(I) invert(const Image<I>& input);
69 
70 
72 
85  template <typename I>
86  void invert_inplace(Image<I>& input);
87 
88 
89 # ifndef MLN_INCLUDE_ONLY
90 
91  namespace impl
92  {
93 
94  namespace generic
95  {
96 
97  template <typename I, typename O>
98  inline
99  void invert(const Image<I>& input_, Image<O>& output_)
100  {
101  trace::entering("world::rgb::impl::generic::invert");
102 
103  const I& input = exact(input_);
104  O& output = exact(output_);
105 
106  mln_precondition(input.is_valid());
107  mln_precondition(output.is_valid());
108 
109  typedef mln_value(I) V;
110  mln_piter(I) p(input.domain());
111  for_all(p)
112  output(p) = mln_min(V) + (mln_max(V) - input(p));
113 
114  trace::exiting("world::rgb::impl::generic::invert");
115  }
116 
117  } // end of namespace mln::world::rgb::impl::generic
118 
119 
120  } // end of namespace mln::world::rgb::impl
121 
122 
123 
124  // Dispatch.
125 
126  namespace internal
127  {
128 
129  template <typename I, typename O>
130  inline
131  void
132  invert_dispatch(trait::image::speed::any, const mln_value(I)&,
133  const I& input, O& output)
134  {
135  // No implementation found. May be input is not a RGB image?
136  mlc_abort(I)::check();
137  }
138 
139 
140  template <typename I, typename O, unsigned n>
141  inline
142  void
143  invert_dispatch(trait::image::speed::any, const value::rgb<n>&,
144  const I& input, O& output)
145  {
146  impl::invert_rgb(input, output);
147  }
148 
149  template <typename I, typename O, unsigned n>
150  inline
151  void
152  invert_dispatch(trait::image::speed::fastest, const value::rgb<n>&,
153  const I& input, O& output)
154  {
155  impl::invert_rgb_fastest(input, output);
156  }
157 
158 
159  template <typename I, typename O>
160  inline
161  void
162  invert_dispatch(const Image<I>& input, Image<O>& output)
163  {
164  typedef mln_value(I) V;
165  invert_dispatch(mln_trait_image_speed(I)(), V(),
166  exact(input), exact(output));
167 
168  }
169 
170 
171  } // end of namespace mln::world::rgb::internal
172 
173 
174 
175 
176  // Facades.
177 
178  template <typename I>
179  inline
180  mln_concrete(I) invert(const Image<I>& input)
181  {
182  trace::entering("world::rgb::invert");
183 
184  mln_precondition(exact(input).is_valid());
185 
186  mln_concrete(I) output;
187  initialize(output, input);
188  internal::invert_dispatch(input, output);
189 
190  trace::exiting("world::rgb::invert");
191  return output;
192  }
193 
194  template <typename I>
195  inline
196  void invert_inplace(Image<I>& input)
197  {
198  trace::entering("world::rgb::invert_inplace");
199 
200  mln_precondition(exact(input).is_valid());
201 
202  internal::invert_dispatch(input, input);
203 
204  trace::exiting("world::rgb::invert_inplace");
205  }
206 
207 # endif // ! MLN_INCLUDE_ONLY
208 
209  } // end of namespace mln::world::rgb
210 
211  } // end of namespace mln::world
212 
213 } // end of namespace mln
214 
215 
216 #endif // ! MLN_WORLD_RGB_INVERT_HH