typedefs.hpp 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. //
  2. // Copyright 2005-2007 Adobe Systems Incorporated
  3. // Copyright 2018 Mateusz Loskot <mateusz@loskot.net>
  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. // B - bits size/signedness, CM - channel model, CS - colour space, LAYOUT - pixel layout
  20. // Example: B = '8', CM = 'uint8_t', CS = 'bgr, LAYOUT='bgr_layout_t'
  21. #define GIL_DEFINE_BASE_TYPEDEFS_INTERNAL(B, CM, CS, LAYOUT) \
  22. template <typename, typename> struct pixel; \
  23. template <typename, typename> struct planar_pixel_reference; \
  24. template <typename, typename> struct planar_pixel_iterator; \
  25. template <typename> class memory_based_step_iterator; \
  26. template <typename> class point; \
  27. template <typename> class memory_based_2d_locator; \
  28. template <typename> class image_view; \
  29. template <typename, bool, typename> class image; \
  30. using CS##B##_pixel_t = pixel<CM, LAYOUT>; \
  31. using CS##B##c_pixel_t = pixel<CM, LAYOUT> const; \
  32. using CS##B##_ref_t = pixel<CM, LAYOUT>&; \
  33. using CS##B##c_ref_t = pixel<CM, LAYOUT> const&; \
  34. using CS##B##_ptr_t = CS##B##_pixel_t*; \
  35. using CS##B##c_ptr_t = CS##B##c_pixel_t*; \
  36. using CS##B##_step_ptr_t = memory_based_step_iterator<CS##B##_ptr_t>; \
  37. using CS##B##c_step_ptr_t = memory_based_step_iterator<CS##B##c_ptr_t>; \
  38. using CS##B##_loc_t \
  39. = memory_based_2d_locator<memory_based_step_iterator<CS##B##_ptr_t>>; \
  40. using CS##B##c_loc_t \
  41. = memory_based_2d_locator<memory_based_step_iterator<CS##B##c_ptr_t>>; \
  42. using CS##B##_step_loc_t \
  43. = memory_based_2d_locator<memory_based_step_iterator<CS##B##_step_ptr_t>>; \
  44. using CS##B##c_step_loc_t \
  45. = memory_based_2d_locator<memory_based_step_iterator<CS##B##c_step_ptr_t>>; \
  46. using CS##B##_view_t = image_view<CS##B##_loc_t>; \
  47. using CS##B##c_view_t = image_view<CS##B##c_loc_t>; \
  48. using CS##B##_step_view_t = image_view<CS##B##_step_loc_t>; \
  49. using CS##B##c_step_view_t = image_view<CS##B##c_step_loc_t>; \
  50. using CS##B##_image_t = image<CS##B##_pixel_t, false, std::allocator<unsigned char>>;
  51. // Example: B = '8', CM = 'uint8_t', CS = 'bgr' CS_FULL = 'rgb_t' LAYOUT='bgr_layout_t'
  52. #define GIL_DEFINE_ALL_TYPEDEFS_INTERNAL(B, CM, CS, CS_FULL, LAYOUT) \
  53. GIL_DEFINE_BASE_TYPEDEFS_INTERNAL(B, CM, CS, LAYOUT) \
  54. using CS##B##_planar_ref_t = planar_pixel_reference<CM&, CS_FULL>; \
  55. using CS##B##c_planar_ref_t = planar_pixel_reference<CM const&, CS_FULL>; \
  56. using CS##B##_planar_ptr_t = planar_pixel_iterator<CM*, CS_FULL>; \
  57. using CS##B##c_planar_ptr_t = planar_pixel_iterator<CM const*, CS_FULL>; \
  58. using CS##B##_planar_step_ptr_t = memory_based_step_iterator<CS##B##_planar_ptr_t>; \
  59. using CS##B##c_planar_step_ptr_t \
  60. = memory_based_step_iterator<CS##B##c_planar_ptr_t>; \
  61. using CS##B##_planar_loc_t \
  62. = memory_based_2d_locator<memory_based_step_iterator<CS##B##_planar_ptr_t>>; \
  63. using CS##B##c_planar_loc_t \
  64. = memory_based_2d_locator<memory_based_step_iterator<CS##B##c_planar_ptr_t>>; \
  65. using CS##B##_planar_step_loc_t \
  66. = memory_based_2d_locator<memory_based_step_iterator<CS##B##_planar_step_ptr_t>>; \
  67. using CS##B##c_planar_step_loc_t \
  68. = memory_based_2d_locator<memory_based_step_iterator<CS##B##c_planar_step_ptr_t>>; \
  69. using CS##B##_planar_view_t = image_view<CS##B##_planar_loc_t>; \
  70. using CS##B##c_planar_view_t = image_view<CS##B##c_planar_loc_t>; \
  71. using CS##B##_planar_step_view_t = image_view<CS##B##_planar_step_loc_t>; \
  72. using CS##B##c_planar_step_view_t = image_view<CS##B##c_planar_step_loc_t>; \
  73. using CS##B##_planar_image_t \
  74. = image<CS##B##_pixel_t, true, std::allocator<unsigned char>>;
  75. #define GIL_DEFINE_BASE_TYPEDEFS(B, CM, CS) \
  76. GIL_DEFINE_BASE_TYPEDEFS_INTERNAL(B, CM, CS, CS##_layout_t)
  77. #define GIL_DEFINE_ALL_TYPEDEFS(B, CM, CS) \
  78. GIL_DEFINE_ALL_TYPEDEFS_INTERNAL(B, CM, CS, CS##_t, CS##_layout_t)
  79. namespace boost { namespace gil {
  80. // forward declarations
  81. template <typename B, typename Mn, typename Mx> struct scoped_channel_value;
  82. template <typename T> struct float_point_zero;
  83. template <typename T> struct float_point_one;
  84. //////////////////////////////////////////////////////////////////////////////////////////
  85. /// Built-in channel models
  86. //////////////////////////////////////////////////////////////////////////////////////////
  87. /// \ingroup ChannelModel
  88. /// \brief 8-bit unsigned integral channel type (alias from uint8_t). Models ChannelValueConcept
  89. using std::uint8_t;
  90. /// \ingroup ChannelModel
  91. /// \brief 16-bit unsigned integral channel type (alias from uint16_t). Models ChannelValueConcept
  92. using std::uint16_t;
  93. /// \ingroup ChannelModel
  94. /// \brief 32-bit unsigned integral channel type (alias from uint32_t). Models ChannelValueConcept
  95. using std::uint32_t;
  96. /// \ingroup ChannelModel
  97. /// \brief 8-bit signed integral channel type (alias from int8_t). Models ChannelValueConcept
  98. using std::int8_t;
  99. /// \ingroup ChannelModel
  100. /// \brief 16-bit signed integral channel type (alias from int16_t). Models ChannelValueConcept
  101. using std::int16_t;
  102. /// \ingroup ChannelModel
  103. /// \brief 32-bit signed integral channel type (alias from int32_t). Models ChannelValueConcept
  104. using std::int32_t;
  105. /// \ingroup ChannelModel
  106. /// \brief 32-bit floating point channel type with range [0.0f ... 1.0f]. Models ChannelValueConcept
  107. using float32_t = scoped_channel_value<float, float_point_zero<float>, float_point_one<float>>;
  108. /// \ingroup ChannelModel
  109. /// \brief 64-bit floating point channel type with range [0.0f ... 1.0f]. Models ChannelValueConcept
  110. using float64_t = scoped_channel_value<double, float_point_zero<double>, float_point_one<double>>;
  111. GIL_DEFINE_BASE_TYPEDEFS(8, uint8_t, gray)
  112. GIL_DEFINE_BASE_TYPEDEFS(8s, int8_t, gray)
  113. GIL_DEFINE_BASE_TYPEDEFS(16, uint16_t, gray)
  114. GIL_DEFINE_BASE_TYPEDEFS(16s, int16_t, gray)
  115. GIL_DEFINE_BASE_TYPEDEFS(32, uint32_t, gray)
  116. GIL_DEFINE_BASE_TYPEDEFS(32s, int32_t, gray)
  117. GIL_DEFINE_BASE_TYPEDEFS(32f, float32_t, gray)
  118. GIL_DEFINE_BASE_TYPEDEFS(8, uint8_t, bgr)
  119. GIL_DEFINE_BASE_TYPEDEFS(8s, int8_t, bgr)
  120. GIL_DEFINE_BASE_TYPEDEFS(16, uint16_t, bgr)
  121. GIL_DEFINE_BASE_TYPEDEFS(16s, int16_t, bgr)
  122. GIL_DEFINE_BASE_TYPEDEFS(32, uint32_t, bgr)
  123. GIL_DEFINE_BASE_TYPEDEFS(32s, int32_t, bgr)
  124. GIL_DEFINE_BASE_TYPEDEFS(32f, float32_t, bgr)
  125. GIL_DEFINE_BASE_TYPEDEFS(8, uint8_t, argb)
  126. GIL_DEFINE_BASE_TYPEDEFS(8s, int8_t, argb)
  127. GIL_DEFINE_BASE_TYPEDEFS(16, uint16_t, argb)
  128. GIL_DEFINE_BASE_TYPEDEFS(16s, int16_t, argb)
  129. GIL_DEFINE_BASE_TYPEDEFS(32, uint32_t, argb)
  130. GIL_DEFINE_BASE_TYPEDEFS(32s, int32_t, argb)
  131. GIL_DEFINE_BASE_TYPEDEFS(32f, float32_t, argb)
  132. GIL_DEFINE_BASE_TYPEDEFS(8, uint8_t, abgr)
  133. GIL_DEFINE_BASE_TYPEDEFS(8s, int8_t, abgr)
  134. GIL_DEFINE_BASE_TYPEDEFS(16, uint16_t, abgr)
  135. GIL_DEFINE_BASE_TYPEDEFS(16s, int16_t, abgr)
  136. GIL_DEFINE_BASE_TYPEDEFS(32, uint32_t, abgr)
  137. GIL_DEFINE_BASE_TYPEDEFS(32s, int32_t, abgr)
  138. GIL_DEFINE_BASE_TYPEDEFS(32f, float32_t, abgr)
  139. GIL_DEFINE_BASE_TYPEDEFS(8, uint8_t, bgra)
  140. GIL_DEFINE_BASE_TYPEDEFS(8s, int8_t, bgra)
  141. GIL_DEFINE_BASE_TYPEDEFS(16, uint16_t, bgra)
  142. GIL_DEFINE_BASE_TYPEDEFS(16s, int16_t, bgra)
  143. GIL_DEFINE_BASE_TYPEDEFS(32, uint32_t, bgra)
  144. GIL_DEFINE_BASE_TYPEDEFS(32s, int32_t, bgra)
  145. GIL_DEFINE_BASE_TYPEDEFS(32f, float32_t, bgra)
  146. GIL_DEFINE_ALL_TYPEDEFS(8, uint8_t, rgb)
  147. GIL_DEFINE_ALL_TYPEDEFS(8s, int8_t, rgb)
  148. GIL_DEFINE_ALL_TYPEDEFS(16, uint16_t, rgb)
  149. GIL_DEFINE_ALL_TYPEDEFS(16s, int16_t, rgb)
  150. GIL_DEFINE_ALL_TYPEDEFS(32, uint32_t, rgb)
  151. GIL_DEFINE_ALL_TYPEDEFS(32s, int32_t, rgb)
  152. GIL_DEFINE_ALL_TYPEDEFS(32f, float32_t, rgb)
  153. GIL_DEFINE_ALL_TYPEDEFS(8, uint8_t, rgba)
  154. GIL_DEFINE_ALL_TYPEDEFS(8s, int8_t, rgba)
  155. GIL_DEFINE_ALL_TYPEDEFS(16, uint16_t, rgba)
  156. GIL_DEFINE_ALL_TYPEDEFS(16s, int16_t, rgba)
  157. GIL_DEFINE_ALL_TYPEDEFS(32, uint32_t, rgba)
  158. GIL_DEFINE_ALL_TYPEDEFS(32s, int32_t, rgba)
  159. GIL_DEFINE_ALL_TYPEDEFS(32f, float32_t, rgba)
  160. GIL_DEFINE_ALL_TYPEDEFS(8, uint8_t, cmyk)
  161. GIL_DEFINE_ALL_TYPEDEFS(8s, int8_t, cmyk)
  162. GIL_DEFINE_ALL_TYPEDEFS(16, uint16_t, cmyk)
  163. GIL_DEFINE_ALL_TYPEDEFS(16s, int16_t, cmyk)
  164. GIL_DEFINE_ALL_TYPEDEFS(32, uint32_t, cmyk)
  165. GIL_DEFINE_ALL_TYPEDEFS(32s, int32_t, cmyk)
  166. GIL_DEFINE_ALL_TYPEDEFS(32f, float32_t, cmyk)
  167. template <int N> struct devicen_t;
  168. template <int N> struct devicen_layout_t;
  169. GIL_DEFINE_ALL_TYPEDEFS_INTERNAL(8, uint8_t, dev2n, devicen_t<2>, devicen_layout_t<2>)
  170. GIL_DEFINE_ALL_TYPEDEFS_INTERNAL(8s, int8_t, dev2n, devicen_t<2>, devicen_layout_t<2>)
  171. GIL_DEFINE_ALL_TYPEDEFS_INTERNAL(16, uint16_t, dev2n, devicen_t<2>, devicen_layout_t<2>)
  172. GIL_DEFINE_ALL_TYPEDEFS_INTERNAL(16s, int16_t, dev2n, devicen_t<2>, devicen_layout_t<2>)
  173. GIL_DEFINE_ALL_TYPEDEFS_INTERNAL(32, uint32_t, dev2n, devicen_t<2>, devicen_layout_t<2>)
  174. GIL_DEFINE_ALL_TYPEDEFS_INTERNAL(32s, int32_t, dev2n, devicen_t<2>, devicen_layout_t<2>)
  175. GIL_DEFINE_ALL_TYPEDEFS_INTERNAL(32f, float32_t, dev2n, devicen_t<2>, devicen_layout_t<2>)
  176. GIL_DEFINE_ALL_TYPEDEFS_INTERNAL(8, uint8_t, dev3n, devicen_t<3>, devicen_layout_t<3>)
  177. GIL_DEFINE_ALL_TYPEDEFS_INTERNAL(8s, int8_t, dev3n, devicen_t<3>, devicen_layout_t<3>)
  178. GIL_DEFINE_ALL_TYPEDEFS_INTERNAL(16, uint16_t, dev3n, devicen_t<3>, devicen_layout_t<3>)
  179. GIL_DEFINE_ALL_TYPEDEFS_INTERNAL(16s, int16_t, dev3n, devicen_t<3>, devicen_layout_t<3>)
  180. GIL_DEFINE_ALL_TYPEDEFS_INTERNAL(32, uint32_t, dev3n, devicen_t<3>, devicen_layout_t<3>)
  181. GIL_DEFINE_ALL_TYPEDEFS_INTERNAL(32s, int32_t, dev3n, devicen_t<3>, devicen_layout_t<3>)
  182. GIL_DEFINE_ALL_TYPEDEFS_INTERNAL(32f, float32_t, dev3n, devicen_t<3>, devicen_layout_t<3>)
  183. GIL_DEFINE_ALL_TYPEDEFS_INTERNAL(8, uint8_t, dev4n, devicen_t<4>, devicen_layout_t<4>)
  184. GIL_DEFINE_ALL_TYPEDEFS_INTERNAL(8s, int8_t, dev4n, devicen_t<4>, devicen_layout_t<4>)
  185. GIL_DEFINE_ALL_TYPEDEFS_INTERNAL(16, uint16_t, dev4n, devicen_t<4>, devicen_layout_t<4>)
  186. GIL_DEFINE_ALL_TYPEDEFS_INTERNAL(16s, int16_t, dev4n, devicen_t<4>, devicen_layout_t<4>)
  187. GIL_DEFINE_ALL_TYPEDEFS_INTERNAL(32, uint32_t, dev4n, devicen_t<4>, devicen_layout_t<4>)
  188. GIL_DEFINE_ALL_TYPEDEFS_INTERNAL(32s, int32_t, dev4n, devicen_t<4>, devicen_layout_t<4>)
  189. GIL_DEFINE_ALL_TYPEDEFS_INTERNAL(32f, float32_t, dev4n, devicen_t<4>, devicen_layout_t<4>)
  190. GIL_DEFINE_ALL_TYPEDEFS_INTERNAL(8, uint8_t, dev5n, devicen_t<5>, devicen_layout_t<5>)
  191. GIL_DEFINE_ALL_TYPEDEFS_INTERNAL(8s, int8_t, dev5n, devicen_t<5>, devicen_layout_t<5>)
  192. GIL_DEFINE_ALL_TYPEDEFS_INTERNAL(16, uint16_t, dev5n, devicen_t<5>, devicen_layout_t<5>)
  193. GIL_DEFINE_ALL_TYPEDEFS_INTERNAL(16s, int16_t, dev5n, devicen_t<5>, devicen_layout_t<5>)
  194. GIL_DEFINE_ALL_TYPEDEFS_INTERNAL(32, uint32_t, dev5n, devicen_t<5>, devicen_layout_t<5>)
  195. GIL_DEFINE_ALL_TYPEDEFS_INTERNAL(32s, int32_t, dev5n, devicen_t<5>, devicen_layout_t<5>)
  196. GIL_DEFINE_ALL_TYPEDEFS_INTERNAL(32f, float32_t, dev5n, devicen_t<5>, devicen_layout_t<5>)
  197. }} // namespace boost::gil
  198. #endif