Skip to content

Commit

Permalink
Fix Scaling trait for Linear Scaler
Browse files Browse the repository at this point in the history
  • Loading branch information
awxkee committed Jun 5, 2024
1 parent 156a977 commit c46ae0f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ workspace = { members = ["app"] }

[package]
name = "pic-scale"
version = "0.1.1"
version = "0.1.2"
edition = "2021"
description = "High performance image scaling"
readme = "README.md"
Expand Down
19 changes: 10 additions & 9 deletions app/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
use std::time::Instant;

use fast_image_resize::images::Image;
use fast_image_resize::FilterType::Lanczos3;
use fast_image_resize::{
CpuExtensions, IntoImageView, PixelType, ResizeAlg, ResizeOptions, Resizer,
};
use fast_image_resize::FilterType::Lanczos3;
use fast_image_resize::images::Image;
use image::{EncodableLayout, GenericImageView};
use image::io::Reader as ImageReader;
use image::{EncodableLayout, GenericImageView};

use pic_scale::{ImageSize, ImageStore, ResamplingFunction, Scaler, Scaling, ThreadingPolicy};

fn main() {
// test_fast_image();

let img = ImageReader::open("./assets/asset_middle.jpg")
let img = ImageReader::open("./assets/beach_horizon.png")
.unwrap()
.decode()
.unwrap();
Expand All @@ -22,13 +22,14 @@ fn main() {

let start_time = Instant::now();

let mut scaler = Scaler::new(ResamplingFunction::Bartlett);
scaler.set_threading_policy(ThreadingPolicy::Single);
let mut scaler = Scaler::new(ResamplingFunction::Cubic);
scaler.set_threading_policy(ThreadingPolicy::Adaptive);
let store =
ImageStore::<u8, 3>::from_slice(&mut bytes, dimensions.0 as usize, dimensions.1 as usize);
let resized = scaler.resize_rgb(
ImageSize::new(dimensions.0 as usize / 1, dimensions.1 as usize / 1),
ImageStore::<u8, 4>::from_slice(&mut bytes, dimensions.0 as usize, dimensions.1 as usize);
let resized = scaler.resize_rgba(
ImageSize::new(dimensions.0 as usize / 3, dimensions.1 as usize / 3),
store,
true,
);

let elapsed_time = start_time.elapsed();
Expand Down
13 changes: 7 additions & 6 deletions src/threading_policy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

use rayon::ThreadPool;

use crate::ImageSize;

#[derive(Debug, Copy, Clone, Ord, PartialOrd, Eq, PartialEq)]
Expand All @@ -27,7 +28,6 @@ impl<'a> ThreadingPolicy {
}
}
}

}

impl<'a> ThreadingPolicy {
Expand All @@ -36,11 +36,12 @@ impl<'a> ThreadingPolicy {
return None;
}
let threads_count = self.get_threads_count(for_size);
let shared_pool = rayon::ThreadPoolBuilder::new()
return match rayon::ThreadPoolBuilder::new()
.num_threads(threads_count)
.use_current_thread()
.build()
.unwrap();
return Some(shared_pool);
{
Ok(pool) => Some(pool),
Err(_) => None,
};
}
}
}

0 comments on commit c46ae0f

Please sign in to comment.