Skip to content

Commit 920fe85

Browse files
ShahzaibIbrahimHeikoKlare
authored andcommitted
Image type SWT.ICON loses its type during re-scale #1805
Image initialized as SWT.ICON in Image(Device, ImageData, ImageData) loses its "Icon" properties, i.e. type, mask etc., when a handle for a different zoom level is requested and "SMOOTH" scaling is used. This change adapts the initialization of the image when the handle is requested for image type SWT.ICON to preserve the properties. Fixes #1805
1 parent e2ae17b commit 920fe85

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2024 Yatta Solutions
3+
*
4+
* This program and the accompanying materials
5+
* are made available under the terms of the Eclipse Public License 2.0
6+
* which accompanies this distribution, and is available at
7+
* https://www.eclipse.org/legal/epl-2.0/
8+
*
9+
* SPDX-License-Identifier: EPL-2.0
10+
*
11+
* Contributors:
12+
* Yatta Solutions - initial API and implementation
13+
*******************************************************************************/
14+
package org.eclipse.swt.graphics;
15+
16+
import static org.junit.Assert.assertEquals;
17+
18+
import org.eclipse.swt.*;
19+
import org.eclipse.swt.internal.*;
20+
import org.eclipse.swt.widgets.*;
21+
import org.junit.jupiter.api.*;
22+
import org.junit.jupiter.api.extension.*;
23+
24+
@ExtendWith(PlatformSpecificExecutionExtension.class)
25+
@ExtendWith(WithMonitorSpecificScalingExtension.class)
26+
class ImagesWin32Tests {
27+
28+
@Test
29+
public void testImageIconTypeShouldNotChangeAfterCallingGetHandleForDifferentZoom() {
30+
Image icon = Display.getDefault().getSystemImage(SWT.ICON_ERROR);
31+
try {
32+
Image.win32_getHandle(icon, 200);
33+
assertEquals("Image type should stay to SWT.ICON", SWT.ICON, icon.type);
34+
} finally {
35+
icon.dispose();
36+
}
37+
}
38+
}

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

+9-1
Original file line numberDiff line numberDiff line change
@@ -783,7 +783,15 @@ private ImageHandle getImageMetadata(int zoom) {
783783
} else {
784784
ImageData resizedData = getImageData(zoom);
785785
ImageData newData = adaptImageDataIfDisabledOrGray(resizedData);
786-
init(newData, zoom);
786+
if (type == SWT.ICON && newData.getTransparencyType() != SWT.TRANSPARENCY_MASK) {
787+
// If the original type was an icon with transparency mask and re-scaling leads
788+
// to image data without transparency mask, this will create invalid images
789+
// so this fallback will "repair" the image data by explicitly passing
790+
// the transparency mask created from the scaled image data
791+
init(this.device, this, newData, newData.getTransparencyMask(), zoom);
792+
} else {
793+
init(newData, zoom);
794+
}
787795
init();
788796
}
789797
return zoomLevelToImageHandle.get(zoom);

0 commit comments

Comments
 (0)