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