2
0
mirror of https://github.com/boostorg/gil.git synced 2026-02-20 02:42:11 +00:00

Merge pull request #139 from mloskot/ml/trac-ticket-7092

Remove re-assignment of functor from for_each_pixel (Trac 7092)
This commit is contained in:
Mateusz Loskot
2018-09-23 21:26:07 +02:00
committed by GitHub
3 changed files with 50 additions and 1 deletions

View File

@@ -765,7 +765,7 @@ F for_each_pixel(const V& img, F fun) {
return std::for_each(img.begin().x(), img.end().x(), fun);
} else {
for (std::ptrdiff_t y=0; y<img.height(); ++y)
fun = std::for_each(img.row_begin(y),img.row_end(y),fun);
std::for_each(img.row_begin(y),img.row_end(y),fun);
return fun;
}
}

17
test/algorithm/Jamfile Normal file
View File

@@ -0,0 +1,17 @@
# Boost.GIL (Generic Image Library) - tests
#
# Copyright (c) 2018 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)
import testing ;
project
: requirements
<include>$(BOOST_ROOT)
<include>..
;
run for_each_pixel.cpp ;

View File

@@ -0,0 +1,32 @@
//
// Copyright 2018 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/algorithm.hpp>
#include <boost/gil/image.hpp>
#include <boost/core/lightweight_test.hpp>
namespace gil = boost::gil;
void test_lambda_expression()
{
gil::gray8_pixel_t const gray128(128);
gil::gray8_image_t image(2, 2, gray128);
int sum{0};
gil::for_each_pixel(gil::view(image), [&sum](gil::gray8_pixel_t& p) {
sum += gil::at_c<0>(p);
});
BOOST_TEST(sum == 2 * 2 * 128);
}
int main()
{
test_lambda_expression();
return boost::report_errors();
}