summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorManolo Gouy <Manolo>2018-03-28 13:00:12 +0000
committerManolo Gouy <Manolo>2018-03-28 13:00:12 +0000
commit458d0636436b5f25e444dc285007dceac296c2ee (patch)
tree88510e081d4f4199db92879b4a1960ea22204769 /src
parent29bda776bb78352b331771bd1169de31e4edc1be (diff)
Image classes: memorise the width and the height of the cached form of the image to support GUI scaling
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.4@12811 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src')
-rw-r--r--src/Fl_Graphics_Driver.cxx39
-rw-r--r--src/Fl_Image.cxx4
-rw-r--r--src/Fl_Pixmap.cxx2
-rw-r--r--src/drivers/GDI/Fl_GDI_Graphics_Driver_image.cxx20
-rw-r--r--src/drivers/Xlib/Fl_Xlib_Graphics_Driver.H1
-rw-r--r--src/drivers/Xlib/Fl_Xlib_Graphics_Driver_image.cxx18
6 files changed, 58 insertions, 26 deletions
diff --git a/src/Fl_Graphics_Driver.cxx b/src/Fl_Graphics_Driver.cxx
index e1045b460..cbabda596 100644
--- a/src/Fl_Graphics_Driver.cxx
+++ b/src/Fl_Graphics_Driver.cxx
@@ -326,16 +326,18 @@ void Fl_Scalable_Graphics_Driver::draw(Fl_Pixmap *pxm, int XP, int YP, int WP, i
return;
}
// to allow rescale at runtime
- if (*id(pxm) && *cache_scale(pxm) != scale_) {
+ int w2=pxm->w(), h2=pxm->h();
+ cache_size(pxm, w2, h2); // after this, w2 x h2 is size of desired cached image
+ int *pw, *ph;
+ cache_w_h(pxm, pw, ph); // after this, *pw x *ph is current size of cached form of bitmap
+ if (*id(pxm) && (*pw != w2 || *ph != h2)) {
pxm->uncache();
}
if (!*id(pxm)) {
- int w2=pxm->w(), h2=pxm->h();
- cache_size(pxm, w2, h2); // after this, w2 x h2 is size of desired cached image
- if (pxm->data_w() != w2 || pxm->data_h() != h2) { // build a scaled id_ & pixmap_ for pxm
+ if (pxm->data_w() != w2 || pxm->data_h() != h2) { // build a scaled id_ & mask_ for pxm
Fl_Pixmap *pxm2 = (Fl_Pixmap*)pxm->copy(w2, h2);
*id(pxm) = cache(pxm2);
- *cache_scale(pxm) = scale_;
+ *pw = w2; *ph = h2; // memorize size of cached form of pixmap
*mask(pxm) = *mask(pxm2);
*mask(pxm2) = 0;
delete pxm2;
@@ -351,16 +353,18 @@ void Fl_Scalable_Graphics_Driver::draw(Fl_Bitmap *bm, int XP, int YP, int WP, in
if (Fl_Graphics_Driver::start_image(bm, XP, YP, WP, HP, cx, cy, X, Y, W, H)) {
return;
}
- if (*id(bm) && *cache_scale(bm) != scale_) {
+ int w2 = bm->w(), h2 = bm->h();
+ cache_size(bm, w2, h2); // after this, w2 x h2 is size of desired cached image
+ int *pw, *ph;
+ cache_w_h(bm, pw, ph); // after this, *pw x *ph is current size of cached form of bitmap
+ if (*id(bm) && (*pw != w2 || *ph != h2)) {
bm->uncache();
}
if (!*id(bm)) {
- int w2 = bm->w(), h2 = bm->h();
- cache_size(bm, w2, h2); // after this, w2 x h2 is size of desired cached image
if (bm->data_w() != w2 || bm->data_h() != h2) { // build a scaled id_ for bm
Fl_Bitmap *bm2 = (Fl_Bitmap*)bm->copy(w2, h2);
*id(bm) = cache(bm2);
- *cache_scale(bm) = scale_;
+ *pw = w2; *ph = h2; // memorize size of cached form of bitmap
delete bm2;
} else *id(bm) = cache(bm);
}
@@ -387,12 +391,18 @@ void Fl_Scalable_Graphics_Driver::draw(Fl_RGB_Image *img, int XP, int YP, int WP
if (done) return;
}
// to allow rescale at runtime
- if (*id(img) && *cache_scale(img) != scale_) {
+ int w2, h2, *pw, *ph;
+ if (need_scaled_drawing) {
+ w2 = img->w(); h2 = img->h();
+ cache_size(img, w2, h2);
+ } else {
+ w2 = img->data_w(); h2 = img->data_h();
+ } // after this, w2 x h2 is desired cached image size
+ cache_w_h(img, pw, ph); // after this, *pw x *ph is current size of cached image
+ if (*id(img) && (w2 != *pw || h2 != *ph )) {
img->uncache();
}
- if (!*id(img) && need_scaled_drawing ) { // build and draw a scaled id_ for img
- int w2=img->w(), h2=img->h();
- cache_size(img, w2, h2);
+ if (!*id(img) && need_scaled_drawing) { // build and draw a scaled id_ for img
Fl_RGB_Scaling keep = Fl_Image::RGB_scaling();
Fl_Image::RGB_scaling(Fl_Image::scaling_algorithm());
Fl_RGB_Image *img2 = (Fl_RGB_Image*)img->copy(w2, h2);
@@ -400,7 +410,8 @@ void Fl_Scalable_Graphics_Driver::draw(Fl_RGB_Image *img, int XP, int YP, int WP
draw_unscaled(img2, scale_, XP, YP, WP, HP, cx, cy);
*id(img) = *id(img2);
*id(img2) = 0;
- *cache_scale(img) = scale_;
+ *pw = w2;
+ *ph = h2;
delete img2;
}
else { // draw img using its scaled id_
diff --git a/src/Fl_Image.cxx b/src/Fl_Image.cxx
index 4cc6a8603..b1b8b64d7 100644
--- a/src/Fl_Image.cxx
+++ b/src/Fl_Image.cxx
@@ -349,7 +349,7 @@ Fl_RGB_Image::Fl_RGB_Image(const uchar *bits, int W, int H, int D, int LD) :
alloc_array(0),
id_(0),
mask_(0),
- cache_scale_(1)
+ cache_w_(0), cache_h_(0)
{
data((const char **)&array, 1);
ld(LD);
@@ -372,7 +372,7 @@ Fl_RGB_Image::Fl_RGB_Image(const Fl_Pixmap *pxm, Fl_Color bg):
alloc_array(0),
id_(0),
mask_(0),
- cache_scale_(1)
+ cache_w_(0), cache_h_(0)
{
if (pxm && pxm->w() > 0 && pxm->h() > 0) {
array = new uchar[w() * h() * d()];
diff --git a/src/Fl_Pixmap.cxx b/src/Fl_Pixmap.cxx
index ca76362de..33c76233d 100644
--- a/src/Fl_Pixmap.cxx
+++ b/src/Fl_Pixmap.cxx
@@ -42,7 +42,7 @@ void Fl_Pixmap::measure() {
if (w()<0 && data()) {
fl_measure_pixmap(data(), W, H);
w(W); h(H);
- cache_scale_ = 1;
+ cache_w_ = cache_h_ = 0;
}
}
diff --git a/src/drivers/GDI/Fl_GDI_Graphics_Driver_image.cxx b/src/drivers/GDI/Fl_GDI_Graphics_Driver_image.cxx
index 5c00198f0..6b9cb6d87 100644
--- a/src/drivers/GDI/Fl_GDI_Graphics_Driver_image.cxx
+++ b/src/drivers/GDI/Fl_GDI_Graphics_Driver_image.cxx
@@ -498,7 +498,10 @@ void Fl_GDI_Graphics_Driver::draw_unscaled(Fl_RGB_Image *img, float s, int X, in
if (H + cy > img->data_h()) H = img->data_h() - cy;
if (!*Fl_Graphics_Driver::id(img)) {
*Fl_Graphics_Driver::id(img) = (fl_uintptr_t)build_id(img, (void**)(Fl_Graphics_Driver::mask(img)));
- *cache_scale(img) = 1;
+ int *pw, *ph;
+ cache_w_h(img, pw, ph);
+ *pw = img->data_w();
+ *ph = img->data_h();
}
Fl_Region r2 = scale_clip(s);
if (*Fl_Graphics_Driver::mask(img)) {
@@ -541,7 +544,10 @@ int Fl_GDI_Graphics_Driver::draw_scaled(Fl_Image *img, int XP, int YP, int WP, i
if (!*Fl_Graphics_Driver::id(rgb)) {
*Fl_Graphics_Driver::id(rgb) = (fl_uintptr_t)build_id(rgb,
(void**)(Fl_Graphics_Driver::mask(rgb)));
- *cache_scale(rgb) = 1;
+ int *pw, *ph;
+ cache_w_h(rgb, pw, ph);
+ *pw = rgb->data_w();
+ *ph = rgb->data_h();
}
cache_size(img, WP, HP);
HDC new_gc = CreateCompatibleDC(gc_);
@@ -600,7 +606,10 @@ static Fl_Bitmask fl_create_bitmap(int w, int h, const uchar *data) {
}
fl_uintptr_t Fl_GDI_Graphics_Driver::cache(Fl_Bitmap *bm) {
- *cache_scale(bm) = Fl_Scalable_Graphics_Driver::scale();
+ int *pw, *ph;
+ cache_w_h(bm, pw, ph);
+ *pw = bm->data_w();
+ *ph = bm->data_h();
return (fl_uintptr_t)fl_create_bitmap(bm->data_w(), bm->data_h(), bm->array);
}
@@ -660,7 +669,10 @@ fl_uintptr_t Fl_GDI_Graphics_Driver::cache(Fl_Pixmap *img) {
Fl_Surface_Device::pop_current();
Fl_Offscreen id = surf->get_offscreen_before_delete();
delete surf;
- *cache_scale(img) = 1;
+ int *pw, *ph;
+ cache_w_h(img, pw, ph);
+ *pw = img->data_w();
+ *ph = img->data_h();
return (fl_uintptr_t)id;
}
diff --git a/src/drivers/Xlib/Fl_Xlib_Graphics_Driver.H b/src/drivers/Xlib/Fl_Xlib_Graphics_Driver.H
index 7d74b70e1..785c76369 100644
--- a/src/drivers/Xlib/Fl_Xlib_Graphics_Driver.H
+++ b/src/drivers/Xlib/Fl_Xlib_Graphics_Driver.H
@@ -101,6 +101,7 @@ protected:
static Window draw_window;
static struct _XftDraw* draw_;
#endif
+ Fl_Offscreen cache_rgb(Fl_RGB_Image *img);
public:
Fl_Xlib_Graphics_Driver(void);
virtual ~Fl_Xlib_Graphics_Driver();
diff --git a/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_image.cxx b/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_image.cxx
index 902cb5e45..c271dae53 100644
--- a/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_image.cxx
+++ b/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_image.cxx
@@ -696,7 +696,7 @@ static void alpha_blend(Fl_RGB_Image *img, int X, int Y, int W, int H, int cx, i
delete[] dst;
}
-static Fl_Offscreen cache_rgb(Fl_RGB_Image *img) {
+Fl_Offscreen Fl_Xlib_Graphics_Driver::cache_rgb(Fl_RGB_Image *img) {
Fl_Image_Surface *surface;
int depth = img->d();
if (depth == 1 || depth == 3) {
@@ -713,6 +713,10 @@ static Fl_Offscreen cache_rgb(Fl_RGB_Image *img) {
Fl_Surface_Device::pop_current();
Fl_Offscreen off = surface->get_offscreen_before_delete();
delete surface;
+ int *pw, *ph;
+ cache_w_h(img, pw, ph);
+ *pw = img->data_w();
+ *ph = img->data_h();
return off;
}
@@ -728,7 +732,6 @@ void Fl_Xlib_Graphics_Driver::draw_unscaled(Fl_RGB_Image *img, float s, int X, i
if (H + cy > img->data_h()) H = img->data_h() - cy;
if (!*Fl_Graphics_Driver::id(img)) {
*Fl_Graphics_Driver::id(img) = cache_rgb(img);
- *cache_scale(img) = 1;
}
Fl_Region r2 = scale_clip(s);
if (*Fl_Graphics_Driver::id(img)) {
@@ -767,7 +770,10 @@ void Fl_Xlib_Graphics_Driver::uncache(Fl_RGB_Image*, fl_uintptr_t &id_, fl_uintp
}
fl_uintptr_t Fl_Xlib_Graphics_Driver::cache(Fl_Bitmap *bm) {
- *cache_scale(bm) = Fl_Scalable_Graphics_Driver::scale();
+ int *pw, *ph;
+ cache_w_h(bm, pw, ph);
+ *pw = bm->data_w();
+ *ph = bm->data_h();
return (fl_uintptr_t)create_bitmask(bm->data_w(), bm->data_h(), bm->array);
}
@@ -830,7 +836,10 @@ fl_uintptr_t Fl_Xlib_Graphics_Driver::cache(Fl_Pixmap *pxm) {
Fl_Surface_Device::pop_current();
Fl_Offscreen id = surf->get_offscreen_before_delete();
delete surf;
- *cache_scale(pxm) = 1;
+ int *pw, *ph;
+ cache_w_h(pxm, pw, ph);
+ *pw = pxm->data_w();
+ *ph = pxm->data_h();
return (fl_uintptr_t)id;
}
@@ -881,7 +890,6 @@ int Fl_Xlib_Graphics_Driver::draw_scaled(Fl_Image *img, int XP, int YP, int WP,
if (!rgb || !can_do_alpha_blending()) return 0;
if (!*Fl_Graphics_Driver::id(rgb)) {
*Fl_Graphics_Driver::id(rgb) = cache_rgb(rgb);
- *cache_scale(rgb) = 1;
}
cache_size(img, WP, HP);
return scale_and_render_pixmap( *Fl_Graphics_Driver::id(rgb), rgb->d(),