9
3

view_type.cpp 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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.hpp>
  9. #include <type_traits>
  10. namespace gil = boost::gil;
  11. struct Interleaved : std::false_type {};
  12. struct Planar : std::true_type {};
  13. struct NotStepX : std::false_type {};
  14. struct StepX : std::true_type {};
  15. struct Immutable : std::false_type {};
  16. struct Mutable : std::true_type {};
  17. template <typename ResultView, typename Layout, typename IsPlanar, typename IsStepX, typename IsMutable>
  18. void test()
  19. {
  20. static_assert(std::is_same
  21. <
  22. typename gil::view_type
  23. <
  24. std::uint8_t,
  25. Layout,
  26. IsPlanar::value,
  27. IsStepX::value,
  28. IsMutable::value
  29. >::type,
  30. ResultView
  31. >::value, "view_type yields unexpected view");
  32. }
  33. template <typename ResultView, typename Layout, typename IsPlanar, typename IsStepX, typename IsMutable>
  34. void test_not()
  35. {
  36. static_assert(!std::is_same
  37. <
  38. typename gil::view_type
  39. <
  40. std::uint8_t,
  41. Layout,
  42. IsPlanar::value,
  43. IsStepX::value,
  44. IsMutable::value
  45. >::type,
  46. ResultView
  47. >::value, "view_type yields unexpected view");
  48. }
  49. int main()
  50. {
  51. test<gil::gray8_view_t, gil::gray_layout_t, Interleaved, NotStepX, Mutable>();
  52. test<gil::gray8c_view_t, gil::gray_layout_t, Interleaved, NotStepX, Immutable>();
  53. test<gil::gray8_step_view_t, gil::gray_layout_t, Interleaved, StepX, Mutable>();
  54. test<gil::gray8c_step_view_t, gil::gray_layout_t, Interleaved, StepX, Immutable>();
  55. test_not<gil::gray8_view_t, gil::gray_layout_t, Planar, NotStepX, Mutable>();
  56. test_not<gil::gray8_view_t, gil::rgb_layout_t, Planar, NotStepX, Mutable>();
  57. test_not<gil::gray8_view_t, gil::gray_layout_t, Interleaved, StepX, Mutable>();
  58. test_not<gil::gray8_view_t, gil::gray_layout_t, Interleaved, NotStepX, Immutable>();
  59. test<gil::abgr8_view_t, gil::abgr_layout_t, Interleaved, NotStepX, Mutable>();
  60. test<gil::abgr8c_view_t, gil::abgr_layout_t, Interleaved, NotStepX, Immutable>();
  61. test<gil::abgr8_step_view_t, gil::abgr_layout_t, Interleaved, StepX, Mutable>();
  62. test<gil::abgr8c_step_view_t, gil::abgr_layout_t, Interleaved, StepX, Immutable>();
  63. test_not<gil::abgr8_view_t, gil::bgra_layout_t, Interleaved, NotStepX, Mutable>();
  64. test_not<gil::abgr8_view_t, gil::rgba_layout_t, Interleaved, NotStepX, Mutable>();
  65. test<gil::argb8_view_t, gil::argb_layout_t, Interleaved, NotStepX, Mutable>();
  66. test<gil::argb8c_view_t, gil::argb_layout_t, Interleaved, NotStepX, Immutable>();
  67. test<gil::argb8_step_view_t, gil::argb_layout_t, Interleaved, StepX, Mutable>();
  68. test<gil::argb8c_step_view_t, gil::argb_layout_t, Interleaved, StepX, Immutable>();
  69. test<gil::bgr8_view_t, gil::bgr_layout_t, Interleaved, NotStepX, Mutable>();
  70. test<gil::bgr8c_view_t, gil::bgr_layout_t, Interleaved, NotStepX, Immutable>();
  71. test<gil::bgr8_step_view_t, gil::bgr_layout_t, Interleaved, StepX, Mutable>();
  72. test<gil::bgr8c_step_view_t, gil::bgr_layout_t, Interleaved, StepX, Immutable>();
  73. test_not<gil::bgr8_view_t, gil::rgb_layout_t, Interleaved, NotStepX, Mutable>();
  74. test<gil::bgra8_view_t, gil::bgra_layout_t, Interleaved, NotStepX, Mutable>();
  75. test<gil::bgra8c_view_t, gil::bgra_layout_t, Interleaved, NotStepX, Immutable>();
  76. test<gil::bgra8_step_view_t, gil::bgra_layout_t, Interleaved, StepX, Mutable>();
  77. test<gil::bgra8c_step_view_t, gil::bgra_layout_t, Interleaved, StepX, Immutable>();
  78. test_not<gil::bgra8_view_t, gil::abgr_layout_t, Interleaved, NotStepX, Mutable>();
  79. test_not<gil::bgra8_view_t, gil::rgba_layout_t, Interleaved, NotStepX, Mutable>();
  80. test<gil::rgb8_view_t, gil::rgb_layout_t, Interleaved, NotStepX, Mutable>();
  81. test<gil::rgb8c_view_t, gil::rgb_layout_t, Interleaved, NotStepX, Immutable>();
  82. test<gil::rgb8_step_view_t, gil::rgb_layout_t, Interleaved, StepX, Mutable>();
  83. test<gil::rgb8c_step_view_t, gil::rgb_layout_t, Interleaved, StepX, Immutable>();
  84. test_not<gil::rgb8_view_t, gil::rgb_layout_t, Planar, NotStepX, Mutable>();
  85. test_not<gil::rgb8_view_t, gil::abgr_layout_t, Interleaved, NotStepX, Mutable>();
  86. test_not<gil::rgb8_view_t, gil::bgra_layout_t, Interleaved, NotStepX, Mutable>();
  87. test<gil::rgb8_planar_view_t, gil::rgb_layout_t, Planar, NotStepX, Mutable>();
  88. test<gil::rgb8c_planar_view_t, gil::rgb_layout_t, Planar, NotStepX, Immutable>();
  89. test<gil::rgb8_planar_step_view_t, gil::rgb_layout_t, Planar, StepX, Mutable>();
  90. test<gil::rgb8c_planar_step_view_t, gil::rgb_layout_t, Planar, StepX, Immutable>();
  91. test<gil::cmyk8_view_t, gil::cmyk_layout_t, Interleaved, NotStepX, Mutable>();
  92. test<gil::cmyk8c_view_t, gil::cmyk_layout_t, Interleaved, NotStepX, Immutable>();
  93. test<gil::cmyk8_step_view_t, gil::cmyk_layout_t, Interleaved, StepX, Mutable>();
  94. test<gil::cmyk8c_step_view_t, gil::cmyk_layout_t, Interleaved, StepX, Immutable>();
  95. test_not<gil::cmyk8_view_t, gil::rgba_layout_t, Interleaved, NotStepX, Mutable>();
  96. test<gil::cmyk8_planar_view_t, gil::cmyk_layout_t, Planar, NotStepX, Mutable>();
  97. test<gil::cmyk8c_planar_view_t, gil::cmyk_layout_t, Planar, NotStepX, Immutable>();
  98. test<gil::cmyk8_planar_step_view_t, gil::cmyk_layout_t, Planar, StepX, Mutable>();
  99. test<gil::cmyk8c_planar_step_view_t, gil::cmyk_layout_t, Planar, StepX, Immutable>();
  100. }