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

Even if the RGB value is 100%, it will not be 255(ColorParser) #134

Closed
SDH0531 opened this issue Feb 16, 2023 · 3 comments · Fixed by #141
Closed

Even if the RGB value is 100%, it will not be 255(ColorParser) #134

SDH0531 opened this issue Feb 16, 2023 · 3 comments · Fixed by #141
Labels
Milestone

Comments

@SDH0531
Copy link

SDH0531 commented Feb 16, 2023

[AngleSharp.CSS v0.17.0]

If the color is specified in % like "RGB(100%,100%,100%);", the RGB value will be 254 instead of 255.
I checked the source code, the calculation of the color value was as follows.

ColorParser.cs(217)
return (Byte)(255f / 100f * value);

With this, even if the value is 100, the result will be 254.
I don't think this is the correct behavior.

@SDH0531 SDH0531 added the bug label Feb 16, 2023
@SDH0531 SDH0531 changed the title Even if the RGB value is 100%, it will not be 255(CssPrser) Even if the RGB value is 100%, it will not be 255(ColorPrser) Feb 16, 2023
@SDH0531 SDH0531 changed the title Even if the RGB value is 100%, it will not be 255(ColorPrser) Even if the RGB value is 100%, it will not be 255(ColorParser) Feb 16, 2023
@FlorianRappl
Copy link
Contributor

Yes for stability it should be multiplication before division, otherwise we run into FP issues.

PR welcome.

@FlorianRappl FlorianRappl added this to the v1.0 milestone Feb 16, 2023
@SDH0531
Copy link
Author

SDH0531 commented Feb 16, 2023

Hi Florian
That's right, this problem caused by performing division first.
Therefore, this problem can be solved by simply performing the multiplication first.
Thanks

@cyraid
Copy link

cyraid commented Apr 19, 2023

If value is between 0.0 and 1.0, why wouldn't you just do return (byte)(255.0 * value); ? Or am I missing something?

jogibear9988 added a commit to jogibear9988/AngleSharp.Css that referenced this issue Apr 20, 2023
@jogibear9988 jogibear9988 mentioned this issue Apr 20, 2023
9 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants