Skip to content
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

Color conversion precision error #7

Open
FilippoVigani opened this issue Apr 11, 2022 · 0 comments
Open

Color conversion precision error #7

FilippoVigani opened this issue Apr 11, 2022 · 0 comments

Comments

@FilippoVigani
Copy link

I was playing around with the library - great work by the way - and encountered some issues when converting back to sRGB.

I noticed them when creating an awt.Color after a few conversions using the library and noticed the sRGB float value was out of range. You can easily reproduce the issue with the following code:

    val srgbColor = Srgb(testColor)
    val oklabColor = srgbColor.convert<Oklab>()
    val computedSrgbColor = oklabColor.convert<Srgb>()
    val awtColor = java.awt.Color(computedSrgbColor.r.toFloat(), computedSrgbColor.g.toFloat(), computedSrgbColor.b.toFloat())

The value of computedSrgbColor has a value of r which is 1.0000000001775198, when converted back to Float it rounds back to 1.0. However both the value of g and b, even when converter to float fall out of the range [0,1], and are in fact negative (respectively -6.415840168402798E-8 and -3.9362722935143425E-7).

I was wondering if they are both just expected rounding errors which are safe to be coerced in the range [0,1], or I am missing something which isn't obvious.

For clarification I'm just using the conversion to awt.Color to easily preview them in the debugger :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant