summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohannes Hofmann <Johannes.Hofmann@gmx.de>2007-03-18 13:15:43 +0100
committerJohannes Hofmann <Johannes.Hofmann@gmx.de>2007-03-18 13:15:43 +0100
commiteba7fcd8f7f91f7076ee291438d86545fdb9856d (patch)
tree5cabb3c87ed7344b947f29f83f3b431dabdad218 /src
parent3b1c107918825178fc60e54cb818d9098a000293 (diff)
remove bilinear interpolation
Diffstat (limited to 'src')
-rw-r--r--src/GipfelWidget.H6
-rw-r--r--src/GipfelWidget.cxx67
2 files changed, 14 insertions, 59 deletions
diff --git a/src/GipfelWidget.H b/src/GipfelWidget.H
index ed251ef..0ddfbef 100644
--- a/src/GipfelWidget.H
+++ b/src/GipfelWidget.H
@@ -41,9 +41,6 @@ class GipfelWidget : public Fl_Widget {
static int get_pixel_nearest(Fl_Image *img, double x, double y,
int *r, int *g, int *b);
- static int get_pixel_bilinear(Fl_Image *img, double x, double y,
- int *r, int *g, int *b);
-
static int get_pixel_bicubic(Fl_Image *img, double x, double y,
int *r, int *g, int *b);
@@ -53,8 +50,7 @@ class GipfelWidget : public Fl_Widget {
public:
typedef enum {
NEAREST = 0,
- BILINEAR = 1,
- BICUBIC = 2
+ BICUBIC = 1
} sample_mode_t;
GipfelWidget(int X,int Y,int W, int H);
diff --git a/src/GipfelWidget.cxx b/src/GipfelWidget.cxx
index 2daea2a..73be7e2 100644
--- a/src/GipfelWidget.cxx
+++ b/src/GipfelWidget.cxx
@@ -683,10 +683,7 @@ GipfelWidget::get_pixel(GipfelWidget::sample_mode_t m,
return 1;
}
- if (m == GipfelWidget::BILINEAR) {
- ret = get_pixel_bilinear(img, px + ((double) img->w()) / 2.0,
- py + ((double) img->h()) / 2.0, r, g, b);
- } else if (m == GipfelWidget::BICUBIC) {
+ if (m == GipfelWidget::BICUBIC) {
ret = get_pixel_bicubic(img, px + ((double) img->w()) / 2.0,
py + ((double) img->h()) / 2.0, r, g, b);
} else {
@@ -715,71 +712,33 @@ GipfelWidget::get_pixel_nearest(Fl_Image *img, double x, double y,
}
}
-int
-GipfelWidget::get_pixel_bilinear(Fl_Image *img, double x, double y,
- int *r, int *g, int *b) {
- int a_r[4] = {0, 0, 0, 0};
- int a_g[4] = {0, 0, 0, 0};
- int 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 = (int) 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 = (int) 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 = (int) rint(v0 * (1 - (y - fl_y)) + v1 * (y - fl_y));
-
- if (n >= 1) {
- return 1;
- } else {
- return 0;
- }
-}
-
-static double
-interp_cubic(double x, double *v) {
+static inline double
+interp_cubic(double x, double x2, double x3, double *v) {
double a0, a1, a2, a3;
- double x2 = x * x;
a0 = v[3] - v[2] - v[0] + v[1];
a1 = v[0] - v[1] - a0;
a2 = v[2] - v[0];
a3 = v[1];
- return a0 * x * x2 +a1 * x2 + a2 * x + a3;
+ return a0 * x3 + a1 * x2 + a2 * x + a3;
}
int
GipfelWidget::get_pixel_bicubic(Fl_Image *img, double x, double y,
int *r, int *g, int *b) {
- int fl_x = (int) rint(x);
- int fl_y = (int) rint(y);
+ double fl_x = floor(x);
+ double fl_y = floor(y);
+ double dx = x - fl_x, dx2 = dx * dx, dx3 = dx2 * dx;
+ double dy = y - fl_y, dy2 = dy * dy, dy3 = dy2 * dy;
int ic[3];
double c[3][4];
double c1[3][4];
for (int iy = 0; iy < 4; iy++) {
for (int ix = 0; ix < 4; ix++) {
- if (get_pixel(img, fl_x + ix - 2, fl_y + iy - 2,
+ if (get_pixel(img, (int) fl_x + ix, (int) fl_y + iy,
&ic[0], &ic[1], &ic[2]) != 0) {
return 1;
}
@@ -790,13 +749,13 @@ GipfelWidget::get_pixel_bicubic(Fl_Image *img, double x, double y,
}
for (int l = 0; l < 3; l++) {
- c1[l][iy] = interp_cubic(x - fl_x, c[l]);
+ c1[l][iy] = interp_cubic(dx, dx2, dx3, c[l]);
}
}
- *r = (int) rint(interp_cubic(x - fl_x, c1[0]));
- *g = (int) rint(interp_cubic(x - fl_x, c1[1]));
- *b = (int) rint(interp_cubic(x - fl_x, c1[2]));
+ *r = (int) rint(interp_cubic(dy, dy2, dy3, c1[0]));
+ *g = (int) rint(interp_cubic(dy, dy2, dy3, c1[1]));
+ *b = (int) rint(interp_cubic(dy, dy2, dy3, c1[2]));
return 0;
}