Imported Upstream version 1.72.0
[platform/upstream/boost.git] / boost / gil / extension / io / jpeg / detail / supported_types.hpp
1 //
2 // Copyright 2007-2008 Christian Henning, Andreas Pokorny, Lubomir Bourdev
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_JPEG_DETAIL_SUPPORTED_TYPES_HPP
9 #define BOOST_GIL_EXTENSION_IO_JPEG_DETAIL_SUPPORTED_TYPES_HPP
10
11 #include <boost/gil/extension/io/jpeg/tags.hpp>
12
13 #include <boost/gil/channel.hpp>
14 #include <boost/gil/color_base.hpp>
15
16 #include <type_traits>
17
18 namespace boost { namespace gil { namespace detail {
19
20 // Read support
21
22 template< jpeg_color_space::type ColorSpace >
23 struct jpeg_rw_support_base
24 {
25     static const jpeg_color_space::type _color_space = ColorSpace;
26 };
27
28 template< typename Channel
29         , typename ColorSpace
30         >
31 struct jpeg_read_support : read_support_false
32                          , jpeg_rw_support_base< JCS_UNKNOWN > {};
33
34 template<>
35 struct jpeg_read_support<uint8_t
36                         , rgb_t
37                         > : read_support_true
38                           , jpeg_rw_support_base< JCS_RGB > {};
39
40 template<>
41 struct jpeg_read_support<uint8_t
42                         , cmyk_t
43                         > : read_support_true
44                           , jpeg_rw_support_base< JCS_CMYK > {};
45
46 template<>
47 struct jpeg_read_support<uint8_t
48                         , gray_t
49                         > : read_support_true
50                           , jpeg_rw_support_base< JCS_GRAYSCALE > {};
51
52 // Write support
53
54 template< typename Channel
55         , typename ColorSpace
56         >
57 struct jpeg_write_support : write_support_false
58                           , jpeg_rw_support_base< JCS_UNKNOWN > {};
59
60 template<>
61 struct jpeg_write_support<uint8_t
62                          , gray_t
63                          > : write_support_true
64                           , jpeg_rw_support_base< JCS_GRAYSCALE > {};
65
66 template<>
67 struct jpeg_write_support<uint8_t
68                          , rgb_t
69                          > : write_support_true
70                           , jpeg_rw_support_base< JCS_RGB > {};
71
72 template<>
73 struct jpeg_write_support<uint8_t
74                          , cmyk_t
75                          > : write_support_true
76                           , jpeg_rw_support_base< JCS_CMYK > {};
77
78 } // namespace detail
79
80 template<typename Pixel>
81 struct is_read_supported<Pixel, jpeg_tag>
82     : std::integral_constant
83     <
84         bool,
85         detail::jpeg_read_support
86         <
87             typename channel_type<Pixel>::type,
88             typename color_space_type<Pixel>::type
89         >::is_supported
90     >
91 {
92     using parent_t = detail::jpeg_read_support
93         <
94             typename channel_type<Pixel>::type,
95             typename color_space_type<Pixel>::type
96         >;
97
98     static const typename jpeg_color_space::type _color_space = parent_t::_color_space;
99 };
100
101 template<typename Pixel>
102 struct is_write_supported<Pixel, jpeg_tag>
103     : std::integral_constant
104     <
105         bool,
106         detail::jpeg_write_support
107         <
108             typename channel_type<Pixel>::type,
109             typename color_space_type<Pixel>::type
110         >::is_supported
111     >
112 {};
113
114 } // namespace gil
115 } // namespace boost
116
117 #endif