summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/GipfelWidget.H5
-rw-r--r--src/GipfelWidget.cxx52
-rw-r--r--src/JPEGOutputImage.H1
-rw-r--r--src/Stitch.H13
-rw-r--r--src/Stitch.cxx79
-rw-r--r--src/gipfel.cxx27
6 files changed, 143 insertions, 34 deletions
diff --git a/src/GipfelWidget.H b/src/GipfelWidget.H
index 563cd66..50cb10d 100644
--- a/src/GipfelWidget.H
+++ b/src/GipfelWidget.H
@@ -49,6 +49,9 @@ class GipfelWidget : public Fl_Widget {
int get_rel_track_width(Hill *m);
+ static int get_pixel_nearest(Fl_Image *img, double x, double y,
+ char *r, char *g, char *b);
+
public:
GipfelWidget(int X,int Y,int W, int H);
@@ -57,6 +60,8 @@ class GipfelWidget : public Fl_Widget {
int load_image(char *file);
int save_image(char *file);
+
+ const char * get_image_filename();
int load_data(const char *file);
diff --git a/src/GipfelWidget.cxx b/src/GipfelWidget.cxx
index 67695ad..34716e0 100644
--- a/src/GipfelWidget.cxx
+++ b/src/GipfelWidget.cxx
@@ -40,7 +40,6 @@
#include <FL/fl_draw.H>
#include "Fl_Search_Chooser.H"
-#include "DataImage.H"
#include "choose_hill.H"
#include "util.h"
#include "GipfelWidget.H"
@@ -148,6 +147,11 @@ GipfelWidget::load_image(char *file) {
return 0;
}
+const char *
+GipfelWidget::get_image_filename() {
+ return img_file;
+}
+
int
GipfelWidget::save_image(char *file) {
char * args[32];
@@ -760,8 +764,50 @@ GipfelWidget::get_pixel(double a_view, double a_nick,
return 1;
}
-//printf("===> %s: %f, %f -> %d %d\n", img_file, a_view, a_nick, px, py);
- return DataImage::get_pixel_nearest(img, px + ((double) img->w()) / 2.0,
+ return get_pixel_nearest(img, px + ((double) img->w()) / 2.0,
py + ((double) img->h()) / 2.0, r, g, b);
}
+int
+GipfelWidget::get_pixel_nearest(Fl_Image *img, double x, double y,
+ char *r, char *g, char *b) {
+ if (isnan(x) || isnan(y)) {
+ return 1;
+ }
+
+ if ( img->d() == 0 ) {
+ return 1;
+ }
+
+ if (x < 0 || x >=img->w() || y < 0 || y >= img->h()) {
+ return 1;
+ }
+ long index = (y * img->w() * img->d()) + (x * img->d()); // X/Y -> buf index
+ switch ( img->count() ) {
+ case 1: { // bitmap
+ const char *buf = img->data()[0];
+ switch ( img->d() ) {
+ case 1: { // 8bit
+ *r = *g = *b = *(buf+index);
+ break;
+ }
+ case 3: // 24bit
+ *r = *(buf+index+0);
+ *g = *(buf+index+1);
+ *b = *(buf+index+2);
+ break;
+ default: // ??
+ printf("Not supported: chans=%d\n", img->d());
+ return 1;
+ }
+ break;
+ }
+ default: // ?? pixmap, bit vals
+ printf("Not supported: count=%d\n", img->count());
+ return 1;
+ }
+
+ return 0;
+
+}
+
diff --git a/src/JPEGOutputImage.H b/src/JPEGOutputImage.H
index bf1c6c1..31bdd76 100644
--- a/src/JPEGOutputImage.H
+++ b/src/JPEGOutputImage.H
@@ -23,6 +23,7 @@
#include <stdio.h>
extern "C" {
#include <jpeglib.h>
+#undef HAVE_STDLIB_H
}
#include "OutputImage.H"
diff --git a/src/Stitch.H b/src/Stitch.H
index bc8436e..0bb6d48 100644
--- a/src/Stitch.H
+++ b/src/Stitch.H
@@ -21,13 +21,16 @@
#define STITCH_H
#include "GipfelWidget.H"
-#include "DataImage.H"
+#include "OutputImage.H"
#define MAX_PICS 256
+
class Stitch {
private:
GipfelWidget *gipf[MAX_PICS];
+ OutputImage *single_images[MAX_PICS];
+ OutputImage *merged_image;
public:
@@ -36,8 +39,12 @@ class Stitch {
~Stitch();
int load_image(char *file);
-
- int resample(DataImage *img,
+
+ OutputImage * set_output(OutputImage *img);
+
+ OutputImage * set_output(const char *file, OutputImage *img);
+
+ int resample(int w, int h,
double view_start, double view_end);
};
diff --git a/src/Stitch.cxx b/src/Stitch.cxx
index 535995f..1fe3d88 100644
--- a/src/Stitch.cxx
+++ b/src/Stitch.cxx
@@ -26,6 +26,7 @@
#include <Fl/Fl.H>
+#include "OutputImage.H"
#include "Stitch.H"
static double pi_d = asin(1.0) * 2.0;
@@ -33,7 +34,9 @@ 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() {
@@ -63,34 +66,86 @@ Stitch::load_image(char *file) {
}
+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(DataImage *img,
+Stitch::resample(int w, int h,
double view_start, double view_end) {
- double step_view = (view_end - view_start) / img->w();
+ double step_view = (view_end - view_start) / w;
char r, g, b;
- int y_off = img->h() / 2;
- double radius = (double) img->w() / (view_end -view_start);
+ int y_off = h / 2;
+ int merged_pixel_set;
+ double radius = (double) w / (view_end -view_start);
- for (int y=0; y<img->h(); y++) {
+ 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<img->w(); x++) {
+ 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) {
- img->set_pixel(x, y, r, g, b);
- break;
+ 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 (y % (img->h() / 100 + 1) == 0) {
- img->redraw();
- Fl::check();
+ if (merged_image) {
+ merged_image->done();
+ }
+ for (int i=0; i<MAX_PICS; i++) {
+ if (single_images[i]) {
+ single_images[i]->done();
}
}
}
diff --git a/src/gipfel.cxx b/src/gipfel.cxx
index d8cea1c..5cd170a 100644
--- a/src/gipfel.cxx
+++ b/src/gipfel.cxx
@@ -41,7 +41,7 @@
#include "Fl_Value_Dial.H"
#include "Fl_Search_Chooser.H"
#include "GipfelWidget.H"
-#include "DataImage.H"
+#include "JPEGOutputImage.H"
#include "Stitch.H"
#include "choose_hill.H"
#include "../config.h"
@@ -62,7 +62,6 @@ Fl_Value_Input *i_view_lat, *i_view_long, *i_view_height;
Fl_Box *b_viewpoint;
Fl_Menu_Bar *mb;
-static int tiffstitch(int stitch_w, int stitch_h, int argc, char **argv);
static int stitch(int stitch_w, int stitch_h, int argc, char **argv);
void set_values() {
@@ -324,13 +323,13 @@ int main(int argc, char** argv) {
char c, *sep, *tmp, **my_argv;
char *view_point = NULL;
int err, bflag = 0, dflag = 0, my_argc;
- int stitch_flag = 0, tiff_flag = 0, stitch_w = 2000, stitch_h = 500;
+ int stitch_flag = 0, stitch_w = 2000, stitch_h = 500;
Fl_Window *control_win, *view_win;
Fl_Scroll *scroll;
err = 0;
- while ((c = getopt(argc, argv, "d:v:sw:b:t")) != EOF) {
+ while ((c = getopt(argc, argv, "d:v:sw:b:")) != EOF) {
switch (c) {
case 'h':
usage();
@@ -345,10 +344,6 @@ int main(int argc, char** argv) {
case 's':
stitch_flag++;
break;
- case 't':
- stitch_flag++;
- tiff_flag++;
- break;
case 'w':
stitch_w = atoi(optarg);
break;
@@ -374,11 +369,7 @@ int main(int argc, char** argv) {
}
if (stitch_flag) {
- if (tiff_flag) {
- tiffstitch(stitch_w, stitch_h, my_argc, my_argv);
- } else {
- stitch(stitch_w, stitch_h, my_argc, my_argv);
- }
+ stitch(stitch_w, stitch_h, my_argc, my_argv);
exit(0);
}
@@ -427,6 +418,7 @@ int main(int argc, char** argv) {
return Fl::run();
}
+#if 0
static int tiffstitch(int stitch_w, int stitch_h, int argc, char **argv) {
char buf[256];
@@ -445,6 +437,7 @@ static int tiffstitch(int stitch_w, int stitch_h, int argc, char **argv) {
return 0;
}
+#endif
static int stitch(int stitch_w, int stitch_h, int argc, char **argv) {
@@ -455,16 +448,18 @@ static int stitch(int stitch_w, int stitch_h, int argc, char **argv) {
for (int i=0; i<argc; i++) {
st->load_image(argv[i]);
}
-
+#if 0
win = new Fl_Window(0,0, 1000, stitch_h);
scroll = new Fl_Scroll(0, 0, win->w(), win->h());
- DataImage *img = new DataImage(0, 0, stitch_w, stitch_h);
+ PreviewOutputImage *img = new PreviewOutputImage();
win->resizable(scroll);
win->show(0, argv);
st->resample(img, 0.0, 7.0);
+#endif
- img->write_jpeg("/tmp/bla.jpg", 90);
+ st->set_output((OutputImage*) new JPEGOutputImage("/tmp/bla.jpg", 90));
+ st->resample(stitch_w, stitch_h, 0.0, 7.0);
Fl::run();
return 0;