Skip to content

Commit 04d20e9

Browse files
committed
Revert Smooth Scaling Rounding error fix for win32
This reverts commit 909a985. # Conflicts: # bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Image.java # Conflicts: # bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Image.java
1 parent f35ee7f commit 04d20e9

File tree

2 files changed

+5
-47
lines changed
  • bundles/org.eclipse.swt/Eclipse SWT

2 files changed

+5
-47
lines changed

bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/DPIUtil.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ private static ImageData autoScaleImageData (Device device, final ImageData imag
292292
int height = imageData.height;
293293
int scaledWidth = Math.round (width * scaleFactor);
294294
int scaledHeight = Math.round (height * scaleFactor);
295-
boolean useSmoothScaling = isSmoothScalingEnabled() && imageData.getTransparencyType() != SWT.TRANSPARENCY_MASK;
295+
boolean useSmoothScaling = autoScaleMethod == AutoScaleMethod.SMOOTH && imageData.getTransparencyType() != SWT.TRANSPARENCY_MASK;
296296
if (useSmoothScaling) {
297297
Image original = new Image (device, (ImageDataProvider) zoom -> imageData);
298298
/* Create a 24 bit image data with alpha channel */
@@ -316,10 +316,6 @@ private static ImageData autoScaleImageData (Device device, final ImageData imag
316316
}
317317
}
318318

319-
public static boolean isSmoothScalingEnabled() {
320-
return autoScaleMethod == AutoScaleMethod.SMOOTH;
321-
}
322-
323319
/**
324320
* Returns a new rectangle as per the scaleFactor.
325321
*/
@@ -640,10 +636,6 @@ public static boolean useCairoAutoScale() {
640636
}
641637

642638
public static int getZoomForAutoscaleProperty (int nativeDeviceZoom) {
643-
return getZoomForAutoscaleProperty(nativeDeviceZoom, autoScaleValue);
644-
}
645-
646-
private static int getZoomForAutoscaleProperty (int nativeDeviceZoom, String autoScaleValue) {
647639
int zoom = 0;
648640
if (autoScaleValue != null) {
649641
if ("false".equalsIgnoreCase (autoScaleValue)) {

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

Lines changed: 4 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1265,7 +1265,7 @@ private ImageData getScaledImageData (int zoom) {
12651265
}
12661266
TreeSet<Integer> availableZooms = new TreeSet<>(zoomLevelToImageHandle.keySet());
12671267
int closestZoom = Optional.ofNullable(availableZooms.higher(zoom)).orElse(availableZooms.lower(zoom));
1268-
return scaleImageData(getImageMetadata(closestZoom).getImageData(), zoom, closestZoom);
1268+
return DPIUtil.scaleImageData (device, getImageMetadata(closestZoom).getImageData(), zoom, closestZoom);
12691269
}
12701270

12711271

@@ -1855,40 +1855,6 @@ public void setBackground(Color color) {
18551855
zoomLevelToImageHandle.values().forEach(imageHandle -> imageHandle.setBackground(backgroundColor));
18561856
}
18571857

1858-
private ImageData scaleImageData(final ImageData imageData, int targetZoom, int currentZoom) {
1859-
if (imageData == null || targetZoom == currentZoom || (device != null && !device.isAutoScalable())) return imageData;
1860-
float scaleFactor = (float) targetZoom / (float) currentZoom;
1861-
int width = imageData.width;
1862-
int height = imageData.height;
1863-
int scaledWidth = Math.round (width * scaleFactor);
1864-
int scaledHeight = Math.round (height * scaleFactor);
1865-
boolean useSmoothScaling = DPIUtil.isSmoothScalingEnabled() && imageData.getTransparencyType() != SWT.TRANSPARENCY_MASK;
1866-
if (useSmoothScaling) {
1867-
return scaleToUsingSmoothScaling(scaledWidth, scaledHeight, imageData);
1868-
}
1869-
return imageData.scaledTo (scaledWidth, scaledHeight);
1870-
}
1871-
1872-
private ImageData scaleToUsingSmoothScaling(int width, int height, ImageData imageData) {
1873-
Image original = new Image (device, (ImageDataProvider) zoom -> imageData);
1874-
/* Create a 24 bit image data with alpha channel */
1875-
final ImageData resultData = new ImageData (width, height, 24, new PaletteData (0xFF, 0xFF00, 0xFF0000));
1876-
resultData.alphaData = new byte [width * height];
1877-
Image resultImage = new Image (device, (ImageDataProvider) zoom -> resultData);
1878-
GC gc = new GC (resultImage);
1879-
gc.setAntialias (SWT.ON);
1880-
gc.drawImage (original, 0, 0, imageData.width, imageData.height,
1881-
/* E.g. destWidth here is effectively DPIUtil.autoScaleDown (scaledWidth), but avoiding rounding errors.
1882-
* Nevertheless, we still have some rounding errors due to the point-based API GC#drawImage(..).
1883-
*/
1884-
0, 0, width, height, false);
1885-
gc.dispose ();
1886-
original.dispose ();
1887-
ImageData result = resultImage.getImageData (resultImage.getZoom());
1888-
resultImage.dispose ();
1889-
return result;
1890-
}
1891-
18921858
private int getZoom() {
18931859
return DPIUtil.getZoomForAutoscaleProperty(initialNativeZoom);
18941860
}
@@ -2233,7 +2199,7 @@ ImageData getImageData(int zoom) {
22332199

22342200
private ImageData scaleIfNecessary(ElementAtZoom<ImageData> imageDataAtZoom, int zoom) {
22352201
if (imageDataAtZoom.zoom() != zoom) {
2236-
return scaleImageData(imageDataAtZoom.element(), zoom, imageDataAtZoom.zoom());
2202+
return DPIUtil.scaleImageData(device, imageDataAtZoom, zoom);
22372203
}
22382204
return imageDataAtZoom.element();
22392205
}
@@ -2457,13 +2423,13 @@ private class ImageDataProviderWrapper extends BaseImageProviderWrapper<ImageDat
24572423
@Override
24582424
ImageData getImageData(int zoom) {
24592425
ElementAtZoom<ImageData> data = DPIUtil.validateAndGetImageDataAtZoom (provider, zoom);
2460-
return scaleImageData(data.element(), zoom, data.zoom());
2426+
return DPIUtil.scaleImageData (device, data.element(), zoom, data.zoom());
24612427
}
24622428

24632429
@Override
24642430
ImageHandle getImageMetadata(int zoom) {
24652431
ElementAtZoom<ImageData> imageCandidate = DPIUtil.validateAndGetImageDataAtZoom (provider, zoom);
2466-
ImageData resizedData = scaleImageData(imageCandidate.element(), zoom, imageCandidate.zoom());
2432+
ImageData resizedData = DPIUtil.scaleImageData (device, imageCandidate.element(), zoom, imageCandidate.zoom());
24672433
ImageData newData = adaptImageDataIfDisabledOrGray(resizedData);
24682434
init(newData, zoom);
24692435
return zoomLevelToImageHandle.get(zoom);

0 commit comments

Comments
 (0)