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__