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

Implement [ok]lab, [ok]lch from color-4 spec. #309

Merged
merged 6 commits into from
Oct 20, 2022

Conversation

tiaanl
Copy link
Collaborator

@tiaanl tiaanl commented Oct 18, 2022

https://w3c.github.io/csswg-drafts/css-color-4/#lab-colors

The size of the new color structs are 32*4 bits which is much bigger than the original 32bit for the RGBA value. This might change in the future.

Copy link
Member

@emilio emilio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The WithAlpha thing is my only concern. I need to take a closer look a the tests but it looks good generally. I think I spotted a couple bugs.

src/color.rs Outdated Show resolved Hide resolved
src/color.rs Outdated Show resolved Hide resolved
src/color.rs Outdated Show resolved Hide resolved
src/color.rs Outdated Show resolved Hide resolved
src/color.rs Outdated Show resolved Hide resolved
src/color.rs Outdated Show resolved Hide resolved
src/color.rs Outdated Show resolved Hide resolved
@tiaanl
Copy link
Collaborator Author

tiaanl commented Oct 18, 2022

Removed the WithAlpha for now. For the tests the only thing I can think is to add some more variations of the values.

@tiaanl tiaanl requested a review from emilio October 18, 2022 10:36
src/color.rs Outdated
/// The b-axis component.
pub b: f32,
/// The alpha component.
pub alpha: u8,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think maybe storing the alpha as an f32 might be better long term (avoids having different computed / animated representations). Wdyt?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would make things easier yes. I think I'm going to do it with RGBA.alpha as well. Right now the size of the struct doesn't matter (we'll see if this is an issue) and dealing with alpha values the same would also makes things much simpler. Can you think of issues with this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main issue is that it'd slow down conversion to nscolor (the Gecko representation of a computed rgba value which is ~everywhere). But might not be a huge issue.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll have to convert to rgba (nscolor) anyway from lab/lch/etc. If this becomes a problem we can optimize.

src/color.rs Outdated Show resolved Hide resolved
@tiaanl tiaanl requested a review from emilio October 19, 2022 10:13
Copy link
Member

@emilio emilio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works for me, with the enum variant names fixed to match the structs.

src/color.rs Outdated
#[derive(Clone, Copy, PartialEq, Debug)]
pub enum AbsoluteColor {
/// Specify sRGB colors directly by their red/green/blue/alpha chanels.
RGBA(Rgba),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I meant the variant names should be Rgba() etc (so I was expecting Rgba(RGBA), sorry if that wasn't clear). But Rgba(Rgba) is also alright.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And now those are renamed too 😄

@GPHemsley
Copy link
Contributor

Note that I began a refactor on this same code in #308 that is still awaiting review.

@tiaanl tiaanl requested a review from emilio October 20, 2022 07:10
@emilio
Copy link
Member

emilio commented Oct 20, 2022

@bors-servo r+

@bors-servo
Copy link
Contributor

📌 Commit 250e11d has been approved by emilio

@emilio
Copy link
Member

emilio commented Oct 20, 2022

(CI fix is in #310. Assuming it's green on top this looks good to me)

@bors-servo
Copy link
Contributor

⌛ Testing commit 250e11d with merge d478409...

@bors-servo
Copy link
Contributor

☀️ Test successful - checks-github
Approved by: emilio
Pushing d478409 to master...

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.

4 participants