diff --git a/include/boost/gil/extension/toolbox/metafunctions.hpp b/include/boost/gil/extension/toolbox/metafunctions.hpp index 16d7ee0184..9fc1bce0ef 100644 --- a/include/boost/gil/extension/toolbox/metafunctions.hpp +++ b/include/boost/gil/extension/toolbox/metafunctions.hpp @@ -8,6 +8,7 @@ #ifndef BOOST_GIL_EXTENSION_TOOLBOX_METAFUNCTIONS_HPP #define BOOST_GIL_EXTENSION_TOOLBOX_METAFUNCTIONS_HPP +#include <boost/gil/extension/toolbox/metafunctions/aligned.hpp> #include <boost/gil/extension/toolbox/metafunctions/channel_type.hpp> #include <boost/gil/extension/toolbox/metafunctions/channel_view.hpp> #include <boost/gil/extension/toolbox/metafunctions/get_num_bits.hpp> diff --git a/include/boost/gil/extension/toolbox/metafunctions/aligned.hpp b/include/boost/gil/extension/toolbox/metafunctions/aligned.hpp new file mode 100644 index 0000000000..49a691ac0c --- /dev/null +++ b/include/boost/gil/extension/toolbox/metafunctions/aligned.hpp @@ -0,0 +1,70 @@ +// Copyright Tom Brinkman 2008. 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) + +#ifndef BOOST_GIL_EXTENSION_TOOLBOX_METAFUNCTIONS_ALIGNED_HPP +#define BOOST_GIL_EXTENSION_TOOLBOX_METAFUNCTIONS_ALIGNED_HPP + +#include <boost/gil.hpp> + +namespace boost { namespace gil { + +/// \brief Aligns the image view passed through struct constructor in a specific direction +/// inside the image view passed through the overloaded '()' operator. The direction of +/// alignment is specified by constructor parameters. +template <typename View> +struct aligned +{ + // Following enum variables will be used for specifying alignment of view passed through + // constructor with respect to the view passed through overloaded '()' operator. + enum + { + left = 0x1 << 0, + center = 0x1 << 1, + right = 0x1 << 2, + top = 0x1 << 3, + middle = 0x1 << 5, + bottom = 0x1 << 7, + }; + + View original_view; + int align; + aligned(View temp_view, int temp_align = center | middle) + : original_view(temp_view) + , align(temp_align) + { + } + + void operator()(View view) + { + long int const original_view_width = original_view.width(); + long int const original_view_height = original_view.height(); + long int const view_width = view.width(), view_height = view.height(); + + // For ensuring that view passed through '()' operator has dimensions greater than or + // equal to the dimensions of view passed through constructor. + if (original_view_height > view_height || original_view_width > view_width) + { + throw std::length_error("Image view passed through overloaded '()' operator must have" + " dimensions greater than or equal to the dimensions of image view passed through" + " struct constructor"); + } + + std::ptrdiff_t x = 0; + if (align & center) + x = (view_width - original_view_width) / 2; + else if (align & right) + x = view_width - original_view_width; + + std::ptrdiff_t y = 0; + if (align & middle) + y = (view_height - original_view_height) / 2; + else if (align & bottom) + y = view_height - original_view_height; + + View temp_subimage_view = subimage_view(view, x, y, original_view_width, original_view_height); + copy_pixels(original_view, temp_subimage_view); + } +}; // aligned +}} // namespace boost::gil +#endif diff --git a/test/extension/toolbox/CMakeLists.txt b/test/extension/toolbox/CMakeLists.txt index 70df68db42..7b19c9334f 100644 --- a/test/extension/toolbox/CMakeLists.txt +++ b/test/extension/toolbox/CMakeLists.txt @@ -9,6 +9,7 @@ message(STATUS "Boost.GIL: Configuring tests in test/extension/toolbox") foreach(_name + aligned channel_type channel_view color_convert_cmyka diff --git a/test/extension/toolbox/Jamfile b/test/extension/toolbox/Jamfile index a2a78f7bed..133e936b42 100644 --- a/test/extension/toolbox/Jamfile +++ b/test/extension/toolbox/Jamfile @@ -17,6 +17,7 @@ compile is_bit_aligned.cpp ; compile is_homogeneous.cpp ; compile pixel_bit_size.cpp ; +run aligned.cpp ; run channel_view.cpp ; run color_convert_cmyka.cpp ; run color_convert_gray.cpp ; diff --git a/test/extension/toolbox/aligned.cpp b/test/extension/toolbox/aligned.cpp new file mode 100644 index 0000000000..4f78009e76 --- /dev/null +++ b/test/extension/toolbox/aligned.cpp @@ -0,0 +1,294 @@ +// +// Copyright 2021 Prathamesh Tagore <prathameshtagore@gmail.com> +// +// Use, modification and distribution are subject to 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) +// + +// Reference for test cases was taken from +// https://github.com/tuttleofx/TuttleOFX/blob/develop/libraries/boostHack/boost/gil/extension/toolbox/aligned.tests.cpp + +#include <boost/gil/extension/toolbox/metafunctions.hpp> +#include <boost/core/lightweight_test.hpp> +#include <vector> + +namespace gil = boost::gil; + +// This function helps us fill pixels of a rgb view given as 2nd argument with +// elements of the vector given as 1st argument. +void pixel_fill_rgb(std::vector<std::vector<std::vector<int>>>& vec, gil::rgb8_image_t& img) +{ + for (std::ptrdiff_t view_row = 0; view_row < view(img).height(); ++view_row) + { + for (std::ptrdiff_t view_col = 0; view_col < view(img).width(); ++view_col) + { + gil::view(img)(view_col, view_row) = gil::rgb8_pixel_t( + static_cast<unsigned char>(vec[view_row][view_col][0]), + static_cast<unsigned char>(vec[view_row][view_col][1]), + static_cast<unsigned char>(vec[view_row][view_col][2])); + } + } +} + +int main() +{ + std::vector<std::vector<std::vector<int>>> original_img_vector { + {{255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, + {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, + {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, + {255, 255, 255}}, + {{255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, + {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, + {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, + {255, 255, 255}}, + {{255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, + {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, + {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, + {255, 255, 255}}, + {{255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {191, 191, 191}, + {127, 127, 127}, { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, {127, 127, 127}, + {191, 191, 191}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, + {255, 255, 255}}, + {{255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {191, 191, 191}, { 0, 0, 0}, + { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, + { 0, 0, 0}, {191, 191, 191}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, + {255, 255, 255}}, + {{255, 255, 255}, {255, 255, 255}, {191, 191, 191}, { 0, 0, 0}, { 0, 0, 0}, + { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, + { 0, 0, 0}, { 0, 0, 0}, {191, 191, 191}, {255, 255, 255}, {255, 255, 255}, + {255, 255, 255}}, + {{255, 255, 255}, {255, 255, 255}, {127, 127, 127}, { 0, 0, 0}, { 0, 0, 0}, + { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, + { 0, 0, 0}, { 0, 0, 0}, {127, 127, 127}, {255, 255, 255}, {255, 255, 255}, + {255, 255, 255}}, + {{255, 255, 255}, {255, 255, 255}, { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, + { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, + { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, {255, 255, 255}, {255, 255, 255}, + {255, 255, 255}}, + {{255, 255, 255}, {255, 255, 255}, { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, + { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, + { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, {255, 255, 255}, {255, 255, 255}, + {255, 255, 255}}, + {{255, 255, 255}, {255, 255, 255}, { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, + { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, + { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, {255, 255, 255}, {255, 255, 255}, + {255, 255, 255}}, + {{255, 255, 255}, {255, 255, 255}, {127, 127, 127}, { 0, 0, 0}, { 0, 0, 0}, + { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, + { 0, 0, 0}, { 0, 0, 0}, {127, 127, 127}, {255, 255, 255}, {255, 255, 255}, + {255, 255, 255}}, + {{255, 255, 255}, {255, 255, 255}, {191, 191, 191}, { 0, 0, 0}, { 0, 0, 0}, + { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, + { 0, 0, 0}, { 0, 0, 0}, {191, 191, 191}, {255, 255, 255}, {255, 255, 255}, + {255, 255, 255}}, + {{255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {191, 191, 191}, { 0, 0, 0}, + { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, + { 0, 0, 0}, {191, 191, 191}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, + {255, 255, 255}}, + {{255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {191, 191, 191}, + {127, 127, 127}, { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, {127, 127, 127}, + {191, 191, 191}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, + {255, 255, 255}}, + {{255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, + {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, + {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, + {255, 255, 255}}, + {{255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, + {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, + {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, + {255, 255, 255}} +}; + + std::vector<std::vector<std::vector<int>>> expected_center_middle_vector { + {{255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, + {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, + {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, + {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}}, + {{255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, + {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, + {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, + {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}}, + {{255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, + {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, + {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, + {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}}, + {{255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, + {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, + {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, + {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}}, + {{255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, + {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, + {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, + {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}}, + {{255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, + {255, 255, 255}, {191, 191, 191}, {127, 127, 127}, { 0, 0, 0}, { 0, 0, 0}, + { 0, 0, 0}, {127, 127, 127}, {191, 191, 191}, {255, 255, 255}, {255, 255, 255}, + {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}}, + {{255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, + {191, 191, 191}, { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, + { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, {191, 191, 191}, {255, 255, 255}, + {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}}, + {{255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {191, 191, 191}, + { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, + { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, {191, 191, 191}, + {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}}, + {{255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {127, 127, 127}, + { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, + { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, {127, 127, 127}, + {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}}, + {{255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, { 0, 0, 0}, + { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, + { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, + {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}}, + {{255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, { 0, 0, 0}, + { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, + { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, + {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}}, + {{255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, { 0, 0, 0}, + { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, + { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, + {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}}, + {{255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {127, 127, 127}, + { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, + { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, {127, 127, 127}, + {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}}, + {{255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {191, 191, 191}, + { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, + { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, {191, 191, 191}, + {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}}, + {{255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, + {191, 191, 191}, { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, + { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, {191, 191, 191}, {255, 255, 255}, + {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}}, + {{255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, + {255, 255, 255}, {191, 191, 191}, {127, 127, 127}, { 0, 0, 0}, { 0, 0, 0}, + { 0, 0, 0}, {127, 127, 127}, {191, 191, 191}, {255, 255, 255}, {255, 255, 255}, + {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}}, + {{255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, + {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, + {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, + {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}}, + {{255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, + {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, + {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, + {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}}, + {{255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, + {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, + {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, + {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}}, + {{255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, + {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, + {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, + {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}} +}; + + std::vector<std::vector<std::vector<int>>> expected_left_top_vector { + {{255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, + {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, + {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, + {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}}, + {{255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, + {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, + {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, + {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}}, + {{255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, + {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, + {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, + {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}}, + {{255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {191, 191, 191}, + {127, 127, 127}, { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, {127, 127, 127}, + {191, 191, 191}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, + {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}}, + {{255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {191, 191, 191}, { 0, 0, 0}, + { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, + { 0, 0, 0}, {191, 191, 191}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, + {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}}, + {{255, 255, 255}, {255, 255, 255}, {191, 191, 191}, { 0, 0, 0}, { 0, 0, 0}, + { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, + { 0, 0, 0}, { 0, 0, 0}, {191, 191, 191}, {255, 255, 255}, {255, 255, 255}, + {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}}, + {{255, 255, 255}, {255, 255, 255}, {127, 127, 127}, { 0, 0, 0}, { 0, 0, 0}, + { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, + { 0, 0, 0}, { 0, 0, 0}, {127, 127, 127}, {255, 255, 255}, {255, 255, 255}, + {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}}, + {{255, 255, 255}, {255, 255, 255}, { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, + { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, + { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, {255, 255, 255}, {255, 255, 255}, + {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}}, + {{255, 255, 255}, {255, 255, 255}, { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, + { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, + { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, {255, 255, 255}, {255, 255, 255}, + {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}}, + {{255, 255, 255}, {255, 255, 255}, { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, + { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, + { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, {255, 255, 255}, {255, 255, 255}, + {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}}, + {{255, 255, 255}, {255, 255, 255}, {127, 127, 127}, { 0, 0, 0}, { 0, 0, 0}, + { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, + { 0, 0, 0}, { 0, 0, 0}, {127, 127, 127}, {255, 255, 255}, {255, 255, 255}, + {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}}, + {{255, 255, 255}, {255, 255, 255}, {191, 191, 191}, { 0, 0, 0}, { 0, 0, 0}, + { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, + { 0, 0, 0}, { 0, 0, 0}, {191, 191, 191}, {255, 255, 255}, {255, 255, 255}, + {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}}, + {{255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {191, 191, 191}, { 0, 0, 0}, + { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, + { 0, 0, 0}, {191, 191, 191}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, + {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}}, + {{255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {191, 191, 191}, + {127, 127, 127}, { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, {127, 127, 127}, + {191, 191, 191}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, + {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}}, + {{255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, + {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, + {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, + {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}}, + {{255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, + {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, + {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, + {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}}, + {{255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, + {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, + {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, + {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}}, + {{255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, + {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, + {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, + {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}}, + {{255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, + {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, + {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, + {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}}, + {{255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, + {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, + {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, + {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}} +}; + + gil::rgb8_image_t original_image(16, 16), expected_center_middle_img(20, 20); + gil::rgb8_image_t expected_left_top_img(20, 20), obtained_center_middle_img(20, 20); + gil::rgb8_image_t obtained_left_top_img(20, 20); + + gil::rgb8_view_t obtained_center_middle_view = gil::view(obtained_center_middle_img); + gil::rgb8_view_t obtained_left_top_view = gil::view(obtained_left_top_img); + + gil::fill_pixels(obtained_center_middle_view, gil::rgb8_pixel_t(255, 255, 255)); + gil::fill_pixels(obtained_left_top_view, gil::rgb8_pixel_t(255, 255, 255)); + + pixel_fill_rgb(original_img_vector, original_image); + pixel_fill_rgb(expected_center_middle_vector, expected_center_middle_img); + pixel_fill_rgb(expected_left_top_vector, expected_left_top_img); + + using aligned_t = gil::aligned<gil::rgb8_view_t>; + aligned_t aligned(gil::view(original_image), aligned_t::center | aligned_t::middle); + aligned(obtained_center_middle_view); + + aligned.align = aligned_t::left | aligned_t::top; + aligned(obtained_left_top_view); + + BOOST_TEST(gil::equal_pixels(obtained_center_middle_view, gil::view(expected_center_middle_img))); + BOOST_TEST(gil::equal_pixels(obtained_left_top_view, gil::view(expected_left_top_img))); + + return boost::report_errors(); +}