CLAW Library (a C++ Library Absolutely Wonderful) 1.5.5
Public Member Functions | Private Attributes
claw::graphic::bitmap::reader::rle_bitmap_output_buffer< Coded4bits > Class Template Reference

The output buffer for the RLE decoder. More...

List of all members.

Public Member Functions

 rle_bitmap_output_buffer (const color_palette_type &palette, image &image)
 Constructor.
void fill (unsigned int n, unsigned char pattern)
void copy (unsigned int n, file_input_buffer &buffer)
void next_line ()
 Go to the begining of the next line to fill.
void delta_move (unsigned char x, unsigned char y)
 Move the cursor horizontally and vertically.
template<>
void fill (unsigned int n, unsigned char pattern)
template<>
void fill (unsigned int n, unsigned char pattern)
template<>
void copy (unsigned int n, file_input_buffer &buffer)
template<>
void copy (unsigned int n, file_input_buffer &buffer)

Private Attributes

const color_palette_typem_palette
 Color palette.
imagem_image
 The image to fill.
unsigned int m_x
 Current column index in the bitmap.
unsigned int m_y
 Current row index in the bitmap.

Detailed Description

template<bool Coded4bits>
class claw::graphic::bitmap::reader::rle_bitmap_output_buffer< Coded4bits >

The output buffer for the RLE decoder.

Template parameters

Author:
Julien Jorge

Definition at line 152 of file bitmap.hpp.


Constructor & Destructor Documentation

template<bool Coded4Bits>
claw::graphic::bitmap::reader::rle_bitmap_output_buffer< Coded4Bits >::rle_bitmap_output_buffer ( const color_palette_type palette,
image img 
)

Constructor.

Parameters:
paletteThe color palette to convert the pixels.
imgThe image we're filling.

Definition at line 43 of file bitmap_reader.tpp.

  : m_palette(palette), m_image(img), m_x(0), m_y(m_image.height() - 1)
{

} // bitmap::reader::rle_bitmap_output_buffer::rle_bitmap_output_buffer()

Member Function Documentation

template<bool Coded4bits>
void claw::graphic::bitmap::reader::rle_bitmap_output_buffer< Coded4bits >::copy ( unsigned int  n,
file_input_buffer buffer 
)
template<>
void claw::graphic::bitmap::reader::rle_bitmap_output_buffer< true >::copy ( unsigned int  n,
file_input_buffer buffer 
)
Parameters:
nThe number of pixels to copy.
bufferThe input buffer, to copy from.
Remarks:
This method is for 4bpp bitmaps.

Definition at line 139 of file bitmap_reader.cpp.

References claw::buffered_istream< Stream >::get_buffer(), claw::buffered_istream< Stream >::move(), claw::buffered_istream< Stream >::read_more(), and claw::buffered_istream< Stream >::remaining().

    {
      assert( m_x + n <= m_image.width() );

      // RLE bitmap data is 2-bytes aligned
      unsigned int bytes_needed = n / 2 + n % 2;

      if ( bytes_needed % 2 )
        ++bytes_needed;

      if ( buffer.remaining() < bytes_needed )
        buffer.read_more( bytes_needed );

      assert( buffer.remaining() >= bytes_needed );

      const unsigned char* p =
        reinterpret_cast<const unsigned char*>(buffer.get_buffer());
      const unsigned char* last = p + n / 2;

      for ( ; p != last; ++p, m_x += 2)
        {
          m_image[m_y][m_x] = m_palette[ (*p & 0xF0) >> 4 ];
          m_image[m_y][m_x+1] = m_palette[ *p & 0x0F ];
        }

      if ( n % 2 )
        {
          m_image[m_y][m_x] = m_palette[ (*p & 0xF0) >> 4 ];
          ++m_x;
        }

      buffer.move( bytes_needed );
    } // bitmap::reader::rle_bitmap_output_buffer<true>::copy()
template<>
void claw::graphic::bitmap::reader::rle_bitmap_output_buffer< false >::copy ( unsigned int  n,
file_input_buffer buffer 
)
Parameters:
nThe number of pixels to copy.
bufferThe input buffer, to copy from.
Remarks:
This method is for 8bpp bitmaps.

Definition at line 102 of file bitmap_reader.cpp.

References claw::buffered_istream< Stream >::get_buffer(), claw::buffered_istream< Stream >::move(), claw::buffered_istream< Stream >::read_more(), and claw::buffered_istream< Stream >::remaining().

    {
      assert( m_x + n <= m_image.width() );
      
      // RLE bitmap data is 2-bytes aligned
      const unsigned int bytes_needed = n + n % 2;
      
      if ( buffer.remaining() < bytes_needed )
        buffer.read_more(bytes_needed);
      
      assert( buffer.remaining() >= bytes_needed );
      
      const unsigned char* p =
        reinterpret_cast<const unsigned char*>(buffer.get_buffer());
      
      std::transform( p, p + n, &m_image[m_y][m_x], m_palette );
      
      m_x += n;

      buffer.move(bytes_needed);
    } // bitmap::reader::rle_bitmap_output_buffer<false>::copy()
template<bool Coded4Bits>
void claw::graphic::bitmap::reader::rle_bitmap_output_buffer< Coded4Bits >::delta_move ( unsigned char  x,
unsigned char  y 
)

Move the cursor horizontally and vertically.

Parameters:
xHorizontal displacement.
yVertical displacement.

Definition at line 72 of file bitmap_reader.tpp.

{
  assert( m_x + x < m_image.width() );
  assert( m_y + y < m_image.height() );

  m_x += x;
  m_y += y;
} // bitmap::reader::rle_bitmap_output_buffer::delta_move()
template<>
void claw::graphic::bitmap::reader::rle_bitmap_output_buffer< false >::fill ( unsigned int  n,
unsigned char  pattern 
)
Parameters:
nNumber of copies.
patternThe index of the color to copy.
Remarks:
This method is for 8bpp bitmaps.

Definition at line 46 of file bitmap_reader.cpp.

    {
      assert( m_x + n <= m_image.width() );
      
      std::fill(&m_image[m_y][m_x], &m_image[m_y][m_x] + n, m_palette[pattern]);
      
      m_x += n;
    } // bitmap::reader::rle_bitmap_output_buffer<false>::fill()
template<bool Coded4bits>
void claw::graphic::bitmap::reader::rle_bitmap_output_buffer< Coded4bits >::fill ( unsigned int  n,
unsigned char  pattern 
)
template<>
void claw::graphic::bitmap::reader::rle_bitmap_output_buffer< true >::fill ( unsigned int  n,
unsigned char  pattern 
)
Parameters:
nNumber of pixels to fill.
patternThe index of the two colors to copy.
Remarks:
This method is for 4bpp bitmaps.

Definition at line 70 of file bitmap_reader.cpp.

    {
      assert( m_x + n <= m_image.width() );
      
      for (unsigned int i = 0; i != n / 2; ++i, m_x += 2)
        {
          m_image[m_y][m_x] = m_palette[ (pattern & 0xF0) >> 4 ];
          m_image[m_y][m_x+1] = m_palette[ pattern & 0x0F ];
        }
      
      if ( n % 2 )
        {
          m_image[m_y][m_x] = m_palette[ (pattern & 0xF0) >> 4 ];
          ++m_x;
        }
    } // bitmap::reader::rle_bitmap_output_buffer<false>::fill()
template<bool Coded4Bits>
void claw::graphic::bitmap::reader::rle_bitmap_output_buffer< Coded4Bits >::next_line ( )

Go to the begining of the next line to fill.

Definition at line 55 of file bitmap_reader.tpp.

{
  assert( m_y > 0 );

  m_x = 0;
  --m_y;
} // bitmap::reader::rle_bitmap_output_buffer::next_line()

Member Data Documentation

template<bool Coded4bits>
image& claw::graphic::bitmap::reader::rle_bitmap_output_buffer< Coded4bits >::m_image [private]

The image to fill.

Definition at line 169 of file bitmap.hpp.

template<bool Coded4bits>
const color_palette_type& claw::graphic::bitmap::reader::rle_bitmap_output_buffer< Coded4bits >::m_palette [private]

Color palette.

Definition at line 166 of file bitmap.hpp.

template<bool Coded4bits>
unsigned int claw::graphic::bitmap::reader::rle_bitmap_output_buffer< Coded4bits >::m_x [private]

Current column index in the bitmap.

Definition at line 172 of file bitmap.hpp.

template<bool Coded4bits>
unsigned int claw::graphic::bitmap::reader::rle_bitmap_output_buffer< Coded4bits >::m_y [private]

Current row index in the bitmap.

Definition at line 175 of file bitmap.hpp.


The documentation for this class was generated from the following files: