00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef OLENA_MORPHER_COLOR_MORPHER_HH
00030 # define OLENA_MORPHER_COLOR_MORPHER_HH
00031
00032 # include <oln/morpher/generic_morpher.hh>
00033
00034 namespace oln {
00035
00036 namespace morpher {
00037
00038 template <class I, class Exact = mlc::final>
00039 class color_morpher;
00040
00041 }
00042
00043
00050 template <class I, class Exact>
00051 struct image_id<morpher::color_morpher<I, Exact> >
00052 {
00053 enum {dim = I::dim};
00055 typedef oln_impl_type(I) impl_type;
00057 typedef ntg_comp_type(oln_value_type(I)) value_type;
00062 typedef typename mlc::exact_vt<morpher::color_morpher<I, Exact>,
00063 Exact>::ret exact_type;
00068 typedef oln_point_type(I) point_type;
00069 typedef oln_iter_type(I) iter_type;
00070 };
00071
00072
00079 template <class SrcType, class Exact>
00080 struct image_traits <morpher::color_morpher<SrcType, Exact> > :
00081 public image_traits<morpher::abstract::generic_morpher<SrcType,
00082 typename image_id<morpher::color_morpher<SrcType, Exact> >::exact_type> >
00083 {
00084
00085 };
00086
00087 namespace morpher {
00088
00096 template <class SrcType, class Exact>
00097 class super_color_morpher :
00098 public abstract::generic_morpher<SrcType, Exact>
00099 {
00100 protected:
00101
00108 unsigned n_;
00109
00116 super_color_morpher(const SrcType &ima, unsigned n) : super_type(ima)
00117 {
00118 assert(n == ntg::rgb_R || n == ntg::rgb_G || n == ntg::rgb_B);
00119 n_ = n;
00120 }
00121
00126 super_color_morpher()
00127 {}
00128
00129 public:
00130 typedef abstract::generic_morpher<SrcType, Exact> super_type;
00131 typedef typename image_id<Exact>::impl_type impl_type;
00132
00134 unsigned
00135 get_comp() const
00136 {
00137 return n_;
00138 }
00139
00141 impl_type*
00142 impl()
00143 {
00144 return ima_.impl();
00145 }
00146
00148 const impl_type*
00149 impl() const
00150 {
00151 return ima_.impl();
00152 }
00153
00154
00155
00156 static std::string
00157 name()
00158 {
00159 return "super_color_morpher<" + super_type::name() + ">";
00160 }
00161
00162
00163 };
00164
00176 template <class SrcType, class Exact>
00177 struct color_morpher :
00178 public super_color_morpher<SrcType,
00179 typename image_id<color_morpher<SrcType, Exact> >::exact_type>
00180 {
00182 typedef typename image_id<color_morpher<SrcType, Exact> >::exact_type exact_type;
00183
00184
00185 typedef color_morpher<SrcType, Exact> self_type;
00186 typedef typename image_id<exact_type>::iter_type iter_type;
00188 typedef typename image_id<exact_type>::point_type point_type;
00190 typedef typename image_id<exact_type>::value_type value_type;
00192 typedef super_color_morpher<SrcType, exact_type> super_type;
00195
00196 color_morpher(const SrcType &ima, unsigned n) : super_type(ima, n)
00197 {}
00198
00200 color_morpher(const color_morpher<SrcType, Exact>& r) : super_type(r.get_ima(), r.get_comp())
00201 {}
00202
00207 color_morpher()
00208 {}
00209
00216 value_type&
00217 at(const point_type& p)
00218 {
00219 return const_cast<SrcType &>(this->ima_)[p][this->n_];
00220 }
00221
00227 const value_type
00228 at(const point_type& p) const
00229 {
00230 return this->ima_[p][this->n_];
00231 }
00232
00237 self_type&
00238 assign(self_type& rhs)
00239 {
00240 oln_iter_type(SrcType) it(rhs);
00241
00242 for_all(it)
00243 this->at(it) = rhs[it];
00244 return this->exact();
00245 }
00246
00247 static std::string
00248 name()
00249 {
00250 return "color_morpher<" + SrcType::name() + "," + Exact::name() + ">";
00251 }
00252
00253 };
00254
00263 template <class SrcType, class Exact>
00264 struct color_morpher<const SrcType, Exact> :
00265 public super_color_morpher<const SrcType,
00266 typename image_id<color_morpher<const SrcType,
00267 Exact> >::exact_type>
00268 {
00270 typedef typename image_id<color_morpher<const SrcType, Exact> >::exact_type exact_type;
00271
00272 typedef typename image_id<exact_type>::point_type point_type;
00274 typedef typename image_id<exact_type>::iter_type iter_type;
00276 typedef typename image_id<exact_type>::value_type value_type;
00279 typedef super_color_morpher<const SrcType, exact_type> super_type;
00282
00283 color_morpher(const SrcType &ima, unsigned n) : super_type(ima, n)
00284 {}
00285
00287 color_morpher(const color_morpher<const SrcType, Exact>& r) :
00288 super_type(r.get_ima(), r.get_comp())
00289 {}
00290
00295 color_morpher()
00296 {}
00297
00303 const value_type
00304 at(const point_type& p) const
00305 {
00306 return this->ima_[p][this->n_];
00307 }
00308
00309 static std::string
00310 name()
00311 {
00312 return "color_morpher<" + SrcType::name() + ">";
00313 }
00314
00315 };
00316
00317
00340 template <class I>
00341 const color_morpher<I> rmorph(I &ima)
00342 {
00343 return color_morpher<I>(ima, ntg::rgb_R);
00344 }
00345
00368 template <class I>
00369 const color_morpher<I> gmorph(I &ima)
00370 {
00371 return color_morpher<I>(ima, ntg::rgb_G);
00372 }
00373
00396 template <class I>
00397 const color_morpher<I> bmorph(I &ima)
00398 {
00399 return color_morpher<I>(ima, ntg::rgb_B);
00400 }
00401
00402 }
00403
00404 }
00405
00406 #endif // !OLENA_MORPHER_COLOR_MORPHER_HH