-
Notifications
You must be signed in to change notification settings - Fork 185
Unify and improve image disablement calculation algorithm #1936
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
HeikoKlare
merged 1 commit into
eclipse-platform:master
from
vi-eclipse:disabled-extraction-cleanup
Apr 17, 2025
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
....eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/ImageColorTransformer.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| /******************************************************************************* | ||
| * Copyright (c) 2025 Vector Informatik GmbH and others. | ||
| * | ||
| * This program and the accompanying materials | ||
| * are made available under the terms of the Eclipse Public License 2.0 | ||
| * which accompanies this distribution, and is available at | ||
| * https://www.eclipse.org/legal/epl-2.0/ | ||
| * | ||
| * SPDX-License-Identifier: EPL-2.0 | ||
| *******************************************************************************/ | ||
| package org.eclipse.swt.internal.image; | ||
|
|
||
| import org.eclipse.swt.*; | ||
| import org.eclipse.swt.graphics.*; | ||
|
|
||
| public interface ImageColorTransformer { | ||
|
|
||
| public static final String IMAGE_DISABLEMENT_ALGORITHM_GRAYED = "grayed"; | ||
| public static final String IMAGE_DISABLEMENT_ALGORITHM_GTK = "gtk"; | ||
| public static final String IMAGE_DISABLEMENT_ALGORITHM_DESATURATED = "desaturated"; | ||
| public static final String IMAGE_DISABLEMENT_ALGORITHM = System.getProperty("org.eclipse.swt.image.disablement", | ||
| IMAGE_DISABLEMENT_ALGORITHM_GRAYED).strip(); | ||
|
|
||
| public static final ImageColorTransformer DEFAULT_DISABLED_IMAGE_TRANSFORMER = switch (IMAGE_DISABLEMENT_ALGORITHM) { | ||
| case IMAGE_DISABLEMENT_ALGORITHM_GTK -> ImageColorTransformer.forRGB(0.5f, 0.5f, 0.5f, 0.5f); | ||
| case IMAGE_DISABLEMENT_ALGORITHM_DESATURATED -> ImageColorTransformer.forHSB(1.0f, 0.2f, 0.9f, 0.5f); | ||
| default -> ImageColorTransformer.forGrayscaledContrastBrightness(0.2f, 2.9f); | ||
| }; | ||
|
|
||
| RGBA adaptPixelValue(int red, int green, int blue, int alpha); | ||
|
|
||
| public static ImageColorTransformer forHSB(float hueFactor, float saturationFactor, float brightnessFactor, | ||
| float alphaFactor) { | ||
| return (red, green, blue, alpha) -> { | ||
| float[] hsba = new RGBA(red, green, blue, alpha).getHSBA(); | ||
| float hue = Math.min(hueFactor * hsba[0], 1.0f); | ||
| float saturation = Math.min(saturationFactor * hsba[1], 1.0f); | ||
| float brightness = Math.min(brightnessFactor * hsba[2], 1.0f); | ||
| float alphaResult = Math.min(alphaFactor * hsba[3], 255.0f); | ||
| return new RGBA(hue, saturation, brightness, alphaResult); | ||
| }; | ||
| } | ||
|
|
||
| public static ImageColorTransformer forRGB(float redFactor, float greenFactor, float blueFactor, | ||
| float alphaFactor) { | ||
| return (red, green, blue, alpha) -> { | ||
| int redResult = (int) Math.min(redFactor * red, 255.0f); | ||
| int greenResult = (int) Math.min(greenFactor * green, 255.0f); | ||
| int blueResult = (int) Math.min(blueFactor * blue, 255.0f); | ||
| int alphaResult = (int) Math.min(alphaFactor * alpha, 255.0f); | ||
| return new RGBA(redResult, greenResult, blueResult, alphaResult); | ||
| }; | ||
| } | ||
|
|
||
| public static ImageColorTransformer forIntensityThreshold(Device device) { | ||
| RGBA lowIntensity = device.getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW).getRGBA(); | ||
| RGBA highIntensity = device.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND).getRGBA(); | ||
| return (red, green, blue, alpha) -> { | ||
| int intensity = red * red + green * green + blue * blue; | ||
| RGBA usedGraytone = intensity < 98304 ? lowIntensity : highIntensity; | ||
| return new RGBA(usedGraytone.rgb.red, usedGraytone.rgb.green, usedGraytone.rgb.blue, alpha); | ||
| }; | ||
| } | ||
|
|
||
| public static ImageColorTransformer forGrayscaledContrastBrightness(float contrast, float brightness) { | ||
| return (red, green, blue, alpha) -> { | ||
| int grayValue = Math.min((77 * red + 151 * green + 28 * blue) / 255, 255); | ||
| int resultValue = (int) Math.min(Math.max((contrast * (grayValue * brightness - 128) + 128), 0), 255); | ||
| return new RGBA(resultValue, resultValue, resultValue, alpha); | ||
| }; | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.