This class write an image in a xbm file. More...
#include <xbm.hpp>
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 image & | m_image |
| The image from which we take the data to save. | |
This class write an image in a xbm file.
Definition at line 94 of file xbm.hpp.
| claw::graphic::xbm::writer::writer | ( | const image & | img | ) |
Constructor.
| img | The 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.
| img | The image to save. | |
| f | The file in which we write the data. | |
| opt | Saving options. |
Definition at line 78 of file xbm_writer.cpp.
References claw::graphic::xbm::save().
Save the image in a XBM file.
| f | XBM file. | |
| opt | Saving options. |
Definition at line 91 of file xbm_writer.cpp.
References CLAW_PRECOND, claw::graphic::image::height(), claw::graphic::xbm::writer::options::hot, m_image, claw::graphic::xbm::writer::options::name, save_bits(), claw::graphic::image::width(), 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.
| f | XBM file. |
Definition at line 114 of file xbm_writer.cpp.
References claw::graphic::image::height(), m_image, and claw::graphic::image::width().
Referenced by save().
{
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()
const image& claw::graphic::xbm::writer::m_image [private] |
The image from which we take the data to save.
Definition at line 129 of file xbm.hpp.
Referenced by save(), and save_bits().
1.7.1