File: subimage_view.cpp

package info (click to toggle)
boost1.74 1.74.0-9
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 464,084 kB
  • sloc: cpp: 3,338,324; xml: 131,293; python: 33,088; ansic: 14,336; asm: 4,034; sh: 3,351; makefile: 1,193; perl: 1,036; yacc: 478; php: 212; ruby: 102; lisp: 24; sql: 13; csh: 6
file content (91 lines) | stat: -rw-r--r-- 3,246 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
//
// Copyright 2019-2020 Mateusz Loskot <mateusz at loskot dot net>
//
// 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/core/lightweight_test.hpp>

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

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

struct test_subimage_equals_image
{
    template <typename Image>
    void operator()(Image const&)
    {
        using image_t = Image;
        auto i0 = fixture::create_image<image_t>(4, 4, 128);
        auto const v0 = gil::const_view(i0);
        BOOST_TEST_EQ(v0.dimensions().x, 4);
        BOOST_TEST_EQ(v0.dimensions().y, 4);

        // request with 2 x point_t values
        {
            auto v1 = gil::subimage_view(gil::view(i0), {0, 0}, i0.dimensions());
            BOOST_TEST_EQ(v0.dimensions(), v1.dimensions());
            BOOST_TEST(gil::equal_pixels(v0, v1));
        }
        // request with 4 x dimension values
        {
            auto v1 = gil::subimage_view(gil::view(i0), 0, 0, i0.dimensions().x, i0.dimensions().y);
            BOOST_TEST_EQ(v0.dimensions(), v1.dimensions());
            BOOST_TEST(gil::equal_pixels(v0, v1));
        }
    }
    static void run()
    {
        boost::mp11::mp_for_each<fixture::image_types>(test_subimage_equals_image{});
    }
};

struct test_subimage_equals_image_quadrants
{
    template <typename Image>
    void operator()(Image const&)
    {
        using image_t = Image;
        auto i0 = fixture::create_image<image_t>(4, 4, 0);
        auto v0 = gil::view(i0);
        // create test image and set values of pixels in:
        //  quadrant 1
        auto const i1 = fixture::create_image<image_t>(2, 2, 255);
        v0[2] = v0[3] = v0[6] = v0[7] = gil::const_view(i1)[0];
        //  quadrant 2
        auto const i2 = fixture::create_image<image_t>(2, 2, 128);
        v0[0] = v0[1] = v0[4] = v0[5] = gil::const_view(i2)[0];
        //  quadrant 3
        auto const i3 = fixture::create_image<image_t>(2, 2, 64);
        v0[8] = v0[9] = v0[12] = v0[13] = gil::const_view(i3)[0];
        //  quadrant 4
        auto const i4 = fixture::create_image<image_t>(2, 2, 32);
        v0[10] = v0[11] = v0[14] = v0[15] = gil::const_view(i4)[0];

        auto v1 = gil::subimage_view(gil::view(i0), { 2, 0 }, i0.dimensions() / 2);
        BOOST_TEST(gil::equal_pixels(v1, gil::const_view(i1)));
        auto v2 = gil::subimage_view(gil::view(i0), { 0, 0 }, i0.dimensions() / 2);
        BOOST_TEST(gil::equal_pixels(v2, gil::const_view(i2)));
        auto v3 = gil::subimage_view(gil::view(i0), { 0, 2 }, i0.dimensions() / 2);
        BOOST_TEST(gil::equal_pixels(v3, gil::const_view(i3)));
        auto v4 = gil::subimage_view(gil::view(i0), { 2, 2 }, i0.dimensions() / 2);
        BOOST_TEST(gil::equal_pixels(v4, gil::const_view(i4)));
    }
    static void run()
    {
        boost::mp11::mp_for_each<fixture::image_types>(test_subimage_equals_image_quadrants{});
    }
};

int main()
{
    test_subimage_equals_image::run();
    test_subimage_equals_image_quadrants::run();

    return ::boost::report_errors();
}