is_allowed.hpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. //
  2. // Copyright 2008 Christian Henning, Lubomir Bourdev
  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_PNG_DETAIL_IS_ALLOWED_HPP
  9. #define BOOST_GIL_EXTENSION_IO_PNG_DETAIL_IS_ALLOWED_HPP
  10. #include <boost/gil/extension/io/png/tags.hpp>
  11. #include <type_traits>
  12. namespace boost { namespace gil { namespace detail {
  13. template< typename View >
  14. bool is_allowed( const image_read_info< png_tag >& info
  15. , std::true_type // is read_and_no_convert
  16. )
  17. {
  18. using pixel_t = typename get_pixel_type<View>::type;
  19. using channel_t = typename channel_traits<typename element_type<pixel_t>::type>::value_type;
  20. const png_num_channels::type dst_num_channels = num_channels< pixel_t >::value;
  21. const png_bitdepth::type dst_bit_depth = detail::unsigned_integral_num_bits< channel_t >::value;
  22. return dst_num_channels == info._num_channels
  23. && dst_bit_depth == info._bit_depth;
  24. }
  25. template< typename View >
  26. bool is_allowed( const image_read_info< png_tag >& /* info */
  27. , std::false_type // is read_and_convert
  28. )
  29. {
  30. return true;
  31. }
  32. } // namespace detail
  33. } // namespace gil
  34. } // namespace boost
  35. #endif