9
3

planar_rgba_view.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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.hpp>
  9. #include <boost/core/lightweight_test.hpp>
  10. #include <cstdint>
  11. namespace gil = boost::gil;
  12. int main()
  13. {
  14. gil::point_t d{2, 2};
  15. std::uint8_t r[] = { 1, 2, 3, 4 };
  16. std::uint8_t g[] = { 10, 20, 30, 40 };
  17. std::uint8_t b[] = { 110, 120, 130, 140 };
  18. std::uint8_t a[] = { 251, 252, 253, 254 };
  19. auto v = gil::planar_rgba_view(d.x, d.y, r, g, b, a, sizeof(std::uint8_t) * 2);
  20. BOOST_TEST(!v.empty());
  21. BOOST_TEST(v.dimensions() == d);
  22. BOOST_TEST(v.num_channels() == 4u);
  23. BOOST_TEST(v.size() == static_cast<std::size_t>(d.x * d.y));
  24. gil::rgba8_pixel_t const pf{1, 10, 110, 251};
  25. BOOST_TEST(v.front() == pf);
  26. gil::rgba8_pixel_t const pb{4, 40, 140, 254};
  27. BOOST_TEST(v.back() == pb);
  28. for (std::ptrdiff_t i = 0; i < v.size(); i++)
  29. {
  30. gil::rgba8_pixel_t const p{r[i], g[i], b[i], a[i]};
  31. BOOST_TEST(v[i] == p);
  32. }
  33. return boost::report_errors();
  34. }