summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMatthias Melcher <fltk@matthiasm.com>2018-04-01 16:06:12 +0000
committerMatthias Melcher <fltk@matthiasm.com>2018-04-01 16:06:12 +0000
commitf49267e85b427a66523cff3efc236ec8db5e4051 (patch)
tree4fa527fad89692de7add95b6f2325af81a0336d7 /src
parent936fbd096f3cf1df506bf98a7dd9bece5391b624 (diff)
Android: Drawing RGB image data on the fly via callback
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.4@12818 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src')
-rw-r--r--src/drivers/Android/Fl_Android_Graphics_Driver.H7
-rw-r--r--src/drivers/Android/Fl_Android_Graphics_Driver.cxx71
2 files changed, 68 insertions, 10 deletions
diff --git a/src/drivers/Android/Fl_Android_Graphics_Driver.H b/src/drivers/Android/Fl_Android_Graphics_Driver.H
index 198d32937..db57b97f6 100644
--- a/src/drivers/Android/Fl_Android_Graphics_Driver.H
+++ b/src/drivers/Android/Fl_Android_Graphics_Driver.H
@@ -75,11 +75,11 @@ protected:
virtual void draw_image(const uchar* buf, int X,int Y,int W,int H, int D=3, int L=0) {}
/** 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
/** 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) {}
+ 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) */
- virtual void draw_image_mono(Fl_Draw_Image_Cb cb, void* data, int X,int Y,int W,int H, int D=1) {}
-#endif
+ virtual void draw_image_mono(Fl_Draw_Image_Cb cb, void* data, int X,int Y,int W,int H, int D=1) override;
/** \brief Draws an Fl_RGB_Image object using this graphics driver. */
virtual void draw(Fl_RGB_Image * rgb,int XP, int YP, int WP, int HP, int cx, int cy) override;
/** \brief Draws an Fl_Pixmap object using this graphics driver.
@@ -301,6 +301,7 @@ public:
void make_current(Fl_Window*);
protected:
+ static uint16_t make565(uchar r, uchar g, uchar b);
static uint16_t make565(Fl_Color crgba);
void rectf_unclipped(int x, int y, int w, int h);
void xyline_unclipped(int x, int y, int x1);
diff --git a/src/drivers/Android/Fl_Android_Graphics_Driver.cxx b/src/drivers/Android/Fl_Android_Graphics_Driver.cxx
index a53cb7795..943163521 100644
--- a/src/drivers/Android/Fl_Android_Graphics_Driver.cxx
+++ b/src/drivers/Android/Fl_Android_Graphics_Driver.cxx
@@ -83,11 +83,11 @@ void Fl_Android_Graphics_Driver::make_current(Fl_Window *win)
}
-static uint16_t make565(int red, int green, int blue)
+uint16_t Fl_Android_Graphics_Driver::make565(uchar red, uchar green, uchar blue)
{
- return (uint16_t)( ((red << 8) & 0xf800) |
- ((green << 3) & 0x07e0) |
- ((blue >> 3) & 0x001f) );
+ return (uint16_t)( ((((uint16_t)(red)) << 8) & 0xf800) |
+ ((((uint16_t)(green)) << 3) & 0x07e0) |
+ ((((uint16_t)(blue)) >> 3) & 0x001f) );
}
extern unsigned fl_cmap[256];
@@ -96,9 +96,9 @@ extern unsigned fl_cmap[256];
uint16_t Fl_Android_Graphics_Driver::make565(Fl_Color crgba)
{
if (crgba<0x00000100) crgba = fl_cmap[crgba];
- return (uint16_t)( ((crgba >>16) & 0xf800) |
- ((crgba >>13) & 0x07e0) |
- ((crgba >>11) & 0x001f) );
+ return (uint16_t)( ((crgba >> 16) & 0xf800) |
+ ((crgba >> 13) & 0x07e0) |
+ ((crgba >> 11) & 0x001f) );
}
@@ -1116,6 +1116,63 @@ void Fl_Android_Graphics_Driver::draw(Fl_RGB_Image *img, int XP, int YP, int WP,
}
}
+/*
+ * 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
+ * mean that the fourth value must be an alpha value, and should that be applied here?
+ */
+void Fl_Android_Graphics_Driver::draw_image(Fl_Draw_Image_Cb cb, void* data, int X,int Y,int W,int H, int D)
+{
+ 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());
+ int rBottom = r->bottom();
+ int rRight = r->right();
+ for (int iy=r->top(); iy<rBottom;iy++) {
+ cb(data, r->left()-X, iy-Y, r->w(), buf);
+ uchar *src = buf;
+ 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;
+ }
+ }
+ free(buf);
+ }
+}
+
+/*
+ * 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 two, does that
+ * mean that the fourth value must be an alpha value, and should that be applied here?
+ * If it is three, doe we need to convert RGB to grayscale?
+ * What exactly does a negative value mean? Where is this all documented? Sigh.
+ */
+void Fl_Android_Graphics_Driver::draw_image_mono(Fl_Draw_Image_Cb cb, void* data, int X,int Y,int W,int H, int D)
+{
+ 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());
+ int rBottom = r->bottom();
+ int rRight = r->right();
+ for (int iy=r->top(); iy<rBottom;iy++) {
+ cb(data, r->left()-X, iy-Y, r->w(), buf);
+ uchar *src = buf;
+ 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;
+ }
+ }
+ free(buf);
+ }
+}
+
void Fl_Android_Graphics_Driver::uncache(Fl_RGB_Image*, fl_uintptr_t &id_, fl_uintptr_t&)
{