From b34af9d35171f0ea07d7f370d8eadea94fbff2ac Mon Sep 17 00:00:00 2001 From: Radzivon Bartoshyk Date: Mon, 4 Nov 2024 11:54:09 +0000 Subject: [PATCH] Ongoing reworking --- src/images.rs | 47 +++++ src/lib.rs | 2 +- src/yuv_p10_rgba.rs | 395 ++++++----------------------------- src/yuv_p16_rgba.rs | 375 +++++---------------------------- src/yuv_p16_rgba_alpha.rs | 251 +++++------------------ src/yuv_to_rgba_alpha.rs | 254 +++++------------------ src/yuv_to_yuy2.rs | 395 +++++++---------------------------- src/yuv_to_yuy2_p16.rs | 421 ++++++++------------------------------ 8 files changed, 428 insertions(+), 1712 deletions(-) diff --git a/src/images.rs b/src/images.rs index 3fd9608..edad7b4 100644 --- a/src/images.rs +++ b/src/images.rs @@ -414,3 +414,50 @@ where } } } + +#[derive(Debug)] +/// Non-mutable representation of Bi-Planar YUV image +pub struct YuvPlanarImageWithAlpha<'a, T> +where + T: Copy + Debug, +{ + pub y_plane: &'a [T], + /// Stride here always means Elements per row. + pub y_stride: u32, + pub u_plane: &'a [T], + /// Stride here always means Elements per row. + pub u_stride: u32, + pub v_plane: &'a [T], + /// Stride here always means Elements per row. + pub v_stride: u32, + pub a_plane: &'a [T], + /// Stride here always means Elements per row. + pub a_stride: u32, + pub width: u32, + pub height: u32, +} + +impl YuvPlanarImageWithAlpha<'_, T> +where + T: Copy + Debug, +{ + pub fn check_constraints(&self, subsampling: YuvChromaSample) -> Result<(), YuvError> { + check_y8_channel(self.y_plane, self.y_stride, self.width, self.height)?; + check_y8_channel(self.a_plane, self.a_stride, self.width, self.height)?; + check_chroma_channel( + self.u_plane, + self.u_stride, + self.width, + self.height, + subsampling, + )?; + check_chroma_channel( + self.v_plane, + self.v_stride, + self.width, + self.height, + subsampling, + )?; + Ok(()) + } +} diff --git a/src/lib.rs b/src/lib.rs index b748624..398ae0a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -417,7 +417,7 @@ pub use sharpyuv::SharpYuvGammaTransfer; pub use images::{ BufferStoreMut, YuvBiPlanarImage, YuvBiPlanarImageMut, YuvGrayAlphaImage, YuvGrayImage, - YuvGrayImageMut, YuvPlanarImage, YuvPlanarImageMut, + YuvGrayImageMut, YuvPlanarImage, YuvPlanarImageMut, YuvPlanarImageWithAlpha, }; pub use y_p16_to_rgb16::*; pub use y_p16_with_alpha_to_rgb16::*; diff --git a/src/yuv_p10_rgba.rs b/src/yuv_p10_rgba.rs index 9a84c9e..8ea8523 100644 --- a/src/yuv_p10_rgba.rs +++ b/src/yuv_p10_rgba.rs @@ -37,6 +37,7 @@ use crate::yuv_support::{ get_inverse_transform, get_yuv_range, YuvBytesPacking, YuvChromaSample, YuvEndianness, YuvRange, YuvSourceChannels, YuvStandardMatrix, }; +use crate::{YuvError, YuvPlanarImage}; pub(crate) fn yuv_p16_to_image_impl< const DESTINATION_CHANNELS: u8, @@ -44,26 +45,22 @@ pub(crate) fn yuv_p16_to_image_impl< const ENDIANNESS: u8, const BYTES_POSITION: u8, >( - y_plane: &[u16], - y_stride: u32, - u_plane: &[u16], - u_stride: u32, - v_plane: &[u16], - v_stride: u32, + planar_image: &YuvPlanarImage, rgba: &mut [u8], rgba_stride: u32, - width: u32, - _: u32, range: YuvRange, matrix: YuvStandardMatrix, bit_depth: usize, -) { +) -> Result<(), YuvError> { let dst_chans: YuvSourceChannels = DESTINATION_CHANNELS.into(); let channels = dst_chans.get_channels_count(); let chroma_subsampling: YuvChromaSample = SAMPLING.into(); let endianness: YuvEndianness = ENDIANNESS.into(); let bytes_position: YuvBytesPacking = BYTES_POSITION.into(); + + planar_image.check_constraints(chroma_subsampling)?; + let range = get_yuv_range(bit_depth as u32, range); let kr_kb = matrix.get_kr_kb(); let max_range_p10 = (1u32 << bit_depth as u32) - 1; @@ -101,6 +98,14 @@ pub(crate) fn yuv_p16_to_image_impl< iter = rgba.chunks_exact_mut(rgba_stride as usize); } + let y_stride = planar_image.y_stride * 2; + let u_stride = planar_image.u_stride * 2; + let v_stride = planar_image.v_stride * 2; + let y_plane = planar_image.y_plane; + let u_plane = planar_image.u_plane; + let v_plane = planar_image.v_plane; + let width = planar_image.width; + iter.enumerate().for_each(|(y, rgba)| unsafe { let y_offset = y * (y_stride as usize); let u_offset = if chroma_subsampling == YuvChromaSample::YUV420 { @@ -249,6 +254,8 @@ pub(crate) fn yuv_p16_to_image_impl< cx += 1; } }); + + Ok(()) } /// Convert YUV 420 planar format with 10-bit pixel format to BGRA format. @@ -258,14 +265,7 @@ pub(crate) fn yuv_p16_to_image_impl< /// /// # Arguments /// -/// * `y_plane` - A slice containing Y (luminance) with 10 bit depth. -/// * `y_stride` - The stride (bytes per row) for the Y plane. -/// * `u_plane` - A slice to load the U (chrominance) with 10 bit depth. -/// * `u_stride` - The stride (bytes per row) for the U plane. -/// * `v_plane` - A slice to load the V (chrominance) with 10 bit depth. -/// * `v_stride` - The stride (bytes per row) for the U plane. -/// * `width` - The width of the YUV image. -/// * `height` - The height of the YUV image. +/// * `planar_image` - Source planar image. /// * `bgra` - A mutable slice to store the converted BGRA data. /// * `bgra_stride` - The stride (bytes per row) for BGRA data. /// * `range` - The YUV range (limited or full). @@ -279,21 +279,14 @@ pub(crate) fn yuv_p16_to_image_impl< /// on the specified width, height, and strides, or if invalid YUV range or matrix is provided. /// pub fn yuv420_p10_to_bgra( - y_plane: &[u16], - y_stride: u32, - u_plane: &[u16], - u_stride: u32, - v_plane: &[u16], - v_stride: u32, + planar_image: &YuvPlanarImage, bgra: &mut [u8], bgra_stride: u32, - width: u32, - height: u32, range: YuvRange, matrix: YuvStandardMatrix, endianness: YuvEndianness, bytes_packing: YuvBytesPacking, -) { +) -> Result<(), YuvError> { let dispatcher = match endianness { YuvEndianness::BigEndian => match bytes_packing { YuvBytesPacking::MostSignificantBytes => { @@ -332,21 +325,7 @@ pub fn yuv420_p10_to_bgra( } }, }; - dispatcher( - y_plane, - y_stride, - u_plane, - u_stride, - v_plane, - v_stride, - bgra, - bgra_stride, - width, - height, - range, - matrix, - 10, - ); + dispatcher(planar_image, bgra, bgra_stride, range, matrix, 10) } /// Convert YUV 420 planar format with 10-bit pixel format to BGRA format. @@ -356,14 +335,7 @@ pub fn yuv420_p10_to_bgra( /// /// # Arguments /// -/// * `y_plane` - A slice containing Y (luminance) with 10 bit depth. -/// * `y_stride` - The stride (bytes per row) for the Y plane. -/// * `u_plane` - A slice to load the U (chrominance) with 10 bit depth. -/// * `u_stride` - The stride (bytes per row) for the U plane. -/// * `v_plane` - A slice to load the V (chrominance) with 10 bit depth. -/// * `v_stride` - The stride (bytes per row) for the U plane. -/// * `width` - The width of the YUV image. -/// * `height` - The height of the YUV image. +/// * `planar_image` - Source planar image. /// * `bgra` - A mutable slice to store the converted BGR data. /// * `bgra_stride` - The stride (bytes per row) for BGR data. /// * `range` - The YUV range (limited or full). @@ -377,21 +349,14 @@ pub fn yuv420_p10_to_bgra( /// on the specified width, height, and strides, or if invalid YUV range or matrix is provided. /// pub fn yuv420_p10_to_bgr( - y_plane: &[u16], - y_stride: u32, - u_plane: &[u16], - u_stride: u32, - v_plane: &[u16], - v_stride: u32, + planar_image: &YuvPlanarImage, bgr: &mut [u8], bgr_stride: u32, - width: u32, - height: u32, range: YuvRange, matrix: YuvStandardMatrix, endianness: YuvEndianness, bytes_packing: YuvBytesPacking, -) { +) -> Result<(), YuvError> { let dispatcher = match endianness { YuvEndianness::BigEndian => match bytes_packing { YuvBytesPacking::MostSignificantBytes => { @@ -430,10 +395,7 @@ pub fn yuv420_p10_to_bgr( } }, }; - dispatcher( - y_plane, y_stride, u_plane, u_stride, v_plane, v_stride, bgr, bgr_stride, width, height, - range, matrix, 10, - ); + dispatcher(planar_image, bgr, bgr_stride, range, matrix, 10) } /// Convert YUV 422 format with 10-bit pixel format to BGRA format . @@ -443,14 +405,7 @@ pub fn yuv420_p10_to_bgr( /// /// # Arguments /// -/// * `y_plane` - A slice containing Y (luminance) with 10 bit depth. -/// * `y_stride` - The stride (bytes per row) for the Y plane. -/// * `u_plane` - A slice to load the U (chrominance) with 10 bit depth. -/// * `u_stride` - The stride (bytes per row) for the U plane. -/// * `v_plane` - A slice to load the V (chrominance) with 10 bit depth. -/// * `v_stride` - The stride (bytes per row) for the U plane -/// * `width` - The width of the YUV image. -/// * `height` - The height of the YUV image. +/// * `planar_image` - Source planar image. /// * `bgra` - A mutable slice to store the converted BGRA data. /// * `bgra_stride` - The stride (bytes per row) for BGRA data. /// * `range` - The YUV range (limited or full). @@ -465,21 +420,14 @@ pub fn yuv420_p10_to_bgr( /// on the specified width, height, and strides, or if invalid YUV range or matrix is provided. /// pub fn yuv422_p10_to_bgra( - y_plane: &[u16], - y_stride: u32, - u_plane: &[u16], - u_stride: u32, - v_plane: &[u16], - v_stride: u32, + planar_image: &YuvPlanarImage, bgra: &mut [u8], bgra_stride: u32, - width: u32, - height: u32, range: YuvRange, matrix: YuvStandardMatrix, endianness: YuvEndianness, bytes_packing: YuvBytesPacking, -) { +) -> Result<(), YuvError> { let dispatcher = match endianness { YuvEndianness::BigEndian => match bytes_packing { YuvBytesPacking::MostSignificantBytes => { @@ -518,21 +466,7 @@ pub fn yuv422_p10_to_bgra( } }, }; - dispatcher( - y_plane, - y_stride, - u_plane, - u_stride, - v_plane, - v_stride, - bgra, - bgra_stride, - width, - height, - range, - matrix, - 10, - ); + dispatcher(planar_image, bgra, bgra_stride, range, matrix, 10) } /// Convert YUV 422 format with 10-bit pixel format to BGR format. @@ -542,14 +476,7 @@ pub fn yuv422_p10_to_bgra( /// /// # Arguments /// -/// * `y_plane` - A slice containing Y (luminance) with 10 bit depth. -/// * `y_stride` - The stride (bytes per row) for the Y plane. -/// * `u_plane` - A slice to load the U (chrominance) with 10 bit depth. -/// * `u_stride` - The stride (bytes per row) for the U plane. -/// * `v_plane` - A slice to load the V (chrominance) with 10 bit depth. -/// * `v_stride` - The stride (bytes per row) for the U plane -/// * `width` - The width of the YUV image. -/// * `height` - The height of the YUV image. +/// * `planar_image` - Source planar image. /// * `bgr` - A mutable slice to store the converted BGR data. /// * `bgr_stride` - The stride (bytes per row) for BGR data. /// * `range` - The YUV range (limited or full). @@ -564,21 +491,14 @@ pub fn yuv422_p10_to_bgra( /// on the specified width, height, and strides, or if invalid YUV range or matrix is provided. /// pub fn yuv422_p10_to_bgr( - y_plane: &[u16], - y_stride: u32, - u_plane: &[u16], - u_stride: u32, - v_plane: &[u16], - v_stride: u32, + planar_image: &YuvPlanarImage, bgr: &mut [u8], bgr_stride: u32, - width: u32, - height: u32, range: YuvRange, matrix: YuvStandardMatrix, endianness: YuvEndianness, bytes_packing: YuvBytesPacking, -) { +) -> Result<(), YuvError> { let dispatcher = match endianness { YuvEndianness::BigEndian => match bytes_packing { YuvBytesPacking::MostSignificantBytes => { @@ -617,10 +537,7 @@ pub fn yuv422_p10_to_bgr( } }, }; - dispatcher( - y_plane, y_stride, u_plane, u_stride, v_plane, v_stride, bgr, bgr_stride, width, height, - range, matrix, 10, - ); + dispatcher(planar_image, bgr, bgr_stride, range, matrix, 10) } /// Convert YUV 420 planar format with 10-bit pixel format to RGBA format. @@ -630,14 +547,7 @@ pub fn yuv422_p10_to_bgr( /// /// # Arguments /// -/// * `y_plane` - A slice containing Y (luminance) with 10 bit depth. -/// * `y_stride` - The stride (bytes per row) for the Y plane. -/// * `u_plane` - A slice to load the U (chrominance) with 10 bit depth. -/// * `u_stride` - The stride (bytes per row) for the U plane. -/// * `v_plane` - A slice to load the V (chrominance) with 10 bit depth. -/// * `v_stride` - The stride (bytes per row) for the U plane. -/// * `width` - The width of the YUV image. -/// * `height` - The height of the YUV image. +/// * `planar_image` - Source planar image. /// * `rgba` - A mutable slice to store the converted RGBA data. /// * `rgba_stride` - The stride (bytes per row) for RGBA data. /// * `range` - The YUV range (limited or full). @@ -651,21 +561,14 @@ pub fn yuv422_p10_to_bgr( /// on the specified width, height, and strides, or if invalid YUV range or matrix is provided. /// pub fn yuv420_p10_to_rgba( - y_plane: &[u16], - y_stride: u32, - u_plane: &[u16], - u_stride: u32, - v_plane: &[u16], - v_stride: u32, + planar_image: &YuvPlanarImage, rgba: &mut [u8], rgba_stride: u32, - width: u32, - height: u32, range: YuvRange, matrix: YuvStandardMatrix, endianness: YuvEndianness, bytes_packing: YuvBytesPacking, -) { +) -> Result<(), YuvError> { let dispatcher = match endianness { YuvEndianness::BigEndian => match bytes_packing { YuvBytesPacking::MostSignificantBytes => { @@ -704,21 +607,7 @@ pub fn yuv420_p10_to_rgba( } }, }; - dispatcher( - y_plane, - y_stride, - u_plane, - u_stride, - v_plane, - v_stride, - rgba, - rgba_stride, - width, - height, - range, - matrix, - 10, - ); + dispatcher(planar_image, rgba, rgba_stride, range, matrix, 10) } /// Convert YUV 420 planar format with 10-bit pixel format to RGB format. @@ -728,14 +617,7 @@ pub fn yuv420_p10_to_rgba( /// /// # Arguments /// -/// * `y_plane` - A slice containing Y (luminance) with 10 bit depth. -/// * `y_stride` - The stride (bytes per row) for the Y plane. -/// * `u_plane` - A slice to load the U (chrominance) with 10 bit depth. -/// * `u_stride` - The stride (bytes per row) for the U plane. -/// * `v_plane` - A slice to load the V (chrominance) with 10 bit depth. -/// * `v_stride` - The stride (bytes per row) for the U plane. -/// * `width` - The width of the YUV image. -/// * `height` - The height of the YUV image. +/// * `planar_image` - Source planar image. /// * `rgb` - A mutable slice to store the converted RGB data. /// * `rgb_stride` - The stride (bytes per row) for RGB data. /// * `range` - The YUV range (limited or full). @@ -749,21 +631,14 @@ pub fn yuv420_p10_to_rgba( /// on the specified width, height, and strides, or if invalid YUV range or matrix is provided. /// pub fn yuv420_p10_to_rgb( - y_plane: &[u16], - y_stride: u32, - u_plane: &[u16], - u_stride: u32, - v_plane: &[u16], - v_stride: u32, + planar_image: &YuvPlanarImage, rgb: &mut [u8], rgb_stride: u32, - width: u32, - height: u32, range: YuvRange, matrix: YuvStandardMatrix, endianness: YuvEndianness, bytes_packing: YuvBytesPacking, -) { +) -> Result<(), YuvError> { let dispatcher = match endianness { YuvEndianness::BigEndian => match bytes_packing { YuvBytesPacking::MostSignificantBytes => { @@ -802,10 +677,7 @@ pub fn yuv420_p10_to_rgb( } }, }; - dispatcher( - y_plane, y_stride, u_plane, u_stride, v_plane, v_stride, rgb, rgb_stride, width, height, - range, matrix, 10, - ); + dispatcher(planar_image, rgb, rgb_stride, range, matrix, 10) } /// Convert YUV 422 format with 10-bit pixel format to RGBA format. @@ -815,15 +687,8 @@ pub fn yuv420_p10_to_rgb( /// /// # Arguments /// -/// * `y_plane` - A slice containing Y (luminance) with 10 bit depth. -/// * `y_stride` - The stride (bytes per row) for the Y plane. -/// * `u_plane` - A slice to load the U (chrominance) with 10 bit depth. -/// * `u_stride` - The stride (bytes per row) for the U plane. -/// * `v_plane` - A slice to load the V (chrominance) with 10 bit depth. -/// * `v_stride` - The stride (bytes per row) for the U plane -/// * `width` - The width of the YUV image. -/// * `height` - The height of the YUV image. -/// * `rgba_data` - A mutable slice to store the converted RGBA data. +/// * `planar_image` - Source planar image. +/// * `rgba` - A mutable slice to store the converted RGBA data. /// * `rgba_stride` - The stride (bytes per row) for RGBA data. /// * `range` - The YUV range (limited or full). /// * `matrix` - The YUV standard matrix (BT.601 or BT.709 or BT.2020 or other). @@ -836,21 +701,14 @@ pub fn yuv420_p10_to_rgb( /// on the specified width, height, and strides, or if invalid YUV range or matrix is provided. /// pub fn yuv422_p10_to_rgba( - y_plane: &[u16], - y_stride: u32, - u_plane: &[u16], - u_stride: u32, - v_plane: &[u16], - v_stride: u32, + planar_image: &YuvPlanarImage, rgba: &mut [u8], rgba_stride: u32, - width: u32, - height: u32, range: YuvRange, matrix: YuvStandardMatrix, endianness: YuvEndianness, bytes_packing: YuvBytesPacking, -) { +) -> Result<(), YuvError> { let dispatcher = match endianness { YuvEndianness::BigEndian => match bytes_packing { YuvBytesPacking::MostSignificantBytes => { @@ -889,21 +747,7 @@ pub fn yuv422_p10_to_rgba( } }, }; - dispatcher( - y_plane, - y_stride, - u_plane, - u_stride, - v_plane, - v_stride, - rgba, - rgba_stride, - width, - height, - range, - matrix, - 10, - ); + dispatcher(planar_image, rgba, rgba_stride, range, matrix, 10) } /// Convert YUV 422 format with 10-bit pixel format to RGB format. @@ -913,14 +757,7 @@ pub fn yuv422_p10_to_rgba( /// /// # Arguments /// -/// * `y_plane` - A slice containing Y (luminance) with 10 bit depth. -/// * `y_stride` - The stride (bytes per row) for the Y plane. -/// * `u_plane` - A slice to load the U (chrominance) with 10 bit depth. -/// * `u_stride` - The stride (bytes per row) for the U plane. -/// * `v_plane` - A slice to load the V (chrominance) with 10 bit depth. -/// * `v_stride` - The stride (bytes per row) for the U plane -/// * `width` - The width of the YUV image. -/// * `height` - The height of the YUV image. +/// * `planar_image` - Source planar image. /// * `rgb_data` - A mutable slice to store the converted RGB data. /// * `rgb_stride` - The stride (bytes per row) for RGB data. /// * `range` - The YUV range (limited or full). @@ -934,21 +771,14 @@ pub fn yuv422_p10_to_rgba( /// on the specified width, height, and strides, or if invalid YUV range or matrix is provided. /// pub fn yuv422_p10_to_rgb( - y_plane: &[u16], - y_stride: u32, - u_plane: &[u16], - u_stride: u32, - v_plane: &[u16], - v_stride: u32, + planar_image: &YuvPlanarImage, rgb: &mut [u8], rgb_stride: u32, - width: u32, - height: u32, range: YuvRange, matrix: YuvStandardMatrix, endianness: YuvEndianness, bytes_packing: YuvBytesPacking, -) { +) -> Result<(), YuvError> { let dispatcher = match endianness { YuvEndianness::BigEndian => match bytes_packing { YuvBytesPacking::MostSignificantBytes => { @@ -987,10 +817,7 @@ pub fn yuv422_p10_to_rgb( } }, }; - dispatcher( - y_plane, y_stride, u_plane, u_stride, v_plane, v_stride, rgb, rgb_stride, width, height, - range, matrix, 10, - ); + dispatcher(planar_image, rgb, rgb_stride, range, matrix, 10) } /// Convert YUV 444 planar format with 10-bit pixel format to RGBA format. @@ -1000,14 +827,7 @@ pub fn yuv422_p10_to_rgb( /// /// # Arguments /// -/// * `y_plane` - A slice containing Y (luminance) with 10 bit depth. -/// * `y_stride` - The stride (bytes per row) for the Y plane. -/// * `u_plane` - A slice to load the U (chrominance) with 10 bit depth. -/// * `u_stride` - The stride (bytes per row) for the U plane. -/// * `v_plane` - A slice to load the V (chrominance) with 10 bit depth. -/// * `v_stride` - The stride (bytes per row) for the U plane. -/// * `width` - The width of the YUV image. -/// * `height` - The height of the YUV image. +/// * `planar_image` - Source planar image. /// * `rgba_data` - A mutable slice to store the converted RGBA data. /// * `rgba_stride` - The stride (bytes per row) for RGBA data. /// * `range` - The YUV range (limited or full). @@ -1021,21 +841,14 @@ pub fn yuv422_p10_to_rgb( /// on the specified width, height, and strides, or if invalid YUV range or matrix is provided. /// pub fn yuv444_p10_to_rgba( - y_plane: &[u16], - y_stride: u32, - u_plane: &[u16], - u_stride: u32, - v_plane: &[u16], - v_stride: u32, + planar_image: &YuvPlanarImage, rgba: &mut [u8], rgba_stride: u32, - width: u32, - height: u32, range: YuvRange, matrix: YuvStandardMatrix, endianness: YuvEndianness, bytes_packing: YuvBytesPacking, -) { +) -> Result<(), YuvError> { let dispatcher = match endianness { YuvEndianness::BigEndian => match bytes_packing { YuvBytesPacking::MostSignificantBytes => { @@ -1074,21 +887,7 @@ pub fn yuv444_p10_to_rgba( } }, }; - dispatcher( - y_plane, - y_stride, - u_plane, - u_stride, - v_plane, - v_stride, - rgba, - rgba_stride, - width, - height, - range, - matrix, - 10, - ); + dispatcher(planar_image, rgba, rgba_stride, range, matrix, 10) } /// Convert YUV 444 planar format with 10-bit pixel format to RGB format. @@ -1098,15 +897,8 @@ pub fn yuv444_p10_to_rgba( /// /// # Arguments /// -/// * `y_plane` - A slice containing Y (luminance) with 10 bit depth. -/// * `y_stride` - The stride (bytes per row) for the Y plane. -/// * `u_plane` - A slice to load the U (chrominance) with 10 bit depth. -/// * `u_stride` - The stride (bytes per row) for the U plane. -/// * `v_plane` - A slice to load the V (chrominance) with 10 bit depth. -/// * `v_stride` - The stride (bytes per row) for the U plane. -/// * `width` - The width of the YUV image. -/// * `height` - The height of the YUV image. -/// * `rgb_data` - A mutable slice to store the converted RGB data. +/// * `planar_image` - Source planar image. +/// * `rgb` - A mutable slice to store the converted RGB data. /// * `rgb_stride` - The stride (bytes per row) for RGB data. /// * `range` - The YUV range (limited or full). /// * `matrix` - The YUV standard matrix (BT.601 or BT.709 or BT.2020 or other). @@ -1119,21 +911,14 @@ pub fn yuv444_p10_to_rgba( /// on the specified width, height, and strides, or if invalid YUV range or matrix is provided. /// pub fn yuv444_p10_to_rgb( - y_plane: &[u16], - y_stride: u32, - u_plane: &[u16], - u_stride: u32, - v_plane: &[u16], - v_stride: u32, + planar_image: &YuvPlanarImage, rgb: &mut [u8], rgb_stride: u32, - width: u32, - height: u32, range: YuvRange, matrix: YuvStandardMatrix, endianness: YuvEndianness, bytes_packing: YuvBytesPacking, -) { +) -> Result<(), YuvError> { let dispatcher = match endianness { YuvEndianness::BigEndian => match bytes_packing { YuvBytesPacking::MostSignificantBytes => { @@ -1172,10 +957,7 @@ pub fn yuv444_p10_to_rgb( } }, }; - dispatcher( - y_plane, y_stride, u_plane, u_stride, v_plane, v_stride, rgb, rgb_stride, width, height, - range, matrix, 10, - ); + dispatcher(planar_image, rgb, rgb_stride, range, matrix, 10) } /// Convert YUV 444 planar format with 10-bit pixel format to BGRA format. @@ -1185,14 +967,7 @@ pub fn yuv444_p10_to_rgb( /// /// # Arguments /// -/// * `y_plane` - A slice containing Y (luminance) with 10 bit depth. -/// * `y_stride` - The stride (bytes per row) for the Y plane. -/// * `u_plane` - A slice to load the U (chrominance) with 10 bit depth. -/// * `u_stride` - The stride (bytes per row) for the U plane. -/// * `v_plane` - A slice to load the V (chrominance) with 10 bit depth. -/// * `v_stride` - The stride (bytes per row) for the U plane. -/// * `width` - The width of the YUV image. -/// * `height` - The height of the YUV image. +/// * `planar_image` - Source planar image. /// * `bgra` - A mutable slice to store the converted BGRA data. /// * `bgra_stride` - The stride (bytes per row) for BGRA data. /// * `range` - The YUV range (limited or full). @@ -1206,21 +981,14 @@ pub fn yuv444_p10_to_rgb( /// on the specified width, height, and strides, or if invalid YUV range or matrix is provided. /// pub fn yuv444_p10_to_bgra( - y_plane: &[u16], - y_stride: u32, - u_plane: &[u16], - u_stride: u32, - v_plane: &[u16], - v_stride: u32, + planar_image: &YuvPlanarImage, bgra: &mut [u8], bgra_stride: u32, - width: u32, - height: u32, range: YuvRange, matrix: YuvStandardMatrix, endianness: YuvEndianness, bytes_packing: YuvBytesPacking, -) { +) -> Result<(), YuvError> { let dispatcher = match endianness { YuvEndianness::BigEndian => match bytes_packing { YuvBytesPacking::MostSignificantBytes => { @@ -1259,21 +1027,7 @@ pub fn yuv444_p10_to_bgra( } }, }; - dispatcher( - y_plane, - y_stride, - u_plane, - u_stride, - v_plane, - v_stride, - bgra, - bgra_stride, - width, - height, - range, - matrix, - 10, - ); + dispatcher(planar_image, bgra, bgra_stride, range, matrix, 10) } /// Convert YUV 444 planar format with 10-bit pixel format to BGR format. @@ -1283,14 +1037,7 @@ pub fn yuv444_p10_to_bgra( /// /// # Arguments /// -/// * `y_plane` - A slice containing Y (luminance) with 10 bit depth. -/// * `y_stride` - The stride (bytes per row) for the Y plane. -/// * `u_plane` - A slice to load the U (chrominance) with 10 bit depth. -/// * `u_stride` - The stride (bytes per row) for the U plane. -/// * `v_plane` - A slice to load the V (chrominance) with 10 bit depth. -/// * `v_stride` - The stride (bytes per row) for the U plane. -/// * `width` - The width of the YUV image. -/// * `height` - The height of the YUV image. +/// * `planar_image` - Source planar image. /// * `bgr` - A mutable slice to store the converted BGR data. /// * `bgr_stride` - The stride (bytes per row) for BGR data. /// * `range` - The YUV range (limited or full). @@ -1304,21 +1051,14 @@ pub fn yuv444_p10_to_bgra( /// on the specified width, height, and strides, or if invalid YUV range or matrix is provided. /// pub fn yuv444_p10_to_bgr( - y_plane: &[u16], - y_stride: u32, - u_plane: &[u16], - u_stride: u32, - v_plane: &[u16], - v_stride: u32, + planar_image: &YuvPlanarImage, bgr: &mut [u8], bgr_stride: u32, - width: u32, - height: u32, range: YuvRange, matrix: YuvStandardMatrix, endianness: YuvEndianness, bytes_packing: YuvBytesPacking, -) { +) -> Result<(), YuvError> { let dispatcher = match endianness { YuvEndianness::BigEndian => match bytes_packing { YuvBytesPacking::MostSignificantBytes => { @@ -1357,8 +1097,5 @@ pub fn yuv444_p10_to_bgr( } }, }; - dispatcher( - y_plane, y_stride, u_plane, u_stride, v_plane, v_stride, bgr, bgr_stride, width, height, - range, matrix, 10, - ); + dispatcher(planar_image, bgr, bgr_stride, range, matrix, 10) } diff --git a/src/yuv_p16_rgba.rs b/src/yuv_p16_rgba.rs index a656acc..dcd76bd 100644 --- a/src/yuv_p16_rgba.rs +++ b/src/yuv_p16_rgba.rs @@ -30,6 +30,7 @@ use crate::yuv_p10_rgba::yuv_p16_to_image_impl; use crate::yuv_support::{ YuvBytesPacking, YuvChromaSample, YuvEndianness, YuvRange, YuvSourceChannels, YuvStandardMatrix, }; +use crate::{YuvError, YuvPlanarImage}; /// Convert YUV 420 planar format with 8+ bit pixel format to BGRA format. /// @@ -38,14 +39,7 @@ use crate::yuv_support::{ /// /// # Arguments /// -/// * `y_plane` - A slice containing Y (luminance) with 8+ bit depth. -/// * `y_stride` - The stride (bytes per row) for the Y plane. -/// * `u_plane` - A slice to load the U (chrominance) with 8+ bit depth. -/// * `u_stride` - The stride (bytes per row) for the U plane. -/// * `v_plane` - A slice to load the V (chrominance) with 8+ bit depth. -/// * `v_stride` - The stride (bytes per row) for the U plane. -/// * `width` - The width of the YUV image. -/// * `height` - The height of the YUV image. +/// * `planar_image` - Source planar image. /// * `bgra` - A mutable slice to store the converted BGRA data. /// * `bgra_stride` - The stride (bytes per row) for BGRA data. /// * `range` - The YUV range (limited or full). @@ -60,22 +54,15 @@ use crate::yuv_support::{ /// on the specified width, height, and strides, or if invalid YUV range or matrix is provided. /// pub fn yuv420_p16_to_bgra( - y_plane: &[u16], - y_stride: u32, - u_plane: &[u16], - u_stride: u32, - v_plane: &[u16], - v_stride: u32, + planar_image: &YuvPlanarImage, bgra: &mut [u8], bgra_stride: u32, bit_depth: usize, - width: u32, - height: u32, range: YuvRange, matrix: YuvStandardMatrix, endianness: YuvEndianness, bytes_packing: YuvBytesPacking, -) { +) -> Result<(), YuvError> { let dispatcher = match endianness { YuvEndianness::BigEndian => match bytes_packing { YuvBytesPacking::MostSignificantBytes => { @@ -114,21 +101,7 @@ pub fn yuv420_p16_to_bgra( } }, }; - dispatcher( - y_plane, - y_stride, - u_plane, - u_stride, - v_plane, - v_stride, - bgra, - bgra_stride, - width, - height, - range, - matrix, - bit_depth, - ); + dispatcher(planar_image, bgra, bgra_stride, range, matrix, bit_depth) } /// Convert YUV 420 planar format with 8+ bit pixel format to BGR format. @@ -138,14 +111,7 @@ pub fn yuv420_p16_to_bgra( /// /// # Arguments /// -/// * `y_plane` - A slice containing Y (luminance) with 8+ bit depth. -/// * `y_stride` - The stride (bytes per row) for the Y plane. -/// * `u_plane` - A slice to load the U (chrominance) with 8+ bit depth. -/// * `u_stride` - The stride (bytes per row) for the U plane. -/// * `v_plane` - A slice to load the V (chrominance) with 8+ bit depth. -/// * `v_stride` - The stride (bytes per row) for the U plane. -/// * `width` - The width of the YUV image. -/// * `height` - The height of the YUV image. +/// * `planar_image` - Source planar image. /// * `bgra` - A mutable slice to store the converted BGR data. /// * `bgra_stride` - The stride (bytes per row) for BGR data. /// * `range` - The YUV range (limited or full). @@ -160,22 +126,15 @@ pub fn yuv420_p16_to_bgra( /// on the specified width, height, and strides, or if invalid YUV range or matrix is provided. /// pub fn yuv420_p16_to_bgr( - y_plane: &[u16], - y_stride: u32, - u_plane: &[u16], - u_stride: u32, - v_plane: &[u16], - v_stride: u32, + planar_image: &YuvPlanarImage, bgr: &mut [u8], bgr_stride: u32, bit_depth: usize, - width: u32, - height: u32, range: YuvRange, matrix: YuvStandardMatrix, endianness: YuvEndianness, bytes_packing: YuvBytesPacking, -) { +) -> Result<(), YuvError> { let dispatcher = match endianness { YuvEndianness::BigEndian => match bytes_packing { YuvBytesPacking::MostSignificantBytes => { @@ -214,10 +173,7 @@ pub fn yuv420_p16_to_bgr( } }, }; - dispatcher( - y_plane, y_stride, u_plane, u_stride, v_plane, v_stride, bgr, bgr_stride, width, height, - range, matrix, bit_depth, - ); + dispatcher(planar_image, bgr, bgr_stride, range, matrix, bit_depth) } /// Convert YUV 422 format with 8+ bit pixel format to BGRA format . @@ -227,14 +183,7 @@ pub fn yuv420_p16_to_bgr( /// /// # Arguments /// -/// * `y_plane` - A slice containing Y (luminance) with 8+ bit depth. -/// * `y_stride` - The stride (bytes per row) for the Y plane. -/// * `u_plane` - A slice to load the U (chrominance) with 8+ bit depth. -/// * `u_stride` - The stride (bytes per row) for the U plane. -/// * `v_plane` - A slice to load the V (chrominance) with 8+ bit depth. -/// * `v_stride` - The stride (bytes per row) for the U plane -/// * `width` - The width of the YUV image. -/// * `height` - The height of the YUV image. +/// * `planar_image` - Source planar image. /// * `bgra` - A mutable slice to store the converted BGRA data. /// * `bgra_stride` - The stride (bytes per row) for BGRA data. /// * `range` - The YUV range (limited or full). @@ -250,22 +199,15 @@ pub fn yuv420_p16_to_bgr( /// on the specified width, height, and strides, or if invalid YUV range or matrix is provided. /// pub fn yuv422_p16_to_bgra( - y_plane: &[u16], - y_stride: u32, - u_plane: &[u16], - u_stride: u32, - v_plane: &[u16], - v_stride: u32, + planar_image: &YuvPlanarImage, bgra: &mut [u8], bgra_stride: u32, bit_depth: usize, - width: u32, - height: u32, range: YuvRange, matrix: YuvStandardMatrix, endianness: YuvEndianness, bytes_packing: YuvBytesPacking, -) { +) -> Result<(), YuvError> { let dispatcher = match endianness { YuvEndianness::BigEndian => match bytes_packing { YuvBytesPacking::MostSignificantBytes => { @@ -304,21 +246,7 @@ pub fn yuv422_p16_to_bgra( } }, }; - dispatcher( - y_plane, - y_stride, - u_plane, - u_stride, - v_plane, - v_stride, - bgra, - bgra_stride, - width, - height, - range, - matrix, - bit_depth, - ); + dispatcher(planar_image, bgra, bgra_stride, range, matrix, bit_depth) } /// Convert YUV 422 format with 8+ bit pixel format to BGR format. @@ -328,14 +256,7 @@ pub fn yuv422_p16_to_bgra( /// /// # Arguments /// -/// * `y_plane` - A slice containing Y (luminance) with 8+ bit depth. -/// * `y_stride` - The stride (bytes per row) for the Y plane. -/// * `u_plane` - A slice to load the U (chrominance) with 8+ bit depth. -/// * `u_stride` - The stride (bytes per row) for the U plane. -/// * `v_plane` - A slice to load the V (chrominance) with 8+ bit depth. -/// * `v_stride` - The stride (bytes per row) for the U plane -/// * `width` - The width of the YUV image. -/// * `height` - The height of the YUV image. +/// * `planar_image` - Source planar image. /// * `bgr` - A mutable slice to store the converted BGR data. /// * `bgr_stride` - The stride (bytes per row) for BGR data. /// * `range` - The YUV range (limited or full). @@ -351,22 +272,15 @@ pub fn yuv422_p16_to_bgra( /// on the specified width, height, and strides, or if invalid YUV range or matrix is provided. /// pub fn yuv422_p16_to_bgr( - y_plane: &[u16], - y_stride: u32, - u_plane: &[u16], - u_stride: u32, - v_plane: &[u16], - v_stride: u32, + planar_image: &YuvPlanarImage, bgr: &mut [u8], bgr_stride: u32, bit_depth: usize, - width: u32, - height: u32, range: YuvRange, matrix: YuvStandardMatrix, endianness: YuvEndianness, bytes_packing: YuvBytesPacking, -) { +) -> Result<(), YuvError> { let dispatcher = match endianness { YuvEndianness::BigEndian => match bytes_packing { YuvBytesPacking::MostSignificantBytes => { @@ -405,10 +319,7 @@ pub fn yuv422_p16_to_bgr( } }, }; - dispatcher( - y_plane, y_stride, u_plane, u_stride, v_plane, v_stride, bgr, bgr_stride, width, height, - range, matrix, bit_depth, - ); + dispatcher(planar_image, bgr, bgr_stride, range, matrix, bit_depth) } /// Convert YUV 420 planar format with 8+ bit pixel format to RGBA format. @@ -418,14 +329,7 @@ pub fn yuv422_p16_to_bgr( /// /// # Arguments /// -/// * `y_plane` - A slice containing Y (luminance) with 8+ bit depth. -/// * `y_stride` - The stride (bytes per row) for the Y plane. -/// * `u_plane` - A slice to load the U (chrominance) with 8+ bit depth. -/// * `u_stride` - The stride (bytes per row) for the U plane. -/// * `v_plane` - A slice to load the V (chrominance) with 8+ bit depth. -/// * `v_stride` - The stride (bytes per row) for the U plane. -/// * `width` - The width of the YUV image. -/// * `height` - The height of the YUV image. +/// * `planar_image` - Source planar image. /// * `rgba` - A mutable slice to store the converted RGBA data. /// * `rgba_stride` - The stride (bytes per row) for RGBA data. /// * `range` - The YUV range (limited or full). @@ -440,22 +344,15 @@ pub fn yuv422_p16_to_bgr( /// on the specified width, height, and strides, or if invalid YUV range or matrix is provided. /// pub fn yuv420_p16_to_rgba( - y_plane: &[u16], - y_stride: u32, - u_plane: &[u16], - u_stride: u32, - v_plane: &[u16], - v_stride: u32, + planar_image: &YuvPlanarImage, rgba: &mut [u8], rgba_stride: u32, bit_depth: usize, - width: u32, - height: u32, range: YuvRange, matrix: YuvStandardMatrix, endianness: YuvEndianness, bytes_packing: YuvBytesPacking, -) { +) -> Result<(), YuvError> { let dispatcher = match endianness { YuvEndianness::BigEndian => match bytes_packing { YuvBytesPacking::MostSignificantBytes => { @@ -494,21 +391,7 @@ pub fn yuv420_p16_to_rgba( } }, }; - dispatcher( - y_plane, - y_stride, - u_plane, - u_stride, - v_plane, - v_stride, - rgba, - rgba_stride, - width, - height, - range, - matrix, - bit_depth, - ); + dispatcher(planar_image, rgba, rgba_stride, range, matrix, bit_depth) } /// Convert YUV 420 planar format with 8+ bit pixel format to RGB format. @@ -518,14 +401,7 @@ pub fn yuv420_p16_to_rgba( /// /// # Arguments /// -/// * `y_plane` - A slice containing Y (luminance) with 8+ bit depth. -/// * `y_stride` - The stride (bytes per row) for the Y plane. -/// * `u_plane` - A slice to load the U (chrominance) with 8+ bit depth. -/// * `u_stride` - The stride (bytes per row) for the U plane. -/// * `v_plane` - A slice to load the V (chrominance) with 8+ bit depth. -/// * `v_stride` - The stride (bytes per row) for the U plane. -/// * `width` - The width of the YUV image. -/// * `height` - The height of the YUV image. +/// * `planar_image` - Source planar image. /// * `rgb` - A mutable slice to store the converted RGB data. /// * `rgb_stride` - The stride (bytes per row) for RGB data. /// * `range` - The YUV range (limited or full). @@ -540,22 +416,15 @@ pub fn yuv420_p16_to_rgba( /// on the specified width, height, and strides, or if invalid YUV range or matrix is provided. /// pub fn yuv420_p16_to_rgb( - y_plane: &[u16], - y_stride: u32, - u_plane: &[u16], - u_stride: u32, - v_plane: &[u16], - v_stride: u32, + planar_image: &YuvPlanarImage, rgb: &mut [u8], rgb_stride: u32, bit_depth: usize, - width: u32, - height: u32, range: YuvRange, matrix: YuvStandardMatrix, endianness: YuvEndianness, bytes_packing: YuvBytesPacking, -) { +) -> Result<(), YuvError> { let dispatcher = match endianness { YuvEndianness::BigEndian => match bytes_packing { YuvBytesPacking::MostSignificantBytes => { @@ -594,10 +463,7 @@ pub fn yuv420_p16_to_rgb( } }, }; - dispatcher( - y_plane, y_stride, u_plane, u_stride, v_plane, v_stride, rgb, rgb_stride, width, height, - range, matrix, bit_depth, - ); + dispatcher(planar_image, rgb, rgb_stride, range, matrix, bit_depth) } /// Convert YUV 422 format with 8+ bit pixel format to RGBA format. @@ -607,15 +473,8 @@ pub fn yuv420_p16_to_rgb( /// /// # Arguments /// -/// * `y_plane` - A slice containing Y (luminance) with 8+ bit depth. -/// * `y_stride` - The stride (bytes per row) for the Y plane. -/// * `u_plane` - A slice to load the U (chrominance) with 8+ bit depth. -/// * `u_stride` - The stride (bytes per row) for the U plane. -/// * `v_plane` - A slice to load the V (chrominance) with 8+ bit depth. -/// * `v_stride` - The stride (bytes per row) for the U plane -/// * `width` - The width of the YUV image. -/// * `height` - The height of the YUV image. -/// * `rgba_data` - A mutable slice to store the converted RGBA data. +/// * `planar_image` - Source planar image. +/// * `rgba` - A mutable slice to store the converted RGBA data. /// * `rgba_stride` - The stride (bytes per row) for RGBA data. /// * `range` - The YUV range (limited or full). /// * `matrix` - The YUV standard matrix (BT.601 or BT.709 or BT.2020 or other). @@ -629,22 +488,15 @@ pub fn yuv420_p16_to_rgb( /// on the specified width, height, and strides, or if invalid YUV range or matrix is provided. /// pub fn yuv422_p16_to_rgba( - y_plane: &[u16], - y_stride: u32, - u_plane: &[u16], - u_stride: u32, - v_plane: &[u16], - v_stride: u32, + planar_image: &YuvPlanarImage, rgba: &mut [u8], rgba_stride: u32, bit_depth: usize, - width: u32, - height: u32, range: YuvRange, matrix: YuvStandardMatrix, endianness: YuvEndianness, bytes_packing: YuvBytesPacking, -) { +) -> Result<(), YuvError> { let dispatcher = match endianness { YuvEndianness::BigEndian => match bytes_packing { YuvBytesPacking::MostSignificantBytes => { @@ -683,21 +535,7 @@ pub fn yuv422_p16_to_rgba( } }, }; - dispatcher( - y_plane, - y_stride, - u_plane, - u_stride, - v_plane, - v_stride, - rgba, - rgba_stride, - width, - height, - range, - matrix, - bit_depth, - ); + dispatcher(planar_image, rgba, rgba_stride, range, matrix, bit_depth) } /// Convert YUV 422 format with 8+ bit pixel format to RGB format. @@ -707,15 +545,8 @@ pub fn yuv422_p16_to_rgba( /// /// # Arguments /// -/// * `y_plane` - A slice containing Y (luminance) with 8+ bit depth. -/// * `y_stride` - The stride (bytes per row) for the Y plane. -/// * `u_plane` - A slice to load the U (chrominance) with 8+ bit depth. -/// * `u_stride` - The stride (bytes per row) for the U plane. -/// * `v_plane` - A slice to load the V (chrominance) with 8+ bit depth. -/// * `v_stride` - The stride (bytes per row) for the U plane -/// * `width` - The width of the YUV image. -/// * `height` - The height of the YUV image. -/// * `rgb_data` - A mutable slice to store the converted RGB data. +/// * `planar_image` - Source planar image. +/// * `rgb` - A mutable slice to store the converted RGB data. /// * `rgb_stride` - The stride (bytes per row) for RGB data. /// * `range` - The YUV range (limited or full). /// * `matrix` - The YUV standard matrix (BT.601 or BT.709 or BT.2020 or other). @@ -729,22 +560,15 @@ pub fn yuv422_p16_to_rgba( /// on the specified width, height, and strides, or if invalid YUV range or matrix is provided. /// pub fn yuv422_p16_to_rgb( - y_plane: &[u16], - y_stride: u32, - u_plane: &[u16], - u_stride: u32, - v_plane: &[u16], - v_stride: u32, + planar_image: &YuvPlanarImage, rgb: &mut [u8], rgb_stride: u32, bit_depth: usize, - width: u32, - height: u32, range: YuvRange, matrix: YuvStandardMatrix, endianness: YuvEndianness, bytes_packing: YuvBytesPacking, -) { +) -> Result<(), YuvError> { let dispatcher = match endianness { YuvEndianness::BigEndian => match bytes_packing { YuvBytesPacking::MostSignificantBytes => { @@ -783,10 +607,7 @@ pub fn yuv422_p16_to_rgb( } }, }; - dispatcher( - y_plane, y_stride, u_plane, u_stride, v_plane, v_stride, rgb, rgb_stride, width, height, - range, matrix, bit_depth, - ); + dispatcher(planar_image, rgb, rgb_stride, range, matrix, bit_depth) } /// Convert YUV 444 planar format with 8+ bit pixel format to RGBA format. @@ -796,15 +617,8 @@ pub fn yuv422_p16_to_rgb( /// /// # Arguments /// -/// * `y_plane` - A slice containing Y (luminance) with 8+ bit depth. -/// * `y_stride` - The stride (bytes per row) for the Y plane. -/// * `u_plane` - A slice to load the U (chrominance) with 8+ bit depth. -/// * `u_stride` - The stride (bytes per row) for the U plane. -/// * `v_plane` - A slice to load the V (chrominance) with 8+ bit depth. -/// * `v_stride` - The stride (bytes per row) for the U plane. -/// * `width` - The width of the YUV image. -/// * `height` - The height of the YUV image. -/// * `rgba_data` - A mutable slice to store the converted RGBA data. +/// * `planar_image` - Source planar image. +/// * `rgba` - A mutable slice to store the converted RGBA data. /// * `rgba_stride` - The stride (bytes per row) for RGBA data. /// * `range` - The YUV range (limited or full). /// * `matrix` - The YUV standard matrix (BT.601 or BT.709 or BT.2020 or other). @@ -818,22 +632,15 @@ pub fn yuv422_p16_to_rgb( /// on the specified width, height, and strides, or if invalid YUV range or matrix is provided. /// pub fn yuv444_p16_to_rgba( - y_plane: &[u16], - y_stride: u32, - u_plane: &[u16], - u_stride: u32, - v_plane: &[u16], - v_stride: u32, + planar_image: &YuvPlanarImage, rgba: &mut [u8], rgba_stride: u32, bit_depth: usize, - width: u32, - height: u32, range: YuvRange, matrix: YuvStandardMatrix, endianness: YuvEndianness, bytes_packing: YuvBytesPacking, -) { +) -> Result<(), YuvError> { let dispatcher = match endianness { YuvEndianness::BigEndian => match bytes_packing { YuvBytesPacking::MostSignificantBytes => { @@ -872,21 +679,7 @@ pub fn yuv444_p16_to_rgba( } }, }; - dispatcher( - y_plane, - y_stride, - u_plane, - u_stride, - v_plane, - v_stride, - rgba, - rgba_stride, - width, - height, - range, - matrix, - bit_depth, - ); + dispatcher(planar_image, rgba, rgba_stride, range, matrix, bit_depth) } /// Convert YUV 444 planar format with 8+ bit pixel format to RGB format. @@ -896,15 +689,8 @@ pub fn yuv444_p16_to_rgba( /// /// # Arguments /// -/// * `y_plane` - A slice containing Y (luminance) with 8+ bit depth. -/// * `y_stride` - The stride (bytes per row) for the Y plane. -/// * `u_plane` - A slice to load the U (chrominance) with 8+ bit depth. -/// * `u_stride` - The stride (bytes per row) for the U plane. -/// * `v_plane` - A slice to load the V (chrominance) with 8+ bit depth. -/// * `v_stride` - The stride (bytes per row) for the U plane. -/// * `width` - The width of the YUV image. -/// * `height` - The height of the YUV image. -/// * `rgb_data` - A mutable slice to store the converted RGB data. +/// * `planar_image` - Source planar image. +/// * `rgb` - A mutable slice to store the converted RGB data. /// * `rgb_stride` - The stride (bytes per row) for RGB data. /// * `range` - The YUV range (limited or full). /// * `matrix` - The YUV standard matrix (BT.601 or BT.709 or BT.2020 or other). @@ -918,22 +704,15 @@ pub fn yuv444_p16_to_rgba( /// on the specified width, height, and strides, or if invalid YUV range or matrix is provided. /// pub fn yuv444_p16_to_rgb( - y_plane: &[u16], - y_stride: u32, - u_plane: &[u16], - u_stride: u32, - v_plane: &[u16], - v_stride: u32, + planar_image: &YuvPlanarImage, rgb: &mut [u8], rgb_stride: u32, bit_depth: usize, - width: u32, - height: u32, range: YuvRange, matrix: YuvStandardMatrix, endianness: YuvEndianness, bytes_packing: YuvBytesPacking, -) { +) -> Result<(), YuvError> { let dispatcher = match endianness { YuvEndianness::BigEndian => match bytes_packing { YuvBytesPacking::MostSignificantBytes => { @@ -972,10 +751,7 @@ pub fn yuv444_p16_to_rgb( } }, }; - dispatcher( - y_plane, y_stride, u_plane, u_stride, v_plane, v_stride, rgb, rgb_stride, width, height, - range, matrix, bit_depth, - ); + dispatcher(planar_image, rgb, rgb_stride, range, matrix, bit_depth) } /// Convert YUV 444 planar format with 8+ bit pixel format to BGRA format. @@ -985,14 +761,7 @@ pub fn yuv444_p16_to_rgb( /// /// # Arguments /// -/// * `y_plane` - A slice containing Y (luminance) with 8+ bit depth. -/// * `y_stride` - The stride (bytes per row) for the Y plane. -/// * `u_plane` - A slice to load the U (chrominance) with 8+ bit depth. -/// * `u_stride` - The stride (bytes per row) for the U plane. -/// * `v_plane` - A slice to load the V (chrominance) with 8+ bit depth. -/// * `v_stride` - The stride (bytes per row) for the U plane. -/// * `width` - The width of the YUV image. -/// * `height` - The height of the YUV image. +/// * `planar_image` - Source planar image. /// * `bgra` - A mutable slice to store the converted BGRA data. /// * `bgra_stride` - The stride (bytes per row) for BGRA data. /// * `range` - The YUV range (limited or full). @@ -1007,22 +776,15 @@ pub fn yuv444_p16_to_rgb( /// on the specified width, height, and strides, or if invalid YUV range or matrix is provided. /// pub fn yuv444_p16_to_bgra( - y_plane: &[u16], - y_stride: u32, - u_plane: &[u16], - u_stride: u32, - v_plane: &[u16], - v_stride: u32, + planar_image: &YuvPlanarImage, bgra: &mut [u8], bgra_stride: u32, bit_depth: usize, - width: u32, - height: u32, range: YuvRange, matrix: YuvStandardMatrix, endianness: YuvEndianness, bytes_packing: YuvBytesPacking, -) { +) -> Result<(), YuvError> { let dispatcher = match endianness { YuvEndianness::BigEndian => match bytes_packing { YuvBytesPacking::MostSignificantBytes => { @@ -1061,21 +823,7 @@ pub fn yuv444_p16_to_bgra( } }, }; - dispatcher( - y_plane, - y_stride, - u_plane, - u_stride, - v_plane, - v_stride, - bgra, - bgra_stride, - width, - height, - range, - matrix, - bit_depth, - ); + dispatcher(planar_image, bgra, bgra_stride, range, matrix, bit_depth) } /// Convert YUV 444 planar format with 8+ bit pixel format to BGR format. @@ -1085,14 +833,7 @@ pub fn yuv444_p16_to_bgra( /// /// # Arguments /// -/// * `y_plane` - A slice containing Y (luminance) with 8+ bit depth. -/// * `y_stride` - The stride (bytes per row) for the Y plane. -/// * `u_plane` - A slice to load the U (chrominance) with 8+ bit depth. -/// * `u_stride` - The stride (bytes per row) for the U plane. -/// * `v_plane` - A slice to load the V (chrominance) with 8+ bit depth. -/// * `v_stride` - The stride (bytes per row) for the U plane. -/// * `width` - The width of the YUV image. -/// * `height` - The height of the YUV image. +/// * `planar_image` - Source planar image. /// * `bgr` - A mutable slice to store the converted BGR data. /// * `bgr_stride` - The stride (bytes per row) for BGR data. /// * `range` - The YUV range (limited or full). @@ -1107,22 +848,15 @@ pub fn yuv444_p16_to_bgra( /// on the specified width, height, and strides, or if invalid YUV range or matrix is provided. /// pub fn yuv444_p16_to_bgr( - y_plane: &[u16], - y_stride: u32, - u_plane: &[u16], - u_stride: u32, - v_plane: &[u16], - v_stride: u32, + planar_image: &YuvPlanarImage, bgr: &mut [u8], bgr_stride: u32, bit_depth: usize, - width: u32, - height: u32, range: YuvRange, matrix: YuvStandardMatrix, endianness: YuvEndianness, bytes_packing: YuvBytesPacking, -) { +) -> Result<(), YuvError> { let dispatcher = match endianness { YuvEndianness::BigEndian => match bytes_packing { YuvBytesPacking::MostSignificantBytes => { @@ -1161,8 +895,5 @@ pub fn yuv444_p16_to_bgr( } }, }; - dispatcher( - y_plane, y_stride, u_plane, u_stride, v_plane, v_stride, bgr, bgr_stride, width, height, - range, matrix, bit_depth, - ); + dispatcher(planar_image, bgr, bgr_stride, range, matrix, bit_depth) } diff --git a/src/yuv_p16_rgba_alpha.rs b/src/yuv_p16_rgba_alpha.rs index eb5d701..b923e22 100644 --- a/src/yuv_p16_rgba_alpha.rs +++ b/src/yuv_p16_rgba_alpha.rs @@ -32,6 +32,7 @@ use crate::yuv_support::{ get_inverse_transform, get_yuv_range, YuvBytesPacking, YuvChromaSample, YuvEndianness, YuvRange, YuvSourceChannels, YuvStandardMatrix, }; +use crate::{YuvError, YuvPlanarImageWithAlpha}; #[cfg(feature = "rayon")] use rayon::iter::{IndexedParallelIterator, ParallelIterator}; #[cfg(feature = "rayon")] @@ -43,22 +44,13 @@ pub(crate) fn yuv_p16_to_image_alpha_impl< const ENDIANNESS: u8, const BYTES_POSITION: u8, >( - y_plane: &[u16], - y_stride: u32, - u_plane: &[u16], - u_stride: u32, - v_plane: &[u16], - v_stride: u32, - a_plane: &[u16], - a_stride: u32, + planar_image_with_alpha: &YuvPlanarImageWithAlpha, rgba: &mut [u8], rgba_stride: u32, - width: u32, - _: u32, range: YuvRange, matrix: YuvStandardMatrix, bit_depth: usize, -) { +) -> Result<(), YuvError> { let dst_chans: YuvSourceChannels = DESTINATION_CHANNELS.into(); let channels = dst_chans.get_channels_count(); @@ -69,6 +61,9 @@ pub(crate) fn yuv_p16_to_image_alpha_impl< let chroma_subsampling: YuvChromaSample = SAMPLING.into(); let endianness: YuvEndianness = ENDIANNESS.into(); let bytes_position: YuvBytesPacking = BYTES_POSITION.into(); + + planar_image_with_alpha.check_constraints(chroma_subsampling)?; + let range = get_yuv_range(bit_depth as u32, range); let kr_kb = matrix.get_kr_kb(); let max_range_p10 = (1u32 << bit_depth as u32) - 1; @@ -97,6 +92,16 @@ pub(crate) fn yuv_p16_to_image_alpha_impl< let dst_offset = 0usize; + let y_stride = planar_image_with_alpha.y_stride * 2; + let u_stride = planar_image_with_alpha.u_stride * 2; + let v_stride = planar_image_with_alpha.v_stride * 2; + let y_plane = planar_image_with_alpha.y_plane; + let u_plane = planar_image_with_alpha.u_plane; + let v_plane = planar_image_with_alpha.v_plane; + let a_plane = planar_image_with_alpha.a_plane; + let a_stride = planar_image_with_alpha.a_stride * 2; + let width = planar_image_with_alpha.width; + let iter; #[cfg(feature = "rayon")] { @@ -275,6 +280,8 @@ pub(crate) fn yuv_p16_to_image_alpha_impl< cx += 1; } }); + + Ok(()) } /// Convert YUV 420 planar format with 8+ bit pixel format to BGRA format with interleaving alpha. @@ -284,16 +291,7 @@ pub(crate) fn yuv_p16_to_image_alpha_impl< /// /// # Arguments /// -/// * `y_plane` - A slice containing Y (luminance) with 8+ bit depth. -/// * `y_stride` - The stride (bytes per row) for the Y plane. -/// * `u_plane` - A slice to load the U (chrominance) with 8+ bit depth. -/// * `u_stride` - The stride (bytes per row) for the U plane. -/// * `v_plane` - A slice to load the V (chrominance) with 8+ bit depth. -/// * `v_stride` - The stride (bytes per row) for the U plane. -/// * `a_plane` - A slice to load the alpha with 8+ bit depth. -/// * `a_stride` - The stride (bytes per row) for the Alpha plane. -/// * `width` - The width of the YUV image. -/// * `height` - The height of the YUV image. +/// * `planar_image_with_alpha` - Source planar image with alpha. /// * `bgra` - A mutable slice to store the converted BGRA data. /// * `bgra_stride` - The stride (bytes per row) for BGRA data. /// * `range` - The YUV range (limited or full). @@ -308,24 +306,15 @@ pub(crate) fn yuv_p16_to_image_alpha_impl< /// on the specified width, height, and strides, or if invalid YUV range or matrix is provided. /// pub fn yuv420_p16_with_alpha_to_bgra( - y_plane: &[u16], - y_stride: u32, - u_plane: &[u16], - u_stride: u32, - v_plane: &[u16], - v_stride: u32, - a_plane: &[u16], - a_stride: u32, + planar_image_with_alpha: &YuvPlanarImageWithAlpha, bgra: &mut [u8], bgra_stride: u32, bit_depth: usize, - width: u32, - height: u32, range: YuvRange, matrix: YuvStandardMatrix, endianness: YuvEndianness, bytes_packing: YuvBytesPacking, -) { +) -> Result<(), YuvError> { let dispatcher = match endianness { YuvEndianness::BigEndian => match bytes_packing { YuvBytesPacking::MostSignificantBytes => { @@ -365,22 +354,13 @@ pub fn yuv420_p16_with_alpha_to_bgra( }, }; dispatcher( - y_plane, - y_stride, - u_plane, - u_stride, - v_plane, - v_stride, - a_plane, - a_stride, + planar_image_with_alpha, bgra, bgra_stride, - width, - height, range, matrix, bit_depth, - ); + ) } /// Convert YUV 422 format with 8+ bit pixel format to BGRA format with interleaving alpha. @@ -390,16 +370,7 @@ pub fn yuv420_p16_with_alpha_to_bgra( /// /// # Arguments /// -/// * `y_plane` - A slice containing Y (luminance) with 8+ bit depth. -/// * `y_stride` - The stride (bytes per row) for the Y plane. -/// * `u_plane` - A slice to load the U (chrominance) with 8+ bit depth. -/// * `u_stride` - The stride (bytes per row) for the U plane. -/// * `v_plane` - A slice to load the V (chrominance) with 8+ bit depth. -/// * `v_stride` - The stride (bytes per row) for the U plane. -/// * `a_plane` - A slice to load the alpha with 8+ bit depth. -/// * `a_stride` - The stride (bytes per row) for the Alpha plane. -/// * `width` - The width of the YUV image. -/// * `height` - The height of the YUV image. +/// * `planar_image_with_alpha` - Source planar image with alpha. /// * `bgra` - A mutable slice to store the converted BGRA data. /// * `bgra_stride` - The stride (bytes per row) for BGRA data. /// * `range` - The YUV range (limited or full). @@ -415,24 +386,15 @@ pub fn yuv420_p16_with_alpha_to_bgra( /// on the specified width, height, and strides, or if invalid YUV range or matrix is provided. /// pub fn yuv422_p16_with_alpha_to_bgra( - y_plane: &[u16], - y_stride: u32, - u_plane: &[u16], - u_stride: u32, - v_plane: &[u16], - v_stride: u32, - a_plane: &[u16], - a_stride: u32, + planar_image_with_alpha: &YuvPlanarImageWithAlpha, bgra: &mut [u8], bgra_stride: u32, bit_depth: usize, - width: u32, - height: u32, range: YuvRange, matrix: YuvStandardMatrix, endianness: YuvEndianness, bytes_packing: YuvBytesPacking, -) { +) -> Result<(), YuvError> { let dispatcher = match endianness { YuvEndianness::BigEndian => match bytes_packing { YuvBytesPacking::MostSignificantBytes => { @@ -472,22 +434,13 @@ pub fn yuv422_p16_with_alpha_to_bgra( }, }; dispatcher( - y_plane, - y_stride, - u_plane, - u_stride, - v_plane, - v_stride, - a_plane, - a_stride, + planar_image_with_alpha, bgra, bgra_stride, - width, - height, range, matrix, bit_depth, - ); + ) } /// Convert YUV 420 planar format with 8+ bit pixel format to RGBA format with interleaving alpha. @@ -497,16 +450,7 @@ pub fn yuv422_p16_with_alpha_to_bgra( /// /// # Arguments /// -/// * `y_plane` - A slice containing Y (luminance) with 8+ bit depth. -/// * `y_stride` - The stride (bytes per row) for the Y plane. -/// * `u_plane` - A slice to load the U (chrominance) with 8+ bit depth. -/// * `u_stride` - The stride (bytes per row) for the U plane. -/// * `v_plane` - A slice to load the V (chrominance) with 8+ bit depth. -/// * `v_stride` - The stride (bytes per row) for the U plane. -/// * `a_plane` - A slice to load the alpha with 8+ bit depth. -/// * `a_stride` - The stride (bytes per row) for the Alpha plane. -/// * `width` - The width of the YUV image. -/// * `height` - The height of the YUV image. +/// * `planar_image_with_alpha` - Source planar image with alpha. /// * `rgba` - A mutable slice to store the converted RGBA data. /// * `rgba_stride` - The stride (bytes per row) for RGBA data. /// * `range` - The YUV range (limited or full). @@ -521,24 +465,15 @@ pub fn yuv422_p16_with_alpha_to_bgra( /// on the specified width, height, and strides, or if invalid YUV range or matrix is provided. /// pub fn yuv420_p16_with_alpha_to_rgba( - y_plane: &[u16], - y_stride: u32, - u_plane: &[u16], - u_stride: u32, - v_plane: &[u16], - v_stride: u32, - a_plane: &[u16], - a_stride: u32, + planar_image_with_alpha: &YuvPlanarImageWithAlpha, rgba: &mut [u8], rgba_stride: u32, bit_depth: usize, - width: u32, - height: u32, range: YuvRange, matrix: YuvStandardMatrix, endianness: YuvEndianness, bytes_packing: YuvBytesPacking, -) { +) -> Result<(), YuvError> { let dispatcher = match endianness { YuvEndianness::BigEndian => match bytes_packing { YuvBytesPacking::MostSignificantBytes => { @@ -578,22 +513,13 @@ pub fn yuv420_p16_with_alpha_to_rgba( }, }; dispatcher( - y_plane, - y_stride, - u_plane, - u_stride, - v_plane, - v_stride, - a_plane, - a_stride, + planar_image_with_alpha, rgba, rgba_stride, - width, - height, range, matrix, bit_depth, - ); + ) } /// Convert YUV 422 format with 8+ bit pixel format to RGBA format with interleaving alpha. @@ -603,16 +529,7 @@ pub fn yuv420_p16_with_alpha_to_rgba( /// /// # Arguments /// -/// * `y_plane` - A slice containing Y (luminance) with 8+ bit depth. -/// * `y_stride` - The stride (bytes per row) for the Y plane. -/// * `u_plane` - A slice to load the U (chrominance) with 8+ bit depth. -/// * `u_stride` - The stride (bytes per row) for the U plane. -/// * `v_plane` - A slice to load the V (chrominance) with 8+ bit depth. -/// * `v_stride` - The stride (bytes per row) for the U plane. -/// * `a_plane` - A slice to load the alpha with 8+ bit depth. -/// * `a_stride` - The stride (bytes per row) for the Alpha plane. -/// * `width` - The width of the YUV image. -/// * `height` - The height of the YUV image. +/// * `planar_image_with_alpha` - Source planar image with alpha. /// * `rgba_data` - A mutable slice to store the converted RGBA data. /// * `rgba_stride` - The stride (bytes per row) for RGBA data. /// * `range` - The YUV range (limited or full). @@ -627,24 +544,15 @@ pub fn yuv420_p16_with_alpha_to_rgba( /// on the specified width, height, and strides, or if invalid YUV range or matrix is provided. /// pub fn yuv422_p16_with_alpha_to_rgba( - y_plane: &[u16], - y_stride: u32, - u_plane: &[u16], - u_stride: u32, - v_plane: &[u16], - v_stride: u32, - a_plane: &[u16], - a_stride: u32, + planar_image_with_alpha: &YuvPlanarImageWithAlpha, rgba: &mut [u8], rgba_stride: u32, bit_depth: usize, - width: u32, - height: u32, range: YuvRange, matrix: YuvStandardMatrix, endianness: YuvEndianness, bytes_packing: YuvBytesPacking, -) { +) -> Result<(), YuvError> { let dispatcher = match endianness { YuvEndianness::BigEndian => match bytes_packing { YuvBytesPacking::MostSignificantBytes => { @@ -684,22 +592,13 @@ pub fn yuv422_p16_with_alpha_to_rgba( }, }; dispatcher( - y_plane, - y_stride, - u_plane, - u_stride, - v_plane, - v_stride, - a_plane, - a_stride, + planar_image_with_alpha, rgba, rgba_stride, - width, - height, range, matrix, bit_depth, - ); + ) } /// Convert YUV 444 planar format with 8+ bit pixel format to RGBA format with interleaving alpha. @@ -709,16 +608,7 @@ pub fn yuv422_p16_with_alpha_to_rgba( /// /// # Arguments /// -/// * `y_plane` - A slice containing Y (luminance) with 8+ bit depth. -/// * `y_stride` - The stride (bytes per row) for the Y plane. -/// * `u_plane` - A slice to load the U (chrominance) with 8+ bit depth. -/// * `u_stride` - The stride (bytes per row) for the U plane. -/// * `v_plane` - A slice to load the V (chrominance) with 8+ bit depth. -/// * `v_stride` - The stride (bytes per row) for the U plane. -/// * `a_plane` - A slice to load the alpha with 8+ bit depth. -/// * `a_stride` - The stride (bytes per row) for the Alpha plane. -/// * `width` - The width of the YUV image. -/// * `height` - The height of the YUV image. +/// * `planar_image_with_alpha` - Source planar image with alpha. /// * `rgba_data` - A mutable slice to store the converted RGBA data. /// * `rgba_stride` - The stride (bytes per row) for RGBA data. /// * `range` - The YUV range (limited or full). @@ -733,24 +623,15 @@ pub fn yuv422_p16_with_alpha_to_rgba( /// on the specified width, height, and strides, or if invalid YUV range or matrix is provided. /// pub fn yuv444_p16_with_alpha_to_rgba( - y_plane: &[u16], - y_stride: u32, - u_plane: &[u16], - u_stride: u32, - v_plane: &[u16], - v_stride: u32, - a_plane: &[u16], - a_stride: u32, + planar_image_with_alpha: &YuvPlanarImageWithAlpha, rgba: &mut [u8], rgba_stride: u32, bit_depth: usize, - width: u32, - height: u32, range: YuvRange, matrix: YuvStandardMatrix, endianness: YuvEndianness, bytes_packing: YuvBytesPacking, -) { +) -> Result<(), YuvError> { let dispatcher = match endianness { YuvEndianness::BigEndian => match bytes_packing { YuvBytesPacking::MostSignificantBytes => { @@ -790,22 +671,13 @@ pub fn yuv444_p16_with_alpha_to_rgba( }, }; dispatcher( - y_plane, - y_stride, - u_plane, - u_stride, - v_plane, - v_stride, - a_plane, - a_stride, + planar_image_with_alpha, rgba, rgba_stride, - width, - height, range, matrix, bit_depth, - ); + ) } /// Convert YUV 444 planar format with 8+ bit pixel format to BGRA format with interleaving alpha. @@ -815,16 +687,7 @@ pub fn yuv444_p16_with_alpha_to_rgba( /// /// # Arguments /// -/// * `y_plane` - A slice containing Y (luminance) with 8+ bit depth. -/// * `y_stride` - The stride (bytes per row) for the Y plane. -/// * `u_plane` - A slice to load the U (chrominance) with 8+ bit depth. -/// * `u_stride` - The stride (bytes per row) for the U plane. -/// * `v_plane` - A slice to load the V (chrominance) with 8+ bit depth. -/// * `v_stride` - The stride (bytes per row) for the U plane. -/// * `a_plane` - A slice to load the alpha with 8+ bit depth. -/// * `a_stride` - The stride (bytes per row) for the Alpha plane. -/// * `width` - The width of the YUV image. -/// * `height` - The height of the YUV image. +/// * `planar_image_with_alpha` - Source planar image with alpha. /// * `bgra` - A mutable slice to store the converted BGRA data. /// * `bgra_stride` - The stride (bytes per row) for BGRA data. /// * `range` - The YUV range (limited or full). @@ -839,24 +702,15 @@ pub fn yuv444_p16_with_alpha_to_rgba( /// on the specified width, height, and strides, or if invalid YUV range or matrix is provided. /// pub fn yuv444_p16_with_alpha_to_bgra( - y_plane: &[u16], - y_stride: u32, - u_plane: &[u16], - u_stride: u32, - v_plane: &[u16], - v_stride: u32, - a_plane: &[u16], - a_stride: u32, + planar_image_with_alpha: &YuvPlanarImageWithAlpha, bgra: &mut [u8], bgra_stride: u32, bit_depth: usize, - width: u32, - height: u32, range: YuvRange, matrix: YuvStandardMatrix, endianness: YuvEndianness, bytes_packing: YuvBytesPacking, -) { +) -> Result<(), YuvError> { let dispatcher = match endianness { YuvEndianness::BigEndian => match bytes_packing { YuvBytesPacking::MostSignificantBytes => { @@ -896,20 +750,11 @@ pub fn yuv444_p16_with_alpha_to_bgra( }, }; dispatcher( - y_plane, - y_stride, - u_plane, - u_stride, - v_plane, - v_stride, - a_plane, - a_stride, + planar_image_with_alpha, bgra, bgra_stride, - width, - height, range, matrix, bit_depth, - ); + ) } diff --git a/src/yuv_to_rgba_alpha.rs b/src/yuv_to_rgba_alpha.rs index c6a1478..47deab5 100644 --- a/src/yuv_to_rgba_alpha.rs +++ b/src/yuv_to_rgba_alpha.rs @@ -38,28 +38,19 @@ use crate::neon::neon_yuv_to_rgba_alpha; use crate::numerics::{div_by_255, qrshr}; #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] use crate::sse::sse_yuv_to_rgba_alpha_row; -use crate::yuv_error::{check_chroma_channel, check_rgba_destination, check_y8_channel}; +use crate::yuv_error::check_rgba_destination; #[allow(unused_imports)] use crate::yuv_support::*; -use crate::{YuvError, YuvRange, YuvStandardMatrix}; +use crate::{YuvError, YuvPlanarImageWithAlpha, YuvRange, YuvStandardMatrix}; #[cfg(feature = "rayon")] use rayon::iter::{IndexedParallelIterator, ParallelIterator}; #[cfg(feature = "rayon")] use rayon::prelude::{ParallelSlice, ParallelSliceMut}; fn yuv_with_alpha_to_rgbx( - y_plane: &[u8], - y_stride: u32, - u_plane: &[u8], - u_stride: u32, - v_plane: &[u8], - v_stride: u32, - a_plane: &[u8], - a_stride: u32, + planar_with_alpha: &YuvPlanarImageWithAlpha, rgba: &mut [u8], rgba_stride: u32, - width: u32, - height: u32, range: YuvRange, matrix: YuvStandardMatrix, premultiply_alpha: bool, @@ -72,11 +63,14 @@ fn yuv_with_alpha_to_rgbx( ); let channels = dst_chans.get_channels_count(); - check_rgba_destination(rgba, rgba_stride, width, height, channels)?; - check_y8_channel(y_plane, y_stride, width, height)?; - check_y8_channel(a_plane, a_stride, width, height)?; - check_chroma_channel(u_plane, u_stride, width, height, chroma_subsampling)?; - check_chroma_channel(v_plane, v_stride, width, height, chroma_subsampling)?; + check_rgba_destination( + rgba, + rgba_stride, + planar_with_alpha.width, + planar_with_alpha.height, + channels, + )?; + planar_with_alpha.check_constraints(chroma_subsampling)?; let range = get_yuv_range(8, range); let kr_kb = matrix.get_kr_kb(); @@ -103,6 +97,16 @@ fn yuv_with_alpha_to_rgbx( ))] let mut _use_avx512 = std::arch::is_x86_feature_detected!("avx512bw"); + let width = planar_with_alpha.width; + let y_plane = planar_with_alpha.y_plane; + let u_plane = planar_with_alpha.u_plane; + let v_plane = planar_with_alpha.v_plane; + let y_stride = planar_with_alpha.y_stride; + let u_stride = planar_with_alpha.u_stride; + let v_stride = planar_with_alpha.v_stride; + let a_plane = planar_with_alpha.a_plane; + let a_stride = planar_with_alpha.a_stride; + let iter; #[cfg(feature = "rayon")] { @@ -359,17 +363,9 @@ fn yuv_with_alpha_to_rgbx( /// /// # Arguments /// -/// * `y_plane` - A slice to load the Y (luminance) plane data. -/// * `y_stride` - The stride (bytes per row) for the Y plane. -/// * `u_plane` - A slice to load the U (chrominance) plane data. -/// * `u_stride` - The stride (bytes per row) for the U plane. -/// * `v_plane` - A slice to load the V (chrominance) plane data. -/// * `v_stride` - The stride (bytes per row) for the V plane. -/// * `a_plane` - A slice to load alpha plane to append to result. -/// * `a_stride` - The stride (bytes per row) for the alpha plane. -/// * `width` - The width of the YUV image. -/// * `height` - The height of the YUV image. -/// * `rgba_data` - A mutable slice to store the converted RGBA data. +/// * `planar_with_alpha` - Source planar image. +/// * `rgba` - A mutable slice to store the converted RGBA data. +/// * `rgba_stride` - Elements per row. /// * `range` - The YUV range (limited or full). /// * `matrix` - The YUV standard matrix (BT.601 or BT.709 or BT.2020 or other). /// * `premultiply_alpha` - Flag to premultiply alpha or not @@ -380,35 +376,17 @@ fn yuv_with_alpha_to_rgbx( /// on the specified width, height, and strides, or if invalid YUV range or matrix is provided. /// pub fn yuv420_with_alpha_to_rgba( - y_plane: &[u8], - y_stride: u32, - u_plane: &[u8], - u_stride: u32, - v_plane: &[u8], - v_stride: u32, - a_plane: &[u8], - a_stride: u32, + planar_with_alpha: &YuvPlanarImageWithAlpha, rgba: &mut [u8], rgba_stride: u32, - width: u32, - height: u32, range: YuvRange, matrix: YuvStandardMatrix, premultiply_alpha: bool, ) -> Result<(), YuvError> { yuv_with_alpha_to_rgbx::<{ YuvSourceChannels::Rgba as u8 }, { YuvChromaSample::YUV420 as u8 }>( - y_plane, - y_stride, - u_plane, - u_stride, - v_plane, - v_stride, - a_plane, - a_stride, + planar_with_alpha, rgba, rgba_stride, - width, - height, range, matrix, premultiply_alpha, @@ -422,17 +400,9 @@ pub fn yuv420_with_alpha_to_rgba( /// /// # Arguments /// -/// * `y_plane` - A slice to load the Y (luminance) plane data. -/// * `y_stride` - The stride (bytes per row) for the Y plane. -/// * `u_plane` - A slice to load the U (chrominance) plane data. -/// * `u_stride` - The stride (bytes per row) for the U plane. -/// * `v_plane` - A slice to load the V (chrominance) plane data. -/// * `v_stride` - The stride (bytes per row) for the V plane. -/// * `a_plane` - A slice to load alpha plane to append to result. -/// * `a_stride` - The stride (bytes per row) for the alpha plane. -/// * `width` - The width of the YUV image. -/// * `height` - The height of the YUV image. -/// * `bgra_data` - A mutable slice to store the converted BGRA data. +/// * `planar_with_alpha` - Source planar image. +/// * `bgra` - A mutable slice to store the converted BGRA data. +/// * `bgra_stride` - Elements per row. /// * `range` - The YUV range (limited or full). /// * `matrix` - The YUV standard matrix (BT.601 or BT.709 or BT.2020 or other). /// * `premultiply_alpha` - Flag to premultiply alpha or not @@ -443,35 +413,17 @@ pub fn yuv420_with_alpha_to_rgba( /// on the specified width, height, and strides, or if invalid YUV range or matrix is provided. /// pub fn yuv420_with_alpha_to_bgra( - y_plane: &[u8], - y_stride: u32, - u_plane: &[u8], - u_stride: u32, - v_plane: &[u8], - v_stride: u32, - a_plane: &[u8], - a_stride: u32, + planar_with_alpha: &YuvPlanarImageWithAlpha, bgra: &mut [u8], bgra_stride: u32, - width: u32, - height: u32, range: YuvRange, matrix: YuvStandardMatrix, premultiply_alpha: bool, ) -> Result<(), YuvError> { yuv_with_alpha_to_rgbx::<{ YuvSourceChannels::Bgra as u8 }, { YuvChromaSample::YUV420 as u8 }>( - y_plane, - y_stride, - u_plane, - u_stride, - v_plane, - v_stride, - a_plane, - a_stride, + planar_with_alpha, bgra, bgra_stride, - width, - height, range, matrix, premultiply_alpha, @@ -485,17 +437,9 @@ pub fn yuv420_with_alpha_to_bgra( /// /// # Arguments /// -/// * `y_plane` - A slice to load the Y (luminance) plane data. -/// * `y_stride` - The stride (bytes per row) for the Y plane. -/// * `u_plane` - A slice to load the U (chrominance) plane data. -/// * `u_stride` - The stride (bytes per row) for the U plane. -/// * `v_plane` - A slice to load the V (chrominance) plane data. -/// * `v_stride` - The stride (bytes per row) for the V plane. -/// * `a_plane` - A slice to load alpha plane to append to result. -/// * `a_stride` - The stride (bytes per row) for the alpha plane. -/// * `width` - The width of the YUV image. -/// * `height` - The height of the YUV image. -/// * `rgba_data` - A mutable slice to store the converted RGBA data. +/// * `planar_with_alpha` - Source planar image. +/// * `rgba` - A mutable slice to store the converted RGBA data. +/// * `rgba_stride` - Elements per row. /// * `range` - The YUV range (limited or full). /// * `matrix` - The YUV standard matrix (BT.601 or BT.709 or BT.2020 or other). /// * `premultiply_alpha` - Flag to premultiply alpha or not @@ -506,35 +450,17 @@ pub fn yuv420_with_alpha_to_bgra( /// on the specified width, height, and strides, or if invalid YUV range or matrix is provided. /// pub fn yuv422_with_alpha_to_rgba( - y_plane: &[u8], - y_stride: u32, - u_plane: &[u8], - u_stride: u32, - v_plane: &[u8], - v_stride: u32, - a_plane: &[u8], - a_stride: u32, + planar_with_alpha: &YuvPlanarImageWithAlpha, rgba: &mut [u8], rgba_stride: u32, - width: u32, - height: u32, range: YuvRange, matrix: YuvStandardMatrix, premultiply_alpha: bool, ) -> Result<(), YuvError> { yuv_with_alpha_to_rgbx::<{ YuvSourceChannels::Rgba as u8 }, { YuvChromaSample::YUV422 as u8 }>( - y_plane, - y_stride, - u_plane, - u_stride, - v_plane, - v_stride, - a_plane, - a_stride, + planar_with_alpha, rgba, rgba_stride, - width, - height, range, matrix, premultiply_alpha, @@ -548,17 +474,9 @@ pub fn yuv422_with_alpha_to_rgba( /// /// # Arguments /// -/// * `y_plane` - A slice to load the Y (luminance) plane data. -/// * `y_stride` - The stride (bytes per row) for the Y plane. -/// * `u_plane` - A slice to load the U (chrominance) plane data. -/// * `u_stride` - The stride (bytes per row) for the U plane. -/// * `v_plane` - A slice to load the V (chrominance) plane data. -/// * `v_stride` - The stride (bytes per row) for the V plane. -/// * `a_plane` - A slice to load alpha plane to append to result. -/// * `a_stride` - The stride (bytes per row) for the alpha plane. -/// * `width` - The width of the YUV image. -/// * `height` - The height of the YUV image. -/// * `bgra_data` - A mutable slice to store the converted BGRA data. +/// * `planar_with_alpha` - Source planar image. +/// * `bgra` - A mutable slice to store the converted BGRA data. +/// * `bgra_stride` - Elements per row. /// * `range` - The YUV range (limited or full). /// * `matrix` - The YUV standard matrix (BT.601 or BT.709 or BT.2020 or other). /// * `premultiply_alpha` - Flag to premultiply alpha or not @@ -569,35 +487,17 @@ pub fn yuv422_with_alpha_to_rgba( /// on the specified width, height, and strides, or if invalid YUV range or matrix is provided. /// pub fn yuv422_with_alpha_to_bgra( - y_plane: &[u8], - y_stride: u32, - u_plane: &[u8], - u_stride: u32, - v_plane: &[u8], - v_stride: u32, - a_plane: &[u8], - a_stride: u32, + planar_with_alpha: &YuvPlanarImageWithAlpha, bgra: &mut [u8], bgra_stride: u32, - width: u32, - height: u32, range: YuvRange, matrix: YuvStandardMatrix, premultiply_alpha: bool, ) -> Result<(), YuvError> { yuv_with_alpha_to_rgbx::<{ YuvSourceChannels::Bgra as u8 }, { YuvChromaSample::YUV422 as u8 }>( - y_plane, - y_stride, - u_plane, - u_stride, - v_plane, - v_stride, - a_plane, - a_stride, + planar_with_alpha, bgra, bgra_stride, - width, - height, range, matrix, premultiply_alpha, @@ -611,17 +511,9 @@ pub fn yuv422_with_alpha_to_bgra( /// /// # Arguments /// -/// * `y_plane` - A slice to load the Y (luminance) plane data. -/// * `y_stride` - The stride (bytes per row) for the Y plane. -/// * `u_plane` - A slice to load the U (chrominance) plane data. -/// * `u_stride` - The stride (bytes per row) for the U plane. -/// * `v_plane` - A slice to load the V (chrominance) plane data. -/// * `v_stride` - The stride (bytes per row) for the V plane. -/// * `a_plane` - A slice to load alpha plane to append to result. -/// * `a_stride` - The stride (bytes per row) for the alpha plane. -/// * `width` - The width of the YUV image. -/// * `height` - The height of the YUV image. -/// * `rgba_data` - A mutable slice to store the converted RGBA data. +/// * `planar_with_alpha` - Source planar image. +/// * `rgba` - A mutable slice to store the converted RGBA data. +/// * `rgba_stride` - Elements per row. /// * `range` - The YUV range (limited or full). /// * `matrix` - The YUV standard matrix (BT.601 or BT.709 or BT.2020 or other). /// * `premultiply_alpha` - Flag to premultiply alpha or not @@ -632,35 +524,17 @@ pub fn yuv422_with_alpha_to_bgra( /// on the specified width, height, and strides, or if invalid YUV range or matrix is provided. /// pub fn yuv444_with_alpha_to_rgba( - y_plane: &[u8], - y_stride: u32, - u_plane: &[u8], - u_stride: u32, - v_plane: &[u8], - v_stride: u32, - a_plane: &[u8], - a_stride: u32, + planar_with_alpha: &YuvPlanarImageWithAlpha, rgba: &mut [u8], rgba_stride: u32, - width: u32, - height: u32, range: YuvRange, matrix: YuvStandardMatrix, premultiply_alpha: bool, ) -> Result<(), YuvError> { yuv_with_alpha_to_rgbx::<{ YuvSourceChannels::Rgba as u8 }, { YuvChromaSample::YUV444 as u8 }>( - y_plane, - y_stride, - u_plane, - u_stride, - v_plane, - v_stride, - a_plane, - a_stride, + planar_with_alpha, rgba, rgba_stride, - width, - height, range, matrix, premultiply_alpha, @@ -674,17 +548,9 @@ pub fn yuv444_with_alpha_to_rgba( /// /// # Arguments /// -/// * `y_plane` - A slice to load the Y (luminance) plane data. -/// * `y_stride` - The stride (bytes per row) for the Y plane. -/// * `u_plane` - A slice to load the U (chrominance) plane data. -/// * `u_stride` - The stride (bytes per row) for the U plane. -/// * `v_plane` - A slice to load the V (chrominance) plane data. -/// * `v_stride` - The stride (bytes per row) for the V plane. -/// * `a_plane` - A slice to load alpha plane to append to result. -/// * `a_stride` - The stride (bytes per row) for the alpha plane. -/// * `width` - The width of the YUV image. -/// * `height` - The height of the YUV image. -/// * `bgra_data` - A mutable slice to store the converted BGRA data. +/// * `planar_with_alpha` - Source planar image. +/// * `bgra` - A mutable slice to store the converted BGRA data. +/// * `bgra_stride` - Elements per row. /// * `range` - The YUV range (limited or full). /// * `matrix` - The YUV standard matrix (BT.601 or BT.709 or BT.2020 or other). /// * `premultiply_alpha` - Flag to premultiply alpha or not @@ -695,35 +561,17 @@ pub fn yuv444_with_alpha_to_rgba( /// on the specified width, height, and strides, or if invalid YUV range or matrix is provided. /// pub fn yuv444_with_alpha_to_bgra( - y_plane: &[u8], - y_stride: u32, - u_plane: &[u8], - u_stride: u32, - v_plane: &[u8], - v_stride: u32, - a_plane: &[u8], - a_stride: u32, + planar_with_alpha: &YuvPlanarImageWithAlpha, bgra: &mut [u8], bgra_stride: u32, - width: u32, - height: u32, range: YuvRange, matrix: YuvStandardMatrix, premultiply_alpha: bool, ) -> Result<(), YuvError> { yuv_with_alpha_to_rgbx::<{ YuvSourceChannels::Bgra as u8 }, { YuvChromaSample::YUV444 as u8 }>( - y_plane, - y_stride, - u_plane, - u_stride, - v_plane, - v_stride, - a_plane, - a_stride, + planar_with_alpha, bgra, bgra_stride, - width, - height, range, matrix, premultiply_alpha, diff --git a/src/yuv_to_yuy2.rs b/src/yuv_to_yuy2.rs index 9af459c..029fb27 100644 --- a/src/yuv_to_yuy2.rs +++ b/src/yuv_to_yuy2.rs @@ -33,6 +33,7 @@ use crate::neon::yuv_to_yuy2_neon_impl; #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] use crate::sse::yuv_to_yuy2_sse_impl; use crate::yuv_support::{YuvChromaSample, Yuy2Description}; +use crate::{YuvError, YuvPlanarImage}; #[cfg(feature = "rayon")] use rayon::iter::{IndexedParallelIterator, ParallelIterator}; #[cfg(feature = "rayon")] @@ -54,20 +55,15 @@ impl YuvToYuy2Navigation { } fn yuv_to_yuy2_impl( - y_plane: &[u8], - y_stride: u32, - u_plane: &[u8], - u_stride: u32, - v_plane: &[u8], - v_stride: u32, + planar_image: &YuvPlanarImage, yuy2_store: &mut [u8], yuy2_stride: u32, - width: u32, - _: u32, -) { +) -> Result<(), YuvError> { let yuy2_target: Yuy2Description = YUY2_TARGET.into(); let chroma_subsampling: YuvChromaSample = SAMPLING.into(); + planar_image.check_constraints(chroma_subsampling)?; + let yuy_offset = 0usize; #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] @@ -85,6 +81,14 @@ fn yuv_to_yuy2_impl( iter = yuy2_store.chunks_exact_mut(yuy2_stride as usize); } + let y_stride = planar_image.y_stride; + let u_stride = planar_image.u_stride; + let v_stride = planar_image.v_stride; + let y_plane = planar_image.y_plane; + let v_plane = planar_image.v_plane; + let u_plane = planar_image.u_plane; + let width = planar_image.width; + iter.enumerate().for_each(|(y, yuy2_store)| unsafe { let y_offset = y * (y_stride as usize); let u_offset = if chroma_subsampling == YuvChromaSample::YUV420 { @@ -215,6 +219,7 @@ fn yuv_to_yuy2_impl( *dst_store.get_unchecked_mut(yuy2_target.get_v_position()) = v_value; } }); + Ok(()) } /// Convert YUV 444 planar format to YUYV ( YUV Packed ) format. @@ -225,14 +230,7 @@ fn yuv_to_yuy2_impl( /// /// # Arguments /// -/// * `y_plane` - A slice to load the Y (luminance) plane data. -/// * `y_stride` - The stride (bytes per row) for the Y plane. -/// * `u_plane` - A slice to load the U (chrominance) plane data. -/// * `u_stride` - The stride (bytes per row) for the U plane. -/// * `v_plane` - A slice to load the V (chrominance) plane data. -/// * `v_stride` - The stride (bytes per row) for the V plane. -/// * `width` - The width of the YUV image. -/// * `height` - The height of the YUV image. +/// * `planar_image` - Source planar image. /// * `yuy2_store` - A mutable slice to store the converted YUYV data. /// * `yuy2_stride` - The stride (bytes per row) for the YUYV plane. /// @@ -243,29 +241,15 @@ fn yuv_to_yuy2_impl( /// Panic will be received if buffer doesn't expand with (width + 1) size for odd width /// pub fn yuv444_to_yuyv422( - y_plane: &[u8], - y_stride: u32, - u_plane: &[u8], - u_stride: u32, - v_plane: &[u8], - v_stride: u32, + planar_image: &YuvPlanarImage, yuy2_store: &mut [u8], yuy2_stride: u32, - width: u32, - height: u32, -) { +) -> Result<(), YuvError> { yuv_to_yuy2_impl::<{ YuvChromaSample::YUV444 as u8 }, { Yuy2Description::YUYV as usize }>( - y_plane, - y_stride, - u_plane, - u_stride, - v_plane, - v_stride, + planar_image, yuy2_store, yuy2_stride, - width, - height, - ); + ) } /// Convert YUV 422 planar format to YUYV ( YUV Packed ) format. @@ -276,14 +260,7 @@ pub fn yuv444_to_yuyv422( /// /// # Arguments /// -/// * `y_plane` - A slice to load the Y (luminance) plane data. -/// * `y_stride` - The stride (bytes per row) for the Y plane. -/// * `u_plane` - A slice to load the U (chrominance) plane data. -/// * `u_stride` - The stride (bytes per row) for the U plane. -/// * `v_plane` - A slice to load the V (chrominance) plane data. -/// * `v_stride` - The stride (bytes per row) for the V plane. -/// * `width` - The width of the YUV image. -/// * `height` - The height of the YUV image. +/// * `planar_image` - Source planar image. /// * `yuy2_store` - A mutable slice to store the converted YUYV data. /// * `yuy2_stride` - The stride (bytes per row) for the YUYV plane. /// @@ -294,29 +271,15 @@ pub fn yuv444_to_yuyv422( /// Panic will be received if buffer doesn't expand with (width + 1) size for odd width /// pub fn yuv422_to_yuyv422( - y_plane: &[u8], - y_stride: u32, - u_plane: &[u8], - u_stride: u32, - v_plane: &[u8], - v_stride: u32, + planar_image: &YuvPlanarImage, yuy2_store: &mut [u8], yuy2_stride: u32, - width: u32, - height: u32, -) { +) -> Result<(), YuvError> { yuv_to_yuy2_impl::<{ YuvChromaSample::YUV422 as u8 }, { Yuy2Description::YUYV as usize }>( - y_plane, - y_stride, - u_plane, - u_stride, - v_plane, - v_stride, + planar_image, yuy2_store, yuy2_stride, - width, - height, - ); + ) } /// Convert YUV 420 planar format to YUYV ( YUV Packed ) format. @@ -327,14 +290,7 @@ pub fn yuv422_to_yuyv422( /// /// # Arguments /// -/// * `y_plane` - A slice to load the Y (luminance) plane data. -/// * `y_stride` - The stride (bytes per row) for the Y plane. -/// * `u_plane` - A slice to load the U (chrominance) plane data. -/// * `u_stride` - The stride (bytes per row) for the U plane. -/// * `v_plane` - A slice to load the V (chrominance) plane data. -/// * `v_stride` - The stride (bytes per row) for the V plane. -/// * `width` - The width of the YUV image. -/// * `height` - The height of the YUV image. +/// * `planar_image` - Source planar image. /// * `yuy2_store` - A mutable slice to store the converted YUYV data. /// * `yuy2_stride` - The stride (bytes per row) for the YUYV plane. /// @@ -345,29 +301,15 @@ pub fn yuv422_to_yuyv422( /// Panic will be received if buffer doesn't expand with (width + 1) size for odd width /// pub fn yuv420_to_yuyv422( - y_plane: &[u8], - y_stride: u32, - u_plane: &[u8], - u_stride: u32, - v_plane: &[u8], - v_stride: u32, + planar_image: &YuvPlanarImage, yuy2_store: &mut [u8], yuy2_stride: u32, - width: u32, - height: u32, -) { +) -> Result<(), YuvError> { yuv_to_yuy2_impl::<{ YuvChromaSample::YUV420 as u8 }, { Yuy2Description::YUYV as usize }>( - y_plane, - y_stride, - u_plane, - u_stride, - v_plane, - v_stride, + planar_image, yuy2_store, yuy2_stride, - width, - height, - ); + ) } /// Convert YUV 444 planar format to YVYU ( YUV Packed ) format. @@ -378,14 +320,7 @@ pub fn yuv420_to_yuyv422( /// /// # Arguments /// -/// * `y_plane` - A slice to load the Y (luminance) plane data. -/// * `y_stride` - The stride (bytes per row) for the Y plane. -/// * `u_plane` - A slice to load the U (chrominance) plane data. -/// * `u_stride` - The stride (bytes per row) for the U plane. -/// * `v_plane` - A slice to load the V (chrominance) plane data. -/// * `v_stride` - The stride (bytes per row) for the V plane. -/// * `width` - The width of the YUV image. -/// * `height` - The height of the YUV image. +/// * `planar_image` - Source planar image. /// * `yuy2_store` - A mutable slice to store the converted YVYU data. /// * `yuy2_stride` - The stride (bytes per row) for the YVYU plane. /// @@ -396,29 +331,15 @@ pub fn yuv420_to_yuyv422( /// Panic will be received if buffer doesn't expand with (width + 1) size for odd width /// pub fn yuv444_to_yvyu422( - y_plane: &[u8], - y_stride: u32, - u_plane: &[u8], - u_stride: u32, - v_plane: &[u8], - v_stride: u32, + planar_image: &YuvPlanarImage, yuy2_store: &mut [u8], yuy2_stride: u32, - width: u32, - height: u32, -) { +) -> Result<(), YuvError> { yuv_to_yuy2_impl::<{ YuvChromaSample::YUV444 as u8 }, { Yuy2Description::YVYU as usize }>( - y_plane, - y_stride, - u_plane, - u_stride, - v_plane, - v_stride, + planar_image, yuy2_store, yuy2_stride, - width, - height, - ); + ) } /// Convert YUV 422 planar format to YVYU ( YUV Packed ) format. @@ -429,14 +350,7 @@ pub fn yuv444_to_yvyu422( /// /// # Arguments /// -/// * `y_plane` - A slice to load the Y (luminance) plane data. -/// * `y_stride` - The stride (bytes per row) for the Y plane. -/// * `u_plane` - A slice to load the U (chrominance) plane data. -/// * `u_stride` - The stride (bytes per row) for the U plane. -/// * `v_plane` - A slice to load the V (chrominance) plane data. -/// * `v_stride` - The stride (bytes per row) for the V plane. -/// * `width` - The width of the YUV image. -/// * `height` - The height of the YUV image. +/// * `planar_image` - Source planar image. /// * `yuy2_store` - A mutable slice to store the converted YVYU data. /// * `yuy2_stride` - The stride (bytes per row) for the YVYU plane. /// @@ -447,29 +361,15 @@ pub fn yuv444_to_yvyu422( /// Panic will be received if buffer doesn't expand with (width + 1) size for odd width /// pub fn yuv422_to_yvyu422( - y_plane: &[u8], - y_stride: u32, - u_plane: &[u8], - u_stride: u32, - v_plane: &[u8], - v_stride: u32, + planar_image: &YuvPlanarImage, yuy2_store: &mut [u8], yuy2_stride: u32, - width: u32, - height: u32, -) { +) -> Result<(), YuvError> { yuv_to_yuy2_impl::<{ YuvChromaSample::YUV422 as u8 }, { Yuy2Description::YVYU as usize }>( - y_plane, - y_stride, - u_plane, - u_stride, - v_plane, - v_stride, + planar_image, yuy2_store, yuy2_stride, - width, - height, - ); + ) } /// Convert YUV 420 planar format to YVYU ( YUV Packed ) format. @@ -480,14 +380,7 @@ pub fn yuv422_to_yvyu422( /// /// # Arguments /// -/// * `y_plane` - A slice to load the Y (luminance) plane data. -/// * `y_stride` - The stride (bytes per row) for the Y plane. -/// * `u_plane` - A slice to load the U (chrominance) plane data. -/// * `u_stride` - The stride (bytes per row) for the U plane. -/// * `v_plane` - A slice to load the V (chrominance) plane data. -/// * `v_stride` - The stride (bytes per row) for the V plane. -/// * `width` - The width of the YUV image. -/// * `height` - The height of the YUV image. +/// * `planar_image` - Source planar image. /// * `yuy2_store` - A mutable slice to store the converted YVYU data. /// * `yuy2_stride` - The stride (bytes per row) for the YVYU plane. /// @@ -498,29 +391,15 @@ pub fn yuv422_to_yvyu422( /// Panic will be received if buffer doesn't expand with (width + 1) size for odd width /// pub fn yuv420_to_yvyu422( - y_plane: &[u8], - y_stride: u32, - u_plane: &[u8], - u_stride: u32, - v_plane: &[u8], - v_stride: u32, + planar_image: &YuvPlanarImage, yuy2_store: &mut [u8], yuy2_stride: u32, - width: u32, - height: u32, -) { +) -> Result<(), YuvError> { yuv_to_yuy2_impl::<{ YuvChromaSample::YUV420 as u8 }, { Yuy2Description::YVYU as usize }>( - y_plane, - y_stride, - u_plane, - u_stride, - v_plane, - v_stride, + planar_image, yuy2_store, yuy2_stride, - width, - height, - ); + ) } /// Convert YUV 444 planar format to VYUY ( YUV Packed ) format. @@ -531,14 +410,7 @@ pub fn yuv420_to_yvyu422( /// /// # Arguments /// -/// * `y_plane` - A slice to load the Y (luminance) plane data. -/// * `y_stride` - The stride (bytes per row) for the Y plane. -/// * `u_plane` - A slice to load the U (chrominance) plane data. -/// * `u_stride` - The stride (bytes per row) for the U plane. -/// * `v_plane` - A slice to load the V (chrominance) plane data. -/// * `v_stride` - The stride (bytes per row) for the V plane. -/// * `width` - The width of the YUV image. -/// * `height` - The height of the YUV image. +/// * `planar_image` - Source planar image. /// * `yuy2_store` - A mutable slice to store the converted VYUY data. /// * `yuy2_stride` - The stride (bytes per row) for the VYUY plane. /// @@ -549,29 +421,15 @@ pub fn yuv420_to_yvyu422( /// Panic will be received if buffer doesn't expand with (width + 1) size for odd width /// pub fn yuv444_to_vyuy422( - y_plane: &[u8], - y_stride: u32, - u_plane: &[u8], - u_stride: u32, - v_plane: &[u8], - v_stride: u32, + planar_image: &YuvPlanarImage, yuy2_store: &mut [u8], yuy2_stride: u32, - width: u32, - height: u32, -) { +) -> Result<(), YuvError> { yuv_to_yuy2_impl::<{ YuvChromaSample::YUV444 as u8 }, { Yuy2Description::VYUY as usize }>( - y_plane, - y_stride, - u_plane, - u_stride, - v_plane, - v_stride, + planar_image, yuy2_store, yuy2_stride, - width, - height, - ); + ) } /// Convert YUV 422 planar format to VYUY ( YUV Packed ) format. @@ -582,14 +440,7 @@ pub fn yuv444_to_vyuy422( /// /// # Arguments /// -/// * `y_plane` - A slice to load the Y (luminance) plane data. -/// * `y_stride` - The stride (bytes per row) for the Y plane. -/// * `u_plane` - A slice to load the U (chrominance) plane data. -/// * `u_stride` - The stride (bytes per row) for the U plane. -/// * `v_plane` - A slice to load the V (chrominance) plane data. -/// * `v_stride` - The stride (bytes per row) for the V plane. -/// * `width` - The width of the YUV image. -/// * `height` - The height of the YUV image. +/// * `planar_image` - Source planar image. /// * `yuy2_store` - A mutable slice to store the converted VYUY data. /// * `yuy2_stride` - The stride (bytes per row) for the VYUY plane. /// @@ -600,29 +451,15 @@ pub fn yuv444_to_vyuy422( /// Panic will be received if buffer doesn't expand with (width + 1) size for odd width /// pub fn yuv422_to_vyuy422( - y_plane: &[u8], - y_stride: u32, - u_plane: &[u8], - u_stride: u32, - v_plane: &[u8], - v_stride: u32, + planar_image: &YuvPlanarImage, yuy2_store: &mut [u8], yuy2_stride: u32, - width: u32, - height: u32, -) { +) -> Result<(), YuvError> { yuv_to_yuy2_impl::<{ YuvChromaSample::YUV422 as u8 }, { Yuy2Description::VYUY as usize }>( - y_plane, - y_stride, - u_plane, - u_stride, - v_plane, - v_stride, + planar_image, yuy2_store, yuy2_stride, - width, - height, - ); + ) } /// Convert YUV 420 planar format to VYUY ( YUV Packed ) format. @@ -633,14 +470,7 @@ pub fn yuv422_to_vyuy422( /// /// # Arguments /// -/// * `y_plane` - A slice to load the Y (luminance) plane data. -/// * `y_stride` - The stride (bytes per row) for the Y plane. -/// * `u_plane` - A slice to load the U (chrominance) plane data. -/// * `u_stride` - The stride (bytes per row) for the U plane. -/// * `v_plane` - A slice to load the V (chrominance) plane data. -/// * `v_stride` - The stride (bytes per row) for the V plane. -/// * `width` - The width of the YUV image. -/// * `height` - The height of the YUV image. +/// * `planar_image` - Source planar image. /// * `yuy2_store` - A mutable slice to store the converted VYUY data. /// * `yuy2_stride` - The stride (bytes per row) for the VYUY plane. /// @@ -651,29 +481,15 @@ pub fn yuv422_to_vyuy422( /// Panic will be received if buffer doesn't expand with (width + 1) size for odd width /// pub fn yuv420_to_vyuy422( - y_plane: &[u8], - y_stride: u32, - u_plane: &[u8], - u_stride: u32, - v_plane: &[u8], - v_stride: u32, + planar_image: &YuvPlanarImage, yuy2_store: &mut [u8], yuy2_stride: u32, - width: u32, - height: u32, -) { +) -> Result<(), YuvError> { yuv_to_yuy2_impl::<{ YuvChromaSample::YUV420 as u8 }, { Yuy2Description::VYUY as usize }>( - y_plane, - y_stride, - u_plane, - u_stride, - v_plane, - v_stride, + planar_image, yuy2_store, yuy2_stride, - width, - height, - ); + ) } /// Convert YUV 444 planar format to UYVY ( YUV Packed ) format. @@ -684,14 +500,7 @@ pub fn yuv420_to_vyuy422( /// /// # Arguments /// -/// * `y_plane` - A slice to load the Y (luminance) plane data. -/// * `y_stride` - The stride (bytes per row) for the Y plane. -/// * `u_plane` - A slice to load the U (chrominance) plane data. -/// * `u_stride` - The stride (bytes per row) for the U plane. -/// * `v_plane` - A slice to load the V (chrominance) plane data. -/// * `v_stride` - The stride (bytes per row) for the V plane. -/// * `width` - The width of the YUV image. -/// * `height` - The height of the YUV image. +/// * `planar_image` - Source planar image. /// * `yuy2_store` - A mutable slice to store the converted UYVY data. /// * `yuy2_stride` - The stride (bytes per row) for the UYVY plane. /// @@ -702,29 +511,15 @@ pub fn yuv420_to_vyuy422( /// Panic will be received if buffer doesn't expand with (width + 1) size for odd width /// pub fn yuv444_to_uyvy422( - y_plane: &[u8], - y_stride: u32, - u_plane: &[u8], - u_stride: u32, - v_plane: &[u8], - v_stride: u32, + planar_image: &YuvPlanarImage, yuy2_store: &mut [u8], yuy2_stride: u32, - width: u32, - height: u32, -) { +) -> Result<(), YuvError> { yuv_to_yuy2_impl::<{ YuvChromaSample::YUV444 as u8 }, { Yuy2Description::UYVY as usize }>( - y_plane, - y_stride, - u_plane, - u_stride, - v_plane, - v_stride, + planar_image, yuy2_store, yuy2_stride, - width, - height, - ); + ) } /// Convert YUV 422 planar format to UYVY ( YUV Packed ) format. @@ -735,14 +530,7 @@ pub fn yuv444_to_uyvy422( /// /// # Arguments /// -/// * `y_plane` - A slice to load the Y (luminance) plane data. -/// * `y_stride` - The stride (bytes per row) for the Y plane. -/// * `u_plane` - A slice to load the U (chrominance) plane data. -/// * `u_stride` - The stride (bytes per row) for the U plane. -/// * `v_plane` - A slice to load the V (chrominance) plane data. -/// * `v_stride` - The stride (bytes per row) for the V plane. -/// * `width` - The width of the YUV image. -/// * `height` - The height of the YUV image. +/// * `planar_image` - Source planar image. /// * `yuy2_store` - A mutable slice to store the converted UYVY data. /// * `yuy2_stride` - The stride (bytes per row) for the UYVY plane. /// @@ -753,29 +541,15 @@ pub fn yuv444_to_uyvy422( /// Panic will be received if buffer doesn't expand with (width + 1) size for odd width /// pub fn yuv422_to_uyvy422( - y_plane: &[u8], - y_stride: u32, - u_plane: &[u8], - u_stride: u32, - v_plane: &[u8], - v_stride: u32, + planar_image: &YuvPlanarImage, yuy2_store: &mut [u8], yuy2_stride: u32, - width: u32, - height: u32, -) { +) -> Result<(), YuvError> { yuv_to_yuy2_impl::<{ YuvChromaSample::YUV422 as u8 }, { Yuy2Description::UYVY as usize }>( - y_plane, - y_stride, - u_plane, - u_stride, - v_plane, - v_stride, + planar_image, yuy2_store, yuy2_stride, - width, - height, - ); + ) } /// Convert YUV 420 planar format to UYVY ( YUV Packed ) format. @@ -786,14 +560,7 @@ pub fn yuv422_to_uyvy422( /// /// # Arguments /// -/// * `y_plane` - A slice to load the Y (luminance) plane data. -/// * `y_stride` - The stride (bytes per row) for the Y plane. -/// * `u_plane` - A slice to load the U (chrominance) plane data. -/// * `u_stride` - The stride (bytes per row) for the U plane. -/// * `v_plane` - A slice to load the V (chrominance) plane data. -/// * `v_stride` - The stride (bytes per row) for the V plane. -/// * `width` - The width of the YUV image. -/// * `height` - The height of the YUV image. +/// * `planar_image` - Source planar image. /// * `yuy2_store` - A mutable slice to store the converted UYVY data. /// * `yuy2_stride` - The stride (bytes per row) for the UYVY plane. /// @@ -804,27 +571,13 @@ pub fn yuv422_to_uyvy422( /// Panic will be received if buffer doesn't expand with (width + 1) size for odd width /// pub fn yuv420_to_uyvy422( - y_plane: &[u8], - y_stride: u32, - u_plane: &[u8], - u_stride: u32, - v_plane: &[u8], - v_stride: u32, + planar_image: &YuvPlanarImage, yuy2_store: &mut [u8], yuy2_stride: u32, - width: u32, - height: u32, -) { +) -> Result<(), YuvError> { yuv_to_yuy2_impl::<{ YuvChromaSample::YUV420 as u8 }, { Yuy2Description::UYVY as usize }>( - y_plane, - y_stride, - u_plane, - u_stride, - v_plane, - v_stride, + planar_image, yuy2_store, yuy2_stride, - width, - height, - ); + ) } diff --git a/src/yuv_to_yuy2_p16.rs b/src/yuv_to_yuy2_p16.rs index 5620b8d..d74c57b 100644 --- a/src/yuv_to_yuy2_p16.rs +++ b/src/yuv_to_yuy2_p16.rs @@ -27,27 +27,32 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ use crate::yuv_support::{YuvChromaSample, Yuy2Description}; +use crate::{YuvError, YuvPlanarImage}; fn yuv_to_yuy2_impl_p16( - y_plane: &[u16], - y_stride: u32, - u_plane: &[u16], - u_stride: u32, - v_plane: &[u16], - v_stride: u32, + planar_image: &YuvPlanarImage, yuy2_store: &mut [u16], yuy2_stride: u32, - width: u32, - height: u32, -) { +) -> Result<(), YuvError> { let yuy2_target: Yuy2Description = YUY2_TARGET.into(); let chroma_subsampling: YuvChromaSample = SAMPLING.into(); + planar_image.check_constraints(chroma_subsampling)?; + let mut y_offset = 0usize; let mut u_offset = 0usize; let mut v_offset = 0usize; let mut yuy_offset = 0usize; + let height = planar_image.height; + let width = planar_image.width; + let y_stride = planar_image.y_stride * 2; + let u_stride = planar_image.u_stride * 2; + let v_stride = planar_image.v_stride * 2; + let y_plane = planar_image.y_plane; + let v_plane = planar_image.v_plane; + let u_plane = planar_image.u_plane; + for y in 0..height as usize { let mut _cx = 0usize; let mut _uv_x = 0usize; @@ -159,6 +164,8 @@ fn yuv_to_yuy2_impl_p16( } } } + + Ok(()) } /// Convert YUV 444 planar format to YUYV ( YUV Packed ) format. @@ -169,14 +176,7 @@ fn yuv_to_yuy2_impl_p16( /// /// # Arguments /// -/// * `y_plane` - A slice to load the Y (luminance) plane data. -/// * `y_stride` - The stride (bytes per row) for the Y plane. -/// * `u_plane` - A slice to load the U (chrominance) plane data. -/// * `u_stride` - The stride (bytes per row) for the U plane. -/// * `v_plane` - A slice to load the V (chrominance) plane data. -/// * `v_stride` - The stride (bytes per row) for the V plane. -/// * `width` - The width of the YUV image. -/// * `height` - The height of the YUV image. +/// * `planar_image` - Source planar image. /// * `yuy2_store` - A mutable slice to store the converted YUYV data. /// * `yuy2_stride` - The stride (bytes per row) for the YUYV plane. /// @@ -184,32 +184,18 @@ fn yuv_to_yuy2_impl_p16( /// /// This function panics if the lengths of the planes or the input YUYV data are not valid based /// on the specified width, height, and strides, or if invalid YUV range or matrix is provided. -/// Panic will be received if buffer doesn't expand with (width + 1) size for odd width +/// Panic will be received if buffer doesn't expand with (width + 1) size for odd width. /// pub fn yuv444_to_yuyv422_p16( - y_plane: &[u16], - y_stride: u32, - u_plane: &[u16], - u_stride: u32, - v_plane: &[u16], - v_stride: u32, + planar_image: &YuvPlanarImage, yuy2_store: &mut [u16], yuy2_stride: u32, - width: u32, - height: u32, -) { +) -> Result<(), YuvError> { yuv_to_yuy2_impl_p16::<{ YuvChromaSample::YUV444 as u8 }, { Yuy2Description::YUYV as usize }>( - y_plane, - y_stride, - u_plane, - u_stride, - v_plane, - v_stride, + planar_image, yuy2_store, yuy2_stride, - width, - height, - ); + ) } /// Convert YUV 422 planar format to YUYV ( YUV Packed ) format. @@ -220,14 +206,7 @@ pub fn yuv444_to_yuyv422_p16( /// /// # Arguments /// -/// * `y_plane` - A slice to load the Y (luminance) plane data. -/// * `y_stride` - The stride (bytes per row) for the Y plane. -/// * `u_plane` - A slice to load the U (chrominance) plane data. -/// * `u_stride` - The stride (bytes per row) for the U plane. -/// * `v_plane` - A slice to load the V (chrominance) plane data. -/// * `v_stride` - The stride (bytes per row) for the V plane. -/// * `width` - The width of the YUV image. -/// * `height` - The height of the YUV image. +/// * `planar_image` - Source planar image. /// * `yuy2_store` - A mutable slice to store the converted YUYV data. /// * `yuy2_stride` - The stride (bytes per row) for the YUYV plane. /// @@ -235,32 +214,18 @@ pub fn yuv444_to_yuyv422_p16( /// /// This function panics if the lengths of the planes or the input YUYV data are not valid based /// on the specified width, height, and strides, or if invalid YUV range or matrix is provided. -/// Panic will be received if buffer doesn't expand with (width + 1) size for odd width +/// Panic will be received if buffer doesn't expand with (width + 1) size for odd width. /// pub fn yuv422_to_yuyv422_p16( - y_plane: &[u16], - y_stride: u32, - u_plane: &[u16], - u_stride: u32, - v_plane: &[u16], - v_stride: u32, + planar_image: &YuvPlanarImage, yuy2_store: &mut [u16], yuy2_stride: u32, - width: u32, - height: u32, -) { +) -> Result<(), YuvError> { yuv_to_yuy2_impl_p16::<{ YuvChromaSample::YUV422 as u8 }, { Yuy2Description::YUYV as usize }>( - y_plane, - y_stride, - u_plane, - u_stride, - v_plane, - v_stride, + planar_image, yuy2_store, yuy2_stride, - width, - height, - ); + ) } /// Convert YUV 420 planar format to YUYV ( YUV Packed ) format. @@ -271,14 +236,7 @@ pub fn yuv422_to_yuyv422_p16( /// /// # Arguments /// -/// * `y_plane` - A slice to load the Y (luminance) plane data. -/// * `y_stride` - The stride (bytes per row) for the Y plane. -/// * `u_plane` - A slice to load the U (chrominance) plane data. -/// * `u_stride` - The stride (bytes per row) for the U plane. -/// * `v_plane` - A slice to load the V (chrominance) plane data. -/// * `v_stride` - The stride (bytes per row) for the V plane. -/// * `width` - The width of the YUV image. -/// * `height` - The height of the YUV image. +/// * `planar_image` - Source planar image. /// * `yuy2_store` - A mutable slice to store the converted YUYV data. /// * `yuy2_stride` - The stride (bytes per row) for the YUYV plane. /// @@ -286,32 +244,18 @@ pub fn yuv422_to_yuyv422_p16( /// /// This function panics if the lengths of the planes or the input YUYV data are not valid based /// on the specified width, height, and strides, or if invalid YUV range or matrix is provided. -/// Panic will be received if buffer doesn't expand with (width + 1) size for odd width +/// Panic will be received if buffer doesn't expand with (width + 1) size for odd width. /// pub fn yuv420_to_yuyv422_p16( - y_plane: &[u16], - y_stride: u32, - u_plane: &[u16], - u_stride: u32, - v_plane: &[u16], - v_stride: u32, + planar_image: &YuvPlanarImage, yuy2_store: &mut [u16], yuy2_stride: u32, - width: u32, - height: u32, -) { +) -> Result<(), YuvError> { yuv_to_yuy2_impl_p16::<{ YuvChromaSample::YUV420 as u8 }, { Yuy2Description::YUYV as usize }>( - y_plane, - y_stride, - u_plane, - u_stride, - v_plane, - v_stride, + planar_image, yuy2_store, yuy2_stride, - width, - height, - ); + ) } /// Convert YUV 444 planar format to YVYU ( YUV Packed ) format. @@ -322,14 +266,7 @@ pub fn yuv420_to_yuyv422_p16( /// /// # Arguments /// -/// * `y_plane` - A slice to load the Y (luminance) plane data. -/// * `y_stride` - The stride (bytes per row) for the Y plane. -/// * `u_plane` - A slice to load the U (chrominance) plane data. -/// * `u_stride` - The stride (bytes per row) for the U plane. -/// * `v_plane` - A slice to load the V (chrominance) plane data. -/// * `v_stride` - The stride (bytes per row) for the V plane. -/// * `width` - The width of the YUV image. -/// * `height` - The height of the YUV image. +/// * `planar_image` - Source planar image. /// * `yuy2_store` - A mutable slice to store the converted YVYU data. /// * `yuy2_stride` - The stride (bytes per row) for the YVYU plane. /// @@ -337,32 +274,18 @@ pub fn yuv420_to_yuyv422_p16( /// /// This function panics if the lengths of the planes or the input YVYU data are not valid based /// on the specified width, height, and strides, or if invalid YUV range or matrix is provided. -/// Panic will be received if buffer doesn't expand with (width + 1) size for odd width +/// Panic will be received if buffer doesn't expand with (width + 1) size for odd width. /// pub fn yuv444_to_yvyu422_p16( - y_plane: &[u16], - y_stride: u32, - u_plane: &[u16], - u_stride: u32, - v_plane: &[u16], - v_stride: u32, + planar_image: &YuvPlanarImage, yuy2_store: &mut [u16], yuy2_stride: u32, - width: u32, - height: u32, -) { +) -> Result<(), YuvError> { yuv_to_yuy2_impl_p16::<{ YuvChromaSample::YUV444 as u8 }, { Yuy2Description::YVYU as usize }>( - y_plane, - y_stride, - u_plane, - u_stride, - v_plane, - v_stride, + planar_image, yuy2_store, yuy2_stride, - width, - height, - ); + ) } /// Convert YUV 422 planar format to YVYU ( YUV Packed ) format. @@ -373,14 +296,7 @@ pub fn yuv444_to_yvyu422_p16( /// /// # Arguments /// -/// * `y_plane` - A slice to load the Y (luminance) plane data. -/// * `y_stride` - The stride (bytes per row) for the Y plane. -/// * `u_plane` - A slice to load the U (chrominance) plane data. -/// * `u_stride` - The stride (bytes per row) for the U plane. -/// * `v_plane` - A slice to load the V (chrominance) plane data. -/// * `v_stride` - The stride (bytes per row) for the V plane. -/// * `width` - The width of the YUV image. -/// * `height` - The height of the YUV image. +/// * `planar_image` - Source planar image. /// * `yuy2_store` - A mutable slice to store the converted YVYU data. /// * `yuy2_stride` - The stride (bytes per row) for the YVYU plane. /// @@ -388,32 +304,18 @@ pub fn yuv444_to_yvyu422_p16( /// /// This function panics if the lengths of the planes or the input YVYU data are not valid based /// on the specified width, height, and strides, or if invalid YUV range or matrix is provided. -/// Panic will be received if buffer doesn't expand with (width + 1) size for odd width +/// Panic will be received if buffer doesn't expand with (width + 1) size for odd width. /// pub fn yuv422_to_yvyu422_p16( - y_plane: &[u16], - y_stride: u32, - u_plane: &[u16], - u_stride: u32, - v_plane: &[u16], - v_stride: u32, + planar_image: &YuvPlanarImage, yuy2_store: &mut [u16], yuy2_stride: u32, - width: u32, - height: u32, -) { +) -> Result<(), YuvError> { yuv_to_yuy2_impl_p16::<{ YuvChromaSample::YUV422 as u8 }, { Yuy2Description::YVYU as usize }>( - y_plane, - y_stride, - u_plane, - u_stride, - v_plane, - v_stride, + planar_image, yuy2_store, yuy2_stride, - width, - height, - ); + ) } /// Convert YUV 420 planar format to YVYU ( YUV Packed ) format. @@ -424,14 +326,7 @@ pub fn yuv422_to_yvyu422_p16( /// /// # Arguments /// -/// * `y_plane` - A slice to load the Y (luminance) plane data. -/// * `y_stride` - The stride (bytes per row) for the Y plane. -/// * `u_plane` - A slice to load the U (chrominance) plane data. -/// * `u_stride` - The stride (bytes per row) for the U plane. -/// * `v_plane` - A slice to load the V (chrominance) plane data. -/// * `v_stride` - The stride (bytes per row) for the V plane. -/// * `width` - The width of the YUV image. -/// * `height` - The height of the YUV image. +/// * `planar_image` - Source planar image. /// * `yuy2_store` - A mutable slice to store the converted YVYU data. /// * `yuy2_stride` - The stride (bytes per row) for the YVYU plane. /// @@ -439,32 +334,18 @@ pub fn yuv422_to_yvyu422_p16( /// /// This function panics if the lengths of the planes or the input YVYU data are not valid based /// on the specified width, height, and strides, or if invalid YUV range or matrix is provided. -/// Panic will be received if buffer doesn't expand with (width + 1) size for odd width +/// Panic will be received if buffer doesn't expand with (width + 1) size for odd width. /// pub fn yuv420_to_yvyu422_p16( - y_plane: &[u16], - y_stride: u32, - u_plane: &[u16], - u_stride: u32, - v_plane: &[u16], - v_stride: u32, + planar_image: &YuvPlanarImage, yuy2_store: &mut [u16], yuy2_stride: u32, - width: u32, - height: u32, -) { +) -> Result<(), YuvError> { yuv_to_yuy2_impl_p16::<{ YuvChromaSample::YUV420 as u8 }, { Yuy2Description::YVYU as usize }>( - y_plane, - y_stride, - u_plane, - u_stride, - v_plane, - v_stride, + planar_image, yuy2_store, yuy2_stride, - width, - height, - ); + ) } /// Convert YUV 444 planar format to VYUY ( YUV Packed ) format. @@ -475,14 +356,7 @@ pub fn yuv420_to_yvyu422_p16( /// /// # Arguments /// -/// * `y_plane` - A slice to load the Y (luminance) plane data. -/// * `y_stride` - The stride (bytes per row) for the Y plane. -/// * `u_plane` - A slice to load the U (chrominance) plane data. -/// * `u_stride` - The stride (bytes per row) for the U plane. -/// * `v_plane` - A slice to load the V (chrominance) plane data. -/// * `v_stride` - The stride (bytes per row) for the V plane. -/// * `width` - The width of the YUV image. -/// * `height` - The height of the YUV image. +/// * `planar_image` - Source planar image. /// * `yuy2_store` - A mutable slice to store the converted VYUY data. /// * `yuy2_stride` - The stride (bytes per row) for the VYUY plane. /// @@ -490,32 +364,18 @@ pub fn yuv420_to_yvyu422_p16( /// /// This function panics if the lengths of the planes or the input VYUY data are not valid based /// on the specified width, height, and strides, or if invalid YUV range or matrix is provided. -/// Panic will be received if buffer doesn't expand with (width + 1) size for odd width +/// Panic will be received if buffer doesn't expand with (width + 1) size for odd width. /// pub fn yuv444_to_vyuy422_p16( - y_plane: &[u16], - y_stride: u32, - u_plane: &[u16], - u_stride: u32, - v_plane: &[u16], - v_stride: u32, + planar_image: &YuvPlanarImage, yuy2_store: &mut [u16], yuy2_stride: u32, - width: u32, - height: u32, -) { +) -> Result<(), YuvError> { yuv_to_yuy2_impl_p16::<{ YuvChromaSample::YUV444 as u8 }, { Yuy2Description::VYUY as usize }>( - y_plane, - y_stride, - u_plane, - u_stride, - v_plane, - v_stride, + planar_image, yuy2_store, yuy2_stride, - width, - height, - ); + ) } /// Convert YUV 422 planar format to VYUY ( YUV Packed ) format. @@ -526,14 +386,7 @@ pub fn yuv444_to_vyuy422_p16( /// /// # Arguments /// -/// * `y_plane` - A slice to load the Y (luminance) plane data. -/// * `y_stride` - The stride (bytes per row) for the Y plane. -/// * `u_plane` - A slice to load the U (chrominance) plane data. -/// * `u_stride` - The stride (bytes per row) for the U plane. -/// * `v_plane` - A slice to load the V (chrominance) plane data. -/// * `v_stride` - The stride (bytes per row) for the V plane. -/// * `width` - The width of the YUV image. -/// * `height` - The height of the YUV image. +/// * `planar_image` - Source planar image. /// * `yuy2_store` - A mutable slice to store the converted VYUY data. /// * `yuy2_stride` - The stride (bytes per row) for the VYUY plane. /// @@ -541,32 +394,18 @@ pub fn yuv444_to_vyuy422_p16( /// /// This function panics if the lengths of the planes or the input VYUY data are not valid based /// on the specified width, height, and strides, or if invalid YUV range or matrix is provided. -/// Panic will be received if buffer doesn't expand with (width + 1) size for odd width +/// Panic will be received if buffer doesn't expand with (width + 1) size for odd width. /// pub fn yuv422_to_vyuy422_p16( - y_plane: &[u16], - y_stride: u32, - u_plane: &[u16], - u_stride: u32, - v_plane: &[u16], - v_stride: u32, + planar_image: &YuvPlanarImage, yuy2_store: &mut [u16], yuy2_stride: u32, - width: u32, - height: u32, -) { +) -> Result<(), YuvError> { yuv_to_yuy2_impl_p16::<{ YuvChromaSample::YUV422 as u8 }, { Yuy2Description::VYUY as usize }>( - y_plane, - y_stride, - u_plane, - u_stride, - v_plane, - v_stride, + planar_image, yuy2_store, yuy2_stride, - width, - height, - ); + ) } /// Convert YUV 420 planar format to VYUY ( YUV Packed ) format. @@ -577,14 +416,7 @@ pub fn yuv422_to_vyuy422_p16( /// /// # Arguments /// -/// * `y_plane` - A slice to load the Y (luminance) plane data. -/// * `y_stride` - The stride (bytes per row) for the Y plane. -/// * `u_plane` - A slice to load the U (chrominance) plane data. -/// * `u_stride` - The stride (bytes per row) for the U plane. -/// * `v_plane` - A slice to load the V (chrominance) plane data. -/// * `v_stride` - The stride (bytes per row) for the V plane. -/// * `width` - The width of the YUV image. -/// * `height` - The height of the YUV image. +/// * `planar_image` - Source planar image. /// * `yuy2_store` - A mutable slice to store the converted VYUY data. /// * `yuy2_stride` - The stride (bytes per row) for the VYUY plane. /// @@ -592,32 +424,18 @@ pub fn yuv422_to_vyuy422_p16( /// /// This function panics if the lengths of the planes or the input VYUY data are not valid based /// on the specified width, height, and strides, or if invalid YUV range or matrix is provided. -/// Panic will be received if buffer doesn't expand with (width + 1) size for odd width +/// Panic will be received if buffer doesn't expand with (width + 1) size for odd width. /// pub fn yuv420_to_vyuy422_p16( - y_plane: &[u16], - y_stride: u32, - u_plane: &[u16], - u_stride: u32, - v_plane: &[u16], - v_stride: u32, + planar_image: &YuvPlanarImage, yuy2_store: &mut [u16], yuy2_stride: u32, - width: u32, - height: u32, -) { +) -> Result<(), YuvError> { yuv_to_yuy2_impl_p16::<{ YuvChromaSample::YUV420 as u8 }, { Yuy2Description::VYUY as usize }>( - y_plane, - y_stride, - u_plane, - u_stride, - v_plane, - v_stride, + planar_image, yuy2_store, yuy2_stride, - width, - height, - ); + ) } /// Convert YUV 444 planar format to UYVY ( YUV Packed ) format. @@ -628,14 +446,7 @@ pub fn yuv420_to_vyuy422_p16( /// /// # Arguments /// -/// * `y_plane` - A slice to load the Y (luminance) plane data. -/// * `y_stride` - The stride (bytes per row) for the Y plane. -/// * `u_plane` - A slice to load the U (chrominance) plane data. -/// * `u_stride` - The stride (bytes per row) for the U plane. -/// * `v_plane` - A slice to load the V (chrominance) plane data. -/// * `v_stride` - The stride (bytes per row) for the V plane. -/// * `width` - The width of the YUV image. -/// * `height` - The height of the YUV image. +/// * `planar_image` - Source planar image. /// * `yuy2_store` - A mutable slice to store the converted UYVY data. /// * `yuy2_stride` - The stride (bytes per row) for the UYVY plane. /// @@ -643,32 +454,18 @@ pub fn yuv420_to_vyuy422_p16( /// /// This function panics if the lengths of the planes or the input UYVY data are not valid based /// on the specified width, height, and strides, or if invalid YUV range or matrix is provided. -/// Panic will be received if buffer doesn't expand with (width + 1) size for odd width +/// Panic will be received if buffer doesn't expand with (width + 1) size for odd width. /// pub fn yuv444_to_uyvy422_p16( - y_plane: &[u16], - y_stride: u32, - u_plane: &[u16], - u_stride: u32, - v_plane: &[u16], - v_stride: u32, + planar_image: &YuvPlanarImage, yuy2_store: &mut [u16], yuy2_stride: u32, - width: u32, - height: u32, -) { +) -> Result<(), YuvError> { yuv_to_yuy2_impl_p16::<{ YuvChromaSample::YUV444 as u8 }, { Yuy2Description::UYVY as usize }>( - y_plane, - y_stride, - u_plane, - u_stride, - v_plane, - v_stride, + planar_image, yuy2_store, yuy2_stride, - width, - height, - ); + ) } /// Convert YUV 422 planar format to UYVY ( YUV Packed ) format. @@ -679,14 +476,7 @@ pub fn yuv444_to_uyvy422_p16( /// /// # Arguments /// -/// * `y_plane` - A slice to load the Y (luminance) plane data. -/// * `y_stride` - The stride (bytes per row) for the Y plane. -/// * `u_plane` - A slice to load the U (chrominance) plane data. -/// * `u_stride` - The stride (bytes per row) for the U plane. -/// * `v_plane` - A slice to load the V (chrominance) plane data. -/// * `v_stride` - The stride (bytes per row) for the V plane. -/// * `width` - The width of the YUV image. -/// * `height` - The height of the YUV image. +/// * `planar_image` - Source planar image. /// * `yuy2_store` - A mutable slice to store the converted UYVY data. /// * `yuy2_stride` - The stride (bytes per row) for the UYVY plane. /// @@ -694,32 +484,18 @@ pub fn yuv444_to_uyvy422_p16( /// /// This function panics if the lengths of the planes or the input UYVY data are not valid based /// on the specified width, height, and strides, or if invalid YUV range or matrix is provided. -/// Panic will be received if buffer doesn't expand with (width + 1) size for odd width +/// Panic will be received if buffer doesn't expand with (width + 1) size for odd width. /// pub fn yuv422_to_uyvy422_p16( - y_plane: &[u16], - y_stride: u32, - u_plane: &[u16], - u_stride: u32, - v_plane: &[u16], - v_stride: u32, + planar_image: &YuvPlanarImage, yuy2_store: &mut [u16], yuy2_stride: u32, - width: u32, - height: u32, -) { +) -> Result<(), YuvError> { yuv_to_yuy2_impl_p16::<{ YuvChromaSample::YUV422 as u8 }, { Yuy2Description::UYVY as usize }>( - y_plane, - y_stride, - u_plane, - u_stride, - v_plane, - v_stride, + planar_image, yuy2_store, yuy2_stride, - width, - height, - ); + ) } /// Convert YUV 420 planar format to UYVY ( YUV Packed ) format. @@ -730,14 +506,7 @@ pub fn yuv422_to_uyvy422_p16( /// /// # Arguments /// -/// * `y_plane` - A slice to load the Y (luminance) plane data. -/// * `y_stride` - The stride (bytes per row) for the Y plane. -/// * `u_plane` - A slice to load the U (chrominance) plane data. -/// * `u_stride` - The stride (bytes per row) for the U plane. -/// * `v_plane` - A slice to load the V (chrominance) plane data. -/// * `v_stride` - The stride (bytes per row) for the V plane. -/// * `width` - The width of the YUV image. -/// * `height` - The height of the YUV image. +/// * `planar_image` - Source planar image. /// * `yuy2_store` - A mutable slice to store the converted UYVY data. /// * `yuy2_stride` - The stride (bytes per row) for the UYVY plane. /// @@ -745,30 +514,16 @@ pub fn yuv422_to_uyvy422_p16( /// /// This function panics if the lengths of the planes or the input UYVY data are not valid based /// on the specified width, height, and strides, or if invalid YUV range or matrix is provided. -/// Panic will be received if buffer doesn't expand with (width + 1) size for odd width +/// Panic will be received if buffer doesn't expand with (width + 1) size for odd width. /// pub fn yuv420_to_uyvy422_p16( - y_plane: &[u16], - y_stride: u32, - u_plane: &[u16], - u_stride: u32, - v_plane: &[u16], - v_stride: u32, + planar_image: &YuvPlanarImage, yuy2_store: &mut [u16], yuy2_stride: u32, - width: u32, - height: u32, -) { +) -> Result<(), YuvError> { yuv_to_yuy2_impl_p16::<{ YuvChromaSample::YUV420 as u8 }, { Yuy2Description::UYVY as usize }>( - y_plane, - y_stride, - u_plane, - u_stride, - v_plane, - v_stride, + planar_image, yuy2_store, yuy2_stride, - width, - height, - ); + ) }