diff --git a/bingus/Cargo.toml b/bingus/Cargo.toml index 6676362..066fc46 100644 --- a/bingus/Cargo.toml +++ b/bingus/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bingus" -version = "0.3.0" +version = "0.3.1" edition.workspace = true license.workspace = true description.workspace = true @@ -10,9 +10,9 @@ keywords.workspace = true # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -image = { version = "0.25", features = ["rayon"] } +image = { version = "0.25" } num = "0" -rayon = "1" +rayon = { version = "1", optional = true } infer = "0" thiserror = "2" derive-new = "0" @@ -28,7 +28,6 @@ printpdf = { version = "0.8.2", features = [ "jpeg", "png", "pnm", - "rayon", "tga", "tiff", "js-sys", @@ -41,3 +40,7 @@ font-kit = { version = "0.14.2", features = ["loader-freetype-default"] } [dev-dependencies] project-root = "0" pretty_assertions = "1" + +[features] +default = [] +rayon = ["image/rayon", "printpdf/rayon", "dep:rayon"] diff --git a/bingus/src/bin_/bytes.rs b/bingus/src/bin_/bytes.rs index 0b77a2c..6e1733e 100644 --- a/bingus/src/bin_/bytes.rs +++ b/bingus/src/bin_/bytes.rs @@ -1,5 +1,6 @@ use std::{borrow::Cow, convert::Infallible}; +#[cfg(feature = "rayon")] use rayon::iter::{IntoParallelRefMutIterator, ParallelIterator}; use crate::{Bendable, Bytes, IntoDataBytes, TryFromDataBytes}; @@ -27,10 +28,15 @@ impl TryFromDataBytes for Bytes { impl Bendable for Bytes { type Unit = u8; + #[cfg(feature = "rayon")] fn map) -> Self::Unit + Sync>(mut self, f: F) -> Self { self.par_iter_mut().for_each(|e| *e = f(Cow::Borrowed(e))); self } + fn map) -> Self::Unit + Sync>(mut self, f: F) -> Self { + self.iter_mut().for_each(|e| *e = f(Cow::Borrowed(e))); + self + } fn format() -> crate::Format { crate::Format::Binary } diff --git a/bingus/src/img/image.rs b/bingus/src/img/image.rs index c91e359..6681379 100644 --- a/bingus/src/img/image.rs +++ b/bingus/src/img/image.rs @@ -10,6 +10,7 @@ use num::{ traits::{FromBytes, ToBytes}, Zero, }; +#[cfg(feature = "rayon")] use rayon::iter::ParallelIterator; use thiserror::Error; @@ -178,10 +179,15 @@ where P: Send + Sync, { type Unit = P; + #[cfg(feature = "rayon")] fn map) -> Self::Unit + Sync>(mut self, f: F) -> Self { self.par_pixels_mut().for_each(|p| *p = f(Cow::Borrowed(p))); self } + fn map) -> Self::Unit + Sync>(mut self, f: F) -> Self { + self.pixels_mut().for_each(|p| *p = f(Cow::Borrowed(p))); + self + } fn format() -> crate::Format { Format::Image } diff --git a/bingus/src/snd/raw.rs b/bingus/src/snd/raw.rs index 35ed099..944c5c0 100644 --- a/bingus/src/snd/raw.rs +++ b/bingus/src/snd/raw.rs @@ -6,6 +6,7 @@ use num::{ traits::{FromBytes, ToBytes}, Zero, }; +#[cfg(feature = "rayon")] use rayon::iter::{IntoParallelRefMutIterator, ParallelIterator}; use crate::{Bendable, IntoDataBytes, TryFromDataBytes}; @@ -66,6 +67,7 @@ where } } +#[cfg(feature = "rayon")] impl Bendable for RawSamples where T: Sample + FromBytes + ToBytes + Zero + Send, @@ -81,3 +83,18 @@ where crate::Format::Sound } } + +impl Bendable for RawSamples +where + T: Sample + FromBytes + ToBytes + Zero + Send, + ::Bytes: Sized + for<'a> TryFrom<&'a [u8]>, +{ + type Unit = T; + fn map) -> Self::Unit + Sync>(mut self, f: F) -> Self { + self.0.iter_mut().for_each(|e| *e = f(Cow::Borrowed(e))); + self + } + fn format() -> crate::dynamic::Format { + crate::Format::Sound + } +}