Skip to content

Commit

Permalink
Merge pull request #34 from awxkee/dev
Browse files Browse the repository at this point in the history
x86 improvements and bugfixes
  • Loading branch information
awxkee authored Jan 9, 2025
2 parents 9e3da32 + 4f4d0b6 commit 8346606
Show file tree
Hide file tree
Showing 21 changed files with 710 additions and 1,621 deletions.
2 changes: 1 addition & 1 deletion app/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ edition = "2021"
[dependencies]
image = { version = "0.25.5", features = ["default"] }
#image = { path= "../../../RustroverProjects/image", features = ["default", "avif", "avif-native"] }
pic-scale = { path = "..", features = ["half", "nightly_i8mm"], default-features = true }
pic-scale = { path = "..", features = ["half", "nightly_avx512"], default-features = true }
fast_image_resize = { version = "5.0.0", features = [] }
half = { version = "2.4.1", default-features = true }

Expand Down
11 changes: 4 additions & 7 deletions app/benches/resize_rgb/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,10 @@ pub fn criterion_benchmark(c: &mut Criterion) {
let src_bytes = binding.as_bytes();

c.bench_function("Pic scale RGB: Lanczos 3", |b| {
let mut copied: Vec<u8> = Vec::from(src_bytes);
let store = ImageStore::<u8, 3>::from_slice(
&mut copied,
dimensions.0 as usize,
dimensions.1 as usize,
)
.unwrap();
let copied: Vec<u8> = Vec::from(src_bytes);
let store =
ImageStore::<u8, 3>::from_slice(&copied, dimensions.0 as usize, dimensions.1 as usize)
.unwrap();
b.iter(|| {
let mut scaler = Scaler::new(ResamplingFunction::Lanczos3);
scaler.set_threading_policy(ThreadingPolicy::Single);
Expand Down
12 changes: 6 additions & 6 deletions app/benches/resize_rgba/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ pub fn criterion_benchmark(c: &mut Criterion) {
let dimensions = img.dimensions();
let src_bytes = img.as_bytes();
c.bench_function("Pic scale RGBA with alpha: Lanczos 3", |b| {
let mut copied: Vec<u8> = Vec::from(src_bytes);
let copied: Vec<u8> = Vec::from(src_bytes);
b.iter(|| {
let mut scaler = Scaler::new(ResamplingFunction::Lanczos3);
scaler.set_threading_policy(ThreadingPolicy::Single);
let store = ImageStore::<u8, 4>::from_slice(
&mut copied,
&copied,
dimensions.0 as usize,
dimensions.1 as usize,
)
Expand All @@ -35,12 +35,12 @@ pub fn criterion_benchmark(c: &mut Criterion) {
let f32_image: Vec<f32> = src_bytes.iter().map(|&x| x as f32 / 255f32).collect();

c.bench_function("Pic scale RGBA with alpha f32: Lanczos 3", |b| {
let mut copied: Vec<f32> = Vec::from(f32_image.clone());
let copied: Vec<f32> = Vec::from(f32_image.clone());
b.iter(|| {
let mut scaler = Scaler::new(ResamplingFunction::Lanczos3);
scaler.set_threading_policy(ThreadingPolicy::Single);
let store = ImageStore::<f32, 4>::from_slice(
&mut copied,
&copied,
dimensions.0 as usize,
dimensions.1 as usize,
)
Expand Down Expand Up @@ -81,12 +81,12 @@ pub fn criterion_benchmark(c: &mut Criterion) {
});

c.bench_function("Pic scale RGBA without alpha: Lanczos 3", |b| {
let mut copied: Vec<u8> = Vec::from(src_bytes);
let copied: Vec<u8> = Vec::from(src_bytes);
b.iter(|| {
let mut scaler = Scaler::new(ResamplingFunction::Lanczos3);
scaler.set_threading_policy(ThreadingPolicy::Single);
let store = ImageStore::<u8, 4>::from_slice(
&mut copied,
&copied,
dimensions.0 as usize,
dimensions.1 as usize,
)
Expand Down
22 changes: 15 additions & 7 deletions app/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,21 @@ fn resize_plane(
}

fn main() {
let mut j = [
3, 3, 3, 3, 7, 7, 7, 7, 11, 11, 11, 11, 15, 15, 15, 15, 19, 19, 19, 19, 23, 23, 23, 23, 27,
27, 27, 27, 31, 31, 31, 31, 35, 35, 35, 35, 39, 39, 39, 39, 43, 43, 43, 43, 47, 47, 47, 47,
51, 51, 51, 51, 55, 55, 55, 55, 59, 59, 59, 59, 63, 63, 63, 63,
];
j.reverse();

println!("{:?}", j);
// test_fast_image();
let img = ImageReader::open("./assets/asset_4.png")
let img = ImageReader::open("./assets/asset_middle.jpg")
.unwrap()
.decode()
.unwrap();
let dimensions = img.dimensions();
let transient = img.to_rgba8();
let transient = img.to_rgb8();
let mut bytes = Vec::from(transient.as_bytes());

let mut scaler = Scaler::new(ResamplingFunction::Lanczos3);
Expand All @@ -60,7 +68,7 @@ fn main() {

//
let store =
ImageStore::<u8, 4>::from_slice(&bytes, dimensions.0 as usize, dimensions.1 as usize)
ImageStore::<u8, 3>::from_slice(&bytes, dimensions.0 as usize, dimensions.1 as usize)
.unwrap();

let dst_size = ImageSize::new(dimensions.0 as usize / 4, dimensions.1 as usize / 4);
Expand All @@ -75,15 +83,15 @@ fn main() {
// )
// .unwrap();

let mut dst_store = ImageStoreMut::<u8, 4>::alloc_with_depth(
dimensions.0 as usize / 2,
dimensions.1 as usize / 2,
let mut dst_store = ImageStoreMut::<u8, 3>::alloc_with_depth(
dimensions.0 as usize / 3,
dimensions.1 as usize / 3,
10,
);

// for i in 0..25 {
let start_time = Instant::now();
scaler.resize_rgba(&store, &mut dst_store, true).unwrap();
scaler.resize_rgb(&store, &mut dst_store).unwrap();

let elapsed_time = start_time.elapsed();
// Print the elapsed time in milliseconds
Expand Down
6 changes: 0 additions & 6 deletions src/avx2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ mod rgb_u8_dot_i8;
#[cfg(feature = "half")]
mod rgba_f16;
mod rgba_f32;
#[cfg(feature = "nightly_avx512")]
mod rgba_u8_dot_lp;
mod rgba_u8_lb;
pub(crate) mod utils;
#[cfg(feature = "half")]
Expand All @@ -50,10 +48,6 @@ mod vertical_u16_lb;
mod vertical_u8;
mod vertical_u8_lp;

#[cfg(feature = "nightly_avx512")]
pub(crate) use crate::avx2::rgba_u8_dot_lp::{
convolve_horizontal_rgba_row_dot, convolve_horizontal_rgba_rows_4_dot,
};
#[cfg(feature = "half")]
pub(crate) use alpha_f16::{avx_premultiply_alpha_rgba_f16, avx_unpremultiply_alpha_rgba_f16};
pub(crate) use alpha_f32::avx_premultiply_alpha_rgba_f32;
Expand Down
Loading

0 comments on commit 8346606

Please sign in to comment.