Skip to content

Commit 29a2ce3

Browse files
committed
Revert Smooth Scaling Rounding error fix for win32
This reverts commit 909a985.
1 parent b29048a commit 29a2ce3

File tree

2 files changed

+10
-54
lines changed
  • bundles/org.eclipse.swt/Eclipse SWT

2 files changed

+10
-54
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
*/
@@ -632,10 +628,6 @@ public static boolean useCairoAutoScale() {
632628
}
633629

634630
public static int getZoomForAutoscaleProperty (int nativeDeviceZoom) {
635-
return getZoomForAutoscaleProperty(nativeDeviceZoom, autoScaleValue);
636-
}
637-
638-
private static int getZoomForAutoscaleProperty (int nativeDeviceZoom, String autoScaleValue) {
639631
int zoom = 0;
640632
if (autoScaleValue != null) {
641633
if ("false".equalsIgnoreCase (autoScaleValue)) {

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

Lines changed: 9 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ public Image(Device device, ImageData data) {
372372
if (data == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
373373
initialNativeZoom = DPIUtil.getNativeDeviceZoom();
374374
int deviceZoom = getZoom();
375-
data = scaleImageData(data, deviceZoom, 100);
375+
data = DPIUtil.scaleImageData(device, new ElementAtZoom<>(data, 100), deviceZoom);
376376
init(data, deviceZoom);
377377
init();
378378
this.device.registerResourceWithZoomSupport(this);
@@ -416,8 +416,8 @@ public Image(Device device, ImageData source, ImageData mask) {
416416
SWT.error(SWT.ERROR_INVALID_ARGUMENT);
417417
}
418418
initialNativeZoom = DPIUtil.getNativeDeviceZoom();
419-
source = scaleImageData(source, getZoom(), 100);
420-
mask = scaleImageData(mask, getZoom(), 100);
419+
source = DPIUtil.autoScaleUp(device, source);
420+
mask = DPIUtil.autoScaleUp(device, mask);
421421
mask = ImageData.convertMask(mask);
422422
initIconHandle(this.device, source, mask, getZoom());
423423
init();
@@ -481,8 +481,7 @@ public Image (Device device, InputStream stream) {
481481
super(device);
482482
initialNativeZoom = DPIUtil.getNativeDeviceZoom();
483483
int deviceZoom = getZoom();
484-
ElementAtZoom<ImageData> imageCandidate = ImageDataLoader.load(stream, FileFormat.DEFAULT_ZOOM, deviceZoom);
485-
ImageData data = scaleImageData(imageCandidate.element(), deviceZoom, imageCandidate.zoom());
484+
ImageData data = DPIUtil.scaleImageData(device, ImageDataLoader.load(stream, FileFormat.DEFAULT_ZOOM, deviceZoom), deviceZoom);
486485
init(data, deviceZoom);
487486
init();
488487
this.device.registerResourceWithZoomSupport(this);
@@ -525,8 +524,7 @@ public Image (Device device, String filename) {
525524
if (filename == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
526525
initialNativeZoom = DPIUtil.getNativeDeviceZoom();
527526
int deviceZoom = getZoom();
528-
ElementAtZoom<ImageData> imageCandidate = ImageDataLoader.load(filename, FileFormat.DEFAULT_ZOOM, deviceZoom);
529-
ImageData data = scaleImageData(imageCandidate.element(), deviceZoom, imageCandidate.zoom());
527+
ImageData data = DPIUtil.scaleImageData(device, ImageDataLoader.load(filename, FileFormat.DEFAULT_ZOOM, deviceZoom), deviceZoom);
530528
init(data, deviceZoom);
531529
init();
532530
this.device.registerResourceWithZoomSupport(this);
@@ -1266,7 +1264,7 @@ private ImageData getScaledImageData (int zoom) {
12661264
}
12671265
TreeSet<Integer> availableZooms = new TreeSet<>(zoomLevelToImageHandle.keySet());
12681266
int closestZoom = Optional.ofNullable(availableZooms.higher(zoom)).orElse(availableZooms.lower(zoom));
1269-
return scaleImageData(getImageMetadata(closestZoom).getImageData(), zoom, closestZoom);
1267+
return DPIUtil.scaleImageData (device, getImageMetadata(closestZoom).getImageData(), zoom, closestZoom);
12701268
}
12711269

12721270

@@ -1856,40 +1854,6 @@ public void setBackground(Color color) {
18561854
zoomLevelToImageHandle.values().forEach(imageHandle -> imageHandle.setBackground(backgroundColor));
18571855
}
18581856

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

21102074
private ImageData scaleIfNecessary(ElementAtZoom<ImageData> imageDataAtZoom, int zoom) {
21112075
if (imageDataAtZoom.zoom() != zoom) {
2112-
return scaleImageData(imageDataAtZoom.element(), zoom, imageDataAtZoom.zoom());
2076+
return DPIUtil.scaleImageData(device, imageDataAtZoom, zoom);
21132077
} else {
21142078
return imageDataAtZoom.element();
21152079
}
@@ -2334,13 +2298,13 @@ private class ImageDataProviderWrapper extends BaseImageProviderWrapper<ImageDat
23342298
@Override
23352299
ImageData getImageData(int zoom) {
23362300
ElementAtZoom<ImageData> data = DPIUtil.validateAndGetImageDataAtZoom (provider, zoom);
2337-
return scaleImageData(data.element(), zoom, data.zoom());
2301+
return DPIUtil.scaleImageData (device, data.element(), zoom, data.zoom());
23382302
}
23392303

23402304
@Override
23412305
ImageHandle getImageMetadata(int zoom) {
23422306
ElementAtZoom<ImageData> imageCandidate = DPIUtil.validateAndGetImageDataAtZoom (provider, zoom);
2343-
ImageData resizedData = scaleImageData(imageCandidate.element(), zoom, imageCandidate.zoom());
2307+
ImageData resizedData = DPIUtil.scaleImageData (device, imageCandidate.element(), zoom, imageCandidate.zoom());
23442308
ImageData newData = adaptImageDataIfDisabledOrGray(resizedData);
23452309
init(newData, zoom);
23462310
return zoomLevelToImageHandle.get(zoom);

0 commit comments

Comments
 (0)