summaryrefslogtreecommitdiff
path: root/src/GipfelWidget.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'src/GipfelWidget.cxx')
-rw-r--r--src/GipfelWidget.cxx52
1 files changed, 49 insertions, 3 deletions
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;
+
+}
+