FLTK logo

[master] 42aa31b - X11 platform: Accurately control RGB image drawing with GUI scaling.

FLTK matrix user chat room
(using Element browser app)   FLTK gitter user chat room   GitHub FLTK Project   FLTK News RSS Feed  
  FLTK Apps      FLTK Library      Forums      Links     Login 
 All Forums  |  Back to fltk.commit  ]
 
Previous Message ]Next Message ]

[master] 42aa31b - X11 platform: Accurately control RGB image drawing with GUI scaling. "ManoloFLTK" Mar 02, 2021  
 
commit 42aa31b900db5878137090e2a657c37bb1791f46
Author:     ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>
AuthorDate: Tue Mar 2 10:06:55 2021 +0100
Commit:     ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>
CommitDate: Tue Mar 2 10:07:06 2021 +0100

    X11 platform: Accurately control RGB image drawing with GUI scaling.

 src/drivers/Xlib/Fl_Xlib_Graphics_Driver.H         |  2 +-
 src/drivers/Xlib/Fl_Xlib_Graphics_Driver_image.cxx | 23 ++++++++++++----------
 2 files changed, 14 insertions(+), 11 deletions(-)

diff --git src/drivers/Xlib/Fl_Xlib_Graphics_Driver.H src/drivers/Xlib/Fl_Xlib_Graphics_Driver.H
index 7f86680..b593657 100644
--- src/drivers/Xlib/Fl_Xlib_Graphics_Driver.H
+++ src/drivers/Xlib/Fl_Xlib_Graphics_Driver.H
@@ -70,7 +70,7 @@ protected:
   virtual void draw_image_mono_unscaled(Fl_Draw_Image_Cb cb, void* data, int X,int Y,int W,int H, int D=1);
 #if HAVE_XRENDER
   virtual void draw_rgb(Fl_RGB_Image *rgb, int XP, int YP, int WP, int HP, int cx, int cy);
-  int scale_and_render_pixmap(Fl_Offscreen pixmap, int depth, double scale_x, double scale_y, int srcx, int srcy, int XP, int YP, int WP, int HP);
+  int scale_and_render_pixmap(Fl_Offscreen pixmap, int depth, double scale_x, double scale_y, int XP, int YP, int WP, int HP);
 #endif
   virtual int height_unscaled();
   virtual int descent_unscaled();
diff --git src/drivers/Xlib/Fl_Xlib_Graphics_Driver_image.cxx src/drivers/Xlib/Fl_Xlib_Graphics_Driver_image.cxx
index 40cd8e8..9361e5d 100644
--- src/drivers/Xlib/Fl_Xlib_Graphics_Driver_image.cxx
+++ src/drivers/Xlib/Fl_Xlib_Graphics_Driver_image.cxx
@@ -769,25 +769,28 @@ void Fl_Xlib_Graphics_Driver::draw_rgb(Fl_RGB_Image *rgb, int XP, int YP, int WP
     Fl_Graphics_Driver::draw_rgb(rgb, XP, YP, WP, HP, cx, cy);
     return;
   }
-  int X, Y, W, H;
-  if (Fl_Graphics_Driver::start_image(rgb, XP, YP, WP, HP, cx, cy, X, Y, W, H)) {
-    return;
-  }
   if (!*Fl_Graphics_Driver::id(rgb)) {
     cache(rgb);
   }
-  cache_size(rgb, W, H);
-  int Wfull = rgb->w(), Hfull = rgb->h();
+  push_clip(XP, YP, WP, HP);
+  int Wfull = rgb->w(), Hfull = rgb->h(), offset = 0;
   cache_size(rgb, Wfull, Hfull);
+  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),
-                          cx*scale(), cy*scale(), (X + offset_x_)*scale(), (Y + offset_y_)*scale(), W, H);
+                          rgb->data_w() / double(Wfull), rgb->data_h() / double(Hfull),
+                          (XP-cx + offset_x_)*scale()-offset, (YP-cy + offset_y_)*scale()-offset, Wfull, Hfull);
+  pop_clip();
 }
 
 /* Draws with Xrender an Fl_Offscreen with optional scaling and accounting for transparency if necessary.
  XP,YP,WP,HP are in drawing units
  */
-int Fl_Xlib_Graphics_Driver::scale_and_render_pixmap(Fl_Offscreen pixmap, int depth, double scale_x, double scale_y, int srcx, int srcy, int XP, int YP, int WP, int HP) {
+int Fl_Xlib_Graphics_Driver::scale_and_render_pixmap(Fl_Offscreen pixmap, int depth, double scale_x, double scale_y, int XP, int YP, int WP, int HP) {
   bool has_alpha = (depth == 2 || depth == 4);
   XRenderPictureAttributes srcattr;
   memset(&srcattr, 0, sizeof(XRenderPictureAttributes));
@@ -822,7 +825,7 @@ int Fl_Xlib_Graphics_Driver::scale_and_render_pixmap(Fl_Offscreen pixmap, int de
       // has_alpha = true;
     }
   }
-  XRenderComposite(fl_display, (has_alpha ? PictOpOver : PictOpSrc), src, None, dst, srcx, srcy, 0, 0,
+  XRenderComposite(fl_display, (has_alpha ? PictOpOver : PictOpSrc), src, None, dst, 0, 0, 0, 0,
                    XP, YP, WP, HP);
   XRenderFreePicture(fl_display, src);
   XRenderFreePicture(fl_display, dst);
Direct Link to Message ]
 
     
Previous Message ]Next Message ]
 
 

Comments are owned by the poster. All other content is copyright 1998-2024 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to 'erco@seriss.com'.