initialize validbounds on ::init, log_debug sizes
[gnash.git] / libbase / GnashImageGif.h
blob982478da3d86cc2685d1deaed7378e85f9436a6e
1 // GnashImageGif.h: gif_lib wrapper for Gnash.
2 //
3 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Free Software
4 // Foundation, Inc
5 //
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 3 of the License, or
9 // (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 #ifndef GNASH_IMAGE_GIF_H
22 #define GNASH_IMAGE_GIF_H
24 #include <memory>
26 #include "dsodefs.h"
27 #include "GnashImage.h"
28 #include <boost/scoped_array.hpp>
29 #include <boost/shared_ptr.hpp>
31 extern "C" {
32 #include <gif_lib.h>
35 // Forward declarations
36 namespace gnash { class IOChannel; }
38 namespace gnash {
39 namespace image {
41 class GifInput : public Input
44 public:
46 /// Construct a GifInput object to read from an IOChannel.
48 /// @param in The stream to read GIF data from. Ownership is shared
49 /// between caller and GifInput, so it is freed
50 /// automatically when the last owner is destroyed.
51 GifInput(boost::shared_ptr<IOChannel> in);
53 ~GifInput();
55 /// Begin processing the image data.
56 void read();
58 /// Get the image's height in pixels.
60 /// @return The height of the image in pixels.
61 size_t getHeight() const;
63 /// Get the image's width in pixels.
65 /// @return The width of the image in pixels.
66 size_t getWidth() const;
68 /// Get number of components (channels)
70 /// @return The number of components, e.g. 3 for RGB
71 size_t getComponents() const { return 3; }
73 /// Read a scanline's worth of image data into the given buffer.
75 /// The amount of data read is getWidth() * getComponents().
76 ///
77 /// @param rgbData The buffer for writing raw RGB data to.
78 void readScanline(unsigned char* rgb_data);
80 /// Create a GifInput and transfer ownership to the caller.
82 /// @param in The IOChannel to read GIF data from.
83 DSOEXPORT static std::auto_ptr<Input> create(
84 boost::shared_ptr<IOChannel> in)
86 std::auto_ptr<Input> ret(new GifInput(in));
87 if (ret.get()) ret->read();
88 return ret;
91 private:
93 /// Initialize gif_lib
94 void init();
96 /// Process a single image record
98 /// @return false if no image was parsed, true if we have an image.
99 bool processRecord(GifRecordType record);
101 // State needed for input.
102 GifFileType* _gif;
104 // A counter for keeping track of the last row copied.
105 size_t _currentRow;
107 typedef boost::scoped_array<GifPixelType> PixelRow;
109 // A 2-dimensional scoped array holding the unpacked pixel data.
110 boost::scoped_array<PixelRow> _gifData;
116 } // namespace image
117 } // namespace gnash
120 #endif