Skip to content

Commit dcc8cd1

Browse files
akoch-yattafedejeanne
authored andcommitted
Use ImageGcDrawer for smooth scaling of ImageData
This commit adapts the smooth scaling implementation to use ImageGcDrawer.
1 parent f039195 commit dcc8cd1

File tree

4 files changed

+19
-11
lines changed

4 files changed

+19
-11
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -906,6 +906,7 @@ private ImageData drawWithImageGcDrawer(ImageGcDrawer imageGcDrawer, int width,
906906
int gcStyle = imageGcDrawer.getGcStyle();
907907
Image image;
908908
if ((gcStyle & SWT.TRANSPARENT) != 0) {
909+
/* Create a 24 bit image data with alpha channel */
909910
final ImageData resultData = new ImageData (width, height, 24, new PaletteData (0xFF, 0xFF00, 0xFF0000));
910911
resultData.alphaData = new byte [width * height];
911912
image = new Image(device, resultData);

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

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -306,16 +306,21 @@ private static ImageData autoScaleImageData (Device device, final ImageData imag
306306
boolean useSmoothScaling = isSmoothScalingEnabled() && imageData.getTransparencyType() != SWT.TRANSPARENCY_MASK;
307307
if (useSmoothScaling) {
308308
Image original = new Image (device, (ImageDataProvider) zoom -> imageData);
309-
/* Create a 24 bit image data with alpha channel */
310-
final ImageData resultData = new ImageData (scaledWidth, scaledHeight, 24, new PaletteData (0xFF, 0xFF00, 0xFF0000));
311-
resultData.alphaData = new byte [scaledWidth * scaledHeight];
312-
Image resultImage = new Image (device, (ImageDataProvider) zoom -> resultData);
313-
GC gc = new GC (resultImage);
314-
gc.setAntialias (SWT.ON);
315-
Image.drawScaled(gc, original, width, height, scaleFactor);
316-
gc.dispose ();
309+
ImageGcDrawer drawer = new ImageGcDrawer() {
310+
@Override
311+
public void drawOn(GC gc, int imageWidth, int imageHeight) {
312+
gc.setAntialias (SWT.ON);
313+
Image.drawScaled(gc, original, width, height, scaleFactor);
314+
};
315+
316+
@Override
317+
public int getGcStyle() {
318+
return SWT.TRANSPARENT;
319+
}
320+
};
321+
Image resultImage = new Image (device, drawer, scaledWidth, scaledHeight);
322+
ImageData result = resultImage.getImageData (100);
317323
original.dispose ();
318-
ImageData result = resultImage.getImageData (getDeviceZoom ());
319324
resultImage.dispose ();
320325
return result;
321326
} else {

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1168,6 +1168,7 @@ private ImageData drawWithImageGcDrawer(int width, int height, int zoom) {
11681168
int gcStyle = imageGcDrawer.getGcStyle();
11691169
Image image;
11701170
if ((gcStyle & SWT.TRANSPARENT) != 0) {
1171+
/* Create a 24 bit image data with alpha channel */
11711172
final ImageData resultData = new ImageData(width, height, 24, new PaletteData (0xFF, 0xFF00, 0xFF0000));
11721173
resultData.alphaData = new byte [width * height];
11731174
image = new Image(device, resultData, zoom);
@@ -1288,7 +1289,7 @@ void init(ImageData image) {
12881289
init(image, DPIUtil.getDeviceZoom());
12891290
}
12901291

1291-
void init(ImageData image, int zoom) {
1292+
private void init(ImageData image, int zoom) {
12921293
if (image == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
12931294

12941295
PaletteData palette = image.palette;

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1972,7 +1972,7 @@ private class PlainImageDataProviderWrapper extends ImageFromImageDataProviderWr
19721972
this(imageData, 100);
19731973
}
19741974

1975-
PlainImageDataProviderWrapper(ImageData imageData, int zoom) {
1975+
private PlainImageDataProviderWrapper(ImageData imageData, int zoom) {
19761976
this.imageDataAtBaseZoom = (ImageData) imageData.clone();
19771977
this.baseZoom = zoom;
19781978
initImage();
@@ -2499,6 +2499,7 @@ protected ImageHandle newImageHandle(int zoom) {
24992499
if ((gcStyle & SWT.TRANSPARENT) != 0) {
25002500
int scaledHeight = DPIUtil.scaleUp(height, zoom);
25012501
int scaledWidth = DPIUtil.scaleUp(width, zoom);
2502+
/* Create a 24 bit image data with alpha channel */
25022503
final ImageData resultData = new ImageData (scaledWidth, scaledHeight, 24, new PaletteData (0xFF, 0xFF00, 0xFF0000));
25032504
resultData.alphaData = new byte [scaledWidth * scaledHeight];
25042505
image = new Image(device, resultData, zoom);

0 commit comments

Comments
 (0)