Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public final class Program {
String name;
String command;
String iconName;
String extension;
static final String [] ARGUMENTS = new String [] {"%1", "%l", "%L"}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$

/**
Expand Down Expand Up @@ -101,6 +102,7 @@ public static Program findProgram (String extension) {
program.name = name;
program.command = command;
program.iconName = iconName;
program.extension = extension;
}
return program;
}
Expand Down Expand Up @@ -182,7 +184,7 @@ static String getKeyValue (String string, boolean expand) {
return result;
}

static Program getProgram (String key) {
static Program getProgram (String key, String extension) {

/* Name */
String name = getKeyValue (key, false);
Expand All @@ -208,6 +210,7 @@ static Program getProgram (String key) {
program.name = name;
program.command = command;
program.iconName = iconName;
program.extension = extension;
return program;
}

Expand All @@ -233,7 +236,7 @@ static Program getProgram (String key) {
//map paths to programs in parallel which takes now ~ 4/5 of time:
ConcurrentHashMap<String, Program> programs = new ConcurrentHashMap<>(paths.size());
paths.stream().parallel().forEach(path -> {
Program program = getProgram(path); // getProgram takes most time
Program program = getProgram(path, null); // getProgram takes most time
if (program != null) {
programs.put(path, program);
}
Expand Down Expand Up @@ -377,6 +380,22 @@ public ImageData getImageData () {
* @since 3.125
*/
public ImageData getImageData (int zoom) {
// Windows API returns image data according to primary monitor zoom factor
// rather than at original scaling
int nativeZoomFactor = 100 * Display.getCurrent().getPrimaryMonitor().getZoom() / DPIUtil.getDeviceZoom();
int imageZoomFactor = 100 * zoom / nativeZoomFactor;
if (extension != null) {
SHFILEINFO shfi = new SHFILEINFO ();
int flags = OS.SHGFI_ICON | OS.SHGFI_SMALLICON | OS.SHGFI_USEFILEATTRIBUTES;
TCHAR pszPath = new TCHAR (0, extension, true);
OS.SHGetFileInfo (pszPath.chars, OS.FILE_ATTRIBUTE_NORMAL, shfi, SHFILEINFO.sizeof, flags);
if (shfi.hIcon != 0) {
Image image = Image.win32_new (null, SWT.ICON, shfi.hIcon);
ImageData imageData = image.getImageData (imageZoomFactor);
image.dispose ();
return imageData;
}
}
int nIconIndex = 0;
String fileName = iconName;
int index = iconName.indexOf (',');
Expand All @@ -398,10 +417,7 @@ public ImageData getImageData (int zoom) {
OS.ExtractIconEx (lpszFile, nIconIndex, phiconLarge, phiconSmall, 1);
if (phiconSmall [0] == 0) return null;
Image image = Image.win32_new (null, SWT.ICON, phiconSmall [0]);
// Windows API returns image data according to primary monitor zoom factor
// rather than at original scaling
int nativeZoomFactor = 100 * Display.getCurrent().getPrimaryMonitor().getZoom() / DPIUtil.getDeviceZoom();
ImageData imageData = image.getImageData (100 * zoom / nativeZoomFactor);
ImageData imageData = image.getImageData (imageZoomFactor);
image.dispose ();
return imageData;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1430,6 +1430,7 @@ public ImageData getImageDataAtCurrentZoom() {

/* Do the mask */
byte [] maskData = null;
byte [] alphaData = null;
if (info.hbmColor == 0) {
/* Do the bottom half of the mask */
maskData = new byte[imageSize];
Expand Down Expand Up @@ -1459,7 +1460,9 @@ public ImageData getImageDataAtCurrentZoom() {
maskData = new byte[imageSize];
OS.GetDIBits(hBitmapDC, info.hbmMask, 0, height, maskData, bmi, OS.DIB_RGB_COLORS);
/* Loop to invert the mask */
boolean hasMaskData = false;
for (int i = 0; i < maskData.length; i++) {
hasMaskData |= maskData[i] != 0;
maskData[i] ^= -1;
}
/* Make sure mask scanlinePad is 2 */
Expand All @@ -1470,6 +1473,21 @@ public ImageData getImageDataAtCurrentZoom() {
if (calcBpl == bpl) break;
}
maskData = ImageData.convertPad(maskData, width, height, 1, maskPad, 2);
// For missing mask data, see https://github.com/eclipse-platform/eclipse.platform.swt/issues/715
if (!hasMaskData && depth == 32) {
alphaData = new byte[width * height];
boolean hasAlphaData = false;
for (int pixelIndex = 0; pixelIndex < alphaData.length; pixelIndex++) {
alphaData[pixelIndex] = data[pixelIndex * 4 + 3];
hasAlphaData |= alphaData[pixelIndex] != -1;
}
// In case there is alpha data, replace the empty mask data with proper alpha data
if (hasAlphaData) {
maskData = null;
} else {
alphaData = null;
}
}
}
/* Clean up */
OS.SelectObject(hBitmapDC, hOldBitmap);
Expand All @@ -1482,6 +1500,7 @@ public ImageData getImageDataAtCurrentZoom() {
if (info.hbmMask != 0) OS.DeleteObject(info.hbmMask);
/* Construct and return the ImageData */
ImageData imageData = new ImageData(width, height, depth, palette, 4, data);
imageData.alphaData = alphaData;
imageData.maskData = maskData;
imageData.maskPad = 2;
return imageData;
Expand Down