Gnash  0.8.11dev
GnashImage.h
Go to the documentation of this file.
1 // GnashImage.h: Base class for reading image data in Gnash.
2 //
3 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
4 // Free Software 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
19 //
20 
21 // The GnashImage class and subclasses are partly based on the public domain
22 // work of Thatcher Ulrich <tu@tulrich.com> 2002
23 
24 #ifndef GNASH_GNASHIMAGE_H
25 #define GNASH_GNASHIMAGE_H
26 
27 #include <boost/shared_ptr.hpp>
28 #include <boost/noncopyable.hpp>
29 #include <boost/cstdint.hpp>
30 #include <boost/scoped_array.hpp>
31 #include <memory>
32 
33 #include "GnashEnums.h"
34 #include "log.h"
35 #include "dsodefs.h"
36 
37 // Forward declarations
38 namespace gnash {
39  class IOChannel;
40 }
41 
42 namespace gnash {
43 
45 namespace image {
46 
49 {
53 };
54 
57 {
60 };
61 
62 inline size_t
64 {
65  switch (t) {
66  case TYPE_RGBA:
67  return 4;
68  case TYPE_RGB:
69  return 3;
70  default:
71  std::abort();
72  }
73 }
74 
76 //
79 class DSOEXPORT GnashImage : boost::noncopyable
80 {
81 public:
82 
83  typedef boost::uint8_t value_type;
84  typedef boost::scoped_array<value_type> container_type;
85  typedef value_type* iterator;
86  typedef const value_type* const_iterator;
87 
88  virtual ~GnashImage() {}
89 
91  //
93  ImageType type() const {
94  return _type;
95  }
96 
98  //
101  return _location;
102  }
103 
105  //
107  size_t size() const {
108  return stride() * _height;
109  }
110 
112  //
114  virtual size_t stride() const {
115  return _width * channels();
116  }
117 
119  //
121  size_t channels() const {
122  return numChannels(_type);
123  }
124 
126  //
128  size_t width() const {
129  return _width;
130  }
131 
133  //
135  size_t height() const {
136  return _height;
137  }
138 
140  //
146  void update(const_iterator data);
147 
149  //
153  void update(const GnashImage& from);
154 
156  virtual iterator begin() {
157  return _data.get();
158  }
159 
161  virtual const_iterator begin() const {
162  return _data.get();
163  }
164 
167  return begin() + size();
168  }
169 
171  const_iterator end() const {
172  return begin() + size();
173  }
174 
175 protected:
176 
178  //
184  GnashImage(iterator data, size_t width, size_t height, ImageType type,
185  ImageLocation location = GNASH_IMAGE_CPU);
186 
188  //
191  //
195  GnashImage(size_t width, size_t height, ImageType type,
196  ImageLocation location = GNASH_IMAGE_CPU);
197 
200 
203 
205  const size_t _width;
206 
208  const size_t _height;
209 
212 
213 };
214 
216 //
219 {
220 public:
221 
223  ImageRGB(size_t width, size_t height);
224 
226  ImageRGB(iterator data, size_t width, size_t height)
227  :
228  GnashImage(data, width, height, TYPE_RGB)
229  {}
230 
231  virtual ~ImageRGB();
232 };
233 
235 //
238 {
239 
240 public:
241 
243  ImageRGBA(size_t width, size_t height);
244 
245  ImageRGBA(iterator data, size_t width, size_t height)
246  :
247  GnashImage(data, width, height, TYPE_RGBA)
248  {}
249 
250  ~ImageRGBA();
251 
253  //
256  void setPixel(size_t x, size_t y, value_type r, value_type g, value_type b,
257  value_type a);
258 };
259 
261 class Input : boost::noncopyable
262 {
263 public:
264 
266  //
270  Input(boost::shared_ptr<IOChannel> in)
271  :
272  _inStream(in),
274  {}
275 
276  virtual ~Input() {}
277 
279  virtual void read() = 0;
280 
282  //
284  virtual size_t getHeight() const = 0;
285 
287  //
289  virtual size_t getWidth() const = 0;
290 
292  //
294  virtual size_t getComponents() const = 0;
295 
297  //
299  virtual void readScanline(unsigned char* rgbData) = 0;
300 
302  //
306  ImageType imageType() { return _type; }
307 
311  DSOEXPORT static std::auto_ptr<ImageRGBA> readSWFJpeg3(
312  boost::shared_ptr<gnash::IOChannel> in);
313 
315  //
321  DSOEXPORT static std::auto_ptr<GnashImage> readImageData(
322  boost::shared_ptr<gnash::IOChannel> in, FileType type);
323 
324 protected:
325 
326  boost::shared_ptr<IOChannel> _inStream;
327 
329 
330 };
331 
332 // Base class for writing image data.
333 class Output : boost::noncopyable
334 {
335 
336 public:
337 
339  //
344  Output(boost::shared_ptr<IOChannel> out, size_t width, size_t height)
345  :
346  _width(width),
347  _height(height),
348  _outStream(out)
349  {}
350 
351  virtual ~Output() {}
352 
354  //
356  virtual void writeImageRGB(const unsigned char* rgbData) = 0;
357 
359  //
361  virtual void writeImageRGBA(const unsigned char* /*rgbaData*/)
362  {
363  log_error(_("This image format does not support writing RGBA images"));
364  }
365 
367  //
376  boost::shared_ptr<gnash::IOChannel> out, const GnashImage& image,
377  int quality);
378 
379 protected:
380 
381  const size_t _width;
382 
383  const size_t _height;
384 
385  boost::shared_ptr<IOChannel> _outStream;
386 
387 };
388 
390 //
394 scanline(GnashImage& im, size_t row)
395 {
396  assert(row < im.height());
397  return im.begin() + im.stride() * row;
398 }
399 
401 //
405 scanline(const GnashImage& im, size_t row)
406 {
407  assert(row < im.height());
408  return im.begin() + im.stride() * row;
409 }
410 
411 DSOEXPORT void mergeAlpha(ImageRGBA& im, GnashImage::const_iterator alphaData,
412  const size_t bufferLength);
413 
414 } // namespace image
415 } // namespace gnash
416 
417 #endif
Definition: GnashKey.h:147
const_iterator end() const
An iterator to the end of the data.
Definition: GnashImage.h:171
virtual size_t getHeight() const =0
Get the image's height in pixels.
Output(boost::shared_ptr< IOChannel > out, size_t width, size_t height)
Construct an Output for writing to an IOChannel.
Definition: GnashImage.h:344
size_t width() const
Get the image's width.
Definition: GnashImage.h:128
virtual size_t stride() const
Get the pitch of the image buffer.
Definition: GnashImage.h:114
32-bit RGBA bitmap
Definition: GnashImage.h:237
int _height
Definition: Renderer_cairo.cpp:213
FileType
Definition: GnashEnums.h:25
const size_t _height
Definition: GnashImage.h:383
ImageLocation location() const
Return the ImageLocation of the image.
Definition: GnashImage.h:100
static DSOEXPORT void writeImageData(FileType type, boost::shared_ptr< gnash::IOChannel > out, const GnashImage &image, int quality)
Write the given image to the given IOChannel in a specified format.
Definition: GnashImage.cpp:177
int _width
Definition: Renderer_cairo.cpp:212
ImageRGBA(iterator data, size_t width, size_t height)
Definition: GnashImage.h:245
Definition: GnashImage.h:51
Input(boost::shared_ptr< IOChannel > in)
Construct an Input object to read from an IOChannel.
Definition: GnashImage.h:270
const ImageLocation _location
Image data location (CPU or GPU)
Definition: GnashImage.h:202
ImageRGB(iterator data, size_t width, size_t height)
Create an ImageRGB taking ownership of the data.
Definition: GnashImage.h:226
pixel_iterator< T > begin(GnashImage &im)
Definition: ImageIterators.h:191
virtual ~GnashImage()
Definition: GnashImage.h:88
virtual iterator begin()
Access the raw data.
Definition: GnashImage.h:156
container_type _data
Data if held in this class.
Definition: GnashImage.h:211
SimpleBuffer data
Definition: LocalConnection_as.cpp:153
type
Definition: GnashKey.h:329
const size_t _width
Definition: GnashImage.h:381
Definition: klash_part.cpp:329
24-bit RGB bitmap
Definition: GnashImage.h:218
virtual ~Input()
Definition: GnashImage.h:276
const size_t _width
Width of image, in pixels.
Definition: GnashImage.h:205
size_t size() const
Get the size of the image buffer.
Definition: GnashImage.h:107
ImageType imageType()
Get the ImageType of the image.
Definition: GnashImage.h:306
Definition: GnashImage.h:52
Definition: GnashKey.h:164
Definition: GnashKey.h:166
ImageType type() const
Return the ImageType of the image.
Definition: GnashImage.h:93
Definition: klash_part.cpp:329
boost::uint8_t value_type
Definition: GnashImage.h:83
#define _(String)
Definition: log.h:44
boost::shared_ptr< IOChannel > _inStream
Definition: GnashImage.h:326
size_t channels() const
Get the number of channels.
Definition: GnashImage.h:121
ImageType
The types of images handled in Gnash.
Definition: GnashImage.h:48
virtual void writeImageRGBA(const unsigned char *)
Write RGBA image data using the parameters supplied at construction.
Definition: GnashImage.h:361
SimpleBuffer _data
The data to be sent by POST with this request.
Definition: NetConnection_as.cpp:211
GnashImage::iterator scanline(GnashImage &im, size_t row)
Get a pointer to a given row of any image.
Definition: GnashImage.h:394
boost::shared_ptr< IOChannel > _outStream
Definition: GnashImage.h:385
virtual void readScanline(unsigned char *rgbData)=0
Read a scanline's worth of image data into the given buffer.
boost::int32_t x
Definition: BitmapData_as.cpp:434
size_t height() const
Get the image's width.
Definition: GnashImage.h:135
boost::scoped_array< value_type > container_type
Definition: GnashImage.h:84
size_t numChannels(ImageType t)
Definition: GnashImage.h:63
Definition: GnashKey.h:148
static DSOEXPORT std::auto_ptr< GnashImage > readImageData(boost::shared_ptr< gnash::IOChannel > in, FileType type)
Read image data from an IOChannel into an GnashImage.
Definition: GnashImage.cpp:217
#define DSOEXPORT
Definition: dsodefs.h:55
ImageLocation
The locations of images handled in Gnash.
Definition: GnashImage.h:56
Definition: GnashImage.h:333
const size_t _height
Height of image, in pixels.
Definition: GnashImage.h:208
Definition: GnashImage.h:58
static DSOEXPORT std::auto_ptr< ImageRGBA > readSWFJpeg3(boost::shared_ptr< gnash::IOChannel > in)
For reading SWF JPEG3-style image data, like ordinary JPEG, but stores the data in ImageRGBA format...
Definition: GnashImage.cpp:285
value_type * iterator
Definition: GnashImage.h:85
boost::int32_t y
Definition: BitmapData_as.cpp:435
Base class for different types of bitmaps.
Definition: GnashImage.h:79
virtual size_t getComponents() const =0
Get number of components (channels)
Definition: GnashKey.h:153
Definition: GnashImage.h:59
const ImageType _type
The type of the image: RGBA or RGB.
Definition: GnashImage.h:199
void mergeAlpha(ImageRGBA &im, GnashImage::const_iterator alphaData, const size_t bufferLength)
Definition: GnashImage.cpp:148
iterator end()
An iterator to the end of the data.
Definition: GnashImage.h:166
virtual const_iterator begin() const
Access the raw data.
Definition: GnashImage.h:161
virtual void writeImageRGB(const unsigned char *rgbData)=0
Write RGB image data using the parameters supplied at construction.
ImageType _type
Definition: GnashImage.h:328
virtual void read()=0
Begin processing the image data.
const value_type * const_iterator
Definition: GnashImage.h:86
virtual ~Output()
Definition: GnashImage.h:351
Definition: GnashImage.h:50
virtual size_t getWidth() const =0
Get the image's width in pixels.
The base class for reading image data.
Definition: GnashImage.h:261