-
Notifications
You must be signed in to change notification settings - Fork 163
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Added for_each_pixel overload for any_image (#648)
Take functor by value instead of reference. Test cases to use the same fixture as the other any_image tests. Fixes #579
- Loading branch information
1 parent
3289fe0
commit c063d1c
Showing
4 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Boost.GIL (Generic Image Library) - tests | ||
# | ||
# Copyright (c) 2022 Marco Langer <langer.m86 at gmail dot com> | ||
# | ||
# 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) | ||
|
||
import testing ; | ||
|
||
run for_each_pixel.cpp ; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// | ||
// Copyright 2022 Marco Langer | ||
// | ||
// 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/extension/dynamic_image/any_image.hpp> | ||
#include <boost/gil/extension/dynamic_image/algorithm.hpp> | ||
|
||
#include <boost/core/lightweight_test.hpp> | ||
|
||
#include "../test_fixture.hpp" | ||
#include "core/image/test_fixture.hpp" | ||
|
||
namespace gil = boost::gil; | ||
namespace fixture = boost::gil::test::fixture; | ||
|
||
struct accumulator | ||
{ | ||
template <typename Pixel> | ||
void operator()(Pixel const& p) | ||
{ | ||
sum += gil::at_c<0>(p); | ||
} | ||
|
||
int sum{}; | ||
}; | ||
|
||
struct test_for_each_pixel | ||
{ | ||
template <typename Image> | ||
void operator()(Image const&) | ||
{ | ||
using image_t = Image; | ||
fixture::dynamic_image image(fixture::create_image<image_t>(2, 2, 128)); | ||
accumulator acc = gil::for_each_pixel(gil::const_view(image), accumulator()); | ||
BOOST_TEST_EQ(acc.sum, 2 * 2 * 128); | ||
} | ||
|
||
static void run() | ||
{ | ||
boost::mp11::mp_for_each<fixture::image_types>(test_for_each_pixel{}); | ||
} | ||
}; | ||
|
||
int main() | ||
{ | ||
test_for_each_pixel::run(); | ||
|
||
return ::boost::report_errors(); | ||
} |