/usr/include/claw/impl/targa_writer.tpp is in libclaw-graphic-dev 1.7.3-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 | /*
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
*/
/**
* \file targa_writer.tpp
* \brief Implementation of the template methods of the targa::writer class and
* subclasses.
* \author Julien Jorge
*/
#include <limits>
#include <iterator>
//********************* targa::writer::file_output_buffer **********************
/*----------------------------------------------------------------------------*/
/**
* \brief Constructor.
* \param os The
*/
template<typename Pixel>
claw::graphic::targa::writer::file_output_buffer<Pixel>::file_output_buffer
( std::ostream& os )
: m_stream(os)
{
} // targa::writer::file_output_buffer::file_output_buffer()
/*----------------------------------------------------------------------------*/
/**
* \brief Code a pixel.
* \param n The number of time the pixel appears.
* \param pattern The value of the pixel.
*/
template<typename Pixel>
void claw::graphic::targa::writer::file_output_buffer<Pixel>::encode
( unsigned int n, pattern_type pattern )
{
assert( n <= max_encodable() );
assert( n >= min_interesting() );
unsigned char key = (n-1) | 0x80;
m_stream << key;
order_pixel_bytes( pattern );
} // targa::writer::file_output_buffer::encode()
/*----------------------------------------------------------------------------*/
/**
* \brief Write raw data int the stream.
* \param first Iterator on the first data.
* \param last Iterator past the last data.
*/
template<typename Pixel>
template<typename Iterator>
void claw::graphic::targa::writer::file_output_buffer<Pixel>::raw
( Iterator first, Iterator last )
{
unsigned int n = std::distance(first, last);
unsigned int full = n / max_encodable();
unsigned int remaining = n % max_encodable();
unsigned char key = max_encodable() - 1;
for (unsigned int i=0; i!=full; ++i)
{
m_stream << key;
for (unsigned int j=0; j!=max_encodable(); ++j, ++first)
order_pixel_bytes( *first );
}
if (remaining)
{
key = remaining - 1;
m_stream << key;
for (unsigned int j=0; j!=remaining; ++j, ++first)
order_pixel_bytes( *first );
}
} // targa::writer::file_output_buffer::raw()
/*----------------------------------------------------------------------------*/
/**
* \brief Get the minimum number of pixels needed for encoding.
*/
template<typename Pixel>
unsigned int
claw::graphic::targa::writer::file_output_buffer<Pixel>::min_interesting() const
{
return 2;
} // targa::writer::file_output_buffer::min_interesting()
/*----------------------------------------------------------------------------*/
/**
* \brief Get the maximum number of pixel a code can encode.
*/
template<typename Pixel>
unsigned int
claw::graphic::targa::writer::file_output_buffer<Pixel>::max_encodable() const
{
return 0x80;
} // targa::writer::file_output_buffer::max_encodable()
|