diff --git a/.gitignore b/.gitignore index 8282d28986..f16ee331e4 100644 --- a/.gitignore +++ b/.gitignore @@ -15,6 +15,7 @@ doc/warnings.txt /.vs .vscode *.code-workspace +out # Clang/LLVM /.clang-format diff --git a/include/boost/gil/image.hpp b/include/boost/gil/image.hpp index d91a7908b6..c3cc6818b7 100644 --- a/include/boost/gil/image.hpp +++ b/include/boost/gil/image.hpp @@ -110,6 +110,16 @@ class image allocate_and_copy(img.dimensions(),img._view); } + template ::value, int>::type = 0> + image(const image_view& view, + std::size_t alignment = 0, + const Alloc alloc_in = Alloc()) : _memory(nullptr), _align_in_bytes(alignment), _alloc(alloc_in) + , _allocated_bytes( 0 ) + { + allocate_and_copy(view.dimensions(),view); + } + // TODO Optimization: use noexcept (requires _view to be nothrow copy constructible) image(image&& img) : _view(img._view), diff --git a/test/core/image/image.cpp b/test/core/image/image.cpp index 0010359984..52d7bd7034 100644 --- a/test/core/image/image.cpp +++ b/test/core/image/image.cpp @@ -72,6 +72,31 @@ struct test_constructor_from_other_image } }; +struct test_constructor_from_view +{ + template + void operator()(Image const&) + { + using image_t = Image; + gil::point_t const dimensions{ 256, 128 }; + using pixel_t = typename image_t::view_t::value_type; + pixel_t const rnd_pixel = fixture::pixel_generator::random(); + { + //constructor interleaved from planar + gil::image image1(dimensions, rnd_pixel); + auto v1 = gil::transposed_view(gil::const_view(image1)); + image_t image2(gil::transposed_view(v1)); + BOOST_TEST_EQ(image2.dimensions(), dimensions); + auto v2 = gil::const_view(image2); + BOOST_TEST_ALL_EQ(v1.begin(), v1.end(), v2.begin(), v2.end()); + } + } + static void run() + { + boost::mp11::mp_for_each(test_constructor_from_view{}); + } +}; + struct test_move_constructor { template