Gnash  0.8.10
ScreenShotter.h
Go to the documentation of this file.
00001 // 
00002 //   Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010,
00003 //   2011 Free Software Foundation, Inc
00004 // 
00005 // This program is free software; you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation; either version 3 of the License, or
00008 // (at your option) any later version.
00009 // 
00010 // This program is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 // 
00015 // You should have received a copy of the GNU General Public License
00016 // along with this program; if not, write to the Free Software
00017 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00018 
00019 #ifndef GNASH_SCREENSHOT_H
00020 #define GNASH_SCREENSHOT_H
00021 
00022 #include <vector>
00023 #include <string>
00024 #include <boost/shared_ptr.hpp>
00025 #include <set>
00026 #include <algorithm>
00027 #include <boost/lexical_cast.hpp>
00028 
00029 #include "GnashEnums.h"
00030 
00031 namespace gnash {
00032     class Renderer;
00033 }
00034 
00035 namespace gnash {
00036 
00038 class ScreenShotter
00039 {
00040 public:
00041 
00042     typedef std::vector<size_t> FrameList;
00043 
00045     ScreenShotter(const std::string& fileName, int quality = 100);
00046     
00048     ScreenShotter(const std::string& fileName, FileType f, int quality = 100);
00049 
00050     ~ScreenShotter();
00051 
00053     void now() {
00054         _immediate = true;
00055     }
00056 
00058     void lastFrame() {
00059         _last = true;
00060     }
00061 
00062     struct NoAction { void operator()() const {} };
00063 
00065     //
00067     //
00072     void last(const Renderer& r) const {
00073         last<NoAction>(r);
00074     }
00075 
00077     //
00081     //
00086     template<typename Action>
00087     void last(const Renderer& r, Action* t = 0) const
00088     {
00089         if (_last) {
00090             if (t) (*t)();
00091             saveImage(r, "last");
00092         }
00093     }
00094 
00096     //
00098     //
00102     void screenShot(const Renderer& r, size_t frameAdvance) {
00103         screenShot<NoAction>(r, frameAdvance);
00104     }
00105 
00107     //
00110     //
00116     template<typename Action>
00117     void screenShot(const Renderer& r, size_t frameAdvance, Action* t = 0) {
00118         // Save an image if a spontaneous screenshot was requested or the
00119         // frame is in the list of requested frames.
00120         if (_immediate || std::binary_search(_frames.begin(), _frames.end(),
00121                     frameAdvance)) {
00122 
00123             // Check whether we've rendered an image for this frame.
00124             if (_done.find(frameAdvance) != _done.end()) {
00125                 return;
00126             }
00127             if (t) (*t)();
00128             _done.insert(frameAdvance);
00129 
00130             saveImage(r, boost::lexical_cast<std::string>(frameAdvance));
00131             _immediate = false;
00132         }
00133         
00134     }
00135 
00137     void setFrames(const FrameList& frames);
00138 
00139 private:
00140 
00142     void saveImage(const Renderer& r, const std::string& filename) const;
00143 
00145     bool _immediate;
00146 
00148     const std::string _fileName;
00149 
00151     bool _last;
00152 
00153     FrameList _frames;
00154 
00155     const FileType _type;
00156 
00157     const int _quality;
00158 
00159     std::set<int> _done;
00160 
00161 };
00162  
00163 } // end of gnash namespace
00164 
00165 #endif
00166 
00167 // Local Variables:
00168 // mode: C++
00169 // indent-tabs-mode: nil
00170 // End: