test_fixture.hpp 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. //
  2. // Copyright 2019 Mateusz Loskot <mateusz at loskot dot net>
  3. // Copyright 2005-2007 Adobe Systems Incorporated
  4. //
  5. // Distributed under the Boost Software License, Version 1.0
  6. // See accompanying file LICENSE_1_0.txt or copy at
  7. // http://www.boost.org/LICENSE_1_0.txt
  8. //
  9. #include <boost/gil/channel.hpp>
  10. #include <boost/gil/color_base_algorithm.hpp>
  11. #include <boost/gil/concepts/pixel.hpp>
  12. #include <boost/gil/pixel.hpp>
  13. #include <boost/gil/planar_pixel_reference.hpp>
  14. #include <boost/gil/promote_integral.hpp>
  15. #include <boost/gil/typedefs.hpp>
  16. #include <boost/core/ignore_unused.hpp>
  17. #include <boost/mp11.hpp>
  18. #include <boost/mp11/mpl.hpp> // for compatibility with Boost.Test
  19. #include <cstdint>
  20. #include <iostream>
  21. #include <tuple>
  22. #include <type_traits>
  23. namespace boost { namespace gil {
  24. namespace test { namespace fixture {
  25. template <typename Pixel, int Tag = 0>
  26. class pixel_value
  27. {
  28. public:
  29. using type = Pixel;
  30. using pixel_t = type;
  31. type pixel_{};
  32. pixel_value() = default;
  33. explicit pixel_value(pixel_t const& pixel)
  34. : pixel_(pixel) // test copy constructor
  35. {
  36. type temp_pixel; // test default constructor
  37. boost::ignore_unused(temp_pixel);
  38. boost::function_requires<PixelValueConcept<pixel_t> >();
  39. }
  40. };
  41. // Alias compatible with naming of equivalent class in the test/legacy/pixel.cpp
  42. // The core suffix indicates `Pixel` is GIL core pixel type.
  43. template <typename Pixel, int Tag = 0>
  44. using value_core = pixel_value<Pixel, Tag>;
  45. template <typename PixelRef, int Tag = 0>
  46. struct pixel_reference
  47. : pixel_value
  48. <
  49. typename std::remove_reference<PixelRef>::type,
  50. Tag
  51. >
  52. {
  53. static_assert(
  54. std::is_reference<PixelRef>::value ||
  55. gil::is_planar<PixelRef>::value, // poor-man test for specialization of planar_pixel_reference
  56. "PixelRef must be reference or gil::planar_pixel_reference");
  57. using type = PixelRef;
  58. using pixel_t = typename std::remove_reference<PixelRef>::type;
  59. using parent_t = pixel_value<typename pixel_t::value_type, Tag>;
  60. using value_t = typename pixel_t::value_type;
  61. type pixel_{}; // reference
  62. pixel_reference() : parent_t{}, pixel_(parent_t::pixel_) {}
  63. explicit pixel_reference(value_t const& pixel) : parent_t(pixel), pixel_(parent_t::pixel_)
  64. {
  65. boost::function_requires<PixelConcept<pixel_t>>();
  66. }
  67. };
  68. // Alias compatible with naming of equivalent class in the test/legacy/pixel.cpp
  69. // The core suffix indicates `Pixel` is GIL core pixel type.
  70. template <typename Pixel, int Tag = 0>
  71. using reference_core = pixel_reference<Pixel, Tag>;
  72. // Metafunction to yield nested type of a representative pixel type
  73. template <typename PixelValueOrReference>
  74. using nested_type = typename PixelValueOrReference::type;
  75. // Metafunction to yield nested type of a representative pixel_t type
  76. template <typename PixelValueOrReference>
  77. using nested_pixel_type = typename PixelValueOrReference::pixel_t;
  78. // Subset of pixel models that covers all color spaces, channel depths,
  79. // reference/value, planar/interleaved, const/mutable.
  80. // Operations like color conversion will be invoked on pairs of those.
  81. using representative_pixel_types= ::boost::mp11::mp_list
  82. <
  83. value_core<gil::gray8_pixel_t>,
  84. reference_core<gil::gray16_pixel_t&>,
  85. value_core<gil::bgr8_pixel_t>,
  86. reference_core<gil::rgb8_planar_ref_t>,
  87. value_core<gil::argb32_pixel_t>,
  88. reference_core<gil::cmyk32f_pixel_t&>,
  89. reference_core<gil::abgr16c_ref_t>, // immutable reference
  90. reference_core<gil::rgb32fc_planar_ref_t>
  91. >;
  92. // List of all integer-based core pixel typedefs (i.e. with cv-qualifiers)
  93. using pixel_integer_types = ::boost::mp11::mp_list
  94. <
  95. gil::gray8_pixel_t,
  96. gil::gray8s_pixel_t,
  97. gil::gray16_pixel_t,
  98. gil::gray16s_pixel_t,
  99. gil::gray32_pixel_t,
  100. gil::gray32s_pixel_t,
  101. gil::bgr8_pixel_t,
  102. gil::bgr8s_pixel_t,
  103. gil::bgr16_pixel_t,
  104. gil::bgr16s_pixel_t,
  105. gil::bgr32_pixel_t,
  106. gil::bgr32s_pixel_t,
  107. gil::rgb8_pixel_t,
  108. gil::rgb8s_pixel_t,
  109. gil::rgb16_pixel_t,
  110. gil::rgb16s_pixel_t,
  111. gil::rgb32_pixel_t,
  112. gil::rgb32s_pixel_t,
  113. gil::abgr8_pixel_t,
  114. gil::abgr8s_pixel_t,
  115. gil::abgr16_pixel_t,
  116. gil::abgr16s_pixel_t,
  117. gil::abgr32_pixel_t,
  118. gil::abgr32s_pixel_t,
  119. gil::bgra8_pixel_t,
  120. gil::bgra8s_pixel_t,
  121. gil::bgra16_pixel_t,
  122. gil::bgra16s_pixel_t,
  123. gil::bgra32_pixel_t,
  124. gil::bgra32s_pixel_t,
  125. gil::cmyk8_pixel_t,
  126. gil::cmyk8s_pixel_t,
  127. gil::cmyk16_pixel_t,
  128. gil::cmyk16s_pixel_t,
  129. gil::cmyk32_pixel_t,
  130. gil::cmyk32s_pixel_t,
  131. gil::rgba8_pixel_t,
  132. gil::rgba8s_pixel_t,
  133. gil::rgba16_pixel_t,
  134. gil::rgba16s_pixel_t,
  135. gil::rgba32_pixel_t,
  136. gil::rgba32s_pixel_t
  137. >;
  138. // List of all integer-based core pixel typedefs (i.e. with cv-qualifiers)
  139. using pixel_float_types = ::boost::mp11::mp_list
  140. <
  141. gil::gray32f_pixel_t,
  142. gil::bgr32f_pixel_t,
  143. gil::rgb32f_pixel_t,
  144. gil::abgr32f_pixel_t,
  145. gil::bgra32f_pixel_t,
  146. gil::cmyk32f_pixel_t,
  147. gil::rgba32f_pixel_t
  148. >;
  149. // List of all core pixel types (i.e. without cv-qualifiers)
  150. using pixel_types = ::boost::mp11::mp_append
  151. <
  152. pixel_integer_types,
  153. pixel_float_types
  154. >;
  155. // List of all core pixel typedefs (i.e. with cv-qualifiers)
  156. using pixel_typedefs = ::boost::mp11::mp_append
  157. <
  158. pixel_integer_types,
  159. pixel_float_types,
  160. ::boost::mp11::mp_list
  161. <
  162. gil::gray8c_pixel_t,
  163. gil::gray8sc_pixel_t,
  164. gil::gray16c_pixel_t,
  165. gil::gray16sc_pixel_t,
  166. gil::gray32c_pixel_t,
  167. gil::gray32fc_pixel_t,
  168. gil::gray32sc_pixel_t,
  169. gil::bgr8c_pixel_t,
  170. gil::bgr8sc_pixel_t,
  171. gil::bgr16c_pixel_t,
  172. gil::bgr16sc_pixel_t,
  173. gil::bgr32c_pixel_t,
  174. gil::bgr32fc_pixel_t,
  175. gil::bgr32sc_pixel_t,
  176. gil::rgb8c_pixel_t,
  177. gil::rgb8sc_pixel_t,
  178. gil::rgb16c_pixel_t,
  179. gil::rgb16sc_pixel_t,
  180. gil::rgb32c_pixel_t,
  181. gil::rgb32fc_pixel_t,
  182. gil::rgb32sc_pixel_t,
  183. gil::abgr8c_pixel_t,
  184. gil::abgr8sc_pixel_t,
  185. gil::abgr16c_pixel_t,
  186. gil::abgr16sc_pixel_t,
  187. gil::abgr32c_pixel_t,
  188. gil::abgr32fc_pixel_t,
  189. gil::abgr32sc_pixel_t,
  190. gil::bgra8c_pixel_t,
  191. gil::bgra8sc_pixel_t,
  192. gil::bgra16c_pixel_t,
  193. gil::bgra16sc_pixel_t,
  194. gil::bgra32c_pixel_t,
  195. gil::bgra32fc_pixel_t,
  196. gil::bgra32sc_pixel_t,
  197. gil::cmyk8c_pixel_t,
  198. gil::cmyk8sc_pixel_t,
  199. gil::cmyk16c_pixel_t,
  200. gil::cmyk16sc_pixel_t,
  201. gil::cmyk32c_pixel_t,
  202. gil::cmyk32fc_pixel_t,
  203. gil::cmyk32sc_pixel_t,
  204. gil::rgba8c_pixel_t,
  205. gil::rgba8sc_pixel_t,
  206. gil::rgba16c_pixel_t,
  207. gil::rgba16sc_pixel_t,
  208. gil::rgba32c_pixel_t,
  209. gil::rgba32fc_pixel_t,
  210. gil::rgba32sc_pixel_t
  211. >
  212. >;
  213. struct not_a_pixel_type {};
  214. using non_pixels = ::boost::mp11::mp_list
  215. <
  216. not_a_pixel_type,
  217. char,
  218. short, int, long,
  219. double, float,
  220. std::size_t,
  221. std::true_type,
  222. std::false_type
  223. >;
  224. }}}} // namespace boost::gil::test::fixture