supported_types.hpp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. //
  2. // Copyright 2008 Christian Henning
  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_EXTENSION_IO_PNM_DETAIL_SUPPORTED_TYPES_HPP
  9. #define BOOST_GIL_EXTENSION_IO_PNM_DETAIL_SUPPORTED_TYPES_HPP
  10. #include <boost/gil/extension/io/pnm/tags.hpp>
  11. #include <boost/gil/channel.hpp>
  12. #include <boost/gil/color_base.hpp>
  13. #include <boost/gil/io/base.hpp>
  14. #include <type_traits>
  15. namespace boost { namespace gil { namespace detail {
  16. // Read Support
  17. template< pnm_image_type::type ASCII_Type
  18. , pnm_image_type::type Binary_Type
  19. >
  20. struct pnm_rw_support_base
  21. {
  22. static const pnm_image_type::type _asc_type = ASCII_Type;
  23. static const pnm_image_type::type _bin_type = Binary_Type;
  24. };
  25. template< typename Channel
  26. , typename ColorSpace
  27. >
  28. struct pnm_read_support : read_support_false
  29. , pnm_rw_support_base< 0
  30. , 0
  31. > {};
  32. template< typename BitField, bool Mutable >
  33. struct pnm_read_support< packed_dynamic_channel_reference< BitField
  34. , 1
  35. , Mutable
  36. >
  37. , gray_t
  38. > : read_support_true
  39. , pnm_rw_support_base< pnm_image_type::mono_asc_t::value
  40. , pnm_image_type::mono_bin_t::value
  41. > {};
  42. template<>
  43. struct pnm_read_support<uint8_t
  44. , gray_t
  45. > : read_support_true
  46. , pnm_rw_support_base< pnm_image_type::gray_asc_t::value
  47. , pnm_image_type::gray_bin_t::value
  48. > {};
  49. template<>
  50. struct pnm_read_support<uint8_t
  51. , rgb_t
  52. > : read_support_true
  53. , pnm_rw_support_base< pnm_image_type::color_asc_t::value
  54. , pnm_image_type::color_bin_t::value
  55. > {};
  56. // Write support
  57. template< typename Channel
  58. , typename ColorSpace
  59. >
  60. struct pnm_write_support : write_support_false
  61. {};
  62. template< typename BitField, bool Mutable >
  63. struct pnm_write_support< packed_dynamic_channel_reference< BitField
  64. , 1
  65. , Mutable
  66. >
  67. , gray_t
  68. > : write_support_true
  69. , pnm_rw_support_base< pnm_image_type::mono_asc_t::value
  70. , pnm_image_type::mono_bin_t::value
  71. > {};
  72. template<>
  73. struct pnm_write_support<uint8_t
  74. , gray_t
  75. > : write_support_true
  76. , pnm_rw_support_base< pnm_image_type::gray_asc_t::value
  77. , pnm_image_type::gray_bin_t::value
  78. > {};
  79. template<>
  80. struct pnm_write_support<uint8_t
  81. , rgb_t
  82. > : write_support_true
  83. , pnm_rw_support_base< pnm_image_type::color_asc_t::value
  84. , pnm_image_type::color_bin_t::value
  85. > {};
  86. } // namespace detail
  87. template<typename Pixel>
  88. struct is_read_supported<Pixel, pnm_tag>
  89. : std::integral_constant
  90. <
  91. bool,
  92. detail::pnm_read_support
  93. <
  94. typename channel_type<Pixel>::type,
  95. typename color_space_type<Pixel>::type
  96. >::is_supported
  97. >
  98. {
  99. using parent_t = detail::pnm_read_support
  100. <
  101. typename channel_type<Pixel>::type,
  102. typename color_space_type<Pixel>::type
  103. >;
  104. static const pnm_image_type::type _asc_type = parent_t::_asc_type;
  105. static const pnm_image_type::type _bin_type = parent_t::_bin_type;
  106. };
  107. template<typename Pixel>
  108. struct is_write_supported<Pixel, pnm_tag>
  109. : std::integral_constant
  110. <
  111. bool,
  112. detail::pnm_write_support
  113. <
  114. typename channel_type<Pixel>::type,
  115. typename color_space_type<Pixel>::type
  116. >::is_supported
  117. >
  118. {};
  119. } // namespace gil
  120. } // namespace boost
  121. #endif