This file is indexed.

/usr/include/gnash/GnashImage.h is in gnash-dev 0.8.11~git20160109-1build1.

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
// GnashImage.h: Base class for reading image data in Gnash.
// 
//   Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
//   Free Software Foundation, Inc
// 
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version.
// 
// This program 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 General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
//

// The GnashImage class and subclasses are partly based on the public domain
// work of Thatcher Ulrich <tu@tulrich.com> 2002

#ifndef GNASH_GNASHIMAGE_H
#define GNASH_GNASHIMAGE_H

#include <boost/noncopyable.hpp>
#include <cstdint>
#include <memory> 

#include "GnashEnums.h"
#include "log.h"
#include "dsodefs.h"

// Forward declarations
namespace gnash {
    class IOChannel;
}

namespace gnash {

/// Image handling functions and classes.
namespace image {

/// The types of images handled in Gnash.
enum ImageType
{
    GNASH_IMAGE_INVALID,
    TYPE_RGB,
    TYPE_RGBA
};

/// The locations of images handled in Gnash.
enum ImageLocation
{
    GNASH_IMAGE_CPU = 1,
    GNASH_IMAGE_GPU
};

inline size_t
numChannels(ImageType t)
{
    switch (t) {
        case TYPE_RGBA:
            return 4;
        case TYPE_RGB:
            return 3;
        default:
            std::abort();
    }
}

/// Base class for different types of bitmaps
//
/// 1. Bytes are packed in RGB(A) order.
/// 2. Rowstride is equal to channels * width
class DSOEXPORT GnashImage : boost::noncopyable
{
public:

    typedef std::uint8_t value_type;
    typedef std::unique_ptr<value_type[]> container_type;
    typedef value_type* iterator;
    typedef const value_type* const_iterator;

    virtual ~GnashImage() {}

    /// Return the ImageType of the image.
    //
    /// This saves guessing when dynamic_cast is used.
    ImageType type() const {
        return _type;
    }

    /// Return the ImageLocation of the image.
    //
    /// This saves guessing when dynamic_cast is used.
    ImageLocation location() const {
        return _location;
    }

    /// Get the size of the image buffer
    //
    /// @return     The size of the buffer in bytes
    size_t size() const {
        return stride() * _height;
    }

    /// Get the pitch of the image buffer
    //
    /// @return     The rowstride of the buffer in bytes
    virtual size_t stride() const {
        return _width * channels();
    }

    /// Get the number of channels
    //
    /// @return     The number of channels
    size_t channels() const {
        return numChannels(_type);
    }

    /// Get the image's width
    //
    /// @return     The image's width in pixels.
    size_t width() const {
        return _width;
    }

    /// Get the image's width
    //
    /// @return     The image's height in pixels.
    size_t height() const {
        return _height;
    }

    /// Copy image data from a buffer.
    //
    /// Note that this buffer MUST have the same rowstride and type, or
    /// unexpected things will happen. In general, it is only safe to copy
    /// from another GnashImage or unexpected things will happen. 
    ///
    /// @param data     buffer to copy data from.
    void update(const_iterator data);

    /// Copy image data from another image data
    //
    /// Note that this buffer must have the same rowstride and type
    ///
    /// @param from     image to copy data from.
    void update(const GnashImage& from);
    
    /// Access the raw data.
    virtual iterator begin() {
        return _data.get();
    }

    /// Access the raw data
    virtual const_iterator begin() const {
        return _data.get();
    }

    /// An iterator to the end of the data.
    iterator end() {
        return begin() + size();
    }

    /// An iterator to the end of the data.
    const_iterator end() const {
        return begin() + size();
    }

protected:

    /// Construct a GnashImage from a data buffer, taking ownership of the data.
    //
    /// @param data     The raw image data. This class takes ownership.
    /// @param width    The width of the image in pixels.
    /// @param height   The height of the image in pixels.
    /// @param pitch    The pitch (rowstride) of the image in bytes.
    /// @param type     The ImageType of the image.
    GnashImage(iterator data, size_t width, size_t height, ImageType type,
            ImageLocation location = GNASH_IMAGE_CPU);

    /// Construct an empty GnashImage
    //
    /// Note: there is an arbitrary limit of std::int32_t::max bytes for the
    /// total size of the bitmap constructed with this constructor.
    //
    /// @param width    The width of the image in pixels.
    /// @param height   The height of the image in pixels.
    /// @param type     The ImageType of the image.
    GnashImage(size_t width, size_t height, ImageType type,
               ImageLocation location = GNASH_IMAGE_CPU);

    /// The type of the image: RGBA or RGB.
    const ImageType _type;

    /// Image data location (CPU or GPU)
    const ImageLocation _location;

    /// Width of image, in pixels
    const size_t _width;

    /// Height of image, in pixels
    const size_t _height;

    /// Data if held in this class
    container_type _data;

};

/// 24-bit RGB bitmap
//
/// Channels are in RGB order.
class DSOEXPORT ImageRGB : public GnashImage
{
public:

    /// Create an empty RGB image with uninitialized data.
    ImageRGB(size_t width, size_t height);

    /// Create an ImageRGB taking ownership of the data.
    ImageRGB(iterator data, size_t width, size_t height)
        :
        GnashImage(data, width, height, TYPE_RGB)
    {}

    virtual ~ImageRGB();
};

/// 32-bit RGBA bitmap
//
/// Channels are in RGBA order.
class DSOEXPORT ImageRGBA : public GnashImage
{

public:

    /// Create an empty RGB image with uninitialized data.
    ImageRGBA(size_t width, size_t height);

    ImageRGBA(iterator data, size_t width, size_t height)
        :
        GnashImage(data, width, height, TYPE_RGBA)
    {}
    
    ~ImageRGBA();

    /// Set pixel value 
    //
    /// TODO: move in base class ?
    ///
    void setPixel(size_t x, size_t y, value_type r, value_type g, value_type b,
            value_type a);
};

/// The base class for reading image data. 
class Input : boost::noncopyable
{
public:

    /// Construct an Input object to read from an IOChannel.
    //
    /// @param in   The stream to read data from. Ownership is shared
    ///             between caller and Input, so it is freed
    ///             automatically when the last owner is destroyed.
    Input(std::shared_ptr<IOChannel> in)
        :
        _inStream(in),
        _type(GNASH_IMAGE_INVALID)
    {}

    virtual ~Input() {}

    /// Begin processing the image data.
    virtual void read() = 0;

    /// Get the image's height in pixels.
    //
    /// @return     The height of the image in pixels.
    virtual size_t getHeight() const = 0;

    /// Get the image's width in pixels.
    //
    /// @return     The width of the image in pixels.
    virtual size_t getWidth() const = 0;

    /// Get number of components (channels)
    //
    /// @return     The number of components, e.g. 3 for RGB
    virtual size_t getComponents() const = 0;

    /// Read a scanline's worth of image data into the given buffer.
    //
    /// @param rgbData  The buffer for writing raw RGB data to.
    virtual void readScanline(unsigned char* rgbData) = 0;

    /// Get the ImageType of the image.
    //
    /// @return The type of the image. This is GNASH_IMAGE_INVALID
    ///         at least until read() has been called and reads some
    ///         valid data.
    ImageType imageType() { return _type; }

    /// \brief
    /// For reading SWF JPEG3-style image data, like ordinary JPEG, 
    /// but stores the data in ImageRGBA format.
    DSOEXPORT static std::unique_ptr<ImageRGBA> readSWFJpeg3(
            std::shared_ptr<gnash::IOChannel> in);

    /// Read image data from an IOChannel into an GnashImage.
    //
    /// @param in   The IOChannel to read the image from.
    /// @param type The type of image to read.
    /// @return     An GnashImage with the read image data. If type
    ///             is an unsupported FileType or image reading fails,
    ///             a NULL unique_ptr is returned.
    DSOEXPORT static std::unique_ptr<GnashImage> readImageData(
            std::shared_ptr<gnash::IOChannel> in, FileType type);

protected:

    std::shared_ptr<IOChannel> _inStream;

    ImageType _type;

};

// Base class for writing image data.
class Output : boost::noncopyable
{

public:

    /// Construct an Output for writing to an IOChannel
    //
    /// @param out      The gnash::IOChannel to write the image to. Ownership
    ///                 is shared.
    /// @param width    The width of the resulting image
    /// @param height   The height of the resulting image.
    Output(std::shared_ptr<IOChannel> out, size_t width, size_t height)
        :
        _width(width),
        _height(height),
        _outStream(out)
    {}

    virtual ~Output() {}
    
    /// Write RGB image data using the parameters supplied at construction.
    //
    /// @param rgbData  The raw RGB image data to write as an image.
    virtual void writeImageRGB(const unsigned char* rgbData) = 0;
    
    /// Write RGBA image data using the parameters supplied at construction.
    //
    /// @param rgbaData  The raw RGBA image data to write as an image.
    virtual void writeImageRGBA(const unsigned char* /*rgbaData*/)
    {
        log_error(_("This image format does not support writing RGBA images"));
    }

    /// Write the given image to the given IOChannel in a specified format.
    //
    /// @param type     The image format to write in (see GnashEnums.h)
    /// @param out      The IOChannel to write to.
    /// @param image    The image to write.
    /// @param quality  The quality of the image output, from 0..100. Values
    ///                 outside this range will be clamped to the minimum or
    ///                 maxium value. The quality is not used for all
    ///                 formats.
    DSOEXPORT static void writeImageData(FileType type,
            std::shared_ptr<gnash::IOChannel> out, const GnashImage& image,
            int quality);

protected:

    const size_t _width;

    const size_t _height;
    
    std::shared_ptr<IOChannel> _outStream;

};

/// Get a pointer to a given row of any image.
//
/// @param row    The index of the required row.
/// @return     A pointer to the first byte of the specified row.
inline GnashImage::iterator
scanline(GnashImage& im, size_t row)
{
    assert(row < im.height());
    return im.begin() + im.stride() * row;
}

/// Get a read-only pointer to a given row of any image.
//
/// @param y    The index of the required row.
/// @return     A read-only pointer to the first byte of the specified row.
inline GnashImage::const_iterator
scanline(const GnashImage& im, size_t row)
{
    assert(row < im.height());
    return im.begin() + im.stride() * row;
}

DSOEXPORT void mergeAlpha(ImageRGBA& im, GnashImage::const_iterator alphaData,
        const size_t bufferLength);

} // namespace image
} // namespace gnash

#endif