Classes | Public Member Functions | Private Member Functions | Private Attributes

claw::graphic::xbm::writer Class Reference

This class write an image in a xbm file. More...

#include <xbm.hpp>

List of all members.

Classes

struct  options
 Parameters of the writing algorithm. More...

Public Member Functions

 writer (const image &img)
 Constructor.
 writer (const image &img, std::ostream &f, const options &opt=options())
 Constructor.
void save (std::ostream &f, const options &opt=options()) const
 Save the image in a XBM file.

Private Member Functions

void save_bits (std::ostream &f) const
 Save the pixels of the image in a XBM file.

Private Attributes

const imagem_image
 The image from which we take the data to save.

Detailed Description

This class write an image in a xbm file.

Author:
Julien Jorge

Definition at line 94 of file xbm.hpp.


Constructor & Destructor Documentation

claw::graphic::xbm::writer::writer ( const image img )

Constructor.

Parameters:
imgThe image in which the data will be stored.

Definition at line 64 of file xbm_writer.cpp.

  : m_image( img )
{

} // xbm::writer::writer()
claw::graphic::xbm::writer::writer ( const image img,
std::ostream &  f,
const options opt = options() 
)

Constructor.

Parameters:
imgThe image to save.
fThe file in which we write the data.
optSaving options.

Definition at line 78 of file xbm_writer.cpp.

References claw::graphic::xbm::save().

  : m_image( img )
{
  save(f, opt);
} // xbm::writer::writer()

Member Function Documentation

void claw::graphic::xbm::writer::save ( std::ostream &  f,
const options opt = options() 
) const

Save the image in a XBM file.

Parameters:
fXBM file.
optSaving options.

Definition at line 91 of file xbm_writer.cpp.

References CLAW_PRECOND, claw::graphic::xbm::writer::options::hot, claw::graphic::xbm::writer::options::name, claw::math::coordinate_2d< T >::x, and claw::math::coordinate_2d< T >::y.

{
  CLAW_PRECOND( !!f );

  f << "#define " << opt.name << "_width " << m_image.width() << "\n";
  f << "#define " << opt.name << "_height " << m_image.height() << "\n";

  if ( opt.hot != NULL )
    {
      f << "#define " << opt.name << "_x_hot " << opt.hot->x << "\n";
      f << "#define " << opt.name << "_y_hot " << opt.hot->y << "\n";
    }

  f << "static unsigned char " << opt.name << "_bits[] = {\n ";

  save_bits(f);
} // xbm::writer::save()
void claw::graphic::xbm::writer::save_bits ( std::ostream &  f ) const [private]

Save the pixels of the image in a XBM file.

Parameters:
fXBM file.

Definition at line 114 of file xbm_writer.cpp.

References std::endl().

{
  const unsigned int max_per_line = (80 - 1) / 6;
  const unsigned int nb_pxl = m_image.width() * m_image.height();

  unsigned int pxl_count = 0;
  unsigned int per_line = 0;

  for (unsigned int y=0; y!=m_image.height(); ++y)
    {
      unsigned int x=0;

      while ( x!=m_image.width() )
        {
          unsigned int v(0);
          unsigned int bits;

          for ( bits=0; (x!=m_image.width()) && (bits != 8);
                ++bits, ++x, ++pxl_count )
            {
              v >>= 1;
              if ( m_image[y][x].luminosity() <= 127 )
                v |= 0x80;
            }

          v >>= 8 - bits;

          ++per_line;

          f << " 0x" << std::setw(2) << std::setfill('0') << std::hex << v;

          if ( pxl_count != nb_pxl )
            {
              f  << ",";

              if ( per_line == max_per_line )
                {
                  f << "\n ";
                  per_line = 0;
                }
            }
        }
    }

  f << "};" << std::endl;
} // xbm::writer::save()

Member Data Documentation

The image from which we take the data to save.

Definition at line 129 of file xbm.hpp.


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