-
Notifications
You must be signed in to change notification settings - Fork 623
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
Revamp the Pixel
trait via the pixeli
crate
#2255
Conversation
The only remaining failing CI check is the |
Thanks for your interest in this crate. This change is far too large and has way too many breaking changes to review/iterate on. Breaking changes and big API additions need to be discussed and agreed on individually before they can be added. And in any case, we've generally been aiming to go 1-2 years between breaking releases |
This comment was marked as off-topic.
This comment was marked as off-topic.
Just to be clear here, this PR would solve:
But if you think not making breaking changes is more important to users, then that is your decision to make I suppose. I'd be interested to your opinion @HeroicKatora on this topic if you have time. |
I don't think this addresses enough of major points raised by #1523 to warrant the breakage either. This PR changes the representation which the least problem here. Declaring a new pre- Designing around the easy goals won't work, as it is the harder goals that break the current design, too. The two key points missing are awareness of color spaces and single responsibility. Instead, this design encodes even more information into the type system and it will run into the same troubles. The There are a few interesting pieces here and there:
If you take one key point, then let it be the one summary also raised during |
BTW we've had a similar conversation about the |
Do you have more info on this? |
See this whole talk, but particularly starting from here: https://youtu.be/m0JgF5Wb-dA?t=395&si=XoK-TroLp4idLt2g |
Repeating some feedback given offline:
|
Good point, I didn't tackle the color space issue at the same time, in that regard the four choices I can think of for attaching color-space to pixels are:
enum ColorSpace {
Unknown,
Linear,
...
}
struct Rgba<T> {
r: T,
g: T,
b: T,
a: T,
color_space: ColorSpace,
}
struct ImageBuffer<P> {
pixels: Vec<P>,
color_space: ColorSpace,
}
As you say the type-system heavy approaches in 3. and 4. are harder to reason with and learn, (is that similar to how With option 2. I think trait FromPixelCommon<P> {
fn from_pixel_common(pixel: P, source_color_space: ColorSpace, destination_color_space: ColorSpace) -> Self;
} Am I understanding correctly? On the single responsibility aspect, which bit of this design goes did you see going against that principle? Are you suggesting moving the helper functions such as |
This is an overhaul of the crate to extract out the
Pixel
types and traits and improve them simultaneously into thepixeli
crate. This would fix #1523 and possibly many of its linked issues.Summary of Changes:
pixeli
crate which becomes a dependencyRgb([T; 3])
to#[repr(C)] struct Rgb<T> {r: T, g: T, b: T}
which is nicer to work with (pixel.g
vspixel.0[1]
)pixeli
dependecy since users will often need to use those types/traits for doing pixel related stuffLuma
is renamed toGray
as that is more understandablePixel::Subpixel
is renamed toPixel::Component
since subpixels are used with physical monitors for the rgb components and so the alpha component doesn't fitDynamicImage
variants needed to be added to pass the testsGray32F
andGrayAlpha32F
which removes the edge condition for thegrayscale()
function not actually convertingRgb32F
image variants to grayscale.channels4()
legacy methods.convert_generic_image()
I understand this is huge PR, but for this to be an atomic PR there wasn't really a way of splitting it any smaller. I also understand that this probably is a breaking change in many different areas, but I think that's acceptable given the scale of improvement this PR offers.
Btw the
pixeli
crate is pretty cool in my biased opinion, the newPixel
trait is wayyy more powerful than the previous one (credit to @johannesvollmer for some of the inspiration (#1523) and @kornelski for the related discussions in thergb
crate) and solves lots of previous issues, (like nowmap_components()
can map to a different component type!).