Skip to content

Conversation

bresilla
Copy link
Contributor

@bresilla bresilla commented Dec 28, 2020

For each colorstruct (Color, Lab, RGB...) traits 'From' and 'Diplay'
are coded. Those are very important when you want simply comvert
from one color to another with standard Rust things:
let new_color = Lab::from(&Color)
or
let new_color: Lab = somme_color.into()

In addidtion another delta_e was added: cir94, which is faster
than ciede2000 bu more accurate than cie76.

Lastly, a function nearest was added that is 5 lines, but,
with your premission in the future, i want to add functionality
to extract colors fom image, and this function is needed. It
simply finds the index and distance from nearest color from a group of
colors

For each colorstruct (Color, Lab, RGB...) traits <From> and <Diplay>
are coded. Those are very important when you want simply comvert
from one color to another with:
`let new_color = Lab::from(&Color)`
or
`let new_color: Lab = somme_color.into()`

Same time another delta_e was added: cir94, which is faster
than ciede2000 bu more accurate than cie76.

Lastly, a function `nearest` was added that is 5 lines, but,
with your premission in the future, i want to add functionality
to extract colors fom image, and this function is needed. It
simply finds the index and distance from nearest color from a group of
colors
@sharkdp
Copy link
Owner

sharkdp commented Dec 29, 2020

Thank you for your contribution!

All of these changes sound great, but I would prefer if we could split them into multiple PRs.

i want to add functionality
to extract colors fom image, and this function is needed.

This sounds like a useful functionality, but I'm not sure it would really fit into this library. Wouldn't it require new dependencies?

@bresilla
Copy link
Contributor Author

Yes sure. I think that delta_e changes can be ingnored for the moment. I can try later as anther PR for that (an loading colors from images - which requires only image lib).

The changes in lib file are that have the traits From and Display added.
I don't know if you want this as two PR's (one for each)? Is that what you mean to split in multiple PR'S?

@sharkdp
Copy link
Owner

sharkdp commented Dec 29, 2020

I don't know if you want this as two PR's (one for each)? Is that what you mean to split in multiple PR'S?

No. I Display and From is fine in one PR, but it would be great to split out the other things (nearest and new distance function)

@bresilla
Copy link
Contributor Author

Sure thing.
I'll do that.

PS: I am building a tool that uses extensively pastel, and along the way, if i see that some functions are better in pastel, I'll make a PR :)

Some changes added to `delta_e` are reverted back
so latter another PR will be added with those changes
To the main struct Color, the display functionality is added
and it defaults to HSLA display. Since they are very similar
to print the.
@sharkdp
Copy link
Owner

sharkdp commented Dec 29, 2020

PS: I am building a tool that uses extensively pastel, and along the way, if i see that some functions are better in pastel, I'll make a PR :)

Sounds great. Definitely interested to hear more 😄

@bresilla
Copy link
Contributor Author

bresilla commented Dec 29, 2020

You already have in the main function the print_XXX_string(), which in all cases is a formated version something like hsl({:.0},{space}{:.1}%,{space}{:.1}%). Do you think that the display funciton we should have more like hsl({}, {}, {}), so its more like raw numbers. SO when people want to use:

let new_color = Color::from(&RGBA{ r:100, g:100, b:100, alpha: 1.0} )

then this println!("{}", new_color.to_hsl_string()) would print better formmated version like:

hsl(0, 1.0, 0.5)

while this println!("{}", new_color) would print a rawer version:

hsl(0.0000, 1.0000, 0.5253)

So, if you use the function you build it, then you get a prettier format, but if you don't specify, the Display trait will print it a bit more accurate but less pretty.

@sharkdp
Copy link
Owner

sharkdp commented Dec 29, 2020

So, if you use the function you build it, then you get a prettier format, but if you don't specify, the Display trait will print it a bit more accurate but less pretty.

Yes, I think that's a good idea. Just do the "bare minimum" work in the Display trait. It's meant for debugging, not for pretty-printing (to my knowledge).

@sharkdp
Copy link
Owner

sharkdp commented Dec 29, 2020

Could you please also add an entry to the "unreleased" section in CHANGELOG.md? The format for entries is:

- Description what has been changed, see #123 (@user)

where #123 links to the bug ticket and/or the PR and user is your username.

@bresilla
Copy link
Contributor Author

Could you please also add an entry to the "unreleased" section in CHANGELOG.md? The format for entries is:

Done. :)

So, if you use the function you build it, then you get a prettier format, but if you don't specify, the Display trait will print it a bit more accurate but less pretty.

Well, there is the Debug trait too but that is automatically implemented i believe, in the other hand the Display makes possible that any struct that implements can have to_string() which is very useful for others that want to use this library.

@sharkdp sharkdp merged commit 9f0c882 into sharkdp:master Dec 29, 2020
@sharkdp
Copy link
Owner

sharkdp commented Dec 29, 2020

Thank you!

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

Successfully merging this pull request may close these issues.

2 participants