use crate::YuvError;
use fast_transpose::{
rotate180_plane, rotate180_plane16, rotate180_plane16_with_alpha, rotate180_plane_with_alpha,
rotate180_rgb, rotate180_rgb16, rotate180_rgba, rotate180_rgba16, transpose_plane,
transpose_plane16, transpose_plane16_with_alpha, transpose_plane_with_alpha, transpose_rgb,
transpose_rgb16, transpose_rgba, transpose_rgba16, FlipMode, FlopMode, TransposeError,
};
#[derive(Copy, Clone, Debug, Ord, PartialOrd, Eq, PartialEq, Hash)]
pub enum RotationMode {
Rotate90,
Rotate180,
Rotate270,
}
#[inline]
pub(crate) fn map_ft_result(result: Result<(), TransposeError>) -> Result<(), YuvError> {
match result {
Ok(_) => Ok(()),
Err(err) => match err {
TransposeError::MismatchDimensions => Err(YuvError::ImageDimensionsNotMatch),
TransposeError::InvalidArraySize => Err(YuvError::ImagesSizesNotMatch),
},
}
}
pub fn rotate_rgba(
src: &[u8],
src_stride: usize,
dst: &mut [u8],
dst_stride: usize,
width: usize,
height: usize,
mode: RotationMode,
) -> Result<(), YuvError> {
let rs = match mode {
RotationMode::Rotate90 => transpose_rgba(
src,
src_stride,
dst,
dst_stride,
width,
height,
FlipMode::NoFlip,
FlopMode::NoFlop,
),
RotationMode::Rotate180 => rotate180_rgba(src, src_stride, dst, dst_stride, width, height),
RotationMode::Rotate270 => transpose_rgba(
src,
src_stride,
dst,
dst_stride,
width,
height,
FlipMode::Flip,
FlopMode::Flop,
),
};
map_ft_result(rs)
}
pub fn rotate_rgb(
src: &[u8],
src_stride: usize,
dst: &mut [u8],
dst_stride: usize,
width: usize,
height: usize,
mode: RotationMode,
) -> Result<(), YuvError> {
let rs = match mode {
RotationMode::Rotate90 => transpose_rgb(
src,
src_stride,
dst,
dst_stride,
width,
height,
FlipMode::NoFlip,
FlopMode::NoFlop,
),
RotationMode::Rotate180 => rotate180_rgb(src, src_stride, dst, dst_stride, width, height),
RotationMode::Rotate270 => transpose_rgb(
src,
src_stride,
dst,
dst_stride,
width,
height,
FlipMode::Flip,
FlopMode::Flop,
),
};
map_ft_result(rs)
}
pub fn rotate_cbcr(
src: &[u8],
src_stride: usize,
dst: &mut [u8],
dst_stride: usize,
width: usize,
height: usize,
mode: RotationMode,
) -> Result<(), YuvError> {
let rs = match mode {
RotationMode::Rotate90 => transpose_plane_with_alpha(
src,
src_stride,
dst,
dst_stride,
width,
height,
FlipMode::NoFlip,
FlopMode::NoFlop,
),
RotationMode::Rotate180 => {
rotate180_plane_with_alpha(src, src_stride, dst, dst_stride, width, height)
}
RotationMode::Rotate270 => transpose_plane_with_alpha(
src,
src_stride,
dst,
dst_stride,
width,
height,
FlipMode::Flip,
FlopMode::Flop,
),
};
map_ft_result(rs)
}
pub fn rotate_plane(
src: &[u8],
src_stride: usize,
dst: &mut [u8],
dst_stride: usize,
width: usize,
height: usize,
mode: RotationMode,
) -> Result<(), YuvError> {
let rs = match mode {
RotationMode::Rotate90 => transpose_plane(
src,
src_stride,
dst,
dst_stride,
width,
height,
FlipMode::NoFlip,
FlopMode::NoFlop,
),
RotationMode::Rotate180 => rotate180_plane(src, src_stride, dst, dst_stride, width, height),
RotationMode::Rotate270 => transpose_plane(
src,
src_stride,
dst,
dst_stride,
width,
height,
FlipMode::Flip,
FlopMode::Flop,
),
};
map_ft_result(rs)
}
pub fn rotate_rgba16(
src: &[u16],
src_stride: usize,
dst: &mut [u16],
dst_stride: usize,
width: usize,
height: usize,
mode: RotationMode,
) -> Result<(), YuvError> {
let rs = match mode {
RotationMode::Rotate90 => transpose_rgba16(
src,
src_stride,
dst,
dst_stride,
width,
height,
FlipMode::NoFlip,
FlopMode::NoFlop,
),
RotationMode::Rotate180 => {
rotate180_rgba16(src, src_stride, dst, dst_stride, width, height)
}
RotationMode::Rotate270 => transpose_rgba16(
src,
src_stride,
dst,
dst_stride,
width,
height,
FlipMode::Flip,
FlopMode::Flop,
),
};
map_ft_result(rs)
}
pub fn rotate_rgb16(
src: &[u16],
src_stride: usize,
dst: &mut [u16],
dst_stride: usize,
width: usize,
height: usize,
mode: RotationMode,
) -> Result<(), YuvError> {
let rs = match mode {
RotationMode::Rotate90 => transpose_rgb16(
src,
src_stride,
dst,
dst_stride,
width,
height,
FlipMode::NoFlip,
FlopMode::NoFlop,
),
RotationMode::Rotate180 => rotate180_rgb16(src, src_stride, dst, dst_stride, width, height),
RotationMode::Rotate270 => transpose_rgb16(
src,
src_stride,
dst,
dst_stride,
width,
height,
FlipMode::Flip,
FlopMode::Flop,
),
};
map_ft_result(rs)
}
pub fn rotate_cbcr16(
src: &[u16],
src_stride: usize,
dst: &mut [u16],
dst_stride: usize,
width: usize,
height: usize,
mode: RotationMode,
) -> Result<(), YuvError> {
let rs = match mode {
RotationMode::Rotate90 => transpose_plane16_with_alpha(
src,
src_stride,
dst,
dst_stride,
width,
height,
FlipMode::NoFlip,
FlopMode::NoFlop,
),
RotationMode::Rotate180 => {
rotate180_plane16_with_alpha(src, src_stride, dst, dst_stride, width, height)
}
RotationMode::Rotate270 => transpose_plane16_with_alpha(
src,
src_stride,
dst,
dst_stride,
width,
height,
FlipMode::Flip,
FlopMode::Flop,
),
};
map_ft_result(rs)
}
pub fn rotate_plane16(
src: &[u16],
src_stride: usize,
dst: &mut [u16],
dst_stride: usize,
width: usize,
height: usize,
mode: RotationMode,
) -> Result<(), YuvError> {
let rs = match mode {
RotationMode::Rotate90 => transpose_plane16(
src,
src_stride,
dst,
dst_stride,
width,
height,
FlipMode::NoFlip,
FlopMode::NoFlop,
),
RotationMode::Rotate180 => {
rotate180_plane16(src, src_stride, dst, dst_stride, width, height)
}
RotationMode::Rotate270 => transpose_plane16(
src,
src_stride,
dst,
dst_stride,
width,
height,
FlipMode::Flip,
FlopMode::Flop,
),
};
map_ft_result(rs)
}