Imported Upstream version 1.72.0
[platform/upstream/boost.git] / boost / gil / extension / io / targa / detail / is_allowed.hpp
1 //
2 // Copyright 2010 Kenneth Riddile
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_TARGA_DETAIL_IS_ALLOWED_HPP
9 #define BOOST_GIL_EXTENSION_IO_TARGA_DETAIL_IS_ALLOWED_HPP
10
11 #include <boost/gil/extension/io/targa/tags.hpp>
12
13 #include <type_traits>
14
15 namespace boost { namespace gil { namespace detail {
16
17 template< typename View >
18 bool is_allowed( const image_read_info< targa_tag >& info
19                , std::true_type   // is read_and_no_convert
20                )
21 {
22     targa_depth::type src_bits_per_pixel = 0;
23
24     switch( info._bits_per_pixel )
25     {
26         case 24:
27         case 32:
28         {
29             src_bits_per_pixel = info._bits_per_pixel;
30             break;
31         }
32         default:
33         {
34             io_error( "Pixel size not supported." );
35             break;
36         }
37     }
38
39     using channel_t = typename channel_traits<typename element_type<typename View::value_type>::type>::value_type;
40     targa_depth::type dst_bits_per_pixel = detail::unsigned_integral_num_bits< channel_t >::value * num_channels< View >::value;
41
42     return ( dst_bits_per_pixel == src_bits_per_pixel );
43 }
44
45 template< typename View >
46 bool is_allowed( const image_read_info< targa_tag >& /* info */
47                , std::false_type  // is read_and_convert
48                )
49 {
50     return true;
51 }
52
53 } // namespace detail
54 } // namespace gil
55 } // namespace boost
56
57 #endif