From 2e07560b960522bf22b3da7018622a82936efb1a Mon Sep 17 00:00:00 2001 From: Heiko Klare Date: Fri, 7 Mar 2025 16:14:58 +0100 Subject: [PATCH] [Win32] Replace autoScaleUp of ImageData with proper scaleImageData In some image constructors, image data are currently auto-scaled. This works by accident, as the device zoom used for auto scaling conforms to the zoom of the image to be initialized. However, to make this explicit, with this change the proper zoom is passed to scale method. It also makes the autoScaleUp method in DPIUtil obsolete and removes it. Co-authored-by: Hannes Wellmann --- .../common/org/eclipse/swt/internal/DPIUtil.java | 4 ---- .../win32/org/eclipse/swt/graphics/Image.java | 15 +++++++++------ 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/DPIUtil.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/DPIUtil.java index 0f08710d468..40dd39211c6 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/DPIUtil.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/DPIUtil.java @@ -346,10 +346,6 @@ public static ImageData autoScaleUp (Device device, final ImageData imageData) { return autoScaleImageData(device, imageData, 100); } -public static ImageData autoScaleUp (Device device, final ElementAtZoom elementAtZoom) { - return autoScaleImageData(device, elementAtZoom.element(), elementAtZoom.zoom()); -} - public static int[] autoScaleUp(int[] pointArray) { return scaleUp(pointArray, deviceZoom); } diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Image.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Image.java index 9a114a3150c..d086604d3df 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Image.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Image.java @@ -363,8 +363,9 @@ public Image(Device device, ImageData data) { super(device); if (data == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); initialNativeZoom = DPIUtil.getNativeDeviceZoom(); - data = DPIUtil.autoScaleUp(device, new ElementAtZoom<>(data, 100)); - init(data, getZoom()); + int deviceZoom = getZoom(); + data = DPIUtil.scaleImageData(device, new ElementAtZoom<>(data, 100), deviceZoom); + init(data, deviceZoom); init(); this.device.registerResourceWithZoomSupport(this); } @@ -471,8 +472,9 @@ public Image(Device device, ImageData source, ImageData mask) { public Image (Device device, InputStream stream) { super(device); initialNativeZoom = DPIUtil.getNativeDeviceZoom(); - ImageData data = DPIUtil.autoScaleUp(device, new ElementAtZoom<>(new ImageData (stream), 100)); - init(data, getZoom()); + int deviceZoom = getZoom(); + ImageData data = DPIUtil.scaleImageData(device, new ElementAtZoom<>(new ImageData (stream), 100), deviceZoom); + init(data, deviceZoom); init(); this.device.registerResourceWithZoomSupport(this); } @@ -513,8 +515,9 @@ public Image (Device device, String filename) { super(device); if (filename == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); initialNativeZoom = DPIUtil.getNativeDeviceZoom(); - ImageData data = DPIUtil.autoScaleUp(device, new ElementAtZoom<>(new ImageData (filename), 100)); - init(data, getZoom()); + int deviceZoom = getZoom(); + ImageData data = DPIUtil.scaleImageData(device, new ElementAtZoom<>(new ImageData (filename), 100), deviceZoom); + init(data, deviceZoom); init(); this.device.registerResourceWithZoomSupport(this); }