typedefs.hpp 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. //
  2. // Copyright 2005-2007 Adobe Systems Incorporated
  3. // Copyright 2018 Mateusz Loskot <[email protected]>
  4. //
  5. // Use, modification and distribution are subject to the Boost Software License,
  6. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  7. // http://www.boost.org/LICENSE_1_0.txt)
  8. //
  9. #ifndef BOOST_GIL_TYPEDEFS_HPP
  10. #define BOOST_GIL_TYPEDEFS_HPP
  11. #include <boost/gil/cmyk.hpp>
  12. #include <boost/gil/device_n.hpp>
  13. #include <boost/gil/gray.hpp>
  14. #include <boost/gil/point.hpp>
  15. #include <boost/gil/rgb.hpp>
  16. #include <boost/gil/rgba.hpp>
  17. #include <cstdint>
  18. #include <memory>
  19. #if !defined(BOOST_NO_CXX17_HDR_MEMORY_RESOURCE)
  20. # include <memory_resource>
  21. #endif //!defined(BOOST_NO_CXX17_HDR_MEMORY_RESOURCE)
  22. // B - bits size/signedness, CM - channel model, CS - colour space, LAYOUT - pixel layout
  23. // Example: B = '8', CM = 'uint8_t', CS = 'bgr, LAYOUT='bgr_layout_t'
  24. #define BOOST_GIL_DEFINE_BASE_TYPEDEFS_INTERNAL(B, CM, CS, LAYOUT) \
  25. template <typename, typename> \
  26. struct pixel; \
  27. template <typename, typename> \
  28. struct planar_pixel_reference; \
  29. template <typename, typename> \
  30. struct planar_pixel_iterator; \
  31. template <typename> \
  32. class memory_based_step_iterator; \
  33. template <typename> \
  34. class point; \
  35. template <typename> \
  36. class memory_based_2d_locator; \
  37. template <typename> \
  38. class image_view; \
  39. template <typename, bool, typename> \
  40. class image; \
  41. using CS##B##_pixel_t = pixel<CM, LAYOUT>; \
  42. using CS##B##c_pixel_t = pixel<CM, LAYOUT> const; \
  43. using CS##B##_ref_t = pixel<CM, LAYOUT>&; \
  44. using CS##B##c_ref_t = pixel<CM, LAYOUT> const&; \
  45. using CS##B##_ptr_t = CS##B##_pixel_t*; \
  46. using CS##B##c_ptr_t = CS##B##c_pixel_t*; \
  47. using CS##B##_step_ptr_t = memory_based_step_iterator<CS##B##_ptr_t>; \
  48. using CS##B##c_step_ptr_t = memory_based_step_iterator<CS##B##c_ptr_t>; \
  49. using CS##B##_loc_t = memory_based_2d_locator<memory_based_step_iterator<CS##B##_ptr_t>>; \
  50. using CS##B##c_loc_t = memory_based_2d_locator<memory_based_step_iterator<CS##B##c_ptr_t>>; \
  51. using CS##B##_step_loc_t \
  52. = memory_based_2d_locator<memory_based_step_iterator<CS##B##_step_ptr_t>>; \
  53. using CS##B##c_step_loc_t \
  54. = memory_based_2d_locator<memory_based_step_iterator<CS##B##c_step_ptr_t>>; \
  55. using CS##B##_view_t = image_view<CS##B##_loc_t>; \
  56. using CS##B##c_view_t = image_view<CS##B##c_loc_t>; \
  57. using CS##B##_step_view_t = image_view<CS##B##_step_loc_t>; \
  58. using CS##B##c_step_view_t = image_view<CS##B##c_step_loc_t>; \
  59. using CS##B##_image_t = image<CS##B##_pixel_t, false, std::allocator<unsigned char>>;
  60. #define BOOST_GIL_DEFINE_BASE_PMR_TYPEDEFS_INTERNAL(B, CM, CS, LAYOUT) \
  61. namespace pmr { \
  62. using CS##B##_image_t \
  63. = image<CS##B##_pixel_t, false, std::pmr::polymorphic_allocator<unsigned char>>; \
  64. }
  65. // Example: B = '8', CM = 'uint8_t', CS = 'bgr' CS_FULL = 'rgb_t' LAYOUT='bgr_layout_t'
  66. #define BOOST_GIL_DEFINE_ALL_TYPEDEFS_INTERNAL(B, CM, CS, CS_FULL, LAYOUT) \
  67. BOOST_GIL_DEFINE_BASE_TYPEDEFS_INTERNAL(B, CM, CS, LAYOUT) \
  68. using CS##B##_planar_ref_t = planar_pixel_reference<CM&, CS_FULL>; \
  69. using CS##B##c_planar_ref_t = planar_pixel_reference<CM const&, CS_FULL>; \
  70. using CS##B##_planar_ptr_t = planar_pixel_iterator<CM*, CS_FULL>; \
  71. using CS##B##c_planar_ptr_t = planar_pixel_iterator<CM const*, CS_FULL>; \
  72. using CS##B##_planar_step_ptr_t = memory_based_step_iterator<CS##B##_planar_ptr_t>; \
  73. using CS##B##c_planar_step_ptr_t = memory_based_step_iterator<CS##B##c_planar_ptr_t>; \
  74. using CS##B##_planar_loc_t \
  75. = memory_based_2d_locator<memory_based_step_iterator<CS##B##_planar_ptr_t>>; \
  76. using CS##B##c_planar_loc_t \
  77. = memory_based_2d_locator<memory_based_step_iterator<CS##B##c_planar_ptr_t>>; \
  78. using CS##B##_planar_step_loc_t \
  79. = memory_based_2d_locator<memory_based_step_iterator<CS##B##_planar_step_ptr_t>>; \
  80. using CS##B##c_planar_step_loc_t \
  81. = memory_based_2d_locator<memory_based_step_iterator<CS##B##c_planar_step_ptr_t>>; \
  82. using CS##B##_planar_view_t = image_view<CS##B##_planar_loc_t>; \
  83. using CS##B##c_planar_view_t = image_view<CS##B##c_planar_loc_t>; \
  84. using CS##B##_planar_step_view_t = image_view<CS##B##_planar_step_loc_t>; \
  85. using CS##B##c_planar_step_view_t = image_view<CS##B##c_planar_step_loc_t>; \
  86. using CS##B##_planar_image_t = image<CS##B##_pixel_t, true, std::allocator<unsigned char>>;
  87. #define BOOST_GIL_DEFINE_ALL_PMR_TYPEDEFS_INTERNAL(B, CM, CS, CS_FULL, LAYOUT) \
  88. BOOST_GIL_DEFINE_BASE_PMR_TYPEDEFS_INTERNAL(B, CM, CS, LAYOUT) \
  89. namespace pmr { \
  90. using CS##B##_planar_image_t \
  91. = image<CS##B##_pixel_t, true, std::pmr::polymorphic_allocator<unsigned char>>; \
  92. }
  93. #if defined(BOOST_NO_CXX17_HDR_MEMORY_RESOURCE)
  94. # define BOOST_GIL_DEFINE_BASE_TYPEDEFS(B, CM, CS) \
  95. BOOST_GIL_DEFINE_BASE_TYPEDEFS_INTERNAL(B, CM, CS, CS##_layout_t)
  96. # define BOOST_GIL_DEFINE_ALL_TYPEDEFS(B, CM, CS) \
  97. BOOST_GIL_DEFINE_ALL_TYPEDEFS_INTERNAL(B, CM, CS, CS##_t, CS##_layout_t)
  98. #else
  99. # define BOOST_GIL_DEFINE_BASE_TYPEDEFS(B, CM, CS) \
  100. BOOST_GIL_DEFINE_BASE_TYPEDEFS_INTERNAL(B, CM, CS, CS##_layout_t) \
  101. BOOST_GIL_DEFINE_BASE_PMR_TYPEDEFS_INTERNAL(B, CM, CS, CS##_layout_t)
  102. # define BOOST_GIL_DEFINE_ALL_TYPEDEFS(B, CM, CS) \
  103. BOOST_GIL_DEFINE_ALL_TYPEDEFS_INTERNAL(B, CM, CS, CS##_t, CS##_layout_t) \
  104. BOOST_GIL_DEFINE_ALL_PMR_TYPEDEFS_INTERNAL(B, CM, CS, CS##_t, CS##_layout_t)
  105. #endif //!defined(BOOST_NO_CXX17_HDR_MEMORY_RESOURCE)
  106. namespace boost { namespace gil {
  107. // forward declarations
  108. template <typename B, typename Mn, typename Mx> struct scoped_channel_value;
  109. template <typename T> struct float_point_zero;
  110. template <typename T> struct float_point_one;
  111. //////////////////////////////////////////////////////////////////////////////////////////
  112. /// Built-in channel models
  113. //////////////////////////////////////////////////////////////////////////////////////////
  114. /// \ingroup ChannelModel
  115. /// \brief 8-bit unsigned integral channel type (alias from uint8_t). Models ChannelValueConcept
  116. using std::uint8_t;
  117. /// \ingroup ChannelModel
  118. /// \brief 16-bit unsigned integral channel type (alias from uint16_t). Models ChannelValueConcept
  119. using std::uint16_t;
  120. /// \ingroup ChannelModel
  121. /// \brief 32-bit unsigned integral channel type (alias from uint32_t). Models ChannelValueConcept
  122. using std::uint32_t;
  123. /// \ingroup ChannelModel
  124. /// \brief 8-bit signed integral channel type (alias from int8_t). Models ChannelValueConcept
  125. using std::int8_t;
  126. /// \ingroup ChannelModel
  127. /// \brief 16-bit signed integral channel type (alias from int16_t). Models ChannelValueConcept
  128. using std::int16_t;
  129. /// \ingroup ChannelModel
  130. /// \brief 32-bit signed integral channel type (alias from int32_t). Models ChannelValueConcept
  131. using std::int32_t;
  132. /// \ingroup ChannelModel
  133. /// \brief 32-bit floating point channel type with range [0.0f ... 1.0f]. Models ChannelValueConcept
  134. using float32_t = scoped_channel_value<float, float_point_zero<float>, float_point_one<float>>;
  135. /// \ingroup ChannelModel
  136. /// \brief 64-bit floating point channel type with range [0.0f ... 1.0f]. Models ChannelValueConcept
  137. using float64_t = scoped_channel_value<double, float_point_zero<double>, float_point_one<double>>;
  138. BOOST_GIL_DEFINE_BASE_TYPEDEFS(8, uint8_t, gray)
  139. BOOST_GIL_DEFINE_BASE_TYPEDEFS(8s, int8_t, gray)
  140. BOOST_GIL_DEFINE_BASE_TYPEDEFS(16, uint16_t, gray)
  141. BOOST_GIL_DEFINE_BASE_TYPEDEFS(16s, int16_t, gray)
  142. BOOST_GIL_DEFINE_BASE_TYPEDEFS(32, uint32_t, gray)
  143. BOOST_GIL_DEFINE_BASE_TYPEDEFS(32s, int32_t, gray)
  144. BOOST_GIL_DEFINE_BASE_TYPEDEFS(32f, float32_t, gray)
  145. BOOST_GIL_DEFINE_BASE_TYPEDEFS(8, uint8_t, bgr)
  146. BOOST_GIL_DEFINE_BASE_TYPEDEFS(8s, int8_t, bgr)
  147. BOOST_GIL_DEFINE_BASE_TYPEDEFS(16, uint16_t, bgr)
  148. BOOST_GIL_DEFINE_BASE_TYPEDEFS(16s, int16_t, bgr)
  149. BOOST_GIL_DEFINE_BASE_TYPEDEFS(32, uint32_t, bgr)
  150. BOOST_GIL_DEFINE_BASE_TYPEDEFS(32s, int32_t, bgr)
  151. BOOST_GIL_DEFINE_BASE_TYPEDEFS(32f, float32_t, bgr)
  152. BOOST_GIL_DEFINE_BASE_TYPEDEFS(8, uint8_t, argb)
  153. BOOST_GIL_DEFINE_BASE_TYPEDEFS(8s, int8_t, argb)
  154. BOOST_GIL_DEFINE_BASE_TYPEDEFS(16, uint16_t, argb)
  155. BOOST_GIL_DEFINE_BASE_TYPEDEFS(16s, int16_t, argb)
  156. BOOST_GIL_DEFINE_BASE_TYPEDEFS(32, uint32_t, argb)
  157. BOOST_GIL_DEFINE_BASE_TYPEDEFS(32s, int32_t, argb)
  158. BOOST_GIL_DEFINE_BASE_TYPEDEFS(32f, float32_t, argb)
  159. BOOST_GIL_DEFINE_BASE_TYPEDEFS(8, uint8_t, abgr)
  160. BOOST_GIL_DEFINE_BASE_TYPEDEFS(8s, int8_t, abgr)
  161. BOOST_GIL_DEFINE_BASE_TYPEDEFS(16, uint16_t, abgr)
  162. BOOST_GIL_DEFINE_BASE_TYPEDEFS(16s, int16_t, abgr)
  163. BOOST_GIL_DEFINE_BASE_TYPEDEFS(32, uint32_t, abgr)
  164. BOOST_GIL_DEFINE_BASE_TYPEDEFS(32s, int32_t, abgr)
  165. BOOST_GIL_DEFINE_BASE_TYPEDEFS(32f, float32_t, abgr)
  166. BOOST_GIL_DEFINE_BASE_TYPEDEFS(8, uint8_t, bgra)
  167. BOOST_GIL_DEFINE_BASE_TYPEDEFS(8s, int8_t, bgra)
  168. BOOST_GIL_DEFINE_BASE_TYPEDEFS(16, uint16_t, bgra)
  169. BOOST_GIL_DEFINE_BASE_TYPEDEFS(16s, int16_t, bgra)
  170. BOOST_GIL_DEFINE_BASE_TYPEDEFS(32, uint32_t, bgra)
  171. BOOST_GIL_DEFINE_BASE_TYPEDEFS(32s, int32_t, bgra)
  172. BOOST_GIL_DEFINE_BASE_TYPEDEFS(32f, float32_t, bgra)
  173. BOOST_GIL_DEFINE_ALL_TYPEDEFS(8, uint8_t, rgb)
  174. BOOST_GIL_DEFINE_ALL_TYPEDEFS(8s, int8_t, rgb)
  175. BOOST_GIL_DEFINE_ALL_TYPEDEFS(16, uint16_t, rgb)
  176. BOOST_GIL_DEFINE_ALL_TYPEDEFS(16s, int16_t, rgb)
  177. BOOST_GIL_DEFINE_ALL_TYPEDEFS(32, uint32_t, rgb)
  178. BOOST_GIL_DEFINE_ALL_TYPEDEFS(32s, int32_t, rgb)
  179. BOOST_GIL_DEFINE_ALL_TYPEDEFS(32f, float32_t, rgb)
  180. BOOST_GIL_DEFINE_ALL_TYPEDEFS(8, uint8_t, rgba)
  181. BOOST_GIL_DEFINE_ALL_TYPEDEFS(8s, int8_t, rgba)
  182. BOOST_GIL_DEFINE_ALL_TYPEDEFS(16, uint16_t, rgba)
  183. BOOST_GIL_DEFINE_ALL_TYPEDEFS(16s, int16_t, rgba)
  184. BOOST_GIL_DEFINE_ALL_TYPEDEFS(32, uint32_t, rgba)
  185. BOOST_GIL_DEFINE_ALL_TYPEDEFS(32s, int32_t, rgba)
  186. BOOST_GIL_DEFINE_ALL_TYPEDEFS(32f, float32_t, rgba)
  187. BOOST_GIL_DEFINE_ALL_TYPEDEFS(8, uint8_t, cmyk)
  188. BOOST_GIL_DEFINE_ALL_TYPEDEFS(8s, int8_t, cmyk)
  189. BOOST_GIL_DEFINE_ALL_TYPEDEFS(16, uint16_t, cmyk)
  190. BOOST_GIL_DEFINE_ALL_TYPEDEFS(16s, int16_t, cmyk)
  191. BOOST_GIL_DEFINE_ALL_TYPEDEFS(32, uint32_t, cmyk)
  192. BOOST_GIL_DEFINE_ALL_TYPEDEFS(32s, int32_t, cmyk)
  193. BOOST_GIL_DEFINE_ALL_TYPEDEFS(32f, float32_t, cmyk)
  194. template <int N> struct devicen_t;
  195. template <int N> struct devicen_layout_t;
  196. BOOST_GIL_DEFINE_ALL_TYPEDEFS_INTERNAL(8, uint8_t, dev2n, devicen_t<2>, devicen_layout_t<2>)
  197. BOOST_GIL_DEFINE_ALL_TYPEDEFS_INTERNAL(8s, int8_t, dev2n, devicen_t<2>, devicen_layout_t<2>)
  198. BOOST_GIL_DEFINE_ALL_TYPEDEFS_INTERNAL(16, uint16_t, dev2n, devicen_t<2>, devicen_layout_t<2>)
  199. BOOST_GIL_DEFINE_ALL_TYPEDEFS_INTERNAL(16s, int16_t, dev2n, devicen_t<2>, devicen_layout_t<2>)
  200. BOOST_GIL_DEFINE_ALL_TYPEDEFS_INTERNAL(32, uint32_t, dev2n, devicen_t<2>, devicen_layout_t<2>)
  201. BOOST_GIL_DEFINE_ALL_TYPEDEFS_INTERNAL(32s, int32_t, dev2n, devicen_t<2>, devicen_layout_t<2>)
  202. BOOST_GIL_DEFINE_ALL_TYPEDEFS_INTERNAL(32f, float32_t, dev2n, devicen_t<2>, devicen_layout_t<2>)
  203. BOOST_GIL_DEFINE_ALL_TYPEDEFS_INTERNAL(8, uint8_t, dev3n, devicen_t<3>, devicen_layout_t<3>)
  204. BOOST_GIL_DEFINE_ALL_TYPEDEFS_INTERNAL(8s, int8_t, dev3n, devicen_t<3>, devicen_layout_t<3>)
  205. BOOST_GIL_DEFINE_ALL_TYPEDEFS_INTERNAL(16, uint16_t, dev3n, devicen_t<3>, devicen_layout_t<3>)
  206. BOOST_GIL_DEFINE_ALL_TYPEDEFS_INTERNAL(16s, int16_t, dev3n, devicen_t<3>, devicen_layout_t<3>)
  207. BOOST_GIL_DEFINE_ALL_TYPEDEFS_INTERNAL(32, uint32_t, dev3n, devicen_t<3>, devicen_layout_t<3>)
  208. BOOST_GIL_DEFINE_ALL_TYPEDEFS_INTERNAL(32s, int32_t, dev3n, devicen_t<3>, devicen_layout_t<3>)
  209. BOOST_GIL_DEFINE_ALL_TYPEDEFS_INTERNAL(32f, float32_t, dev3n, devicen_t<3>, devicen_layout_t<3>)
  210. BOOST_GIL_DEFINE_ALL_TYPEDEFS_INTERNAL(8, uint8_t, dev4n, devicen_t<4>, devicen_layout_t<4>)
  211. BOOST_GIL_DEFINE_ALL_TYPEDEFS_INTERNAL(8s, int8_t, dev4n, devicen_t<4>, devicen_layout_t<4>)
  212. BOOST_GIL_DEFINE_ALL_TYPEDEFS_INTERNAL(16, uint16_t, dev4n, devicen_t<4>, devicen_layout_t<4>)
  213. BOOST_GIL_DEFINE_ALL_TYPEDEFS_INTERNAL(16s, int16_t, dev4n, devicen_t<4>, devicen_layout_t<4>)
  214. BOOST_GIL_DEFINE_ALL_TYPEDEFS_INTERNAL(32, uint32_t, dev4n, devicen_t<4>, devicen_layout_t<4>)
  215. BOOST_GIL_DEFINE_ALL_TYPEDEFS_INTERNAL(32s, int32_t, dev4n, devicen_t<4>, devicen_layout_t<4>)
  216. BOOST_GIL_DEFINE_ALL_TYPEDEFS_INTERNAL(32f, float32_t, dev4n, devicen_t<4>, devicen_layout_t<4>)
  217. BOOST_GIL_DEFINE_ALL_TYPEDEFS_INTERNAL(8, uint8_t, dev5n, devicen_t<5>, devicen_layout_t<5>)
  218. BOOST_GIL_DEFINE_ALL_TYPEDEFS_INTERNAL(8s, int8_t, dev5n, devicen_t<5>, devicen_layout_t<5>)
  219. BOOST_GIL_DEFINE_ALL_TYPEDEFS_INTERNAL(16, uint16_t, dev5n, devicen_t<5>, devicen_layout_t<5>)
  220. BOOST_GIL_DEFINE_ALL_TYPEDEFS_INTERNAL(16s, int16_t, dev5n, devicen_t<5>, devicen_layout_t<5>)
  221. BOOST_GIL_DEFINE_ALL_TYPEDEFS_INTERNAL(32, uint32_t, dev5n, devicen_t<5>, devicen_layout_t<5>)
  222. BOOST_GIL_DEFINE_ALL_TYPEDEFS_INTERNAL(32s, int32_t, dev5n, devicen_t<5>, devicen_layout_t<5>)
  223. BOOST_GIL_DEFINE_ALL_TYPEDEFS_INTERNAL(32f, float32_t, dev5n, devicen_t<5>, devicen_layout_t<5>)
  224. }} // namespace boost::gil
  225. #endif