42void claw::graphic::pcx::reader::converter_mono::operator()(
43 const std::vector<color_plane_type>& scanline, image& img,
50 for(
unsigned int code = 0; x != img.width(); ++code)
54 for(
unsigned int i = 0; (i != 8) && (x != img.width());
67claw::graphic::pcx::reader::converter_16::converter_16(
const header& h)
77void claw::graphic::pcx::reader::converter_16::operator()(
78 const std::vector<color_plane_type>& scanline, image& img,
85 for(
unsigned int code = 0; x != img.width(); ++code)
92 for(
unsigned int i = 0; (i != 8) && (x != img.width()); ++x, ++i)
94 unsigned int index = ((c3 & 0x80) >> 4) | ((c2 & 0x80) >> 5)
95 | ((c1 & 0x80) >> 6) | ((c0 & 0x80) >> 7);
97 img[y][x] = m_header.color_map[index];
111claw::graphic::pcx::reader::converter_256::converter_256(
112 const color_palette32& palette)
122void claw::graphic::pcx::reader::converter_256::operator()(
123 const std::vector<color_plane_type>& scanline, image& img,
124 unsigned int y)
const
128 for(
unsigned int x = 0; x != img.width(); ++x)
129 img[y][x] = m_palette[scanline[0][x]];
138void claw::graphic::pcx::reader::converter_true_color::operator()(
139 const std::vector<color_plane_type>& scanline,
image& img,
140 unsigned int y)
const
144 for(
unsigned int x = 0; x != img.width(); ++x)
146 img[y][x].components.red = scanline[0][x];
147 img[y][x].components.green = scanline[1][x];
148 img[y][x].components.blue = scanline[2][x];
149 img[y][x].components.alpha
150 = std::numeric_limits<rgba_pixel_8::component_type>::max();
159claw::graphic::pcx::reader::rle_pcx_output_buffer::rle_pcx_output_buffer(
160 color_plane_type& result)
170void claw::graphic::pcx::reader::rle_pcx_output_buffer::fill(
unsigned int n,
175 for(
unsigned int i = 0; i != n; ++i)
176 m_result[m_position + i] = pattern;
186void claw::graphic::pcx::reader::rle_pcx_output_buffer::copy(
187 unsigned int n, rle_pcx_input_buffer& buffer)
189 CLAW_ASSERT(
false,
"This method should not have been called");
195bool claw::graphic::pcx::reader::rle_pcx_output_buffer::completed()
const
197 return m_position == m_result.size();
205void claw::graphic::pcx::reader::rle_pcx_decoder::read_mode(
206 input_buffer_type& input, output_buffer_type& output)
208 this->m_mode = this->stop;
209 bool ok = !output.completed();
211 if(ok && (input.remaining() < 1))
212 ok = input.read_more(1);
216 unsigned char key = input.get_next();
217 this->m_mode = this->compressed;
219 if((key & 0xC0) == 0xC0)
221 this->m_count = key & 0x3F;
223 if(input.remaining() < 1)
226 this->m_pattern = input.get_next();
231 this->m_pattern = key;
263 std::istream::pos_type init_pos = f.tellg();
269 f.read(
reinterpret_cast<char*
>(&h),
sizeof(header));
271 if(f.rdstate() == std::ios_base::goodbit)
275 m_image.set_size(h.window.x_max - h.window.x_min + 1,
276 h.window.y_max - h.window.y_min + 1);
278 bool supported_format =
true;
280 switch(h.color_planes)
286 load_256_color_mapped(h, f);
288 supported_format =
false;
292 load_true_color(h, f);
294 supported_format =
false;
298 load_16_color_mapped(h, f);
300 supported_format =
false;
303 supported_format =
false;
306 if(supported_format ==
false)
315 f.seekg(init_pos, std::ios_base::beg);
324void claw::graphic::pcx::reader::check_if_pcx(
const header& h)
const
326 if(h.manufacturer != 0x0A)
335void claw::graphic::pcx::reader::load_mono(
const header& h, std::istream& f)
337 assert(h.color_planes == 1);
339 converter_mono convert;
340 decompress(h, f, convert);
348void claw::graphic::pcx::reader::load_16_color_mapped(
const header& h,
351 assert(h.color_planes == 4);
353 converter_16 convert(h);
354 decompress(h, f, convert);
362void claw::graphic::pcx::reader::load_true_color(
const header& h,
365 assert(h.color_planes == 3);
367 converter_true_color convert;
368 decompress(h, f, convert);
376void claw::graphic::pcx::reader::load_256_color_mapped(
const header& h,
379 assert(h.color_planes == 1);
382 const unsigned int palette_length = 256 * 3;
384 color_palette32 palette(256);
385 std::istream::pos_type init_pos = f.tellg();
388 f.seekg(-(std::istream::off_type)palette_length - 1, std::ios_base::end);
396 char buffer[palette_length];
397 f.read(buffer, palette_length);
399 for(
unsigned int i = 0, j = 0; i != palette_length; i += 3, ++j)
401 palette[j].components.alpha = 255;
402 palette[j].components.red = buffer[i];
403 palette[j].components.green = buffer[i + 1];
404 palette[j].components.blue = buffer[i + 2];
408 converter_256 convert(palette);
409 decompress(h, f, convert);
417void claw::graphic::pcx::reader::decompress_line(
418 std::istream& f, color_plane_type&
scanline)
const
420 rle_pcx_input_buffer input(f);
421 rle_pcx_output_buffer output(
scanline);
423 rle_pcx_decoder decoder;
425 decoder.decode(input, output);
#define CLAW_PRECOND(b)
Abort the program if a precondition is not true.
#define CLAW_ASSERT(b, s)
Print a message on std::cerr and stop the program if a condition is not true.
image()
Constructor. Creates an image without datas.
void load(std::istream &f)
Load an image from a pcx 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.
rgba_pixel white_pixel
The white color.
rgba_pixel black_pixel
The black color.
unsigned_integer_of_size< 8 >::type u_int_8
An unsigned integer on 8 bits.
A class for pcx pictures.