Milena (Olena)
User documentation 2.0a Id
|
00001 // Copyright (C) 2010 EPITA Research and Development Laboratory (LRDE) 00002 // 00003 // This file is part of Olena. 00004 // 00005 // Olena is free software: you can redistribute it and/or modify it under 00006 // the terms of the GNU General Public License as published by the Free 00007 // Software Foundation, version 2 of the License. 00008 // 00009 // Olena is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 // General Public License for more details. 00013 // 00014 // You should have received a copy of the GNU General Public License 00015 // along with Olena. If not, see <http://www.gnu.org/licenses/>. 00016 // 00017 // As a special exception, you may use this file as part of a free 00018 // software project without restriction. Specifically, if other files 00019 // instantiate templates or use macros or inline functions from this 00020 // file, or you compile this file and link it with other files to produce 00021 // an executable, this file does not by itself cause the resulting 00022 // executable to be covered by the GNU General Public License. This 00023 // exception does not however invalidate any other reasons why the 00024 // executable file might be covered by the GNU General Public License. 00025 00026 #ifndef MLN_WORLD_RGB_INVERT_HH 00027 # define MLN_WORLD_RGB_INVERT_HH 00028 00034 00035 # include <mln/core/concept/image.hh> 00036 # include <mln/trait/value_.hh> 00037 # include <mln/value/rgb.hh> 00038 00039 // Specializations are in: 00040 # include <mln/world/rgb/invert.spe.hh> 00041 00042 00043 namespace mln 00044 { 00045 00046 namespace world 00047 { 00048 00049 namespace rgb 00050 { 00051 00053 00067 template <typename I> 00068 mln_concrete(I) invert(const Image<I>& input); 00069 00070 00072 00085 template <typename I> 00086 void invert_inplace(Image<I>& input); 00087 00088 00089 # ifndef MLN_INCLUDE_ONLY 00090 00091 namespace impl 00092 { 00093 00094 namespace generic 00095 { 00096 00097 template <typename I, typename O> 00098 inline 00099 void invert(const Image<I>& input_, Image<O>& output_) 00100 { 00101 trace::entering("world::rgb::impl::generic::invert"); 00102 00103 const I& input = exact(input_); 00104 O& output = exact(output_); 00105 00106 mln_precondition(input.is_valid()); 00107 mln_precondition(output.is_valid()); 00108 00109 typedef mln_value(I) V; 00110 mln_piter(I) p(input.domain()); 00111 for_all(p) 00112 output(p) = mln_min(V) + (mln_max(V) - input(p)); 00113 00114 trace::exiting("world::rgb::impl::generic::invert"); 00115 } 00116 00117 } // end of namespace mln::world::rgb::impl::generic 00118 00119 00120 } // end of namespace mln::world::rgb::impl 00121 00122 00123 00124 // Dispatch. 00125 00126 namespace internal 00127 { 00128 00129 template <typename I, typename O> 00130 inline 00131 void 00132 invert_dispatch(trait::image::speed::any, const mln_value(I)&, 00133 const I& input, O& output) 00134 { 00135 // No implementation found. May be input is not a RGB image? 00136 mlc_abort(I)::check(); 00137 } 00138 00139 00140 template <typename I, typename O, unsigned n> 00141 inline 00142 void 00143 invert_dispatch(trait::image::speed::any, const value::rgb<n>&, 00144 const I& input, O& output) 00145 { 00146 impl::invert_rgb(input, output); 00147 } 00148 00149 template <typename I, typename O, unsigned n> 00150 inline 00151 void 00152 invert_dispatch(trait::image::speed::fastest, const value::rgb<n>&, 00153 const I& input, O& output) 00154 { 00155 impl::invert_rgb_fastest(input, output); 00156 } 00157 00158 00159 template <typename I, typename O> 00160 inline 00161 void 00162 invert_dispatch(const Image<I>& input, Image<O>& output) 00163 { 00164 typedef mln_value(I) V; 00165 invert_dispatch(mln_trait_image_speed(I)(), V(), 00166 exact(input), exact(output)); 00167 00168 } 00169 00170 00171 } // end of namespace mln::world::rgb::internal 00172 00173 00174 00175 00176 // Facades. 00177 00178 template <typename I> 00179 inline 00180 mln_concrete(I) invert(const Image<I>& input) 00181 { 00182 trace::entering("world::rgb::invert"); 00183 00184 mln_precondition(exact(input).is_valid()); 00185 00186 mln_concrete(I) output; 00187 initialize(output, input); 00188 internal::invert_dispatch(input, output); 00189 00190 trace::exiting("world::rgb::invert"); 00191 return output; 00192 } 00193 00194 template <typename I> 00195 inline 00196 void invert_inplace(Image<I>& input) 00197 { 00198 trace::entering("world::rgb::invert_inplace"); 00199 00200 mln_precondition(exact(input).is_valid()); 00201 00202 internal::invert_dispatch(input, input); 00203 00204 trace::exiting("world::rgb::invert_inplace"); 00205 } 00206 00207 # endif // ! MLN_INCLUDE_ONLY 00208 00209 } // end of namespace mln::world::rgb 00210 00211 } // end of namespace mln::world 00212 00213 } // end of namespace mln 00214 00215 00216 #endif // ! MLN_WORLD_RGB_INVERT_HH