This class read data from a pcx file and store it in an image. More...
#include <pcx.hpp>
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... | |
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. |
This class read data from a pcx file and store it in an image.
Definition at line 158 of file pcx.hpp.
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 270 of file pcx_reader.cpp.
00271 : m_image( img ) 00272 { 00273 00274 } // 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 283 of file pcx_reader.cpp.
References 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 361 of file pcx_reader.cpp.
References CLAW_EXCEPTION, and claw::graphic::pcx::header::manufacturer.
Referenced by load().
00362 { 00363 if ( h.manufacturer != 0x0A ) 00364 throw CLAW_EXCEPTION( "Not a Pcx file." ); 00365 } // pcx::reader::check_if_pcx()
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_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()
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 460 of file pcx_reader.cpp.
References claw::rle_decoder< Pattern, InputBuffer, OutputBuffer >::decode().
00461 { 00462 rle_pcx_input_buffer input(f); 00463 rle_pcx_output_buffer output(scanline); 00464 00465 rle_pcx_decoder decoder; 00466 00467 decoder.decode( input, output ); 00468 } // pcx::reader::decompress_line()
void claw::graphic::pcx::reader::load | ( | std::istream & | f | ) |
Load an image from a pcx file.
f | Pcx file. |
Definition at line 294 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().
00295 { 00296 CLAW_PRECOND( !!f ); 00297 std::istream::pos_type init_pos = f.tellg(); 00298 00299 try 00300 { 00301 header h; 00302 00303 f.read( reinterpret_cast<char*>(&h), sizeof(header) ); 00304 00305 if ( f.rdstate() == std::ios_base::goodbit ) 00306 { 00307 check_if_pcx(h); 00308 00309 m_image.set_size( h.window.x_max - h.window.x_min + 1, 00310 h.window.y_max - h.window.y_min + 1 ); 00311 00312 bool supported_format = true; 00313 00314 switch(h.color_planes) 00315 { 00316 case 1: 00317 if (h.bpp == 1) 00318 load_mono(h, f); 00319 else if (h.bpp == 8) 00320 load_256_color_mapped(h, f); 00321 else 00322 supported_format = false; 00323 break; 00324 case 3: 00325 if (h.bpp == 8) 00326 load_true_color(h, f); 00327 else 00328 supported_format = false; 00329 break; 00330 case 4: 00331 if (h.bpp == 1) 00332 load_16_color_mapped(h, f); 00333 else 00334 supported_format = false; 00335 break; 00336 default : 00337 supported_format = false; 00338 } 00339 00340 if ( supported_format == false ) 00341 throw claw::bad_format 00342 ( "pcx::reader::pcx: unsupported image type" ); 00343 } 00344 else 00345 throw claw::bad_format 00346 ( "claw::pcx::reader::pcx: can't read header" ); 00347 } 00348 catch(...) 00349 { 00350 f.clear(); 00351 f.seekg( init_pos, std::ios_base::beg ); 00352 throw; 00353 } 00354 } // pcx::reader::load()
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 388 of file pcx_reader.cpp.
References claw::graphic::pcx::header::color_planes.
Referenced by load().
00389 { 00390 assert( h.color_planes == 4 ); 00391 00392 converter_16 convert(h); 00393 decompress( h, f, convert ); 00394 } // pcx::reader::load_16_color_mapped()
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 418 of file pcx_reader.cpp.
References CLAW_EXCEPTION, claw::graphic::pcx::header::color_planes, and claw::buffered_istream< Stream >::read().
Referenced by load().
00419 { 00420 assert( h.color_planes == 1 ); 00421 00422 // 256 RGB triplets 00423 const unsigned int palette_length = 256 * 3; 00424 00425 color_palette32 palette(256); 00426 std::istream::pos_type init_pos = f.tellg(); 00427 00428 // -1 for the check byte 00429 f.seekg( -(std::istream::off_type)palette_length - 1, std::ios_base::end ); 00430 00431 char check; 00432 f.read(&check, 1); 00433 00434 if ( check != 12 ) 00435 throw CLAW_EXCEPTION( "PCX: The color palette is missing." ); 00436 00437 char buffer[palette_length]; 00438 f.read(buffer, palette_length); 00439 00440 for (unsigned int i=0, j=0; i!=palette_length; i+=3, ++j) 00441 { 00442 palette[j].components.alpha = 255; 00443 palette[j].components.red = buffer[i]; 00444 palette[j].components.green = buffer[i+1]; 00445 palette[j].components.blue = buffer[i+2]; 00446 } 00447 00448 f.seekg( init_pos ); 00449 converter_256 convert(palette); 00450 decompress( h, f, convert ); 00451 } // pcx::reader::load_256_color_mapped()
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 373 of file pcx_reader.cpp.
References claw::graphic::pcx::header::color_planes, and decompress().
Referenced by load().
00374 { 00375 assert( h.color_planes == 1 ); 00376 00377 converter_mono convert; 00378 decompress( h, f, convert ); 00379 } // pcx::reader::load_mono()
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 403 of file pcx_reader.cpp.
References claw::graphic::pcx::header::color_planes, and decompress().
Referenced by load().
00404 { 00405 assert( h.color_planes == 3 ); 00406 00407 converter_true_color convert; 00408 decompress( h, f, convert ); 00409 } // pcx::reader::load_true_color()
image& claw::graphic::pcx::reader::m_image [private] |