From d3c1a2eff43540e1973977fcf524e47a4d92b1a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20=C5=81oskot?= Date: Wed, 13 Mar 2019 19:15:33 +0100 Subject: [PATCH] Add test for some bit-aligned pixel types and metafunctions (#257) Test bit_aligned_pixel_reference and packed_pixel as well as some of related metafunctions generating types of their members and intermediate specializations. --- test/pixel/CMakeLists.txt | 2 + test/pixel/Jamfile | 2 + test/pixel/bit_aligned_pixel_reference.cpp | 46 +++++++++ test/pixel/is_pixel.cpp | 24 ++++- test/pixel/packed_pixel.cpp | 107 +++++++++++++++++++++ 5 files changed, 179 insertions(+), 2 deletions(-) create mode 100644 test/pixel/bit_aligned_pixel_reference.cpp create mode 100644 test/pixel/packed_pixel.cpp diff --git a/test/pixel/CMakeLists.txt b/test/pixel/CMakeLists.txt index 8333eefdb..a34ee1577 100644 --- a/test/pixel/CMakeLists.txt +++ b/test/pixel/CMakeLists.txt @@ -7,9 +7,11 @@ # foreach(_name concepts + bit_aligned_pixel_reference is_pixel is_planar num_channels + packed_pixel pixel_reference_is_mutable pixels_are_compatible test_fixture) diff --git a/test/pixel/Jamfile b/test/pixel/Jamfile index 90d51a6e6..9bf6cf311 100644 --- a/test/pixel/Jamfile +++ b/test/pixel/Jamfile @@ -13,10 +13,12 @@ project .. ; +compile bit_aligned_pixel_reference.cpp ; compile concepts.cpp ; compile is_pixel.cpp ; compile is_planar.cpp ; compile num_channels.cpp ; +compile packed_pixel.cpp ; compile pixel_reference_is_mutable.cpp ; compile pixels_are_compatible.cpp ; diff --git a/test/pixel/bit_aligned_pixel_reference.cpp b/test/pixel/bit_aligned_pixel_reference.cpp new file mode 100644 index 000000000..047572211 --- /dev/null +++ b/test/pixel/bit_aligned_pixel_reference.cpp @@ -0,0 +1,46 @@ +// +// Copyright 2019 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 +#include +namespace gil = boost::gil; +namespace mpl = boost::mpl; + +int main() +{ + using bgr121_ref_t = gil::bit_aligned_pixel_reference + < + std::uint8_t, mpl::vector3_c, gil::bgr_layout_t, true + >; + + static_assert(bgr121_ref_t::bit_size == 4, + "bit size should be 4"); + + static_assert(std::is_same::value, + "bit field type should be std::uint8_t"); + + static_assert(std::is_same::value, + "layout type should be bgr"); + + static_assert(std::is_same::value && + bgr121_ref_t::is_mutable, + "is_mutable should be boolean"); + + using packed_pixel_t = gil::packed_pixel + < + std::uint8_t, + typename gil::detail::packed_channel_references_vector_type + < + std::uint8_t, mpl::vector3_c + >::type, + gil::bgr_layout_t + >; + static_assert(std::is_same::value, + "value_type should be specialization of packed_pixel"); +} diff --git a/test/pixel/is_pixel.cpp b/test/pixel/is_pixel.cpp index 28d7a775d..6a986d58c 100644 --- a/test/pixel/is_pixel.cpp +++ b/test/pixel/is_pixel.cpp @@ -5,9 +5,12 @@ // See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt // +#include +#include #include -#include +#include #include +#include #include @@ -40,7 +43,6 @@ int main() >::value, "is_pixel does not yield true for representative pixel types"); - static_assert(std::is_same < mp_all_of, @@ -54,4 +56,22 @@ int main() std::true_type >::value, "is_pixel yields true for non-pixel type"); + + using bgr121_ref_t = gil::bit_aligned_pixel_reference + < + std::uint8_t, boost::mpl::vector3_c, gil::bgr_layout_t, true + >; + static_assert(gil::is_pixel::value, + "is_pixel does not yield true for bit_aligned_pixel_reference"); + + using rgb121_ref_t = gil::bit_aligned_pixel_reference + < + std::uint8_t, boost::mpl::vector3_c, gil::rgb_layout_t, true + >; + static_assert(gil::is_pixel::value, + "is_pixel does not yield true for bit_aligned_pixel_reference"); + + using rgb121_packed_pixel_t = rgb121_ref_t::value_type; + static_assert(gil::is_pixel::value, + "is_pixel does not yield true for packed_pixel"); } diff --git a/test/pixel/packed_pixel.cpp b/test/pixel/packed_pixel.cpp new file mode 100644 index 000000000..f94cd2068 --- /dev/null +++ b/test/pixel/packed_pixel.cpp @@ -0,0 +1,107 @@ +// +// Copyright 2019 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 +#include +#include +#include +#include +namespace gil = boost::gil; +namespace mpl = boost::mpl; + +int main() +{ + using packed_channel_references_vector = + typename gil::detail::packed_channel_references_vector_type + < + std::uint8_t, + mpl::vector3_c + >::type; + + using packed_pixel = gil::packed_pixel + < + std::uint8_t, + packed_channel_references_vector, + gil::bgr_layout_t + >; + + // Verify packed_pixel members + + static_assert(std::is_same::value, + "layout should be bgr"); + + static_assert(std::is_same::value, + "value_type member should be of the same type as the packed_pixel specialization"); + + static_assert(std::is_reference::value, + "reference member should be a reference"); + + static_assert(std::is_reference::value, + "const_reference member should be a reference"); + + static_assert(std::is_same::value && + packed_pixel::is_mutable, + "is_mutable should be boolean"); + + // Verify metafunctions + + using channel_references_t = packed_channel_references_vector::type; + + static_assert(mpl::size::value == 3, + "packed_channel_references_vector_type should define three references to channel start bits"); + + using channel1_ref_t = mpl::at_c::type; + static_assert(channel1_ref_t::num_bits == 1, + "1st channel of bgr121 pixel should be of 1-bit size"); + + using channel2_ref_t = mpl::at_c::type; + static_assert(channel2_ref_t::num_bits == 2, + "2nd channel of bgr121 pixel should be of 2-bit size"); + + using channel3_ref_t = mpl::at_c::type; + static_assert(channel3_ref_t::num_bits == 1, + "3rd channel of bgr121 pixel should be of 1-bit size"); + + static_assert(std::is_same + < + channel1_ref_t, + gil::packed_channel_reference const + >::value, + "1st element of packed_channel_references_vector should be packed_channel_reference of 1st channel"); + + static_assert(std::is_same + < + channel2_ref_t, + gil::packed_channel_reference const + >::value, + "2nd element of packed_channel_references_vector should be packed_channel_reference of 2nd channel"); + + static_assert(std::is_same + < + channel3_ref_t, + gil::packed_channel_reference const + >::value, + "3rd element of packed_channel_references_vector should be packed_channel_reference of 3rd channel"); + + // double check intermediate metafunction packed_channel_reference_type + static_assert(std::is_same + < + gil::detail::packed_channel_reference_type, mpl::int_<1>>::type, + channel1_ref_t + >::value, + "packed_channel_reference_type should return packed_channel_reference"); + static_assert(std::is_same + < + gil::detail::packed_channel_reference_type, mpl::int_<1>>::type, + gil::packed_channel_reference const + >::value, + "packed_channel_reference_type should return packed_channel_reference"); + + return 0; +}