Skip to content

Commit 1a36df3

Browse files
Guard Image Type Icon from Smooth Scaling
Enabling the smooth scaling for icon produce erroneous result. Resulting in icon losing its transparency.
1 parent 3e8da4a commit 1a36df3

File tree

1 file changed

+12
-8
lines changed
  • bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal

1 file changed

+12
-8
lines changed

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

+12-8
Original file line numberDiff line numberDiff line change
@@ -292,8 +292,9 @@ 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-
return switch (autoScaleMethod) {
296-
case SMOOTH -> {
295+
ImageData result;
296+
boolean useSmoothScaling = autoScaleMethod == AutoScaleMethod.SMOOTH && imageData.getTransparencyType() != SWT.TRANSPARENCY_MASK;
297+
if (useSmoothScaling) {
297298
Image original = new Image (device, (ImageDataProvider) zoom -> imageData);
298299
/* Create a 24 bit image data with alpha channel */
299300
final ImageData resultData = new ImageData (scaledWidth, scaledHeight, 24, new PaletteData (0xFF, 0xFF00, 0xFF0000));
@@ -302,18 +303,21 @@ private static ImageData autoScaleImageData (Device device, final ImageData imag
302303
GC gc = new GC (resultImage);
303304
gc.setAntialias (SWT.ON);
304305
gc.drawImage (original, 0, 0, autoScaleDown (width), autoScaleDown (height),
305-
/* E.g. destWidth here is effectively DPIUtil.autoScaleDown (scaledWidth), but avoiding rounding errors.
306-
* Nevertheless, we still have some rounding errors due to the point-based API GC#drawImage(..).
306+
/*
307+
* E.g. destWidth here is effectively DPIUtil.autoScaleDown (scaledWidth), but
308+
* avoiding rounding errors. Nevertheless, we still have some rounding errors
309+
* due to the point-based API GC#drawImage(..).
307310
*/
308311
0, 0, Math.round (autoScaleDown (width * scaleFactor)), Math.round (autoScaleDown (height * scaleFactor)));
309312
gc.dispose ();
310313
original.dispose ();
311-
ImageData result = resultImage.getImageData (getDeviceZoom ());
314+
result = resultImage.getImageData (getDeviceZoom ());
312315
resultImage.dispose ();
313-
yield result;
316+
} else {
317+
result = imageData.scaledTo (scaledWidth, scaledHeight);
314318
}
315-
default -> imageData.scaledTo (scaledWidth, scaledHeight);
316-
};
319+
320+
return result;
317321
}
318322

319323
/**

0 commit comments

Comments
 (0)