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

colour_to_integer() for "transparent" and NA_character_ "colors" #13

Closed
trevorld opened this issue May 31, 2024 · 2 comments
Closed

colour_to_integer() for "transparent" and NA_character_ "colors" #13

trevorld opened this issue May 31, 2024 · 2 comments

Comments

@trevorld
Copy link

I'm observing that colour_to_integer() is casting "transparent" to an opaque color equivalent to "white" (with a message saying unknown color) and is casting NA_character_ to "#00000000" which is a fully transparent value but a slightly different fully transparent value from what col2rgb() assigns to it. I'd pedantically "expect" colour_to_integer(NA_character_) to instead return 16777215L (the same as colour_to_integer("#FFFFFF00")).

> library("nara")
> colour_to_integer("#FFFFFF00") |> integer_to_colour()
[1] "#ffffff00"
> colour_to_integer("transparent") |> integer_to_colour()
Unknown colour: transparent
[1] "#ffffffff"
> colour_to_integer(NA_character_) |> integer_to_colour()
[1] "#00000000"
> col2rgb(c("transparent", "#FFFFFF00", NA_character_, "white"),  
          alpha = TRUE)
      [,1] [,2] [,3] [,4]
red    255  255  255  255
green  255  255  255  255
blue   255  255  255  255
alpha    0    0    0  255

I've observed that farver::encode_native() also has trouble with these two edge cases: thomasp85/farver#47

@trevorld
Copy link
Author

My understanding is that some graphic devices or image viewers don't support alpha transparency so this would be the difference between a "transparent" background being rendered "white" or "black" in such devices/programs...

@coolbutuseless
Copy link
Owner

Thanks for raising the issue.

transparent and NA_character now return the integer for #ffffff00

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

2 participants