From faf5dff31fcbafb5cfa8575b85ffaf2408ff5d39 Mon Sep 17 00:00:00 2001 From: Johannes Hofmann Date: Mon, 18 Dec 2006 18:26:41 +0100 Subject: make bilinear resampling optional --- src/GipfelWidget.H | 9 +++++++-- src/GipfelWidget.cxx | 13 +++++++++---- src/Stitch.H | 4 ++-- src/Stitch.cxx | 7 ++++--- src/gipfel.cxx | 25 +++++++++++++++++-------- 5 files changed, 39 insertions(+), 19 deletions(-) (limited to 'src') diff --git a/src/GipfelWidget.H b/src/GipfelWidget.H index b6bb901..2210e07 100644 --- a/src/GipfelWidget.H +++ b/src/GipfelWidget.H @@ -46,6 +46,11 @@ class GipfelWidget : public Fl_Widget { uchar *r, uchar *g, uchar *b); public: + typedef enum { + NEAREST = 0, + BILINEAR = 1 + } sample_mode_t; + GipfelWidget(int X,int Y,int W, int H); void center(); @@ -114,8 +119,8 @@ class GipfelWidget : public Fl_Widget { int comp_params(); - int get_pixel(double a_alph, double a_nick, - uchar *r, uchar *g, uchar *b); + int get_pixel(GipfelWidget::sample_mode_t, + double a_alph, double a_nick, uchar *r, uchar *g, uchar *b); void draw(); }; diff --git a/src/GipfelWidget.cxx b/src/GipfelWidget.cxx index 5f75693..837a5fb 100644 --- a/src/GipfelWidget.cxx +++ b/src/GipfelWidget.cxx @@ -667,8 +667,8 @@ GipfelWidget::handle(int event) { } int -GipfelWidget::get_pixel(double a_alph, double a_nick, - uchar *r, uchar *g, uchar *b) { +GipfelWidget::get_pixel(GipfelWidget::sample_mode_t m, + double a_alph, double a_nick, uchar *r, uchar *g, uchar *b) { double px, py; if (img == NULL) { @@ -679,8 +679,13 @@ GipfelWidget::get_pixel(double a_alph, double a_nick, return 1; } - return get_pixel_bilinear(img, px + ((double) img->w()) / 2.0, - py + ((double) img->h()) / 2.0, r, g, b); + if (m == GipfelWidget::BILINEAR) { + return get_pixel_bilinear(img, px + ((double) img->w()) / 2.0, + py + ((double) img->h()) / 2.0, r, g, b); + } else { + return get_pixel_nearest(img, px + ((double) img->w()) / 2.0, + py + ((double) img->h()) / 2.0, r, g, b); + } } int diff --git a/src/Stitch.H b/src/Stitch.H index 49dd6b8..dcfc691 100644 --- a/src/Stitch.H +++ b/src/Stitch.H @@ -31,8 +31,8 @@ class Stitch { OutputImage * set_output(const char *file, OutputImage *img); - int resample(int w, int h, - double view_start, double view_end); + int resample(GipfelWidget::sample_mode_t m, + int w, int h, double view_start, double view_end); }; #endif diff --git a/src/Stitch.cxx b/src/Stitch.cxx index 6fd0d84..f21c140 100644 --- a/src/Stitch.cxx +++ b/src/Stitch.cxx @@ -78,8 +78,8 @@ Stitch::set_output(const char *file, OutputImage *img) { } int -Stitch::resample(int w, int h, - double view_start, double view_end) { +Stitch::resample(GipfelWidget::sample_mode_t m, + int w, int h, double view_start, double view_end) { view_start = view_start * deg2rad; view_end = view_end * deg2rad; @@ -109,7 +109,8 @@ Stitch::resample(int w, int h, for (int i=0; iget_pixel(a_view, a_nick, &r, &g, &b)==0) { + } else if (gipf[i]->get_pixel(m, a_view, a_nick, + &r, &g, &b) == 0) { if (single_images[i]) { single_images[i]->set_pixel(x, r, g, b); } diff --git a/src/gipfel.cxx b/src/gipfel.cxx index 491020d..ba62ff6 100644 --- a/src/gipfel.cxx +++ b/src/gipfel.cxx @@ -52,8 +52,9 @@ Fl_Menu_Bar *mb; #define STITCH_PREVIEW 1 #define STITCH_JPEG 2 #define STITCH_TIFF 4 -static int stitch(int stitch_w, int stitch_h, double from, double to, int type, const char *path, - int argc, char **argv); + +static int stitch(GipfelWidget::sample_mode_t m ,int stitch_w, int stitch_h, + double from, double to, int type, const char *path, int argc, char **argv); void set_values() { s_center->value(gipf->get_center_angle()); @@ -201,6 +202,7 @@ void usage() { " -d Use for GPS data.\n" " -u , Use distortion correction values k0,k1.\n" " -s Stitch mode.\n" + " -b Use bilinear interpolation for stitching.\n" " -w Width of result image.\n" " -h Height of result image.\n" " -j JPEG output file for Stitch mode.\n" @@ -316,6 +318,7 @@ int main(int argc, char** argv) { int err, my_argc; int stitch_flag = 0, stitch_w = 2000, stitch_h = 500; int jpeg_flag = 0, tiff_flag = 0, distortion_flag = 0; + int bilinear_flag = 0; double stitch_from = 0.0, stitch_to = 380.0; double dist_k0 = 0.0, dist_k1 = 0.0; char *outpath = "/tmp"; @@ -323,7 +326,7 @@ int main(int argc, char** argv) { err = 0; - while ((c = getopt(argc, argv, ":?d:v:s:w:h:j:t:u:")) != EOF) { + while ((c = getopt(argc, argv, ":?d:v:s:w:h:j:t:u:b")) != EOF) { switch (c) { case '?': usage(); @@ -367,6 +370,9 @@ int main(int argc, char** argv) { case 'h': stitch_h = atoi(optarg); break; + case 'b': + bilinear_flag++; + break; default: err++; } @@ -393,8 +399,10 @@ int main(int argc, char** argv) { type = STITCH_TIFF; } - stitch(stitch_w, stitch_h, stitch_from, stitch_to, + stitch(bilinear_flag?GipfelWidget::BILINEAR:GipfelWidget::NEAREST, + stitch_w, stitch_h, stitch_from, stitch_to, type, outpath, my_argc, my_argv); + exit(0); } @@ -450,7 +458,8 @@ int main(int argc, char** argv) { } static int -stitch(int stitch_w, int stitch_h, double from, double to, +stitch(GipfelWidget::sample_mode_t m, + int stitch_w, int stitch_h, double from, double to, int type, const char *path, int argc, char **argv) { Fl_Window *win; @@ -464,7 +473,7 @@ stitch(int stitch_w, int stitch_h, double from, double to, if (type == STITCH_JPEG) { st->set_output((OutputImage*) new JPEGOutputImage(path, 90)); - st->resample(stitch_w, stitch_h, from, to); + st->resample(m, stitch_w, stitch_h, from, to); } else if (type == STITCH_TIFF) { @@ -480,7 +489,7 @@ stitch(int stitch_w, int stitch_h, double from, double to, st->set_output(argv[i], (OutputImage*) new TIFFOutputImage(buf)); } - st->resample(stitch_w, stitch_h, from, to); + st->resample(m, stitch_w, stitch_h, from, to); } else { win = new Fl_Window(0,0, stitch_w, stitch_h); @@ -491,7 +500,7 @@ stitch(int stitch_w, int stitch_h, double from, double to, win->resizable(scroll); win->show(0, argv); st->set_output((OutputImage*) img); - st->resample(stitch_w, stitch_h, from, to); + st->resample(m, stitch_w, stitch_h, from, to); img->redraw(); Fl::run(); } -- cgit v1.2.3