summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>2022-08-10 10:53:29 +0200
committerManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>2022-08-10 10:53:29 +0200
commitb8c227a8f2bb004de5819c93be5b7f6218402716 (patch)
tree1271a93512d5f1211305c23b549db3f019ca4b21 /src
parent7d7784d14009343ba224bcc62291bede711f653c (diff)
Fix Fl_Xlib_Graphics_Driver for drawing tiled images.
Conflicting demands arise in the implementation of class Fl_Xlib_Graphics_Driver for drawing images with the XRender library : 1) Issue #163 leads to use a bilinear filter to draw-and-scale images. 2) This tends to blur the edges of drawn areas which is bad for tiled images (that is because the edges get alpha values, even for an opaque source image). This commit resolves the conflict adding a means to detect whether the library is busy drawing a tiled image. If so, the bilinear filter is not applied, drawn areas don't have blurred edges, resulting in a nice tiling. With this commit, these test apps perform correctly: - tiled_image is correct at all scaling factor values also when modified to use a depth-3 or a depth-4 Fl_RGB_Image as tile; - unittests - Drawing Images is correct at all scaling factor values; - pixmap_browser scales correctly up and down JPEG and PNG images.
Diffstat (limited to 'src')
-rw-r--r--src/Fl_Tiled_Image.cxx4
-rw-r--r--src/drivers/Xlib/Fl_Xlib_Graphics_Driver_image.cxx15
2 files changed, 10 insertions, 9 deletions
diff --git a/src/Fl_Tiled_Image.cxx b/src/Fl_Tiled_Image.cxx
index 2ec62e79a..cfc89bfb4 100644
--- a/src/Fl_Tiled_Image.cxx
+++ b/src/Fl_Tiled_Image.cxx
@@ -20,6 +20,8 @@
#include <FL/Fl_Window.H>
#include <FL/fl_draw.H>
+bool Fl_Tiled_Image::drawing_tiled_image_ = false;
+
/**
The constructors create a new tiled image containing the specified image.
Use a width and height of 0 to tile the whole window/widget.
@@ -181,6 +183,7 @@ Fl_Tiled_Image::draw(int X, // I - Starting X position
if (W == 0 || H == 0) return;
fl_push_clip(X, Y, W, H);
+ drawing_tiled_image_ = true;
if (cx > 0) iw -= cx; // crop image
if (cy > 0) ih -= cy;
@@ -194,5 +197,6 @@ Fl_Tiled_Image::draw(int X, // I - Starting X position
}
}
}
+ drawing_tiled_image_ = false;
fl_pop_clip();
}
diff --git a/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_image.cxx b/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_image.cxx
index 73bea246e..d57e5b031 100644
--- a/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_image.cxx
+++ b/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_image.cxx
@@ -51,6 +51,7 @@
# include <FL/fl_draw.H>
# include <FL/platform.H>
# include <FL/Fl_Image_Surface.H>
+# include <FL/Fl_Tiled_Image.H>
# include "../../Fl_Screen_Driver.H"
# include "../../Fl_XColor.H"
# include "../../flstring.h"
@@ -780,16 +781,9 @@ void Fl_Xlib_Graphics_Driver::draw_rgb(Fl_RGB_Image *rgb, int XP, int YP, int WP
if (Wfull == 0 || Hfull == 0) return;
bool need_clip = (cx || cy || WP < rgb->w() || HP < rgb->h());
if (need_clip) push_clip(XP, YP, WP, HP);
- int offset = 0;
- if (Wfull > rgb->data_w() || Hfull > rgb->data_h()) {
- // When enlarging while drawing with XRender, 1 pixel around target area seems unpainted,
- // so we increase a bit the target area and move it 1 pixel to left and top.
- Wfull = (rgb->w()+2)*scale(), Hfull = (rgb->h()+2)*scale();
- offset = 1;
- }
scale_and_render_pixmap( *Fl_Graphics_Driver::id(rgb), rgb->d(),
rgb->data_w() / double(Wfull), rgb->data_h() / double(Hfull),
- Xs + this->floor(offset_x_) - offset, Ys + this->floor(offset_y_) - offset,
+ Xs + this->floor(offset_x_), Ys + this->floor(offset_y_),
Wfull, Hfull);
if (need_clip) pop_clip();
}
@@ -830,7 +824,10 @@ int Fl_Xlib_Graphics_Driver::scale_and_render_pixmap(Fl_Offscreen pixmap, int de
{ XDoubleToFixed( 0 ), XDoubleToFixed( 0 ), XDoubleToFixed( 1 ) }
}};
XRenderSetPictureTransform(fl_display, src, &mat);
- if (Fl_Image::scaling_algorithm() == FL_RGB_SCALING_BILINEAR) {
+ if (Fl_Image::scaling_algorithm() == FL_RGB_SCALING_BILINEAR &&
+ !Fl_Tiled_Image::drawing_tiled_image()) {
+ // The filter is not used when drawing tiled images because drawn image edges
+ // become somewhat blurry.
XRenderSetPictureFilter(fl_display, src, FilterBilinear, 0, 0);
// A note at https://www.talisman.org/~erlkonig/misc/x11-composite-tutorial/ :
// "When you use a filter you'll probably want to use PictOpOver as the render op,