Gnash  0.8.11dev
BitmapData_as.h
Go to the documentation of this file.
1 // BitmapData_as.h: ActionScript "BitmapData" class, for 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 #ifndef GNASH_ASOBJ_BITMAPDATA_H
22 #define GNASH_ASOBJ_BITMAPDATA_H
23 
24 #include <list>
25 #include <cstdint>
26 #include <memory>
27 #include <cassert>
28 #include <boost/intrusive_ptr.hpp>
29 #include <memory>
30 
31 #include "Relay.h"
32 #include "CachedBitmap.h"
33 #include "GnashImage.h"
34 #include "ImageIterators.h"
35 
36 namespace gnash {
37  class as_object;
38  struct ObjectURI;
39  class MovieClip;
40  class Transform;
41  class DisplayObject;
42  namespace image {
43  class GnashImage;
44  }
45 }
46 
47 namespace gnash {
48 
50 //
55 //
59 //
63 class BitmapData_as : public Relay
64 {
65 public:
66 
67  enum Channel {
71  CHANNEL_ALPHA = 8
72  };
73 
75 
77  //
80  BitmapData_as(as_object* owner, std::unique_ptr<image::GnashImage> im);
81 
82  virtual ~BitmapData_as() {}
83 
85  //
87  size_t width() const {
88  assert(data());
89  return data()->width();
90  }
91 
93  //
95  size_t height() const {
96  assert(data());
97  return data()->height();
98  }
99 
101  //
103  bool transparent() const {
104  assert(data());
105  return (data()->type() == image::TYPE_RGBA);
106  }
107 
109  //
111  const CachedBitmap* bitmapInfo() const {
112  return _cachedBitmap.get();
113  }
114 
116  //
118  void dispose();
119 
121  void draw(MovieClip& mc, const Transform& transform);
122 
124  //
126  void attach(DisplayObject* obj) {
127  _attachedObjects.push_back(obj);
128  }
129 
131  virtual void setReachable();
132 
134  //
139  bool disposed() const {
140  return !data();
141  }
142 
144  iterator begin() const {
145  assert(!disposed());
146  return image::begin<image::ARGB>(*data());
147  }
148 
150  iterator end() const {
151  assert(!disposed());
152  return image::end<image::ARGB>(*data());
153  }
154 
156  void updateObjects() const;
157 
158 private:
159 
160  image::GnashImage* data() const {
161  return _cachedBitmap.get() ? &_cachedBitmap->image() : _image.get();
162  }
163 
165  as_object* _owner;
166 
167  boost::intrusive_ptr<CachedBitmap> _cachedBitmap;
168 
169  std::unique_ptr<image::GnashImage> _image;
170 
171  std::list<DisplayObject*> _attachedObjects;
172 
173 };
174 
176 void bitmapdata_class_init(as_object& where, const ObjectURI& uri);
177 
178 void registerBitmapDataNative(as_object& global);
179 
180 } // end of gnash namespace
181 
182 #endif
ASConversions.h
gnash::isNativeType
bool isNativeType(const as_object *obj, T *&relay)
Check whether the object is an instance of a known type.
Definition: as_object.h:875
pix
BitmapData_as::iterator pix
Definition: BitmapData_as.cpp:568
gnash::toNumber
double toNumber(const as_value &v, const VM &vm)
Convert an as_value to a double.
Definition: VM.cpp:451
gnash::BitmapData_as::BitmapData_as
BitmapData_as(as_object *owner, std::unique_ptr< image::GnashImage > im)
Construct a BitmapData.
Definition: BitmapData_as.cpp:599
Movie.h
gnash::isNaN
bool isNaN(const T &num)
Definition: GnashNumeric.h:62
gnash::toBool
bool toBool(const as_value &v, const VM &vm)
Convert an as_value to boolean type.
Definition: VM.cpp:445
height
@ height
Definition: klash_part.cpp:329
gnash::toInt
std::int32_t toInt(const as_value &v, const VM &vm)
AS2-compatible conversion to 32bit integer.
Definition: VM.cpp:463
gnash::image::GnashImage::width
size_t width() const
Get the image's width.
Definition: GnashImage.h:126
gnash::as_object
The base class for all ActionScript objects.
Definition: as_object.h:162
as_object.h
gnash::BitmapData_as::bitmapInfo
const CachedBitmap * bitmapInfo() const
Return the image data.
Definition: BitmapData_as.h:111
gnash::registerBitmapDataNative
void registerBitmapDataNative(as_object &global)
Definition: BitmapData_as.cpp:673
gnash::RunResources::renderer
Renderer * renderer() const
Definition: RunResources.h:112
gnash::toObject
as_object * toObject(const as_value &v, VM &vm)
Convert an as_value to an object.
Definition: VM.cpp:457
gnash::key::T
@ T
Definition: GnashKey.h:132
gnash::log_debug
void log_debug(StringType msg, Args... args)
Definition: log.h:301
y
std::int32_t y
Definition: BitmapData_as.cpp:435
gnash::key::i
@ i
Definition: GnashKey.h:155
gnash::Renderer::Internal
Definition: Renderer.h:563
LOG_ONCE
#define LOG_ONCE(x)
Definition: log.h:49
_
#define _(String)
Definition: log.h:44
Renderer.h
gnash::VM
The AVM1 virtual machine.
Definition: VM.h:72
Transform.h
gnash
Anonymous namespace for callbacks, local functions, event handlers etc.
Definition: dbus_ext.cpp:41
ColorTransform_as.h
gnash::Renderer::Internal::renderer
Renderer * renderer() const
Definition: Renderer.h:573
gnash::key::g
@ g
Definition: GnashKey.h:153
gnash::image::GnashImage
Base class for different types of bitmaps.
Definition: GnashImage.h:78
gnash::Renderer
Base class for render handlers.
Definition: Renderer.h:189
gnash::key::s
@ s
Definition: GnashKey.h:165
NativeFunction.h
gnash::key::n
@ n
Definition: GnashKey.h:160
Global_as.h
gnash::NSV::PROP_WIDTH
@ PROP_WIDTH
Definition: namedStrings.h:130
__FUNCTION__
#define __FUNCTION__
Definition: log.h:437
gnash::getGlobal
Global_as & getGlobal(const as_environment &env)
Definition: as_environment.cpp:651
GnashImage.h
gnash::MovieClip
A MovieClip is a container for DisplayObjects.
Definition: MovieClip.h:84
gnash::getVM
VM & getVM(const as_environment &env)
Definition: as_environment.h:222
UNUSED
#define UNUSED(x)
Definition: utility.h:113
gnash::getMember
as_value getMember(as_object &o, const ObjectURI &uri)
Get a member of an object using AS lookup rules.
Definition: as_object.h:756
gnash::as_object::init_destructive_property
bool init_destructive_property(const ObjectURI &uri, as_function &getter, int flags=PropFlags::dontEnum)
Initialize a destructive getter property.
Definition: as_object.cpp:720
gnash::BitmapData_as::CHANNEL_GREEN
@ CHANNEL_GREEN
Definition: BitmapData_as.h:69
gnash::createObject
as_object * createObject(const Global_as &gl)
Definition: Global_as.cpp:303
CachedBitmap.h
BitmapData_as.h
gnash::key::t
@ t
Definition: GnashKey.h:166
color
const VGfloat color[4]
Definition: testr_gtk.cpp:82
gnash::key::r
@ r
Definition: GnashKey.h:164
fill
VGPaint fill
Definition: testr_gtk.cpp:86
gnash::fn_call::Args
FunctionArgs< as_value > Args
Definition: fn_call.h:121
gnash::renderer::opengl::for_each
void for_each(C &container, R(T::*pmf)(const A &), const A &arg)
Definition: Renderer_ogl.cpp:690
gnash::BitmapData_as::draw
void draw(MovieClip &mc, const Transform &transform)
Draw a MovieClip to a BitmapData.
Definition: BitmapData_as.cpp:639
gnash::BitmapData_as::disposed
bool disposed() const
Whether the BitmapData has been disposed.
Definition: BitmapData_as.h:139
gnash::key::a
@ a
Definition: GnashKey.h:147
gnash::Relay
This is the base class for type-specific object data.
Definition: Relay.h:50
gnash::BitmapData_as::updateObjects
void updateObjects() const
Inform any attached objects that the data has changed.
Definition: BitmapData_as.cpp:623
gnash::getRunResources
const RunResources & getRunResources(const as_object &o)
Get the RunResources from an as_object.
Definition: as_object.cpp:1142
gnash::key::type
type
Definition: GnashKey.h:330
gnash::toSWFMatrix
SWFMatrix toSWFMatrix(as_object &m)
Convert an object to a SWFMatrix.
Definition: ASConversions.cpp:45
gnash::image::pixel_iterator
The pixel_iterator class is a pixel-level adaptor for a GnashImage.
Definition: ImageIterators.h:126
IF_VERBOSE_ASCODING_ERRORS
#define IF_VERBOSE_ASCODING_ERRORS(x)
Definition: log.h:397
gnash::constructInstance
as_object * constructInstance(as_function &ctor, const as_environment &env, fn_call::Args &args)
Definition: as_function.cpp:47
gnash::key::h
@ h
Definition: GnashKey.h:154
gnash::BitmapData_as::iterator
image::pixel_iterator< image::ARGB > iterator
Definition: BitmapData_as.h:74
gnash::VM::registerNative
void registerNative(as_c_function_ptr fun, unsigned int x, unsigned int y)
Definition: VM.cpp:268
MovieClip.h
gnash::NSV::PROP_X
@ PROP_X
Definition: namedStrings.h:131
gnash::key::p
@ p
Definition: GnashKey.h:162
gnash::BitmapData_as::height
size_t height() const
Return the height of the image.
Definition: BitmapData_as.h:95
test.w
w
Definition: test.py:8
gnash::BitmapData_as::setReachable
virtual void setReachable()
Overrides Relay::setReachable().
Definition: BitmapData_as.cpp:615
gnash::BitmapData_as::CHANNEL_RED
@ CHANNEL_RED
Definition: BitmapData_as.h:68
gnash::DisplayObject::update
virtual void update()
Notify a change in the DisplayObject's appearance.
Definition: DisplayObject.h:667
gnash::BitmapData_as::Channel
Channel
Definition: BitmapData_as.h:67
GnashNumeric.h
gnash::clamp
T clamp(T i, T min, T max)
Definition: GnashNumeric.h:77
gnash::PropFlags::onlySWF8Up
@ onlySWF8Up
Only visible by VM initialized for version 8 or higher.
Definition: PropFlags.h:54
VM.h
ImageIterators.h
gnash::key::j
@ j
Definition: GnashKey.h:156
gnash::BitmapData_as::end
iterator end() const
Return a BitmapData_as::iterator to a one-past-the end pixel.
Definition: BitmapData_as.h:150
gnash::BitmapData_as::~BitmapData_as
virtual ~BitmapData_as()
Definition: BitmapData_as.h:82
gnash::log_aserror
void log_aserror(StringType msg, Args... args)
Definition: log.h:331
DisplayObject.h
Relay.h
log.h
fn_call.h
namedStrings.h
RunResources.h
test.uri
uri
Definition: test.py:12
gnash::bitmapdata_class_init
void bitmapdata_class_init(as_object &where, const ObjectURI &uri)
Initialize the global BitmapData class.
Definition: BitmapData_as.cpp:664
gnash::key::c
@ c
Definition: GnashKey.h:149
gnash::BitmapData_as::CHANNEL_BLUE
@ CHANNEL_BLUE
Definition: BitmapData_as.h:70
gnash::NSV::PROP_uuPROTOuu
@ PROP_uuPROTOuu
Definition: namedStrings.h:118
movie_definition.h
gnash::DisplayObject
DisplayObject is the base class for all DisplayList objects.
Definition: DisplayObject.h:169
Array_as.h
gnash::BitmapData_as
Implements the BitmapData native type.
Definition: BitmapData_as.h:64
source
@ source
Definition: klash_part.cpp:329
gnash::NSV::PROP_HEIGHT
@ PROP_HEIGHT
Definition: namedStrings.h:78
gnash::Transform
The Transform class expresses a stage in a cumulative transformation.
Definition: Transform.h:34
gnash::toCxForm
SWFCxForm toCxForm(const ColorTransform_as &tr)
Convert a ColorTransform_as to a SWFCxForm record.
Definition: ASConversions.cpp:85
gnash::key::o
@ o
Definition: GnashKey.h:161
width
@ width
Definition: klash_part.cpp:329
gnash::foreachArray
void foreachArray(as_object &array, T &pred)
Definition: Array_as.h:78
gnash::BitmapData_as::dispose
void dispose()
Free the bitmap data.
Definition: BitmapData_as.cpp:630
gnash::log_unimpl
void log_unimpl(StringType msg, Args... args)
Definition: log.h:289
gnash::NSV::PROP_Y
@ PROP_Y
Definition: namedStrings.h:132
gnash::NSV::PROP_PROTOTYPE
@ PROP_PROTOTYPE
Definition: namedStrings.h:87
gnash::key::u
@ u
Definition: GnashKey.h:167
gnash::ObjectURI
A URI for describing as_objects.
Definition: ObjectURI.h:45
gnash::CachedBitmap
A CachedBitmap is created by the renderer in a format of its choosing.
Definition: CachedBitmap.h:38
GnashException.h
x
std::int32_t x
Definition: BitmapData_as.cpp:434
gnash::findObject
as_object * findObject(const as_environment &ctx, const std::string &path, const as_environment::ScopeStack *scope)
Find the object referenced by the given path.
Definition: as_environment.cpp:116
gnash::key::b
@ b
Definition: GnashKey.h:148
test.v
v
Definition: test.py:11
gnash::key::e
@ e
Definition: GnashKey.h:151
gnash::image::TYPE_RGBA
@ TYPE_RGBA
Definition: GnashImage.h:50
gnash::BitmapData_as::width
size_t width() const
Return the width of the image.
Definition: BitmapData_as.h:87
gnash::BitmapData_as::transparent
bool transparent() const
Whether the BitmapData_as has transparency.
Definition: BitmapData_as.h:103
gnash::BitmapData_as::CHANNEL_ALPHA
@ CHANNEL_ALPHA
Definition: BitmapData_as.h:71
gnash::image::GnashImage::height
size_t height() const
Get the image's width.
Definition: GnashImage.h:133
gnash::BitmapData_as::attach
void attach(DisplayObject *obj)
Attach this BitmapData to an object.
Definition: BitmapData_as.h:126
gnash::MovieClip::draw
void draw(Renderer &renderer, const Transform &xform)
Draw this MovieClip.
Definition: MovieClip.cpp:1195
gnash::GcResource::setReachable
void setReachable() const
Mark this resource as being reachable.
Definition: GC.h:92
gnash::BitmapData_as::begin
iterator begin() const
Return a BitmapData_as::iterator to the first pixel in the data.
Definition: BitmapData_as.h:144