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

Importing using Hex and exporting using RGB255 does not always return the correct values #12

Closed
belak opened this issue Jul 6, 2017 · 2 comments

Comments

@belak
Copy link
Contributor

belak commented Jul 6, 2017

Ran into an example with the base16-builder-go where grabbing a value from a hex string and then outputting the rgb values then converting them back to hex isn't matching up.

Here's an example:

package main

import (
	"fmt"

	"github.com/lucasb-eyer/go-colorful"
)

func main() {
	color, _ := colorful.Hex("#4a4543")
	r, g, b := color.RGB255()
	fmt.Printf("#%02x%02x%02x\n", r, g, b)
}

As you can see the input value is #4a4543 but (on my machine) it outputs #494543.

@belak
Copy link
Contributor Author

belak commented Jul 6, 2017

It looks like the fix is fairly simple (add 0.5 to all the values from RGB255 before converting to uint8, same as what Hex does), but the tests are painful because they don't line up with the other values (turns out using numbers that aren't as clean for input means you don't get numbers as clean in the output ☹️ ) and there are no tests covering RGBA or RGB255.

@belak
Copy link
Contributor Author

belak commented Jul 6, 2017

Also, as far as I can tell, this is related to golang/go#20100 as well because even the +0.5 isn't a perfect round function.

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