Skip to content

Commit

Permalink
Ongoing reworking
Browse files Browse the repository at this point in the history
  • Loading branch information
awxkee committed Nov 4, 2024
1 parent 3d14b00 commit e27bec8
Show file tree
Hide file tree
Showing 13 changed files with 44 additions and 41 deletions.
4 changes: 2 additions & 2 deletions src/avx512bw/rgba_to_yuv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
*/

use crate::avx512bw::avx512_utils::{
avx512_deinterleave_rgb, avx512_deinterleave_rgba, avx512_pack_u16, avx512_pairwise_widen_avg,
avx512_rgb_to_ycbcr,
avx512_deinterleave_rgb, avx512_deinterleave_rgba, avx512_pack_u16, avx512_pairwise_widen_avg
,
};
use crate::internals::ProcessedOffset;
use crate::yuv_support::{
Expand Down
4 changes: 2 additions & 2 deletions src/avx512bw/yuv_to_rgba_alpha.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ pub unsafe fn avx512_yuv_to_rgba_alpha<const DESTINATION_CHANNELS: u8, const SAM
rounding_const,
));

let a_values = _mm512_loadu_si512(a_plane.as_ptr().add(a_offset + cx) as *const i32);
let a_values = _mm512_loadu_si512(a_plane.as_ptr().add(cx) as *const i32);

let (r_values, g_values, b_values);

Expand All @@ -203,7 +203,7 @@ pub unsafe fn avx512_yuv_to_rgba_alpha<const DESTINATION_CHANNELS: u8, const SAM
b_values = avx512_pack_u16(b_low, b_high);
}

let dst_shift = rgba_offset + cx * channels;
let dst_shift = cx * channels;

match destination_channels {
YuvSourceChannels::Rgb => {
Expand Down
4 changes: 3 additions & 1 deletion src/images.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,16 @@ pub enum BufferStoreMut<'a, T: Copy + Debug> {
}

impl<T: Copy + Debug> BufferStoreMut<'_, T> {
#[allow(clippy::should_implement_trait)]
pub fn borrow(&self) -> &[T] {
match self {
Self::Borrowed(p_ref) => p_ref,
Self::Owned(vec) => vec,
}
}

pub fn as_mut(&mut self) -> &mut [T] {
#[allow(clippy::should_implement_trait)]
pub fn borrow_mut(&mut self) -> &mut [T] {
match self {
Self::Borrowed(p_ref) => p_ref,
Self::Owned(vec) => vec,
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#![allow(clippy::manual_clamp)]
#![cfg_attr(feature = "nightly_avx512", feature(cfg_version))]
#![cfg_attr(feature = "nightly_avx512", feature(avx512_target_feature))]
#![cfg_attr(feature = "nightly_avx512", feature(stdarch_x86_avx512))]
extern crate core;

#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
Expand Down
4 changes: 2 additions & 2 deletions src/rgb_to_nv_p16.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ fn rgbx_to_yuv_bi_planar_10_impl<
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
let _use_sse = std::arch::is_x86_feature_detected!("sse4.1");

let y_plane = bi_planar_image.y_plane.as_mut();
let uv_plane = bi_planar_image.uv_plane.as_mut();
let y_plane = bi_planar_image.y_plane.borrow_mut();
let uv_plane = bi_planar_image.uv_plane.borrow_mut();
let height = bi_planar_image.height;
let width = bi_planar_image.width;
let y_stride = bi_planar_image.y_stride * 2;
Expand Down
4 changes: 2 additions & 2 deletions src/rgb_to_y.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,15 @@ fn rgbx_to_y<const ORIGIN_CHANNELS: u8>(
{
iter = gray_image
.y_plane
.as_mut()
.borrow_mut()
.par_chunks_exact_mut(gray_image.y_stride as usize)
.zip(rgba.par_chunks_exact(rgba_stride as usize));
}
#[cfg(not(feature = "rayon"))]
{
iter = gray_image
.y_plane
.as_mut()
.borrow_mut()
.chunks_exact_mut(gray_image.y_stride as usize)
.zip(rgba.chunks_exact(rgba_stride as usize));
}
Expand Down
6 changes: 3 additions & 3 deletions src/rgb_to_yuv_p16.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,9 @@ fn rgbx_to_yuv_impl<
let rgba_offset = rgba_stride as usize * y;

let rgba = &rgba[rgba_offset..];
let y_plane = &mut planar_image.y_plane.as_mut()[y_offset..];
let u_plane = &mut planar_image.u_plane.as_mut()[u_offset..];
let v_plane = &mut planar_image.v_plane.as_mut()[v_offset..];
let y_plane = &mut planar_image.y_plane.borrow_mut()[y_offset..];
let u_plane = &mut planar_image.u_plane.borrow_mut()[u_offset..];
let v_plane = &mut planar_image.v_plane.borrow_mut()[v_offset..];

let mut _cx = 0usize;
let mut _ux = 0usize;
Expand Down
4 changes: 2 additions & 2 deletions src/rgba_to_nv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ fn rgbx_to_nv<const ORIGIN_CHANNELS: u8, const UV_ORDER: u8, const SAMPLING: u8>

let height = bi_planar_image.height;
let width = bi_planar_image.width;
let y_plane = bi_planar_image.y_plane.as_mut();
let y_plane = bi_planar_image.y_plane.borrow_mut();
let y_stride = bi_planar_image.y_stride;
let uv_plane = bi_planar_image.uv_plane.as_mut();
let uv_plane = bi_planar_image.uv_plane.borrow_mut();
let uv_stride = bi_planar_image.uv_stride;

for y in 0..height as usize {
Expand Down
6 changes: 3 additions & 3 deletions src/rgba_to_yuv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ fn rgbx_to_yuv8<const ORIGIN_CHANNELS: u8, const SAMPLING: u8>(
))]
let mut _use_avx512 = std::arch::is_x86_feature_detected!("avx512bw");

let y_plane = planar_image.y_plane.as_mut();
let u_plane = planar_image.u_plane.as_mut();
let v_plane = planar_image.v_plane.as_mut();
let y_plane = planar_image.y_plane.borrow_mut();
let u_plane = planar_image.u_plane.borrow_mut();
let v_plane = planar_image.v_plane.borrow_mut();
let width = planar_image.width;
let y_stride = planar_image.y_stride;
let u_stride = planar_image.u_stride;
Expand Down
30 changes: 15 additions & 15 deletions src/sharpyuv/sharp_rgba_to_yuv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,31 +400,31 @@ fn rgbx_to_sharp_yuv<const ORIGIN_CHANNELS: u8, const SAMPLING: u8>(
{
y_iter = planar_image
.y_plane
.as_mut()
.borrow_mut()
.par_chunks_exact_mut(planar_image.y_stride as usize * 2);
u_iter = planar_image
.u_plane
.as_mut()
.borrow_mut()
.par_chunks_exact_mut(planar_image.u_stride as usize);
v_iter = planar_image
.v_plane
.as_mut()
.borrow_mut()
.par_chunks_exact_mut(planar_image.v_stride as usize);
rgb_iter = rgba.par_chunks_exact(rgba_stride as usize * 2);
}
#[cfg(not(feature = "rayon"))]
{
y_iter = planar_image
.y_plane
.as_mut()
.borrow_mut()
.chunks_exact_mut(planar_image.y_stride as usize * 2);
u_iter = planar_image
.u_plane
.as_mut()
.borrow_mut()
.chunks_exact_mut(planar_image.u_stride as usize);
v_iter = planar_image
.v_plane
.as_mut()
.borrow_mut()
.chunks_exact_mut(planar_image.v_stride as usize);
rgb_iter = rgba.chunks_exact(rgba_stride as usize * 2);
}
Expand All @@ -433,31 +433,31 @@ fn rgbx_to_sharp_yuv<const ORIGIN_CHANNELS: u8, const SAMPLING: u8>(
{
y_iter = planar_image
.y_plane
.as_mut()
.borrow_mut()
.par_chunks_exact_mut(planar_image.y_stride as usize);
u_iter = planar_image
.u_plane
.as_mut()
.borrow_mut()
.par_chunks_exact_mut(planar_image.u_stride as usize);
v_iter = planar_image
.v_plane
.as_mut()
.borrow_mut()
.par_chunks_exact_mut(planar_image.v_stride as usize);
rgb_iter = rgba.par_chunks_exact(rgba_stride as usize);
}
#[cfg(not(feature = "rayon"))]
{
y_iter = planar_image
.y_plane
.as_mut()
.borrow_mut()
.chunks_exact_mut(planar_image.y_stride as usize);
u_iter = planar_image
.u_plane
.as_mut()
.borrow_mut()
.chunks_exact_mut(planar_image.u_stride as usize);
v_iter = planar_image
.v_plane
.as_mut()
.borrow_mut()
.chunks_exact_mut(planar_image.v_stride as usize);
rgb_iter = rgba.chunks_exact(rgba_stride as usize);
}
Expand Down Expand Up @@ -524,19 +524,19 @@ fn rgbx_to_sharp_yuv<const ORIGIN_CHANNELS: u8, const SAMPLING: u8>(
if planar_image.height & 1 != 0 && chroma_subsampling == YuvChromaSample::Yuv420 {
let y_iter = planar_image
.y_plane
.as_mut()
.borrow_mut()
.chunks_exact_mut(planar_image.y_stride as usize)
.rev()
.take(1);
let u_iter = planar_image
.u_plane
.as_mut()
.borrow_mut()
.chunks_exact_mut(planar_image.u_stride as usize)
.rev()
.take(1);
let v_iter = planar_image
.v_plane
.as_mut()
.borrow_mut()
.chunks_exact_mut(planar_image.v_stride as usize)
.rev()
.take(1);
Expand Down
6 changes: 3 additions & 3 deletions src/to_identity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ where
image.check_constraints(YuvChromaSample::Yuv444)?;
check_rgba_destination(rgba, rgba_stride, image.width, image.height, channels)?;

let y_plane = image.y_plane.as_mut();
let u_plane = image.u_plane.as_mut();
let v_plane = image.v_plane.as_mut();
let y_plane = image.y_plane.borrow_mut();
let u_plane = image.u_plane.borrow_mut();
let v_plane = image.v_plane.borrow_mut();
let y_stride = image.y_stride as usize;
let u_stride = image.u_stride as usize;
let v_stride = image.v_stride as usize;
Expand Down
6 changes: 3 additions & 3 deletions src/yuy2_to_yuv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ fn yuy2_to_yuv_impl<const SAMPLING: u8, const YUY2_TARGET: usize>(
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
let mut _use_avx2 = std::arch::is_x86_feature_detected!("avx2");

let y_plane = planar_image.y_plane.as_mut();
let u_plane = planar_image.u_plane.as_mut();
let v_plane = planar_image.v_plane.as_mut();
let y_plane = planar_image.y_plane.borrow_mut();
let u_plane = planar_image.u_plane.borrow_mut();
let v_plane = planar_image.v_plane.borrow_mut();
let y_stride = planar_image.y_stride;
let u_stride = planar_image.u_stride;
let v_stride = planar_image.v_stride;
Expand Down
6 changes: 3 additions & 3 deletions src/yuy2_to_yuv_p16.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ fn yuy2_to_yuv_impl<const SAMPLING: u8, const YUY2_TARGET: usize>(

let width = planar_image.width;
let height = planar_image.height;
let y_plane = planar_image.y_plane.as_mut();
let y_plane = planar_image.y_plane.borrow_mut();
let y_stride = planar_image.y_stride * 2;
let u_plane = planar_image.u_plane.as_mut();
let u_plane = planar_image.u_plane.borrow_mut();
let u_stride = planar_image.u_stride * 2;
let v_plane = planar_image.v_plane.as_mut();
let v_plane = planar_image.v_plane.borrow_mut();
let v_stride = planar_image.v_stride * 2;

for y in 0..height as usize {
Expand Down

0 comments on commit e27bec8

Please sign in to comment.