Merge pull request #56 from mina86/a

Add bytemuck feature and implement some bytemuck traits for Pixel type
This commit is contained in:
Kirill Kuzminykh
2025-11-27 22:39:29 +03:00
committed by GitHub
2 changed files with 22 additions and 0 deletions
+3
View File
@@ -36,6 +36,9 @@ rayon = { version = "1.11", optional = true }
## [DynamicImage](https://docs.rs/image/latest/image/enum.DynamicImage.html)
## type from the `image` crate.
image = ["dep:image", "dep:bytemuck"]
## Enable this feature to implement traits [bytemuck::Pod] and
## [bytemuck::Zeroable] for `Pixel` type.
bytemuck = ["dep:bytemuck"]
## This feature enables image processing in the ` rayon ` thread pool.
rayon = ["dep:rayon", "resize/rayon", "image/rayon"]
for_testing = ["image", "image/png"]
+19
View File
@@ -208,6 +208,25 @@ where
}
}
// SAFETY: bytemuck derives are tripped by the use of generic arguments.
// However, since Pixel<T, _, _> is repr(C) it introduces no padding after T nor
// imposes any additional limitations on T. Hence, if T is Zeroable, Pixel is
// Zeroable.
#[cfg(feature = "bytemuck")]
unsafe impl<T: bytemuck::Zeroable, C, const COUNT_OF_COMPONENTS: usize>
bytemuck::Zeroable for Pixel<T, C, COUNT_OF_COMPONENTS>
where
T: Sized + Copy + Clone + PartialEq + Default + 'static,
C: PixelComponent {}
// SAFETY: As above. If T is Pod than Pixel<T> is Pod.
#[cfg(feature = "bytemuck")]
unsafe impl<T: bytemuck::Pod, C, const COUNT_OF_COMPONENTS: usize>
bytemuck::Pod for Pixel<T, C, COUNT_OF_COMPONENTS>
where
T: Sized + Copy + Clone + PartialEq + Default + 'static,
C: PixelComponent {}
macro_rules! pixel_struct {
($name:ident, $type:tt, $comp_type:tt, $comp_count:literal, $pixel_type:expr, $doc:expr) => {
#[doc = $doc]