Imported Upstream version 1.72.0
[platform/upstream/boost.git] / boost / gil / extension / io / raw / 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_RAW_DETAIL_IS_ALLOWED_HPP
9 #define BOOST_GIL_EXTENSION_IO_RAW_DETAIL_IS_ALLOWED_HPP
10
11 #include <boost/gil/extension/io/raw/tags.hpp>
12 #include <boost/gil/io/base.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< raw_tag >& info
20                , std::true_type   // is read_and_no_convert
21                )
22 {
23     using pixel_t = typename get_pixel_type<View>::type;
24     using num_channel_t = typename num_channels<pixel_t>::value_type;
25     using channel_t = typename channel_traits<typename element_type<typename View::value_type>::type>::value_type;
26
27     constexpr num_channel_t dst_samples_per_pixel = num_channels<pixel_t>::value;
28     constexpr unsigned int dst_bits_per_pixel = detail::unsigned_integral_num_bits<channel_t>::value;
29     constexpr bool is_type_signed = std::is_signed<channel_t>::value;
30
31     return (dst_samples_per_pixel == info._samples_per_pixel &&
32             dst_bits_per_pixel == static_cast<unsigned int>(info._bits_per_pixel) &&
33             !is_type_signed);
34 }
35
36 template< typename View >
37 bool is_allowed( const image_read_info< raw_tag >& /* info */
38                , std::false_type  // is read_and_convert
39                )
40 {
41     return true;
42 }
43
44 } // namespace detail
45 } // namespace gil
46 } // namespace boost
47
48 #endif