00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00030 #ifndef __CLAW_XBM_HPP__
00031 #define __CLAW_XBM_HPP__
00032
00033 #include <claw/image.hpp>
00034 #include <iostream>
00035 #include <string>
00036
00037 namespace claw
00038 {
00039 namespace graphic
00040 {
00045 class xbm : public image
00046 {
00047 public:
00048
00053 class reader
00054 {
00055 public:
00056 reader( image& img );
00057 reader( image& img, std::istream& f );
00058 reader( xbm& img, std::istream& f );
00059 ~reader();
00060
00061 void load( std::istream& f );
00062
00063 private:
00064 void read_from_file( std::istream& f );
00065
00066 void read_size( std::istream& f );
00067 unsigned int read_dim( const std::string& line ) const;
00068 unsigned int read_bits_per_entry( std::istream& f ) const;
00069 void read_name( std::istream& f );
00070 void read_pixels( std::istream& f, unsigned int bpe ) const;
00071
00072 void read_line
00073 ( std::istream& f, std::string& line, char endchar ) const;
00074 void remove_comments
00075 ( std::istream& f, std::string& line, char endchar ) const;
00076
00077 private:
00079 image& m_image;
00080
00082 std::string m_name;
00083
00085 claw::math::coordinate_2d<int>* m_hot;
00086
00087 };
00088
00089
00094 class writer
00095 {
00096 public:
00100 struct options
00101 {
00102 public:
00103 options();
00104
00105 options( const std::string& n,
00106 const claw::math::coordinate_2d<int>* h );
00107
00108 public:
00110 std::string name;
00111
00113 const claw::math::coordinate_2d<int>* hot;
00114
00115 };
00116
00117 public:
00118 writer( const image& img );
00119 writer( const image& img, std::ostream& f,
00120 const options& opt = options() );
00121
00122 void save( std::ostream& f, const options& opt = options() ) const;
00123
00124 private:
00125 void save_bits( std::ostream& f ) const;
00126
00127 private:
00129 const image& m_image;
00130
00131 };
00132
00133 public:
00134 xbm( unsigned int w, unsigned int h );
00135 xbm( const image& that );
00136 xbm( std::istream& f );
00137 ~xbm();
00138
00139 void save( std::ostream& os ) const;
00140
00141 void set_name( const std::string& name );
00142 void set_hot( const claw::math::coordinate_2d<int>& hot );
00143
00144 private:
00146 std::string m_name;
00147
00149 claw::math::coordinate_2d<int>* m_hot;
00150
00151 };
00152 }
00153 }
00154
00155 #endif // __CLAW_XBM_HPP__