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

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

converter.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 #ifndef __INCLUDE_CONVERTER__
34 #define __INCLUDE_CONVERTER__
35
36
37 #ifndef __INCLUDE_MIST_H__
38 #include "mist.h"
39 #endif
40
41 #ifndef __INCLUDE_MIST_COLOR_H__
42 #include "config/color.h"
43 #endif
44
45 #ifndef __INCLUDE_BITMAP_H__
46 #include "bitmap.h"
47 #endif
48
49
50 // mist名前空間の始まり
51 _MIST_BEGIN
52
53
54 namespace __converter__
55 {
56 template < class T1, class T2, class Allocator1, class Allocator2 >
57 inline void resize( const mist::array< T1, Allocator1 > &in, mist::array< T2, Allocator2 > &out )
58 {
59 out.resize( in.size( ) );
60 }
61
62 template < class T1, class T2, class Allocator1, class Allocator2 >
63 inline void resize( const mist::array1< T1, Allocator1 > &in, mist::array1< T2, Allocator2 > &out )
64 {
65 out.resize( in.size( ) );
66 out.reso1( in.reso1( ) );
67 }
68
69 template < class T1, class T2, class Allocator1, class Allocator2 >
70 inline void resize( const mist::array2< T1, Allocator1 > &in, mist::array2< T2, Allocator2 > &out )
71 {
72 out.resize( in.size1( ), in.size2( ) );
73 out.reso1( in.reso1( ) );
74 out.reso2( in.reso2( ) );
75 }
76
77 template < size_t T1, class T2, class Allocator1, class Allocator2 >
78 inline void resize( const mist::bitmap< T1, Allocator1 > &in, mist::array2< T2, Allocator2 > &out )
79 {
80 out.resize( in.size1( ), in.size2( ) );
81 out.reso1( 1.0 );
82 out.reso2( 1.0 );
83 }
84
85 template < class T1, size_t T2, class Allocator1, class Allocator2 >
86 inline void resize( const mist::array2< T1, Allocator1 > &in, mist::bitmap< T2, Allocator2 > &out )
87 {
88 out.resize( in.size1( ), in.size2( ) );
89 }
90
91 template < size_t T1, size_t T2, class Allocator1, class Allocator2 >
92 inline void resize( const mist::bitmap< T1, Allocator1 > &in, mist::bitmap< T2, Allocator2 > &out )
93 {
94 out.resize( in.size1( ), in.size2( ) );
95 }
96
97 template < class T1, class T2, class Allocator1, class Allocator2 >
98 inline void resize( const mist::array3< T1, Allocator1 > &in, mist::array3< T2, Allocator2 > &out )
99 {
100 out.resize( in.size1( ), in.size2( ), in.size3( ) );
101 out.reso1( in.reso1( ) );
102 out.reso2( in.reso2( ) );
103 out.reso3( in.reso3( ) );
104 }
105
106 template < bool b1, bool b2 >
107 struct _converter_
108 {
109 template < class T1, class T2 >
110 static void convert( const T1 &in, T2 &out )
111 {
112 out = static_cast< T2 >( in );
113 }
114 };
115
116 template < >
117 struct _converter_< true, false >
118 {
119 template < class T1, class T2 >
120 static void convert( const T1 &in, T2 &out )
121 {
122 out = static_cast< T2 >( in.get_value( ) );
123 }
124 };
125
126 template < >
127 struct _converter_< false, true >
128 {
129 template < class T1, class T2 >
130 static void convert( const T1 &in, T2 &out )
131 {
132 out = in;
133 }
134 };
135
136 template < >
137 struct _converter_< true, true >
138 {
139 template < class T1, class T2 >
140 static void convert( const T1 &in, T2 &out )
141 {
142 out = in;
143 }
144 };
145
146 template < class T1, class T2 >
147 inline void converter( const T1 &in, T2 &out )
148 {
149 _converter_< is_color< T1 >::value, is_color< T2 >::value >::convert( in, out );
150 }
151 }
152
153
161
170 template < class Array1, class Array2 >
171 inline void convert( const Array1 &in, Array2 &out )
172 {
173 typedef typename Array1::size_type size_type;
174 typedef typename Array1::value_type value_type;
175 typedef typename Array2::value_type out_value_type;
176 typedef unsigned short hist_value;
177
178 __converter__::resize( in, out );
179
180 for( size_type i = 0 ; i < in.size( ) ; i++ )
181 {
182 __converter__::converter( in[ i ], out[ i ] );
183 }
184 }
185
187 // 画像変換グループの終わり
188
189
190 // mist名前空間の終わり
191 _MIST_END
192
193
194
195 #endif // __INCLUDE_CONVERTER__
196