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 <set>
25 #include <algorithm>
26 
27 #include "GnashEnums.h"
28 
29 namespace gnash {
30  class Renderer;
31 }
32 
33 namespace gnash {
34 
37 {
38 public:
39 
40  typedef std::vector<size_t> FrameList;
41 
43  ScreenShotter(const std::string& fileName, int quality = 100);
44 
46  ScreenShotter(std::string fileName, FileType f, int quality = 100);
47 
49 
51  void now() {
52  _immediate = true;
53  }
54 
56  void lastFrame() {
57  _last = true;
58  }
59 
60  struct NoAction { void operator()() const {} };
61 
63  //
65  //
70  void last(const Renderer& r) const {
71  last<NoAction>(r);
72  }
73 
75  //
79  //
84  template<typename Action>
85  void last(const Renderer& r, Action* t = 0) const
86  {
87  if (_last) {
88  if (t) (*t)();
89  saveImage(r, "last");
90  }
91  }
92 
94  //
96  //
100  void screenShot(const Renderer& r, size_t frameAdvance) {
101  screenShot<NoAction>(r, frameAdvance);
102  }
103 
105  //
108  //
114  template<typename Action>
115  void screenShot(const Renderer& r, size_t frameAdvance, Action* t = 0) {
116  // Save an image if a spontaneous screenshot was requested or the
117  // frame is in the list of requested frames.
118  if (_immediate || std::binary_search(_frames.begin(), _frames.end(),
119  frameAdvance)) {
120 
121  // Check whether we've rendered an image for this frame.
122  if (_done.find(frameAdvance) != _done.end()) {
123  return;
124  }
125  if (t) (*t)();
126  _done.insert(frameAdvance);
127 
128  saveImage(r, std::to_string(frameAdvance));
129  _immediate = false;
130  }
131 
132  }
133 
135  void setFrames(const FrameList& frames);
136 
137 private:
138 
140  void saveImage(const Renderer& r, const std::string& filename) const;
141 
143  bool _immediate;
144 
146  const std::string _fileName;
147 
149  bool _last;
150 
151  FrameList _frames;
152 
153  const FileType _type;
154 
155  const int _quality;
156 
157  std::set<int> _done;
158 
159 };
160 
161 } // end of gnash namespace
162 
163 #endif
164 
165 // Local Variables:
166 // mode: C++
167 // indent-tabs-mode: nil
168 // End:
ScreenShotter.h
gnash::ScreenShotter::setFrames
void setFrames(const FrameList &frames)
Request a list of frames to be rendered to image files.
Definition: ScreenShotter.cpp:104
tu_file.h
gnash::ScreenShotter::now
void now()
Take a screenshot at the next possible moment.
Definition: ScreenShotter.h:51
gnash::ScreenShotter::screenShot
void screenShot(const Renderer &r, size_t frameAdvance, Action *t=0)
Takes a screenshot if required.
Definition: ScreenShotter.h:115
gnash::ScreenShotter::~ScreenShotter
~ScreenShotter()
Definition: ScreenShotter.cpp:82
_
#define _(String)
Definition: log.h:44
Renderer.h
gnash
Anonymous namespace for callbacks, local functions, event handlers etc.
Definition: dbus_ext.cpp:41
gnash::FileType
FileType
Definition: GnashEnums.h:25
gnash::GNASH_FILETYPE_JPEG
@ GNASH_FILETYPE_JPEG
Definition: GnashEnums.h:26
gnash::Renderer
Base class for render handlers.
Definition: Renderer.h:189
gnash::ScreenShotter::last
void last(const Renderer &r) const
To be called on the last frame before exit.
Definition: ScreenShotter.h:70
gnash::ScreenShotter::screenShot
void screenShot(const Renderer &r, size_t frameAdvance)
Takes a screenshot if required.
Definition: ScreenShotter.h:100
GnashEnums.h
gnash::log_error
void log_error(StringType msg, Args... args)
Definition: log.h:283
gnash::key::t
@ t
Definition: GnashKey.h:166
gnash::key::r
@ r
Definition: GnashKey.h:164
gnash::key::type
type
Definition: GnashKey.h:330
gnash::ScreenShotter::NoAction
Definition: ScreenShotter.h:60
gnash::ScreenShotter
Handles screen dumps.
Definition: ScreenShotter.h:37
gnash::ScreenShotter::FrameList
std::vector< size_t > FrameList
Definition: ScreenShotter.h:40
gnash::ScreenShotter::last
void last(const Renderer &r, Action *t=0) const
To be called on the last frame before exit.
Definition: ScreenShotter.h:85
gnash::ScreenShotter::NoAction::operator()
void operator()() const
Definition: ScreenShotter.h:60
gnash::GNASH_FILETYPE_PNG
@ GNASH_FILETYPE_PNG
Definition: GnashEnums.h:27
log.h
gnash::ScreenShotter::ScreenShotter
ScreenShotter(const std::string &fileName, int quality=100)
Create a ScreenShotter with output type selected from filename.
Definition: ScreenShotter.cpp:61
gnash::key::f
@ f
Definition: GnashKey.h:152
gnash::makeFileChannel
std::unique_ptr< IOChannel > makeFileChannel(FILE *fp, bool close)
Creates an IOChannel wrapper around a C stream.
Definition: tu_file.cpp:244
gnash::ScreenShotter::lastFrame
void lastFrame()
Take a screenshot when the last frame is reached.
Definition: ScreenShotter.h:56
gnash::typeFromFileName
FileType typeFromFileName(const std::string &filename)
Guess an appropriate file type from the filename.
Definition: ScreenShotter.cpp:41
IOChannel.h