Gnash 0.8.9

BitmapData_as.h

Go to the documentation of this file.
00001 // BitmapData_as.h:  ActionScript "BitmapData" class, for Gnash.
00002 //
00003 //   Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010,
00004 //   2011 Free Software Foundation, Inc
00005 //
00006 // This program is free software; you can redistribute it and/or modify
00007 // it under the terms of the GNU General Public License as published by
00008 // the Free Software Foundation; either version 3 of the License, or
00009 // (at your option) any later version.
00010 //
00011 // This program is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 // GNU General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU General Public License
00017 // along with this program; if not, write to the Free Software
00018 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00019 //
00020 
00021 #ifndef GNASH_ASOBJ_BITMAPDATA_H
00022 #define GNASH_ASOBJ_BITMAPDATA_H
00023 
00024 #include <list>
00025 #include <boost/cstdint.hpp>
00026 #include <boost/scoped_ptr.hpp>
00027 #include <cassert>
00028 #include "smart_ptr.h"
00029 #include <boost/intrusive_ptr.hpp>
00030 #include <memory>
00031 
00032 #include "Relay.h"
00033 #include "CachedBitmap.h"
00034 #include "GnashImage.h"
00035 #include "ImageIterators.h"
00036 
00037 namespace gnash {
00038     class as_object;
00039     struct ObjectURI;
00040     class MovieClip;
00041     class Transform;
00042     class DisplayObject;
00043     namespace image {
00044         class GnashImage;
00045     }
00046 }
00047 
00048 namespace gnash {
00049 
00051 //
00054 class BitmapData_as : public Relay
00055 {
00056 public:
00057 
00058     typedef image::pixel_iterator<image::ARGB> iterator;
00059 
00061     //
00064         BitmapData_as(as_object* owner, std::auto_ptr<image::GnashImage> im);
00065 
00066     virtual ~BitmapData_as() {}
00067 
00069     //
00071     size_t width() const {
00072         assert(data());
00073         return data()->width();
00074     }
00075     
00077     //
00079     size_t height() const {
00080         assert(data());
00081         return data()->height();
00082     }
00083 
00084     bool transparent() const {
00085         assert(data());
00086         return (data()->type() == image::TYPE_RGBA);
00087     }
00088 
00089     const CachedBitmap* bitmapInfo() const {
00090         return _cachedBitmap.get();
00091     }
00092 
00094     //
00096     void setPixel(size_t x, size_t y, boost::uint32_t color) const;
00097 
00099     void setPixel32(size_t x, size_t y, boost::uint32_t color) const;
00100 
00102     //
00104     boost::uint32_t getPixel(size_t x, size_t y) const;
00105 
00107     //
00109     void fillRect(int x, int y, int w, int h, boost::uint32_t color);
00110 
00111     void floodFill(size_t x, size_t y, boost::uint32_t old,
00112             boost::uint32_t fill);
00113     
00115     void dispose();
00116     
00118     void draw(MovieClip& mc, const Transform& transform);
00119 
00121     //
00123     void attach(DisplayObject* obj) {
00124         _attachedObjects.push_back(obj);
00125     }
00126 
00128     virtual void setReachable();
00129 
00131     bool disposed() const {
00132         return !data();
00133     }
00134  
00135     iterator begin() const {
00136         assert(!disposed());
00137         return image::begin<image::ARGB>(*data());
00138     }
00139     
00140     iterator end() const {
00141         assert(!disposed());
00142         return image::end<image::ARGB>(*data());
00143     }
00144 
00145 private:
00146     
00147     image::GnashImage* data() const {
00148         return _cachedBitmap.get() ? &_cachedBitmap->image() : _image.get();
00149     }
00150 
00152     void updateObjects();
00153 
00155     as_object* _owner;
00156 
00157     boost::intrusive_ptr<CachedBitmap> _cachedBitmap;
00158 
00159     boost::scoped_ptr<image::GnashImage> _image;
00160 
00161     std::list<DisplayObject*> _attachedObjects;
00162 
00163 };
00164 
00166 void bitmapdata_class_init(as_object& where, const ObjectURI& uri);
00167 
00168 void registerBitmapDataNative(as_object& global);
00169 
00170 } // end of gnash namespace
00171 
00172 #endif