27 #ifndef MLN_BORDER_FILL_HH
28 # define MLN_BORDER_FILL_HH
37 # include <mln/core/concept/image.hh>
38 # include <mln/core/box_runstart_piter.hh>
39 # include <mln/opt/element.hh>
59 void fill(
const Image<I>& ima,
const mln_value(I)& v);
62 # ifndef MLN_INCLUDE_ONLY
70 void fill_tests(
const Image<I>& ima,
const mln_value(I)&)
72 mln_precondition(exact(ima).is_valid());
84 void fill_size_1(
const Image<I>& ima_,
const mln_value(I)& v)
86 trace::entering(
"border::impl::fill_size_1");
88 const I& ima = exact(ima_);
89 internal::fill_tests(ima, v);
91 typedef mln_psite(I) P;
92 typedef mln_psite(I) P;
93 mln_box_runstart_piter(I) pl(ima.domain());
95 unsigned len_r = pl.run_length();
100 unsigned end = ima.index_of_point (pl);
102 std::memset((
void*)&opt::element(ima, st),
107 if (st < opt::nelements(ima))
108 std::memset((
void*)&opt::element(ima, st),
110 opt::nelements(ima) - st);
112 trace::exiting(
"border::impl::fill_size_1");
116 template <
typename I>
118 void fill_size_n(
const I& ima_,
const mln_value(I)& v)
120 trace::entering(
"border::impl::fill_size_n");
122 I& ima =
const_cast<I&
>( exact(ima_) );
123 internal::fill_tests(ima, v);
125 typedef mln_psite(I) P;
126 mln_box_runstart_piter(I) pl(ima.domain());
127 unsigned len_r = pl.run_length();
132 unsigned end = ima.index_of_point (pl);
133 for (
unsigned i = st; i < end; ++i)
134 opt::element(ima, i) = v;
137 for (
unsigned i = st; i < opt::nelements(ima); ++i)
138 opt::element(ima, i) = v;
140 trace::exiting(
"border::impl::fill_size_n");
152 template <
typename I>
154 void fill_dispatch(
const Image<I>& ima,
const mln_value(I)& v);
156 template <
typename I>
158 void fill_dispatch(mln::trait::image::category::primary,
159 mln::trait::image::speed::fastest,
160 I& ima,
const mln_value(I)& v)
162 if (
sizeof(mln_value(I)) == 1)
163 impl::fill_size_1(ima, v);
165 impl::fill_size_n(ima, v);
168 template <
typename I>
170 void fill_dispatch(mln::trait::image::category::primary,
171 mln::trait::image::speed::any,
172 I& ,
const mln_value(I)& )
177 template <
typename I>
179 void fill_dispatch(mln::trait::image::category::morpher,
180 mln::trait::image::speed::any,
181 I& ima,
const mln_value(I)& v)
183 fill_dispatch(ima.unmorph_(), v);
186 template <
typename I>
188 void fill_dispatch(
const Image<I>& ima_,
const mln_value(I)& v)
190 I& ima =
const_cast<I&
>(exact(ima_));
191 fill_dispatch(mln_trait_image_category(I)(),
192 mln_trait_image_speed(I)(),
202 template <
typename I>
206 trace::entering(
"border::fill");
208 internal::fill_tests(ima, v);
209 internal::fill_dispatch(ima, v);
211 trace::exiting(
"border::fill");
215 # endif // ! MLN_INCLUDE_ONLY
222 #endif // ! MLN_BORDER_FILL_HH