Skip to content

Commit

Permalink
Some bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
awxkee committed Nov 4, 2024
1 parent 01fdb7d commit 059cfc3
Show file tree
Hide file tree
Showing 12 changed files with 45 additions and 49 deletions.
6 changes: 2 additions & 4 deletions src/avx2/yuv_to_rgba_alpha.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,8 @@ pub unsafe fn avx2_yuv_to_rgba_alpha<const DESTINATION_CHANNELS: u8, const SAMPL
let rounding_const = _mm256_set1_epi16(1 << 5);

while cx + 32 < width {
let y_values = _mm256_subs_epu8(
_mm256_loadu_si256(y_ptr.add(cx) as *const __m256i),
y_corr,
);
let y_values =
_mm256_subs_epu8(_mm256_loadu_si256(y_ptr.add(cx) as *const __m256i), y_corr);

let a_values = _mm256_loadu_si256(a_ptr.add(cx) as *const __m256i);

Expand Down
5 changes: 1 addition & 4 deletions src/avx512bw/yuv_to_rgba_alpha.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,7 @@ pub unsafe fn avx512_yuv_to_rgba_alpha<const DESTINATION_CHANNELS: u8, const SAM
let rounding_const = _mm512_set1_epi16(1 << 5);

while cx + 64 < width {
let y_values = _mm512_subs_epu8(
_mm512_loadu_si512(y_ptr.add(cx) as *const i32),
y_corr,
);
let y_values = _mm512_subs_epu8(_mm512_loadu_si512(y_ptr.add(cx) as *const i32), y_corr);

let (u_high_u8, v_high_u8, u_low_u8, v_low_u8);

Expand Down
16 changes: 8 additions & 8 deletions src/images.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl<T: Copy + Debug> BufferStoreMut<'_, T> {
}
}

pub fn borrow_mut(&mut self) -> &mut [T] {
pub fn as_mut(&mut self) -> &mut [T] {
match self {
Self::Borrowed(p_ref) => p_ref,
Self::Owned(vec) => vec,
Expand All @@ -69,7 +69,7 @@ where
pub height: u32,
}

impl<'a, T> YuvBiPlanarImage<'a, T>
impl<T> YuvBiPlanarImage<'_, T>
where
T: Copy + Debug,
{
Expand Down Expand Up @@ -102,7 +102,7 @@ where
pub height: u32,
}

impl<'a, T> YuvBiPlanarImageMut<'a, T>
impl<T> YuvBiPlanarImageMut<'_, T>
where
T: Copy + Debug,
{
Expand Down Expand Up @@ -191,7 +191,7 @@ where
pub height: u32,
}

impl<'a, T> YuvGrayImage<'a, T>
impl<T> YuvGrayImage<'_, T>
where
T: Copy + Debug,
{
Expand Down Expand Up @@ -238,7 +238,7 @@ where
}
}

impl<'a, T> YuvGrayImageMut<'a, T>
impl<T> YuvGrayImageMut<'_, T>
where
T: Copy + Debug + Clone + Default,
{
Expand Down Expand Up @@ -270,7 +270,7 @@ where
pub height: u32,
}

impl<'a, T> YuvGrayAlphaImage<'a, T>
impl<T> YuvGrayAlphaImage<'_, T>
where
T: Copy + Debug,
{
Expand Down Expand Up @@ -300,7 +300,7 @@ where
pub height: u32,
}

impl<'a, T> YuvPlanarImage<'a, T>
impl<T> YuvPlanarImage<'_, T>
where
T: Copy + Debug,
{
Expand Down Expand Up @@ -343,7 +343,7 @@ where
pub height: u32,
}

impl<'a, T> YuvPlanarImageMut<'a, T>
impl<T> YuvPlanarImageMut<'_, T>
where
T: Copy + Debug,
{
Expand Down
2 changes: 1 addition & 1 deletion src/numerics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ pub(crate) fn qrshr<const PRECISION: i32, const BIT_DEPTH: usize>(val: i32) -> i
#[inline]
pub(crate) fn div_by_255(v: u16) -> u8 {
((((v + 0x80) >> 8) + v + 0x80) >> 8).min(255) as u8
}
}
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.borrow_mut();
let uv_plane = bi_planar_image.uv_plane.borrow_mut();
let y_plane = bi_planar_image.y_plane.as_mut();
let uv_plane = bi_planar_image.uv_plane.as_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
.borrow_mut()
.as_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
.borrow_mut()
.as_mut()
.chunks_exact_mut(gray_image.y_stride as usize)
.zip(rgba.chunks_exact(rgba_stride as usize));
}
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.borrow_mut();
let y_plane = bi_planar_image.y_plane.as_mut();
let y_stride = bi_planar_image.y_stride;
let uv_plane = bi_planar_image.uv_plane.borrow_mut();
let uv_plane = bi_planar_image.uv_plane.as_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.borrow_mut();
let u_plane = planar_image.u_plane.borrow_mut();
let v_plane = planar_image.v_plane.borrow_mut();
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 width = planar_image.width;
let y_stride = planar_image.y_stride;
let u_stride = planar_image.u_stride;
Expand Down
34 changes: 18 additions & 16 deletions src/sharpyuv/sharp_rgba_to_yuv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,62 +400,64 @@ fn rgbx_to_sharp_yuv<const ORIGIN_CHANNELS: u8, const SAMPLING: u8>(
{
y_iter = planar_image
.y_plane
.borrow_mut()
.as_mut()
.par_chunks_exact_mut(planar_image.y_stride as usize * 2);
u_iter = planar_image
.u_plane
.borrow_mut()
.as_mut()
.par_chunks_exact_mut(planar_image.u_stride as usize);
v_iter = planar_image
.v_plane
.borrow_mut()
.as_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
.borrow_mut()
.as_mut()
.chunks_exact_mut(planar_image.y_stride as usize * 2);
u_iter = planar_image
.u_plane
.borrow_mut()
.as_mut()
.chunks_exact_mut(planar_image.u_stride as usize);
v_iter =
planar_image.v_plane.borrow_mut().chunks_exact_mut(planar_image.v_stride as usize);
v_iter = planar_image
.v_plane
.as_mut()
.chunks_exact_mut(planar_image.v_stride as usize);
rgb_iter = rgba.chunks_exact(rgba_stride as usize * 2);
}
} else {
#[cfg(feature = "rayon")]
{
y_iter = planar_image
.y_plane
.borrow_mut()
.as_mut()
.par_chunks_exact_mut(planar_image.y_stride as usize);
u_iter = planar_image
.u_plane
.borrow_mut()
.as_mut()
.par_chunks_exact_mut(planar_image.u_stride as usize);
v_iter = planar_image
.v_plane
.borrow_mut()
.as_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
.borrow_mut()
.as_mut()
.chunks_exact_mut(planar_image.y_stride as usize);
u_iter = planar_image
.u_plane
.borrow_mut()
.as_mut()
.chunks_exact_mut(planar_image.u_stride as usize);
v_iter = planar_image
.v_plane
.borrow_mut()
.as_mut()
.chunks_exact_mut(planar_image.v_stride as usize);
rgb_iter = rgba.chunks_exact(rgba_stride as usize);
}
Expand Down Expand Up @@ -522,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
.borrow_mut()
.as_mut()
.chunks_exact_mut(planar_image.y_stride as usize)
.rev()
.take(1);
let u_iter = planar_image
.u_plane
.borrow_mut()
.as_mut()
.chunks_exact_mut(planar_image.u_stride as usize)
.rev()
.take(1);
let v_iter = planar_image
.v_plane
.borrow_mut()
.as_mut()
.chunks_exact_mut(planar_image.v_stride as usize)
.rev()
.take(1);
Expand Down
1 change: 0 additions & 1 deletion src/yuv_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,6 @@ pub(crate) fn check_chroma_channel<V>(
Ok(())
}


#[inline]
pub(crate) fn check_interleaved_chroma_channel<V>(
data: &[V],
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.borrow_mut();
let u_plane = planar_image.u_plane.borrow_mut();
let v_plane = planar_image.v_plane.borrow_mut();
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_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.borrow_mut();
let y_plane = planar_image.y_plane.as_mut();
let y_stride = planar_image.y_stride * 2;
let u_plane = planar_image.u_plane.borrow_mut();
let u_plane = planar_image.u_plane.as_mut();
let u_stride = planar_image.u_stride * 2;
let v_plane = planar_image.v_plane.borrow_mut();
let v_plane = planar_image.v_plane.as_mut();
let v_stride = planar_image.v_stride * 2;

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

0 comments on commit 059cfc3

Please sign in to comment.