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

Decouple palette Rgb from Sled #64

Closed
DavJCosby opened this issue Feb 7, 2024 · 4 comments
Closed

Decouple palette Rgb from Sled #64

DavJCosby opened this issue Feb 7, 2024 · 4 comments
Labels
design Discussing larger design and architecture ideas e/api Improving a method in the API, or adding a new one
Milestone

Comments

@DavJCosby
Copy link
Owner

DavJCosby commented Feb 7, 2024

Right now to create a sled, your only option is:

let sled = Sled::new("/path/to/config.toml")?;

Which will populate the Sled struct with LED data, each LED getting 32-bits/channel for color. This behavior should be overridable.

type Rgb8 = Rgb<_, u8>;
type Rgb64 = Rgb<_, u64>;

let lightweight_sled = Sled::<Rgb8>::new("/path/to/config.toml")?; 
let precise_sled = Sled::<Rgb64>::new("/path/to/config.toml")?;

Perhaps even extending to support other palette spaces like RGBA, HSL, etc.

@DavJCosby DavJCosby added e/api Improving a method in the API, or adding a new one design Discussing larger design and architecture ideas labels Feb 7, 2024
@DavJCosby DavJCosby added this to the 0.3.0 milestone Feb 7, 2024
@DavJCosby
Copy link
Owner Author

DavJCosby commented Nov 11, 2024

Lets play some more with this idea. If we let the user specify the the data structure they want to use for colors, we can totally drop palette as a dependency altogether. We'd just have to add some trait bounds to make some guarantees.

One for example, we'd probably need T impl Default to allow us to construct generic colors in the first place.

When #26 gets added, that compiler feature would probably add some requirements like T impl std::ops::Mul<f32, Output=T> and t impl std::ops::Add<Output=T> to enable us to blend between colors.

I'll be experimenting with this design on a the decouple_colors branch.

@DavJCosby
Copy link
Owner Author

I've got this compiling on the decouple_colors branch. Unit tests don't pass yet as they'll need some rewriting, but this seems to be working!

use palette::rgb::Rgb;
let mut palette_sled = Sled::<Rgb>::new("path/to/config.yap")?;
let mut tuple_sled = Sled::<(u8, u8, u8)>::new("path/to/config.yap")?;

palette_sled.set_all(Rgb::new(1.0, 1.0, 1.0));
tuple_sled.set_at_angle(0.2, (64, 128, 255));

@DavJCosby
Copy link
Owner Author

Added bonus, with palette moved from a dependency to a dev dependency, a vanilla build of spatial_led compiles much faster. Goes from 31 dependencies down to 20, compiling on release went from 10.44s down to 3.22s.

@DavJCosby DavJCosby changed the title Option to override color depth for a sled Decouple palette Rgb from Sled Nov 12, 2024
@github-project-automation github-project-automation bot moved this to Backlog in 0.2 Roadmap Nov 12, 2024
@DavJCosby
Copy link
Owner Author

Completed by #91

@github-project-automation github-project-automation bot moved this from Backlog to Done in 0.2 Roadmap Dec 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
design Discussing larger design and architecture ideas e/api Improving a method in the API, or adding a new one
Projects
Status: Done
Development

No branches or pull requests

1 participant