Skip to content

Add support color mode.#96

Open
tychedelia wants to merge 3 commits intoprocessing:mainfrom
tychedelia:color-mode
Open

Add support color mode.#96
tychedelia wants to merge 3 commits intoprocessing:mainfrom
tychedelia:color-mode

Conversation

@tychedelia
Copy link
Copy Markdown
Member

Adds support for "color mode", see p5 and processing.

This is a bit weird and partly legacy cruft. The key contention here is about this question of scaling, i.e. the "max" positional args. It seems, historically, this was used to switch between 8bit and 0-1 normalized color values (despite the fact that everything in Processing is 8-bit internally). However, p5 also demonstrates using it just to set an arbitrary range. I cannot for the life of me understand why / when this latter use case would be helpful, but it exists.

Internally, everything in our core just uses Bevy color which is floats.

Here's basically our current logic as expressed in this PR for a given Python method foo which accepts a color:

  • foo(1.0, 1.0, 1.0, 1.0) uses the configured ColorMode , by default sRGB.
  • foo(1.0) or foo(1.0, 1.0) maps to grayscale and scales using ColorMode.
  • foo(vec4(...)) or foo(vec4(..)) same as above but using vec instances.
  • foo(255, 255, 255, 255) (i.e. ints) uses the configured ColorMode and is scaled to a normalized float internally.
  • foo(oklch(...)) uses the provided Color instance and is considered to be fully resolved, i.e. it does not observe the configured color mode.

Comment on lines -19 to -27
impl From<LinearRgba> for Color {
fn from(lin: LinearRgba) -> Self {
let srgb: Srgba = lin.into();
srgb.into()
}
}

impl From<Srgba> for Color {
fn from(srgb: Srgba) -> Self {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this was surprising to me! Isn't From<T> the way to handle generally?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Mmm, probably a more stylistic thing but before we were saying a color is ALWAYS a srgb repr and now it's more just like, this is one way you can construct a color? Since all the specific color spaces impl Into<bevy::Color> we could probably impl From<bevy::Color> for our color and it would probably "just work"

Copy link
Copy Markdown
Contributor

@catilac catilac left a comment

Choose a reason for hiding this comment

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

left question but i think this looks good! I like the interface of tuples to structured color object, and being able to pass a specific color space explicitly


impl From<Srgba> for Color {
fn from(srgb: Srgba) -> Self {
pub fn from_linear(lin: LinearRgba) -> Self {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is the idea we would implement this for every color space?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is just a specific helper because some operations like GPU readback return raw bytes in a linear format.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ahh i see!

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