1//
2// Copyright 2022 Marco Langer <langer.m86 at gmail dot com>
3//
4// Distributed under the Boost Software License, Version 1.0
5// See accompanying file LICENSE_1_0.txt or copy at
6// http://www.boost.org/LICENSE_1_0.txt
7//
8#include <boost/gil/extension/dynamic_image/algorithm.hpp>
9#include <boost/gil/extension/dynamic_image/any_image.hpp>
10
11#include <boost/core/lightweight_test.hpp>
12
13#include "core/image/test_fixture.hpp"
14#include "extension/dynamic_image/test_fixture.hpp"
15
16namespace gil = boost::gil;
17namespace fixture = boost::gil::test::fixture;
18
19struct accumulator
20{
21 template <typename Pixel>
22 void operator()(Pixel const& p)
23 {
24 sum += gil::at_c<0>(p);
25 }
26
27 int sum{};
28};
29
30struct test_for_each_pixel
31{
32 template <typename Image>
33 void operator()(Image const&)
34 {
35 using image_t = Image;
36 fixture::dynamic_image image(fixture::create_image<image_t>(2, 2, 128));
37 accumulator acc = gil::for_each_pixel(view: gil::const_view(img: image), fun: accumulator());
38 BOOST_TEST_EQ(acc.sum, 2 * 2 * 128);
39 }
40
41 static void run()
42 {
43 boost::mp11::mp_for_each<fixture::image_types>(f: test_for_each_pixel{});
44 }
45};
46
47int main()
48{
49 test_for_each_pixel::run();
50
51 return ::boost::report_errors();
52}
53

source code of boost/libs/gil/test/extension/dynamic_image/algorithm/for_each_pixel.cpp