summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/GipfelWidget.H9
-rw-r--r--src/GipfelWidget.cxx46
-rw-r--r--src/Stitch.cxx2
3 files changed, 49 insertions, 8 deletions
diff --git a/src/GipfelWidget.H b/src/GipfelWidget.H
index e1708f2..cba4513 100644
--- a/src/GipfelWidget.H
+++ b/src/GipfelWidget.H
@@ -37,10 +37,13 @@ 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);
+ uchar *r, uchar *g, uchar *b);
+
+ static int get_pixel_bilinear(Fl_Image *img, double x, double y,
+ uchar *r, uchar *g, uchar *b);
static int get_pixel(Fl_Image *img, int x, int y,
- char *r, char *g, char *b);
+ uchar *r, uchar *g, uchar *b);
public:
GipfelWidget(int X,int Y,int W, int H);
@@ -114,7 +117,7 @@ class GipfelWidget : public Fl_Widget {
int update();
int get_pixel(double a_view, double a_nick,
- char *r, char *g, char *b);
+ uchar *r, uchar *g, uchar *b);
void draw();
};
diff --git a/src/GipfelWidget.cxx b/src/GipfelWidget.cxx
index aa8469f..e1dad77 100644
--- a/src/GipfelWidget.cxx
+++ b/src/GipfelWidget.cxx
@@ -673,7 +673,7 @@ GipfelWidget::handle(int event) {
int
GipfelWidget::get_pixel(double a_view, double a_nick,
- char *r, char *g, char *b) {
+ uchar *r, uchar *g, uchar *b) {
double px, py;
@@ -685,13 +685,13 @@ GipfelWidget::get_pixel(double a_view, double a_nick,
return 1;
}
- return get_pixel_nearest(img, px + ((double) img->w()) / 2.0,
+ return get_pixel_bilinear(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) {
+ uchar *r, uchar *g, uchar *b) {
if (isnan(x) || isnan(y)) {
return 1;
} else {
@@ -699,10 +699,48 @@ GipfelWidget::get_pixel_nearest(Fl_Image *img, double x, double y,
}
}
+int
+GipfelWidget::get_pixel_bilinear(Fl_Image *img, double x, double y,
+ uchar *r, uchar *g, uchar *b) {
+ uchar a_r[4] = {0, 0, 0, 0};
+ uchar a_g[4] = {0, 0, 0, 0};
+ uchar a_b[4] = {0, 0, 0, 0};
+ float v0 , v1;
+ int fl_x = (int) floor(x);
+ int fl_y = (int) floor(y);
+ int i, n;
+
+ i = 0;
+ n = 0;
+ for (int iy = 0; iy <= 1; iy++) {
+ for (int ix = 0; ix <= 1; ix++) {
+ n += get_pixel(img, fl_x + ix, fl_y + iy, &(a_r[i]), &(a_g[i]), &(a_b[i]));
+ i++;
+ }
+ }
+
+ v0 = a_r[0] * (1 - (x - fl_x)) + a_r[1] * (x - fl_x);
+ v1 = a_r[2] * (1 - (x - fl_x)) + a_r[3] * (x - fl_x);
+ *r = (uchar) rint(v0 * (1 - (y - fl_y)) + v1 * (y - fl_y));
+
+ v0 = a_g[0] * (1 - (x - fl_x)) + a_g[1] * (x - fl_x);
+ v1 = a_g[2] * (1 - (x - fl_x)) + a_g[3] * (x - fl_x);
+ *g = (uchar) rint(v0 * (1 - (y - fl_y)) + v1 * (y - fl_y));
+
+ v0 = a_b[0] * (1 - (x - fl_x)) + a_b[1] * (x - fl_x);
+ v1 = a_b[2] * (1 - (x - fl_x)) + a_b[3] * (x - fl_x);
+ *b = (uchar) rint(v0 * (1 - (y - fl_y)) + v1 * (y - fl_y));
+
+ if (n >= 1) {
+ return 1;
+ } else {
+ return 0;
+ }
+}
int
GipfelWidget::get_pixel(Fl_Image *img, int x, int y,
- char *r, char *g, char *b) {
+ uchar *r, uchar *g, uchar *b) {
if ( img->d() == 0 ) {
return 1;
}
diff --git a/src/Stitch.cxx b/src/Stitch.cxx
index 7e8f909..f45bda4 100644
--- a/src/Stitch.cxx
+++ b/src/Stitch.cxx
@@ -80,7 +80,7 @@ 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;
+ uchar r, g, b;
int y_off = h / 2;
int merged_pixel_set;
double radius = (double) w / (view_end -view_start);