Skip to content
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

WIP: Add support for std::simd #13

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ rust-version = "1.61"
[features]
default = ["std"]
simd = ["std"]
nightly-portable-simd = ["std"]
std = []

[dependencies]
Expand Down
56 changes: 45 additions & 11 deletions src/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -453,19 +453,53 @@ impl<W: JfifWrite> Encoder<W> {
}
}

match color_type {
ColorType::Luma => self.encode_image(GrayImage(data, width, height))?,
ColorType::Rgb => self.encode_image(RgbImage(data, width, height))?,
ColorType::Rgba => self.encode_image(RgbaImage(data, width, height))?,
ColorType::Bgr => self.encode_image(BgrImage(data, width, height))?,
ColorType::Bgra => self.encode_image(BgraImage(data, width, height))?,
ColorType::Ycbcr => self.encode_image(YCbCrImage(data, width, height))?,
ColorType::Cmyk => self.encode_image(CmykImage(data, width, height))?,
ColorType::CmykAsYcck => self.encode_image(CmykAsYcckImage(data, width, height))?,
ColorType::Ycck => self.encode_image(YcckImage(data, width, height))?,
#[cfg(feature = "nightly-portable-simd")]
{
use crate::std_simd::*;

return match color_type {
ColorType::Luma => self
.encode_image_internal::<_, StdSimdOperations>(GrayImage(data, width, height)),
ColorType::Rgb => self.encode_image_internal::<_, StdSimdOperations>(
RgbImageStdSimd(data, width, height),
),
ColorType::Rgba => self.encode_image_internal::<_, StdSimdOperations>(
RgbaImageStdSimd(data, width, height),
),
ColorType::Bgr => self.encode_image_internal::<_, StdSimdOperations>(
BgrImageStdSimd(data, width, height),
),
ColorType::Bgra => self.encode_image_internal::<_, StdSimdOperations>(
BgraImageStdSimd(data, width, height),
),
ColorType::Ycbcr => self.encode_image_internal::<_, StdSimdOperations>(
YCbCrImage(data, width, height),
),
ColorType::Cmyk => self
.encode_image_internal::<_, StdSimdOperations>(CmykImage(data, width, height)),
ColorType::CmykAsYcck => self.encode_image_internal::<_, StdSimdOperations>(
CmykAsYcckImage(data, width, height),
),
ColorType::Ycck => self
.encode_image_internal::<_, StdSimdOperations>(YcckImage(data, width, height)),
};
}

Ok(())
#[cfg(not(feature = "nightly-portable-simd"))]
{
match color_type {
ColorType::Luma => self.encode_image(GrayImage(data, width, height))?,
ColorType::Rgb => self.encode_image(RgbImage(data, width, height))?,
ColorType::Rgba => self.encode_image(RgbaImage(data, width, height))?,
ColorType::Bgr => self.encode_image(BgrImage(data, width, height))?,
ColorType::Bgra => self.encode_image(BgraImage(data, width, height))?,
ColorType::Ycbcr => self.encode_image(YCbCrImage(data, width, height))?,
ColorType::Cmyk => self.encode_image(CmykImage(data, width, height))?,
ColorType::CmykAsYcck => self.encode_image(CmykAsYcckImage(data, width, height))?,
ColorType::Ycck => self.encode_image(YcckImage(data, width, height))?,
}
Ok(())
}
}

/// Encode an image
Expand Down
6 changes: 6 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#![no_std]
#![cfg_attr(not(feature = "simd"), forbid(unsafe_code))]

#![cfg_attr(feature = "nightly-portable-simd", feature(portable_simd))]

#[cfg(feature = "std")]
extern crate std;

Expand All @@ -33,6 +35,10 @@ extern crate core;

#[cfg(all(feature = "simd", any(target_arch = "x86", target_arch = "x86_64")))]
mod avx2;

#[cfg(feature = "nightly-portable-simd")]
mod std_simd;

mod encoder;
mod error;
mod fdct;
Expand Down
9 changes: 9 additions & 0 deletions src/std_simd.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
mod ycbcr;

pub(crate) use ycbcr::*;
use crate::encoder::Operations;

pub(crate) struct StdSimdOperations;

impl Operations for StdSimdOperations {
}
Loading
Loading