$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
invert.hh
1 // Copyright (C) 2010, 2012, 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 #ifndef MLN_WORLD_RGB_INVERT_HH
28 # define MLN_WORLD_RGB_INVERT_HH
29 
35 
36 # include <mln/core/concept/image.hh>
37 # include <mln/trait/value_.hh>
38 # include <mln/value/rgb.hh>
39 
40 // Specializations are in:
41 # include <mln/world/rgb/invert.spe.hh>
42 
43 
44 namespace mln
45 {
46 
47  namespace world
48  {
49 
50  namespace rgb
51  {
52 
54 
68  template <typename I>
69  mln_concrete(I) invert(const Image<I>& input);
70 
71 
73 
86  template <typename I>
87  void invert_inplace(Image<I>& input);
88 
89 
90 # ifndef MLN_INCLUDE_ONLY
91 
92  namespace impl
93  {
94 
95  namespace generic
96  {
97 
98  template <typename I, typename O>
99  inline
100  void invert(const Image<I>& input_, Image<O>& output_)
101  {
102  mln_trace("world::rgb::impl::generic::invert");
103 
104  const I& input = exact(input_);
105  O& output = exact(output_);
106 
107  mln_precondition(input.is_valid());
108  mln_precondition(output.is_valid());
109 
110  typedef mln_value(I) V;
111  mln_piter(I) p(input.domain());
112  for_all(p)
113  output(p) = mln_min(V) + (mln_max(V) - input(p));
114 
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. Maybe `input' is not an 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  mln_trace("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  return output;
191  }
192 
193  template <typename I>
194  inline
195  void invert_inplace(Image<I>& input)
196  {
197  mln_trace("world::rgb::invert_inplace");
198 
199  mln_precondition(exact(input).is_valid());
200 
201  internal::invert_dispatch(input, input);
202 
203  }
204 
205 # endif // ! MLN_INCLUDE_ONLY
206 
207  } // end of namespace mln::world::rgb
208 
209  } // end of namespace mln::world
210 
211 } // end of namespace mln
212 
213 
214 #endif // ! MLN_WORLD_RGB_INVERT_HH