diff --git a/test/core/image/CMakeLists.txt b/test/core/image/CMakeLists.txt index 6574cf275..32c72f572 100644 --- a/test/core/image/CMakeLists.txt +++ b/test/core/image/CMakeLists.txt @@ -7,6 +7,7 @@ # foreach(_name concepts + alignment image) set(_test t_core_image_${_name}) set(_target test_core_image_${_name}) diff --git a/test/core/image/Jamfile b/test/core/image/Jamfile index 07da63467..9ab5bc05d 100644 --- a/test/core/image/Jamfile +++ b/test/core/image/Jamfile @@ -11,3 +11,4 @@ import testing ; compile concepts.cpp ; run image.cpp ; +run alignment.cpp ; diff --git a/test/core/image/alignment.cpp b/test/core/image/alignment.cpp new file mode 100644 index 000000000..1ddf9b977 --- /dev/null +++ b/test/core/image/alignment.cpp @@ -0,0 +1,125 @@ +// +// Copyright 2022 Mateusz Loskot +// +// 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 + +#include + +#include "test_fixture.hpp" +#include "core/pixel/test_fixture.hpp" + +namespace gil = boost::gil; +namespace fixture = boost::gil::test::fixture; + +struct test_constructor_with_alignment +{ + template + void operator()(Image const&) + { + std::size_t alignment = 0; + Image image(alignment); + BOOST_TEST(image.width() == 0); + BOOST_TEST(image.height() == 0); + } + + static void run() + { + boost::mp11::mp_for_each(test_constructor_with_alignment{}); + } +}; + +struct test_constructor_with_alignment_allocator +{ + template + void operator()(Image const&) + { + std::size_t alignment = 0; + std::allocator allocator; + Image image(alignment, allocator); + BOOST_TEST(image.width() == 0); + BOOST_TEST(image.height() == 0); + } + + static void run() + { + boost::mp11::mp_for_each(test_constructor_with_alignment_allocator{}); + } +}; + +struct test_constructor_with_dimensions_alignment +{ + template + void operator()(Image const&) + { + gil::point_t const dimensions{256, 128}; + std::size_t alignment = 0; + Image image(dimensions, alignment); + BOOST_TEST(image.width() == dimensions.x); + BOOST_TEST(image.height() == dimensions.y); + } + + static void run() + { + boost::mp11::mp_for_each(test_constructor_with_dimensions_alignment{}); + } +}; + +struct test_constructor_with_dimensions_alignment_allocator +{ + template + void operator()(Image const&) + { + gil::point_t const dimensions{256, 128}; + std::size_t alignment = 0; + std::allocator allocator; + Image image(dimensions, alignment, allocator); + BOOST_TEST(image.width() == dimensions.x); + BOOST_TEST(image.height() == dimensions.y); + } + + static void run() + { + boost::mp11::mp_for_each(test_constructor_with_dimensions_alignment_allocator{}); + } +}; + +struct test_constructor_with_dimensions_pixel_alignment +{ + template + void operator()(Image const &) + { + gil::point_t const dimensions{3, 3}; + using pixel_t = typename Image::view_t::value_type; + pixel_t const rnd_pixel = fixture::pixel_generator::random(); + + Image image(dimensions, rnd_pixel, 32u); + BOOST_TEST(image.width() == dimensions.x); + BOOST_TEST(image.height() == dimensions.y); + + for (pixel_t const& p : gil::view(image)) + { + BOOST_TEST(p == rnd_pixel); + } + } + + static void run() + { + boost::mp11::mp_for_each(test_constructor_with_dimensions_pixel_alignment{}); + } +}; + +int main() +{ + test_constructor_with_alignment::run(); + test_constructor_with_alignment_allocator::run(); + test_constructor_with_dimensions_alignment::run(); + test_constructor_with_dimensions_alignment_allocator::run(); + test_constructor_with_dimensions_pixel_alignment::run(); + test_constructor_with_dimensions_pixel_alignment::run(); + + return ::boost::report_errors(); +} diff --git a/test/core/image/image.cpp b/test/core/image/image.cpp index b2cca6868..5b60f31fd 100644 --- a/test/core/image/image.cpp +++ b/test/core/image/image.cpp @@ -142,6 +142,7 @@ struct test_move_assignement BOOST_TEST_EQ(image.dimensions(), gil::point_t{}); } } + static void run() { boost::mp11::mp_for_each(test_move_assignement{}); diff --git a/test/core/image/test_fixture.hpp b/test/core/image/test_fixture.hpp index 8b149cd63..056ebfc0d 100644 --- a/test/core/image/test_fixture.hpp +++ b/test/core/image/test_fixture.hpp @@ -9,7 +9,6 @@ #define BOOST_GIL_TEST_CORE_IMAGE_TEST_FIXTURE_HPP #include -#include #include #include @@ -18,8 +17,6 @@ #include #include -#include "core/test_fixture.hpp" - namespace boost { namespace gil { namespace test { namespace fixture { using image_types = std::tuple @@ -51,6 +48,16 @@ using rgb_interleaved_image_types = std::tuple gil::rgba32_image_t >; +using bit_aligned_image_types = std::tuple +< + gil::bit_aligned_image1_type<1, gil::gray_layout_t>::type, + gil::bit_aligned_image1_type<3, gil::gray_layout_t>::type, + gil::bit_aligned_image1_type<8, gil::gray_layout_t>::type, + gil::bit_aligned_image3_type<2, 2, 2, gil::rgb_layout_t>::type, + gil::bit_aligned_image3_type<5, 6, 5, gil::rgb_layout_t>::type, + gil::bit_aligned_image3_type<6, 6, 6, gil::rgb_layout_t>::type +>; + template auto generate_image(std::ptrdiff_t size_x, std::ptrdiff_t size_y, Generator&& generate) -> Image {