summaryrefslogtreecommitdiff
path: root/src/DataImage.cxx
diff options
context:
space:
mode:
authorJohannes Hofmann <Johannes.Hofmann@gmx.de>2006-06-25 09:51:23 +0200
committerJohannes Hofmann <Johannes.Hofmann@gmx.de>2006-06-25 09:51:23 +0200
commit8717d1dd411e7859a29e097e893956521bd1cd70 (patch)
tree68f4443562115d17073bcd6b4f93ce09070ba1d2 /src/DataImage.cxx
parentc58cf1232ea3134671d632dcba651fbf11eb0155 (diff)
import image data grabbing from
http://seriss.com/people/erco/fltk/#Fl_Image
Diffstat (limited to 'src/DataImage.cxx')
-rw-r--r--src/DataImage.cxx46
1 files changed, 46 insertions, 0 deletions
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;
+}
+
+
+
+
+
+
+