Gnash 0.8.10dev
|
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 <boost/intrusive_ptr.hpp> 00029 #include <memory> 00030 00031 #include "Relay.h" 00032 #include "CachedBitmap.h" 00033 #include "GnashImage.h" 00034 #include "ImageIterators.h" 00035 00036 namespace gnash { 00037 class as_object; 00038 struct ObjectURI; 00039 class MovieClip; 00040 class Transform; 00041 class DisplayObject; 00042 namespace image { 00043 class GnashImage; 00044 } 00045 } 00046 00047 namespace gnash { 00048 00050 // 00053 class BitmapData_as : public Relay 00054 { 00055 public: 00056 00057 typedef image::pixel_iterator<image::ARGB> iterator; 00058 00060 // 00063 BitmapData_as(as_object* owner, std::auto_ptr<image::GnashImage> im); 00064 00065 virtual ~BitmapData_as() {} 00066 00068 // 00070 size_t width() const { 00071 assert(data()); 00072 return data()->width(); 00073 } 00074 00076 // 00078 size_t height() const { 00079 assert(data()); 00080 return data()->height(); 00081 } 00082 00083 bool transparent() const { 00084 assert(data()); 00085 return (data()->type() == image::TYPE_RGBA); 00086 } 00087 00088 const CachedBitmap* bitmapInfo() const { 00089 return _cachedBitmap.get(); 00090 } 00091 00093 // 00095 void setPixel(size_t x, size_t y, boost::uint32_t color) const; 00096 00098 void setPixel32(size_t x, size_t y, boost::uint32_t color) const; 00099 00101 // 00103 boost::uint32_t getPixel(size_t x, size_t y) const; 00104 00106 // 00108 void fillRect(int x, int y, int w, int h, boost::uint32_t color); 00109 00110 void floodFill(size_t x, size_t y, boost::uint32_t old, 00111 boost::uint32_t fill); 00112 00114 void dispose(); 00115 00117 void draw(MovieClip& mc, const Transform& transform); 00118 00120 // 00122 void attach(DisplayObject* obj) { 00123 _attachedObjects.push_back(obj); 00124 } 00125 00127 virtual void setReachable(); 00128 00130 bool disposed() const { 00131 return !data(); 00132 } 00133 00134 iterator begin() const { 00135 assert(!disposed()); 00136 return image::begin<image::ARGB>(*data()); 00137 } 00138 00139 iterator end() const { 00140 assert(!disposed()); 00141 return image::end<image::ARGB>(*data()); 00142 } 00143 00145 void updateObjects(); 00146 00147 private: 00148 00149 image::GnashImage* data() const { 00150 return _cachedBitmap.get() ? &_cachedBitmap->image() : _image.get(); 00151 } 00152 00154 as_object* _owner; 00155 00156 boost::intrusive_ptr<CachedBitmap> _cachedBitmap; 00157 00158 boost::scoped_ptr<image::GnashImage> _image; 00159 00160 std::list<DisplayObject*> _attachedObjects; 00161 00162 }; 00163 00165 void bitmapdata_class_init(as_object& where, const ObjectURI& uri); 00166 00167 void registerBitmapDataNative(as_object& global); 00168 00169 } // end of gnash namespace 00170 00171 #endif