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