is_allowed.hpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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_BMP_DETAIL_IS_ALLOWED_HPP
  9. #define BOOST_GIL_EXTENSION_IO_BMP_DETAIL_IS_ALLOWED_HPP
  10. #include <boost/gil/extension/io/bmp/tags.hpp>
  11. #include <boost/gil/channel.hpp>
  12. #include <type_traits>
  13. namespace boost { namespace gil { namespace detail {
  14. template< typename View >
  15. bool is_allowed( const image_read_info< bmp_tag >& info
  16. , std::true_type // is read_and_no_convert
  17. )
  18. {
  19. bmp_bits_per_pixel::type src_bits_per_pixel = 0;
  20. switch( info._bits_per_pixel )
  21. {
  22. case 1:
  23. case 4:
  24. case 8:
  25. {
  26. if( info._header_size == bmp_header_size::_win32_info_size
  27. && info._compression != bmp_compression::_rle8
  28. && info._compression != bmp_compression::_rle4
  29. )
  30. {
  31. src_bits_per_pixel = 32;
  32. }
  33. else
  34. {
  35. src_bits_per_pixel = 24;
  36. }
  37. break;
  38. }
  39. case 15:
  40. case 16:
  41. {
  42. src_bits_per_pixel = 24;
  43. break;
  44. }
  45. case 24:
  46. case 32:
  47. {
  48. src_bits_per_pixel = info._bits_per_pixel;
  49. break;
  50. }
  51. default:
  52. {
  53. io_error( "Pixel size not supported." );
  54. }
  55. }
  56. using channel_t = typename channel_traits<typename element_type<typename View::value_type>::type>::value_type;
  57. bmp_bits_per_pixel::type dst_bits_per_pixel = detail::unsigned_integral_num_bits< channel_t >::value
  58. * num_channels< View >::value;
  59. return ( dst_bits_per_pixel == src_bits_per_pixel );
  60. }
  61. template< typename View >
  62. bool is_allowed( const image_read_info< bmp_tag >& /* info */
  63. , std::false_type // is read_and_convert
  64. )
  65. {
  66. return true;
  67. }
  68. } // namespace detail
  69. } // namespace gil
  70. } // namespace boost
  71. #endif