1 // 2 // Copyright 2019 Mateusz Loskot <mateusz at loskot dot net> 3 // Copyright 2005-2007 Adobe Systems Incorporated 4 // 5 // Distributed under the Boost Software License, Version 1.0 6 // See accompanying file LICENSE_1_0.txt or copy at 7 // http://www.boost.org/LICENSE_1_0.txt 8 // 9 #include <boost/gil/channel.hpp> 10 #include <boost/gil/color_base_algorithm.hpp> 11 #include <boost/gil/concepts/pixel.hpp> 12 #include <boost/gil/pixel.hpp> 13 #include <boost/gil/planar_pixel_reference.hpp> 14 #include <boost/gil/promote_integral.hpp> 15 #include <boost/gil/typedefs.hpp> 16 17 #include <boost/core/ignore_unused.hpp> 18 #include <boost/mp11.hpp> 19 #include <boost/mp11/mpl.hpp> // for compatibility with Boost.Test 20 21 #include <cstdint> 22 #include <iostream> 23 #include <tuple> 24 #include <type_traits> 25 26 namespace boost { namespace gil { 27 28 namespace test { namespace fixture { 29 30 template <typename Pixel, int Tag = 0> 31 class pixel_value 32 { 33 public: 34 using type = Pixel; 35 using pixel_t = type; 36 type pixel_{}; 37 38 pixel_value() = default; pixel_value(pixel_t const & pixel)39 explicit pixel_value(pixel_t const& pixel) 40 : pixel_(pixel) // test copy constructor 41 { 42 type temp_pixel; // test default constructor 43 boost::ignore_unused(temp_pixel); 44 boost::function_requires<PixelValueConcept<pixel_t> >(); 45 } 46 }; 47 48 // Alias compatible with naming of equivalent class in the test/legacy/pixel.cpp 49 // The core suffix indicates `Pixel` is GIL core pixel type. 50 template <typename Pixel, int Tag = 0> 51 using value_core = pixel_value<Pixel, Tag>; 52 53 template <typename PixelRef, int Tag = 0> 54 struct pixel_reference 55 : pixel_value 56 < 57 typename std::remove_reference<PixelRef>::type, 58 Tag 59 > 60 { 61 static_assert( 62 std::is_reference<PixelRef>::value || 63 gil::is_planar<PixelRef>::value, // poor-man test for specialization of planar_pixel_reference 64 "PixelRef must be reference or gil::planar_pixel_reference"); 65 66 using type = PixelRef; 67 using pixel_t = typename std::remove_reference<PixelRef>::type; 68 using parent_t = pixel_value<typename pixel_t::value_type, Tag>; 69 using value_t = typename pixel_t::value_type; 70 type pixel_{}; // reference 71 pixel_referenceboost::gil::test::fixture::pixel_reference72 pixel_reference() : parent_t{}, pixel_(parent_t::pixel_) {} pixel_referenceboost::gil::test::fixture::pixel_reference73 explicit pixel_reference(value_t const& pixel) : parent_t(pixel), pixel_(parent_t::pixel_) 74 { 75 boost::function_requires<PixelConcept<pixel_t>>(); 76 } 77 }; 78 79 // Alias compatible with naming of equivalent class in the test/legacy/pixel.cpp 80 // The core suffix indicates `Pixel` is GIL core pixel type. 81 template <typename Pixel, int Tag = 0> 82 using reference_core = pixel_reference<Pixel, Tag>; 83 84 // Metafunction to yield nested type of a representative pixel type 85 template <typename PixelValueOrReference> 86 using nested_type = typename PixelValueOrReference::type; 87 88 // Metafunction to yield nested type of a representative pixel_t type 89 template <typename PixelValueOrReference> 90 using nested_pixel_type = typename PixelValueOrReference::pixel_t; 91 92 // Subset of pixel models that covers all color spaces, channel depths, 93 // reference/value, planar/interleaved, const/mutable. 94 // Operations like color conversion will be invoked on pairs of those. 95 using representative_pixel_types= ::boost::mp11::mp_list 96 < 97 value_core<gil::gray8_pixel_t>, 98 reference_core<gil::gray16_pixel_t&>, 99 value_core<gil::bgr8_pixel_t>, 100 reference_core<gil::rgb8_planar_ref_t>, 101 value_core<gil::argb32_pixel_t>, 102 reference_core<gil::cmyk32f_pixel_t&>, 103 reference_core<gil::abgr16c_ref_t>, // immutable reference 104 reference_core<gil::rgb32fc_planar_ref_t> 105 >; 106 107 108 // List of all integer-based core pixel typedefs (i.e. with cv-qualifiers) 109 using pixel_integer_types = ::boost::mp11::mp_list 110 < 111 gil::gray8_pixel_t, 112 gil::gray8s_pixel_t, 113 gil::gray16_pixel_t, 114 gil::gray16s_pixel_t, 115 gil::gray32_pixel_t, 116 gil::gray32s_pixel_t, 117 gil::bgr8_pixel_t, 118 gil::bgr8s_pixel_t, 119 gil::bgr16_pixel_t, 120 gil::bgr16s_pixel_t, 121 gil::bgr32_pixel_t, 122 gil::bgr32s_pixel_t, 123 gil::rgb8_pixel_t, 124 gil::rgb8s_pixel_t, 125 gil::rgb16_pixel_t, 126 gil::rgb16s_pixel_t, 127 gil::rgb32_pixel_t, 128 gil::rgb32s_pixel_t, 129 gil::abgr8_pixel_t, 130 gil::abgr8s_pixel_t, 131 gil::abgr16_pixel_t, 132 gil::abgr16s_pixel_t, 133 gil::abgr32_pixel_t, 134 gil::abgr32s_pixel_t, 135 gil::bgra8_pixel_t, 136 gil::bgra8s_pixel_t, 137 gil::bgra16_pixel_t, 138 gil::bgra16s_pixel_t, 139 gil::bgra32_pixel_t, 140 gil::bgra32s_pixel_t, 141 gil::cmyk8_pixel_t, 142 gil::cmyk8s_pixel_t, 143 gil::cmyk16_pixel_t, 144 gil::cmyk16s_pixel_t, 145 gil::cmyk32_pixel_t, 146 gil::cmyk32s_pixel_t, 147 gil::rgba8_pixel_t, 148 gil::rgba8s_pixel_t, 149 gil::rgba16_pixel_t, 150 gil::rgba16s_pixel_t, 151 gil::rgba32_pixel_t, 152 gil::rgba32s_pixel_t 153 >; 154 155 // List of all integer-based core pixel typedefs (i.e. with cv-qualifiers) 156 using pixel_float_types = ::boost::mp11::mp_list 157 < 158 gil::gray32f_pixel_t, 159 gil::bgr32f_pixel_t, 160 gil::rgb32f_pixel_t, 161 gil::abgr32f_pixel_t, 162 gil::bgra32f_pixel_t, 163 gil::cmyk32f_pixel_t, 164 gil::rgba32f_pixel_t 165 >; 166 167 168 // List of all core pixel types (i.e. without cv-qualifiers) 169 using pixel_types = ::boost::mp11::mp_append 170 < 171 pixel_integer_types, 172 pixel_float_types 173 >; 174 175 // List of all core pixel typedefs (i.e. with cv-qualifiers) 176 using pixel_typedefs = ::boost::mp11::mp_append 177 < 178 pixel_integer_types, 179 pixel_float_types, 180 ::boost::mp11::mp_list 181 < 182 gil::gray8c_pixel_t, 183 gil::gray8sc_pixel_t, 184 gil::gray16c_pixel_t, 185 gil::gray16sc_pixel_t, 186 gil::gray32c_pixel_t, 187 gil::gray32fc_pixel_t, 188 gil::gray32sc_pixel_t, 189 gil::bgr8c_pixel_t, 190 gil::bgr8sc_pixel_t, 191 gil::bgr16c_pixel_t, 192 gil::bgr16sc_pixel_t, 193 gil::bgr32c_pixel_t, 194 gil::bgr32fc_pixel_t, 195 gil::bgr32sc_pixel_t, 196 gil::rgb8c_pixel_t, 197 gil::rgb8sc_pixel_t, 198 gil::rgb16c_pixel_t, 199 gil::rgb16sc_pixel_t, 200 gil::rgb32c_pixel_t, 201 gil::rgb32fc_pixel_t, 202 gil::rgb32sc_pixel_t, 203 gil::abgr8c_pixel_t, 204 gil::abgr8sc_pixel_t, 205 gil::abgr16c_pixel_t, 206 gil::abgr16sc_pixel_t, 207 gil::abgr32c_pixel_t, 208 gil::abgr32fc_pixel_t, 209 gil::abgr32sc_pixel_t, 210 gil::bgra8c_pixel_t, 211 gil::bgra8sc_pixel_t, 212 gil::bgra16c_pixel_t, 213 gil::bgra16sc_pixel_t, 214 gil::bgra32c_pixel_t, 215 gil::bgra32fc_pixel_t, 216 gil::bgra32sc_pixel_t, 217 gil::cmyk8c_pixel_t, 218 gil::cmyk8sc_pixel_t, 219 gil::cmyk16c_pixel_t, 220 gil::cmyk16sc_pixel_t, 221 gil::cmyk32c_pixel_t, 222 gil::cmyk32fc_pixel_t, 223 gil::cmyk32sc_pixel_t, 224 gil::rgba8c_pixel_t, 225 gil::rgba8sc_pixel_t, 226 gil::rgba16c_pixel_t, 227 gil::rgba16sc_pixel_t, 228 gil::rgba32c_pixel_t, 229 gil::rgba32fc_pixel_t, 230 gil::rgba32sc_pixel_t 231 > 232 >; 233 234 struct not_a_pixel_type {}; 235 236 using non_pixels = ::boost::mp11::mp_list 237 < 238 not_a_pixel_type, 239 char, 240 short, int, long, 241 double, float, 242 std::size_t, 243 std::true_type, 244 std::false_type 245 >; 246 247 248 }}}} // namespace boost::gil::test::fixture 249