File: test_fixture.hpp

package info (click to toggle)
boost1.74 1.74.0-9
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 464,084 kB
  • sloc: cpp: 3,338,324; xml: 131,293; python: 33,088; ansic: 14,336; asm: 4,034; sh: 3,351; makefile: 1,193; perl: 1,036; yacc: 478; php: 212; ruby: 102; lisp: 24; sql: 13; csh: 6
file content (346 lines) | stat: -rw-r--r-- 9,889 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
//
// Copyright 2019 Mateusz Loskot <mateusz at loskot dot net>
// Copyright 2005-2007 Adobe Systems Incorporated
//
// Distributed under the Boost Software License, Version 1.0
// See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt
//
#ifndef BOOST_GIL_TEST_CORE_PIXEL_TEST_FIXTURE_HPP
#define BOOST_GIL_TEST_CORE_PIXEL_TEST_FIXTURE_HPP

#include <boost/gil/channel.hpp>
#include <boost/gil/color_base_algorithm.hpp>
#include <boost/gil/concepts/pixel.hpp>
#include <boost/gil/packed_pixel.hpp>
#include <boost/gil/pixel.hpp>
#include <boost/gil/planar_pixel_reference.hpp>
#include <boost/gil/promote_integral.hpp>
#include <boost/gil/typedefs.hpp>
#include <boost/gil/extension/toolbox/metafunctions/channel_type.hpp> // channel_type for packed and bit-aligned pixels

#include <boost/core/ignore_unused.hpp>
#include <boost/mp11.hpp>
#include <boost/mp11/mpl.hpp> // for compatibility with Boost.Test

#include <cstdint>
#include <iterator>
#include <tuple>
#include <type_traits>

#include "core/test_fixture.hpp" // random_value
#include "core/channel/test_fixture.hpp" // channel_minmax_value

namespace boost { namespace gil { namespace test { namespace fixture {

template <typename Pixel>
struct pixel_generator
{
    using channel_t = typename gil::channel_type<Pixel>::type;

    static auto max() -> Pixel
    {
        channel_minmax_value<channel_t> channel;
        Pixel pixel;
        gil::static_fill(pixel, channel.max_v_);
        return pixel;
    }

    static auto min()-> Pixel
    {
        channel_minmax_value<channel_t> channel;
        Pixel pixel;
        gil::static_fill(pixel, channel.min_v_);
        return pixel;
    }

    static auto random() -> Pixel
    {
        random_value<channel_t> generate;
        Pixel pixel;
        gil::static_generate(pixel, [&generate]() { return generate(); });
        return pixel;
    }
};

template <typename Pixel, int Tag = 0>
class pixel_value
{
public:
    using type = Pixel;
    using pixel_t = type;
    type pixel_{};

    pixel_value() = default;
    explicit pixel_value(pixel_t const& pixel)
        : pixel_(pixel) // test copy constructor
    {
        type temp_pixel; // test default constructor
        boost::ignore_unused(temp_pixel);
        boost::function_requires<PixelValueConcept<pixel_t> >();
    }
};

// Alias compatible with naming of equivalent class in the test/legacy/pixel.cpp
// The core suffix indicates `Pixel` is GIL core pixel type.
template <typename Pixel, int Tag = 0>
using value_core = pixel_value<Pixel, Tag>;

template <typename PixelRef, int Tag = 0>
struct pixel_reference
    : pixel_value
    <
        typename std::remove_reference<PixelRef>::type,
        Tag
    >
{
    static_assert(
        std::is_reference<PixelRef>::value ||
        gil::is_planar<PixelRef>::value, // poor-man test for specialization of planar_pixel_reference
        "PixelRef must be reference or gil::planar_pixel_reference");

    using type = PixelRef;
    using pixel_t = typename std::remove_reference<PixelRef>::type;
    using parent_t = pixel_value<typename pixel_t::value_type, Tag>;
    using value_t = typename pixel_t::value_type;
    type pixel_; // reference

    pixel_reference() : parent_t{}, pixel_(parent_t::pixel_) {}
    explicit pixel_reference(value_t const& pixel) : parent_t(pixel), pixel_(parent_t::pixel_)
    {
        boost::function_requires<PixelConcept<pixel_t>>();
    }
};

// Alias compatible with naming of equivalent class in the test/legacy/pixel.cpp
// The core suffix indicates `Pixel` is GIL core pixel type.
template <typename Pixel, int Tag = 0>
using reference_core = pixel_reference<Pixel, Tag>;

// Metafunction to yield nested type of a representative pixel type
template <typename PixelValueOrReference>
using nested_type = typename PixelValueOrReference::type;

// Metafunction to yield nested type of a representative pixel_t type
template <typename PixelValueOrReference>
using nested_pixel_type = typename PixelValueOrReference::pixel_t;

// Subset of pixel models that covers all color spaces, channel depths,
// reference/value, planar/interleaved, const/mutable.
// Operations like color conversion will be invoked on pairs of those.
using representative_pixel_types= ::boost::mp11::mp_list
<
    value_core<gil::gray8_pixel_t>,
    reference_core<gil::gray16_pixel_t&>,
    value_core<gil::bgr8_pixel_t>,
    reference_core<gil::rgb8_planar_ref_t>,
    value_core<gil::argb32_pixel_t>,
    reference_core<gil::cmyk32f_pixel_t&>,
    reference_core<gil::abgr16c_ref_t>, // immutable reference
    reference_core<gil::rgb32fc_planar_ref_t>
>;

// List of all integer-based core pixel typedefs (i.e. with cv-qualifiers)
using pixel_integer_types = ::boost::mp11::mp_list
<
    gil::gray8_pixel_t,
    gil::gray8s_pixel_t,
    gil::gray16_pixel_t,
    gil::gray16s_pixel_t,
    gil::gray32_pixel_t,
    gil::gray32s_pixel_t,
    gil::bgr8_pixel_t,
    gil::bgr8s_pixel_t,
    gil::bgr16_pixel_t,
    gil::bgr16s_pixel_t,
    gil::bgr32_pixel_t,
    gil::bgr32s_pixel_t,
    gil::rgb8_pixel_t,
    gil::rgb8s_pixel_t,
    gil::rgb16_pixel_t,
    gil::rgb16s_pixel_t,
    gil::rgb32_pixel_t,
    gil::rgb32s_pixel_t,
    gil::abgr8_pixel_t,
    gil::abgr8s_pixel_t,
    gil::abgr16_pixel_t,
    gil::abgr16s_pixel_t,
    gil::abgr32_pixel_t,
    gil::abgr32s_pixel_t,
    gil::bgra8_pixel_t,
    gil::bgra8s_pixel_t,
    gil::bgra16_pixel_t,
    gil::bgra16s_pixel_t,
    gil::bgra32_pixel_t,
    gil::bgra32s_pixel_t,
    gil::cmyk8_pixel_t,
    gil::cmyk8s_pixel_t,
    gil::cmyk16_pixel_t,
    gil::cmyk16s_pixel_t,
    gil::cmyk32_pixel_t,
    gil::cmyk32s_pixel_t,
    gil::rgba8_pixel_t,
    gil::rgba8s_pixel_t,
    gil::rgba16_pixel_t,
    gil::rgba16s_pixel_t,
    gil::rgba32_pixel_t,
    gil::rgba32s_pixel_t
>;

// List of all integer-based core pixel typedefs (i.e. with cv-qualifiers)
using pixel_float_types = ::boost::mp11::mp_list
<
    gil::gray32f_pixel_t,
    gil::bgr32f_pixel_t,
    gil::rgb32f_pixel_t,
    gil::abgr32f_pixel_t,
    gil::bgra32f_pixel_t,
    gil::cmyk32f_pixel_t,
    gil::rgba32f_pixel_t
>;

// List of all core pixel types (i.e. without cv-qualifiers)
using pixel_types = ::boost::mp11::mp_append
<
    pixel_integer_types,
    pixel_float_types
>;

// List of all core pixel typedefs (i.e. with cv-qualifiers)
using pixel_typedefs = ::boost::mp11::mp_append
<
    pixel_integer_types,
    pixel_float_types,
    ::boost::mp11::mp_list
    <
        gil::gray8c_pixel_t,
        gil::gray8sc_pixel_t,
        gil::gray16c_pixel_t,
        gil::gray16sc_pixel_t,
        gil::gray32c_pixel_t,
        gil::gray32fc_pixel_t,
        gil::gray32sc_pixel_t,
        gil::bgr8c_pixel_t,
        gil::bgr8sc_pixel_t,
        gil::bgr16c_pixel_t,
        gil::bgr16sc_pixel_t,
        gil::bgr32c_pixel_t,
        gil::bgr32fc_pixel_t,
        gil::bgr32sc_pixel_t,
        gil::rgb8c_pixel_t,
        gil::rgb8sc_pixel_t,
        gil::rgb16c_pixel_t,
        gil::rgb16sc_pixel_t,
        gil::rgb32c_pixel_t,
        gil::rgb32fc_pixel_t,
        gil::rgb32sc_pixel_t,
        gil::abgr8c_pixel_t,
        gil::abgr8sc_pixel_t,
        gil::abgr16c_pixel_t,
        gil::abgr16sc_pixel_t,
        gil::abgr32c_pixel_t,
        gil::abgr32fc_pixel_t,
        gil::abgr32sc_pixel_t,
        gil::bgra8c_pixel_t,
        gil::bgra8sc_pixel_t,
        gil::bgra16c_pixel_t,
        gil::bgra16sc_pixel_t,
        gil::bgra32c_pixel_t,
        gil::bgra32fc_pixel_t,
        gil::bgra32sc_pixel_t,
        gil::cmyk8c_pixel_t,
        gil::cmyk8sc_pixel_t,
        gil::cmyk16c_pixel_t,
        gil::cmyk16sc_pixel_t,
        gil::cmyk32c_pixel_t,
        gil::cmyk32fc_pixel_t,
        gil::cmyk32sc_pixel_t,
        gil::rgba8c_pixel_t,
        gil::rgba8sc_pixel_t,
        gil::rgba16c_pixel_t,
        gil::rgba16sc_pixel_t,
        gil::rgba32c_pixel_t,
        gil::rgba32fc_pixel_t,
        gil::rgba32sc_pixel_t
    >
>;

struct not_a_pixel_type {};

using non_pixels = ::boost::mp11::mp_list
<
    not_a_pixel_type,
    char,
    short, int, long,
    double, float,
    std::size_t,
    std::true_type,
    std::false_type
>;

using packed_channel_references_3 = typename gil::detail::packed_channel_references_vector_type
<
    std::uint8_t,
    mp11::mp_list_c<int, 3>
>::type;

using packed_pixel_gray3 = gil::packed_pixel
<
    std::uint8_t,
    packed_channel_references_3,
    gil::gray_layout_t
>;

using packed_channel_references_121 = typename gil::detail::packed_channel_references_vector_type
<
    std::uint8_t,
    mp11::mp_list_c<int, 1, 2, 1>
>::type;

using packed_pixel_bgr121 = gil::packed_pixel
<
    std::uint8_t,
    packed_channel_references_121,
    gil::bgr_layout_t
>;

using packed_channel_references_535 = typename gil::detail::packed_channel_references_vector_type
<
    std::uint16_t,
    mp11::mp_list_c<int, 5, 3, 5>
>::type;

using packed_pixel_rgb535 = gil::packed_pixel
<
    std::uint16_t,
    packed_channel_references_535,
    gil::rgb_layout_t
>;

using bit_aligned_pixel_bgr232_refefence = gil::bit_aligned_pixel_reference
    <
        std::uint8_t,
        mp11::mp_list_c<int, 2, 3, 2>,
        gil::bgr_layout_t,
        true
    > const;

using bit_aligned_pixel_bgr232_iterator = bit_aligned_pixel_iterator<bit_aligned_pixel_bgr232_refefence>;

using bit_aligned_pixel_bgr232 = std::iterator_traits<bit_aligned_pixel_bgr232_iterator>::value_type;

using bit_aligned_pixel_rgb567_refefence = gil::bit_aligned_pixel_reference
    <
        std::uint32_t,
        mp11::mp_list_c<int, 5, 6, 7>,
        gil::rgb_layout_t,
        true
    > const;

using bit_aligned_pixel_rgb567_iterator = bit_aligned_pixel_iterator<bit_aligned_pixel_rgb567_refefence>;

using bit_aligned_pixel_rgb567 = std::iterator_traits<bit_aligned_pixel_rgb567_iterator>::value_type;

}}}} // namespace boost::gil::test::fixture

#endif