summaryrefslogtreecommitdiff
path: root/src/ScreenDump.cxx
diff options
context:
space:
mode:
authorJohannes Hofmann <Johannes.Hofmann@gmx.de>2009-03-26 23:14:04 +0100
committerJohannes Hofmann <Johannes.Hofmann@gmx.de>2009-03-26 23:14:04 +0100
commit29ffdb1136d0c5926cf920b874db93421ac7c75d (patch)
tree2f3ba908096b906493740d17130658a972521526 /src/ScreenDump.cxx
parentf4e55a2fb37e86d82c378e2aebc4d3631a462fab (diff)
add ScreenDump
Diffstat (limited to 'src/ScreenDump.cxx')
-rw-r--r--src/ScreenDump.cxx42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/ScreenDump.cxx b/src/ScreenDump.cxx
new file mode 100644
index 0000000..20a038f
--- /dev/null
+++ b/src/ScreenDump.cxx
@@ -0,0 +1,42 @@
+#include <stdlib.h>
+
+#include <FL/Fl.H>
+#include <FL/x.H>
+#include <FL/fl_draw.H>
+
+#include "JPEGOutputImage.H"
+#include "ScreenDump.H"
+
+ScreenDump::ScreenDump(GipfelWidget *g) {
+ Fl_Offscreen offscreen;
+
+ gipf = g;
+ Fl::flush();
+ offscreen = fl_create_offscreen(gipf->w(), gipf->h());
+ fl_begin_offscreen(offscreen);
+ gipf->draw();
+ rgb = fl_read_image(NULL, 0, 0, gipf->w(), gipf->h());
+ fl_end_offscreen();
+ fl_delete_offscreen(offscreen);
+}
+
+ScreenDump::~ScreenDump() {
+ free(rgb);
+}
+
+int
+ScreenDump::save(const char *file) {
+ JPEGOutputImage out(file, 95);
+
+ out.init(gipf->w(), gipf->h());
+
+ for (int y = 0; y < gipf->h(); y++) {
+ for (int x = 0; x < gipf->w(); x++) {
+ unsigned char *px = &rgb[(y * gipf->w() + x) * 3];
+ out.set_pixel(x, px[0] * 255, px[1] * 255, px[2] * 255);
+ }
+ out.next_line();
+ }
+
+ out.done();
+}