Claw  1.7.3
xbm.hpp
Go to the documentation of this file.
1 /*
2  CLAW - a C++ Library Absolutely Wonderful
3 
4  CLAW is a free library without any particular aim but being useful to
5  anyone.
6 
7  Copyright (C) 2005-2011 Julien Jorge
8 
9  This library is free software; you can redistribute it and/or
10  modify it under the terms of the GNU Lesser General Public
11  License as published by the Free Software Foundation; either
12  version 2.1 of the License, or (at your option) any later version.
13 
14  This library is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  Lesser General Public License for more details.
18 
19  You should have received a copy of the GNU Lesser General Public
20  License along with this library; if not, write to the Free Software
21  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 
23  contact: julien.jorge@gamned.org
24 */
30 #ifndef __CLAW_XBM_HPP__
31 #define __CLAW_XBM_HPP__
32 
33 #include <claw/image.hpp>
34 #include <iostream>
35 #include <string>
36 
37 namespace claw
38 {
39  namespace graphic
40  {
45  class xbm : public image
46  {
47  public:
48  /*----------------------------------------------------------------------*/
53  class reader
54  {
55  public:
56  reader( image& img );
57  reader( image& img, std::istream& f );
58  reader( xbm& img, std::istream& f );
59  ~reader();
60 
61  void load( std::istream& f );
62 
63  private:
64  void read_from_file( std::istream& f );
65 
66  void read_size( std::istream& f );
67  unsigned int read_dim( const std::string& line ) const;
68  unsigned int read_bits_per_entry( std::istream& f ) const;
69  void read_name( std::istream& f );
70  void read_pixels( std::istream& f, unsigned int bpe ) const;
71 
72  void read_line
73  ( std::istream& f, std::string& line, char endchar ) const;
74  void remove_comments
75  ( std::istream& f, std::string& line, char endchar ) const;
76 
77  private:
79  image& m_image;
80 
82  std::string m_name;
83 
86 
87  }; // class reader
88 
89  /*----------------------------------------------------------------------*/
94  class writer
95  {
96  public:
100  struct options
101  {
102  public:
103  options();
104 
105  options( const std::string& n,
107 
108  public:
110  std::string name;
111 
114 
115  }; // options
116 
117  public:
118  writer( const image& img );
119  writer( const image& img, std::ostream& f,
120  const options& opt = options() );
121 
122  void save( std::ostream& f, const options& opt = options() ) const;
123 
124  private:
125  void save_bits( std::ostream& f ) const;
126 
127  private:
129  const image& m_image;
130 
131  }; // class writer
132 
133  public:
134  xbm( unsigned int w, unsigned int h );
135  xbm( const image& that );
136  xbm( std::istream& f );
137  ~xbm();
138 
139  void save( std::ostream& os ) const;
140 
141  void set_name( const std::string& name );
142  void set_hot( const claw::math::coordinate_2d<int>& hot );
143 
144  private:
146  std::string m_name;
147 
150 
151  }; // class xbm
152  } // namespace graphic
153 } // namespace claw
154 
155 #endif // __CLAW_XBM_HPP__
claw::graphic::xbm::writer
This class write an image in a xbm file.
Definition: xbm.hpp:94
claw::graphic::xbm::reader::~reader
~reader()
Destructor.
Definition: xbm_reader.cpp:81
claw
This is the main namespace.
Definition: algorithm.hpp:33
claw::graphic::xbm::save
void save(std::ostream &os) const
Save the image.
Definition: xbm.cpp:82
claw::math::coordinate_2d< int >
claw::graphic::xbm::writer::options::name
std::string name
The name of the image structure in the file.
Definition: xbm.hpp:110
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::reader::load
void load(std::istream &f)
Load an image from a xbm file.
Definition: xbm_reader.cpp:95
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::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::~xbm
~xbm()
Destructor.
Definition: xbm.cpp:71
claw::graphic::xbm::writer::options
Parameters of the writing algorithm.
Definition: xbm.hpp:100
claw::graphic::xbm::xbm
xbm(unsigned int w, unsigned int h)
Constructor. Creates an empty image.
Definition: xbm.cpp:39
image.hpp
A class to deal with images.
claw::graphic::xbm::set_name
void set_name(const std::string &name)
Set the name of the image.
Definition: xbm.cpp:92
claw::graphic::xbm::reader
This class read data from a xbm file and store it in an image.
Definition: xbm.hpp:53
claw::graphic::image
A class to deal with images.
Definition: image.hpp:49
claw::graphic::xbm
A class for xbm pictures.
Definition: xbm.hpp:45
claw::graphic::xbm::reader::reader
reader(image &img)
Constructor.
Definition: xbm_reader.cpp:41
claw::graphic::xbm::writer::options::options
options()
Default constructor.
Definition: xbm_writer.cpp:37