fix for rayon, new test
This commit is contained in:
parent
9748483e74
commit
0d5532ab08
3 changed files with 30 additions and 9 deletions
|
@ -12,3 +12,4 @@ keywords.workspace = true
|
||||||
[dependencies]
|
[dependencies]
|
||||||
image = { version = "0.25", features = ["rayon"] }
|
image = { version = "0.25", features = ["rayon"] }
|
||||||
num = "0"
|
num = "0"
|
||||||
|
rayon = "1"
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
use std::ops::{BitOr, Deref, Shl};
|
use std::ops::{BitOr, Deref, DerefMut, Shl};
|
||||||
|
|
||||||
pub use image::*;
|
pub use image::*;
|
||||||
use num::{traits::ToBytes, Zero};
|
use num::{traits::ToBytes, Zero};
|
||||||
|
use rayon::iter::ParallelIterator;
|
||||||
|
|
||||||
use crate::{Bendable, IntoDataBytes, TryFromDataBytes};
|
use crate::{Bendable, IntoDataBytes, TryFromDataBytes};
|
||||||
|
|
||||||
|
@ -54,13 +55,18 @@ where
|
||||||
|
|
||||||
impl<P: Pixel> Bendable for ImageBuffer<P, Vec<P::Subpixel>>
|
impl<P: Pixel> Bendable for ImageBuffer<P, Vec<P::Subpixel>>
|
||||||
where
|
where
|
||||||
Vec<P::Subpixel>: Deref<Target = [P::Subpixel]>,
|
Vec<P::Subpixel>: Deref<Target = [P::Subpixel]> + DerefMut,
|
||||||
P::Subpixel:
|
P::Subpixel: ToBytes
|
||||||
ToBytes + Zero + Shl<u8, Output = P::Subpixel> + BitOr<P::Subpixel, Output = P::Subpixel>,
|
+ Zero
|
||||||
|
+ Shl<u8, Output = P::Subpixel>
|
||||||
|
+ BitOr<P::Subpixel, Output = P::Subpixel>
|
||||||
|
+ Send
|
||||||
|
+ Sync,
|
||||||
|
P: Pixel + Send + Sync,
|
||||||
{
|
{
|
||||||
type Unit = P;
|
type Unit = P;
|
||||||
fn apply<F: Fn(&Self::Unit) -> Self::Unit>(mut self, f: F) -> Self {
|
fn apply<F: Fn(&Self::Unit) -> Self::Unit + Sync>(mut self, f: F) -> Self {
|
||||||
self.pixels_mut().for_each(|p| *p = f(p));
|
self.par_pixels_mut().for_each(|p| *p = f(p));
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -69,8 +75,7 @@ where
|
||||||
mod tests {
|
mod tests {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod ser_de {
|
mod ser_de {
|
||||||
use super::super::{Dimensions, IntoDataBytes, TryFromDataBytes};
|
use super::super::{Dimensions, IntoDataBytes, RgbImage, TryFromDataBytes};
|
||||||
use image::RgbImage;
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn empty() {
|
fn empty() {
|
||||||
|
@ -86,5 +91,20 @@ mod tests {
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn simple() {
|
||||||
|
let image = RgbImage::from_raw(3, 1, vec![1, 2, 3, 4, 5, 6, 7, 8, 9]).unwrap();
|
||||||
|
assert_eq!(
|
||||||
|
Ok(image.clone()),
|
||||||
|
RgbImage::try_from_bytes(
|
||||||
|
image.into_bytes(),
|
||||||
|
Dimensions {
|
||||||
|
width: 3,
|
||||||
|
height: 1
|
||||||
|
}
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@ pub trait Bendable: TryFromDataBytes + IntoDataBytes {
|
||||||
) -> Result<Self, <Self as TryFromDataBytes>::Error> {
|
) -> Result<Self, <Self as TryFromDataBytes>::Error> {
|
||||||
Self::try_from_bytes(b.into_bytes(), format)
|
Self::try_from_bytes(b.into_bytes(), format)
|
||||||
}
|
}
|
||||||
fn apply<F: Fn(&Self::Unit) -> Self::Unit>(self, f: F) -> Self;
|
fn apply<F: Fn(&Self::Unit) -> Self::Unit + Sync>(self, f: F) -> Self;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait IntoDataBytes: Sized {
|
pub trait IntoDataBytes: Sized {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue