targa_writer.cpp

Go to the documentation of this file.
00001 /*
00002   CLAW - a C++ Library Absolutely Wonderful
00003 
00004   CLAW is a free library without any particular aim but being useful to 
00005   anyone.
00006 
00007   Copyright (C) 2005-2008 Julien Jorge
00008 
00009   This library is free software; you can redistribute it and/or
00010   modify it under the terms of the GNU Lesser General Public
00011   License as published by the Free Software Foundation; either
00012   version 2.1 of the License, or (at your option) any later version.
00013 
00014   This library is distributed in the hope that it will be useful,
00015   but WITHOUT ANY WARRANTY; without even the implied warranty of
00016   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017   Lesser General Public License for more details.
00018 
00019   You should have received a copy of the GNU Lesser General Public
00020   License along with this library; if not, write to the Free Software
00021   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00022 
00023   contact: julien_jorge@yahoo.fr
00024 */
00030 #include <claw/targa.hpp>
00031 #include <claw/exception.hpp>
00032 
00033 
00034 //********************** targa::writer::file_output_buffer *********************
00035 
00036 
00037 
00038 
00039 namespace claw
00040 {
00041   namespace graphic
00042   {
00043     /*------------------------------------------------------------------------*/
00050     template< >
00051     void targa::writer::file_output_buffer<claw::graphic::rgba_pixel_8>::
00052     order_pixel_bytes( const pixel_type& p )
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()
00057   } // namespace graphic
00058 } // namespace claw
00059 
00060 
00061 //************************** targa::writer::writer *****************************
00062 
00063 
00064 
00065 
00066 /*----------------------------------------------------------------------------*/
00071 claw::graphic::targa::writer::writer( const image& img )
00072   : m_image(img)
00073 {
00074 
00075 } // targa::writer::writer()
00076 
00077 /*----------------------------------------------------------------------------*/
00084 claw::graphic::targa::writer::writer
00085 ( const image& img, std::ostream& f, bool rle )
00086   : m_image(img)
00087 {
00088   save(f, rle);
00089 } // targa::writer::writer()
00090 
00091 /*----------------------------------------------------------------------------*/
00097 void claw::graphic::targa::writer::save( std::ostream& os, bool rle ) const
00098 {
00099   header h( m_image.width(), m_image.height() );
00100 
00101   if (rle)
00102     h.image_type = rle_true_color;
00103   else
00104     h.image_type = true_color;
00105 
00106   os.write( reinterpret_cast<char*>(&h), sizeof(header) );
00107 
00108   if (rle)
00109     save_rle_true_color(os);
00110   else
00111     save_true_color(os);
00112 
00113   footer f;
00114   os.write( reinterpret_cast<char*>(&f), sizeof(footer) );
00115 } // targa::writer::save()
00116 
00117 /*----------------------------------------------------------------------------*/
00122 void claw::graphic::targa::writer::save_true_color( std::ostream& os ) const
00123 {
00124   file_output_buffer<rgba_pixel_8> output_buffer(os);
00125 
00126   for (const_iterator it=m_image.begin(); it!=m_image.end(); ++it)
00127     output_buffer.order_pixel_bytes(*it);
00128 } // targa::writer::save_true_color()
00129 
00130 /*----------------------------------------------------------------------------*/
00135 void claw::graphic::targa::writer::save_rle_true_color( std::ostream& os ) const
00136 {
00137   rle32_encoder encoder;
00138   rle32_encoder::output_buffer_type output_buffer(os);
00139 
00140   for ( unsigned int y=0; y!=m_image.height(); ++y )
00141     encoder.encode( m_image[y].begin(), m_image[y].end(), output_buffer );
00142 } // targa::writer::save_rle_true_color()

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