Skip to content

Commit 29397ec

Browse files
committed
Fix zoom-aware Image initialization on Linux and Windows
1 parent b220571 commit 29397ec

File tree

2 files changed

+23
-22
lines changed
  • bundles/org.eclipse.swt/Eclipse SWT

2 files changed

+23
-22
lines changed

bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Image.java

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -532,9 +532,7 @@ public Image(Device device, ImageData source, ImageData mask) {
532532
public Image(Device device, InputStream stream) {
533533
super(device);
534534
currentDeviceZoom = DPIUtil.getDeviceZoom();
535-
// FIXME: is this the right zoom? That's what is done in windows Image.getZoom()?
536-
int zoom = DPIUtil.getZoomForAutoscaleProperty(currentDeviceZoom);
537-
ElementAtZoom<ImageData> image = ImageDataLoader.load(stream, FileFormat.DEFAULT_ZOOM, zoom);
535+
ElementAtZoom<ImageData> image = ImageDataLoader.load(stream, FileFormat.DEFAULT_ZOOM, currentDeviceZoom);
538536
ImageData data = DPIUtil.autoScaleUp(device, image);
539537
init(data);
540538
init();
@@ -576,9 +574,7 @@ public Image(Device device, String filename) {
576574
super(device);
577575
if (filename == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
578576
currentDeviceZoom = DPIUtil.getDeviceZoom();
579-
// FIXME: is this the right zoom? That's what is done in windows Image.getZoom()?
580-
int zoom = DPIUtil.getZoomForAutoscaleProperty(currentDeviceZoom);
581-
ElementAtZoom<ImageData> image = ImageDataLoader.load(filename, FileFormat.DEFAULT_ZOOM, zoom);
577+
ElementAtZoom<ImageData> image = ImageDataLoader.load(filename, FileFormat.DEFAULT_ZOOM, currentDeviceZoom);
582578
ImageData data = DPIUtil.autoScaleUp(device, image);
583579
init(data);
584580
init();
@@ -617,17 +613,18 @@ public Image(Device device, ImageFileNameProvider imageFileNameProvider) {
617613
super(device);
618614
this.imageFileNameProvider = imageFileNameProvider;
619615
currentDeviceZoom = DPIUtil.getDeviceZoom();
620-
ElementAtZoom<String> filename = DPIUtil.validateAndGetImagePathAtZoom (imageFileNameProvider, currentDeviceZoom);
621-
ElementAtZoom<ImageData> imageData = ImageDataLoader.load(filename.element(), filename.zoom(), currentDeviceZoom);
622-
if (imageData.zoom() == currentDeviceZoom) {
623-
initNative (filename.element());
624-
625-
if (this.surface == 0) {
616+
ElementAtZoom<String> fileName = DPIUtil.validateAndGetImagePathAtZoom (imageFileNameProvider, currentDeviceZoom);
617+
if (fileName.zoom() == currentDeviceZoom) {
618+
initNative(fileName.element());
619+
}
620+
if (this.surface == 0) {
621+
ElementAtZoom<ImageData> imageData = ImageDataLoader.load(fileName.element(), fileName.zoom(), currentDeviceZoom);
622+
if (imageData.zoom() == currentDeviceZoom) {
626623
init(imageData.element());
624+
} else {
625+
ImageData resizedData = DPIUtil.autoScaleUp(device, imageData);
626+
init(resizedData);
627627
}
628-
} else {
629-
ImageData resizedData = DPIUtil.autoScaleUp(device, imageData);
630-
init(resizedData);
631628
}
632629
init ();
633630
}

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Image.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -557,16 +557,20 @@ public Image(Device device, ImageFileNameProvider imageFileNameProvider) {
557557
initialNativeZoom = DPIUtil.getNativeDeviceZoom();
558558
int deviceZoom = getZoom();
559559
ElementAtZoom<String> fileName = DPIUtil.validateAndGetImagePathAtZoom(imageFileNameProvider, deviceZoom);
560-
ElementAtZoom<ImageData> imageData = ImageDataLoader.load(fileName.element(), fileName.zoom(), deviceZoom);
561-
if (imageData.zoom() == deviceZoom) {
562-
ImageHandle imageMetadata = initNative(fileName.element(), deviceZoom);
563-
if (imageMetadata == null) {
560+
ImageHandle nativeImageMetadata = null;
561+
if (fileName.zoom() == deviceZoom) {
562+
nativeImageMetadata = initNative(fileName.element(), deviceZoom);
563+
}
564+
if (nativeImageMetadata == null) {
565+
ElementAtZoom<ImageData> imageData = ImageDataLoader.load(fileName.element(), fileName.zoom(), deviceZoom);
566+
if (imageData.zoom() == deviceZoom) {
564567
init(imageData.element(), deviceZoom);
568+
} else {
569+
ImageData resizedData = DPIUtil.autoScaleUp(device, imageData);
570+
init(resizedData, deviceZoom);
565571
}
566-
} else {
567-
ImageData resizedData = DPIUtil.autoScaleUp(device, imageData);
568-
init(resizedData, deviceZoom);
569572
}
573+
570574
init();
571575
this.device.registerResourceWithZoomSupport(this);
572576
}

0 commit comments

Comments
 (0)