34 #ifndef __INCLUDE_BITMAP_H__
35 #define __INCLUDE_BITMAP_H__
38 #ifndef __INCLUDE_MIST_CONF_H__
42 #ifndef __INCLUDE_MIST_H__
46 #ifndef __INCLUDE_MIST_COLOR_H__
55 template <
size_t BITS >
58 typedef bgr< unsigned char > value_type;
62 struct bitmap_type< 8 >
64 typedef unsigned char value_type;
79 template <
size_t BITS,
class Allocator = std::allocator<
unsigned char > >
107 width = width * pixel_bytes( );
110 width += 4 - ( width % 4 );
131 nbytes_ = num_bytes( num1 );
132 if( base::resize( nbytes_ * num2 ) )
140 size1_ = size2_ = nbytes_ = 0;
159 if( w_ <= static_cast< difference_type >( x ) || w_ < static_cast< difference_type >( x + w ) )
163 else if( h_ <= static_cast< difference_type >( y ) || h_ < static_cast< difference_type >( y + h ) )
167 else if( w_ == w && h_ == h )
182 if( base::is_memory_shared( ) )
192 operator ()( i, j ) = o( i + x, j + y );
208 o( i, j ) = operator ()( i + x, j + y );
230 if( base::swap( a ) )
276 template <
size_t BBITS,
class AAlocator >
281 for(
size_type j = 0 ; j < size2_ ; j++ )
283 for(
size_type i = 0 ; i < size1_ ; i++ )
285 operator ()( i, j ) = o( i, j );
304 template <
class TT,
class AAlocator >
309 for(
size_type j = 0 ; j < size2_ ; j++ )
311 for(
size_type i = 0 ; i < size1_ ; i++ )
313 operator ()( i, j ) = o( i, j );
333 if(
this == &o )
return( *
this );
335 base::operator =( o );
353 return( reinterpret_cast< pointer >( base::data_ + i * pixel_bytes( ) + j * nbytes_ ) );
365 return( reinterpret_cast< const_pointer >( base::data_ + i * pixel_bytes( ) + j * nbytes_ ) );
379 _CHECK_ACCESS_VIOLATION1U_( index )
382 return( reinterpret_cast< reference >( base::data_[ i * pixel_bytes( ) + j * nbytes_ ] ) );
396 _CHECK_ACCESS_VIOLATION1U_( index )
399 return( reinterpret_cast< reference >( base::data_[ i * pixel_bytes( ) + j * nbytes_ ] ) );
415 _CHECK_ACCESS_VIOLATION2U_( i, j )
416 return( reinterpret_cast< reference >( base::data_[ i * pixel_bytes( ) + j * nbytes_ ] ) );
432 _CHECK_ACCESS_VIOLATION2U_( i, j )
433 return( reinterpret_cast< reference >( base::data_[ i * pixel_bytes( ) + j * nbytes_ ] ) );
449 _CHECK_ACCESS_VIOLATION2U_( i, j )
450 return( reinterpret_cast< reference >( base::data_[ i * pixel_bytes( ) + j * nbytes_ ] ) );
466 _CHECK_ACCESS_VIOLATION2U_( i, j )
467 return( reinterpret_cast< reference >( base::data_[ i * pixel_bytes( ) + j * nbytes_ ] ) );
473 bitmap( ) :
base( ), size1_( 0 ), size2_( 0 ), nbytes_( 0 ) {}
476 explicit bitmap(
const Allocator &a ) :
base( a ), size1_( 0 ), size2_( 0 ), nbytes_( 0 ) {}
481 if( base::empty( ) ) size1_ = size2_ = nbytes_ = 0;
485 bitmap(
size_type num1,
size_type num2,
const Allocator &a ) :
base( num_bytes( num1 ) * num2, a ), size1_( num1 ), size2_( num2 ), nbytes_( num_bytes( num1 ) )
487 if( base::empty( ) ) size1_ = size2_ = nbytes_ = 0;
494 if( base::empty( ) ) size1_ = size2_ = nbytes_ = 0;
500 if( base::empty( ) ) size1_ = size2_ = nbytes_ = 0;
505 bitmap(
size_type num1,
size_type num2,
void *ptr,
size_type mem_available ) :
base( num_bytes( num1 ) * num2, reinterpret_cast< unsigned char * >( ptr ), mem_available ), size1_( num1 ), size2_( num2 ), nbytes_( num_bytes( num1 ) )
507 if( base::empty( ) ) size1_ = size2_ = nbytes_ = 0;
511 bitmap(
size_type num1,
size_type num2,
const value_type &val,
void *ptr,
size_type mem_available ) :
base( num_bytes( num1 ) * num2, reinterpret_cast< unsigned char * >( ptr ), mem_available ), size1_( num1 ), size2_( num2 ), nbytes_( num_bytes( num1 ) )
515 size1_ = size2_ = nbytes_ = 0;
519 for(
size_type j = 0 ; j < size2_ ; j++ )
521 for(
size_type i = 0 ; i < size1_ ; i++ )
523 operator ()( i, j ) = val;
534 template <
size_t BBITS,
class AAlocator >
539 for(
size_type j = 0 ; j < size2( ) ; j++ )
541 for(
size_type i = 0 ; i < size1( ) ; i++ )
543 operator ()( i, j ) = o( i, j );
554 template <
class TT,
class AAlocator >
559 for(
size_type j = 0 ; j < size2( ) ; j++ )
561 for(
size_type i = 0 ; i < size1( ) ; i++ )
563 operator ()( i, j ) = o( i, j );
588 template <
size_t BITS,
class Allocator >
589 inline std::ostream &operator <<( std::ostream &out, const bitmap< BITS, Allocator > &a )
592 for( j = 0 ; j < a.
size2( ) ; j++ )
598 for( i = 0 ; i < a.
size1( ) ; i++ )
601 if( i != a.
size1( ) - 1 ) out <<
", ";
614 #endif // __INCLUDE_MIST_H__