targa_writer.cpp
Go to the documentation of this file.
/*
CLAW - a C++ Library Absolutely Wonderful
CLAW is a free library without any particular aim but being useful to
anyone.
Copyright (C) 2005-2011 Julien Jorge
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
contact: julien.jorge@gamned.org
*/
#include <claw/targa.hpp>
#include <claw/exception.hpp>
//********************** targa::writer::file_output_buffer *********************
namespace claw
{
namespace graphic
{
/*------------------------------------------------------------------------*/
template< >
void targa::writer::file_output_buffer<claw::graphic::rgba_pixel_8>::
order_pixel_bytes( const pixel_type& p )
{
m_stream << p.components.blue << p.components.green
<< p.components.red << p.components.alpha;
} // targa::writer::file_output_buffer::order_pixel_bytes()
} // namespace graphic
} // namespace claw
//************************** targa::writer::writer *****************************
/*----------------------------------------------------------------------------*/
claw::graphic::targa::writer::writer( const image& img )
: m_image(img)
{
} // targa::writer::writer()
/*----------------------------------------------------------------------------*/
claw::graphic::targa::writer::writer
( const image& img, std::ostream& f, bool rle )
: m_image(img)
{
save(f, rle);
} // targa::writer::writer()
/*----------------------------------------------------------------------------*/
void claw::graphic::targa::writer::save( std::ostream& os, bool rle ) const
{
header h( m_image.width(), m_image.height() );
if (rle)
h.image_type = rle_true_color;
else
h.image_type = true_color;
os.write( reinterpret_cast<char*>(&h), sizeof(header) );
if (rle)
save_rle_true_color(os);
else
save_true_color(os);
footer f;
os.write( reinterpret_cast<char*>(&f), sizeof(footer) );
} // targa::writer::save()
/*----------------------------------------------------------------------------*/
void claw::graphic::targa::writer::save_true_color( std::ostream& os ) const
{
file_output_buffer<rgba_pixel_8> output_buffer(os);
for (const_iterator it=m_image.begin(); it!=m_image.end(); ++it)
output_buffer.order_pixel_bytes(*it);
} // targa::writer::save_true_color()
/*----------------------------------------------------------------------------*/
void claw::graphic::targa::writer::save_rle_true_color( std::ostream& os ) const
{
rle32_encoder encoder;
rle32_encoder::output_buffer_type output_buffer(os);
for ( unsigned int y=0; y!=m_image.height(); ++y )
encoder.encode( m_image[y].begin(), m_image[y].end(), output_buffer );
} // targa::writer::save_rle_true_color()
claw::graphic::targa::file_structure::header
Header of a targa file.
Definition: targa.hpp:76
claw::graphic::targa::writer::save
void save(std::ostream &f, bool rle) const
Save the content of the image in a stream.
Definition: targa_writer.cpp:98
claw::graphic::image::end
iterator end()
Get an iterator pointing just past the last pixel.
Definition: image.cpp:177
claw::graphic::image::height
unsigned int height() const
Gets image&#39;s height.
Definition: image.cpp:159
claw::graphic::targa::writer::rle_targa_encoder
RLE encoder for targa format.
Definition: targa.hpp:464
claw::graphic::image::base_iterator
Base class for iterators on an image.
Definition: image.hpp:106
claw::graphic::targa::file_structure::header::image_type
char image_type
Image type.
Definition: targa.hpp:88
claw::graphic::image::width
unsigned int width() const
Gets image&#39;s width.
Definition: image.cpp:147
claw::graphic::targa::writer::file_output_buffer::order_pixel_bytes
void order_pixel_bytes(const pixel_type &p)
Write a pixel in the stream and set its value in the good order.
exception.hpp
A simple class to use as exception with string message.
claw::graphic::targa::writer::writer
writer(const image &img)
Constructor.
Definition: targa_writer.cpp:72
claw::graphic::targa::writer::file_output_buffer::pixel_type
Pixel pixel_type
The type of the pixels in the input buffer.
Definition: targa.hpp:426
claw::graphic::image::begin
iterator begin()
Get an iterator pointing on the first pixel.
Definition: image.cpp:168
claw::graphic::image
A class to deal with images.
Definition: image.hpp:49
targa.hpp
A class for targa pictures.
claw
This is the main namespace.
Definition: algorithm.hpp:33
claw::graphic::targa::writer::file_output_buffer
The type of the output buffer associated with the file when encoding RLE data.
Definition: targa.hpp:422