is_allowed.hpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. //
  2. // Copyright 2009 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_RAW_DETAIL_IS_ALLOWED_HPP
  9. #define BOOST_GIL_EXTENSION_IO_RAW_DETAIL_IS_ALLOWED_HPP
  10. #include <boost/gil/extension/io/raw/tags.hpp>
  11. #include <boost/gil/io/base.hpp>
  12. #include <type_traits>
  13. namespace boost { namespace gil { namespace detail {
  14. template< typename View >
  15. bool is_allowed( const image_read_info< raw_tag >& info
  16. , std::true_type // is read_and_no_convert
  17. )
  18. {
  19. using pixel_t = typename get_pixel_type<View>::type;
  20. using num_channel_t = typename num_channels<pixel_t>::value_type;
  21. using channel_t = typename channel_traits<typename element_type<typename View::value_type>::type>::value_type;
  22. constexpr num_channel_t dst_samples_per_pixel = num_channels<pixel_t>::value;
  23. constexpr unsigned int dst_bits_per_pixel = detail::unsigned_integral_num_bits<channel_t>::value;
  24. constexpr bool is_type_signed = std::is_signed<channel_t>::value;
  25. return (dst_samples_per_pixel == info._samples_per_pixel &&
  26. dst_bits_per_pixel == static_cast<unsigned int>(info._bits_per_pixel) &&
  27. !is_type_signed);
  28. }
  29. template< typename View >
  30. bool is_allowed( const image_read_info< raw_tag >& /* info */
  31. , std::false_type // is read_and_convert
  32. )
  33. {
  34. return true;
  35. }
  36. } // namespace detail
  37. } // namespace gil
  38. } // namespace boost
  39. #endif