Imported Upstream version 1.72.0
[platform/upstream/boost.git] / boost / gil / extension / io / bmp / detail / supported_types.hpp
1 //
2 // Copyright 2008 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_SUPPORTED_TYPES_HPP
9 #define BOOST_GIL_EXTENSION_IO_BMP_DETAIL_SUPPORTED_TYPES_HPP
10
11 #include <boost/gil/extension/io/bmp/tags.hpp>
12
13 #include <boost/gil/bit_aligned_pixel_reference.hpp>
14 #include <boost/gil/channel.hpp>
15 #include <boost/gil/color_base.hpp>
16 #include <boost/gil/packed_pixel.hpp>
17 #include <boost/gil/io/base.hpp>
18
19 #include <type_traits>
20
21 namespace boost { namespace gil { namespace detail {
22
23 // Read support
24
25 template< typename Channel
26         , typename ColorSpace
27         >
28 struct bmp_read_support : read_support_false
29 {
30     static const bmp_bits_per_pixel::type bpp = 0;
31 };
32
33 template< typename BitField
34         , bool     Mutable
35         >
36 struct bmp_read_support< packed_dynamic_channel_reference< BitField
37                                                          , 1
38                                                          , Mutable
39                                                          >
40                        , gray_t
41                        > : read_support_true
42 {
43     static const bmp_bits_per_pixel::type bpp = 1;
44 };
45
46 template< typename BitField
47         , bool     Mutable
48         >
49 struct bmp_read_support< packed_dynamic_channel_reference< BitField
50                                                          , 4
51                                                          , Mutable
52                                                          >
53                        , gray_t
54                        > : read_support_true
55 {
56     static const bmp_bits_per_pixel::type bpp = 4;
57 };
58
59
60 template<>
61 struct bmp_read_support<uint8_t
62                        , gray_t
63                        > : read_support_true
64 {
65     static const bmp_bits_per_pixel::type bpp = 8;
66 };
67
68
69
70 template<>
71 struct bmp_read_support<uint8_t
72                        , rgb_t
73                        > : read_support_true
74 {
75     static const bmp_bits_per_pixel::type bpp = 24;
76 };
77
78
79 template<>
80 struct bmp_read_support<uint8_t
81                        , rgba_t
82                        > : read_support_true
83 {
84     static const bmp_bits_per_pixel::type bpp = 32;
85 };
86
87
88 // Write support
89
90 template< typename Channel
91         , typename ColorSpace
92         >
93 struct bmp_write_support : write_support_false
94 {};
95
96 template<>
97 struct bmp_write_support<uint8_t
98                         , rgb_t
99                         > : write_support_true {};
100
101 template<>
102 struct bmp_write_support<uint8_t
103                         , rgba_t
104                         > : write_support_true {};
105
106 } // namespace detail
107
108 template<typename Pixel>
109 struct is_read_supported<Pixel, bmp_tag>
110     : std::integral_constant
111     <
112         bool,
113         detail::bmp_read_support
114         <
115             typename channel_type<Pixel>::type,
116             typename color_space_type<Pixel>::type
117         >::is_supported
118     >
119 {
120     using parent_t = detail::bmp_read_support
121         <
122             typename channel_type<Pixel>::type,
123             typename color_space_type<Pixel>::type
124         >;
125
126     static const typename bmp_bits_per_pixel::type bpp = parent_t::bpp;
127 };
128
129 template<typename Pixel>
130 struct is_write_supported<Pixel, bmp_tag>
131     : std::integral_constant
132     <
133         bool,
134         detail::bmp_write_support
135         <
136             typename channel_type<Pixel>::type,
137             typename color_space_type<Pixel>::type
138         >::is_supported
139     >
140 {};
141
142 } // namespace gil
143 } // namespace boost
144
145 #endif