-
Notifications
You must be signed in to change notification settings - Fork 521
8325445: [macOS] Colors are not displayed in sRGB color space #1473
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
Conversation
👋 Welcome back mfox! A progress list of the required criteria for merging this PR into |
@beldenfox This change now passes all automated pre-integration checks. ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details. After integration, the commit message for the final commit will be:
You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been 28 new commits pushed to the
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details. ➡️ To integrate this PR with the above commit message to the |
Webrevs
|
Reviewers: @kevinrushforth @arapte /reviewers 2 |
@kevinrushforth |
As a datapoint, we were doing some testing in the jfx-sandbox:metal branch, and had over a hundred test failures that we tracked down to the color profile not being set to sRGB (the test system had the default "Color LCD profile"). I applied the fix from this patch (and resolving a couple merge conflicts due to some Metal-specific changes in the sandbox branch), and ran one of the failing tests with the default "Color LCD" profile and it now passes. Even if this PR doesn't fix all of the problems, it seems like a good fix to consider. |
@beldenfox Can you merge in the latest master so we will see a test build on macOS / aarch64? |
|
||
// The component tolerance allows one bit of rounding when writing a color | ||
// out and another bit when reading it back in. | ||
static final double COMPONENT_TOLERANCE = 2.0 / 255.0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: 2.0001 / 255.0 to account for floating point errors
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure this test needs to be that precise. And I'm fine with the threshold falling below 2.0/255.0 since it should be as small as possible (I even experimented briefly with lower numbers). I haven't run into an issue on the three platforms I've run this test on.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then the comment might not be technically correct, because it is possible to have "two bit difference" in the integer color values, yet fail due to small error intrinsic in floating point operations.
Example:
a=253 b=251 delta=0.007843137254902044 tol=0.00784313725490196
delta=0.007843137254902044
tol=0.00784313725490196 (2.0 / 255.0)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've updated the constant as you suggested.
} | ||
|
||
// We use an AWT Robot since it is color space aware and will correctly convert | ||
// from the screeen's color space to sRGB. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we plan to fix FX robot eventually?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR fixes the JavaFX Robot. I give a more detailed explanation of why I'm using the AWT Robot in a comment just before the sRGBPixelTest. I've updated the comments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reproducer in the ticket fails without the fix and works as described on 2021 macOS 14.5 M1, using built-in retina and an external Samsung LS27A600U display (which seems to have a different color profile).
I would like to request a change for SRGBTest.COMPONENT_TOLERANCE value (or comment), please see inline comments.
components[0] = (CGFloat)((color & 0x00FF0000) >> 16) / 255.0; | ||
components[1] = (CGFloat)((color & 0x0000FF00) >> 8) / 255.0; | ||
components[2] = (CGFloat)((color & 0x000000FF)) / 255.0; | ||
components[3] = (CGFloat)((color & 0xFF000000) >> 24) / 255.0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this line guaranteed not to produce negative values? e.g. when color = 0xffffffff
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. I've updated the code to read the pixel value into an unsigned integer.
|
||
// The component tolerance allows one bit of rounding when writing a color | ||
// out and another bit when reading it back in. | ||
static final double COMPONENT_TOLERANCE = 2.0 / 255.0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then the comment might not be technically correct, because it is possible to have "two bit difference" in the integer color values, yet fail due to small error intrinsic in floating point operations.
Example:
a=253 b=251 delta=0.007843137254902044 tol=0.00784313725490196
delta=0.007843137254902044
tol=0.00784313725490196 (2.0 / 255.0)
…t handling in Robot
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
retested, looks good.
thank you for the meticulously commented unit tests!
I'll test the updated version. From my earlier testing, I think the following two things need to be addressed, but I'll let you know for sure:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code changes all look good. Everything looks good on macOS. I finished all my testing, including testing with the metal pipeline.
The only thing needed is a timeout value on one of the tests to avoid hanging on Linux when running with a Wayland display server. I'll approve once you make that change.
// only verify that the JavaFX renderer and JavaFX Robot can round-trip | ||
// colors but they might both be working in the wrong space. We use an | ||
// AWT Robot to verify that they are working in sRGB. | ||
@Test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test needs a timeout value to avoid hanging the test job on Linux with Wayland. See JDK-8335468. I recommend:
@Test(timeout = 15000)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe there is a way to skip the test on Wayland until we find a proper solution?
Asking for completeness sake - simply adding a timeout works too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Q: is this the only test that needs explicit timeout?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see any way to query whether we're running under Wayland or not. That would be nice to have.
This is the only test that uses the AWT Robot on Linux. The window background test also uses the AWT Robot but only runs on Mac.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@azvegint added an isOnWayland
method to SwingNodeBase.java
. I'll file a new testbug to skip tests that use AWT Robot on Wayland pending the fix for JDK-8335468. As part of that, we can move isOnWayland
to Util.java
(and fix it to first check PlatformUtil::isLinux
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe we ought to fast track an isolated addition of isOnWayland()
and integrate that first? what do you think?
edit: never mind, this PR is already integrated. aren't we supposed to wait 24 hrs before integrating?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I filed https://bugs.openjdk.org/browse/JDK-8337827 to track this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe we ought to fast track an isolated addition of
isOnWayland()
and integrate that first? what do you think?
Not as part of this PR, no.
edit: never mind, this PR is already integrated. aren't we supposed to wait 24 hrs before integrating?
That's 24 hours after "rfr".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's all good then. thanks for filing JDK-8337827
/integrate |
Going to push as commit 19d09e6.
Your commit was automatically rebased without conflicts. |
@beldenfox Pushed as commit 19d09e6. 💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored. |
When drawing to the screen JavaFX is producing sRGB colors but on macOS that’s not necessarily what the user is seeing. Since the pixels are not tagged as sRGB the OS is copying them unmodified to the frame buffer to be displayed in the screen’s color space. In general Mac’s don’t default to sRGB so the colors will be wrong. The fix for this is a one-liner; we just need to declare that our CALayer uses the sRGB color space so the OS will convert it to the screen’s space (presumably with a slight performance penalty).
In the reverse direction the Robot should be returning sRGB colors. The getPixelColor calls were making no conversion. The getScreenCapture calls were converting to genericRGB, not sRGB, and so the results didn’t match the getPixelColor calls. This PR fixes these bugs; getPixelColor and getScreenCapture both return sRGB.
Now that everything is working in the same space when JavaFX writes out a pixel and then reads it back in the colors should match within a limited tolerance (due to rounding issues when converting from float to int and back). But that just means the various glass code paths are using the same space to perform conversions, not that it’s sRGB. AWT is color space aware and so the automated test employs an AWT Robot to double-check the results.
I swept through the rest of the Mac glass code and found a few places where colors were being converted to deviceRGB instead of sRGB e.g. when reading colors for PlatformPreferences or creating images for drag and drop. I could not think of a good way of writing automated tests for these cases.
I started investigating this since Robot tests were failing unless the monitor’s profile was set to sRGB. Unfortunately this PR doesn’t entirely fix that. My monitor uses Display P3 and I’m still seeing failures on the SwingNodeJDialogTest. The test writes out pure BLUE colors and gets back colors with a surprising amount of red. I’ve verified that this has nothing to do with JavaFX, it happens when I use CoreGraphics to make the sRGB => Display P3 color conversions directly. I guess this is a cautionary tale about what happens when you work near the edges of a color space’s gamut.
Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jfx.git pull/1473/head:pull/1473
$ git checkout pull/1473
Update a local copy of the PR:
$ git checkout pull/1473
$ git pull https://git.openjdk.org/jfx.git pull/1473/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 1473
View PR using the GUI difftool:
$ git pr show -t 1473
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jfx/pull/1473.diff
Webrev
Link to Webrev Comment