Gnash  0.8.10
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, 2011, 2012
00004 //   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 //
00055 //
00059 //
00063 class BitmapData_as : public Relay
00064 {
00065 public:
00066 
00067     enum Channel {
00068         CHANNEL_RED = 1,
00069         CHANNEL_GREEN = 2,
00070         CHANNEL_BLUE = 4,
00071         CHANNEL_ALPHA = 8
00072     };
00073 
00074     typedef image::pixel_iterator<image::ARGB> iterator;
00075 
00077     //
00080         BitmapData_as(as_object* owner, std::auto_ptr<image::GnashImage> im);
00081 
00082     virtual ~BitmapData_as() {}
00083 
00085     //
00087     size_t width() const {
00088         assert(data());
00089         return data()->width();
00090     }
00091     
00093     //
00095     size_t height() const {
00096         assert(data());
00097         return data()->height();
00098     }
00099 
00101     //
00103     bool transparent() const {
00104         assert(data());
00105         return (data()->type() == image::TYPE_RGBA);
00106     }
00107 
00109     //
00111     const CachedBitmap* bitmapInfo() const {
00112         return _cachedBitmap.get();
00113     }
00114 
00116     //
00118     void dispose();
00119     
00121     void draw(MovieClip& mc, const Transform& transform);
00122 
00124     //
00126     void attach(DisplayObject* obj) {
00127         _attachedObjects.push_back(obj);
00128     }
00129 
00131     virtual void setReachable();
00132 
00134     //
00139     bool disposed() const {
00140         return !data();
00141     }
00142  
00144     iterator begin() const {
00145         assert(!disposed());
00146         return image::begin<image::ARGB>(*data());
00147     }
00148     
00150     iterator end() const {
00151         assert(!disposed());
00152         return image::end<image::ARGB>(*data());
00153     }
00154 
00156     void updateObjects() const;
00157 
00158 private:
00159     
00160     image::GnashImage* data() const {
00161         return _cachedBitmap.get() ? &_cachedBitmap->image() : _image.get();
00162     }
00163 
00165     as_object* _owner;
00166 
00167     boost::intrusive_ptr<CachedBitmap> _cachedBitmap;
00168 
00169     boost::scoped_ptr<image::GnashImage> _image;
00170 
00171     std::list<DisplayObject*> _attachedObjects;
00172 
00173 };
00174 
00176 void bitmapdata_class_init(as_object& where, const ObjectURI& uri);
00177 
00178 void registerBitmapDataNative(as_object& global);
00179 
00180 } // end of gnash namespace
00181 
00182 #endif