diff options
author | Johannes Hofmann <Johannes.Hofmann@gmx.de> | 2006-06-25 09:51:23 +0200 |
---|---|---|
committer | Johannes Hofmann <Johannes.Hofmann@gmx.de> | 2006-06-25 09:51:23 +0200 |
commit | 8717d1dd411e7859a29e097e893956521bd1cd70 (patch) | |
tree | 68f4443562115d17073bcd6b4f93ce09070ba1d2 | |
parent | c58cf1232ea3134671d632dcba651fbf11eb0155 (diff) |
import image data grabbing from
http://seriss.com/people/erco/fltk/#Fl_Image
-rw-r--r-- | src/DataImage.H | 3 | ||||
-rw-r--r-- | src/DataImage.cxx | 46 |
2 files changed, 49 insertions, 0 deletions
diff --git a/src/DataImage.H b/src/DataImage.H index abeb4f5..99910e5 100644 --- a/src/DataImage.H +++ b/src/DataImage.H @@ -32,6 +32,9 @@ class DataImage : Fl_Widget { ~DataImage(); int set_pixel(nt x, int y, char r, char g, char b); + + static int get_pixel(Fl_RGB_Image *img, int x, int y, + char *r, char *g, char *b); }; #endif diff --git a/src/DataImage.cxx b/src/DataImage.cxx index 83881ff..0775068 100644 --- a/src/DataImage.cxx +++ b/src/DataImage.cxx @@ -39,3 +39,49 @@ DataImage::~DataImage() { int DataImage::set_pixel(int x, int y, char r, char g, char b) { } + +static int +DataImage::get_pixel(Fl_RGB_Image *img, int x, int y, + char *r, char *g, char *b) { + 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()); + exit(1); + } + + return 0; +} + + + + + + + |