27 #ifndef MLN_DATA_MEMCPY__HH
28 # define MLN_DATA_MEMCPY__HH
37 # include <mln/core/concept/image.hh>
38 # include <mln/core/pixel.hh>
39 # include <mln/metal/is_not_const.hh>
40 # include <mln/opt/element.hh>
65 template <
typename Pd,
typename Ps>
66 void memcpy_(Generalized_Pixel<Pd>& dest,
const Generalized_Pixel<Ps>& src,
70 # ifndef MLN_INCLUDE_ONLY
75 template <
typename Pd,
typename Ps>
77 void memcpy__(Pd& dest,
const Ps& src, std::size_t n)
81 typedef mln_image(Pd) Id;
82 typedef mln_image(Ps) Is;
88 dest.val() = src.val();
103 if (
sizeof(mln_value(Id)) == 1)
105 std::memcpy((
void*) (&dest.val()),
106 (
const void*) (&src.val()),
111 mln_value(Id)* p_d = &dest.val();
112 const mln_value(Is)* p_s = &src.val();
113 for (std::size_t i = 0; i < n; ++i)
121 template <
typename Pd,
typename Ps>
123 void memcpy_(Generalized_Pixel<Pd>& dest_,
124 const Generalized_Pixel<Ps>& src_,
129 typedef mln_image(Pd) Id;
130 metal::is_not_const<Id>::check();
131 typedef mln_image(Ps) Is;
132 Pd& dest = mln::internal::force_exact<Pd>(dest_);
133 Ps& src = mln::internal::force_exact<Ps>(src_);
135 mln_precondition(sizeof(mln_value(Id)) == sizeof(mln_value(Is)));
136 mln_precondition(dest.ima().is_valid());
137 mln_precondition(src.ima().is_valid());
139 mln_precondition(&dest.val() >= &opt::element(dest.ima(), 0));
140 mln_precondition(&dest.val() < &opt::element(dest.ima(), 0) +
141 opt::nelements(dest.ima()));
143 mln_precondition(&dest.val() + n <= &opt::element(dest.ima(), 0) +
144 opt::nelements(dest.ima()));
146 mln_precondition(&src.val() >= &opt::element(src.ima(), 0));
147 mln_precondition(&src.val() < &opt::element(src.ima(), 0) +
148 opt::nelements(src.ima()));
149 mln_precondition(&src.val() + n <= &opt::element(src.ima(), 0) +
150 opt::nelements(src.ima()));
152 impl::memcpy__(dest, src, n);
156 # endif // ! MLN_INCLUDE_ONLY
163 #endif // ! MLN_DATA_MEMCPY__HH