Classes | Public Types | Public Member Functions | Private Member Functions | Private Attributes

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

This class write an image in a pcx file. More...

#include <pcx.hpp>

List of all members.

Classes

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

Public Types

typedef rle_encoder
< file_output_buffer
rle_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.

Detailed Description

This class write an image in a pcx file.

Author:
Julien Jorge

Definition at line 303 of file pcx.hpp.


Member Typedef Documentation

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.

  : m_image(img)
{

} // 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().

  : m_image(img)
{
  save(f);
} // 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().

{
  const unsigned int bytes_per_line = m_image.width() + m_image.width() % 2;

  write_header(os, bytes_per_line);
  save_rle_true_color(os, bytes_per_line);
} // 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().

{
  std::vector<u_int_8> data(bytes_per_line, 0);

  rle_pcx_encoder encoder;
  file_output_buffer output(os);

  for (unsigned int y=0; y!=m_image.height(); ++y)
    {
      // red
      for (unsigned int x=0; x!=m_image.width(); ++x)
        data[x] = m_image[y][x].components.red;

      encoder.encode( data.begin(), data.end(), output );

      // green
      for (unsigned int x=0; x!=m_image.width(); ++x)
        data[x] = m_image[y][x].components.green;

      encoder.encode( data.begin(), data.end(), output );

      // blue
      for (unsigned int x=0; x!=m_image.width(); ++x)
        data[x] = m_image[y][x].components.blue;

      encoder.encode( data.begin(), data.end(), output );
    }
} // 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().

{
  header h;

  h.manufacturer   = 10;
  h.version        = 5;
  h.encoded        = 1;
  h.bpp            = 8;
  h.window.x_min   = 0;
  h.window.y_min   = 0;
  h.window.x_max   = m_image.width() - 1;
  h.window.y_max   = m_image.height() - 1;
  h.horizontal_dpi = 72; // arbitrary value
  h.vertical_dpi   = 72;
  std::fill( h.color_map, h.color_map+16, rgb_pixel_8(0, 0, 0) );
  h.reserved               = 0;
  h.color_planes           = 3; // RGB
  h.bytes_per_line         = bytes_per_line;
  h.palette_info           = 0;
  h.screen_size.horizontal = 0;
  h.screen_size.vertical   = 0;
  std::fill( h.filler, h.filler+54, 0 );

  os.write( reinterpret_cast<char*>(&h), sizeof(header) );
} // pcx::writer::write_header()


Member Data Documentation

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: