-
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
A compatible option for decoding to various pixel types #1499
Comments
The problem with the current Pixel trait is how COLOR_TYPE is implemented. After stripping out the macros, the code looks like: impl<T: Primitive + 'static> Pixel for Rgba<T> {
const COLOR_TYPE: ColorType =
[ColorType::Rgba8, ColorType::Rgba16][(std::mem::size_of::<T>() > 1) as usize];
} At one point I looked into using I guess that |
Wouldn't it be possible to have one macro call for each color type? Like: impl_pixel!{ RGB, f32, 3 }
impl_pixel!{ RGBA, f32, 4 }
impl_pixel!{ RGB, u8, 3 }
impl_pixel!{ RGBA, u8, 4 }
impl_pixel!{ Y, f32, 1 }
... This might simplify the implementation of the macro |
Not without getting rid of |
Yes, but I don't think this would be a problem. Each macro invocation implements the type directly instead of having one generic I'll try to find out whether implementing pixel this way would be an easy change |
I think I have arrived at a possible solution. I changed the macro definition. It should be a backwards-compatible change, except for the generic parameter now being replaced with concrete primitive types. It's not backwards compatible, because the user now can't put their own Calling the macro now looks like this: impl_colors! {
Rgb, #[doc="Red, green, and blue. No alpha. Can contain three `u8`, `u16` or `f32` values."],
"RGB", 3, false,
u8:Rgb8, u16:Rgb16, f32:Rgb32F
}
impl_colors! {
Rgba, #[doc="Red, green, blue and alpha. Can contain four `u8`, `u16` or `f32` values."],
"RGBA", 4, true,
u8:Rgba8, u16:Rgba16, f32:Rgba32F
}
impl_colors! {
Bgr, #[doc="Red, green, and blue. No alpha. Can contain three `u8` or `u16` values."],
"BGR", 3, false,
u8:Bgr8
}
impl_colors! {
Bgra, #[doc="Red, green, blue and alpha. Can contain four `u8` or `u16` values."],
"BGRA", 4, true,
u8:Bgra8
}
impl_colors! {
Luma, #[doc="Luminance. No alpha. Can contain one `u8` or `u16` value."],
"Y", 1, false,
u8:L8, u16:L16
}
impl_colors! {
LumaA, #[doc="Luminance and alpha. Can contain two `u8` or `u16` values."],
"YA", 2, true,
u8:La8, u16:La16
} |
Also, there seem to be some |
The pixel type could be drastically simplified, even using a generic implementation again, if we could split up the channels and the bit depth ( |
I'm not a fan of taking chances on this one. It either is compatible according to the Rust RFC rules or we add a second trait. In any case, the cost of a different trait doesn't seem too high unless your experimentation yields a different result. |
I do think a breaking change could be justified if a significant enough improvement was being made to the pixel structs. But we shouldn't release a minor version which could risk breaking downstream users |
That's what I was trying to say: Definitely enough to justify going to the next major version, not enough to disregard SemVer and try to come up with justifications to represent it as compatible. |
I'm currently trying to add f32 support for the dynamic image, where it is necessary to implement f32 support for the pixel type. The dynamic image will be a breaking change anyways, and I already refactored the pixel macro for that use case. How about we target both the dynamic image f32 variant and the pixel f32 support for the |
This helper method as sketched would then be better suited for
impl ImageBuffer
. It is similar toDynamicImage::from_decoder
. I'm afraid thePixel
issue is something we can't easily resolve in this major version ofimage
. We could, however, already add an improved trait that is just used for these method. Something like:In any case, I would much rather discuss these helpers in a separate PR after the core EXR functionality has been added together with the new
ColorType
variant :)Originally posted by @HeroicKatora in #1475 (comment) (Read the responses from before, this is a condensed sketch derived from the oberservation of @johannesvollmer in supporting a large range of types in EXR decoder).
The text was updated successfully, but these errors were encountered: