summaryrefslogtreecommitdiff
path: root/src/DataImage.cxx
diff options
context:
space:
mode:
authorJohannes Hofmann <Johannes.Hofmann@gmx.de>2006-06-25 11:49:32 +0200
committerJohannes Hofmann <Johannes.Hofmann@gmx.de>2006-06-25 11:49:32 +0200
commit7d900b4ede22215413e4a0ddd1675c650ba3225f (patch)
tree6e39f45e68578ebc33e42b920c2370cefd954a3e /src/DataImage.cxx
parent8b9902ac6e239bd36681a2997ee1bdfa4239a5d8 (diff)
implement various helper methods
Diffstat (limited to 'src/DataImage.cxx')
-rw-r--r--src/DataImage.cxx29
1 files changed, 23 insertions, 6 deletions
diff --git a/src/DataImage.cxx b/src/DataImage.cxx
index 0775068..c230ed1 100644
--- a/src/DataImage.cxx
+++ b/src/DataImage.cxx
@@ -22,13 +22,14 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
-#include <math.h>
-#include "DataImage.H"
-
-DataImage::DataImage() {
+#include <Fl/fl_draw.h>
+#include "DataImage.H"
+DataImage::DataImage(int X, int Y, int W, int H): Fl_Widget(X, Y, W, H) {
+ d = 3;
+ data = (uchar*) malloc(W * H * d);
}
DataImage::~DataImage() {
@@ -38,10 +39,26 @@ DataImage::~DataImage() {
int
DataImage::set_pixel(int x, int y, char r, char g, char b) {
+ if (x < 0 || x >= w() || y < 0 || y >= h()) {
+ return 1;
+ }
+
+ long index = (y * w() * d + (x * d)); // X/Y -> buf index
+ *(data+index+0) = r;
+ *(data+index+1) = g;
+ *(data+index+2) = b;
+
+ return 0;
+}
+
+
+void
+DataImage::draw() {
+ fl_draw_image(data, 0, 0, w(), h(), d);
}
-static int
-DataImage::get_pixel(Fl_RGB_Image *img, int x, int y,
+int
+DataImage::get_pixel(Fl_Image *img, int x, int y,
char *r, char *g, char *b) {
if ( img->d() == 0 ) {
return 1;