mirror of
https://github.com/bend-n/fimg.git
synced 2024-12-22 18:38:21 -06:00
do 270 degree rot out of place
This commit is contained in:
parent
f863d295d6
commit
248bba7bb9
|
@ -28,8 +28,8 @@ bench!(fn flip_h() { run flip_h() } flip_hc);
|
||||||
bench!(fn flip_v() { run flip_v() } flip_vc);
|
bench!(fn flip_v() { run flip_v() } flip_vc);
|
||||||
bench!(fn rotate_90() { run rot_90() } rot_90c);
|
bench!(fn rotate_90() { run rot_90() } rot_90c);
|
||||||
bench!(fn rotate_180() { run rot_180() } rot_180c);
|
bench!(fn rotate_180() { run rot_180() } rot_180c);
|
||||||
bench!(fn rotate_270() { run rot_270() } rot_280c);
|
bench!(fn rotate_270() { run rot_270() } rot_270c);
|
||||||
iai::main!(
|
iai::main!(
|
||||||
flip_h, flip_v, rotate_90, rotate_180, rotate_270, flip_hc, flip_vc, rot_90c, rot_180c,
|
flip_h, flip_v, rotate_90, rotate_180, rotate_270, flip_hc, flip_vc, rot_90c, rot_180c,
|
||||||
rot_280c
|
rot_270c
|
||||||
);
|
);
|
||||||
|
|
|
@ -107,16 +107,8 @@ impl<const CHANNELS: usize> ImageCloner<'_, CHANNELS> {
|
||||||
/// UB if the image is not square
|
/// UB if the image is not square
|
||||||
#[must_use = "function does not modify the original image"]
|
#[must_use = "function does not modify the original image"]
|
||||||
pub unsafe fn rot_90(&self) -> Image<Vec<u8>, CHANNELS> {
|
pub unsafe fn rot_90(&self) -> Image<Vec<u8>, CHANNELS> {
|
||||||
let mut out = self.alloc();
|
|
||||||
// SAFETY: yep
|
// SAFETY: yep
|
||||||
unsafe {
|
let mut out = unsafe { transpose_out(self) };
|
||||||
mattr::transpose(
|
|
||||||
self.flatten(),
|
|
||||||
out.flatten_mut(),
|
|
||||||
self.height() as usize,
|
|
||||||
self.width() as usize,
|
|
||||||
)
|
|
||||||
};
|
|
||||||
// SAFETY: sqar
|
// SAFETY: sqar
|
||||||
unsafe { crev(out.as_mut()) };
|
unsafe { crev(out.as_mut()) };
|
||||||
out
|
out
|
||||||
|
@ -128,9 +120,9 @@ impl<const CHANNELS: usize> ImageCloner<'_, CHANNELS> {
|
||||||
/// UB if the image is not square
|
/// UB if the image is not square
|
||||||
#[must_use = "function does not modify the original image"]
|
#[must_use = "function does not modify the original image"]
|
||||||
pub unsafe fn rot_270(&self) -> Image<Vec<u8>, CHANNELS> {
|
pub unsafe fn rot_270(&self) -> Image<Vec<u8>, CHANNELS> {
|
||||||
let mut out = self.flip_h();
|
// SAFETY: yep
|
||||||
// SAFETY: sqar
|
let mut out = unsafe { transpose_out(self) };
|
||||||
unsafe { transpose(&mut out.as_mut()) };
|
out.flip_v();
|
||||||
out
|
out
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -178,7 +170,7 @@ unsafe fn crev<const CHANNELS: usize, T: DerefMut<Target = [u8]>>(mut img: Image
|
||||||
let mut start = 0;
|
let mut start = 0;
|
||||||
let mut end = size - 1;
|
let mut end = size - 1;
|
||||||
while start < end {
|
while start < end {
|
||||||
// SAFETY: hmm
|
// SAFETY: hmm
|
||||||
unsafe { b.swap_unchecked(i * size + start, i * size + end) };
|
unsafe { b.swap_unchecked(i * size + start, i * size + end) };
|
||||||
start += 1;
|
start += 1;
|
||||||
end -= 1;
|
end -= 1;
|
||||||
|
@ -186,6 +178,26 @@ unsafe fn crev<const CHANNELS: usize, T: DerefMut<Target = [u8]>>(mut img: Image
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Transpose a square image out of place
|
||||||
|
/// # Safety
|
||||||
|
///
|
||||||
|
/// UB if provided image rectangular
|
||||||
|
unsafe fn transpose_out<const CHANNELS: usize>(
|
||||||
|
i: &ImageCloner<'_, CHANNELS>,
|
||||||
|
) -> Image<Vec<u8>, CHANNELS> {
|
||||||
|
let mut out = i.alloc();
|
||||||
|
// SAFETY: yep
|
||||||
|
unsafe {
|
||||||
|
mattr::transpose(
|
||||||
|
i.flatten(),
|
||||||
|
out.flatten_mut(),
|
||||||
|
i.height() as usize,
|
||||||
|
i.width() as usize,
|
||||||
|
)
|
||||||
|
};
|
||||||
|
out
|
||||||
|
}
|
||||||
|
|
||||||
/// Transpose a square image
|
/// Transpose a square image
|
||||||
/// # Safety
|
/// # Safety
|
||||||
///
|
///
|
||||||
|
|
Loading…
Reference in a new issue