Skip to content

Commit

Permalink
Thread improvements, a lot of reworking
Browse files Browse the repository at this point in the history
  • Loading branch information
awxkee committed Jun 4, 2024
1 parent 90d6e5b commit b734bcd
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 28 deletions.
42 changes: 21 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,27 @@ Supported only NEON and SSE.

This library provides for you some conveniences to scale in different color spaces.

#### Example integration with `image` crate

```rust
let img = ImageReader::open("./assets/asset.png")
.unwrap()
.decode()
.unwrap();
let dimensions = img.dimensions();
let mut bytes = Vec::from(img.as_bytes());

let mut scaler = LinearScaler::new(ResamplingFunction::Lanczos3);
scaler.set_threading_policy(ThreadingPolicy::Adaptive);
let store =
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 / 2, dimensions.1 as usize / 2),
store,
true
);
```

### Performance

Faster or comparable to `fast-image-resize`, when implemented equal SIMD and pixel type.
Expand Down Expand Up @@ -54,27 +75,6 @@ M3 Pro. NEON
| pic-scale | 38.75 |
| fir sse | 45.79 |

#### Example integration with `image` crate

```rust
let img = ImageReader::open("./assets/asset.png")
.unwrap()
.decode()
.unwrap();
let dimensions = img.dimensions();
let mut bytes = Vec::from(img.as_bytes());

let mut scaler = LinearScaler::new(ResamplingFunction::Lanczos3);
scaler.set_threading_policy(ThreadingPolicy::Adaptive);
let store =
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 / 2, dimensions.1 as usize / 2),
store,
true
);
```

#### Example in sRGB

In common, you should not downsize an image in sRGB colorspace, however if speed is more preferable than more proper scale you may omit linearizing
Expand Down
1 change: 1 addition & 0 deletions src/rgba_f32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ fn convolve_horizontal_rgba_f32_native(
}
}

#[cfg(all(target_arch = "aarch64", target_feature = "neon"))]
#[inline(always)]
fn convolve_vertical_rgb_native_row(
total_width: usize,
Expand Down
12 changes: 5 additions & 7 deletions src/rgba_u8.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#[cfg(all(target_arch = "aarch64", target_feature = "neon"))]
use std::arch::aarch64::*;
#[cfg(target_arch = "x86")]
use std::arch::x86::*;
use std::sync::Arc;

Check failure on line 3 in src/rgba_u8.rs

View workflow job for this annotation

GitHub Actions / Build

unused import: `std::sync::Arc`

use rayon::ThreadPool;
Expand All @@ -14,9 +12,9 @@ use crate::neon_simd_u8::*;
use crate::rgb_u8::*;
#[cfg(any(target_arch = "x86_64", target_arch = "x86"))]
use crate::sse_rgb_u8::sse_rgb::*;
use crate::support::{PRECISION, ROUNDING_APPROX};
use crate::unsafe_slice::UnsafeSlice;

Check failure on line 16 in src/rgba_u8.rs

View workflow job for this annotation

GitHub Actions / Build

unused import: `crate::unsafe_slice::UnsafeSlice`
use crate::ImageStore;
use crate::support::ROUNDING_APPROX;

#[cfg(any(target_arch = "x86_64", target_arch = "x86"))]
fn convolve_horizontal_rgba_sse(
Expand Down Expand Up @@ -280,10 +278,10 @@ fn convolve_horizontal_rgba_native(
let dest_ptr = unsafe { unsafe_destination_ptr_0.add(px) };

unsafe {
*dest_ptr = (sum_r >> 12).min(255).max(0) as u8;
*dest_ptr.add(1) = (sum_g >> 12).min(255).max(0) as u8;
*dest_ptr.add(2) = (sum_b >> 12).min(255).max(0) as u8;
*dest_ptr.add(3) = (sum_a >> 12).min(255).max(0) as u8;
*dest_ptr = (sum_r >> PRECISION).min(255).max(0) as u8;
*dest_ptr.add(1) = (sum_g >> PRECISION).min(255).max(0) as u8;
*dest_ptr.add(2) = (sum_b >> PRECISION).min(255).max(0) as u8;
*dest_ptr.add(3) = (sum_a >> PRECISION).min(255).max(0) as u8;
}

filter_offset += approx_weights.aligned_size;
Expand Down

0 comments on commit b734bcd

Please sign in to comment.