42 : m_image( img ), m_hot(NULL)
55 : m_image( img ), m_hot(NULL)
68 : m_image( img ), m_hot(NULL)
99 std::istream::pos_type init_pos = f.tellg();
117 f.seekg( init_pos, std::ios_base::beg );
127void claw::graphic::xbm::reader::read_from_file( std::istream& f )
130 bool valid_format =
false;
134 bpe = read_bits_per_entry(f);
136 read_line( f, line,
'{' );
141 read_line(f, line,
';');
155void claw::graphic::xbm::reader::read_size( std::istream& f )
157 unsigned int w(0), h(0);
162 while ( valid && !stop )
164 std::ios::pos_type pos = f.tellg();
166 read_line( f, line,
'\n' );
170 if ( line.find(
"width") != std::string::npos )
172 else if ( line.find(
"height") != std::string::npos )
174 else if ( line.find(
"x_hot") != std::string::npos )
179 m_hot->
x = read_dim(line);
181 else if ( line.find(
"y_hot") != std::string::npos )
186 m_hot->
y = read_dim(line);
188 else if ( line.find(
"static") != std::string::npos )
199 m_image.set_size(w, h);
210claw::graphic::xbm::reader::read_dim(
const std::string& line )
const
213 std::istringstream iss(line);
218 if ( token ==
"#define" )
235claw::graphic::xbm::reader::read_bits_per_entry( std::istream& f )
const
238 unsigned int result(0);
243 if ( token ==
"static" )
246 if ( token ==
"unsigned" )
248 else if ( token ==
"signed" )
251 if ( token ==
"char" )
252 result =
sizeof(char) * 8;
253 else if ( token ==
"short" )
254 result =
sizeof(short) * 8;
255 else if ( token ==
"int" )
256 result =
sizeof(int) * 8;
257 else if ( token ==
"long" )
258 result =
sizeof(long) * 8;
272void claw::graphic::xbm::reader::read_name( std::istream& f )
277 read_line(f, line,
'[');
281 std::string::size_type
end = line.find_last_of(
'_');
283 if (
end != std::string::npos )
285 std::string::size_type
begin = line.find_last_of(
" \t",
end);
287 if (
begin == std::string::npos )
305void claw::graphic::xbm::reader::read_pixels
306( std::istream& f,
unsigned int bpe )
const
315 while ( (first!=last) && valid )
318 read_line( f, s_val,
',' );
320 std::istringstream iss(s_val);
323 if ( iss >> std::hex >> val )
325 for(
unsigned int i=0;
326 (i!=bpe) && (first!=last) && (x!=m_image.width());
327 ++i, ++first, ++x, val >>= 1 )
333 if ( x==m_image.width() )
351void claw::graphic::xbm::reader::read_line
352( std::istream& f, std::string& line,
char endchar )
const
359 if ( std::getline( f, line, endchar ) )
364 remove_comments(f, line, endchar);
365 stop = !line.empty();
379void claw::graphic::xbm::reader::remove_comments
380( std::istream& f, std::string& line,
char endchar )
const
382 std::string working(line);
383 std::string::size_type beg = working.find(
"/*" );
385 if ( beg != std::string::npos )
387 line = working.substr(0, beg);
389 std::string::size_type
end = working.rfind(
"*/" );
392 while ( (
end == std::string::npos) && !stop )
393 if ( std::getline(f, working, endchar) )
394 end = working.find(
"*/" );
400 line += working.substr(
end+2, line.length() -
end - 2);
405 remove_comments(f, line, endchar);
Some assert macros to strengthen you code.
#define CLAW_PRECOND(b)
Abort the program if a precondition is not true.
A simple class to use as exception with string message.
A class to deal with images.
base_iterator< image, pixel_type > iterator
The type of the iterator on the pixels of the image.
iterator end()
Get an iterator pointing just past the last pixel.
iterator begin()
Get an iterator pointing on the first pixel.
reader(image &img)
Constructor.
void load(std::istream &f)
Load an image from a xbm file.
A class for xbm pictures.
void set_hot(const claw::math::coordinate_2d< int > &hot)
Set the hot spot of the image.
void set_name(const std::string &name)
Set the name of the image.
Coordinates in a two dimensional space.
value_type x
X-coordinate.
value_type y
Y-coordinate.
A simple class to use as exception with string message.
rgba_pixel black_pixel(0, 0, 0, std::numeric_limits< rgba_pixel::component_type >::max())
The black color.
rgba_pixel white_pixel
The white color.
Generic algorithms on strings.
A class for xbm pictures.