xbm.hpp
Go to the documentation of this file.
/*
CLAW - a C++ Library Absolutely Wonderful
CLAW is a free library without any particular aim but being useful to
anyone.
Copyright (C) 2005-2011 Julien Jorge
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
contact: julien.jorge@gamned.org
*/
#ifndef __CLAW_XBM_HPP__
#define __CLAW_XBM_HPP__
#include <claw/image.hpp>
#include <iostream>
#include <string>
namespace claw
{
namespace graphic
{
class xbm : public image
{
public:
/*----------------------------------------------------------------------*/
class reader
{
public:
reader( image& img );
reader( image& img, std::istream& f );
reader( xbm& img, std::istream& f );
~reader();
void load( std::istream& f );
private:
void read_from_file( std::istream& f );
void read_size( std::istream& f );
unsigned int read_dim( const std::string& line ) const;
unsigned int read_bits_per_entry( std::istream& f ) const;
void read_name( std::istream& f );
void read_pixels( std::istream& f, unsigned int bpe ) const;
void read_line
( std::istream& f, std::string& line, char endchar ) const;
void remove_comments
( std::istream& f, std::string& line, char endchar ) const;
private:
image& m_image;
std::string m_name;
claw::math::coordinate_2d<int>* m_hot;
}; // class reader
/*----------------------------------------------------------------------*/
class writer
{
public:
struct options
{
public:
options();
options( const std::string& n,
const claw::math::coordinate_2d<int>* h );
public:
std::string name;
const claw::math::coordinate_2d<int>* hot;
}; // options
public:
writer( const image& img );
writer( const image& img, std::ostream& f,
const options& opt = options() );
void save( std::ostream& f, const options& opt = options() ) const;
private:
void save_bits( std::ostream& f ) const;
private:
const image& m_image;
}; // class writer
public:
xbm( unsigned int w, unsigned int h );
xbm( const image& that );
xbm( std::istream& f );
~xbm();
void save( std::ostream& os ) const;
void set_name( const std::string& name );
void set_hot( const claw::math::coordinate_2d<int>& hot );
private:
std::string m_name;
claw::math::coordinate_2d<int>* m_hot;
}; // class xbm
} // namespace graphic
} // namespace claw
#endif // __CLAW_XBM_HPP__
claw::graphic::image::image
image()
Constructor. Creates an image without datas.
Definition image.cpp:106
claw::graphic::xbm::reader::reader
reader(image &img)
Constructor.
Definition xbm_reader.cpp:41
claw::graphic::xbm::reader::load
void load(std::istream &f)
Load an image from a xbm file.
Definition xbm_reader.cpp:95
claw::graphic::xbm::reader::~reader
~reader()
Destructor.
Definition xbm_reader.cpp:81
claw::graphic::xbm::writer::save
void save(std::ostream &f, const options &opt=options()) const
Save the image in a XBM file.
Definition xbm_writer.cpp:91
claw::graphic::xbm::writer::writer
writer(const image &img)
Constructor.
Definition xbm_writer.cpp:64
claw::graphic::xbm::save
void save(std::ostream &os) const
Save the image.
Definition xbm.cpp:82
claw::graphic::xbm::xbm
xbm(unsigned int w, unsigned int h)
Constructor. Creates an empty image.
Definition xbm.cpp:39
claw::graphic::xbm::~xbm
~xbm()
Destructor.
Definition xbm.cpp:71
claw::graphic::xbm::set_hot
void set_hot(const claw::math::coordinate_2d< int > &hot)
Set the hot spot of the image.
Definition xbm.cpp:102
claw::graphic::xbm::set_name
void set_name(const std::string &name)
Set the name of the image.
Definition xbm.cpp:92
claw::math::coordinate_2d
Coordinates in a two dimensional space.
Definition coordinate_2d.hpp:43
image.hpp
A class to deal with images.
claw::graphic
Everything about image structures and processing.
Definition bitmap.hpp:43
claw
This is the main namespace.
Definition algorithm.hpp:34
claw::graphic::xbm::writer::options
Parameters of the writing algorithm.
Definition xbm.hpp:101
claw::graphic::xbm::writer::options::options
options()
Default constructor.
Definition xbm_writer.cpp:37
claw::graphic::xbm::writer::options::hot
const claw::math::coordinate_2d< int > * hot
The position of the hot spot in the image.
Definition xbm.hpp:113
claw::graphic::xbm::writer::options::name
std::string name
The name of the image structure in the file.
Definition xbm.hpp:110