34 #ifndef __INCLUDE_MIST_INTERLACE__
35 #define __INCLUDE_MIST_INTERLACE__
38 #ifndef __INCLUDE_MIST_H__
43 #ifndef __INCLUDE_MIST_COLOR_H__
44 #include "../config/color.h"
53 namespace __interlace_controller__
56 struct interlace_controller
58 template <
class T,
class Allocator >
59 static bool interlace_odd_row(
const array2< T, Allocator > &in, array2< T, Allocator > &out )
61 typedef typename array2< T, Allocator >::size_type size_type;
62 typedef typename array2< T, Allocator >::value_type value_type;
64 if( in.height( ) < 2 )
75 for( i = 0 ; i < in.width( ) ; i++ )
77 out( i, 0 ) = in( i, 1 );
80 for( j = 2 ; j < in.height( ) - 1 ; j += 2 )
82 for( i = 0 ; i < in.width( ) ; i++ )
84 out( i, j ) =
static_cast< value_type
>( ( in( i, j - 1 ) + in( i, j + 1 ) ) / 2.0 );
88 if( j == in.height( ) - 1 )
90 for( i = 0 ; i < in.width( ) ; i++ )
92 out( i, j ) = in( i, j - 1 );
98 template <
class T,
class Allocator >
99 static bool interlace_odd_col(
const array2< T, Allocator > &in, array2< T, Allocator > &out )
101 typedef typename array2< T, Allocator >::size_type size_type;
102 typedef typename array2< T, Allocator >::value_type value_type;
104 if( in.width( ) < 2 )
115 for( i = 0 ; i < in.height( ) ; i++ )
117 out( 0, i ) = in( 1, i );
120 for( j = 0 ; j < in.height( ) ; j++ )
122 for( i = 2 ; i < in.width( ) - 1 ; i += 2 )
124 out( i, j ) =
static_cast< value_type
>( ( in( i - 1, j ) + in( i + 1, j ) ) / 2.0 );
128 if( i == in.width( ) - 1 )
130 out( i, j ) = in( i - 1, j );
136 template <
class T,
class Allocator >
137 static bool interlace_even_row(
const array2< T, Allocator > &in, array2< T, Allocator > &out )
139 typedef typename array2< T, Allocator >::size_type size_type;
140 typedef typename array2< T, Allocator >::value_type value_type;
142 if( in.height( ) < 2 )
153 for( j = 1 ; j < in.height( ) - 1 ; j += 2 )
155 for( i = 0 ; i < in.width( ) ; i++ )
157 out( i, j ) =
static_cast< value_type
>( ( in( i, j - 1 ) + in( i, j + 1 ) ) / 2.0 );
161 if( j == in.height( ) - 1 )
163 for( i = 0 ; i < in.width( ) ; i++ )
165 out( i, j ) = in( i, j - 1 );
171 template <
class T,
class Allocator >
172 static bool interlace_even_col(
const array2< T, Allocator > &in, array2< T, Allocator > &out )
174 typedef typename array2< T, Allocator >::size_type size_type;
175 typedef typename array2< T, Allocator >::value_type value_type;
177 if( in.width( ) < 2 )
188 for( j = 0 ; j < in.height( ) ; j++ )
190 for( i = 1 ; i < in.width( ) - 1 ; i += 2 )
192 out( i, j ) =
static_cast< value_type
>( ( in( i - 1, j ) + in( i + 1, j ) ) / 2.0 );
196 if( i == in.width( ) - 1 )
198 out( i, j ) = in( i - 1, j );
206 struct interlace_controller< true >
208 template <
class T,
class Allocator >
209 static bool interlace_odd_row(
const array2< T, Allocator > &in, array2< T, Allocator > &out )
211 typedef typename array2< T, Allocator >::size_type size_type;
212 typedef typename array2< T, Allocator >::value_type color_type;
213 typedef typename color_type::value_type value_type;
215 if( in.height( ) < 2 )
227 for( i = 0 ; i < in.width( ) ; i++ )
229 out( i, 0 ) = in( i, 1 );
232 for( j = 2 ; j < in.height( ) - 1 ; j += 2 )
234 for( i = 0 ; i < in.width( ) ; i++ )
236 r = ( in( i, j - 1 ).r + in( i, j + 1 ).r ) / 2.0;
237 g = ( in( i, j - 1 ).g + in( i, j + 1 ).g ) / 2.0;
238 b = ( in( i, j - 1 ).b + in( i, j + 1 ).b ) / 2.0;
239 out( i, j ) = color_type( static_cast< value_type >( r ), static_cast< value_type >( g ), static_cast< value_type >( b ) );
243 if( j == in.height( ) - 1 )
245 for( i = 0 ; i < in.width( ) ; i++ )
247 out( i, j ) = in( i, j - 1 );
253 template <
class T,
class Allocator >
254 static bool interlace_odd_col(
const array2< T, Allocator > &in, array2< T, Allocator > &out )
256 typedef typename array2< T, Allocator >::size_type size_type;
257 typedef typename array2< T, Allocator >::value_type color_type;
258 typedef typename color_type::value_type value_type;
260 if( in.width( ) < 2 )
272 for( i = 0 ; i < in.height( ) ; i++ )
274 out( 0, i ) = in( 1, i );
277 for( j = 0 ; j < in.height( ) ; j++ )
279 for( i = 2 ; i < in.width( ) - 1 ; i += 2 )
281 r = ( in( i - 1, j ).r + in( i + 1, j ).r ) / 2.0;
282 g = ( in( i - 1, j ).g + in( i + 1, j ).g ) / 2.0;
283 b = ( in( i - 1, j ).b + in( i + 1, j ).b ) / 2.0;
284 out( i, j ) = color_type( static_cast< value_type >( r ), static_cast< value_type >( g ), static_cast< value_type >( b ) );
288 if( i == in.width( ) - 1 )
290 out( i, j ) = in( i - 1, j );
296 template <
class T,
class Allocator >
297 static bool interlace_even_row(
const array2< T, Allocator > &in, array2< T, Allocator > &out )
299 typedef typename array2< T, Allocator >::size_type size_type;
300 typedef typename array2< T, Allocator >::value_type color_type;
301 typedef typename color_type::value_type value_type;
303 if( in.height( ) < 2 )
314 for( j = 1 ; j < in.height( ) - 1 ; j += 2 )
316 for( i = 0 ; i < in.width( ) ; i++ )
318 r = ( in( i, j - 1 ).r + in( i, j + 1 ).r ) / 2.0;
319 g = ( in( i, j - 1 ).g + in( i, j + 1 ).g ) / 2.0;
320 b = ( in( i, j - 1 ).b + in( i, j + 1 ).b ) / 2.0;
321 out( i, j ) = color_type( static_cast< value_type >( r ), static_cast< value_type >( g ), static_cast< value_type >( b ) );
324 if( j == in.height( ) - 1 )
326 for( i = 0 ; i < in.width( ) ; i++ )
328 out( i, j ) = in( i, j - 1 );
334 template <
class T,
class Allocator >
335 static bool interlace_even_col(
const array2< T, Allocator > &in, array2< T, Allocator > &out )
337 typedef typename array2< T, Allocator >::size_type size_type;
338 typedef typename array2< T, Allocator >::value_type color_type;
339 typedef typename color_type::value_type value_type;
341 if( in.width( ) < 2 )
353 for( j = 0 ; j < in.height( ) ; j++ )
355 for( i = 1 ; i < in.width( ) - 1 ; i += 2 )
357 r = ( in( i - 1, j ).r + in( i + 1, j ).r ) / 2.0;
358 g = ( in( i - 1, j ).g + in( i + 1, j ).g ) / 2.0;
359 b = ( in( i - 1, j ).b + in( i + 1, j ).b ) / 2.0;
360 out( i, j ) = color_type( static_cast< value_type >( r ), static_cast< value_type >( g ), static_cast< value_type >( b ) );
364 if( i == in.width( ) - 1 )
366 out( i, j ) = in( i - 1, j );
396 template <
class T,
class Allocator >
401 if( is_row_interlace )
403 return( __interlace_controller__::interlace_controller<
is_color< T >::value >::interlace_odd_row( in, out ) );
407 return( __interlace_controller__::interlace_controller<
is_color< T >::value >::interlace_odd_col( in, out ) );
412 if( is_row_interlace )
414 return( __interlace_controller__::interlace_controller<
is_color< T >::value >::interlace_even_row( in, out ) );
418 return( __interlace_controller__::interlace_controller<
is_color< T >::value >::interlace_even_col( in, out ) );
432 #endif // __INCLUDE_MIST_INTERLACE__