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
This commit is contained in:
parent
936fbd096f
commit
f49267e85b
@ -323,7 +323,7 @@ test/cairo_test.cxx test/pixmap.cxx
|
||||
test/checkers.cxx test/pixmap_browser.cxx
|
||||
test/clock.cxx test/resizebox.cxx
|
||||
test/colbrowser.cxx test/rotated_text.cxx
|
||||
* test/color_chooser.cxx: - can't draw 'on the fly' yet
|
||||
* test/color_chooser.cxx:+ 'color_chooser' works
|
||||
test/scroll.cxx
|
||||
test/connect.cxx test/shape.cxx
|
||||
test/cube.cxx test/subwindow.cxx
|
||||
|
@ -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) {}
|
||||
/** 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) {}
|
||||
/** 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
|
||||
/** 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) */
|
||||
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);
|
||||
|
@ -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&)
|
||||
{
|
||||
|
@ -28,7 +28,7 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#if !defined(_WIN32) && !defined(__APPLE__) && !defined(FL_PORTING)
|
||||
#if !defined(_WIN32) && !defined(__APPLE__) && !defined(FL_PORTING) && !defined(__ANDROID__)
|
||||
#include "list_visuals.cxx"
|
||||
#endif
|
||||
|
||||
@ -114,7 +114,7 @@ int main(int argc, char ** argv) {
|
||||
" - : default visual\n"
|
||||
" r : call Fl::visual(FL_RGB)\n"
|
||||
" c : call Fl::own_colormap()\n",argv[0]);
|
||||
#if !defined(_WIN32) && !defined(__APPLE__) && !defined(FL_PORTING)
|
||||
#if !defined(_WIN32) && !defined(__APPLE__) && !defined(FL_PORTING) && !defined(__ANDROID__)
|
||||
printf(" # : use this visual with an empty colormap:\n");
|
||||
list_visuals();
|
||||
#endif
|
||||
@ -127,7 +127,7 @@ int main(int argc, char ** argv) {
|
||||
} else if (argv[i][0] == 'c') {
|
||||
Fl::own_colormap();
|
||||
} else if (argv[i][0] != '-') {
|
||||
#if !defined(_WIN32) && !defined(__APPLE__) && !defined(FL_PORTING)
|
||||
#if !defined(_WIN32) && !defined(__APPLE__) && !defined(FL_PORTING) && !defined(__ANDROID__)
|
||||
int visid = atoi(argv[i]);
|
||||
fl_open_display();
|
||||
XVisualInfo templt; int num;
|
||||
|
Loading…
Reference in New Issue
Block a user