mirror of
https://github.com/bend-n/fimg.git
synced 2024-12-22 10:28:21 -06:00
fix transpose comments
This commit is contained in:
parent
62fbd6fd1a
commit
0a5f7f14fd
|
@ -104,35 +104,33 @@ impl<const CHANNELS: usize> Rotations for Image<&mut [u8], CHANNELS> {
|
||||||
// This is done by first flipping
|
// This is done by first flipping
|
||||||
self.flip_v();
|
self.flip_v();
|
||||||
// Then transposing the image, to save allocations.
|
// Then transposing the image, to save allocations.
|
||||||
// SAFETY: caller ensures rectangularity
|
// SAFETY: caller ensures square
|
||||||
unsafe { transpose(self) };
|
unsafe { transpose(self) };
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
unsafe fn rot_270(&mut self) {
|
unsafe fn rot_270(&mut self) {
|
||||||
self.flip_h();
|
self.flip_h();
|
||||||
// SAFETY: caller ensures rectangularity
|
// SAFETY: caller ensures squareness
|
||||||
unsafe { transpose(self) };
|
unsafe { transpose(self) };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Transpose a square image
|
||||||
/// # Safety
|
/// # Safety
|
||||||
///
|
///
|
||||||
/// UB if supplied image rectangular
|
/// UB if supplied image rectangular
|
||||||
unsafe fn transpose<const CHANNELS: usize>(img: &mut Image<&mut [u8], CHANNELS>) {
|
unsafe fn transpose<const CHANNELS: usize>(img: &mut Image<&mut [u8], CHANNELS>) {
|
||||||
debug_assert_eq!(img.width(), img.height());
|
debug_assert_eq!(img.width(), img.height());
|
||||||
let size = img.width();
|
let size = img.width() as usize;
|
||||||
|
// SAFETY: no half pixels
|
||||||
|
let b = unsafe { img.buffer.as_chunks_unchecked_mut::<CHANNELS>() };
|
||||||
for i in 0..size {
|
for i in 0..size {
|
||||||
for j in i..size {
|
for j in i..size {
|
||||||
for c in 0..CHANNELS {
|
// SAFETY: caller ensures squarity
|
||||||
// SAFETY: caller gurantees rectangularity
|
unsafe {
|
||||||
unsafe {
|
b.swap_unchecked(i * size + j, j * size + i);
|
||||||
img.buffer.swap_unchecked(
|
};
|
||||||
(i * size + j) as usize * CHANNELS + c,
|
|
||||||
(j * size + i) as usize * CHANNELS + c,
|
|
||||||
);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#![feature(
|
#![feature(
|
||||||
slice_swap_unchecked,
|
slice_swap_unchecked,
|
||||||
|
slice_as_chunks,
|
||||||
unchecked_math,
|
unchecked_math,
|
||||||
portable_simd,
|
portable_simd,
|
||||||
array_chunks,
|
array_chunks,
|
||||||
|
|
Loading…
Reference in a new issue