From 29ffdb1136d0c5926cf920b874db93421ac7c75d Mon Sep 17 00:00:00 2001 From: Johannes Hofmann Date: Thu, 26 Mar 2009 23:14:04 +0100 Subject: add ScreenDump --- src/GipfelWidget.H | 3 +++ src/Makefile.am | 4 +++- src/ScreenDump.H | 25 +++++++++++++++++++++++++ src/ScreenDump.cxx | 42 ++++++++++++++++++++++++++++++++++++++++++ src/gipfel.cxx | 16 ++++++++++++---- 5 files changed, 85 insertions(+), 5 deletions(-) create mode 100644 src/ScreenDump.H create mode 100644 src/ScreenDump.cxx (limited to 'src') diff --git a/src/GipfelWidget.H b/src/GipfelWidget.H index 85de338..57ce337 100644 --- a/src/GipfelWidget.H +++ b/src/GipfelWidget.H @@ -7,8 +7,11 @@ #ifndef GipfelWidget_H #define GipfelWidget_H +#include + #include #include + #include "Panorama.H" #include "ImageMetaData.H" diff --git a/src/Makefile.am b/src/Makefile.am index df932a8..acf66f5 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -17,7 +17,8 @@ gipfel_SOURCES = \ JPEGOutputImage.cxx \ TIFFOutputImage.cxx \ PreviewOutputImage.cxx \ - ImageMetaData.cxx + ImageMetaData.cxx \ + ScreenDump.cxx noinst_HEADERS = \ GipfelWidget.H \ @@ -38,4 +39,5 @@ noinst_HEADERS = \ TIFFOutputImage.H \ PreviewOutputImage.H \ ImageMetaData.H \ + ScreenDump.H \ util.h diff --git a/src/ScreenDump.H b/src/ScreenDump.H new file mode 100644 index 0000000..f527404 --- /dev/null +++ b/src/ScreenDump.H @@ -0,0 +1,25 @@ +// +// Copyright 2009 Johannes Hofmann +// +// This software may be used and distributed according to the terms +// of the GNU General Public License, incorporated herein by reference. + +#ifndef SCREENDUMP_H +#define SCREENDUMP_H + +#include "GipfelWidget.H" +#include "OutputImage.H" + +class ScreenDump { + private: + GipfelWidget *gipf; + unsigned char * rgb; + + public: + ScreenDump(GipfelWidget *g); + ~ScreenDump(); + + int save(const char *file); +}; + +#endif 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 + +#include +#include +#include + +#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(); +} diff --git a/src/gipfel.cxx b/src/gipfel.cxx index e6d9f49..2b665b5 100644 --- a/src/gipfel.cxx +++ b/src/gipfel.cxx @@ -35,6 +35,7 @@ #include "TIFFOutputImage.H" #include "PreviewOutputImage.H" #include "Stitch.H" +#include "ScreenDump.H" #include "choose_hill.H" #include "../config.h" @@ -91,11 +92,11 @@ void set_values() { i_view_height->value(gipf->get_view_height()); b_viewpoint->label(gipf->get_viewpoint()); if (gipf->projection() == ProjectionLSQ::RECTILINEAR) { - mb->mode(8, FL_MENU_RADIO|FL_MENU_VALUE); - mb->mode(9, FL_MENU_RADIO); - } else { mb->mode(9, FL_MENU_RADIO|FL_MENU_VALUE); - mb->mode(8, FL_MENU_RADIO); + mb->mode(10, FL_MENU_RADIO); + } else { + mb->mode(10, FL_MENU_RADIO|FL_MENU_VALUE); + mb->mode(9, FL_MENU_RADIO); } gipf->get_distortion_params(&k0, &k1, &x0); @@ -136,6 +137,12 @@ void save_cb() { fl_message("ERROR: Saving image %s failed.", file); } +void dump_cb(Fl_Widget * o, void*) { + ScreenDump dmp(gipf); + + dmp.save("/tmp/dmp.jpg"); +} + void focal_length_cb(Fl_Slider* o, void*) { gipf->set_focal_length_35mm(o->value()); } @@ -273,6 +280,7 @@ void fill_menubar(Fl_Menu_Bar* mb) { mb->add("&File/&Save Image", FL_CTRL+'s', (Fl_Callback*)save_cb); mb->add("&File/Choose &Viewpoint", FL_CTRL+'v', (Fl_Callback*)viewpoint_cb); mb->add("&File/Load &Track", FL_CTRL+'t', (Fl_Callback*)track_cb); + mb->add("&File/Screen &Dump", FL_CTRL+'d', (Fl_Callback*)dump_cb); mb->add("&File/&Quit", FL_CTRL+'q', (Fl_Callback*)quit_cb); mb->add("&Projection/Normal Projection", 0, (Fl_Callback *)proj_cb, -- cgit v1.2.3