summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorManolo Gouy <Manolo>2016-11-03 16:34:13 +0000
committerManolo Gouy <Manolo>2016-11-03 16:34:13 +0000
commit95a9edcb55513a6e4fd13893b16d225a837c499b (patch)
tree9b442e5244b7fd87a3252103bcd573212f4563cb
parentd3f1a3c167954a4c874162ed4986a2235109ac33 (diff)
Factorize repeated code across platform-specific graphics drivers and image types
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3-porting@12077 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
-rw-r--r--FL/Fl_Graphics_Driver.H2
-rw-r--r--src/Fl_Bitmap.cxx11
-rw-r--r--src/Fl_Graphics_Driver.cxx16
-rw-r--r--src/Fl_Pixmap.cxx36
-rw-r--r--src/drivers/GDI/Fl_GDI_Graphics_Driver_image.cxx19
-rw-r--r--src/drivers/Quartz/Fl_Quartz_Graphics_Driver_image.cxx17
-rw-r--r--src/drivers/Xlib/Fl_Xlib_Graphics_Driver_image.cxx6
7 files changed, 31 insertions, 76 deletions
diff --git a/FL/Fl_Graphics_Driver.H b/FL/Fl_Graphics_Driver.H
index 3530d4423..02aab1a9a 100644
--- a/FL/Fl_Graphics_Driver.H
+++ b/FL/Fl_Graphics_Driver.H
@@ -135,6 +135,8 @@ protected:
virtual Fl_Bitmask create_bitmask(int w, int h, const uchar *array) {return 0; }
/** Support function for image drawing */
virtual void delete_bitmask(Fl_Bitmask bm) {}
+ int start_image(int XP, int YP, int WP, int HP, int w, int h, int &cx, int &cy,
+ int &X, int &Y, int &W, int &H);
// accessor functions to protected image members
static fl_uintptr_t* id(Fl_RGB_Image *rgb) {return &(rgb->id_);}
static fl_uintptr_t* id(Fl_Pixmap *pm) {return &(pm->id_);}
diff --git a/src/Fl_Bitmap.cxx b/src/Fl_Bitmap.cxx
index 58fa411fe..4606f05e3 100644
--- a/src/Fl_Bitmap.cxx
+++ b/src/Fl_Bitmap.cxx
@@ -121,16 +121,7 @@ int Fl_Bitmap::start(int XP, int YP, int WP, int HP, int &cx, int &cy,
draw_empty(XP, YP);
return 1;
}
- // account for current clip region (faster on Irix):
- fl_clip_box(XP,YP,WP,HP,X,Y,W,H);
- cx += X-XP; cy += Y-YP;
- // clip the box down to the size of image, quit if empty:
- if (cx < 0) {W += cx; X -= cx; cx = 0;}
- if (cx+W > w()) W = w()-cx;
- if (W <= 0) return 1;
- if (cy < 0) {H += cy; Y -= cy; cy = 0;}
- if (cy+H > h()) H = h()-cy;
- if (H <= 0) return 1;
+ if (fl_graphics_driver->start_image(XP,YP,WP,HP,w(),h(),cx,cy,X,Y,W,H)) return 1;
if (!id_)
id_ = fl_graphics_driver->cache(this, w(), h(), array);
return 0;
diff --git a/src/Fl_Graphics_Driver.cxx b/src/Fl_Graphics_Driver.cxx
index 788dbccce..95bae84a1 100644
--- a/src/Fl_Graphics_Driver.cxx
+++ b/src/Fl_Graphics_Driver.cxx
@@ -134,6 +134,22 @@ void Fl_Graphics_Driver::XDestroyRegion(Fl_Region r)
// nothing to do, reimplement in driver if needed
}
+/** Helper function for image drawing by platform-specific graphics drivers */
+int Fl_Graphics_Driver::start_image(int XP, int YP, int WP, int HP, int w, int h, int &cx, int &cy,
+ int &X, int &Y, int &W, int &H)
+{
+ // account for current clip region (faster on Irix):
+ clip_box(XP,YP,WP,HP,X,Y,W,H);
+ cx += X-XP; cy += Y-YP;
+ // clip the box down to the size of image, quit if empty:
+ if (cx < 0) {W += cx; X -= cx; cx = 0;}
+ if (cx+W > w) W = w-cx;
+ if (W <= 0) return 1;
+ if (cy < 0) {H += cy; Y -= cy; cy = 0;}
+ if (cy+H > h) H = h-cy;
+ if (H <= 0) return 1;
+ return 0;
+}
//
// End of "$Id$".
diff --git a/src/Fl_Pixmap.cxx b/src/Fl_Pixmap.cxx
index 68a70f50c..1fc8fa76b 100644
--- a/src/Fl_Pixmap.cxx
+++ b/src/Fl_Pixmap.cxx
@@ -49,41 +49,19 @@ void Fl_Pixmap::draw(int XP, int YP, int WP, int HP, int cx, int cy) {
fl_graphics_driver->draw(this, XP, YP, WP, HP, cx, cy);
}
-static int start(Fl_Pixmap *pxm, int XP, int YP, int WP, int HP, int w, int h, int &cx, int &cy,
- int &X, int &Y, int &W, int &H)
-{
- // ignore empty or bad pixmap data:
- if (!pxm->data()) {
- return 2;
- }
- if (WP == -1) {
- WP = w;
- HP = h;
- }
- if (!w) {
- return 2;
- }
- // account for current clip region (faster on Irix):
- fl_clip_box(XP,YP,WP,HP,X,Y,W,H);
- cx += X-XP; cy += Y-YP;
- // clip the box down to the size of image, quit if empty:
- if (cx < 0) {W += cx; X -= cx; cx = 0;}
- if (cx+W > w) W = w-cx;
- if (W <= 0) return 1;
- if (cy < 0) {H += cy; Y -= cy; cy = 0;}
- if (cy+H > h) H = h-cy;
- if (H <= 0) return 1;
- return 0;
-}
int Fl_Pixmap::prepare(int XP, int YP, int WP, int HP, int &cx, int &cy,
int &X, int &Y, int &W, int &H) {
if (w() < 0) measure();
- int code = start(this, XP, YP, WP, HP, w(), h(), cx, cy, X, Y, W, H);
- if (code) {
- if (code == 2) draw_empty(XP, YP);
+ if (!data() || !w()) {
+ draw_empty(XP, YP);
return 1;
}
+ if (WP == -1) {
+ WP = w();
+ HP = h();
+ }
+ if ( fl_graphics_driver->start_image(XP,YP,WP,HP,w(),h(),cx,cy,X,Y,W,H) ) return 1;
if (!id_) {
id_ = fl_graphics_driver->cache(this, w(), h(), data());
}
diff --git a/src/drivers/GDI/Fl_GDI_Graphics_Driver_image.cxx b/src/drivers/GDI/Fl_GDI_Graphics_Driver_image.cxx
index 01ce91b59..4f7e1beb0 100644
--- a/src/drivers/GDI/Fl_GDI_Graphics_Driver_image.cxx
+++ b/src/drivers/GDI/Fl_GDI_Graphics_Driver_image.cxx
@@ -483,23 +483,6 @@ static Fl_Offscreen build_id(Fl_RGB_Image *img, void **pmask)
}
-static int start(Fl_RGB_Image *img, int XP, int YP, int WP, int HP, int w, int h, int &cx, int &cy,
- int &X, int &Y, int &W, int &H)
-{
- // account for current clip region (faster on Irix):
- fl_clip_box(XP,YP,WP,HP,X,Y,W,H);
- cx += X-XP; cy += Y-YP;
- // clip the box down to the size of image, quit if empty:
- if (cx < 0) {W += cx; X -= cx; cx = 0;}
- if (cx+W > w) W = w-cx;
- if (W <= 0) return 1;
- if (cy < 0) {H += cy; Y -= cy; cy = 0;}
- if (cy+H > h) H = h-cy;
- if (H <= 0) return 1;
- return 0;
-}
-
-
void Fl_GDI_Graphics_Driver::draw(Fl_RGB_Image *img, int XP, int YP, int WP, int HP, int cx, int cy) {
int X, Y, W, H;
// Don't draw an empty image...
@@ -507,7 +490,7 @@ void Fl_GDI_Graphics_Driver::draw(Fl_RGB_Image *img, int XP, int YP, int WP, int
Fl_Graphics_Driver::draw_empty(img, XP, YP);
return;
}
- if (::start(img, XP, YP, WP, HP, img->w(), img->h(), cx, cy, X, Y, W, H)) {
+ if (start_image(XP, YP, WP, HP, img->w(), img->h(), cx, cy, X, Y, W, H)) {
return;
}
if (!*Fl_Graphics_Driver::id(img)) *Fl_Graphics_Driver::id(img) = (fl_uintptr_t)build_id(img, (void**)(Fl_Graphics_Driver::mask(img)));
diff --git a/src/drivers/Quartz/Fl_Quartz_Graphics_Driver_image.cxx b/src/drivers/Quartz/Fl_Quartz_Graphics_Driver_image.cxx
index 8dec36f07..ef64204a1 100644
--- a/src/drivers/Quartz/Fl_Quartz_Graphics_Driver_image.cxx
+++ b/src/drivers/Quartz/Fl_Quartz_Graphics_Driver_image.cxx
@@ -147,21 +147,6 @@ static void imgProviderReleaseData (void *info, const void *data, size_t size)
delete[] (unsigned char *)data;
}
-static int start(Fl_RGB_Image *img, int XP, int YP, int WP, int HP, int w, int h, int &cx, int &cy,
- int &X, int &Y, int &W, int &H)
-{
- // account for current clip region (faster on Irix):
- fl_clip_box(XP,YP,WP,HP,X,Y,W,H);
- cx += X-XP; cy += Y-YP;
- // clip the box down to the size of image, quit if empty:
- if (cx < 0) {W += cx; X -= cx; cx = 0;}
- if (cx+W > w) W = w-cx;
- if (W <= 0) return 1;
- if (cy < 0) {H += cy; Y -= cy; cy = 0;}
- if (cy+H > h) H = h-cy;
- if (H <= 0) return 1;
- return 0;
-}
void Fl_Quartz_Graphics_Driver::draw(Fl_RGB_Image *img, int XP, int YP, int WP, int HP, int cx, int cy) {
int X, Y, W, H;
@@ -170,7 +155,7 @@ void Fl_Quartz_Graphics_Driver::draw(Fl_RGB_Image *img, int XP, int YP, int WP,
Fl_Graphics_Driver::draw_empty(img, XP, YP);
return;
}
- if (::start(img, XP, YP, WP, HP, img->w(), img->h(), cx, cy, X, Y, W, H)) {
+ if (start_image(XP, YP, WP, HP, img->w(), img->h(), cx, cy, X, Y, W, H)) {
return;
}
if (!*Fl_Graphics_Driver::id(img)) {
diff --git a/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_image.cxx b/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_image.cxx
index eea701a33..82d35f515 100644
--- a/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_image.cxx
+++ b/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_image.cxx
@@ -628,7 +628,7 @@ void Fl_Xlib_Graphics_Driver::draw(Fl_Bitmap *bm, int XP, int YP, int WP, int HP
}
-static int start(Fl_RGB_Image *img, int XP, int YP, int WP, int HP, int w, int h, int &cx, int &cy,
+/*static int start_rgb(int XP, int YP, int WP, int HP, int w, int h, int &cx, int &cy,
int &X, int &Y, int &W, int &H)
{
// account for current clip region (faster on Irix):
@@ -642,7 +642,7 @@ static int start(Fl_RGB_Image *img, int XP, int YP, int WP, int HP, int w, int h
if (cy+H > h) H = h-cy;
if (H <= 0) return 1;
return 0;
-}
+}*/
// Composite an image with alpha on systems that don't have accelerated
@@ -710,7 +710,7 @@ void Fl_Xlib_Graphics_Driver::draw(Fl_RGB_Image *img, int XP, int YP, int WP, in
Fl_Graphics_Driver::draw_empty(img, XP, YP);
return;
}
- if (::start(img, XP, YP, WP, HP, img->w(), img->h(), cx, cy, X, Y, W, H)) {
+ if (start_image(XP, YP, WP, HP, img->w(), img->h(), cx, cy, X, Y, W, H)) {
return;
}
if (!*Fl_Graphics_Driver::id(img)) {