- メインページ
- モジュール
- ネームスペース
- データ構造
- ファイル

- ファイル一覧
- グローバル

color.h
説明を見る。
1 //
2 // Copyright (c) 2003-2011, MIST Project, Nagoya University
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without modification,
6 // are permitted provided that the following conditions are met:
7 //
8 // 1. Redistributions of source code must retain the above copyright notice,
9 // this list of conditions and the following disclaimer.
10 //
11 // 2. Redistributions in binary form must reproduce the above copyright notice,
12 // this list of conditions and the following disclaimer in the documentation
13 // and/or other materials provided with the distribution.
14 //
15 // 3. Neither the name of the Nagoya University nor the names of its contributors
16 // may be used to endorse or promote products derived from this software
17 // without specific prior written permission.
18 //
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
20 // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
21 // FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
22 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25 // IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
26 // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 //
28
33
34 #ifndef __INCLUDE_MIST_COLOR_H__
35 #define __INCLUDE_MIST_COLOR_H__
36
37
38 #ifndef __INCLUDE_MIST_CONF_H__
39 #include "mist_conf.h"
40 #endif
41
42 #ifndef __INCLUDE_MIST_TYPE_TRAIT_H__
43 #include "type_trait.h"
44 #endif
45
46 #include <iostream>
47 #include <cmath>
48
49 // mist名前空間の始まり
50 _MIST_BEGIN
51
52 namespace __color_utility__
53 {
54 template < bool >
55 struct __normalized_color__
56 {
57 template < class T >
58 static void compute( const T &r, const T &g, const T &b, T &R, T &G, T &B )
59 {
60 T sum = r + g + b;
61
62 sum = sum > 0 ? sum : 1;
63
64 R = r / sum;
65 G = g / sum;
66 B = b / sum;
67 }
68 };
69
70 template < >
71 struct __normalized_color__< false >
72 {
73 template < class T >
74 static void compute( const T &r, const T &g, const T &b, T &R, T &G, T &B )
75 {
76 double sum = static_cast< double >( r ) + static_cast< double >( g ) + static_cast< double >( b );
77
78 sum = sum > 0.0 ? sum : 1.0;
79
80 R = static_cast< T >( r * 255.0 / sum + 0.5 );
81 G = static_cast< T >( g * 255.0 / sum + 0.5 );
82 B = static_cast< T >( b * 255.0 / sum + 0.5 );
83 }
84 };
85
86 template < class T > inline T maximum( const T &v1, const T &v2 )
87 {
88 return( v1 > v2 ? v1 : v2 );
89 }
90
91 template < class T > inline T minimum( const T &v1, const T &v2 )
92 {
93 return( v1 < v2 ? v1 : v2 );
94 }
95 }
96
97 // MISTで利用する基底のデータ型
98 template < class T > struct bgr;
99
100
108
109
118 template< class T >
119 struct rgb
120 {
121 public:
122 typedef size_t size_type;
123 typedef ptrdiff_t difference_type;
124 typedef T& reference;
125 typedef const T& const_reference;
126 typedef T value_type;
127 typedef T* pointer;
128 typedef const T* const_pointer;
129
131 template < class TT >
132 struct rebind
133 {
134 typedef rgb< TT > other;
135 };
136
137 public:
138 value_type r;
139 value_type g;
140 value_type b;
141
143 rgb( const value_type &pix = 0 ) : r( pix ), g( pix ), b( pix ){ }
144
146 template < class TT >
147 rgb( const rgb< TT > &c ) : r( static_cast< value_type >( c.r ) ), g( static_cast< value_type >( c.g ) ), b( static_cast< value_type >( c.b ) ){ }
148
150 template < class TT >
151 rgb( const bgr< TT > &c ) : r( static_cast< value_type >( c.r ) ), g( static_cast< value_type >( c.g ) ), b( static_cast< value_type >( c.b ) ){ }
152
154 rgb( const rgb< T > &c ) : r( c.r ), g( c.g ), b( c.b ){ }
155
157 rgb( const value_type &rr, const value_type &gg, const value_type &bb ) : r( rr ), g( gg ), b( bb ){ }
158
159
161 template < class TT >
162 const rgb &operator =( const rgb< TT > &c )
163 {
164 r = static_cast< value_type >( c.r );
165 g = static_cast< value_type >( c.g );
166 b = static_cast< value_type >( c.b );
167 return( *this );
168 }
169
171 template < class TT >
172 const rgb &operator =( const bgr< TT > &c )
173 {
174 r = static_cast< value_type >( c.r );
175 g = static_cast< value_type >( c.g );
176 b = static_cast< value_type >( c.b );
177 return( *this );
178 }
179
181 const rgb &operator =( const rgb< T > &c )
182 {
183 if( &c != this )
184 {
185 r = c.r;
186 g = c.g;
187 b = c.b;
188 }
189 return( *this );
190 }
191
193 const rgb &operator =( const value_type &pix )
194 {
195 r = pix;
196 g = pix;
197 b = pix;
198 return( *this );
199 }
200
201
203 const rgb operator -( ) const { return( rgb( -r, -g, -b ) ); }
204
206 template < class TT >
207 const rgb &operator +=( const rgb< TT > &c ){ r = static_cast< value_type >( r + c.r ); g = static_cast< value_type >( g + c.g ); b = static_cast< value_type >( b + c.b ); return( *this ); }
208
210 template < class TT >
211 const rgb &operator -=( const rgb< TT > &c ){ r = static_cast< value_type >( r - c.r ); g = static_cast< value_type >( g - c.g ); b = static_cast< value_type >( b - c.b ); return( *this ); }
212
214 template < class TT >
215 const rgb &operator *=( const rgb< TT > &c ){ r = static_cast< value_type >( r * c.r ); g = static_cast< value_type >( g * c.g ); b = static_cast< value_type >( b * c.b ); return( *this ); }
216
218 template < class TT >
219 const rgb &operator /=( const rgb< TT > &c ){ r = static_cast< value_type >( r / c.r ); g = static_cast< value_type >( g / c.g ); b = static_cast< value_type >( b / c.b ); return( *this ); }
220
222 const rgb &operator %=( const rgb &c ){ r %= c.r; g %= c.g; b %= c.b; return( *this ); }
223
225 const rgb &operator |=( const rgb &c ){ r |= c.r; g |= c.g; b |= c.b; return( *this ); }
226
228 const rgb &operator &=( const rgb &c ){ r &= c.r; g &= c.g; b &= c.b; return( *this ); }
229
231 const rgb &operator ^=( const rgb &c ){ r ^= c.r; g ^= c.g; b ^= c.b; return( *this ); }
232
233
235 #if defined( __MIST_MSVC__ ) && __MIST_MSVC__ < 7
236 const rgb &operator +=( const double &pix )
237 #else
238 template < class TT >
239 const rgb &operator +=( const TT &pix )
240 #endif
241 {
242 r = static_cast< value_type >( r + pix );
243 g = static_cast< value_type >( g + pix );
244 b = static_cast< value_type >( b + pix );
245 return( *this );
246 }
247
249 #if defined( __MIST_MSVC__ ) && __MIST_MSVC__ < 7
250 const rgb &operator -=( const double &pix )
251 #else
252 template < class TT >
253 const rgb &operator -=( const TT &pix )
254 #endif
255 {
256 r = static_cast< value_type >( r - pix );
257 g = static_cast< value_type >( g - pix );
258 b = static_cast< value_type >( b - pix );
259 return( *this );
260 }
261
263 #if defined( __MIST_MSVC__ ) && __MIST_MSVC__ < 7
264 const rgb &operator *=( const double &pix )
265 #else
266 template < class TT >
267 const rgb &operator *=( const TT &pix )
268 #endif
269 {
270 r = static_cast< value_type >( r * pix );
271 g = static_cast< value_type >( g * pix );
272 b = static_cast< value_type >( b * pix );
273 return( *this );
274 }
275
277 #if defined( __MIST_MSVC__ ) && __MIST_MSVC__ < 7
278 const rgb &operator /=( const double &pix )
279 #else
280 template < class TT >
281 const rgb &operator /=( const TT &pix )
282 #endif
283 {
284 r = static_cast< value_type >( r / pix );
285 g = static_cast< value_type >( g / pix );
286 b = static_cast< value_type >( b / pix );
287 return( *this );
288 }
289
290
300 bool operator ==( const rgb &c ) const { return( r == c.r && g == c.g && b == c.b ); }
301
311 bool operator !=( const rgb &c ) const { return( !( *this == c ) ); }
312
322 bool operator < ( const rgb &c ) const
323 {
324 if( r == c.r )
325 {
326 if( g == c.g )
327 {
328 return( b < c.b );
329 }
330 else
331 {
332 return( g < c.g );
333 }
334 }
335 else
336 {
337 return( r < c.r );
338 }
339 }
340
350 bool operator <=( const rgb &c ) const { return( c >= *this ); }
351
361 bool operator > ( const rgb &c ) const { return( c < *this ); }
362
372 bool operator >=( const rgb &c ) const { return( !( *this < c ) ); }
373
374
376 value_type get_value( ) const
377 {
378 return( half_adjust< value_type >::convert( r * 0.298912 + g * 0.586610 + b * 0.114478 ) );
379 }
380
382 value_type get_average( ) const
383 {
384 double rr = r, gg = g, bb = b;
385 return( half_adjust< value_type >::convert( ( rr + gg + bb ) * 0.33333333333333333333333333333333 ) );
386 }
387
388 // カラーからグレースケールへの自動キャスト演算子（危険のため一時停止）
389 //operator value_type( ) const { return( get_value( ) ); }
390 };
391
392
393
395 DEFINE_PROMOTE_BIND_OPERATOR1( rgb, + )
396
397
398 DEFINE_PROMOTE_BIND_OPERATOR2( rgb, + )
399
401 DEFINE_PROMOTE_BIND_OPERATOR3( rgb, + )
402
404 DEFINE_PROMOTE_BIND_OPERATOR1( rgb, - )
405
407 DEFINE_PROMOTE_BIND_OPERATOR2( rgb, - )
408
410 DEFINE_PROMOTE_BIND_OPERATOR4( rgb, - )
411
413 DEFINE_PROMOTE_BIND_OPERATOR1( rgb, * )
414
416 DEFINE_PROMOTE_BIND_OPERATOR2( rgb, * )
417
419 DEFINE_PROMOTE_BIND_OPERATOR3( rgb, * )
420
422 DEFINE_PROMOTE_BIND_OPERATOR1( rgb, / )
423
425 DEFINE_PROMOTE_BIND_OPERATOR2( rgb, / )
426
428 DEFINE_PROMOTE_BIND_OPERATOR1( rgb, % )
429
430
432 DEFINE_PROMOTE_BIND_OPERATOR1( rgb, | )
433
435 DEFINE_PROMOTE_BIND_OPERATOR1( rgb, & )
436
438 DEFINE_PROMOTE_BIND_OPERATOR1( rgb, ^ )
439
440
441
442
453 template< class T >
454 struct bgr
455 {
456 public:
457 typedef size_t size_type;
458 typedef ptrdiff_t difference_type;
459 typedef T& reference;
460 typedef const T& const_reference;
461 typedef T value_type;
462 typedef T* pointer;
463 typedef const T* const_pointer;
464
466 template < class TT >
467 struct rebind
468 {
469 typedef bgr< TT > other;
470 };
471
472 public:
473 value_type b;
474 value_type g;
475 value_type r;
476
478 bgr( const value_type &pix = 0 ) : b( pix ), g( pix ), r( pix ){ }
479
481 template < class TT >
482 bgr( const bgr< TT > &c ) : b( static_cast< value_type >( c.b ) ), g( static_cast< value_type >( c.g ) ), r( static_cast< value_type >( c.r ) ){ }
483
485 bgr( const bgr< T > &c ) : b( c.b ), g( c.g ), r( c.r ){ }
486
488 bgr( const value_type &rr, const value_type &gg, const value_type &bb ) : b( bb ), g( gg ), r( rr ){ }
489
491 template < class TT >
492 bgr( const rgb< TT > &c ) : b( static_cast< value_type >( c.b ) ), g( static_cast< value_type >( c.g ) ), r( static_cast< value_type >( c.r ) ){ }
493
494
496 template < class TT >
497 const bgr &operator =( const bgr< TT > &c )
498 {
499 b = static_cast< value_type >( c.b );
500 g = static_cast< value_type >( c.g );
501 r = static_cast< value_type >( c.r );
502 return( *this );
503 }
504
506 template < class TT >
507 const bgr &operator =( const rgb< TT > &c )
508 {
509 b = static_cast< value_type >( c.b );
510 g = static_cast< value_type >( c.g );
511 r = static_cast< value_type >( c.r );
512 return( *this );
513 }
514
516 const bgr &operator =( const bgr< T > &c )
517 {
518 if( &c != this )
519 {
520 b = c.b;
521 g = c.g;
522 r = c.r;
523 }
524 return( *this );
525 }
526
528 const bgr &operator =( const value_type &pix )
529 {
530 b = pix;
531 g = pix;
532 r = pix;
533 return( *this );
534 }
535
536
538 const bgr operator -( ) const { return( bgr( -r, -g, -b ) ); }
539
541 template < class TT >
542 const bgr &operator +=( const bgr< TT > &c ){ b = static_cast< value_type >( b + c.b ); g = static_cast< value_type >( g + c.g ); r = static_cast< value_type >( r + c.r ); return( *this ); }
543
545 template < class TT >
546 const bgr &operator -=( const bgr< TT > &c ){ b = static_cast< value_type >( b - c.b ); g = static_cast< value_type >( g - c.g ); r = static_cast< value_type >( r - c.r ); return( *this ); }
547
549 template < class TT >
550 const bgr &operator *=( const bgr< TT > &c ){ b = static_cast< value_type >( b * c.b ); g = static_cast< value_type >( g * c.g ); r = static_cast< value_type >( r * c.r ); return( *this ); }
551
553 template < class TT >
554 const bgr &operator /=( const bgr< TT > &c ){ b = static_cast< value_type >( b / c.b ); g = static_cast< value_type >( g / c.g ); r = static_cast< value_type >( r / c.r ); return( *this ); }
555
557 const bgr &operator %=( const bgr &c ){ b %= c.b; g %= c.g; r %= c.r; return( *this ); }
558
560 const bgr &operator |=( const bgr &c ){ b |= c.b; g |= c.g; r |= c.r; return( *this ); }
561
563 const bgr &operator &=( const bgr &c ){ b &= c.b; g &= c.g; r &= c.r; return( *this ); }
564
566 const bgr &operator ^=( const bgr &c ){ b ^= c.b; g ^= c.g; r ^= c.r; return( *this ); }
567
568
570 #if defined( __MIST_MSVC__ ) && __MIST_MSVC__ < 7
571 const bgr &operator +=( const double &pix )
572 #else
573 template < class TT >
574 const bgr &operator +=( const TT &pix )
575 #endif
576 {
577 b = static_cast< value_type >( b + pix );
578 g = static_cast< value_type >( g + pix );
579 r = static_cast< value_type >( r + pix );
580 return( *this );
581 }
582
584 #if defined( __MIST_MSVC__ ) && __MIST_MSVC__ < 7
585 const bgr &operator -=( const double &pix )
586 #else
587 template < class TT >
588 const bgr &operator -=( const TT &pix )
589 #endif
590 {
591 b = static_cast< value_type >( b - pix );
592 g = static_cast< value_type >( g - pix );
593 r = static_cast< value_type >( r - pix );
594 return( *this );
595 }
596
598 #if defined( __MIST_MSVC__ ) && __MIST_MSVC__ < 7
599 const bgr &operator *=( const double &pix )
600 #else
601 template < class TT >
602 const bgr &operator *=( const TT &pix )
603 #endif
604 {
605 b = static_cast< value_type >( b * pix );
606 g = static_cast< value_type >( g * pix );
607 r = static_cast< value_type >( r * pix );
608 return( *this );
609 }
610
612 #if defined( __MIST_MSVC__ ) && __MIST_MSVC__ < 7
613 const bgr &operator /=( const double &pix )
614 #else
615 template < class TT >
616 const bgr &operator /=( const TT &pix )
617 #endif
618 {
619 b = static_cast< value_type >( b / pix );
620 g = static_cast< value_type >( g / pix );
621 r = static_cast< value_type >( r / pix );
622 return( *this );
623 }
624
625
635 bool operator ==( const bgr &c ) const { return( b == c.b && g == c.g && r == c.r ); }
636
646 bool operator !=( const bgr &c ) const { return( !( *this == c ) ); }
647
657 bool operator < ( const bgr &c ) const
658 {
659 if( r == c.r )
660 {
661 if( g == c.g )
662 {
663 return( b < c.b );
664 }
665 else
666 {
667 return( g < c.g );
668 }
669 }
670 else
671 {
672 return( r < c.r );
673 }
674 }
675
685 bool operator <=( const bgr &c ) const { return( c >= *this ); }
686
696 bool operator > ( const bgr &c ) const { return( c < *this ); }
697
707 bool operator >=( const bgr &c ) const { return( !( *this < c ) ); }
708
709
711 value_type get_value( ) const
712 {
713 return( static_cast< value_type >( b * 0.114478 + g * 0.586610 + r * 0.298912 ) );
714 }
715
717 value_type get_average( ) const
718 {
719 double rr = r, gg = g, bb = b;
720 return( static_cast< value_type >( ( rr + gg + bb ) * 0.33333333333333333333333333333333 ) );
721 }
722
723 // カラーからグレースケールへの自動キャスト演算子（危険のため一時停止）
724 //operator value_type( ) const { return( get_value( ) ); }
725
726 };
727
729 DEFINE_PROMOTE_BIND_OPERATOR1( bgr, + )
730
731
732 DEFINE_PROMOTE_BIND_OPERATOR2( bgr, + )
733
735 DEFINE_PROMOTE_BIND_OPERATOR3( bgr, + )
736
738 DEFINE_PROMOTE_BIND_OPERATOR1( bgr, - )
739
741 DEFINE_PROMOTE_BIND_OPERATOR2( bgr, - )
742
744 DEFINE_PROMOTE_BIND_OPERATOR4( bgr, - )
745
747 DEFINE_PROMOTE_BIND_OPERATOR1( bgr, * )
748
750 DEFINE_PROMOTE_BIND_OPERATOR2( bgr, * )
751
753 DEFINE_PROMOTE_BIND_OPERATOR3( bgr, * )
754
756 DEFINE_PROMOTE_BIND_OPERATOR1( bgr, / )
757
759 DEFINE_PROMOTE_BIND_OPERATOR2( bgr, / )
760
762 DEFINE_PROMOTE_BIND_OPERATOR1( bgr, % )
763
764
766 DEFINE_PROMOTE_BIND_OPERATOR1( bgr, | )
767
769 DEFINE_PROMOTE_BIND_OPERATOR1( bgr, & )
770
772 DEFINE_PROMOTE_BIND_OPERATOR1( bgr, ^ )
773
774
775
776
785 template< class T >
786 struct rgba : public rgb< T >
787 {
788 protected:
789 typedef rgb< T > base;
790
791 public:
792 typedef typename base::size_type size_type;
793 typedef typename base::difference_type difference_type;
794 typedef typename base::reference reference;
795 typedef typename base::const_reference const_reference;
796 typedef typename base::value_type value_type;
797 typedef typename base::pointer pointer;
798 typedef typename base::const_pointer const_pointer;
799
801 template < class TT >
802 struct rebind
803 {
804 typedef rgba< TT > other;
805 };
806
807 public:
808 value_type a;
809
811 rgba( const value_type &pix = 0 ) : base( pix ), a( 255 ){ }
812
814 template < class TT >
815 rgba( const rgba< TT > &c ) : base( c ), a( static_cast< value_type >( c.a ) ){ }
816
818 rgba( const rgba< T > &c ) : base( c ), a( c.a ){ }
819
820
822 template < class TT >
823 rgba( const rgb< TT > &c ) : base( c ), a( 255 ){ }
824
826 rgba( const rgb< T > &c ) : base( c ), a( 255 ){ }
827
828
830 rgba( const value_type &rr, const value_type &gg, const value_type &bb, const value_type &aa = 255 ) : base( rr, gg, bb ), a( aa ){ }
831
832
834 template < class TT >
835 const rgba &operator =( const rgba< TT > &c )
836 {
837 base::operator =( c );
838 a = static_cast< value_type >( c.a );
839 return( *this );
840 }
841
843 const rgba &operator =( const rgba< T > &c )
844 {
845 if( &c != this )
846 {
847 base::operator =( c );
848 a = c.a;
849 }
850 return( *this );
851 }
852
854 const rgba &operator =( const value_type &pix )
855 {
856 base::operator =( pix );
857 return( *this );
858 }
859
860
862 const rgba operator -( ) const { return( rgba( -base::r, -base::g, -base::b, a ) ); }
863
865 template < class TT >
866 const rgba &operator +=( const rgba< TT > &c ){ base::operator +=( ( const base &)c ); return( *this ); }
867
869 template < class TT >
870 const rgba &operator -=( const rgba< TT > &c ){ base::operator -=( ( const base &)c ); return( *this ); }
871
873 template < class TT >
874 const rgba &operator *=( const rgba< TT > &c ){ base::operator *=( ( const base &)c ); return( *this ); }
875
877 template < class TT >
878 const rgba &operator /=( const rgba< TT > &c ){ base::operator /=( ( const base &)c ); return( *this ); }
879
881 const rgba &operator %=( const rgba &c ){ base::operator %=( ( const base &)c ); return( *this ); }
882
884 const rgba &operator |=( const rgba &c ){ base::operator |=( ( const base &)c ); return( *this ); }
885
887 const rgba &operator &=( const rgba &c ){ base::operator &=( ( const base &)c ); return( *this ); }
888
890 const rgba &operator ^=( const rgba &c ){ base::operator ^=( ( const base &)c ); return( *this ); }
891
892
894 #if defined( __MIST_MSVC__ ) && __MIST_MSVC__ < 7
895 const rgba &operator +=( const double &pix )
896 #else
897 template < class TT >
898 const rgba &operator +=( const TT &pix )
899 #endif
900 {
901 base::operator +=( pix );
902 return( *this );
903 }
904
906 #if defined( __MIST_MSVC__ ) && __MIST_MSVC__ < 7
907 const rgba &operator -=( const double &pix )
908 #else
909 template < class TT >
910 const rgba &operator -=( const TT &pix )
911 #endif
912 {
913 base::operator -=( pix );
914 return( *this );
915 }
916
918 #if defined( __MIST_MSVC__ ) && __MIST_MSVC__ < 7
919 const rgba &operator *=( const double &pix )
920 #else
921 template < class TT >
922 const rgba &operator *=( const TT &pix )
923 #endif
924 {
925 base::operator *=( pix );
926 return( *this );
927 }
928
930 #if defined( __MIST_MSVC__ ) && __MIST_MSVC__ < 7
931 const rgba &operator /=( const double &pix )
932 #else
933 template < class TT >
934 const rgba &operator /=( const TT &pix )
935 #endif
936 {
937 base::operator /=( pix );
938 return( *this );
939 }
940
941
951 bool operator ==( const rgba &c ) const { return( base::operator ==( c ) ); }
952
962 bool operator !=( const rgba &c ) const { return( !( *this == c ) ); }
963
973 bool operator < ( const rgba &c ) const
974 {
975 if( a == c.a )
976 {
977 return( base::operator <( c ) );
978 }
979 else
980 {
981 return( a < c.a );
982 }
983 }
984
994 bool operator <=( const rgba &c ) const { return( c >= *this ); }
995
1005 bool operator > ( const rgba &c ) const { return( c < *this ); }
1006
1016 bool operator >=( const rgba &c ) const { return( !( *this < c ) ); }
1017
1018 };
1019
1021 DEFINE_PROMOTE_BIND_OPERATOR1( rgba, + )
1022
1023
1024 DEFINE_PROMOTE_BIND_OPERATOR2( rgba, + )
1025
1027 DEFINE_PROMOTE_BIND_OPERATOR3( rgba, + )
1028
1030 DEFINE_PROMOTE_BIND_OPERATOR1( rgba, - )
1031
1033 DEFINE_PROMOTE_BIND_OPERATOR2( rgba, - )
1034
1036 DEFINE_PROMOTE_BIND_OPERATOR4( rgba, - )
1037
1039 DEFINE_PROMOTE_BIND_OPERATOR1( rgba, * )
1040
1042 DEFINE_PROMOTE_BIND_OPERATOR2( rgba, * )
1043
1045 DEFINE_PROMOTE_BIND_OPERATOR3( rgba, * )
1046
1048 DEFINE_PROMOTE_BIND_OPERATOR1( rgba, / )
1049
1051 DEFINE_PROMOTE_BIND_OPERATOR2( rgba, / )
1052
1054 DEFINE_PROMOTE_BIND_OPERATOR1( rgba, % )
1055
1056
1058 DEFINE_PROMOTE_BIND_OPERATOR1( rgba, | )
1059
1061 DEFINE_PROMOTE_BIND_OPERATOR1( rgba, & )
1062
1064 DEFINE_PROMOTE_BIND_OPERATOR1( rgba, ^ )
1065
1066
1067
1068
1069
1070
1071
1072
1073
1084 template< class T >
1085 struct bgra : public bgr< T >
1086 {
1087 protected:
1088 typedef bgr< T > base;
1089
1090 public:
1091 typedef typename base::size_type size_type;
1092 typedef typename base::difference_type difference_type;
1093 typedef typename base::reference reference;
1094 typedef typename base::const_reference const_reference;
1095 typedef typename base::value_type value_type;
1096 typedef typename base::pointer pointer;
1097 typedef typename base::const_pointer const_pointer;
1098
1100 template < class TT >
1101 struct rebind
1102 {
1103 typedef bgra< TT > other;
1104 };
1105
1106 public:
1107 value_type a;
1108
1110 bgra( const value_type &pix = 0 ) : base( pix ), a( 255 ){ }
1111
1113 template < class TT >
1114 bgra( const bgra< TT > &c ) : base( c ), a( static_cast< value_type >( c.a ) ){ }
1115
1117 bgra( const bgra< T > &c ) : base( c ), a( c.a ){ }
1118
1119
1121 template < class TT >
1122 bgra( const rgb< TT > &c ) : base( c ), a( 255 ){ }
1123
1125 bgra( const rgb< T > &c ) : base( c ), a( 255 ){ }
1126
1127
1129 template < class TT >
1130 bgra( const bgr< TT > &c ) : base( c ), a( 255 ){ }
1131
1133 bgra( const bgr< T > &c ) : base( c ), a( 255 ){ }
1134
1136 template < class TT >
1137 bgra( const rgba< TT > &c ) : base( c ), a( c.a ){ }
1138
1140 bgra( const value_type &rr, const value_type &gg, const value_type &bb, const value_type &aa = 255 ) : base( rr, gg, bb ), a( aa ){ }
1141
1142
1144 template < class TT >
1145 const bgra &operator =( const bgra< TT > &c )
1146 {
1147 base::operator =( c );
1148 a = static_cast< value_type >( c.a );
1149 return( *this );
1150 }
1151
1153 const bgra &operator =( const bgra< T > &c )
1154 {
1155 if( &c != this )
1156 {
1157 base::operator =( c );
1158 a = c.a;
1159 }
1160 return( *this );
1161 }
1162
1164 const bgra &operator =( const value_type &pix )
1165 {
1166 base::operator =( pix );
1167 return( *this );
1168 }
1169
1170
1172 const bgra operator -( ) const { return( bgra( -base::r, -base::g, -base::b, a ) ); }
1173
1175 template < class TT >
1176 const bgra &operator +=( const bgra< TT > &c ){ base::operator +=( ( const base &)c ); return( *this ); }
1177
1179 template < class TT >
1180 const bgra &operator -=( const bgra< TT > &c ){ base::operator -=( ( const base &)c ); return( *this ); }
1181
1183 template < class TT >
1184 const bgra &operator *=( const bgra< TT > &c ){ base::operator *=( ( const base &)c ); return( *this ); }
1185
1187 template < class TT >
1188 const bgra &operator /=( const bgra< TT > &c ){ base::operator /=( ( const base &)c ); return( *this ); }
1189
1191 const bgra &operator %=( const bgra &c ){ base::operator %=( ( const base &)c ); return( *this ); }
1192
1194 const bgra &operator |=( const bgra &c ){ base::operator |=( ( const base &)c ); return( *this ); }
1195
1197 const bgra &operator &=( const bgra &c ){ base::operator &=( ( const base &)c ); return( *this ); }
1198
1200 const bgra &operator ^=( const bgra &c ){ base::operator ^=( ( const base &)c ); return( *this ); }
1201
1202
1204 #if defined( __MIST_MSVC__ ) && __MIST_MSVC__ < 7
1205 const bgra &operator +=( const double &pix )
1206 #else
1207 template < class TT >
1208 const bgra &operator +=( const TT &pix )
1209 #endif
1210 {
1211 base::operator +=( pix );
1212 return( *this );
1213 }
1214
1216 #if defined( __MIST_MSVC__ ) && __MIST_MSVC__ < 7
1217 const bgra &operator -=( const double &pix )
1218 #else
1219 template < class TT >
1220 const bgra &operator -=( const TT &pix )
1221 #endif
1222 {
1223 base::operator -=( pix );
1224 return( *this );
1225 }
1226
1228 #if defined( __MIST_MSVC__ ) && __MIST_MSVC__ < 7
1229 const bgra &operator *=( const double &pix )
1230 #else
1231 template < class TT >
1232 const bgra &operator *=( const TT &pix )
1233 #endif
1234 {
1235 base::operator *=( pix );
1236 return( *this );
1237 }
1238
1240 #if defined( __MIST_MSVC__ ) && __MIST_MSVC__ < 7
1241 const bgra &operator /=( const double &pix )
1242 #else
1243 template < class TT >
1244 const bgra &operator /=( const TT &pix )
1245 #endif
1246 {
1247 base::operator /=( pix );
1248 return( *this );
1249 }
1250
1251
1261 bool operator ==( const bgra &c ) const { return( base::operator ==( c ) ); }
1262
1272 bool operator !=( const bgra &c ) const { return( !( *this == c ) ); }
1273
1283 bool operator < ( const bgra &c ) const
1284 {
1285 if( a == c.a )
1286 {
1287 return( base::operator <( c ) );
1288 }
1289 else
1290 {
1291 return( a < c.a );
1292 }
1293 }
1294
1295
1305 bool operator <=( const bgra &c ) const { return( c >= *this ); }
1306
1316 bool operator > ( const bgra &c ) const { return( c < *this ); }
1317
1327 bool operator >=( const bgra &c ) const { return( !( *this < c ) ); }
1328
1329 };
1330
1332 DEFINE_PROMOTE_BIND_OPERATOR1( bgra, + )
1333
1334
1335 DEFINE_PROMOTE_BIND_OPERATOR2( bgra, + )
1336
1338 DEFINE_PROMOTE_BIND_OPERATOR3( bgra, + )
1339
1341 DEFINE_PROMOTE_BIND_OPERATOR1( bgra, - )
1342
1344 DEFINE_PROMOTE_BIND_OPERATOR2( bgra, - )
1345
1347 DEFINE_PROMOTE_BIND_OPERATOR4( bgra, - )
1348
1350 DEFINE_PROMOTE_BIND_OPERATOR1( bgra, * )
1351
1353 DEFINE_PROMOTE_BIND_OPERATOR2( bgra, * )
1354
1356 DEFINE_PROMOTE_BIND_OPERATOR3( bgra, * )
1357
1359 DEFINE_PROMOTE_BIND_OPERATOR1( bgra, / )
1360
1362 DEFINE_PROMOTE_BIND_OPERATOR2( bgra, / )
1363
1365 DEFINE_PROMOTE_BIND_OPERATOR1( bgra, % )
1366
1367
1369 DEFINE_PROMOTE_BIND_OPERATOR1( bgra, | )
1370
1372 DEFINE_PROMOTE_BIND_OPERATOR1( bgra, & )
1373
1375 DEFINE_PROMOTE_BIND_OPERATOR1( bgra, ^ )
1376
1377
1386 template< class T >
1387 struct nRGB : public rgb< T >
1388 {
1389 private:
1390 typedef rgb< T > base;
1391 typedef __color_utility__::__normalized_color__< is_float< T >::value > __color_normalizer__;
1392
1393 public:
1394 typedef typename base::size_type size_type;
1395 typedef typename base::difference_type difference_type;
1396 typedef T& reference;
1397 typedef const T& const_reference;
1398 typedef T value_type;
1399 typedef T* pointer;
1400 typedef const T* const_pointer;
1401
1403 template < class TT >
1404 struct rebind
1405 {
1406 typedef nRGB< TT > other;
1407 };
1408
1409 public:
1410 value_type R;
1411 value_type G;
1412 value_type B;
1413
1415 nRGB( ) : base( ), R( 0 ), G( 0 ), B( 0 ){ }
1416
1418 explicit nRGB( const value_type &pix ) : base( pix )
1419 {
1420 __color_normalizer__::compute( base::r, base::g, base::b, R, G, B );
1421 }
1422
1424 template < class TT >
1425 nRGB( const nRGB< TT > &c ) : base( c ), R( static_cast< T >( c.R ) ), G( static_cast< T >( c.G ) ), B( static_cast< T >( c.B ) ){ }
1426
1428 nRGB( const nRGB< T > &c ) : base( c ), R( c.R ), G( c.G ), B( c.B ){ }
1429
1431 template < class TT >
1432 nRGB( const rgb< TT > &c ) : base( c )
1433 {
1434 __color_normalizer__::compute( base::r, base::g, base::b, R, G, B );
1435 }
1436
1438 nRGB( const rgb< T > &c ) : base( c )
1439 {
1440 __color_normalizer__::compute( base::r, base::g, base::b, R, G, B );
1441 }
1442
1444 template < class TT >
1445 nRGB( const bgr< TT > &c ) : base( c )
1446 {
1447 __color_normalizer__::compute( base::r, base::g, base::b, R, G, B );
1448 }
1449
1451 nRGB( const bgr< T > &c ) : base( c )
1452 {
1453 __color_normalizer__::compute( base::r, base::g, base::b, R, G, B );
1454 }
1455
1456
1458 nRGB( const value_type &rr, const value_type &gg, const value_type &bb ) : base( rr, gg, bb )
1459 {
1460 __color_normalizer__::compute( base::r, base::g, base::b, R, G, B );
1461 }
1462
1464 nRGB( const value_type &rr, const value_type &gg, const value_type &bb, const value_type &RR, const value_type &GG, const value_type &BB ) : base( rr, gg, bb ), R( RR ), G( GG ), B( BB ){ }
1465
1466
1468 template < class TT >
1469 const nRGB &operator =( const nRGB< TT > &c )
1470 {
1471 base::operator =( c );
1472 R = static_cast< value_type >( c.R );
1473 G = static_cast< value_type >( c.G );
1474 B = static_cast< value_type >( c.B );
1475 return( *this );
1476 }
1477
1479 template < class TT >
1480 const nRGB &operator =( const rgb< TT > &c )
1481 {
1482 base::operator =( c );
1483 __color_normalizer__::compute( base::r, base::g, base::b, R, G, B );
1484 return( *this );
1485 }
1486
1488 template < class TT >
1489 const nRGB &operator =( const bgr< TT > &c )
1490 {
1491 base::operator =( c );
1492 __color_normalizer__::compute( base::r, base::g, base::b, R, G, B );
1493 return( *this );
1494 }
1495
1497 const nRGB &operator =( const nRGB< T > &c )
1498 {
1499 if( &c != this )
1500 {
1501 base::operator =( c );
1502 R = c.R;
1503 G = c.G;
1504 B = c.B;
1505 }
1506 return( *this );
1507 }
1508
1510 const nRGB &operator =( const value_type &pix )
1511 {
1512 base::operator =( pix );
1513 __color_normalizer__::compute( base::r, base::g, base::b, R, G, B );
1514 return( *this );
1515 }
1516
1517
1519 const nRGB operator -( ) const { return( nRGB( -base::r, -base::g, -base::b, -R, -G, -B ) ); }
1520
1522 template < class TT >
1523 const nRGB &operator +=( const nRGB< TT > &c )
1524 {
1525 base::operator +=( ( const base &)c );
1526 R = static_cast< value_type >( R + c.R );
1527 G = static_cast< value_type >( G + c.G );
1528 B = static_cast< value_type >( B + c.B );
1529 return( *this );
1530 }
1531
1533 template < class TT >
1534 const nRGB &operator -=( const nRGB< TT > &c )
1535 {
1536 base::operator -=( ( const base &)c );
1537 R = static_cast< value_type >( R - c.R );
1538 G = static_cast< value_type >( G - c.G );
1539 B = static_cast< value_type >( B - c.B );
1540 return( *this );
1541 }
1542
1544 template < class TT >
1545 const nRGB &operator *=( const nRGB< TT > &c )
1546 {
1547 base::operator *=( ( const base &)c );
1548 R = static_cast< value_type >( R * c.R );
1549 G = static_cast< value_type >( G * c.G );
1550 B = static_cast< value_type >( B * c.B );
1551 return( *this );
1552 }
1553
1555 template < class TT >
1556 const nRGB &operator /=( const nRGB< TT > &c )
1557 {
1558 base::operator /=( ( const base &)c );
1559 R = static_cast< value_type >( R / c.R );
1560 G = static_cast< value_type >( G / c.G );
1561 B = static_cast< value_type >( B / c.B );
1562 return( *this );
1563 }
1564
1566 const nRGB &operator %=( const nRGB &c )
1567 {
1568 base::operator %=( ( const base &)c );
1569 R %= c.R;
1570 G %= c.G;
1571 B %= c.B;
1572 return( *this );
1573 }
1574
1576 const nRGB &operator |=( const nRGB &c )
1577 {
1578 base::operator |=( ( const base &)c );
1579 R |= c.R;
1580 G |= c.G;
1581 B |= c.B;
1582 return( *this );
1583 }
1584
1586 const nRGB &operator &=( const nRGB &c )
1587 {
1588 base::operator &=( ( const base &)c );
1589 R &= c.R;
1590 G &= c.G;
1591 B &= c.B;
1592 return( *this );
1593 }
1594
1596 const nRGB &operator ^=( const nRGB &c )
1597 {
1598 base::operator ^=( ( const base &)c );
1599 R ^= c.R;
1600 G ^= c.G;
1601 B ^= c.B;
1602 return( *this );
1603 }
1604
1605
1607 #if defined( __MIST_MSVC__ ) && __MIST_MSVC__ < 7
1608 const nRGB &operator +=( const double &pix )
1609 #else
1610 template < class TT >
1611 const nRGB &operator +=( const TT &pix )
1612 #endif
1613 {
1614 base::operator +=( pix );
1615 R = static_cast< value_type >( R + pix );
1616 G = static_cast< value_type >( G + pix );
1617 B = static_cast< value_type >( B + pix );
1618 return( *this );
1619 }
1620
1622 #if defined( __MIST_MSVC__ ) && __MIST_MSVC__ < 7
1623 const nRGB &operator -=( const double &pix )
1624 #else
1625 template < class TT >
1626 const nRGB &operator -=( const TT &pix )
1627 #endif
1628 {
1629 base::operator -=( pix );
1630 R = static_cast< value_type >( R - pix );
1631 G = static_cast< value_type >( G - pix );
1632 B = static_cast< value_type >( B - pix );
1633 return( *this );
1634 }
1635
1637 #if defined( __MIST_MSVC__ ) && __MIST_MSVC__ < 7
1638 const nRGB &operator *=( const double &pix )
1639 #else
1640 template < class TT >
1641 const nRGB &operator *=( const TT &pix )
1642 #endif
1643 {
1644 base::operator *=( pix );
1645 R = static_cast< value_type >( R * pix );
1646 G = static_cast< value_type >( G * pix );
1647 B = static_cast< value_type >( B * pix );
1648 return( *this );
1649 }
1650
1652 #if defined( __MIST_MSVC__ ) && __MIST_MSVC__ < 7
1653 const nRGB &operator /=( const double &pix )
1654 #else
1655 template < class TT >
1656 const nRGB &operator /=( const TT &pix )
1657 #endif
1658 {
1659 base::operator /=( pix );
1660 R = static_cast< value_type >( R / pix );
1661 G = static_cast< value_type >( G / pix );
1662 B = static_cast< value_type >( B / pix );
1663 return( *this );
1664 }
1665 };
1666
1667
1668
1670 DEFINE_PROMOTE_BIND_OPERATOR1( nRGB, + )
1671
1672
1673 DEFINE_PROMOTE_BIND_OPERATOR2( nRGB, + )
1674
1676 DEFINE_PROMOTE_BIND_OPERATOR3( nRGB, + )
1677
1679 DEFINE_PROMOTE_BIND_OPERATOR1( nRGB, - )
1680
1682 DEFINE_PROMOTE_BIND_OPERATOR2( nRGB, - )
1683
1685 DEFINE_PROMOTE_BIND_OPERATOR4( nRGB, - )
1686
1688 DEFINE_PROMOTE_BIND_OPERATOR1( nRGB, * )
1689
1691 DEFINE_PROMOTE_BIND_OPERATOR2( nRGB, * )
1692
1694 DEFINE_PROMOTE_BIND_OPERATOR3( nRGB, * )
1695
1697 DEFINE_PROMOTE_BIND_OPERATOR1( nRGB, / )
1698
1700 DEFINE_PROMOTE_BIND_OPERATOR2( nRGB, / )
1701
1703 DEFINE_PROMOTE_BIND_OPERATOR1( nRGB, % )
1704
1705
1707 DEFINE_PROMOTE_BIND_OPERATOR1( nRGB, | )
1708
1710 DEFINE_PROMOTE_BIND_OPERATOR1( nRGB, & )
1711
1713 DEFINE_PROMOTE_BIND_OPERATOR1( nRGB, ^ )
1714
1715
1716
1725 template< class T, size_t NDIM = 9 >
1726 struct color
1727 {
1728 public:
1729 typedef size_t size_type;
1730 typedef ptrdiff_t difference_type;
1731 typedef T& reference;
1732 typedef const T& const_reference;
1733 typedef T value_type;
1734 typedef T* pointer;
1735 typedef const T* const_pointer;
1736
1738 template < class TT >
1739 struct rebind
1740 {
1741 typedef color< TT, NDIM > other;
1742 };
1743
1744 private:
1745 value_type c_[ NDIM ];
1746
1747 public:
1748
1750 color( const value_type &pix = 0 )
1751 {
1752 for( size_type i = 0 ; i < NDIM ; i++ )
1753 {
1754 c_[ i ] = pix;
1755 }
1756 }
1757
1759 template < class TT >
1760 color( const color< TT, NDIM > &c )
1761 {
1762 for( size_type i = 0 ; i < NDIM ; i++ )
1763 {
1764 c_[ i ] = static_cast< value_type >( c[ i ] );
1765 }
1766 }
1767
1769 color( const color< T, NDIM > &c )
1770 {
1771 for( size_type i = 0 ; i < NDIM ; i++ )
1772 {
1773 c_[ i ] = c[ i ];
1774 }
1775 }
1776
1777
1779 template < class TT >
1780 const color &operator =( const color< TT, NDIM > &c )
1781 {
1782 for( size_type i = 0 ; i < NDIM ; i++ )
1783 {
1784 c_[ i ] = static_cast< value_type >( c[ i ] );
1785 }
1786 return( *this );
1787 }
1788
1790 const color &operator =( const color< T, NDIM > &c )
1791 {
1792 if( &c != this )
1793 {
1794 for( size_type i = 0 ; i < NDIM ; i++ )
1795 {
1796 c_[ i ] = c[ i ];
1797 }
1798 }
1799 return( *this );
1800 }
1801
1803 const color &operator =( const value_type &pix )
1804 {
1805 for( size_type i = 0 ; i < NDIM ; i++ )
1806 {
1807 c_[ i ] = pix;
1808 }
1809 return( *this );
1810 }
1811
1812
1814 const color operator -( ) const
1815 {
1816 color c;
1817 for( size_type i = 0 ; i < NDIM ; i++ )
1818 {
1819 c[ i ] = -c_[ i ];
1820 }
1821 return( c );
1822 }
1823
1825 template < class TT >
1826 const color &operator +=( const color< TT, NDIM > &c )
1827 {
1828 for( size_type i = 0 ; i < NDIM ; i++ )
1829 {
1830 c_[ i ] = static_cast< value_type >( c_[ i ] + c[ i ] );
1831 }
1832 return( *this );
1833 }
1834
1836 template < class TT >
1837 const color &operator -=( const color< TT, NDIM > &c )
1838 {
1839 for( size_type i = 0 ; i < NDIM ; i++ )
1840 {
1841 c_[ i ] = static_cast< value_type >( c_[ i ] - c[ i ] );
1842 }
1843 return( *this );
1844 }
1845
1847 template < class TT >
1848 const color &operator *=( const color< TT, NDIM > &c )
1849 {
1850 for( size_type i = 0 ; i < NDIM ; i++ )
1851 {
1852 c_[ i ] = static_cast< value_type >( c_[ i ] * c[ i ] );
1853 }
1854 return( *this );
1855 }
1856
1858 template < class TT >
1859 const color &operator /=( const color< TT, NDIM > &c )
1860 {
1861 for( size_type i = 0 ; i < NDIM ; i++ )
1862 {
1863 c_[ i ] = static_cast< value_type >( c_[ i ] / c[ i ] );
1864 }
1865 return( *this );
1866 }
1867
1869 const color &operator %=( const color &c )
1870 {
1871 for( size_type i = 0 ; i < NDIM ; i++ )
1872 {
1873 c_[ i ] %= c[ i ];
1874 }
1875 return( *this );
1876 }
1877
1879 const color &operator |=( const color &c )
1880 {
1881 for( size_type i = 0 ; i < NDIM ; i++ )
1882 {
1883 c_[ i ] |= c[ i ];
1884 }
1885 return( *this );
1886 }
1887
1889 const color &operator &=( const color &c )
1890 {
1891 for( size_type i = 0 ; i < NDIM ; i++ )
1892 {
1893 c_[ i ] &= c[ i ];
1894 }
1895 return( *this );
1896 }
1897
1899 const color &operator ^=( const color &c )
1900 {
1901 for( size_type i = 0 ; i < NDIM ; i++ )
1902 {
1903 c_[ i ] ^= c[ i ];
1904 }
1905 return( *this );
1906 }
1907
1908
1910 #if defined( __MIST_MSVC__ ) && __MIST_MSVC__ < 7
1911 const color &operator +=( const double &pix )
1912 #else
1913 template < class TT >
1914 const color &operator +=( const TT &pix )
1915 #endif
1916 {
1917 for( size_type i = 0 ; i < NDIM ; i++ )
1918 {
1919 c_[ i ] = static_cast< value_type >( c_[ i ] + pix );
1920 }
1921 return( *this );
1922 }
1923
1925 #if defined( __MIST_MSVC__ ) && __MIST_MSVC__ < 7
1926 const color &operator -=( const double &pix )
1927 #else
1928 template < class TT >
1929 const color &operator -=( const TT &pix )
1930 #endif
1931 {
1932 for( size_type i = 0 ; i < NDIM ; i++ )
1933 {
1934 c_[ i ] = static_cast< value_type >( c_[ i ] - pix );
1935 }
1936 return( *this );
1937 }
1938
1940 #if defined( __MIST_MSVC__ ) && __MIST_MSVC__ < 7
1941 const color &operator *=( const double &pix )
1942 #else
1943 template < class TT >
1944 const color &operator *=( const TT &pix )
1945 #endif
1946 {
1947 for( size_type i = 0 ; i < NDIM ; i++ )
1948 {
1949 c_[ i ] = static_cast< value_type >( c_[ i ] * pix );
1950 }
1951 return( *this );
1952 }
1953
1955 #if defined( __MIST_MSVC__ ) && __MIST_MSVC__ < 7
1956 const color &operator /=( const double &pix )
1957 #else
1958 template < class TT >
1959 const color &operator /=( const TT &pix )
1960 #endif
1961 {
1962 for( size_type i = 0 ; i < NDIM ; i++ )
1963 {
1964 c_[ i ] = static_cast< value_type >( c_[ i ] / pix );
1965 }
1966 return( *this );
1967 }
1968
1969
1979 bool operator ==( const color &c ) const
1980 {
1981 for( size_type i = 0 ; i < NDIM ; i++ )
1982 {
1983 if( c_[ i ] != c[ i ] )
1984 {
1985 return( false );
1986 }
1987 }
1988
1989 return( true );
1990 }
1991
2001 bool operator !=( const color &c ) const { return( !( *this == c ) ); }
2002
2012 bool operator < ( const color &c ) const
2013 {
2014 for( size_type i = 0 ; i < NDIM ; i++ )
2015 {
2016 if( c_[ i ] != c[ i ] )
2017 {
2018 return( c_[ i ] < c[ i ] );
2019 }
2020 }
2021
2022 return( false );
2023 }
2024
2034 bool operator <=( const color &c ) const { return( c >= *this ); }
2035
2045 bool operator > ( const color &c ) const { return( c < *this ); }
2046
2056 bool operator >=( const color &c ) const { return( !( *this < c ) ); }
2057
2058 value_type & operator []( size_type index ){ return( c_[ index ] ); }
2059
2060 const value_type & operator []( size_type index ) const { return( c_[ index ] ); }
2061
2063 value_type get_value( ) const
2064 {
2065 double sum = 0.0;
2066 for( size_type i = 0 ; i < NDIM - 1 ; i++ )
2067 {
2068 sum += c_[ i ];
2069 }
2070 return( half_adjust< value_type >::convert( sum ) );
2071 }
2072
2073 // カラーからグレースケールへの自動キャスト演算子（危険のため一時停止）
2074 //operator value_type( ) const { return( get_value( ) ); }
2075 };
2076
2077
2078
2080 DEFINE_PROMOTE_BIND_OPERATOR1_( color, + )
2081
2082
2083 DEFINE_PROMOTE_BIND_OPERATOR2_( color, + )
2084
2086 DEFINE_PROMOTE_BIND_OPERATOR3_( color, + )
2087
2089 DEFINE_PROMOTE_BIND_OPERATOR1_( color, - )
2090
2092 DEFINE_PROMOTE_BIND_OPERATOR2_( color, - )
2093
2095 DEFINE_PROMOTE_BIND_OPERATOR4_( color, - )
2096
2098 DEFINE_PROMOTE_BIND_OPERATOR1_( color, * )
2099
2101 DEFINE_PROMOTE_BIND_OPERATOR2_( color, * )
2102
2104 DEFINE_PROMOTE_BIND_OPERATOR3_( color, * )
2105
2107 DEFINE_PROMOTE_BIND_OPERATOR1_( color, / )
2108
2110 DEFINE_PROMOTE_BIND_OPERATOR2_( color, / )
2111
2113 DEFINE_PROMOTE_BIND_OPERATOR1_( color, % )
2114
2115
2117 DEFINE_PROMOTE_BIND_OPERATOR1_( color, | )
2118
2120 DEFINE_PROMOTE_BIND_OPERATOR1_( color, & )
2121
2123 DEFINE_PROMOTE_BIND_OPERATOR1_( color, ^ )
2124
2125
2126
2127
2139 template < class T > inline std::ostream &operator <<( std::ostream &out, const rgb< T > &c )
2140 {
2141 out << "( ";
2142 out << c.r << ", ";
2143 out << c.g << ", ";
2144 out << c.b << " )";
2145 return( out );
2146 }
2147
2148
2160 template < class T > inline std::ostream &operator <<( std::ostream &out, const rgba< T > &c )
2161 {
2162 out << "( ";
2163 out << c.r << ", ";
2164 out << c.g << ", ";
2165 out << c.b << ", ";
2166 out << c.a << " )";
2167 return( out );
2168 }
2169
2170
2182 template < class T > inline std::ostream &operator <<( std::ostream &out, const nRGB< T > &c )
2183 {
2184 out << "( ";
2185 out << c.r << ", ";
2186 out << c.g << ", ";
2187 out << c.b << ", ";
2188 out << c.R << ", ";
2189 out << c.G << ", ";
2190 out << c.B << " )";
2191 return( out );
2192 }
2193
2194
2206 template < class T, size_t NDIM > inline std::ostream &operator <<( std::ostream &out, const color< T, NDIM > &c )
2207 {
2208 out << "( ";
2209 for( size_t i = 0 ; i < NDIM - 1 ; i++ )
2210 {
2211 out << c[ i ] << ", ";
2212 }
2213 out << c[ NDIM - 1 ] << " )";
2214 return( out );
2215 }
2216
2217
2218
2230 inline void rgb2hsv( double r, double g, double b, double &h, double &s, double &v )
2231 {
2232 double max = __color_utility__::maximum( r, __color_utility__::maximum( g, b ) );
2233 double min = __color_utility__::minimum( r, __color_utility__::minimum( g, b ) );
2234
2235 double d = max - min;
2236 v = max / 255.0;
2237
2238 if( d != 0.0 )
2239 {
2240 s = d / max;
2241 }
2242 else
2243 {
2244 s = 0.0;
2245 }
2246
2247 if( s == 0.0 )
2248 {
2249 h = 0.0;
2250 }
2251 else
2252 {
2253 double rt = max - r * 60.0 / d;
2254 double gt = max - g * 60.0 / d;
2255 double bt = max - b * 60.0 / d;
2256
2257 if( r == max )
2258 {
2259 h = bt - gt;
2260 }
2261 else if( g == max )
2262 {
2263 h = 120 + rt - bt;
2264 }
2265 else
2266 {
2267 h = 240 + gt - rt;
2268 }
2269
2270 if( h < 0.0 )
2271 {
2272 h += 360.0;
2273 }
2274 }
2275 }
2276
2277
2289 inline void hsv2rgb( double h, double s, double v, double &r, double &g, double &b )
2290 {
2291 if( s == 0.0 )
2292 {
2293 r = g = b = v * 255.0;
2294 }
2295 else
2296 {
2297 int ht = static_cast< int >( h * 6.0 );
2298 int d = ht % 360;
2299
2300 ht /= 360;
2301
2302 double t1 = v * ( 1.0 - s );
2303 double t2 = v * ( 1.0 - s * d / 360.0 );
2304 double t3 = v * ( 1.0 - s * ( 360.0 - d ) / 360.0 );
2305
2306 switch( ht )
2307 {
2308 case 0:
2309 r = v;
2310 g = t3;
2311 b = t1;
2312 break;
2313
2314 case 1:
2315 r = t2;
2316 g = v;
2317 b = t1;
2318 break;
2319
2320 case 2:
2321 r = t1;
2322 g = v;
2323 b = t3;
2324 break;
2325
2326 case 3:
2327 r = t1;
2328 g = t2;
2329 b = v;
2330 break;
2331
2332 case 4:
2333 r = t3;
2334 g = t1;
2335 b = v;
2336 break;
2337
2338 default:
2339 r = v;
2340 g = t1;
2341 b = t2;
2342 break;
2343 }
2344
2345 r *= 255.0;
2346 g *= 255.0;
2347 b *= 255.0;
2348 }
2349 }
2350
2361 inline void rgb2yiq( double r, double g, double b, double &y, double &i, double &q )
2362 {
2363 y = 0.299 * r + 0.587 * g + 0.114 * b;
2364 i = 0.596 * r - 0.274 * g - 0.322 * b;
2365 q = 0.211 * r - 0.522 * g + 0.311 * b;
2366 }
2367
2368
2379 inline void yiq2rgb( double y, double i, double q, double &r, double &g, double &b )
2380 {
2381 r = y + 0.9489 * i + 0.6561 * q;
2382 g = y - 0.2645 * i - 0.6847 * q;
2383 b = y - 1.1270 * i + 1.8050 * q;
2384 }
2385
2386
2398 inline void rgb2ycbcr( double r, double g, double b, double &y, double &cb, double &cr )
2399 {
2400 y = 0.257 * r + 0.504 * g + 0.098 * b + 16.0;
2401 cb = -0.148 * r - 0.219 * g + 0.439 * b + 128.0;
2402 cr = 0.439 * r - 0.368 * g - 0.071 * b + 128.0;
2403 //y = 0.29891 * r + 0.58661 * g + 0.11448 * b;
2404 //cb = -0.16874 * r - 0.33126 * g + 0.50000 * b;
2405 //cr = 0.50000 * r - 0.41869 * g - 0.08131 * b;
2406 }
2407
2408
2420 inline void ycbcr2rgb( double y, double cb, double cr, double &r, double &g, double &b )
2421 {
2422 y -= 16.0;
2423 cb -= 128.0;
2424 cr -= 128.0;
2425
2426 r = 1.164 * y + 1.596 * cr;
2427 g = 1.164 * y - 0.813 * cr - 0.392 * cb;
2428 b = 1.164 * y + 2.017 * cb;
2429 //r = y + 1.40200 * cr;
2430 //g = y - 0.71414 * cr - 0.34414 * cb;
2431 //b = y + 1.77200 * cb;
2432 }
2433
2434
2446 inline void rgb2xyz( double r, double g, double b, double &x, double &y, double &z )
2447 {
2448 x = ( 0.412453 * r + 0.357580 * g + 0.180423 * b ) / 255.0;
2449 y = ( 0.212671 * r + 0.715160 * g + 0.072169 * b ) / 255.0;
2450 z = ( 0.019334 * r + 0.119193 * g + 0.950227 * b ) / 255.0;
2451 }
2452
2453
2465 inline void xyz2rgb( double x, double y, double z, double &r, double &g, double &b )
2466 {
2467 r = ( 3.240479 * x - 1.537150 * y - 0.498535 * z ) * 255.0;
2468 g = ( -0.969256 * x + 1.875991 * y + 0.041556 * z ) * 255.0;
2469 b = ( 0.055648 * x - 0.204043 * y + 1.057311 * z ) * 255.0;
2470 }
2471
2472
2484 inline void rgb2lab( double r, double g, double b, double &l_, double &a_, double &b_ )
2485 {
2486 double x, y, z;
2487
2488 // XYZ表色系からRGB表色系へ変換
2489 rgb2xyz( r, g, b, x, y, z );
2490
2491 static const double Xr = 0.9504;
2492 static const double Yr = 1.0;
2493 static const double Zr = 1.0889;
2494
2495 x /= Xr;
2496 y /= Yr;
2497 z /= Zr;
2498
2499 static const double th = 216.0 / 24389.0;
2500 static const double _1_3 = 1.0 / 3.0;
2501 static const double A = 29.0 * 29.0 / ( 3.0 * 6.0 * 6.0 );
2502 static const double B = 4.0 / 29.0;
2503 x = x > th ? std::pow( x, _1_3 ) : A * x + B;
2504 y = y > th ? std::pow( y, _1_3 ) : A * y + B;
2505 z = z > th ? std::pow( z, _1_3 ) : A * z + B;
2506
2507 l_ = 116.0 * y - 16.0;
2508 a_ = 500.0 * ( x - y );
2509 b_ = 200.0 * ( y - z );
2510 }
2511
2523 inline void lab2rgb( double l_, double a_, double b_, double &r, double &g, double &b )
2524 {
2525 double fy = ( l_ + 16.0 ) / 116.0;
2526 double fx = fy + a_ / 500.0 ;
2527 double fz = fy - b_ / 200.0;
2528
2529 static const double Xr = 0.9504;
2530 static const double Yr = 1.0;
2531 static const double Zr = 1.0889;
2532
2533 static const double delta = 6.0 / 29.0;
2534 static const double delta2 = 3.0 * delta * delta;
2535 double y = fy > delta ? Yr * fy * fy * fy : ( fy - 16.0 / 116.0 ) * delta2 * Yr;
2536 double x = fx > delta ? Xr * fx * fx * fx : ( fx - 16.0 / 116.0 ) * delta2 * Xr;
2537 double z = fz > delta ? Zr * fz * fz * fz : ( fz - 16.0 / 116.0 ) * delta2 * Zr;
2538
2539 // XYZ表色系からRGB表色系へ変換
2540 xyz2rgb( x, y, z, r, g, b );
2541 }
2542
2544 template < class T >
2545 struct is_color
2546 {
2547 _MIST_CONST( bool, value, false );
2548 };
2549
2550
2552 // MIST全般で利用できるMIST全般で利用可能な色を表現するクラス
2553
2554
2555 // 画素の変換をサポートするためのコンバータ
2556 template < class T >
2557 struct _pixel_converter_
2558 {
2559 typedef T value_type;
2560 typedef rgba< T > color_type;
2561 enum{ color_num = 1 };
2562
2563 static value_type convert_to( value_type r, value_type g, value_type b, value_type /* a */ = 255 )
2564 {
2565 return( color_type( r, g, b ).get_value( ) );
2566 }
2567
2568 static color_type convert_from( const value_type &pixel )
2569 {
2570 return( color_type( pixel ) );
2571 }
2572 };
2573
2574 #if defined(__MIST_MSVC__) && __MIST_MSVC__ < 7
2575
2576 #define IS_COLOR( type ) \
2577 template < >\
2578 struct is_color< rgb< type > >\
2579 {\
2580 enum{ value = true };\
2581 };\
2582 template < >\
2583 struct is_color< bgr< type > >\
2584 {\
2585 enum{ value = true };\
2586 };\
2587 template < >\
2588 struct is_color< rgba< type > >\
2589 {\
2590 enum{ value = true };\
2591 };\
2592 template < >\
2593 struct is_color< bgra< type > >\
2594 {\
2595 enum{ value = true };\
2596 };\
2597
2598
2599 #define __PIXEL_CONVERTER__( type ) \
2600 template < >\
2601 struct _pixel_converter_< rgb< type > >\
2602 {\
2603 typedef type value_type;\
2604 typedef rgba< type > color_type;\
2605 enum{ color_num = 3 };\
2606 \
2607 static color_type convert_to( value_type r, value_type g, value_type b, value_type a = 255 )\
2608 {\
2609 return( color_type( r, g, b ) );\
2610 }\
2611 \
2612 static color_type convert_from( const color_type &pixel )\
2613 {\
2614 return( pixel );\
2615 }\
2616 };\
2617 template < >\
2618 struct _pixel_converter_< bgr< type > >\
2619 {\
2620 typedef type value_type;\
2621 typedef rgba< type > color_type;\
2622 enum{ color_num = 3 };\
2623 \
2624 static color_type convert_to( value_type r, value_type g, value_type b, value_type a = 255 )\
2625 {\
2626 return( color_type( r, g, b ) );\
2627 }\
2628 \
2629 static color_type convert_from( const color_type &pixel )\
2630 {\
2631 return( pixel );\
2632 }\
2633 };\
2634 template < >\
2635 struct _pixel_converter_< rgba< type > >\
2636 {\
2637 typedef type value_type;\
2638 typedef rgba< type > color_type;\
2639 enum{ color_num = 4 };\
2640 \
2641 static color_type convert_to( value_type r, value_type g, value_type b, value_type a = 255 )\
2642 {\
2643 return( color_type( r, g, b, a ) );\
2644 }\
2645 \
2646 static color_type convert_from( const color_type &pixel )\
2647 {\
2648 return( pixel );\
2649 }\
2650 };\
2651 template < >\
2652 struct _pixel_converter_< bgra< type > >\
2653 {\
2654 typedef type value_type;\
2655 typedef bgra< type > color_type;\
2656 enum{ color_num = 4 };\
2657 \
2658 static color_type convert_to( value_type r, value_type g, value_type b, value_type a = 255 )\
2659 {\
2660 return( color_type( r, g, b, a ) );\
2661 }\
2662 \
2663 static color_type convert_from( const color_type &pixel )\
2664 {\
2665 return( pixel );\
2666 }\
2667 };\
2668
2669 // 各型に対する特殊化
2670 IS_COLOR(unsigned char)
2671 IS_COLOR(unsigned short)
2672 IS_COLOR(unsigned int)
2673 IS_COLOR(unsigned long)
2674 IS_COLOR(signed char)
2675 IS_COLOR(signed short)
2676 IS_COLOR(signed int)
2677 IS_COLOR(signed long)
2678 IS_COLOR(bool)
2679 IS_COLOR(char)
2680 IS_COLOR(float)
2681 IS_COLOR(double)
2682 IS_COLOR(long double)
2683 __PIXEL_CONVERTER__(unsigned char)
2684 __PIXEL_CONVERTER__(unsigned short)
2685 __PIXEL_CONVERTER__(unsigned int)
2686 __PIXEL_CONVERTER__(unsigned long)
2687 __PIXEL_CONVERTER__(signed char)
2688 __PIXEL_CONVERTER__(signed short)
2689 __PIXEL_CONVERTER__(signed int)
2690 __PIXEL_CONVERTER__(signed long)
2691 __PIXEL_CONVERTER__(bool)
2692 __PIXEL_CONVERTER__(char)
2693 __PIXEL_CONVERTER__(float)
2694 __PIXEL_CONVERTER__(double)
2695 __PIXEL_CONVERTER__(long double)
2696
2697 #undef IS_COLOR
2698 #undef __PIXEL_CONVERTER__
2699
2700 #else
2701
2702 template < class T >
2703 struct is_color< rgb< T > >
2704 {
2705 _MIST_CONST( bool, value, true );
2706 };
2707
2708 template < class T >
2709 struct is_color< bgr< T > >
2710 {
2711 _MIST_CONST( bool, value, true );
2712 };
2713
2714 template < class T >
2715 struct is_color< rgba< T > >
2716 {
2717 _MIST_CONST( bool, value, true );
2718 };
2719
2720 template < class T >
2721 struct is_color< bgra< T > >
2722 {
2723 _MIST_CONST( bool, value, true );
2724 };
2725
2726 template < class T >
2727 struct is_color< nRGB< T > >
2728 {
2729 _MIST_CONST( bool, value, true );
2730 };
2731
2732 template < class T, size_t NDIM >
2733 struct is_color< color< T, NDIM > >
2734 {
2735 _MIST_CONST( bool, value, true );
2736 };
2737
2738 template < class T >
2739 struct _pixel_converter_< rgb< T > >
2740 {
2741 typedef T value_type;
2742 typedef rgba< T > color_type;
2743 enum{ color_num = 3 };
2744
2745 static color_type convert_to( value_type r, value_type g, value_type b, value_type a = 255 )
2746 {
2747 return( color_type( r, g, b, a ) );
2748 }
2749
2750 static color_type convert_from( const rgb< T > &pixel )
2751 {
2752 return( pixel );
2753 }
2754 };
2755
2756 template < class T >
2757 struct _pixel_converter_< bgr< T > >
2758 {
2759 typedef T value_type;
2760 typedef rgba< T > color_type;
2761 enum{ color_num = 3 };
2762
2763 static color_type convert_to( value_type r, value_type g, value_type b, value_type a = 255 )
2764 {
2765 return( color_type( r, g, b, a ) );
2766 }
2767
2768 static color_type convert_from( const bgr< T > &pixel )
2769 {
2770 return( color_type( pixel.r, pixel.g, pixel.b ) );
2771 }
2772 };
2773
2774 template < class T >
2775 struct _pixel_converter_< rgba< T > >
2776 {
2777 typedef T value_type;
2778 typedef rgba< T > color_type;
2779 enum{ color_num = 4 };
2780
2781 static color_type convert_to( value_type r, value_type g, value_type b, value_type a = 255 )
2782 {
2783 return( color_type( r, g, b, a ) );
2784 }
2785
2786 static color_type convert_from( const rgba< T > &pixel )
2787 {
2788 return( pixel );
2789 }
2790 };
2791
2792 template < class T >
2793 struct _pixel_converter_< bgra< T > >
2794 {
2795 typedef T value_type;
2796 typedef bgra< T > color_type;
2797 enum{ color_num = 4 };
2798
2799 static color_type convert_to( value_type r, value_type g, value_type b, value_type a = 255 )
2800 {
2801 return( color_type( r, g, b, a ) );
2802 }
2803
2804 static color_type convert_from( const bgra< T > &pixel )
2805 {
2806 return( color_type( pixel.r, pixel.g, pixel.b, pixel.a ) );
2807 }
2808 };
2809
2810 template < class T >
2811 struct _pixel_converter_< nRGB< T > >
2812 {
2813 typedef T value_type;
2814 typedef nRGB< T > color_type;
2815 enum{ color_num = 6 };
2816
2817 static color_type convert_to( value_type r, value_type g, value_type b, value_type /* a */ = 255 )
2818 {
2819 return( color_type( r, g, b ) );
2820 }
2821
2822 static color_type convert_from( const nRGB< T > &pixel )
2823 {
2824 return( color_type( pixel.r, pixel.g, pixel.b ) );
2825 }
2826 };
2827
2828 template < class T, size_t NDIM >
2829 struct _pixel_converter_< color< T, NDIM > >
2830 {
2831 typedef T value_type;
2832 typedef color< T, NDIM > color_type;
2833 enum{ color_num = NDIM };
2834
2835 static color_type convert_to( value_type r, value_type g, value_type b, value_type a = 255 )
2836 {
2837 return( color_type( ( r + g + b ) / 3 ) );
2838 }
2839
2840 static color_type convert_from( const color< T, NDIM > &pixel )
2841 {
2842 if( NDIM < 3 )
2843 {
2844 return( color_type( pixel[ 0 ] ) );
2845 }
2846 else
2847 {
2848 return( color_type( pixel[ 0 ], pixel[ 1 ], pixel[ 2 ] ) );
2849 }
2850 }
2851 };
2852
2853 #endif
2854
2855
2856 #define __DEFINE_COLOR_TYPE_TRAIT__( function, type ) \
2857 template<> struct function< rgb< type > >{ _MIST_CONST( bool, value, true ); }; \
2858 template<> struct function< bgr< type > >{ _MIST_CONST( bool, value, true ); }; \
2859 template<> struct function< rgba< type > >{ _MIST_CONST( bool, value, true ); }; \
2860 template<> struct function< bgra< type > >{ _MIST_CONST( bool, value, true ); }; \
2861 template<> struct function< nRGB< type > >{ _MIST_CONST( bool, value, true ); }; \
2862 template< size_t NDIM > struct function< color< type, NDIM > >{ _MIST_CONST( bool, value, true ); }; \
2863
2864 // type_trait 内の機能を拡張する
2871 __DEFINE_COLOR_TYPE_TRAIT__( is_char, unsigned char )
2872 __DEFINE_COLOR_TYPE_TRAIT__( is_char, signed char )
2873 __DEFINE_COLOR_TYPE_TRAIT__( is_char, char )
2874
2875
2876
2877
2878
2879
2880
2881
2882 __DEFINE_COLOR_TYPE_TRAIT__( is_float, float )
2883 __DEFINE_COLOR_TYPE_TRAIT__( is_float, double )
2884 __DEFINE_COLOR_TYPE_TRAIT__( is_float, long double )
2885
2886
2887
2894 __DEFINE_COLOR_TYPE_TRAIT__( is_integer, unsigned char )
2895 __DEFINE_COLOR_TYPE_TRAIT__( is_integer, unsigned short )
2896 __DEFINE_COLOR_TYPE_TRAIT__( is_integer, unsigned int )
2897 __DEFINE_COLOR_TYPE_TRAIT__( is_integer, unsigned long )
2898 __DEFINE_COLOR_TYPE_TRAIT__( is_integer, signed char )
2899 __DEFINE_COLOR_TYPE_TRAIT__( is_integer, signed short )
2900 __DEFINE_COLOR_TYPE_TRAIT__( is_integer, signed int )
2901 __DEFINE_COLOR_TYPE_TRAIT__( is_integer, signed long )
2902 __DEFINE_COLOR_TYPE_TRAIT__( is_integer, bool )
2903 __DEFINE_COLOR_TYPE_TRAIT__( is_integer, char )
2904
2905 #if defined( __MIST64__ ) && __MIST64__ != 0 && !( defined( __GNUC__ ) || defined( __APPLE__ ) || defined( __ICC ) )
2906 __DEFINE_COLOR_TYPE_TRAIT__( is_integer, size_t )
2907 __DEFINE_COLOR_TYPE_TRAIT__( is_integer, ptrdiff_t )
2908 #endif
2909
2910
2911
2918 __DEFINE_COLOR_TYPE_TRAIT__( is_arithmetic, unsigned char )
2919 __DEFINE_COLOR_TYPE_TRAIT__( is_arithmetic, unsigned short )
2920 __DEFINE_COLOR_TYPE_TRAIT__( is_arithmetic, unsigned int )
2921 __DEFINE_COLOR_TYPE_TRAIT__( is_arithmetic, unsigned long )
2922 __DEFINE_COLOR_TYPE_TRAIT__( is_arithmetic, signed char )
2923 __DEFINE_COLOR_TYPE_TRAIT__( is_arithmetic, signed short )
2924 __DEFINE_COLOR_TYPE_TRAIT__( is_arithmetic, signed int )
2925 __DEFINE_COLOR_TYPE_TRAIT__( is_arithmetic, signed long )
2926 __DEFINE_COLOR_TYPE_TRAIT__( is_arithmetic, bool )
2927 __DEFINE_COLOR_TYPE_TRAIT__( is_arithmetic, char )
2928 __DEFINE_COLOR_TYPE_TRAIT__( is_arithmetic, float )
2929 __DEFINE_COLOR_TYPE_TRAIT__( is_arithmetic, double )
2930 __DEFINE_COLOR_TYPE_TRAIT__( is_arithmetic, long double )
2931
2932 #if defined( __MIST64__ ) && __MIST64__ != 0 && !( defined( __GNUC__ ) || defined( __APPLE__ ) || defined( __ICC ) )
2933 __DEFINE_COLOR_TYPE_TRAIT__( is_arithmetic, size_t )
2934 __DEFINE_COLOR_TYPE_TRAIT__( is_arithmetic, ptrdiff_t )
2935 #endif
2936
2937
2944 template< class T > struct float_type< rgb< T > > { typedef rgb< typename float_type< T >::value_type > value_type; };
2945 template< class T > struct float_type< bgr< T > > { typedef rgb< typename float_type< T >::value_type > value_type; };
2946 template< class T > struct float_type< rgba< T > > { typedef rgb< typename float_type< T >::value_type > value_type; };
2947 template< class T > struct float_type< bgra< T > > { typedef rgb< typename float_type< T >::value_type > value_type; };
2948
2949
2950 #undef __DEFINE_COLOR_TYPE_TRAIT__
2951
2953 template< typename T = rgb< unsigned char > >
2954 struct colors
2955 {
2956 typedef T color_type;
2957
2958 static color_type aliceblue( ) { return color_type( 0xf0, 0xf8, 0xff ); }
2959 static color_type antiquewhite( ) { return color_type( 0xfa, 0xeb, 0xd7 ); }
2960 static color_type aqua( ) { return color_type( 0x00, 0xff, 0xff ); }
2961 static color_type aquamarine( ) { return color_type( 0x7f, 0xff, 0xd4 ); }
2962 static color_type azure( ) { return color_type( 0xf0, 0xff, 0xff ); }
2963 static color_type beige( ) { return color_type( 0xf5, 0xf5, 0xdc ); }
2964 static color_type bisque( ) { return color_type( 0xff, 0xe4, 0xc4 ); }
2965 static color_type black( ) { return color_type( 0x00, 0x00, 0x00 ); }
2966 static color_type blanchedalmond( ) { return color_type( 0xff, 0xeb, 0xcd ); }
2967 static color_type blue( ) { return color_type( 0x00, 0x00, 0xff ); }
2968 static color_type blueviolet( ) { return color_type( 0x8a, 0x2b, 0xe2 ); }
2969 static color_type brown( ) { return color_type( 0xa5, 0x2a, 0x2a ); }
2970 static color_type burlywood( ) { return color_type( 0xde, 0xb8, 0x87 ); }
2971 static color_type cadetblue( ) { return color_type( 0x5f, 0x9e, 0xa0 ); }
2972 static color_type chartreuse( ) { return color_type( 0x7f, 0xff, 0x00 ); }
2973 static color_type chocolate( ) { return color_type( 0xd2, 0x69, 0x1e ); }
2974 static color_type coral( ) { return color_type( 0xff, 0x7f, 0x50 ); }
2975 static color_type cornflowerblue( ) { return color_type( 0x64, 0x95, 0xed ); }
2976 static color_type cornsilk( ) { return color_type( 0xff, 0xf8, 0xdc ); }
2977 static color_type crimson( ) { return color_type( 0xdc, 0x14, 0x3c ); }
2978 static color_type cyan( ) { return color_type( 0x00, 0xff, 0xff ); }
2979 static color_type darkblue( ) { return color_type( 0x00, 0x00, 0x8b ); }
2980 static color_type darkcyan( ) { return color_type( 0x00, 0x8b, 0x8b ); }
2981 static color_type darkgoldenrod( ) { return color_type( 0xb8, 0x86, 0x0b ); }
2982 static color_type darkgray( ) { return color_type( 0xa9, 0xa9, 0xa9 ); }
2983 static color_type darkgreen( ) { return color_type( 0x00, 0x64, 0x00 ); }
2984 static color_type darkkhaki( ) { return color_type( 0xbd, 0xb7, 0x6b ); }
2985 static color_type darkmagenta( ) { return color_type( 0x8b, 0x00, 0x8b ); }
2986 static color_type darkolivegreen( ) { return color_type( 0x55, 0x6b, 0x2f ); }
2987 static color_type darkorange( ) { return color_type( 0xff, 0x8c, 0x00 ); }
2988 static color_type darkorchid( ) { return color_type( 0x99, 0x32, 0xcc ); }
2989 static color_type darkred( ) { return color_type( 0x8b, 0x00, 0x00 ); }
2990 static color_type darksalmon( ) { return color_type( 0xe9, 0x96, 0x7a ); }
2991 static color_type darkseagreen( ) { return color_type( 0x8f, 0xbc, 0x8f ); }
2992 static color_type darkslateblue( ) { return color_type( 0x48, 0x3d, 0x8b ); }
2993 static color_type darkslategray( ) { return color_type( 0x2f, 0x4f, 0x4f ); }
2994 static color_type darkturquoise( ) { return color_type( 0x00, 0xce, 0xd1 ); }
2995 static color_type darkviolet( ) { return color_type( 0x94, 0x00, 0xd3 ); }
2996 static color_type deeppink( ) { return color_type( 0xff, 0x14, 0x93 ); }
2997 static color_type deepskyblue( ) { return color_type( 0x00, 0xbf, 0xff ); }
2998 static color_type dimgray( ) { return color_type( 0x69, 0x69, 0x69 ); }
2999 static color_type dodgerblue( ) { return color_type( 0x1e, 0x90, 0xff ); }
3000 static color_type firebrick( ) { return color_type( 0xb2, 0x22, 0x22 ); }
3001 static color_type floralwhite( ) { return color_type( 0xff, 0xfa, 0xf0 ); }
3002 static color_type forestgreen( ) { return color_type( 0x22, 0x8b, 0x22 ); }
3003 static color_type fuchsia( ) { return color_type( 0xff, 0x00, 0xff ); }
3004 static color_type gainsboro( ) { return color_type( 0xdc, 0xdc, 0xdc ); }
3005 static color_type ghostwhite( ) { return color_type( 0xf8, 0xf8, 0xff ); }
3006 static color_type gold( ) { return color_type( 0xff, 0xd7, 0x00 ); }
3007 static color_type goldenrod( ) { return color_type( 0xda, 0xa5, 0x20 ); }
3008 static color_type gray( ) { return color_type( 0x80, 0x80, 0x80 ); }
3009 static color_type green( ) { return color_type( 0x00, 0xff, 0x00 ); }
3010 static color_type greenyellow( ) { return color_type( 0xad, 0xff, 0x2f ); }
3011 static color_type honeydew( ) { return color_type( 0xf0, 0xff, 0xf0 ); }
3012 static color_type hotpink( ) { return color_type( 0xff, 0x69, 0xb4 ); }
3013 static color_type indianred( ) { return color_type( 0xcd, 0x5c, 0x5c ); }
3014 static color_type indigo( ) { return color_type( 0x4b, 0x00, 0x82 ); }
3015 static color_type ivory( ) { return color_type( 0xff, 0xff, 0xf0 ); }
3016 static color_type khaki( ) { return color_type( 0xf0, 0xe6, 0x8c ); }
3017 static color_type lavender( ) { return color_type( 0xe6, 0xe6, 0xfa ); }
3018 static color_type lavenderblush( ) { return color_type( 0xff, 0xf0, 0xf5 ); }
3019 static color_type lawngreen( ) { return color_type( 0x7c, 0xfc, 0x00 ); }
3020 static color_type lemonchiffon( ) { return color_type( 0xff, 0xfa, 0xcd ); }
3021 static color_type lightblue( ) { return color_type( 0xad, 0xd8, 0xe6 ); }
3022 static color_type lightcoral( ) { return color_type( 0xf0, 0x80, 0x80 ); }
3023 static color_type lightcyan( ) { return color_type( 0xe0, 0xff, 0xff ); }
3024 static color_type lightgoldenrodyellow( ) { return color_type( 0xfa, 0xfa, 0xd2 ); }
3025 static color_type lightgray( ) { return color_type( 0xd3, 0xd3, 0xd3 ); }
3026 static color_type lightgreen( ) { return color_type( 0x90, 0xee, 0x90 ); }
3027 static color_type lightpink( ) { return color_type( 0xff, 0xb6, 0xc1 ); }
3028 static color_type lightsalmon( ) { return color_type( 0xff, 0xa0, 0x7a ); }
3029 static color_type lightseagreen( ) { return color_type( 0x20, 0xb2, 0xaa ); }
3030 static color_type lightskyblue( ) { return color_type( 0x87, 0xce, 0xfa ); }
3031 static color_type lightslategray( ) { return color_type( 0x77, 0x88, 0x99 ); }
3032 static color_type lightsteelblue( ) { return color_type( 0xb0, 0xc4, 0xde ); }
3033 static color_type lightyellow( ) { return color_type( 0xff, 0xff, 0xe0 ); }
3034 static color_type lime( ) { return color_type( 0x00, 0xff, 0x00 ); }
3035 static color_type limegreen( ) { return color_type( 0x32, 0xcd, 0x32 ); }
3036 static color_type linen( ) { return color_type( 0xfa, 0xf0, 0xe6 ); }
3037 static color_type magenta( ) { return color_type( 0xff, 0x00, 0xff ); }
3038 static color_type maroon( ) { return color_type( 0x80, 0x00, 0x00 ); }
3039 static color_type mediumaquamarine( ) { return color_type( 0x66, 0xcd, 0xaa ); }
3040 static color_type mediumblue( ) { return color_type( 0x00, 0x00, 0xcd ); }
3041 static color_type mediumorchid( ) { return color_type( 0xba, 0x55, 0xd3 ); }
3042 static color_type mediumpurple( ) { return color_type( 0x93, 0x70, 0xdb ); }
3043 static color_type mediumseagreen( ) { return color_type( 0x3c, 0xb3, 0x71 ); }
3044 static color_type mediumslateblue( ) { return color_type( 0x7b, 0x68, 0xee ); }
3045 static color_type mediumspringgreen( ) { return color_type( 0x00, 0xfa, 0x9a ); }
3046 static color_type mediumturquoise( ) { return color_type( 0x48, 0xd1, 0xcc ); }
3047 static color_type mediumvioletred( ) { return color_type( 0xc7, 0x15, 0x85 ); }
3048 static color_type midnightblue( ) { return color_type( 0x19, 0x19, 0x70 ); }
3049 static color_type mintcream( ) { return color_type( 0xf5, 0xff, 0xfa ); }
3050 static color_type mistyrose( ) { return color_type( 0xff, 0xe4, 0xe1 ); }
3051 static color_type moccasin( ) { return color_type( 0xff, 0xe4, 0xb5 ); }
3052 static color_type navajowhite( ) { return color_type( 0xff, 0xde, 0xad ); }
3053 static color_type navy( ) { return color_type( 0x00, 0x00, 0x80 ); }
3054 static color_type oldlace( ) { return color_type( 0xfd, 0xf5, 0xe6 ); }
3055 static color_type olive( ) { return color_type( 0x80, 0x80, 0x00 ); }
3056 static color_type olivedrab( ) { return color_type( 0x6b, 0x8e, 0x23 ); }
3057 static color_type orange( ) { return color_type( 0xff, 0xa5, 0x00 ); }
3058 static color_type orangered( ) { return color_type( 0xff, 0x45, 0x00 ); }
3059 static color_type orchid( ) { return color_type( 0xda, 0x70, 0xd6 ); }
3060 static color_type palegoldenrod( ) { return color_type( 0xee, 0xe8, 0xaa ); }
3061 static color_type palegreen( ) { return color_type( 0x98, 0xfb, 0x98 ); }
3062 static color_type paleturquoise( ) { return color_type( 0xaf, 0xee, 0xee ); }
3063 static color_type palevioletred( ) { return color_type( 0xdb, 0x70, 0x93 ); }
3064 static color_type papayawhip( ) { return color_type( 0xff, 0xef, 0xd5 ); }
3065 static color_type peachpuff( ) { return color_type( 0xff, 0xda, 0xb9 ); }
3066 static color_type peru( ) { return color_type( 0xcd, 0x85, 0x3f ); }
3067 static color_type pink( ) { return color_type( 0xff, 0xc0, 0xcb ); }
3068 static color_type plum( ) { return color_type( 0xdd, 0xa0, 0xdd ); }
3069 static color_type powderblue( ) { return color_type( 0xb0, 0xe0, 0xe6 ); }
3070 static color_type purple( ) { return color_type( 0x80, 0x00, 0x80 ); }
3071 static color_type red( ) { return color_type( 0xff, 0x00, 0x00 ); }
3072 static color_type rosybrown( ) { return color_type( 0xbc, 0x8f, 0x8f ); }
3073 static color_type royalblue( ) { return color_type( 0x41, 0x69, 0xe1 ); }
3074 static color_type saddlebrown( ) { return color_type( 0x8b, 0x45, 0x13 ); }
3075 static color_type salmon( ) { return color_type( 0xfa, 0x80, 0x72 ); }
3076 static color_type sandybrown( ) { return color_type( 0xf4, 0xa4, 0x60 ); }
3077 static color_type seagreen( ) { return color_type( 0x2e, 0x8b, 0x57 ); }
3078 static color_type seashell( ) { return color_type( 0xff, 0xf5, 0xee ); }
3079 static color_type sienna( ) { return color_type( 0xa0, 0x52, 0x2d ); }
3080 static color_type silver( ) { return color_type( 0xc0, 0xc0, 0xc0 ); }
3081 static color_type skyblue( ) { return color_type( 0x87, 0xce, 0xeb ); }
3082 static color_type slateblue( ) { return color_type( 0x6a, 0x5a, 0xcd ); }
3083 static color_type slategray( ) { return color_type( 0x70, 0x80, 0x90 ); }
3084 static color_type snow( ) { return color_type( 0xff, 0xfa, 0xfa ); }
3085 static color_type springgreen( ) { return color_type( 0x00, 0xff, 0x7f ); }
3086 static color_type steelblue( ) { return color_type( 0x46, 0x82, 0xb4 ); }
3087 static color_type tan( ) { return color_type( 0xd2, 0xb4, 0x8c ); }
3088 static color_type teal( ) { return color_type( 0x00, 0x80, 0x80 ); }
3089 static color_type thistle( ) { return color_type( 0xd8, 0xbf, 0xd8 ); }
3090 static color_type tomato( ) { return color_type( 0xff, 0x63, 0x47 ); }
3091 static color_type transparent( ) { return color_type( 0x00, 0x00, 0xe0 ); }
3092 static color_type turquoise( ) { return color_type( 0x40, 0xe0, 0xd0 ); }
3093 static color_type violet( ) { return color_type( 0xee, 0x82, 0xee ); }
3094 static color_type wheat( ) { return color_type( 0xf5, 0xde, 0xb3 ); }
3095 static color_type white( ) { return color_type( 0xff, 0xff, 0xff ); }
3096 static color_type whitesmoke( ) { return color_type( 0xf5, 0xf5, 0xf5 ); }
3097 static color_type yellow( ) { return color_type( 0xff, 0xff, 0x00 ); }
3098 static color_type yellowgreen( ) { return color_type( 0x9a, 0xcd, 0x32 ); }
3099 };
3100
3101
3102 // mist名前空間の終わり
3103 _MIST_END
3104
3105
3106 #endif // __INCLUDE_MIST_COLOR_H__
3107