Skip to content

Commit

Permalink
Fix any_image_view::const_t (#526)
Browse files Browse the repository at this point in the history
Use inherited constructors in any_image as well
  • Loading branch information
sdebionne authored Mar 18, 2021
1 parent 6da59cc commit b8564e2
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 28 deletions.
18 changes: 2 additions & 16 deletions include/boost/gil/extension/dynamic_image/any_image.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,29 +89,15 @@ template <typename ...Images>
class any_image : public variant2::variant<Images...>
{
using parent_t = variant2::variant<Images...>;

public:
using view_t = mp11::mp_rename<detail::images_get_views_t<any_image>, any_image_view>;
using const_view_t = mp11::mp_rename<detail::images_get_const_views_t<any_image>, any_image_view>;
using x_coord_t = std::ptrdiff_t;
using y_coord_t = std::ptrdiff_t;
using point_t = point<std::ptrdiff_t>;

any_image() = default;
any_image(any_image const& img) : parent_t((parent_t const&)img) {}

template <typename Image>
explicit any_image(Image const& img) : parent_t(img) {}

template <typename Image>
any_image(Image&& img) : parent_t(std::move(img)) {}

template <typename Image>
explicit any_image(Image& img, bool do_swap) : parent_t(img, do_swap) {}

template <typename ...OtherImages>
any_image(any_image<OtherImages...> const& img)
: parent_t((variant2::variant<OtherImages...> const&)img)
{}
using parent_t::parent_t;

any_image& operator=(any_image const& img)
{
Expand Down
16 changes: 4 additions & 12 deletions include/boost/gil/extension/dynamic_image/any_image_view.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//
// Copyright 2005-2007 Adobe Systems Incorporated
// Copyright 2020 Samuel Debionne
//
// Distributed under the Boost Software License, Version 1.0
// See accompanying file LICENSE_1_0.txt or copy at
Expand All @@ -24,10 +25,10 @@ struct dynamic_xy_step_transposed_type;
namespace detail {

template <typename View>
struct get_const_t { using type = typename View::const_t; };
using get_const_t = typename View::const_t;

template <typename Views>
struct views_get_const_t : mp11::mp_transform<get_const_t, Views> {};
using views_get_const_t = mp11::mp_transform<get_const_t, Views>;

// works for both image_view and image
struct any_type_get_num_channels
Expand Down Expand Up @@ -82,16 +83,7 @@ class any_image_view : public variant2::variant<Views...>
using point_t = point<std::ptrdiff_t>;
using size_type = std::size_t;

any_image_view() = default;
any_image_view(any_image_view const& view) : parent_t((parent_t const&)view) {}

template <typename View>
explicit any_image_view(View const& view) : parent_t(view) {}

template <typename ...OtherViews>
any_image_view(any_image_view<OtherViews...> const& view)
: parent_t((variant2::variant<OtherViews...> const&)view)
{}
using parent_t::parent_t;

any_image_view& operator=(any_image_view const& view)
{
Expand Down
1 change: 1 addition & 0 deletions test/extension/dynamic_image/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
message(STATUS "Boost.GIL: Configuring tests in test/extension/dynamic_image")
foreach(_name
any_image
any_image_view
subimage_view)
set(_test t_ext_dynamic_image_${_name})
set(_target test_ext_dynamic_image_${_name})
Expand Down
1 change: 1 addition & 0 deletions test/extension/dynamic_image/Jamfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ import testing ;
alias headers : [ generate_self_contained_headers extension/dynamic_image ] ;

run any_image.cpp ;
run any_image_view.cpp ;
run subimage_view.cpp ;
128 changes: 128 additions & 0 deletions test/extension/dynamic_image/any_image_view.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
//
// Copyright 2020 Samuel Debionne
//
// Distributed under the Boost Software License, Version 1.0
// See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt
//
#include <boost/gil.hpp>
#include <boost/gil/extension/dynamic_image/any_image_view.hpp>

#include <boost/core/lightweight_test.hpp>
#include <boost/core/lightweight_test_trait.hpp>

#include <type_traits>

#include "test_fixture.hpp"
#include "core/image/test_fixture.hpp"

namespace gil = boost::gil;
namespace fixture = boost::gil::test::fixture;

void test_any_image_view_nested_types()
{
BOOST_TEST_TRAIT_SAME(gil::any_image_view<gil::gray8_view_t>::const_t, gil::any_image_view<gil::gray8c_view_t>);
}


struct test_any_image_view_init_ctor
{
template <typename Image>
void operator()(Image const&)
{
using image_t = Image;
using view_t = typename Image::view_t;
using any_view_t = gil::any_image_view<view_t>;
using any_const_view_t = typename any_view_t::const_t;
Image i0(fixture::create_image<image_t>(4, 4, 128));

view_t v0 = gil::view(i0);
any_view_t v1 = v0;

BOOST_TEST_EQ(v1.dimensions().x, 4);
BOOST_TEST_EQ(v1.dimensions().y, 4);

any_const_view_t v2 = v0;

BOOST_TEST_EQ(v2.dimensions().x, 4);
BOOST_TEST_EQ(v2.dimensions().y, 4);

//any_const_view_t v3 = v1;
}
static void run()
{
boost::mp11::mp_for_each<fixture::image_types>(test_any_image_view_init_ctor{});
}
};

struct test_any_image_view_copy_ctor
{
template <typename Image>
void operator()(Image const&)
{
using image_t = Image;
using view_t = typename Image::view_t;
using any_view_t = gil::any_image_view<view_t>;
using any_const_view_t = typename any_view_t::const_t;
Image i0(fixture::create_image<image_t>(4, 4, 128));

view_t v0 = gil::view(i0);
any_view_t v1 = v0;

BOOST_TEST_EQ(v1.dimensions().x, 4);
BOOST_TEST_EQ(v1.dimensions().y, 4);

any_const_view_t v2 = v0;

BOOST_TEST_EQ(v2.dimensions().x, 4);
BOOST_TEST_EQ(v2.dimensions().y, 4);

//any_const_view_t v3 = v1;
}
static void run()
{
boost::mp11::mp_for_each<fixture::image_types>(test_any_image_view_copy_ctor{});
}
};

struct test_any_image_view_assign_operator
{
template <typename Image>
void operator()(Image const&)
{
using image_t = Image;
using view_t = typename Image::view_t;
using any_view_t = gil::any_image_view<view_t>;
using any_const_view_t = typename any_view_t::const_t;
Image i0(fixture::create_image<image_t>(4, 4, 128));

view_t v0 = gil::view(i0);
any_view_t v1;
any_const_view_t v2;

v1 = v0;

BOOST_TEST_EQ(v1.dimensions().x, 4);
BOOST_TEST_EQ(v1.dimensions().y, 4);

v2 = v0;

BOOST_TEST_EQ(v2.dimensions().x, 4);
BOOST_TEST_EQ(v2.dimensions().y, 4);

//v2 = v1;
}
static void run()
{
boost::mp11::mp_for_each<fixture::image_types>(test_any_image_view_assign_operator{});
}
};

int main()
{
test_any_image_view_init_ctor::run();
test_any_image_view_copy_ctor::run();
test_any_image_view_assign_operator::run();

return ::boost::report_errors();
}

0 comments on commit b8564e2

Please sign in to comment.