From 5f7b1d23242cf62cd4e2b41df92b8f113e90d004 Mon Sep 17 00:00:00 2001 From: Heiko Klare Date: Tue, 21 Oct 2025 11:46:23 +0200 Subject: [PATCH] [GTK] Fix scaling of image copies and stylings The image copy and styling operation via the constructor Image(Device, Image, int) does currently not properly take into account a potential scaling of the original image. The surface for the new image is always created with the size in points, i.e., according to a 100% scaling. When the image is used at 200% it will thus appear blurry. This change adapts the image copy and styling constructor to properly take the scaling of the original image into account. It make the constructor create a surface with a proper size and scaling. --- .../gtk/org/eclipse/swt/graphics/Image.java | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Image.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Image.java index ef3648eb67..63c1df9264 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Image.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Image.java @@ -278,16 +278,16 @@ public Image(Device device, Image srcImage, int flag) { if (flag != SWT.IMAGE_DISABLE) transparentPixel = srcImage.transparentPixel; long imageSurface = srcImage.surface; - int width = this.width = srcImage.width; - int height = this.height = srcImage.height; + this.width = srcImage.width; + this.height = srcImage.height; int format = Cairo.cairo_surface_get_content(imageSurface) == Cairo.CAIRO_CONTENT_COLOR ? Cairo.CAIRO_FORMAT_RGB24 : Cairo.CAIRO_FORMAT_ARGB32; boolean hasAlpha = format == Cairo.CAIRO_FORMAT_ARGB32; - surface = Cairo.cairo_image_surface_create(format, width, height); + int dataWidth = DPIUtil.pointToPixel(this.width, DPIUtil.getDeviceZoom()); + int dataHeight= DPIUtil.pointToPixel(this.height, DPIUtil.getDeviceZoom()); + surface = Cairo.cairo_image_surface_create(format, dataWidth, dataHeight); if (surface == 0) SWT.error(SWT.ERROR_NO_HANDLES); - if (DPIUtil.getDeviceZoom() != currentDeviceZoom) { - double scaleFactor = DPIUtil.getDeviceZoom() / 100f; - Cairo.cairo_surface_set_device_scale(surface, scaleFactor, scaleFactor); - } + double scaleFactor = DPIUtil.getDeviceZoom() / 100f; + Cairo.cairo_surface_set_device_scale(surface, scaleFactor, scaleFactor); long cairo = Cairo.cairo_create(surface); if (cairo == 0) SWT.error(SWT.ERROR_NO_HANDLES); Cairo.cairo_set_operator(cairo, Cairo.CAIRO_OPERATOR_SOURCE); @@ -306,9 +306,9 @@ public Image(Device device, Image srcImage, int flag) { switch (flag) { case SWT.IMAGE_DISABLE: { byte[] line = new byte[stride]; - for (int y=0; y