image.hpp 5.2 KB

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