This file is indexed.

/usr/include/claw/gif.hpp is in libclaw-graphic-dev 1.7.0-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
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
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
/*
  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 gif.hpp
 * \brief Image class for gif files.
 * \author Julien Jorge
 */
#ifndef __CLAW_GIF_HPP__
#define __CLAW_GIF_HPP__

#include <claw/color_palette.hpp>
#include <claw/functional.hpp>
#include <claw/image.hpp>
#include <claw/iterator.hpp>
#include <claw/lzw_decoder.hpp>
#include <claw/types.hpp>

#include <list>

namespace claw
{
  namespace graphic
  {
    /**
     * \brief A class for gif pictures.
     * \author Julien Jorge
     */
    class gif:
      public image
    {
    public:
      /** \brief One frame in the animation. */
      class frame:
        public image
      {
      public:
        /** \brief The type of the parent class. */
        typedef image super;

      public:
        frame();
        frame( std::size_t w, std::size_t h );

        void set_delay(unsigned int d);
        unsigned int get_delay() const;

      private:
        /** \brief Hundredths of a seconds to wait before continuing with the
            next frame. */
        unsigned int m_delay;

      }; // class frame

    private:
      /** \brief A list of frame stored in the gif. */
      typedef std::list<frame*> frame_list;

      /** \brief The type of the parent class. */
      typedef image super;

    public:
      /** \brief Iterator on the content of the gif. */
      typedef wrapped_iterator
      < frame,
        frame_list::iterator,
        claw::dereference<frame> >::iterator_type frame_iterator;

      /** \brief Iterator on the content of the gif. */
      typedef wrapped_iterator
      < const frame,
        frame_list::const_iterator,
        claw::const_dereference<frame> >::iterator_type const_frame_iterator;

    private:
#pragma pack(push, 1)

      /** \brief Header of the gif files. */
      struct header
      {
        /** \brief Signature of the format. */
        u_int_8 signature[3];

        /** \brief Version of the gif format. */
        u_int_8 version[3];

      }; // struct header

      /** \brief Some informations on the screen where the image is rendered. */
      struct screen_descriptor
      {
      public:
        bool has_global_color_table() const;
        unsigned int color_palette_size() const;

      public:
        /** \brief Logical screen width. */
        u_int_16 screen_width;

        /** \brief Logical screen height. */
        u_int_16 screen_height;

        /** \brief Some flags. */
        u_int_8 packed;

        /** \brief Background color index. */
        u_int_8 background_color;

        /** \brief Pixel aspect ratio. */
        u_int_8 aspect_ratio;

      }; // struct screen_descriptor

      /** Description of an image in the file. */
      struct image_descriptor
      {
      public:
        /** \brief Identifier of the block. */
        static const u_int_8 block_id = 0x2C;

      public:
        bool has_color_table() const;
        bool is_interlaced() const;
        unsigned int color_palette_size() const;

      public:
        /** \brief Left position in the logical screen. */
        u_int_16 left;

        /** \brief Top position in the logical screen. */
        u_int_16 top;

        /** \brief Width of the image. */
        u_int_16 width;

        /** \brief Height of the image. */
        u_int_16 height;

        /** \brief Some flags. */
        u_int_8 packed;

      }; // struct image_descriptor

      /** \brief Extension of the format. */
      struct extension
      {
        /** \brief Identifier of the block. */
        static const u_int_8 block_id = 0x21;

        // no field
      }; // struct extension

      /** \brief The end of the file. */
      struct trailer
      {
        /** \brief Identifier of the block. */
        static const u_int_8 block_id = 0x3B;

        // no field
      }; // trailer

      /** \brief Extension describing a rendering block. */
      struct graphic_control_extension
      {
      public:
        /** \brief Identifier of the extension. */
        static const u_int_8 block_label = 0xF9;

        /** \brief Tell how to initialise the canvas before rendering a
            frame. */
        enum disposal_method
        {
          /** \brief No disposal specified. The decoder is not required to
              take any action. */
          dispose_none,

          /** \brief Do not dispose. The graphic is to be left in place. */
          dispose_do_not_dispose,

          /** \brief Restore to background color. The area used by the graphic
              must be restored to the background color. */
          dispose_background,

          /** \brief Restore to previous. The decoder is required to restore
              the area overwritten by the graphic with what was there prior to
              rendering the graphic. */
          dispose_previous

        }; // enum disposal_method

      public:
        disposal_method get_disposal_method() const;
        bool has_transparent_color() const;

      public:
        /** \brief Number of bytes in the block. */
        u_int_8 block_size;

        /** \brief Some flags. */
        u_int_8 packed;

        /** \brief Hundredths of a second to wait before continuing. */
        u_int_16 delay;

        /** \brief Index of the transparent color in the palette. */
        u_int_8 transparent_color;

        /** \brief Block terminator. */
        u_int_8 terminator;

      }; // struct graphic_control_extension

      /** \brief Extension commenting the file. */
      struct comment_extension
      {
      public:
        /** \brief Identifier of the extension. */
        static const u_int_8 block_label = 0xFE;

      public:
        // this block is ignored.

      }; // struct comment_extension

      /** \brief Extension adding graphic text support. */
      struct plain_text_extension
      {
      public:
        /** \brief Identifier of the extension. */
        static const u_int_8 block_label = 0x01;

      public:
        // this block is ignored.

      }; // struct plain_text_extension

      /** \brief Extension adding some informations about the application. */
      struct application_extension
      {
      public:
        /** \brief Identifier of the extension. */
        static const u_int_8 block_label = 0xFF;

      public:
        // this block is ignored.

      }; // struct application_extension
#pragma pack(pop)

    public:
      /*----------------------------------------------------------------------*/
      /**
       * \brief This class reads data from a gif file. The image is resized to
       *        the size of the screen (as defined in the gif file) and the
       *        frames are stored in a list of frames passed as parameter.
       * \author Julien Jorge
       */
      class reader
      {
      private:
        /** \brief The type of the color palettes in the file. */
        typedef color_palette<rgb_pixel> palette_type;

        /** \brief Some global data needed when reading the file. */
        struct reader_info
        {
          /** \brief Description of the screen. */
          screen_descriptor sd;

          /** \brief The global palette. */
          palette_type* palette;

          /** \brief The index of the transparent color for the current frame.*/
          int transparent_color_index;

          /** \brief The disposal method of the frames. */
          std::vector<graphic_control_extension::disposal_method>
          disposal_method;

        }; // struct reader_info

        /** \brief The buffer passed to the LZW decoder to decode the input. */
        class input_buffer
        {
        public:
          input_buffer( std::istream& is, u_int_8 code_size );

          bool end_of_data() const;
          bool end_of_information() const;
          unsigned int symbols_count() const;
          unsigned int get_next();

          void reset();
          void new_code( unsigned int code );

        private:
          void fill_buffer();

        private:
          /** \brief The last value read from the input. */
          unsigned int m_val;

          /** \brief The input data. */
          std::istream& m_input;

          /**
           * \brief Encoded data read from the stream.
           *
           * A data block is 255 bytes long, maximum. But we may have to keep up
           * to 12 bits from the previous block. So we need two more bytes.
           */
          char m_buffer[257];

          /** \brief The position of the next byte to read in \a m_buffer. */
          std::size_t m_pending;

          /** \brief The number of available bits in m_buffer[m_pending]. */
          unsigned char m_pending_bits;

          /** \brief The end of the data in \a m_buffer; */
          std::size_t m_pending_end;

          /** \brief The length of the next data block. */
          u_int_8 m_next_data_length;

          /** \brief The initial size of the codes. */
          const unsigned int m_initial_code_size;

          /** \brief The current size of the codes. */
          unsigned int m_code_size;

          /** \brief The maximum code allowed with the current code size. */
          unsigned int m_code_limit;

        }; // class input_buffer

        /** \brief Buffer passed to the LZW decoder to write decoded data. */
        class output_buffer
        {
        public:
          output_buffer
          ( const palette_type& p, const image_descriptor& id,
            int transparent_color_index, image& output );

          void write( unsigned int code );

        private:
          /** \brief The palette from whick we take the colors of the image. */
          const palette_type& m_palette;

          /** \brief The image descriptor of the frame. */
          const image_descriptor& m_id;

          /** \brief The index of the transparent color. -1 if none. */
          const int m_transparent_color_index;

          /** \brief The image in which we save the decoded data. */
          image& m_output;

          /** \brief The x-position of the next pixel in the image. */
          std::size_t m_x;

          /** \brief The y-position of the next pixel in the image. */
          std::size_t m_y;

          /** \brief Current pass in an interlaced image [0-3]. */
          int m_interlace_pass;

          /** \brief Increment in the current pass of an interlaced image. */
          int m_interlace_step;

        }; // class output_buffer

        /** \brief LZW decoder for the GIF data. */
        typedef claw::lzw_decoder<input_buffer, output_buffer> gif_lzw_decoder;

      public:
        reader( image& img );
        reader( image& img, std::istream& f );
        reader( frame_list& frames, std::istream& f );
        reader( image& img, frame_list& frames, std::istream& f );
        ~reader();

        void load( std::istream& f );

      private:
        void clear();
        void inside_load( std::istream& f );
        void make_frames( const reader_info& info );
        void fill_background( image& img, const reader_info& info ) const;

        void check_if_gif( std::istream& f ) const;
        void read_screen_descriptor( std::istream& f, reader_info& info );

        void read_palette( std::istream& f, palette_type& p ) const;
        void read_data( std::istream& f, reader_info& info );
        void read_frame( std::istream& f, reader_info& info );
        void read_frame_with_gce( std::istream& f, reader_info& info );

        void skip_extension( std::istream& f ) const;
        void read_frame_data
        ( std::istream& f, const reader_info& info, frame& the_frame ) const;

        void decode_data
        ( std::istream& f, const palette_type& palette,
          const image_descriptor& id, int transparent_color_index,
          frame& the_frame ) const;

      private:
        /** \brief The gif file on which we work. */
        image* m_image;

        /** \brief The images in which we store the data we read. */
        frame_list m_frame;

      }; // class reader

    public:
      gif();
      gif( const gif& that );
      gif( std::istream& f );
      ~gif();

      gif& operator=( const gif& that );
      void swap( gif& that );

      frame_iterator frame_begin();
      frame_iterator frame_end();
      const_frame_iterator frame_begin() const;
      const_frame_iterator frame_end() const;

    private:
      /** \brief The list of frames in the animation. */
      frame_list m_frame;

    }; // class gif
  } // namespace graphic
} // namespace claw

namespace std
{
  void swap( claw::graphic::gif& a, claw::graphic::gif& b );
} // namespace std

#endif // __CLAW_GIF_HPP__