is_allowed.hpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. //
  2. // Copyright 2010 Kenneth Riddile
  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_TARGA_DETAIL_IS_ALLOWED_HPP
  9. #define BOOST_GIL_EXTENSION_IO_TARGA_DETAIL_IS_ALLOWED_HPP
  10. #include <boost/gil/extension/io/targa/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< targa_tag >& info
  15. , std::true_type // is read_and_no_convert
  16. )
  17. {
  18. targa_depth::type src_bits_per_pixel = 0;
  19. switch( info._bits_per_pixel )
  20. {
  21. case 24:
  22. case 32:
  23. {
  24. src_bits_per_pixel = info._bits_per_pixel;
  25. break;
  26. }
  27. default:
  28. {
  29. io_error( "Pixel size not supported." );
  30. break;
  31. }
  32. }
  33. using channel_t = typename channel_traits<typename element_type<typename View::value_type>::type>::value_type;
  34. targa_depth::type dst_bits_per_pixel = detail::unsigned_integral_num_bits< channel_t >::value * num_channels< View >::value;
  35. return ( dst_bits_per_pixel == src_bits_per_pixel );
  36. }
  37. template< typename View >
  38. bool is_allowed( const image_read_info< targa_tag >& /* info */
  39. , std::false_type // is read_and_convert
  40. )
  41. {
  42. return true;
  43. }
  44. } // namespace detail
  45. } // namespace gil
  46. } // namespace boost
  47. #endif