diff options
Diffstat (limited to 'src/Stitch.cxx')
-rw-r--r-- | src/Stitch.cxx | 151 |
1 files changed, 151 insertions, 0 deletions
diff --git a/src/Stitch.cxx b/src/Stitch.cxx new file mode 100644 index 0000000..1fe3d88 --- /dev/null +++ b/src/Stitch.cxx @@ -0,0 +1,151 @@ +// +// Stitch routines. +// +// Copyright 2006 by Johannes Hofmann +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Library General Public +// License as published by the Free Software Foundation; either +// version 2 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Library General Public License for more details. +// +// You should have received a copy of the GNU Library General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 +// USA. +// + +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <math.h> + +#include <Fl/Fl.H> + +#include "OutputImage.H" +#include "Stitch.H" + +static double pi_d = asin(1.0) * 2.0; + +Stitch::Stitch() { + for (int i=0; i<MAX_PICS; i++) { + gipf[i] = NULL; + single_images[i] = NULL; + } + merged_image = NULL; +} + +Stitch::~Stitch() { + for (int i=0; i<MAX_PICS; i++) { + if (gipf[i]) { + delete(gipf[i]); + } else { + break; + } + } +} + + +int +Stitch::load_image(char *file) { + for (int i=0; i<MAX_PICS; i++) { + if (gipf[i] == NULL) { + gipf[i] = new GipfelWidget(0, 0, 800, 600); + if (gipf[i]->load_image(file) != 0) { + delete gipf[i]; + gipf[i] = NULL; + } + break; + } + } + + +} + +OutputImage* +Stitch::set_output(OutputImage *img) { + OutputImage *ret = merged_image; + merged_image = img; + return ret; +} + +OutputImage* +Stitch::set_output(const char *file, OutputImage *img) { + OutputImage *ret = NULL; + + for (int i=0; i<MAX_PICS; i++) { + if (gipf[i] != NULL) { + const char *img_file = gipf[i]->get_image_filename(); + if (img_file && strcmp(file, img_file) == 0) { + ret = single_images[i]; + single_images[i] = img; + break; + } + } + } + + return ret; +} + +int +Stitch::resample(int w, int h, + double view_start, double view_end) { + double step_view = (view_end - view_start) / w; + char r, g, b; + int y_off = h / 2; + int merged_pixel_set; + double radius = (double) w / (view_end -view_start); + + if (merged_image) { + merged_image->init(w, h); + } + for (int i=0; i<MAX_PICS; i++) { + if (single_images[i]) { + single_images[i]->init(w, h); + } + } + + for (int y=0; y<h; y++) { + double a_nick = atan((double)(y_off - y)/radius); + + for (int x=0; x<w; x++) { + double a_view; + a_view = view_start + x * step_view; + merged_pixel_set = 0; + for (int i=0; i<MAX_PICS; i++) { + if (gipf[i] == NULL) { + break; + } else if (gipf[i]->get_pixel(a_view, a_nick, &r, &g, &b)==0) { + if (single_images[i]) { + single_images[i]->set_pixel(x, r, g, b); + } + if (!merged_pixel_set && merged_image) { + merged_image->set_pixel(x, r, g, b); + merged_pixel_set++; + } + } + } + } + if (merged_image) { + merged_image->next_line(); + } + for (int i=0; i<MAX_PICS; i++) { + if (single_images[i]) { + single_images[i]->next_line(); + } + } + } + + if (merged_image) { + merged_image->done(); + } + for (int i=0; i<MAX_PICS; i++) { + if (single_images[i]) { + single_images[i]->done(); + } + } +} |