image.hpp 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. //
  2. // Copyright 2005-2007 Adobe Systems Incorporated
  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. #ifndef BOOST_GIL_CONCEPTS_IMAGE_HPP
  9. #define BOOST_GIL_CONCEPTS_IMAGE_HPP
  10. #include <boost/gil/concepts/basic.hpp>
  11. #include <boost/gil/concepts/concept_check.hpp>
  12. #include <boost/gil/concepts/fwd.hpp>
  13. #include <boost/gil/concepts/image_view.hpp>
  14. #include <boost/gil/concepts/point.hpp>
  15. #include <boost/gil/detail/mp11.hpp>
  16. #include <type_traits>
  17. #if defined(BOOST_CLANG)
  18. #pragma clang diagnostic push
  19. #pragma clang diagnostic ignored "-Wunknown-pragmas"
  20. #pragma clang diagnostic ignored "-Wunused-local-typedefs"
  21. #endif
  22. #if defined(BOOST_GCC) && (BOOST_GCC >= 40900)
  23. #pragma GCC diagnostic push
  24. #pragma GCC diagnostic ignored "-Wunused-local-typedefs"
  25. #endif
  26. namespace boost { namespace gil {
  27. /// \ingroup ImageConcept
  28. /// \brief N-dimensional container of values
  29. ///
  30. /// \code
  31. /// concept RandomAccessNDImageConcept<typename Image> : Regular<Image>
  32. /// {
  33. /// typename view_t; where MutableRandomAccessNDImageViewConcept<view_t>;
  34. /// typename const_view_t = view_t::const_t;
  35. /// typename point_t = view_t::point_t;
  36. /// typename value_type = view_t::value_type;
  37. /// typename allocator_type;
  38. ///
  39. /// Image::Image(point_t dims, std::size_t alignment=1);
  40. /// Image::Image(point_t dims, value_type fill_value, std::size_t alignment);
  41. ///
  42. /// void Image::recreate(point_t new_dims, std::size_t alignment=1);
  43. /// void Image::recreate(point_t new_dims, value_type fill_value, std::size_t alignment);
  44. ///
  45. /// const point_t& Image::dimensions() const;
  46. /// const const_view_t& const_view(const Image&);
  47. /// const view_t& view(Image&);
  48. /// };
  49. /// \endcode
  50. template <typename Image>
  51. struct RandomAccessNDImageConcept
  52. {
  53. void constraints()
  54. {
  55. gil_function_requires<Regular<Image>>();
  56. using view_t = typename Image::view_t;
  57. gil_function_requires<MutableRandomAccessNDImageViewConcept<view_t>>();
  58. using const_view_t = typename Image::const_view_t;
  59. using pixel_t = typename Image::value_type;
  60. using point_t = typename Image::point_t;
  61. gil_function_requires<PointNDConcept<point_t>>();
  62. const_view_t cv = const_view(image);
  63. ignore_unused_variable_warning(cv);
  64. view_t v = view(image);
  65. ignore_unused_variable_warning(v);
  66. pixel_t fill_value;
  67. point_t pt = image.dimensions();
  68. Image image1(pt);
  69. Image image2(pt, 1);
  70. Image image3(pt, fill_value, 1);
  71. image.recreate(pt);
  72. image.recreate(pt, 1);
  73. image.recreate(pt, fill_value, 1);
  74. }
  75. Image image;
  76. };
  77. /// \ingroup ImageConcept
  78. /// \brief 2-dimensional container of values
  79. ///
  80. /// \code
  81. /// concept RandomAccess2DImageConcept<RandomAccessNDImageConcept Image>
  82. /// {
  83. /// typename x_coord_t = const_view_t::x_coord_t;
  84. /// typename y_coord_t = const_view_t::y_coord_t;
  85. ///
  86. /// Image::Image(x_coord_t width, y_coord_t height, std::size_t alignment=1);
  87. /// Image::Image(x_coord_t width, y_coord_t height, value_type fill_value, std::size_t alignment);
  88. ///
  89. /// x_coord_t Image::width() const;
  90. /// y_coord_t Image::height() const;
  91. ///
  92. /// void Image::recreate(x_coord_t width, y_coord_t height, std::size_t alignment=1);
  93. /// void Image::recreate(x_coord_t width, y_coord_t height, value_type fill_value, std::size_t alignment);
  94. /// };
  95. /// \endcode
  96. template <typename Image>
  97. struct RandomAccess2DImageConcept
  98. {
  99. void constraints()
  100. {
  101. gil_function_requires<RandomAccessNDImageConcept<Image>>();
  102. using x_coord_t = typename Image::x_coord_t;
  103. using y_coord_t = typename Image::y_coord_t;
  104. using value_t = typename Image::value_type;
  105. gil_function_requires<MutableRandomAccess2DImageViewConcept<typename Image::view_t>>();
  106. x_coord_t w=image.width();
  107. y_coord_t h=image.height();
  108. value_t fill_value;
  109. Image im1(w,h);
  110. Image im2(w,h,1);
  111. Image im3(w,h,fill_value,1);
  112. image.recreate(w,h);
  113. image.recreate(w,h,1);
  114. image.recreate(w,h,fill_value,1);
  115. }
  116. Image image;
  117. };
  118. /// \ingroup ImageConcept
  119. /// \brief 2-dimensional image whose value type models PixelValueConcept
  120. ///
  121. /// \code
  122. /// concept ImageConcept<RandomAccess2DImageConcept Image>
  123. /// {
  124. /// where MutableImageViewConcept<view_t>;
  125. /// typename coord_t = view_t::coord_t;
  126. /// };
  127. /// \endcode
  128. template <typename Image>
  129. struct ImageConcept
  130. {
  131. void constraints()
  132. {
  133. gil_function_requires<RandomAccess2DImageConcept<Image>>();
  134. gil_function_requires<MutableImageViewConcept<typename Image::view_t>>();
  135. using coord_t = typename Image::coord_t;
  136. static_assert(num_channels<Image>::value == mp11::mp_size<typename color_space_type<Image>::type>::value, "");
  137. static_assert(std::is_same<coord_t, typename Image::x_coord_t>::value, "");
  138. static_assert(std::is_same<coord_t, typename Image::y_coord_t>::value, "");
  139. }
  140. Image image;
  141. };
  142. }} // namespace boost::gil
  143. #if defined(BOOST_CLANG)
  144. #pragma clang diagnostic pop
  145. #endif
  146. #if defined(BOOST_GCC) && (BOOST_GCC >= 40900)
  147. #pragma GCC diagnostic pop
  148. #endif
  149. #endif