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:
img The image in which the data will be stored.

Definition at line 64 of file xbm_writer.cpp.

00065   : m_image( img )
00066 {
00067 
00068 } // xbm::writer::writer()

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

Constructor.

Parameters:
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().

00079   : m_image( img )
00080 {
00081   save(f, opt);
00082 } // 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:
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.

00092 {
00093   CLAW_PRECOND( !!f );
00094 
00095   f << "#define " << opt.name << "_width " << m_image.width() << "\n";
00096   f << "#define " << opt.name << "_height " << m_image.height() << "\n";
00097 
00098   if ( opt.hot != NULL )
00099     {
00100       f << "#define " << opt.name << "_x_hot " << opt.hot->x << "\n";
00101       f << "#define " << opt.name << "_y_hot " << opt.hot->y << "\n";
00102     }
00103 
00104   f << "static unsigned char " << opt.name << "_bits[] = {\n ";
00105 
00106   save_bits(f);
00107 } // 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:
f XBM file.

Definition at line 114 of file xbm_writer.cpp.

References std::endl(), claw::graphic::image::height(), m_image, and claw::graphic::image::width().

Referenced by save().

00115 {
00116   const unsigned int max_per_line = (80 - 1) / 6;
00117   const unsigned int nb_pxl = m_image.width() * m_image.height();
00118 
00119   unsigned int pxl_count = 0;
00120   unsigned int per_line = 0;
00121 
00122   for (unsigned int y=0; y!=m_image.height(); ++y)
00123     {
00124       unsigned int x=0;
00125 
00126       while ( x!=m_image.width() )
00127         {
00128           unsigned int v(0);
00129           unsigned int bits;
00130 
00131           for ( bits=0; (x!=m_image.width()) && (bits != 8);
00132                 ++bits, ++x, ++pxl_count )
00133             {
00134               v >>= 1;
00135               if ( m_image[y][x].luminosity() <= 127 )
00136                 v |= 0x80;
00137             }
00138 
00139           v >>= 8 - bits;
00140 
00141           ++per_line;
00142 
00143           f << " 0x" << std::setw(2) << std::setfill('0') << std::hex << v;
00144 
00145           if ( pxl_count != nb_pxl )
00146             {
00147               f  << ",";
00148 
00149               if ( per_line == max_per_line )
00150                 {
00151                   f << "\n ";
00152                   per_line = 0;
00153                 }
00154             }
00155         }
00156     }
00157 
00158   f << "};" << std::endl;
00159 } // xbm::writer::save()


Member Data Documentation

The image from which we take the data to save.

Definition at line 129 of file xbm.hpp.

Referenced by save(), and save_bits().


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

Generated on 9 Nov 2009 for CLAW Library (a C++ Library Absolutely Wonderful) by  doxygen 1.6.1