claw::graphic::pcx::writer Class Reference

#include <pcx.hpp>

List of all members.


Detailed Description

This class write an image in a pcx file.

Author:
Julien Jorge

Definition at line 303 of file pcx.hpp.

Public Types

typedef rle_encoder< file_output_bufferrle_pcx_encoder
 RLE encoder for pcx format.

Public Member Functions

 writer (const image &img)
 Constructor.
 writer (const image &img, std::ostream &f)
 Constructor.
void save (std::ostream &os) const
 Save the content of the image in a stream.

Private Member Functions

void write_header (std::ostream &os, unsigned int bytes_per_line) const
 Save the header of the image in a stream.
void save_rle_true_color (std::ostream &os, unsigned int bytes_per_line) const
 Save the content of the image in a stream.

Private Attributes

const imagem_image
 The image from which we read the data.

Classes

class  file_output_buffer
 The type of the output buffer associated with the file when encoding RLE data. More...


Member Typedef Documentation

typedef rle_encoder<file_output_buffer> claw::graphic::pcx::writer::rle_pcx_encoder

RLE encoder for pcx format.

Author:
Julien Jorge

Definition at line 338 of file pcx.hpp.


Constructor & Destructor Documentation

claw::graphic::pcx::writer::writer ( const image img  ) 

Constructor.

Parameters:
img The image to save.

Definition at line 90 of file pcx_writer.cpp.

00091   : m_image(img)
00092 {
00093 
00094 } // pcx::writer::writer()

claw::graphic::pcx::writer::writer ( const image img,
std::ostream &  f 
)

Constructor.

Parameters:
img The image to save.
f The file in which we save the data.

Definition at line 102 of file pcx_writer.cpp.

References save().

00103   : m_image(img)
00104 {
00105   save(f);
00106 } // pcx::writer::writer()


Member Function Documentation

void claw::graphic::pcx::writer::save ( std::ostream &  os  )  const

Save the content of the image in a stream.

Parameters:
os The stream in which we write.

Definition at line 113 of file pcx_writer.cpp.

References m_image, save_rle_true_color(), claw::graphic::image::width(), and write_header().

Referenced by writer().

00114 {
00115   const unsigned int bytes_per_line = m_image.width() + m_image.width() % 2;
00116 
00117   write_header(os, bytes_per_line);
00118   save_rle_true_color(os, bytes_per_line);
00119 } // pcx::writer::save()

void claw::graphic::pcx::writer::save_rle_true_color ( std::ostream &  os,
unsigned int  bytes_per_line 
) const [private]

Save the content of the image in a stream.

Parameters:
os The stream in which we write.
bytes_per_line Number of bytes per decoded line.

Definition at line 161 of file pcx_writer.cpp.

References claw::rle_encoder< OutputBuffer >::encode().

Referenced by save().

00162 {
00163   std::vector<u_int_8> data(bytes_per_line, 0);
00164 
00165   rle_pcx_encoder encoder;
00166   file_output_buffer output(os);
00167 
00168   for (unsigned int y=0; y!=m_image.height(); ++y)
00169     {
00170       // red
00171       for (unsigned int x=0; x!=m_image.width(); ++x)
00172         data[x] = m_image[y][x].components.red;
00173 
00174       encoder.encode( data.begin(), data.end(), output );
00175 
00176       // green
00177       for (unsigned int x=0; x!=m_image.width(); ++x)
00178         data[x] = m_image[y][x].components.green;
00179 
00180       encoder.encode( data.begin(), data.end(), output );
00181 
00182       // blue
00183       for (unsigned int x=0; x!=m_image.width(); ++x)
00184         data[x] = m_image[y][x].components.blue;
00185 
00186       encoder.encode( data.begin(), data.end(), output );
00187     }
00188 } // pcx::writer::save_rle_true_color()

void claw::graphic::pcx::writer::write_header ( std::ostream &  os,
unsigned int  bytes_per_line 
) const [private]

Save the header of the image in a stream.

Parameters:
os The stream in which we write.
bytes_per_line Number of bytes per decoded line.

Definition at line 128 of file pcx_writer.cpp.

References claw::graphic::pcx::header::bpp, claw::graphic::pcx::header::bytes_per_line, claw::graphic::pcx::header::color_map, claw::graphic::pcx::header::color_planes, claw::graphic::pcx::header::encoded, claw::graphic::pcx::header::filler, claw::graphic::pcx::header::horizontal, claw::graphic::pcx::header::horizontal_dpi, claw::graphic::pcx::header::manufacturer, claw::graphic::pcx::header::palette_info, claw::graphic::pcx::header::reserved, claw::graphic::pcx::header::screen_size, claw::graphic::pcx::header::version, claw::graphic::pcx::header::vertical, claw::graphic::pcx::header::vertical_dpi, 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 save().

00129 {
00130   header h;
00131 
00132   h.manufacturer   = 10;
00133   h.version        = 5;
00134   h.encoded        = 1;
00135   h.bpp            = 8;
00136   h.window.x_min   = 0;
00137   h.window.y_min   = 0;
00138   h.window.x_max   = m_image.width() - 1;
00139   h.window.y_max   = m_image.height() - 1;
00140   h.horizontal_dpi = 72; // arbitrary value
00141   h.vertical_dpi   = 72;
00142   std::fill( h.color_map, h.color_map+16, rgb_pixel_8(0, 0, 0) );
00143   h.reserved               = 0;
00144   h.color_planes           = 3; // RGB
00145   h.bytes_per_line         = bytes_per_line;
00146   h.palette_info           = 0;
00147   h.screen_size.horizontal = 0;
00148   h.screen_size.vertical   = 0;
00149   std::fill( h.filler, h.filler+54, 0 );
00150 
00151   os.write( reinterpret_cast<char*>(&h), sizeof(header) );
00152 } // pcx::writer::write_header()


Member Data Documentation

const image& claw::graphic::pcx::writer::m_image [private]

The image from which we read the data.

Definition at line 354 of file pcx.hpp.

Referenced by save().


The documentation for this class was generated from the following files:
Generated on Mon Nov 9 05:07:35 2009 for CLAW Library (a C++ Library Absolutely Wonderful) by  doxygen 1.4.7