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