for_each_pixel.cpp 734 B

1234567891011121314151617181920212223242526272829303132
  1. //
  2. // Copyright 2018 Mateusz Loskot <mateusz at loskot dot net>
  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/algorithm.hpp>
  9. #include <boost/gil/image.hpp>
  10. #include <boost/core/lightweight_test.hpp>
  11. namespace gil = boost::gil;
  12. void test_lambda_expression()
  13. {
  14. gil::gray8_pixel_t const gray128(128);
  15. gil::gray8_image_t image(2, 2, gray128);
  16. int sum{0};
  17. gil::for_each_pixel(gil::view(image), [&sum](gil::gray8_pixel_t& p) {
  18. sum += gil::at_c<0>(p);
  19. });
  20. BOOST_TEST(sum == 2 * 2 * 128);
  21. }
  22. int main()
  23. {
  24. test_lambda_expression();
  25. return boost::report_errors();
  26. }