#include <pcx.hpp>
Definition at line 158 of file pcx.hpp.
Public Member Functions | |
reader (image &img) | |
Constructor. | |
reader (image &img, std::istream &f) | |
Constructor. | |
void | load (std::istream &f) |
Load an image from a pcx file. | |
Private Types | |
typedef buffered_istream < std::istream > | rle_pcx_input_buffer |
The type of the input buffer associated with the file when decoding RLE files. | |
Private Member Functions | |
void | check_if_pcx (const header &h) const |
Check if an header seems valid for a pcx file. | |
void | load_mono (const header &h, std::istream &f) |
Load the monochrome pcx content. | |
void | load_16_color_mapped (const header &h, std::istream &f) |
Load the 16 bpp color mapped pcx content. | |
void | load_true_color (const header &h, std::istream &f) |
Load the true color (24 bpp) pcx content. | |
void | load_256_color_mapped (const header &h, std::istream &f) |
Load the 8 bpp color mapped pcx content. | |
void | decompress_line (std::istream &f, color_plane_type &scanline) const |
Load the 8 bpp color mapped pcx content. | |
template<typename Converter> | |
void | decompress (const header &h, std::istream &f, const Converter &convert) |
Decompress the scan lines and convert their contents into pixels in the image. | |
Private Attributes | |
image & | m_image |
The image in which we store the data we read. | |
Classes | |
class | converter_16 |
Function object that converts a scanline of a 4bpp color mapped pcx into 32 bpp pixels. More... | |
class | converter_256 |
Function object that converts a scanline of a 8bpp color mapped pcx into 32 bpp pixels. More... | |
class | converter_mono |
Function object that converts a scanline of a monochrome pcx into 32 bpp pixels. More... | |
class | converter_true_color |
Function object that converts a scanline of a 3 planes true color scanline into 32 bpp pixels. More... | |
class | rle_pcx_decoder |
RLE decoder for pcx RLE format. More... | |
class | rle_pcx_output_buffer |
The output buffer for the RLE decoder. More... |
typedef buffered_istream<std::istream> claw::graphic::pcx::reader::rle_pcx_input_buffer [private] |
claw::graphic::pcx::reader::reader | ( | image & | img | ) |
Constructor.
img | The image in which the data will be stored. |
Definition at line 273 of file pcx_reader.cpp.
00274 : m_image( img ) 00275 { 00276 00277 } // pcx::reader::reader()
claw::graphic::pcx::reader::reader | ( | image & | img, | |
std::istream & | f | |||
) |
Constructor.
img | The image in which the data will be stored. | |
f | The file from which we read the data. |
Definition at line 286 of file pcx_reader.cpp.
References load().
void claw::graphic::pcx::reader::load | ( | std::istream & | f | ) |
Load an image from a pcx file.
f | Pcx file. |
Definition at line 297 of file pcx_reader.cpp.
References claw::graphic::pcx::header::bpp, check_if_pcx(), CLAW_PRECOND, claw::graphic::pcx::header::color_planes, load_16_color_mapped(), load_256_color_mapped(), load_mono(), load_true_color(), m_image, claw::graphic::image::set_size(), claw::graphic::pcx::header::window, claw::graphic::pcx::header::x_max, claw::graphic::pcx::header::x_min, claw::graphic::pcx::header::y_max, and claw::graphic::pcx::header::y_min.
Referenced by reader().
00298 { 00299 CLAW_PRECOND( !!f ); 00300 std::istream::pos_type init_pos = f.tellg(); 00301 00302 try 00303 { 00304 header h; 00305 00306 f.read( reinterpret_cast<char*>(&h), sizeof(header) ); 00307 00308 if ( f.rdstate() == std::ios_base::goodbit ) 00309 { 00310 check_if_pcx(h); 00311 00312 m_image.set_size( h.window.x_max - h.window.x_min + 1, 00313 h.window.y_max - h.window.y_min + 1 ); 00314 00315 bool supported_format = true; 00316 00317 switch(h.color_planes) 00318 { 00319 case 1: 00320 if (h.bpp == 1) 00321 load_mono(h, f); 00322 else if (h.bpp == 8) 00323 load_256_color_mapped(h, f); 00324 else 00325 supported_format = false; 00326 break; 00327 case 3: 00328 if (h.bpp == 8) 00329 load_true_color(h, f); 00330 else 00331 supported_format = false; 00332 break; 00333 case 4: 00334 if (h.bpp == 1) 00335 load_16_color_mapped(h, f); 00336 else 00337 supported_format = false; 00338 break; 00339 default : 00340 supported_format = false; 00341 } 00342 00343 if ( supported_format == false ) 00344 throw claw::bad_format 00345 ( "pcx::reader::pcx: unsupported image type" ); 00346 } 00347 else 00348 throw claw::bad_format 00349 ( "claw::pcx::reader::pcx: can't read header" ); 00350 } 00351 catch(...) 00352 { 00353 f.clear(); 00354 f.seekg( init_pos, std::ios_base::beg ); 00355 throw; 00356 } 00357 } // pcx::reader::load()
void claw::graphic::pcx::reader::check_if_pcx | ( | const header & | h | ) | const [private] |
Check if an header seems valid for a pcx file.
h | The header read in the file. |
Definition at line 364 of file pcx_reader.cpp.
References CLAW_EXCEPTION, and claw::graphic::pcx::header::manufacturer.
Referenced by load().
00365 { 00366 if ( h.manufacturer != 0x0A ) 00367 throw CLAW_EXCEPTION( "Not a Pcx file." ); 00368 } // pcx::reader::check_if_pcx()
void claw::graphic::pcx::reader::load_mono | ( | const header & | h, | |
std::istream & | f | |||
) | [private] |
Load the monochrome pcx content.
h | The header read in the file. | |
f | The file from which we read. |
Definition at line 376 of file pcx_reader.cpp.
References claw::graphic::pcx::header::color_planes, and decompress().
Referenced by load().
00377 { 00378 assert( h.color_planes == 1 ); 00379 00380 converter_mono convert; 00381 decompress( h, f, convert ); 00382 } // pcx::reader::load_mono()
void claw::graphic::pcx::reader::load_16_color_mapped | ( | const header & | h, | |
std::istream & | f | |||
) | [private] |
Load the 16 bpp color mapped pcx content.
h | The header read in the file. | |
f | The file from which we read. |
Definition at line 391 of file pcx_reader.cpp.
References claw::graphic::pcx::header::color_planes, and decompress().
Referenced by load().
00392 { 00393 assert( h.color_planes == 4 ); 00394 00395 converter_16 convert(h); 00396 decompress( h, f, convert ); 00397 } // pcx::reader::load_16_color_mapped()
void claw::graphic::pcx::reader::load_true_color | ( | const header & | h, | |
std::istream & | f | |||
) | [private] |
Load the true color (24 bpp) pcx content.
h | The header read in the file. | |
f | The file from which we read. |
Definition at line 406 of file pcx_reader.cpp.
References claw::graphic::pcx::header::color_planes, and decompress().
Referenced by load().
00407 { 00408 assert( h.color_planes == 3 ); 00409 00410 converter_true_color convert; 00411 decompress( h, f, convert ); 00412 } // pcx::reader::load_true_color()
void claw::graphic::pcx::reader::load_256_color_mapped | ( | const header & | h, | |
std::istream & | f | |||
) | [private] |
Load the 8 bpp color mapped pcx content.
h | The header read in the file. | |
f | The file from which we read. |
Definition at line 421 of file pcx_reader.cpp.
References CLAW_EXCEPTION, claw::graphic::pcx::header::color_planes, decompress(), and claw::buffered_istream< Stream >::read().
Referenced by load().
00422 { 00423 assert( h.color_planes == 1 ); 00424 00425 // 256 RGB triplets 00426 const unsigned int palette_length = 256 * 3; 00427 00428 color_palette32 palette(256); 00429 std::istream::pos_type init_pos = f.tellg(); 00430 00431 // -1 for the check byte 00432 f.seekg( -(std::istream::off_type)palette_length - 1, std::ios_base::end ); 00433 00434 char check; 00435 f.read(&check, 1); 00436 00437 if ( check != 12 ) 00438 throw CLAW_EXCEPTION( "PCX: The color palette is missing." ); 00439 00440 char buffer[palette_length]; 00441 f.read(buffer, palette_length); 00442 00443 for (unsigned int i=0, j=0; i!=palette_length; i+=3, ++j) 00444 { 00445 palette[j].components.alpha = 255; 00446 palette[j].components.red = buffer[i]; 00447 palette[j].components.green = buffer[i+1]; 00448 palette[j].components.blue = buffer[i+2]; 00449 } 00450 00451 f.seekg( init_pos ); 00452 converter_256 convert(palette); 00453 decompress( h, f, convert ); 00454 } // pcx::reader::load_256_color_mapped()
void claw::graphic::pcx::reader::decompress_line | ( | std::istream & | f, | |
color_plane_type & | scanline | |||
) | const [private] |
Load the 8 bpp color mapped pcx content.
f | The file from which we read. | |
scanline | (out) Uncompressed scan line. |
Definition at line 463 of file pcx_reader.cpp.
References claw::rle_decoder< Pattern, InputBuffer, OutputBuffer >::decode().
00464 { 00465 rle_pcx_input_buffer input(f); 00466 rle_pcx_output_buffer output(scanline); 00467 00468 rle_pcx_decoder decoder; 00469 00470 decoder.decode( input, output ); 00471 } // pcx::reader::decompress_line()
void claw::graphic::pcx::reader::decompress | ( | const header & | h, | |
std::istream & | f, | |||
const Converter & | convert | |||
) | [inline, private] |
Decompress the scan lines and convert their contents into pixels in the image.
h | The header read in the file. | |
f | The file from which we read. | |
convert | Converter to use to convert the data into pixels. |
Definition at line 41 of file pcx_reader.tpp.
References claw::graphic::pcx::header::bytes_per_line, and claw::graphic::pcx::header::color_planes.
Referenced by load_16_color_mapped(), load_256_color_mapped(), load_mono(), and load_true_color().
00042 { 00043 std::vector<color_plane_type> scanline 00044 ( h.color_planes, color_plane_type(h.bytes_per_line) ); 00045 00046 for ( unsigned int y=0; y!=m_image.height(); ++y) 00047 { 00048 for (unsigned int i=0; i!=h.color_planes; ++i) 00049 decompress_line(f, scanline[i]); 00050 00051 convert( scanline, m_image, y ); 00052 } 00053 } // pcx::reader::decompress()
image& claw::graphic::pcx::reader::m_image [private] |