This file is indexed.

/usr/include/claw/impl/targa_reader.tpp is in libclaw-graphic-dev 1.7.3-1+b2.

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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
/*
  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_reader.tpp
 * \brief Implementation of the template methods of the targa::reader class and
 *        subclasses.
 * \author Julien Jorge
 */
#include <limits>
#include <iterator>

/*----------------------------------------------------------------------------*/
/**
 * \brief Constructor.
 * \param f The file to read.
 */
template< typename Pixel >
claw::graphic::targa::reader::file_input_buffer<Pixel>::file_input_buffer
( std::istream& f )
  : buffered_istream<std::istream>(f)
{
  
} // targa::reader::file_input_buffer::file_input_buffer




//*****************************************************************************/




/*----------------------------------------------------------------------------*/
/**
 * \brief Constructor.
 * \param f The file to read.
 * \param p The color palette.
 */
template< typename Pixel >
claw::graphic::targa::reader::mapped_file_input_buffer<Pixel>::
mapped_file_input_buffer
( std::istream& f, const color_palette32& p )
  : buffered_istream<std::istream>(f), m_palette(p)
{
  
} // targa::reader::mapped_file_input_buffer::mapped_file_input_buffer




//*****************************************************************************/




/*----------------------------------------------------------------------------*/
/**
 * \brief Constructor.
 * \param img The targa image we're loading.
 * \param up_down Tell if the image is stored from top to bottom.
 * \param left_right Tell if the image is stored from left to right.
 */
template<typename InputBuffer>
claw::graphic::targa::reader::rle_targa_output_buffer<InputBuffer>::
rle_targa_output_buffer( image& img, bool up_down, bool left_right )
  : m_image(img), m_x_inc(left_right ? 1 : -1), m_y_inc(up_down ? 1 : -1)
{
  if (up_down)
    m_y = 0;
  else
    m_y = m_image.height() - 1;

  if (left_right)
    m_x = 0;
  else
    m_x = m_image.width() - 1;
} // targa::reader::rle_targa_output_buffer::rle_targa_output_buffer()

/*----------------------------------------------------------------------------*/
/**
 * \brief Copy a pixel a certain number of times.
 * \param n The number of pixel to write.
 * \param pattern The pixel to copy.
 */
template<typename InputBuffer>
void claw::graphic::targa::reader::rle_targa_output_buffer<InputBuffer>::fill
( unsigned int n, rgba_pixel_8 pattern )
{
  assert( (int)(m_x + m_x_inc * n) >= -1 );
  assert( m_x + m_x_inc * n <= m_image.width() );

  const int bound = (int)m_x + m_x_inc * n;
  int x = m_x;

  for ( ; x != bound; x += m_x_inc )
    m_image[m_y][x] = pattern;

  adjust_position(x);
} // targa::reader::rle_targa_output_buffer::fill()

/*----------------------------------------------------------------------------*/
/**
 * \brief Direct copy of a certain number of pixels from the file.
 * \param n The number of pixels to write.
 * \param buffer The buffer from which we read.
 */
template<typename InputBuffer>
void claw::graphic::targa::reader::rle_targa_output_buffer<InputBuffer>::copy
( unsigned int n, input_buffer_type& buffer )
{
  assert( (int)(m_x + m_x_inc * n) >= -1 );
  assert( m_x + m_x_inc * n <= m_image.width() );

  const int bound = (int)m_x + m_x_inc * n;
  int x = m_x;

  for ( ; x != bound; x += m_x_inc )
    m_image[m_y][x] = buffer.get_pixel();

  adjust_position(x);
} // targa::reader::rle_targa_output_buffer::copy()

/*----------------------------------------------------------------------------*/
/**
 * \brief Tell if we have completely filled the image.
 */
template<typename InputBuffer>
bool claw::graphic::targa::reader::rle_targa_output_buffer<InputBuffer>::
completed() const
{
  return ( (int)m_y == -1 ) || ( m_y == m_image.height() );
} // targa::reader::rle_targa_output_buffer::completed()

/*----------------------------------------------------------------------------*/
/**
 * \brief Recalculate the position in the file.
 * \param x The x-coordinate where we stopped.
 *
 * If \a x is lower tha zero, the position is set at the end of the previous
 * line ; if \a is greater or equal to the width of the image, the position is
 * set at the begining of the next line ; otherwise the position is set to \a x.
 */
template<typename InputBuffer>
void
claw::graphic::targa::reader::rle_targa_output_buffer<InputBuffer>::
adjust_position(int x)
{
  if (x < 0)
    {
      m_x = m_image.width() - 1;
      m_y += m_y_inc;
    }
  else if (x >= (int)m_image.width())
    {
      m_x = 0;
      m_y += m_y_inc;
    }
  else
    m_x = x;
} // targa::reader::rle_targa_output_buffer::adjust_position()



//*****************************************************************************/



/*----------------------------------------------------------------------------*/
/**
 * \brief Get the type of the following data in the input buffer.
 * \param input The input stream (the targa file).
 * \param output The output stream (the targa image).
 */
template< typename InputBuffer, typename OutputBuffer >
void
claw::graphic::targa::reader::rle_targa_decoder<InputBuffer, OutputBuffer>::
read_mode( input_buffer_type& input, output_buffer_type& output )
{
  this->m_mode = this->stop;
  bool ok = !output.completed();

  if ( ok && (input.remaining() < 1) )
    ok = input.read_more(1);

  if (ok)
    {
      char key = input.get_next();

      this->m_count = (key & 0x7F) + 1;

      if (key & 0x80) // compressed
        {
          this->m_mode = this->compressed;
          this->m_pattern = input.get_pixel();
        }
      else
        this->m_mode = this->raw;
    }
} // targa::reader::rle_targa_decoder::read_mode()



//*****************************************************************************/


/*----------------------------------------------------------------------------*/
/**
 * \brief Load an uncompressed true color targa file.
 * \param h File's header, must have been read before call.
 * \param f Targa file.
 * \param palette The color palette of the image.
 * \pre f.is_open()
 */
template<typename Pixel>
void claw::graphic::targa::reader::load_color_mapped_raw
( const header& h, std::istream& f, const color_palette32& palette )
{
  /* We use a part of the rle framework but there isn't any compressed data
     here. We only use the direct copy of the rle algorithm. */

  typedef mapped_file_input_buffer<Pixel> input_buffer_type;

  rle_targa_output_buffer<input_buffer_type> output
    ( m_image, h.image_specification.up_down_oriented(),
      h.image_specification.left_right_oriented() );
  input_buffer_type input(f, palette);
  
  for ( unsigned int i=0; i!=m_image.height(); ++i )
    output.copy( m_image.width(), input );
} // targa::reader::load_true_color_raw()

/*----------------------------------------------------------------------------*/
/**
 * \brief Load a RLE color mapped targa file.
 * \param h File's header, must have been read before call.
 * \param f Targa file.
 * \param palette The color palette of the image.
 * \pre f.is_open()
 */
template<typename Decoder>
void claw::graphic::targa::reader::decompress_rle_color_mapped
( const header& h, std::istream& f, const color_palette32& palette )
{
  Decoder decoder;
  typename Decoder::output_buffer_type output_buffer
    (m_image, h.image_specification.up_down_oriented(),
     h.image_specification.left_right_oriented() );
  typename Decoder::input_buffer_type input_buffer(f, palette);
  
  decoder.decode(input_buffer, output_buffer);
} // targa::reader::decompress_rle_color_mapped()

/*----------------------------------------------------------------------------*/
/**
 * \brief Load an uncompressed true color targa file.
 * \param h File's header, must have been read before call.
 * \param f Targa file.
 * \pre f.is_open() && !h.color_map
 */
template<typename Pixel>
void claw::graphic::targa::reader::load_true_color_raw
( const header& h, std::istream& f )
{
  assert(!h.color_map);

  /* We use a part of the rle framework but there isn't any compressed data
     here. We only use the direct copy of the rle algorithm. */

  typedef file_input_buffer<Pixel> input_buffer_type;

  rle_targa_output_buffer<input_buffer_type> output
    ( m_image, h.image_specification.up_down_oriented(),
      h.image_specification.left_right_oriented() );
  input_buffer_type input(f);
  
  for ( unsigned int i=0; i!=m_image.height(); ++i )
    output.copy( m_image.width(), input );
} // targa::reader::load_true_color_raw()

/*----------------------------------------------------------------------------*/
/**
 * \brief Load a true color RLE targa file.
 * \param h File's header, must have been read before call.
 * \param f Targa file.
 * \pre f.is_open() && !h.color_map
 */
template<typename Decoder>
void claw::graphic::targa::reader::decompress_rle_true_color
( const header& h, std::istream& f )
{
  assert(!h.color_map);

  Decoder decoder;
  typename Decoder::output_buffer_type output_buffer
    (m_image, h.image_specification.up_down_oriented(),
     h.image_specification.left_right_oriented() );
  typename Decoder::input_buffer_type input_buffer(f);
  
  decoder.decode(input_buffer, output_buffer);
} // targa::reader::decompress_rle_true_color()

/*----------------------------------------------------------------------------*/
/**
 * \brief Load the content of the color palette.
 * \param f Targa file.
 * \param palette (out) The color palette.
 */
template<typename Pixel>
void claw::graphic::targa::reader::load_palette_content
( std::istream& f, color_palette32& palette ) const
{
  file_input_buffer<Pixel> input(f);

  for (unsigned int i=0; i!=palette.size(); ++i)
    palette[i] = input.get_pixel();
} // targa::reader::load_palette_content()