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::image::image
image()
Constructor. Creates an image without datas.
Definition image.cpp:106
claw::graphic::image::const_iterator
base_iterator< const image, const pixel_type > const_iterator
The type of the iterator to access constant pixels.
Definition image.hpp:202
claw::graphic::targa::file_structure::header
Header of a targa file.
Definition targa.hpp:77
claw::graphic::targa::file_structure::header::image_type
char image_type
Image type.
Definition targa.hpp:88
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::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.
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::targa::writer::writer
writer(const image &img)
Constructor.
Definition targa_writer.cpp:72
exception.hpp
A simple class to use as exception with string message.
claw::graphic
Everything about image structures and processing.
Definition bitmap.hpp:43
claw
This is the main namespace.
Definition algorithm.hpp:34
targa.hpp
A class for targa pictures.