mirror of
https://github.com/Cykooz/fast_image_resize.git
synced 2026-10-07 17:01:09 +00:00
Merge pull request #56 from mina86/a
Add bytemuck feature and implement some bytemuck traits for Pixel type
This commit is contained in:
@@ -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"]
|
||||
|
||||
@@ -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]
|
||||
|
||||
Reference in New Issue
Block a user