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 );
127 void 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,
';');
155 void 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);
210 claw::graphic::xbm::reader::read_dim(
const std::string& line )
const
213 std::istringstream iss(line);
218 if ( token ==
"#define" )
235 claw::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;
272 void 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 )
290 m_name = line.substr(begin, end - begin);
305 void 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() )
351 void claw::graphic::xbm::reader::read_line
352 ( std::istream& f, std::string& line,
char endchar )
const
364 remove_comments(f, line, endchar);
365 stop = !line.empty();
379 void 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 )
394 end = working.find(
"*/" );
400 line += working.substr(end+2, line.length() - end - 2);
405 remove_comments(f, line, endchar);