48 rgba_pixel_8 targa::reader::file_input_buffer<rgba_pixel_8>::get_pixel()
52 if(this->remaining() < 4)
55 assert(this->remaining() >= 4);
57 result.components.blue = this->get_next();
58 result.components.green = this->get_next();
59 result.components.red = this->get_next();
60 result.components.alpha = this->get_next();
78 rgba_pixel_8 targa::reader::file_input_buffer<rgb_pixel_8>::get_pixel()
82 if(this->remaining() < 3)
85 assert(this->remaining() >= 3);
87 result.components.blue = this->get_next();
88 result.components.green = this->get_next();
89 result.components.red = this->get_next();
90 result.components.alpha = std::numeric_limits<
109 rgba_pixel_8 targa::reader::file_input_buffer<targa::pixel16>::get_pixel()
113 if(this->remaining() < 2)
116 assert(this->remaining() >= 2);
118 unsigned char second_byte = this->get_next();
119 unsigned char first_byte = this->get_next();
121 unsigned char r = (first_byte & 0x7C) >> 2;
123 = ((first_byte & 0x03) << 3) | ((second_byte & 0xE0) >> 5);
124 unsigned char b = second_byte & 0x1F;
126 result.components.blue = b * 8;
127 result.components.green = g * 8;
128 result.components.red = r * 8;
129 result.components.alpha = std::numeric_limits<
152 targa::reader::mapped_file_input_buffer<targa::pixel8>::get_pixel()
154 if(this->remaining() < 1)
157 assert(this->remaining() >= 1);
159 unsigned char index = this->get_next();
161 return m_palette[index];
196 std::istream::pos_type init_pos = f.tellg();
204 f.read(
reinterpret_cast<char*
>(&h),
sizeof(
header));
206 if(f.rdstate() == std::ios_base::goodbit)
214 load_color_mapped(h, f);
216 case rle_color_mapped:
217 load_rle_color_mapped(h, f);
220 load_true_color(h, f);
223 load_rle_true_color(h, f);
227 "targa::reader::targa: unsupported image type");
232 "claw::targa::reader::targa: can't read header");
237 f.seekg(init_pos, std::ios_base::beg);
246void claw::graphic::targa::reader::check_if_targa(std::istream& f)
const
250 std::istream::pos_type init_pos = f.tellg();
254 f.seekg(-(std::istream::off_type)
sizeof(footer), std::ios::end);
255 f.read(
reinterpret_cast<char*
>(&foot),
sizeof(footer));
256 f.seekg(init_pos, std::ios::beg);
269void claw::graphic::targa::reader::load_palette(
const header& h,
271 color_palette32& palette)
const
273 assert((h.image_type == color_mapped) || (h.image_type == rle_color_mapped));
275 switch(h.color_map_specification.entry_size)
278 load_palette_content<pixel16>(f, palette);
281 load_palette_content<rgb_pixel_8>(f, palette);
284 load_palette_content<rgba_pixel_8>(f, palette);
288 "targa::reader::load_palette: unsupported entry size");
298void claw::graphic::targa::reader::load_color_mapped(
const header& h,
301 assert(h.image_type == color_mapped);
303 f.seekg(h.id_length, std::ios_base::cur);
305 color_palette32 palette(h.color_map_specification.length);
306 load_palette(h, f, palette);
308 switch(h.image_specification.bpp)
311 load_color_mapped_raw<pixel8>(h, f, palette);
315 "targa::reader::load_color_mapped: unsupported color depth");
325void claw::graphic::targa::reader::load_rle_color_mapped(
const header& h,
328 assert(h.image_type == rle_color_mapped);
330 f.seekg(h.id_length, std::ios_base::cur);
332 color_palette32 palette(h.color_map_specification.length);
333 load_palette(h, f, palette);
335 switch(h.image_specification.bpp)
338 decompress_rle_color_mapped<rle8_decoder>(h, f, palette);
341 throw claw::bad_format(
342 "targa::reader::load_rle_color_mapped: unsupported color depth");
352void claw::graphic::targa::reader::load_true_color(
const header& h,
355 assert(h.image_type == true_color);
357 f.seekg(h.id_length, std::ios_base::cur);
359 switch(h.image_specification.bpp)
362 load_true_color_raw<pixel16>(h, f);
365 load_true_color_raw<rgb_pixel_8>(h, f);
368 load_true_color_raw<rgba_pixel_8>(h, f);
371 throw claw::bad_format(
372 "targa::reader::load_true_color: unsupported color depth");
382void claw::graphic::targa::reader::load_rle_true_color(
const header& h,
385 assert(h.image_type == rle_true_color);
387 f.seekg(h.id_length, std::ios_base::cur);
389 switch(h.image_specification.bpp)
392 decompress_rle_true_color<rle16_decoder>(h, f);
395 decompress_rle_true_color<rle24_decoder>(h, f);
398 decompress_rle_true_color<rle32_decoder>(h, f);
401 throw claw::bad_format(
402 "targa::reader::load_rle_true_color: unsupported color depth");
#define CLAW_PRECOND(b)
Abort the program if a precondition is not true.
image()
Constructor. Creates an image without datas.
void load(std::istream &f)
Load an image from a targa file.
reader(image &img)
Constructor.
A simple class to use as exception with string message.
#define CLAW_EXCEPTION(m)
Create an exception and add the name of the current function to the message.
Everything about image structures and processing.
rgba_pixel rgba_pixel_8
A color with 8 bits per component and an alpha channel.
This is the main namespace.
unsigned char component_type
The type of the components of the color.
A class for targa pictures.