Claw  1.7.3
targa_writer.tpp
Go to the documentation of this file.
1 /*
2  CLAW - a C++ Library Absolutely Wonderful
3 
4  CLAW is a free library without any particular aim but being useful to
5  anyone.
6 
7  Copyright (C) 2005-2011 Julien Jorge
8 
9  This library is free software; you can redistribute it and/or
10  modify it under the terms of the GNU Lesser General Public
11  License as published by the Free Software Foundation; either
12  version 2.1 of the License, or (at your option) any later version.
13 
14  This library is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  Lesser General Public License for more details.
18 
19  You should have received a copy of the GNU Lesser General Public
20  License along with this library; if not, write to the Free Software
21  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 
23  contact: julien.jorge@gamned.org
24 */
31 #include <limits>
32 #include <iterator>
33 
34 
35 //********************* targa::writer::file_output_buffer **********************
36 
37 
38 
39 
40  /*----------------------------------------------------------------------------*/
45 template<typename Pixel>
47 ( std::ostream& os )
48  : m_stream(os)
49 {
50 
51 } // targa::writer::file_output_buffer::file_output_buffer()
52 
53 /*----------------------------------------------------------------------------*/
59 template<typename Pixel>
61 ( unsigned int n, pattern_type pattern )
62 {
63  assert( n <= max_encodable() );
64  assert( n >= min_interesting() );
65 
66  unsigned char key = (n-1) | 0x80;
67 
68  m_stream << key;
69  order_pixel_bytes( pattern );
70 } // targa::writer::file_output_buffer::encode()
71 
72 /*----------------------------------------------------------------------------*/
78 template<typename Pixel>
79 template<typename Iterator>
81 ( Iterator first, Iterator last )
82 {
83  unsigned int n = std::distance(first, last);
84 
85  unsigned int full = n / max_encodable();
86  unsigned int remaining = n % max_encodable();
87 
88  unsigned char key = max_encodable() - 1;
89 
90  for (unsigned int i=0; i!=full; ++i)
91  {
92  m_stream << key;
93 
94  for (unsigned int j=0; j!=max_encodable(); ++j, ++first)
95  order_pixel_bytes( *first );
96  }
97 
98  if (remaining)
99  {
100  key = remaining - 1;
101  m_stream << key;
102 
103  for (unsigned int j=0; j!=remaining; ++j, ++first)
104  order_pixel_bytes( *first );
105  }
106 
107 } // targa::writer::file_output_buffer::raw()
108 
109 /*----------------------------------------------------------------------------*/
113 template<typename Pixel>
114 unsigned int
116 {
117  return 2;
118 } // targa::writer::file_output_buffer::min_interesting()
119 
120 /*----------------------------------------------------------------------------*/
124 template<typename Pixel>
125 unsigned int
127 {
128  return 0x80;
129 } // targa::writer::file_output_buffer::max_encodable()