claw::graphic::targa::writer::file_output_buffer< Pixel > Class Template Reference

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

#include <targa.hpp>

List of all members.

Public Types

typedef Pixel pixel_type
 The type of the pixels in the input buffer.
typedef pixel_type pattern_type

Public Member Functions

 file_output_buffer (std::ostream &os)
 Constructor.
void encode (unsigned int n, pattern_type pattern)
 Code a pixel.
template<typename Iterator >
void raw (Iterator first, Iterator last)
 Write raw data int the stream.
unsigned int min_interesting () const
 Get the minimum number of pixels needed for encoding.
unsigned int max_encodable () const
 Get the maximum number of pixel a code can encode.
void order_pixel_bytes (const pixel_type &p)
template<>
void order_pixel_bytes (const pixel_type &p)

Private Attributes

std::ostream & m_stream
 The stream in which we write.

Detailed Description

template<typename Pixel>
class claw::graphic::targa::writer::file_output_buffer< Pixel >

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

Template parameters

Definition at line 419 of file targa.hpp.


Member Typedef Documentation

template<typename Pixel>
typedef pixel_type claw::graphic::targa::writer::file_output_buffer< Pixel >::pattern_type

Definition at line 425 of file targa.hpp.

template<typename Pixel>
typedef Pixel claw::graphic::targa::writer::file_output_buffer< Pixel >::pixel_type

The type of the pixels in the input buffer.

Definition at line 423 of file targa.hpp.


Constructor & Destructor Documentation

template<typename Pixel >
claw::graphic::targa::writer::file_output_buffer< Pixel >::file_output_buffer ( std::ostream &  os  )  [inline]

Constructor.

Parameters:
os The

Definition at line 47 of file targa_writer.tpp.

00048   : m_stream(os)
00049 {
00050 
00051 } // targa::writer::file_output_buffer::file_output_buffer()


Member Function Documentation

template<typename Pixel >
void claw::graphic::targa::writer::file_output_buffer< Pixel >::encode ( unsigned int  n,
pattern_type  pattern 
) [inline]

Code a pixel.

Parameters:
n The number of time the pixel appears.
pattern The value of the pixel.

Definition at line 61 of file targa_writer.tpp.

00062 {
00063   assert( n <= max_encodable() );
00064   assert( n >= min_interesting() );
00065 
00066   unsigned char key = (n-1) | 0x80;
00067 
00068   m_stream << key;
00069   order_pixel_bytes( pattern );
00070 } // targa::writer::file_output_buffer::encode()

template<typename Pixel >
unsigned int claw::graphic::targa::writer::file_output_buffer< Pixel >::max_encodable (  )  const [inline]

Get the maximum number of pixel a code can encode.

Definition at line 126 of file targa_writer.tpp.

00127 {
00128   return 0x80;
00129 } // targa::writer::file_output_buffer::max_encodable()

template<typename Pixel >
unsigned int claw::graphic::targa::writer::file_output_buffer< Pixel >::min_interesting (  )  const [inline]

Get the minimum number of pixels needed for encoding.

Definition at line 115 of file targa_writer.tpp.

00116 {
00117   return 2;
00118 } // targa::writer::file_output_buffer::min_interesting()

template<>
void claw::graphic::targa::writer::file_output_buffer< claw::graphic::rgba_pixel_8 >::order_pixel_bytes ( const pixel_type p  )  [inline]
Remarks:
This method is specialized for the pixels of type claw::graphic::pixel32.

Definition at line 52 of file targa_writer.cpp.

References claw::graphic::rgba_pixel::alpha, claw::graphic::rgba_pixel::blue, claw::graphic::rgba_pixel::components, claw::graphic::rgba_pixel::green, claw::graphic::targa::writer::file_output_buffer< Pixel >::m_stream, and claw::graphic::rgba_pixel::red.

00053     {
00054       m_stream << p.components.blue << p.components.green
00055          << p.components.red << p.components.alpha;
00056     } // targa::writer::file_output_buffer::order_pixel_bytes()

template<typename Pixel>
void claw::graphic::targa::writer::file_output_buffer< Pixel >::order_pixel_bytes ( const pixel_type p  ) 
template<typename Pixel >
template<typename Iterator >
void claw::graphic::targa::writer::file_output_buffer< Pixel >::raw ( Iterator  first,
Iterator  last 
) [inline]

Write raw data int the stream.

Parameters:
first Iterator on the first data.
last Iterator past the last data.

Definition at line 81 of file targa_writer.tpp.

00082 {
00083   unsigned int n = std::distance(first, last);
00084 
00085   unsigned int full = n / max_encodable();
00086   unsigned int remaining = n % max_encodable();
00087 
00088   unsigned char key = max_encodable() - 1;
00089 
00090   for (unsigned int i=0; i!=full; ++i)
00091     {
00092       m_stream << key;
00093 
00094       for (unsigned int j=0; j!=max_encodable(); ++j, ++first)
00095         order_pixel_bytes( *first );
00096     }
00097 
00098   if (remaining)
00099     {
00100       key = remaining - 1;
00101       m_stream << key;
00102       
00103       for (unsigned int j=0; j!=remaining; ++j, ++first)
00104         order_pixel_bytes( *first );
00105     }
00106 
00107 } // targa::writer::file_output_buffer::raw()


Member Data Documentation

template<typename Pixel>
std::ostream& claw::graphic::targa::writer::file_output_buffer< Pixel >::m_stream [private]

The stream in which we write.

Definition at line 441 of file targa.hpp.

Referenced by claw::graphic::targa::writer::file_output_buffer< Pixel >::order_pixel_bytes().


The documentation for this class was generated from the following files:

Generated on 9 Nov 2009 for CLAW Library (a C++ Library Absolutely Wonderful) by  doxygen 1.6.1