summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMatthias Melcher <fltk@matthiasm.com>2018-04-01 16:16:12 +0000
committerMatthias Melcher <fltk@matthiasm.com>2018-04-01 16:16:12 +0000
commit532099da236bda5992759b77d62c482194e8e7b9 (patch)
tree10800b4ee57b8f5e97f2b9d2788ca679dc984fd6 /src
parentf49267e85b427a66523cff3efc236ec8db5e4051 (diff)
Android: Drawing RGB and monochrome image data on the fly from a buffer. Untested.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.4@12819 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src')
-rw-r--r--src/drivers/Android/Fl_Android_Graphics_Driver.H6
-rw-r--r--src/drivers/Android/Fl_Android_Graphics_Driver.cxx58
2 files changed, 58 insertions, 6 deletions
diff --git a/src/drivers/Android/Fl_Android_Graphics_Driver.H b/src/drivers/Android/Fl_Android_Graphics_Driver.H
index db57b97f6..a8c7ddfd7 100644
--- a/src/drivers/Android/Fl_Android_Graphics_Driver.H
+++ b/src/drivers/Android/Fl_Android_Graphics_Driver.H
@@ -69,13 +69,11 @@ protected:
virtual fl_uintptr_t cache(Fl_Bitmap *img) override;
/** Support function for Fl_RGB_Image drawing */
virtual void uncache(Fl_RGB_Image *img, fl_uintptr_t &id_, fl_uintptr_t &mask_) override;
-#if 0
// --- implementation is in src/drivers/xxx/Fl_xxx_Graphics_Driver_image.cxx
/** see fl_draw_image(const uchar* buf, int X,int Y,int W,int H, int D, int L) */
- virtual void draw_image(const uchar* buf, int X,int Y,int W,int H, int D=3, int L=0) {}
+ virtual void draw_image(const uchar* buf, int X,int Y,int W,int H, int D=3, int L=0) override;
/** see fl_draw_image_mono(const uchar* buf, int X,int Y,int W,int H, int D, int L) */
- virtual void draw_image_mono(const uchar* buf, int X,int Y,int W,int H, int D=1, int L=0) {}
-#endif
+ virtual void draw_image_mono(const uchar* buf, int X,int Y,int W,int H, int D=1, int L=0) override;
/** see fl_draw_image(Fl_Draw_Image_Cb cb, void* data, int X,int Y,int W,int H, int D) */
virtual void draw_image(Fl_Draw_Image_Cb cb, void* data, int X,int Y,int W,int H, int D=3) override;
/** see fl_draw_image_mono(Fl_Draw_Image_Cb cb, void* data, int X,int Y,int W,int H, int D) */
diff --git a/src/drivers/Android/Fl_Android_Graphics_Driver.cxx b/src/drivers/Android/Fl_Android_Graphics_Driver.cxx
index 943163521..d4cd77951 100644
--- a/src/drivers/Android/Fl_Android_Graphics_Driver.cxx
+++ b/src/drivers/Android/Fl_Android_Graphics_Driver.cxx
@@ -1116,6 +1116,60 @@ void Fl_Android_Graphics_Driver::draw(Fl_RGB_Image *img, int XP, int YP, int WP,
}
}
+
+/**
+ * Copy RGB (or RGBA?) image data directly onto the surface.
+ * TODO: I did not find documentation on the possible values of D. If D is four, does that
+ * mean that the fourth value must be an alpha value, and should that be applied here?
+ * What does a negative D indicate?
+ */
+void Fl_Android_Graphics_Driver::draw_image(const uchar* buf, int X,int Y,int W,int H, int D, int L)
+{
+ int srcDelta = abs(D);
+ int srcStride = W*srcDelta+L;
+ for (const auto &it: pClippingRegion.overlapping(Fl_Rect_Region(X, Y, W, H))) {
+ Fl_Rect_Region *r = &it->clipped_rect();
+ int rBottom = r->bottom();
+ int rRight = r->right();
+ for (int iy=r->top(); iy<rBottom;iy++) {
+ const uchar *src = buf + iy*srcStride;
+ uint16_t *dst = pBits + iy*pStride + r->left();
+ for (int ix=r->left();ix<rRight;ix++) {
+ uint16_t c = make565(src[0], src[1], src[2]);
+ src += srcDelta;
+ *dst++ = c;
+ }
+ }
+ }
+}
+
+/**
+ * Copy RGB (or RGBA?) image data directly onto the surface.
+ * TODO: I did not find documentation on the possible values of D. If D is four, does that
+ * mean that the fourth value must be an alpha value, and should that be applied here?
+ * What does a negative D indicate?
+ */
+void Fl_Android_Graphics_Driver::draw_image_mono(const uchar* buf, int X,int Y,int W,int H, int D, int L)
+{
+ int srcDelta = abs(D);
+ int srcStride = W*srcDelta+L;
+ for (const auto &it: pClippingRegion.overlapping(Fl_Rect_Region(X, Y, W, H))) {
+ Fl_Rect_Region *r = &it->clipped_rect();
+ int rBottom = r->bottom();
+ int rRight = r->right();
+ for (int iy=r->top(); iy<rBottom;iy++) {
+ const uchar *src = buf + iy*srcStride;
+ uint16_t *dst = pBits + iy*pStride + r->left();
+ for (int ix=r->left();ix<rRight;ix++) {
+ uchar l = src[0];
+ uint16_t c = make565(l, l, l);
+ src += srcDelta;
+ *dst++ = c;
+ }
+ }
+ }
+}
+
/*
* Draw some graphics line-by-line directly onto this surface
* TODO: I did not find documentation on the possible values of D. If D is four, does that
@@ -1126,7 +1180,7 @@ void Fl_Android_Graphics_Driver::draw_image(Fl_Draw_Image_Cb cb, void* data, int
int srcDelta = abs(D);
for (const auto &it: pClippingRegion.overlapping(Fl_Rect_Region(X, Y, W, H))) {
Fl_Rect_Region *r = &it->clipped_rect();
- uchar *buf = (uchar*)malloc(srcDelta*r->w());
+ uchar *buf = (uchar*)malloc(size_t(srcDelta*r->w()));
int rBottom = r->bottom();
int rRight = r->right();
for (int iy=r->top(); iy<rBottom;iy++) {
@@ -1155,7 +1209,7 @@ void Fl_Android_Graphics_Driver::draw_image_mono(Fl_Draw_Image_Cb cb, void* data
int srcDelta = abs(D);
for (const auto &it: pClippingRegion.overlapping(Fl_Rect_Region(X, Y, W, H))) {
Fl_Rect_Region *r = &it->clipped_rect();
- uchar *buf = (uchar*)malloc(srcDelta*r->w());
+ uchar *buf = (uchar*)malloc(size_t(srcDelta*r->w()));
int rBottom = r->bottom();
int rRight = r->right();
for (int iy=r->top(); iy<rBottom;iy++) {