File indexing completed on 2025-12-17 09:47:31
0001
0002
0003
0004
0005
0006
0007
0008 #ifndef BOOST_GIL_EXTENSION_IO_BMP_DETAIL_IS_ALLOWED_HPP
0009 #define BOOST_GIL_EXTENSION_IO_BMP_DETAIL_IS_ALLOWED_HPP
0010
0011 #include <boost/gil/extension/io/bmp/tags.hpp>
0012 #include <boost/gil/channel.hpp>
0013
0014 #include <type_traits>
0015
0016 namespace boost { namespace gil { namespace detail {
0017
0018 template< typename View >
0019 bool is_allowed( const image_read_info< bmp_tag >& info
0020 , std::true_type
0021 )
0022 {
0023 bmp_bits_per_pixel::type src_bits_per_pixel = 0;
0024
0025 switch( info._bits_per_pixel )
0026 {
0027 case 1:
0028 case 4:
0029 case 8:
0030 {
0031 if( info._header_size == bmp_header_size::_win32_info_size
0032 && info._compression != bmp_compression::_rle8
0033 && info._compression != bmp_compression::_rle4
0034 )
0035 {
0036 src_bits_per_pixel = 32;
0037 }
0038 else
0039 {
0040 src_bits_per_pixel = 24;
0041 }
0042
0043 break;
0044 }
0045
0046 case 15:
0047 case 16:
0048 {
0049 src_bits_per_pixel = 24;
0050
0051 break;
0052 }
0053
0054 case 24:
0055 case 32:
0056 {
0057 src_bits_per_pixel = info._bits_per_pixel;
0058
0059 break;
0060 }
0061 default:
0062 {
0063 io_error( "Pixel size not supported." );
0064 }
0065 }
0066
0067 using channel_t = typename channel_traits<typename element_type<typename View::value_type>::type>::value_type;
0068 bmp_bits_per_pixel::type dst_bits_per_pixel = detail::unsigned_integral_num_bits< channel_t >::value
0069 * num_channels< View >::value;
0070
0071 return ( dst_bits_per_pixel == src_bits_per_pixel );
0072 }
0073
0074 template< typename View >
0075 bool is_allowed( const image_read_info< bmp_tag >&
0076 , std::false_type
0077 )
0078 {
0079 return true;
0080 }
0081
0082 }
0083 }
0084 }
0085
0086 #endif