1 /*
2     Copyright (C) 2009 Johannes Schindelin (johannes.schindelin@gmx.de)
3 
4     This program is free software; you can redistribute it and/or
5     modify it under the terms of the GNU General Public License
6     as published by the Free Software Foundation; either version
7     3 of the License, or (at your option) any later version.
8 
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13 
14     You should have received a copy of the GNU General Public License
15     along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 */
17 
18 #ifndef PPM_FRAME_EXPORTER_H
19 #define PPM_FRAME_EXPORTER_H
20 
21 #include <iostream>
22 #include <fstream>
23 #include <ostream>
24 #include <string>
25 #include <exception>
26 
27 #include "gl.h"
28 
29 enum { FRAME_EXPORTER_WAIT,
30        FRAME_EXPORTER_DUMP,
31        FRAME_EXPORTER_EXIT,
32        FRAME_EXPORTER_STOPPED };
33 
34 class FrameExporter {
35 protected:
36 
37     char* pixels1;
38     char* pixels2;
39     char* pixels_out;
40 
41     char* pixels_shared_ptr;
42 
43     size_t rowstride;
44 
45     GLuint screentex;
46 
47     SDL_Thread* thread;
48     SDL_mutex* mutex;
49     SDL_cond* cond;
50     int dumper_thread_state;
51 
52 public:
53     FrameExporter();
54     virtual ~FrameExporter();
55     void stop();
56     void dump();
57     void dumpThr();
dumpImpl()58     virtual void dumpImpl() {};
59 };
60 
61 class PPMExporterException : public std::exception {
62 protected:
63     std::string filename;
64 public:
PPMExporterException(std::string & filename)65     PPMExporterException(std::string& filename) : filename(filename) {}
~PPMExporterException()66     virtual ~PPMExporterException() throw () {};
67 
what()68     virtual const char* what() const throw() { return filename.c_str(); }
69 };
70 
71 class PPMExporter : public FrameExporter {
72 protected:
73     std::ostream* output;
74     std::string filename;
75     char ppmheader[1024];
76 
77 public:
78     PPMExporter(std::string outputfile);
79     virtual ~PPMExporter();
80     virtual void dumpImpl();
81 };
82 
83 
84 #endif
85