static_transform_gray_to_rgb_fail.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. //
  2. // Copyright 2019 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/color_base_algorithm.hpp>
  9. #include <boost/gil/pixel.hpp>
  10. #include <boost/gil/typedefs.hpp>
  11. #include <cassert>
  12. #include <cstdint>
  13. namespace gil = boost::gil;
  14. int main()
  15. {
  16. // K-element index must be less than size of channel_mapping_t sequence
  17. // of the *destination* color base.
  18. // RGB (wider space) transformation to Gray (narrower space) takes only R channel value
  19. {
  20. gil::rgb8_pixel_t src{ 32, 64, 128 };
  21. gil::gray8_pixel_t dst{ 0 };
  22. gil::static_transform(src, dst, [](std::uint8_t src_channel) {
  23. return src_channel; // copy
  24. });
  25. assert(gil::at_c<0>(dst) == std::uint16_t{32});
  26. }
  27. // Gray (narrower space) to RGB (wider space) transformation FAILS to compile
  28. {
  29. gil::gray8_pixel_t src{32};
  30. gil::rgb8_pixel_t dst{0, 0, 0};
  31. gil::static_transform(src, dst, [](std::uint8_t src_channel) {
  32. return src_channel; // copy
  33. });
  34. }
  35. }