42 void claw::graphic::pcx::reader::converter_mono::operator()
43 (
const std::vector<color_plane_type>& scanline, image& img,
44 unsigned int y )
const
50 for (
unsigned int code=0; x!=img.width(); ++code )
54 for(
unsigned int i=0; (i!=8) && (x!=img.width()); ++x, ++i, c<<=1 )
67 claw::graphic::pcx::reader::converter_16::converter_16(
const header& h )
80 void claw::graphic::pcx::reader::converter_16::operator()
81 (
const std::vector<color_plane_type>& scanline, image& img,
82 unsigned int y )
const
88 for (
unsigned int code=0; x!=img.width(); ++code )
95 for(
unsigned int i=0; (i!=8) && (x!=img.width()); ++x, ++i )
99 | ( (c2 & 0x80) >> 5 )
100 | ( (c1 & 0x80) >> 6 )
101 | ( (c0 & 0x80) >> 7 );
103 img[y][x] = m_header.color_map[index];
118 claw::graphic::pcx::reader::converter_256::converter_256
119 (
const color_palette32& palette )
132 void claw::graphic::pcx::reader::converter_256::operator()
133 (
const std::vector<color_plane_type>& scanline, image& img,
134 unsigned int y )
const
138 for (
unsigned int x=0; x!=img.width(); ++x )
139 img[y][x] = m_palette[ scanline[0][x] ];
149 void claw::graphic::pcx::reader::converter_true_color::operator()
150 (
const std::vector<color_plane_type>& scanline, image& img,
151 unsigned int y )
const
155 for (
unsigned int x=0; x!=img.width(); ++x )
157 img[y][x].components.red = scanline[0][x];
158 img[y][x].components.green = scanline[1][x];
159 img[y][x].components.blue = scanline[2][x];
160 img[y][x].components.alpha =
161 std::numeric_limits<rgba_pixel_8::component_type>::max();
174 claw::graphic::pcx::reader::rle_pcx_output_buffer::rle_pcx_output_buffer
175 ( color_plane_type& result )
176 : m_result(result), m_position(0)
187 void claw::graphic::pcx::reader::rle_pcx_output_buffer::fill
188 (
unsigned int n,
u_int_8 pattern )
192 for (
unsigned int i=0; i!=n; ++i)
193 m_result[m_position + i] = pattern;
204 void claw::graphic::pcx::reader::rle_pcx_output_buffer::copy
205 (
unsigned int n, rle_pcx_input_buffer& buffer )
207 CLAW_ASSERT(
false,
"This method should not have been called" );
214 bool claw::graphic::pcx::reader::rle_pcx_output_buffer::completed()
const
216 return m_position == m_result.size();
229 void claw::graphic::pcx::reader::rle_pcx_decoder::read_mode
230 ( input_buffer_type& input, output_buffer_type& output )
232 this->m_mode = this->stop;
233 bool ok = !output.completed();
235 if ( ok && (input.remaining() < 1) )
236 ok = input.read_more(1);
240 unsigned char key = input.get_next();
241 this->m_mode = this->compressed;
243 if ( (key & 0xC0) == 0xC0 )
245 this->m_count = key & 0x3F;
247 if ( input.remaining() < 1 )
250 this->m_pattern = input.get_next();
255 this->m_pattern = key;
297 std::istream::pos_type init_pos = f.tellg();
303 f.read( reinterpret_cast<char*>(&h),
sizeof(header) );
305 if ( f.rdstate() == std::ios_base::goodbit )
309 m_image.set_size( h.window.x_max - h.window.x_min + 1,
310 h.window.y_max - h.window.y_min + 1 );
312 bool supported_format =
true;
314 switch(h.color_planes)
320 load_256_color_mapped(h, f);
322 supported_format =
false;
326 load_true_color(h, f);
328 supported_format =
false;
332 load_16_color_mapped(h, f);
334 supported_format =
false;
337 supported_format =
false;
340 if ( supported_format ==
false )
342 (
"pcx::reader::pcx: unsupported image type" );
346 (
"claw::pcx::reader::pcx: can't read header" );
351 f.seekg( init_pos, std::ios_base::beg );
361 void claw::graphic::pcx::reader::check_if_pcx(
const header& h )
const
363 if ( h.manufacturer != 0x0A )
373 void claw::graphic::pcx::reader::load_mono(
const header& h, std::istream& f )
375 assert( h.color_planes == 1 );
377 converter_mono convert;
378 decompress( h, f, convert );
387 void claw::graphic::pcx::reader::load_16_color_mapped
388 (
const header& h, std::istream& f )
390 assert( h.color_planes == 4 );
392 converter_16 convert(h);
393 decompress( h, f, convert );
403 claw::graphic::pcx::reader::load_true_color(
const header& h, std::istream& f )
405 assert( h.color_planes == 3 );
407 converter_true_color convert;
408 decompress( h, f, convert );
417 void claw::graphic::pcx::reader::load_256_color_mapped
418 (
const header& h, std::istream& f )
420 assert( h.color_planes == 1 );
423 const unsigned int palette_length = 256 * 3;
425 color_palette32 palette(256);
426 std::istream::pos_type init_pos = f.tellg();
429 f.seekg( -(std::istream::off_type)palette_length - 1, std::ios_base::end );
437 char buffer[palette_length];
438 f.read(buffer, palette_length);
440 for (
unsigned int i=0, j=0; i!=palette_length; i+=3, ++j)
442 palette[j].components.alpha = 255;
443 palette[j].components.red = buffer[i];
444 palette[j].components.green = buffer[i+1];
445 palette[j].components.blue = buffer[i+2];
449 converter_256 convert(palette);
450 decompress( h, f, convert );
459 void claw::graphic::pcx::reader::decompress_line
460 ( std::istream& f, color_plane_type& scanline )
const
462 rle_pcx_input_buffer input(f);
463 rle_pcx_output_buffer output(scanline);
465 rle_pcx_decoder decoder;
467 decoder.decode( input, output );