cleanup-2008 2823: Add fill_with_image_line specialization in fill_with_image routine.

https://svn.lrde.epita.fr/svn/oln/branches/cleanup-2008/milena Index: ChangeLog from Nicolas Ballas <ballas@lrde.epita.fr> Add fill_with_image_line specialization in fill_with_image routine. * tests/level/fill_with_image.cc: Add a new test. * mln/level/paste.spe.hh: Add tests in paste_line. * mln/level/fill_with_value.spe.hh: Update documentation. * mln/level/fill_with_image.spe.hh: Add fill_with_image_line. mln/level/fill_with_image.spe.hh | 49 +++++++++++++++++++++++++++++++-------- mln/level/fill_with_value.spe.hh | 1 mln/level/paste.spe.hh | 4 +-- tests/level/fill_with_image.cc | 15 +++++++++++ 4 files changed, 57 insertions(+), 12 deletions(-) Index: tests/level/fill_with_image.cc --- tests/level/fill_with_image.cc (revision 2822) +++ tests/level/fill_with_image.cc (working copy) @@ -57,6 +57,21 @@ using namespace mln; const unsigned size = 100; + // tests in two dimension + { + box2d b(point2d(1,2), point2d(2,4)); + image2d<int> ima(b, 2); + debug::iota(ima); + + box2d b2(point2d(-1,-2), point2d(3,6)); + image2d<int> ima2(b2, 0); + debug::iota(ima2); + + level::fill_with_image(ima, ima2); // Not so fast version... + mln_assertion(ima == (ima2 | b)); + } + + // 2d tests { image2d<unsigned int> ima(size, size); Index: mln/level/paste.spe.hh --- mln/level/paste.spe.hh (revision 2822) +++ mln/level/paste.spe.hh (working copy) @@ -32,7 +32,6 @@ * * \brief Specializations for mln::level::paste. * - * \todo Rewrite the dispatch!!! */ # ifndef MLN_LEVEL_PASTE_HH @@ -43,7 +42,7 @@ # include <mln/level/fill_with_value.hh> # include <mln/level/memcpy_.hh> # include <mln/core/box_runstart_piter.hh> -# include <mln/border/all.hh> +# include <mln/border/get.hh> @@ -125,6 +124,7 @@ const I& input = exact(input_); J& output = exact(output_); + level::internal::paste_tests(input, output); mln_box_runstart_piter(I) p(input.domain()); for_all(p) Index: mln/level/fill_with_value.spe.hh --- mln/level/fill_with_value.spe.hh (revision 2822) +++ mln/level/fill_with_value.spe.hh (working copy) @@ -31,7 +31,6 @@ /// \file mln/level/fill_with_value.spe.hh /// Specializations for mln::level::fill_with_value. /// -/// \todo See todos in mln/level/fill.hh # ifndef MLN_LEVEL_FILL_WITH_VALUE_HH # error "Forbidden inclusion of *.spe.hh" Index: mln/level/fill_with_image.spe.hh --- mln/level/fill_with_image.spe.hh (revision 2822) +++ mln/level/fill_with_image.spe.hh (working copy) @@ -32,7 +32,6 @@ * * \brief Specializations for mln::level::fill_with_image. * - * \todo Add specializations then rewrite the dispatch. */ # ifndef MLN_LEVEL_FILL_WITH_IMAGE_HH @@ -41,9 +40,9 @@ # include <mln/level/memcpy_.hh> # include <mln/level/fill_with_value.hh> - # include <mln/core/pixel.hh> - +# include <mln/core/box_runstart_piter.hh> +# include <mln/border/get.hh> # ifndef MLN_INCLUDE_ONLY @@ -116,6 +115,26 @@ trace::exiting("level::impl::fill_with_image_fast"); } + template <typename I, typename J> + inline + void fill_with_image_lines(Image<I>& ima_, const Image<J>& data_) + { + trace::entering("level::impl::fill_with_image_lines"); + + I& ima = exact(ima_); + const J& data = exact(data_); + + level::internal::fill_with_image_tests(ima, data); + + mln_box_runstart_piter(I) p(ima.domain()); + for_all(p) + { + pixel<J> dst(ima, p); + memcpy_(dst, make::pixel(data, p), p.run_length()); + } + + trace::exiting("level::impl::fill_with_image_lines"); + } template <typename I, typename J> void fill_with_image_singleton(Image<I>& ima_, @@ -149,10 +168,15 @@ I& ima = exact(ima_); const J& data = exact(data_); - if (ima.border() == data.border() && - sizeof(mln_value(I)) == sizeof(mln_value(J))) + if (sizeof(mln_value(I)) == sizeof(mln_value(J))) + { + if (border::get(ima) == border::get(data) && + ima.domain() == data.domain()) impl::fill_with_image_fastest(ima, data); else + impl::fill_with_image_lines(ima, data); + } + else impl::fill_with_image_fast(ima, data); } @@ -162,12 +186,20 @@ mln::trait::image::value_access::direct, mln::trait::image::ext_domain::none, mln::trait::image::ext_domain::none, - Image<I>& ima, - const Image<J>& data) + Image<I>& ima_, + const Image<J>& data_) { + I& ima = exact(ima_); + const J& data = exact(data_); + if (sizeof(mln_value(I)) == sizeof(mln_value(J))) + { + if (ima.domain() == data.domain()) impl::fill_with_image_fastest(ima, data); else + impl::fill_with_image_lines(ima, data); + } + else impl::fill_with_image_fast(ima, data); } @@ -219,8 +251,7 @@ if (mlc_is(mln_trait_image_value_alignement(I), trait::image::value_alignement::with_grid)::value && mlc_is(mln_trait_image_value_alignement(J), - trait::image::value_alignement::with_grid)::value && - ima.domain() == data.domain()) + trait::image::value_alignement::with_grid)::value) { fill_with_image_(mln_trait_image_value_access(I)(), mln_trait_image_value_access(J)(),
participants (1)
-
Nicolas Ballas