Gnash  0.8.11dev
ScreenShotter.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010,
3 // 2011 Free Software Foundation, Inc
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 
19 #ifndef GNASH_SCREENSHOT_H
20 #define GNASH_SCREENSHOT_H
21 
22 #include <vector>
23 #include <string>
24 #include <boost/shared_ptr.hpp>
25 #include <set>
26 #include <algorithm>
27 #include <boost/lexical_cast.hpp>
28 
29 #include "GnashEnums.h"
30 
31 namespace gnash {
32  class Renderer;
33 }
34 
35 namespace gnash {
36 
39 {
40 public:
41 
42  typedef std::vector<size_t> FrameList;
43 
45  ScreenShotter(const std::string& fileName, int quality = 100);
46 
48  ScreenShotter(const std::string& fileName, FileType f, int quality = 100);
49 
51 
53  void now() {
54  _immediate = true;
55  }
56 
58  void lastFrame() {
59  _last = true;
60  }
61 
62  struct NoAction { void operator()() const {} };
63 
65  //
67  //
72  void last(const Renderer& r) const {
73  last<NoAction>(r);
74  }
75 
77  //
81  //
86  template<typename Action>
87  void last(const Renderer& r, Action* t = 0) const
88  {
89  if (_last) {
90  if (t) (*t)();
91  saveImage(r, "last");
92  }
93  }
94 
96  //
98  //
102  void screenShot(const Renderer& r, size_t frameAdvance) {
103  screenShot<NoAction>(r, frameAdvance);
104  }
105 
107  //
110  //
116  template<typename Action>
117  void screenShot(const Renderer& r, size_t frameAdvance, Action* t = 0) {
118  // Save an image if a spontaneous screenshot was requested or the
119  // frame is in the list of requested frames.
120  if (_immediate || std::binary_search(_frames.begin(), _frames.end(),
121  frameAdvance)) {
122 
123  // Check whether we've rendered an image for this frame.
124  if (_done.find(frameAdvance) != _done.end()) {
125  return;
126  }
127  if (t) (*t)();
128  _done.insert(frameAdvance);
129 
130  saveImage(r, boost::lexical_cast<std::string>(frameAdvance));
131  _immediate = false;
132  }
133 
134  }
135 
137  void setFrames(const FrameList& frames);
138 
139 private:
140 
142  void saveImage(const Renderer& r, const std::string& filename) const;
143 
145  bool _immediate;
146 
148  const std::string _fileName;
149 
151  bool _last;
152 
153  FrameList _frames;
154 
155  const FileType _type;
156 
157  const int _quality;
158 
159  std::set<int> _done;
160 
161 };
162 
163 } // end of gnash namespace
164 
165 #endif
166 
167 // Local Variables:
168 // mode: C++
169 // indent-tabs-mode: nil
170 // End:
FileType
Definition: GnashEnums.h:25
Definition: ScreenShotter.h:62
void lastFrame()
Take a screenshot when the last frame is reached.
Definition: ScreenShotter.h:58
ScreenShotter(const std::string &fileName, int quality=100)
Create a ScreenShotter with output type selected from filename.
Definition: ScreenShotter.cpp:61
Definition: GnashKey.h:152
void setFrames(const FrameList &frames)
Request a list of frames to be rendered to image files.
Definition: ScreenShotter.cpp:104
Base class for render handlers.
Definition: Renderer.h:190
std::vector< size_t > FrameList
Definition: ScreenShotter.h:42
void now()
Take a screenshot at the next possible moment.
Definition: ScreenShotter.h:53
Definition: GnashKey.h:164
Definition: GnashKey.h:166
void last(const Renderer &r, Action *t=0) const
To be called on the last frame before exit.
Definition: ScreenShotter.h:87
void screenShot(const Renderer &r, size_t frameAdvance)
Takes a screenshot if required.
Definition: ScreenShotter.h:102
Handles screen dumps.
Definition: ScreenShotter.h:38
void last(const Renderer &r) const
To be called on the last frame before exit.
Definition: ScreenShotter.h:72
~ScreenShotter()
Definition: ScreenShotter.cpp:82
void operator()() const
Definition: ScreenShotter.h:62
void screenShot(const Renderer &r, size_t frameAdvance, Action *t=0)
Takes a screenshot if required.
Definition: ScreenShotter.h:117