51 rgba_pixel_8 targa::reader::file_input_buffer<rgba_pixel_8>::get_pixel()
55 if ( this->remaining() < 4 )
58 assert( this->remaining() >= 4 );
60 result.components.blue = this->get_next();
61 result.components.green = this->get_next();
62 result.components.red = this->get_next();
63 result.components.alpha = this->get_next();
82 rgba_pixel_8 targa::reader::file_input_buffer<rgb_pixel_8>::get_pixel()
86 if ( this->remaining() < 3 )
89 assert( this->remaining() >= 3 );
91 result.components.blue = this->get_next();
92 result.components.green = this->get_next();
93 result.components.red = this->get_next();
94 result.components.alpha =
95 std::numeric_limits<claw::graphic::rgba_pixel_8::component_type>::max();
114 rgba_pixel_8 targa::reader::file_input_buffer<targa::pixel16>::get_pixel()
118 if ( this->remaining() < 2 )
121 assert( this->remaining() >= 2 );
123 unsigned char second_byte = this->get_next();
124 unsigned char first_byte = this->get_next();
126 unsigned char r = (first_byte & 0x7C) >> 2;
128 ((first_byte & 0x03) << 3) | ((second_byte & 0xE0) >> 5);
129 unsigned char b = second_byte & 0x1F;
131 result.components.blue = b * 8;
132 result.components.green = g * 8;
133 result.components.red = r * 8;
134 result.components.alpha =
135 std::numeric_limits<claw::graphic::rgba_pixel_8::component_type>::max();
165 targa::reader::mapped_file_input_buffer<targa::pixel8>::get_pixel()
167 if ( this->remaining() < 1 )
170 assert( this->remaining() >= 1 );
172 unsigned char index = this->get_next();
174 return m_palette[index];
220 std::istream::pos_type init_pos = f.tellg();
228 f.read( reinterpret_cast<char*>(&h),
sizeof(
header) );
230 if ( f.rdstate() == std::ios_base::goodbit )
237 case color_mapped: load_color_mapped(h, f);
break;
238 case rle_color_mapped: load_rle_color_mapped(h, f);
break;
239 case true_color: load_true_color(h, f);
break;
240 case rle_true_color: load_rle_true_color(h, f);
break;
243 (
"targa::reader::targa: unsupported image type" );
248 (
"claw::targa::reader::targa: can't read header" );
253 f.seekg( init_pos, std::ios_base::beg );
263 void claw::graphic::targa::reader::check_if_targa( std::istream& f )
const
267 std::istream::pos_type init_pos = f.tellg();
271 f.seekg( -(std::istream::off_type)
sizeof(footer), std::ios::end );
272 f.read( reinterpret_cast<char*>(&foot),
sizeof(footer) );
273 f.seekg( init_pos , std::ios::beg );
275 if ( !foot.is_valid() )
287 void claw::graphic::targa::reader::load_palette
288 (
const header& h, std::istream& f, color_palette32& palette )
const
290 assert((h.image_type == color_mapped) || (h.image_type == rle_color_mapped));
292 switch( h.color_map_specification.entry_size )
294 case 16: load_palette_content<pixel16>(f, palette);
break;
295 case 24: load_palette_content<rgb_pixel_8>(f, palette);
break;
296 case 32: load_palette_content<rgba_pixel_8>(f, palette);
break;
299 (
"targa::reader::load_palette: unsupported entry size" );
310 void claw::graphic::targa::reader::load_color_mapped
311 (
const header& h, std::istream& f )
313 assert(h.image_type == color_mapped);
315 f.seekg( h.id_length, std::ios_base::cur );
317 color_palette32 palette( h.color_map_specification.length );
318 load_palette( h, f, palette );
320 switch(h.image_specification.bpp)
322 case 8: load_color_mapped_raw<pixel8>(h, f, palette);
break;
325 (
"targa::reader::load_color_mapped: unsupported color depth" );
336 void claw::graphic::targa::reader::load_rle_color_mapped
337 (
const header& h, std::istream& f )
339 assert(h.image_type == rle_color_mapped);
341 f.seekg( h.id_length, std::ios_base::cur );
343 color_palette32 palette( h.color_map_specification.length );
344 load_palette( h, f, palette );
346 switch(h.image_specification.bpp)
348 case 8: decompress_rle_color_mapped<rle8_decoder>(h, f, palette);
break;
351 (
"targa::reader::load_rle_color_mapped: unsupported color depth" );
362 void claw::graphic::targa::reader::load_true_color
363 (
const header& h, std::istream& f )
365 assert(h.image_type == true_color);
367 f.seekg( h.id_length, std::ios_base::cur );
369 switch(h.image_specification.bpp)
371 case 16 : load_true_color_raw<pixel16>(h, f);
break;
372 case 24 : load_true_color_raw<rgb_pixel_8>(h, f);
break;
373 case 32 : load_true_color_raw<rgba_pixel_8>(h, f);
break;
376 (
"targa::reader::load_true_color: unsupported color depth" );
387 void claw::graphic::targa::reader::load_rle_true_color
388 (
const header& h, std::istream& f )
390 assert(h.image_type == rle_true_color);
392 f.seekg( h.id_length, std::ios_base::cur );
394 switch(h.image_specification.bpp)
396 case 16 : decompress_rle_true_color<rle16_decoder>(h, f);
break;
397 case 24 : decompress_rle_true_color<rle24_decoder>(h, f);
break;
398 case 32 : decompress_rle_true_color<rle32_decoder>(h, f);
break;
401 (
"targa::reader::load_rle_true_color: unsupported color depth" );