/
gil_concept.hpp
2187 lines (1859 loc) · 78.7 KB
/
gil_concept.hpp
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
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
Copyright 2005-2007 Adobe Systems Incorporated
Use, modification and distribution are subject to 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).
See http://opensource.adobe.com/gil for most recent version including documentation.
*/
/*************************************************************************************************/
#ifndef GIL_CONCEPT_H
#define GIL_CONCEPT_H
////////////////////////////////////////////////////////////////////////////////////////
/// \file
/// \brief Concept check classes for GIL concepts
/// \author Lubomir Bourdev and Hailin Jin \n
/// Adobe Systems Incorporated
/// \date 2005-2007 \n Last updated on February 12, 2007
///
////////////////////////////////////////////////////////////////////////////////////////
#include <functional>
#include "gil_config.hpp"
#include <boost/type_traits.hpp>
#include <boost/utility/enable_if.hpp>
#include <boost/concept_check.hpp>
#include <boost/iterator/iterator_concepts.hpp>
#include <boost/mpl/and.hpp>
#include <boost/mpl/size.hpp>
namespace boost { namespace gil {
template <typename T> struct channel_traits;
template <typename P> struct is_pixel;
template <typename dstT, typename srcT>
typename channel_traits<dstT>::value_type channel_convert(const srcT& val);
template <typename T> class point2;
template <std::size_t K, typename T> const T& axis_value(const point2<T>& p);
template <std::size_t K, typename T> T& axis_value( point2<T>& p);
template <typename ColorBase, int K> struct kth_element_type;
template <typename ColorBase, int K> struct kth_element_reference_type;
template <typename ColorBase, int K> struct kth_element_const_reference_type;
template <typename ColorBase, int K> struct kth_semantic_element_reference_type;
template <typename ColorBase, int K> struct kth_semantic_element_const_reference_type;
template <typename ColorBase> struct size;
template <typename ColorBase> struct element_type;
template <typename T> struct channel_type;
template <typename T> struct color_space_type;
template <typename T> struct channel_mapping_type;
template <typename T> struct is_planar;
template <typename T> struct num_channels;
template <typename It> struct const_iterator_type;
template <typename It> struct iterator_is_mutable;
template <typename It> struct is_iterator_adaptor;
template <typename It, typename NewBaseIt> struct iterator_adaptor_rebind;
template <typename It> struct iterator_adaptor_get_base;
// forward-declare at_c
namespace detail { template <typename Element, typename Layout, int K> struct homogeneous_color_base; }
template <int K, typename E, typename L, int N>
typename add_reference<E>::type at_c( detail::homogeneous_color_base<E,L,N>& p);
template <int K, typename E, typename L, int N>
typename add_reference<typename add_const<E>::type>::type at_c(const detail::homogeneous_color_base<E,L,N>& p);
#if !defined(_MSC_VER) || _MSC_VER > 1310
template <typename P, typename C, typename L> struct packed_pixel;
template <int K, typename P, typename C, typename L>
typename kth_element_reference_type<packed_pixel<P,C,L>, K>::type
at_c(packed_pixel<P,C,L>& p);
template <int K, typename P, typename C, typename L>
typename kth_element_const_reference_type<packed_pixel<P,C,L>,K>::type
at_c(const packed_pixel<P,C,L>& p);
template <typename B, typename C, typename L, bool M> struct bit_aligned_pixel_reference;
template <int K, typename B, typename C, typename L, bool M> inline
typename kth_element_reference_type<bit_aligned_pixel_reference<B,C,L,M>, K>::type
at_c(const bit_aligned_pixel_reference<B,C,L,M>& p);
#endif
// Forward-declare semantic_at_c
template <int K, typename ColorBase>
typename disable_if<is_const<ColorBase>,typename kth_semantic_element_reference_type<ColorBase,K>::type>::type semantic_at_c(ColorBase& p);
template <int K, typename ColorBase>
typename kth_semantic_element_const_reference_type<ColorBase,K>::type semantic_at_c(const ColorBase& p);
template <typename T> struct dynamic_x_step_type;
template <typename T> struct dynamic_y_step_type;
template <typename T> struct transposed_type;
namespace detail {
template <typename T>
void initialize_it(T& x) {}
} // namespace detail
template <typename T>
struct remove_const_and_reference : public remove_const<typename remove_reference<T>::type> {};
#ifdef BOOST_GIL_USE_CONCEPT_CHECK
#define GIL_CLASS_REQUIRE(type_var, ns, concept) BOOST_CLASS_REQUIRE(type_var, ns, concept);
template <typename C> void gil_function_requires() { function_requires<C>(); }
#else
#define GIL_CLASS_REQUIRE(T,NS,C)
template <typename C> void gil_function_requires() {}
#endif
/// \ingroup BasicConcepts
/**
\code
auto concept DefaultConstructible<typename T> {
T::T();
};
\endcode
*/
template <typename T>
struct DefaultConstructible {
void constraints() {
function_requires<boost::DefaultConstructibleConcept<T> >();
}
};
/// \ingroup BasicConcepts
/**
\codeauto concept CopyConstructible<typename T> {
T::T(T);
T::~T();
};
\endcode
*/
template <typename T>
struct CopyConstructible {
void constraints() {
function_requires<boost::CopyConstructibleConcept<T> >();
}
};
/// \ingroup BasicConcepts
/**
\code
auto concept Assignable<typename T, typename U = T> {
typename result_type;
result_type operator=(T&, U);
};
\endcode
*/
template <typename T>
struct Assignable {
void constraints() {
function_requires<boost::AssignableConcept<T> >();
}
};
/// \ingroup BasicConcepts
/**
\code
auto concept EqualityComparable<typename T, typename U = T> {
bool operator==(T x, T y);
bool operator!=(T x, T y) { return !(x==y); }
};
\endcode
*/
template <typename T>
struct EqualityComparable {
void constraints() {
function_requires<boost::EqualityComparableConcept<T> >();
}
};
/// \ingroup BasicConcepts
/**
\code
concept SameType<typename T, typename U>;// unspecified
\endcode
*/
template <typename T, typename U>
struct SameType {
void constraints() {
BOOST_STATIC_ASSERT((boost::is_same<T,U>::value_core));
}
};
/// \ingroup BasicConcepts
/**
\code
auto concept Swappable<typename T> {
void swap(T&,T&);
};
\endcode
*/
template <typename T>
struct Swappable {
void constraints() {
using std::swap;
swap(x,y);
}
T x,y;
};
/// \ingroup BasicConcepts
/**
\code
auto concept Regular<typename T> : DefaultConstructible<T>, CopyConstructible<T>, EqualityComparable<T>,
Assignable<T>, Swappable<T> {};
\endcode
*/
template <typename T>
struct Regular {
void constraints() {
gil_function_requires< boost::DefaultConstructibleConcept<T> >();
gil_function_requires< boost::CopyConstructibleConcept<T> >();
gil_function_requires< boost::EqualityComparableConcept<T> >(); // ==, !=
gil_function_requires< boost::AssignableConcept<T> >();
gil_function_requires< Swappable<T> >();
}
};
/// \ingroup BasicConcepts
/**
\code
auto concept Metafunction<typename T> {
typename type;
};
\endcode
*/
template <typename T>
struct Metafunction {
void constraints() {
typedef typename T::type type;
}
};
////////////////////////////////////////////////////////////////////////////////////////
//
// POINT CONCEPTS
//
////////////////////////////////////////////////////////////////////////////////////////
/// \brief N-dimensional point concept
/// \ingroup PointConcept
/**
\code
concept PointNDConcept<typename T> : Regular<T> {
// the type of a coordinate along each axis
template <size_t K> struct axis; where Metafunction<axis>;
const size_t num_dimensions;
// accessor/modifier of the value of each axis.
template <size_t K> const typename axis<K>::type& T::axis_value() const;
template <size_t K> typename axis<K>::type& T::axis_value();
};
\endcode
*/
template <typename P>
struct PointNDConcept {
void constraints() {
gil_function_requires< Regular<P> >();
typedef typename P::value_type value_type;
static const std::size_t N=P::num_dimensions; ignore_unused_variable_warning(N);
typedef typename P::template axis<0>::coord_t FT;
typedef typename P::template axis<N-1>::coord_t LT;
FT ft=gil::axis_value<0>(point);
axis_value<0>(point)=ft;
LT lt=axis_value<N-1>(point);
axis_value<N-1>(point)=lt;
value_type v=point[0]; ignore_unused_variable_warning(v);
point[0]=point[0];
}
P point;
};
/// \brief 2-dimensional point concept
/// \ingroup PointConcept
/**
\code
concept Point2DConcept<typename T> : PointNDConcept<T> {
where num_dimensions == 2;
where SameType<axis<0>::type, axis<1>::type>;
typename value_type = axis<0>::type;
const value_type& operator[](const T&, size_t i);
value_type& operator[]( T&, size_t i);
value_type x,y;
};
\endcode
*/
template <typename P>
struct Point2DConcept {
void constraints() {
gil_function_requires< PointNDConcept<P> >();
BOOST_STATIC_ASSERT(P::num_dimensions == 2);
point.x=point.y;
point[0]=point[1];
}
P point;
};
////////////////////////////////////////////////////////////////////////////////////////
//
// ITERATOR MUTABILITY CONCEPTS
//
// Taken from boost's concept_check.hpp. Isolating mutability to result in faster compile time
//
////////////////////////////////////////////////////////////////////////////////////////
namespace detail {
template <class TT> // Preconditions: TT Models boost_concepts::ForwardTraversalConcept
struct ForwardIteratorIsMutableConcept {
void constraints() {
*i++ = *i; // require postincrement and assignment
}
TT i;
};
template <class TT> // Preconditions: TT Models boost::BidirectionalIteratorConcept
struct BidirectionalIteratorIsMutableConcept {
void constraints() {
gil_function_requires< ForwardIteratorIsMutableConcept<TT> >();
*i-- = *i; // require postdecrement and assignment
}
TT i;
};
template <class TT> // Preconditions: TT Models boost_concepts::RandomAccessTraversalConcept
struct RandomAccessIteratorIsMutableConcept {
void constraints() {
gil_function_requires< BidirectionalIteratorIsMutableConcept<TT> >();
typename std::iterator_traits<TT>::difference_type n=0; ignore_unused_variable_warning(n);
i[n] = *i; // require element access and assignment
}
TT i;
};
} // namespace detail
////////////////////////////////////////////////////////////////////////////////////////
//
// COLOR SPACE CONCEPTS
//
////////////////////////////////////////////////////////////////////////////////////////
/// \brief Color space type concept
/// \ingroup ColorSpaceAndLayoutConcept
/**
\code
concept ColorSpaceConcept<MPLRandomAccessSequence Cs> {
// An MPL Random Access Sequence, whose elements are color tags
};
\endcode
*/
template <typename Cs>
struct ColorSpaceConcept {
void constraints() {
// An MPL Random Access Sequence, whose elements are color tags
}
};
template <typename ColorSpace1, typename ColorSpace2> // Models ColorSpaceConcept
struct color_spaces_are_compatible : public is_same<ColorSpace1,ColorSpace2> {};
/// \brief Two color spaces are compatible if they are the same
/// \ingroup ColorSpaceAndLayoutConcept
/**
\code
concept ColorSpacesCompatibleConcept<ColorSpaceConcept Cs1, ColorSpaceConcept Cs2> {
where SameType<Cs1,Cs2>;
};
\endcode
*/
template <typename Cs1, typename Cs2>
struct ColorSpacesCompatibleConcept {
void constraints() {
BOOST_STATIC_ASSERT((color_spaces_are_compatible<Cs1,Cs2>::value));
}
};
/// \brief Channel mapping concept
/// \ingroup ColorSpaceAndLayoutConcept
/**
\code
concept ChannelMappingConcept<MPLRandomAccessSequence CM> {
// An MPL Random Access Sequence, whose elements model MPLIntegralConstant representing a permutation
};
\endcode
*/
template <typename CM>
struct ChannelMappingConcept {
void constraints() {
// An MPL Random Access Sequence, whose elements model MPLIntegralConstant representing a permutation
}
};
////////////////////////////////////////////////////////////////////////////////////////
///
/// Channel CONCEPTS
///
////////////////////////////////////////////////////////////////////////////////////////
/// \ingroup ChannelConcept
/// \brief A channel is the building block of a color. Color is defined as a mixture of primary colors and a channel defines the degree to which each primary color is used in the mixture.
/**
For example, in the RGB color space, using 8-bit unsigned channels, the color red is defined as [255 0 0], which means maximum of Red, and no Green and Blue.
Built-in scalar types, such as \p int and \p float, are valid GIL channels. In more complex scenarios, channels may be represented as bit ranges or even individual bits.
In such cases special classes are needed to represent the value and reference to a channel.
Channels have a traits class, \p channel_traits, which defines their associated types as well as their operating ranges.
\code
concept ChannelConcept<typename T> : EqualityComparable<T> {
typename value_type = T; // use channel_traits<T>::value_type to access it
typename reference = T&; // use channel_traits<T>::reference to access it
typename pointer = T*; // use channel_traits<T>::pointer to access it
typename const_reference = const T&; // use channel_traits<T>::const_reference to access it
typename const_pointer = const T*; // use channel_traits<T>::const_pointer to access it
static const bool is_mutable; // use channel_traits<T>::is_mutable to access it
static T min_value(); // use channel_traits<T>::min_value to access it
static T max_value(); // use channel_traits<T>::min_value to access it
};
\endcode
*/
template <typename T>
struct ChannelConcept {
void constraints() {
gil_function_requires< boost::EqualityComparableConcept<T> >();
typedef typename channel_traits<T>::value_type v;
typedef typename channel_traits<T>::reference r;
typedef typename channel_traits<T>::pointer p;
typedef typename channel_traits<T>::const_reference cr;
typedef typename channel_traits<T>::const_pointer cp;
channel_traits<T>::min_value();
channel_traits<T>::max_value();
}
T c;
};
namespace detail {
// Preconditions: T models ChannelConcept
template <typename T>
struct ChannelIsMutableConcept {
void constraints() {
c=c;
using std::swap;
swap(c,c);
}
T c;
};
}
/// \brief A channel that allows for modifying its value
/// \ingroup ChannelConcept
/**
\code
concept MutableChannelConcept<ChannelConcept T> : Assignable<T>, Swappable<T> {};
\endcode
*/
template <typename T>
struct MutableChannelConcept {
void constraints() {
gil_function_requires<ChannelConcept<T> >();
gil_function_requires<detail::ChannelIsMutableConcept<T> >();
}
};
/// \brief A channel that supports default construction.
/// \ingroup ChannelConcept
/**
\code
concept ChannelValueConcept<ChannelConcept T> : Regular<T> {};
\endcode
*/
template <typename T>
struct ChannelValueConcept {
void constraints() {
gil_function_requires<ChannelConcept<T> >();
gil_function_requires<Regular<T> >();
}
};
/// \brief Predicate metafunction returning whether two channels are compatible
/// \ingroup ChannelAlgorithm
///
/// Channels are considered compatible if their value types (ignoring constness and references) are the same.
/**
Example:
\code
BOOST_STATIC_ASSERT((channels_are_compatible<bits8, const bits8&>::value));
\endcode
*/
template <typename T1, typename T2> // Models GIL Pixel
struct channels_are_compatible
: public is_same<typename channel_traits<T1>::value_type, typename channel_traits<T2>::value_type> {};
/// \brief Channels are compatible if their associated value types (ignoring constness and references) are the same
/// \ingroup ChannelConcept
/**
\code
concept ChannelsCompatibleConcept<ChannelConcept T1, ChannelConcept T2> {
where SameType<T1::value_type, T2::value_type>;
};
\endcode
*/
template <typename T1, typename T2>
struct ChannelsCompatibleConcept {
void constraints() {
BOOST_STATIC_ASSERT((channels_are_compatible<T1,T2>::value));
}
};
/// \brief A channel is convertible to another one if the \p channel_convert algorithm is defined for the two channels
///
/// Convertibility is non-symmetric and implies that one channel can be converted to another. Conversion is explicit and often lossy operation.
/// \ingroup ChannelConcept
/**
\code
concept ChannelConvertibleConcept<ChannelConcept SrcChannel, ChannelValueConcept DstChannel> {
DstChannel channel_convert(const SrcChannel&);
};
\endcode
*/
template <typename SrcChannel, typename DstChannel>
struct ChannelConvertibleConcept {
void constraints() {
gil_function_requires<ChannelConcept<SrcChannel> >();
gil_function_requires<MutableChannelConcept<DstChannel> >();
dst=channel_convert<DstChannel,SrcChannel>(src); ignore_unused_variable_warning(dst);
}
SrcChannel src;
DstChannel dst;
};
////////////////////////////////////////////////////////////////////////////////////////
///
/// COLOR BASE CONCEPTS
///
////////////////////////////////////////////////////////////////////////////////////////
/// \ingroup ColorBaseConcept
/// \brief A color base is a container of color elements (such as channels, channel references or channel pointers)
/**
The most common use of color base is in the implementation of a pixel, in which case the color
elements are channel values. The color base concept, however, can be used in other scenarios. For example, a planar pixel has channels that are not
contiguous in memory. Its reference is a proxy class that uses a color base whose elements are channel references. Its iterator uses a color base
whose elements are channel iterators.
A color base must have an associated layout (which consists of a color space, as well as an ordering of the channels).
There are two ways to index the elements of a color base: A physical index corresponds to the way they are ordered in memory, and
a semantic index corresponds to the way the elements are ordered in their color space.
For example, in the RGB color space the elements are ordered as {red_t, green_t, blue_t}. For a color base with a BGR layout, the first element
in physical ordering is the blue element, whereas the first semantic element is the red one.
Models of \p ColorBaseConcept are required to provide the \p at_c<K>(ColorBase) function, which allows for accessing the elements based on their
physical order. GIL provides a \p semantic_at_c<K>(ColorBase) function (described later) which can operate on any model of ColorBaseConcept and returns
the corresponding semantic element.
\code
concept ColorBaseConcept<typename T> : CopyConstructible<T>, EqualityComparable<T> {
// a GIL layout (the color space and element permutation)
typename layout_t;
// The type of K-th element
template <int K> struct kth_element_type; where Metafunction<kth_element_type>;
// The result of at_c
template <int K> struct kth_element_const_reference_type; where Metafunction<kth_element_const_reference_type>;
template <int K> kth_element_const_reference_type<T,K>::type at_c(T);
// Copy-constructible and equality comparable with other compatible color bases
template <ColorBaseConcept T2> where { ColorBasesCompatibleConcept<T,T2> }
T::T(T2);
template <ColorBaseConcept T2> where { ColorBasesCompatibleConcept<T,T2> }
bool operator==(const T&, const T2&);
template <ColorBaseConcept T2> where { ColorBasesCompatibleConcept<T,T2> }
bool operator!=(const T&, const T2&);
};
\endcode
*/
template <typename ColorBase>
struct ColorBaseConcept {
void constraints() {
gil_function_requires< CopyConstructible<ColorBase> >();
gil_function_requires< EqualityComparable<ColorBase> >();
typedef typename ColorBase::layout_t::color_space_t color_space_t;
gil_function_requires<ColorSpaceConcept<color_space_t> >();
typedef typename ColorBase::layout_t::channel_mapping_t channel_mapping_t;
// TODO: channel_mapping_t must be an MPL RandomAccessSequence
static const std::size_t num_elements = size<ColorBase>::value;
typedef typename kth_element_type<ColorBase,num_elements-1>::type TN;
typedef typename kth_element_const_reference_type<ColorBase,num_elements-1>::type CR;
#if !defined(_MSC_VER) || _MSC_VER > 1310
CR cr=at_c<num_elements-1>(cb); ignore_unused_variable_warning(cr);
#endif
// functions that work for every pixel (no need to require them)
semantic_at_c<0>(cb);
semantic_at_c<num_elements-1>(cb);
// also static_max(cb), static_min(cb), static_fill(cb,value), and all variations of static_for_each(), static_generate(), static_transform()
}
ColorBase cb;
};
/// \ingroup ColorBaseConcept
/// \brief Color base which allows for modifying its elements
/**
\code
concept MutableColorBaseConcept<ColorBaseConcept T> : Assignable<T>, Swappable<T> {
template <int K> struct kth_element_reference_type; where Metafunction<kth_element_reference_type>;
template <int K> kth_element_reference_type<kth_element_type<T,K>::type>::type at_c(T);
template <ColorBaseConcept T2> where { ColorBasesCompatibleConcept<T,T2> }
T& operator=(T&, const T2&);
};
\endcode
*/
template <typename ColorBase>
struct MutableColorBaseConcept {
void constraints() {
gil_function_requires< ColorBaseConcept<ColorBase> >();
gil_function_requires< Assignable<ColorBase> >();
gil_function_requires< Swappable<ColorBase> >();
typedef typename kth_element_reference_type<ColorBase, 0>::type CR;
#if !defined(_MSC_VER) || _MSC_VER > 1310
CR r=at_c<0>(cb);
at_c<0>(cb)=r;
#endif
}
ColorBase cb;
};
/// \ingroup ColorBaseConcept
/// \brief Color base that also has a default-constructor. Refines Regular
/**
\code
concept ColorBaseValueConcept<typename T> : MutableColorBaseConcept<T>, Regular<T> {
};
\endcode
*/
template <typename ColorBase>
struct ColorBaseValueConcept {
void constraints() {
gil_function_requires< MutableColorBaseConcept<ColorBase> >();
gil_function_requires< Regular<ColorBase> >();
}
};
/// \ingroup ColorBaseConcept
/// \brief Color base whose elements all have the same type
/**
\code
concept HomogeneousColorBaseConcept<ColorBaseConcept CB> {
// For all K in [0 ... size<C1>::value-1):
// where SameType<kth_element_type<CB,K>::type, kth_element_type<CB,K+1>::type>;
kth_element_const_reference_type<CB,0>::type dynamic_at_c(const CB&, std::size_t n) const;
};
\endcode
*/
template <typename ColorBase>
struct HomogeneousColorBaseConcept {
void constraints() {
gil_function_requires< ColorBaseConcept<ColorBase> >();
static const std::size_t num_elements = size<ColorBase>::value;
typedef typename kth_element_type<ColorBase,0>::type T0;
typedef typename kth_element_type<ColorBase,num_elements-1>::type TN;
BOOST_STATIC_ASSERT((is_same<T0,TN>::value)); // better than nothing
typedef typename kth_element_const_reference_type<ColorBase,0>::type CRef0;
CRef0 e0=dynamic_at_c(cb,0);
}
ColorBase cb;
};
/// \ingroup ColorBaseConcept
/// \brief Homogeneous color base that allows for modifying its elements
/**
\code
concept MutableHomogeneousColorBaseConcept<ColorBaseConcept CB> : HomogeneousColorBaseConcept<CB> {
kth_element_reference_type<CB,0>::type dynamic_at_c(CB&, std::size_t n);
};
\endcode
*/
template <typename ColorBase>
struct MutableHomogeneousColorBaseConcept {
void constraints() {
gil_function_requires< ColorBaseConcept<ColorBase> >();
gil_function_requires< HomogeneousColorBaseConcept<ColorBase> >();
typedef typename kth_element_reference_type<ColorBase, 0>::type R0;
R0 x=dynamic_at_c(cb,0);
dynamic_at_c(cb,0) = dynamic_at_c(cb,0);
}
ColorBase cb;
};
/// \ingroup ColorBaseConcept
/// \brief Homogeneous color base that also has a default constructor. Refines Regular.
/**
\code
concept HomogeneousColorBaseValueConcept<typename T> : MutableHomogeneousColorBaseConcept<T>, Regular<T> {
};
\endcode
*/
template <typename ColorBase>
struct HomogeneousColorBaseValueConcept {
void constraints() {
gil_function_requires< MutableHomogeneousColorBaseConcept<ColorBase> >();
gil_function_requires< Regular<ColorBase> >();
}
};
/// \ingroup ColorBaseConcept
/// \brief Two color bases are compatible if they have the same color space and their elements are compatible, semantic-pairwise.
/**
\code
concept ColorBasesCompatibleConcept<ColorBaseConcept C1, ColorBaseConcept C2> {
where SameType<C1::layout_t::color_space_t, C2::layout_t::color_space_t>;
// also, for all K in [0 ... size<C1>::value):
// where Convertible<kth_semantic_element_type<C1,K>::type, kth_semantic_element_type<C2,K>::type>;
// where Convertible<kth_semantic_element_type<C2,K>::type, kth_semantic_element_type<C1,K>::type>;
};
\endcode
*/
template <typename ColorBase1, typename ColorBase2>
struct ColorBasesCompatibleConcept {
void constraints() {
BOOST_STATIC_ASSERT((is_same<typename ColorBase1::layout_t::color_space_t,
typename ColorBase2::layout_t::color_space_t>::value));
// typedef typename kth_semantic_element_type<ColorBase1,0>::type e1;
// typedef typename kth_semantic_element_type<ColorBase2,0>::type e2;
// "e1 is convertible to e2"
}
};
////////////////////////////////////////////////////////////////////////////////////////
///
/// PIXEL CONCEPTS
///
////////////////////////////////////////////////////////////////////////////////////////
/// \brief Concept for all pixel-based GIL constructs, such as pixels, iterators, locators, views and images whose value type is a pixel
/// \ingroup PixelBasedConcept
/**
\code
concept PixelBasedConcept<typename T> {
typename color_space_type<T>;
where Metafunction<color_space_type<T> >;
where ColorSpaceConcept<color_space_type<T>::type>;
typename channel_mapping_type<T>;
where Metafunction<channel_mapping_type<T> >;
where ChannelMappingConcept<channel_mapping_type<T>::type>;
typename is_planar<T>;
where Metafunction<is_planar<T> >;
where SameType<is_planar<T>::type, bool>;
};
\endcode
*/
template <typename P>
struct PixelBasedConcept {
void constraints() {
typedef typename color_space_type<P>::type color_space_t;
gil_function_requires<ColorSpaceConcept<color_space_t> >();
typedef typename channel_mapping_type<P>::type channel_mapping_t;
gil_function_requires<ChannelMappingConcept<channel_mapping_t> >();
static const bool planar = is_planar<P>::type::value; ignore_unused_variable_warning(planar);
// This is not part of the concept, but should still work
static const std::size_t nc = num_channels<P>::value;
ignore_unused_variable_warning(nc);
}
};
/// \brief Concept for homogeneous pixel-based GIL constructs
/// \ingroup PixelBasedConcept
/**
\code
concept HomogeneousPixelBasedConcept<PixelBasedConcept T> {
typename channel_type<T>;
where Metafunction<channel_type<T> >;
where ChannelConcept<channel_type<T>::type>;
};
\endcode
*/
template <typename P>
struct HomogeneousPixelBasedConcept {
void constraints() {
gil_function_requires<PixelBasedConcept<P> >();
typedef typename channel_type<P>::type channel_t;
gil_function_requires<ChannelConcept<channel_t> >();
}
};
/// \brief Pixel concept - A color base whose elements are channels
/// \ingroup PixelConcept
/**
\code
concept PixelConcept<typename P> : ColorBaseConcept<P>, PixelBasedConcept<P> {
where is_pixel<P>::type::value==true;
// where for each K [0..size<P>::value-1]:
// ChannelConcept<kth_element_type<P,K> >;
typename P::value_type; where PixelValueConcept<value_type>;
typename P::reference; where PixelConcept<reference>;
typename P::const_reference; where PixelConcept<const_reference>;
static const bool P::is_mutable;
template <PixelConcept P2> where { PixelConcept<P,P2> }
P::P(P2);
template <PixelConcept P2> where { PixelConcept<P,P2> }
bool operator==(const P&, const P2&);
template <PixelConcept P2> where { PixelConcept<P,P2> }
bool operator!=(const P&, const P2&);
};
\endcode
*/
template <typename P>
struct PixelConcept {
void constraints() {
gil_function_requires<ColorBaseConcept<P> >();
gil_function_requires<PixelBasedConcept<P> >();
BOOST_STATIC_ASSERT((is_pixel<P>::value));
static const bool is_mutable = P::is_mutable; ignore_unused_variable_warning(is_mutable);
typedef typename P::value_type value_type;
// gil_function_requires<PixelValueConcept<value_type> >();
typedef typename P::reference reference;
gil_function_requires<PixelConcept<typename remove_const_and_reference<reference>::type> >();
typedef typename P::const_reference const_reference;
gil_function_requires<PixelConcept<typename remove_const_and_reference<const_reference>::type> >();
}
};
/// \brief Pixel concept that allows for changing its channels
/// \ingroup PixelConcept
/**
\code
concept MutablePixelConcept<PixelConcept P> : MutableColorBaseConcept<P> {
where is_mutable==true;
};
\endcode
*/
template <typename P>
struct MutablePixelConcept {
void constraints() {
gil_function_requires<PixelConcept<P> >();
BOOST_STATIC_ASSERT(P::is_mutable);
}
};
/// \brief Homogeneous pixel concept
/// \ingroup PixelConcept
/**
\code
concept HomogeneousPixelConcept<PixelConcept P> : HomogeneousColorBaseConcept<P>, HomogeneousPixelBasedConcept<P> {
P::template element_const_reference_type<P>::type operator[](P p, std::size_t i) const { return dynamic_at_c(p,i); }
};
\endcode
*/
template <typename P>
struct HomogeneousPixelConcept {
void constraints() {
gil_function_requires<PixelConcept<P> >();
gil_function_requires<HomogeneousColorBaseConcept<P> >();
gil_function_requires<HomogeneousPixelBasedConcept<P> >();
p[0];
}
P p;
};
/// \brief Homogeneous pixel concept that allows for changing its channels
/// \ingroup PixelConcept
/**
\code
concept MutableHomogeneousPixelConcept<HomogeneousPixelConcept P> : MutableHomogeneousColorBaseConcept<P> {
P::template element_reference_type<P>::type operator[](P p, std::size_t i) { return dynamic_at_c(p,i); }
};
\endcode
*/
template <typename P>
struct MutableHomogeneousPixelConcept {
void constraints() {
gil_function_requires<HomogeneousPixelConcept<P> >();
gil_function_requires<MutableHomogeneousColorBaseConcept<P> >();
p[0]=p[0];
}
P p;
};
/// \brief Pixel concept that is a Regular type
/// \ingroup PixelConcept
/**
\code
concept PixelValueConcept<PixelConcept P> : Regular<P> {
where SameType<value_type,P>;
};
\endcode
*/
template <typename P>
struct PixelValueConcept {
void constraints() {
gil_function_requires<PixelConcept<P> >();
gil_function_requires<Regular<P> >();
}
};
/// \brief Homogeneous pixel concept that is a Regular type
/// \ingroup PixelConcept
/**
\code
concept HomogeneousPixelValueConcept<HomogeneousPixelConcept P> : Regular<P> {
where SameType<value_type,P>;
};
\endcode
*/
template <typename P>
struct HomogeneousPixelValueConcept {
void constraints() {
gil_function_requires<HomogeneousPixelConcept<P> >();
gil_function_requires<Regular<P> >();
BOOST_STATIC_ASSERT((is_same<P, typename P::value_type>::value));
}
};
namespace detail {
template <typename P1, typename P2, int K>
struct channels_are_pairwise_compatible : public
mpl::and_<channels_are_pairwise_compatible<P1,P2,K-1>,
channels_are_compatible<typename kth_semantic_element_reference_type<P1,K>::type,
typename kth_semantic_element_reference_type<P2,K>::type> > {};