Skip to content

Commit 80813ea

Browse files
ShahzaibIbrahimHeikoKlare
authored andcommitted
Guard smooth scaling for images not having transparency mask
Enabling the smooth scaling for images with a transparency mask produce erroneous results with a loss of transparency. This guards the application of smooth scaling with the given image not having a transparency mask.
1 parent cc07c36 commit 80813ea

File tree

1 file changed

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

1 file changed

+12
-10
lines changed

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

+12-10
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));
@@ -305,15 +306,16 @@ private static ImageData autoScaleImageData (Device device, final ImageData imag
305306
/* E.g. destWidth here is effectively DPIUtil.autoScaleDown (scaledWidth), but avoiding rounding errors.
306307
* Nevertheless, we still have some rounding errors due to the point-based API GC#drawImage(..).
307308
*/
308-
0, 0, Math.round (autoScaleDown (width * scaleFactor)), Math.round (autoScaleDown (height * scaleFactor)));
309-
gc.dispose ();
310-
original.dispose ();
311-
ImageData result = resultImage.getImageData (getDeviceZoom ());
312-
resultImage.dispose ();
313-
yield result;
309+
0, 0, Math.round(autoScaleDown(width * scaleFactor)), Math.round(autoScaleDown(height * scaleFactor)));
310+
gc.dispose();
311+
original.dispose();
312+
result = resultImage.getImageData(getDeviceZoom());
313+
resultImage.dispose();
314+
} else {
315+
result = imageData.scaledTo (scaledWidth, scaledHeight);
314316
}
315-
default -> imageData.scaledTo (scaledWidth, scaledHeight);
316-
};
317+
318+
return result;
317319
}
318320

319321
/**

0 commit comments

Comments
 (0)