From 8402a08b525fdb225b10b206f9519edf8c5e7336 Mon Sep 17 00:00:00 2001 From: Radzivon Bartoshyk Date: Sun, 10 Nov 2024 10:51:30 +0000 Subject: [PATCH] Small fixes --- Cargo.lock | 2 +- Cargo.toml | 2 +- app/src/main.rs | 13 +++-- src/rgb_to_yuv_p16.rs | 3 +- src/ycgco_to_rgb_alpha.rs | 14 ++--- src/yuv_to_rgba_alpha.rs | 30 ++++++++--- src/yuv_to_yuy2_p16.rs | 108 +++++++++++++++++++++----------------- 7 files changed, 105 insertions(+), 67 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1d65970..910b903 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1353,7 +1353,7 @@ dependencies = [ [[package]] name = "yuvutils-rs" -version = "0.5.0" +version = "0.5.1" dependencies = [ "num-traits", "rayon", diff --git a/Cargo.toml b/Cargo.toml index 02903b9..c9037f9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ workspace = { members = ["app"] } [package] name = "yuvutils-rs" -version = "0.5.0" +version = "0.5.1" edition = "2021" description = "High performance utilities for YUV format handling and conversion." readme = "README.md" diff --git a/app/src/main.rs b/app/src/main.rs index 1305ab4..b1e3158 100644 --- a/app/src/main.rs +++ b/app/src/main.rs @@ -31,7 +31,11 @@ use image::{ColorType, EncodableLayout, GenericImageView, ImageReader}; use std::fs::File; use std::io::Read; use std::time::Instant; -use yuvutils_rs::{rgb_to_sharp_yuv422, rgb_to_yuv_nv12_p16, yuv422_to_rgb, yuv_nv12_to_rgb_p16, SharpYuvGammaTransfer, YuvBiPlanarImageMut, YuvBytesPacking, YuvChromaSubsampling, YuvEndianness, YuvPlanarImageMut, YuvRange, YuvStandardMatrix}; +use yuvutils_rs::{ + rgb_to_sharp_yuv422, rgb_to_yuv_nv12_p16, yuv422_to_rgb, yuv_nv12_to_rgb_p16, + SharpYuvGammaTransfer, YuvBiPlanarImageMut, YuvBytesPacking, YuvChromaSubsampling, + YuvEndianness, YuvPlanarImageMut, YuvRange, YuvStandardMatrix, +}; fn read_file_bytes(file_path: &str) -> Result, String> { // Open the file @@ -82,8 +86,11 @@ fn main() { let mut y_nv_plane = vec![0u8; width as usize * height as usize]; let mut uv_nv_plane = vec![0u8; width as usize * (height as usize + 1) / 2]; - let mut bi_planar_image = - YuvBiPlanarImageMut::::alloc(width as u32, height as u32, YuvChromaSubsampling::Yuv420); + let mut bi_planar_image = YuvBiPlanarImageMut::::alloc( + width as u32, + height as u32, + YuvChromaSubsampling::Yuv420, + ); let mut planar_image = YuvPlanarImageMut::::alloc(width as u32, height as u32, YuvChromaSubsampling::Yuv422); diff --git a/src/rgb_to_yuv_p16.rs b/src/rgb_to_yuv_p16.rs index 128a45e..8f88e9c 100644 --- a/src/rgb_to_yuv_p16.rs +++ b/src/rgb_to_yuv_p16.rs @@ -33,7 +33,8 @@ use crate::neon::neon_rgba_to_yuv_p16; use crate::sse::sse_rgba_to_yuv_p16; use crate::yuv_error::check_rgba_destination; use crate::yuv_support::{ - get_forward_transform, get_yuv_range, ToIntegerTransform, YuvChromaSubsampling, YuvSourceChannels, + get_forward_transform, get_yuv_range, ToIntegerTransform, YuvChromaSubsampling, + YuvSourceChannels, }; use crate::{ YuvBytesPacking, YuvEndianness, YuvError, YuvPlanarImageMut, YuvRange, YuvStandardMatrix, diff --git a/src/ycgco_to_rgb_alpha.rs b/src/ycgco_to_rgb_alpha.rs index 0e8cd3c..020acdf 100644 --- a/src/ycgco_to_rgb_alpha.rs +++ b/src/ycgco_to_rgb_alpha.rs @@ -44,7 +44,7 @@ use crate::yuv_support::*; use crate::{YuvError, YuvPlanarImageWithAlpha, YuvRange}; fn ycgco_ro_rgbx( - planar_image_with_alpha: YuvPlanarImageWithAlpha, + planar_image_with_alpha: &YuvPlanarImageWithAlpha, rgba: &mut [u8], rgba_stride: u32, range: YuvRange, @@ -357,7 +357,7 @@ fn ycgco_ro_rgbx( /// on the specified width, height, and strides, or if invalid YUV range or matrix is provided. /// pub fn ycgco420_with_alpha_to_rgba( - planar_image_with_alpha: YuvPlanarImageWithAlpha, + planar_image_with_alpha: &YuvPlanarImageWithAlpha, rgba: &mut [u8], rgba_stride: u32, range: YuvRange, @@ -391,7 +391,7 @@ pub fn ycgco420_with_alpha_to_rgba( /// on the specified width, height, and strides, or if invalid YUV range or matrix is provided. /// pub fn ycgco420_with_alpha_to_bgra( - planar_image_with_alpha: YuvPlanarImageWithAlpha, + planar_image_with_alpha: &YuvPlanarImageWithAlpha, bgra: &mut [u8], bgra_stride: u32, range: YuvRange, @@ -425,7 +425,7 @@ pub fn ycgco420_with_alpha_to_bgra( /// on the specified width, height, and strides, or if invalid YUV range or matrix is provided. /// pub fn ycgco422_with_alpha_to_rgba( - planar_image_with_alpha: YuvPlanarImageWithAlpha, + planar_image_with_alpha: &YuvPlanarImageWithAlpha, rgba: &mut [u8], rgba_stride: u32, range: YuvRange, @@ -459,7 +459,7 @@ pub fn ycgco422_with_alpha_to_rgba( /// on the specified width, height, and strides, or if invalid YUV range or matrix is provided. /// pub fn ycgco422_with_alpha_to_bgra( - planar_image_with_alpha: YuvPlanarImageWithAlpha, + planar_image_with_alpha: &YuvPlanarImageWithAlpha, bgra: &mut [u8], bgra_stride: u32, range: YuvRange, @@ -493,7 +493,7 @@ pub fn ycgco422_with_alpha_to_bgra( /// on the specified width, height, and strides, or if invalid YUV range or matrix is provided. /// pub fn ycgco444_with_alpha_to_rgba( - planar_image_with_alpha: YuvPlanarImageWithAlpha, + planar_image_with_alpha: &YuvPlanarImageWithAlpha, rgba: &mut [u8], rgba_stride: u32, range: YuvRange, @@ -527,7 +527,7 @@ pub fn ycgco444_with_alpha_to_rgba( /// on the specified width, height, and strides, or if invalid YUV range or matrix is provided. /// pub fn ycgco444_with_alpha_to_bgra( - planar_image_with_alpha: YuvPlanarImageWithAlpha, + planar_image_with_alpha: &YuvPlanarImageWithAlpha, bgra: &mut [u8], bgra_stride: u32, range: YuvRange, diff --git a/src/yuv_to_rgba_alpha.rs b/src/yuv_to_rgba_alpha.rs index d8d33aa..838c6c4 100644 --- a/src/yuv_to_rgba_alpha.rs +++ b/src/yuv_to_rgba_alpha.rs @@ -433,7 +433,10 @@ pub fn yuv420_with_alpha_to_rgba( matrix: YuvStandardMatrix, premultiply_alpha: bool, ) -> Result<(), YuvError> { - yuv_with_alpha_to_rgbx::<{ YuvSourceChannels::Rgba as u8 }, { YuvChromaSubsampling::Yuv420 as u8 }>( + yuv_with_alpha_to_rgbx::< + { YuvSourceChannels::Rgba as u8 }, + { YuvChromaSubsampling::Yuv420 as u8 }, + >( planar_with_alpha, rgba, rgba_stride, @@ -470,7 +473,10 @@ pub fn yuv420_with_alpha_to_bgra( matrix: YuvStandardMatrix, premultiply_alpha: bool, ) -> Result<(), YuvError> { - yuv_with_alpha_to_rgbx::<{ YuvSourceChannels::Bgra as u8 }, { YuvChromaSubsampling::Yuv420 as u8 }>( + yuv_with_alpha_to_rgbx::< + { YuvSourceChannels::Bgra as u8 }, + { YuvChromaSubsampling::Yuv420 as u8 }, + >( planar_with_alpha, bgra, bgra_stride, @@ -507,7 +513,10 @@ pub fn yuv422_with_alpha_to_rgba( matrix: YuvStandardMatrix, premultiply_alpha: bool, ) -> Result<(), YuvError> { - yuv_with_alpha_to_rgbx::<{ YuvSourceChannels::Rgba as u8 }, { YuvChromaSubsampling::Yuv422 as u8 }>( + yuv_with_alpha_to_rgbx::< + { YuvSourceChannels::Rgba as u8 }, + { YuvChromaSubsampling::Yuv422 as u8 }, + >( planar_with_alpha, rgba, rgba_stride, @@ -544,7 +553,10 @@ pub fn yuv422_with_alpha_to_bgra( matrix: YuvStandardMatrix, premultiply_alpha: bool, ) -> Result<(), YuvError> { - yuv_with_alpha_to_rgbx::<{ YuvSourceChannels::Bgra as u8 }, { YuvChromaSubsampling::Yuv422 as u8 }>( + yuv_with_alpha_to_rgbx::< + { YuvSourceChannels::Bgra as u8 }, + { YuvChromaSubsampling::Yuv422 as u8 }, + >( planar_with_alpha, bgra, bgra_stride, @@ -581,7 +593,10 @@ pub fn yuv444_with_alpha_to_rgba( matrix: YuvStandardMatrix, premultiply_alpha: bool, ) -> Result<(), YuvError> { - yuv_with_alpha_to_rgbx::<{ YuvSourceChannels::Rgba as u8 }, { YuvChromaSubsampling::Yuv444 as u8 }>( + yuv_with_alpha_to_rgbx::< + { YuvSourceChannels::Rgba as u8 }, + { YuvChromaSubsampling::Yuv444 as u8 }, + >( planar_with_alpha, rgba, rgba_stride, @@ -618,7 +633,10 @@ pub fn yuv444_with_alpha_to_bgra( matrix: YuvStandardMatrix, premultiply_alpha: bool, ) -> Result<(), YuvError> { - yuv_with_alpha_to_rgbx::<{ YuvSourceChannels::Bgra as u8 }, { YuvChromaSubsampling::Yuv444 as u8 }>( + yuv_with_alpha_to_rgbx::< + { YuvSourceChannels::Bgra as u8 }, + { YuvChromaSubsampling::Yuv444 as u8 }, + >( planar_with_alpha, bgra, bgra_stride, diff --git a/src/yuv_to_yuy2_p16.rs b/src/yuv_to_yuy2_p16.rs index 364c785..c0638da 100644 --- a/src/yuv_to_yuy2_p16.rs +++ b/src/yuv_to_yuy2_p16.rs @@ -51,10 +51,11 @@ pub fn yuv444_to_yuyv422_p16( packed_image: &mut YuvPackedImageMut, planar_image: &YuvPlanarImage, ) -> Result<(), YuvError> { - yuv_to_yuy2_impl::( - planar_image, - packed_image, - ) + yuv_to_yuy2_impl::< + u16, + { YuvChromaSubsampling::Yuv444 as u8 }, + { Yuy2Description::YUYV as usize }, + >(planar_image, packed_image) } /// Convert YUV 422 planar format to YUYV ( YUV Packed ) format. @@ -78,10 +79,11 @@ pub fn yuv422_to_yuyv422_p16( packed_image: &mut YuvPackedImageMut, planar_image: &YuvPlanarImage, ) -> Result<(), YuvError> { - yuv_to_yuy2_impl::( - planar_image, - packed_image, - ) + yuv_to_yuy2_impl::< + u16, + { YuvChromaSubsampling::Yuv422 as u8 }, + { Yuy2Description::YUYV as usize }, + >(planar_image, packed_image) } /// Convert YUV 420 planar format to YUYV ( YUV Packed ) format. @@ -105,10 +107,11 @@ pub fn yuv420_to_yuyv422_p16( packed_image: &mut YuvPackedImageMut, planar_image: &YuvPlanarImage, ) -> Result<(), YuvError> { - yuv_to_yuy2_impl::( - planar_image, - packed_image, - ) + yuv_to_yuy2_impl::< + u16, + { YuvChromaSubsampling::Yuv420 as u8 }, + { Yuy2Description::YUYV as usize }, + >(planar_image, packed_image) } /// Convert YUV 444 planar format to YVYU ( YUV Packed ) format. @@ -132,10 +135,11 @@ pub fn yuv444_to_yvyu422_p16( packed_image: &mut YuvPackedImageMut, planar_image: &YuvPlanarImage, ) -> Result<(), YuvError> { - yuv_to_yuy2_impl::( - planar_image, - packed_image, - ) + yuv_to_yuy2_impl::< + u16, + { YuvChromaSubsampling::Yuv444 as u8 }, + { Yuy2Description::YVYU as usize }, + >(planar_image, packed_image) } /// Convert YUV 422 planar format to YVYU ( YUV Packed ) format. @@ -159,10 +163,11 @@ pub fn yuv422_to_yvyu422_p16( packed_image: &mut YuvPackedImageMut, planar_image: &YuvPlanarImage, ) -> Result<(), YuvError> { - yuv_to_yuy2_impl::( - planar_image, - packed_image, - ) + yuv_to_yuy2_impl::< + u16, + { YuvChromaSubsampling::Yuv422 as u8 }, + { Yuy2Description::YVYU as usize }, + >(planar_image, packed_image) } /// Convert YUV 420 planar format to YVYU ( YUV Packed ) format. @@ -186,10 +191,11 @@ pub fn yuv420_to_yvyu422_p16( packed_image: &mut YuvPackedImageMut, planar_image: &YuvPlanarImage, ) -> Result<(), YuvError> { - yuv_to_yuy2_impl::( - planar_image, - packed_image, - ) + yuv_to_yuy2_impl::< + u16, + { YuvChromaSubsampling::Yuv420 as u8 }, + { Yuy2Description::YVYU as usize }, + >(planar_image, packed_image) } /// Convert YUV 444 planar format to VYUY ( YUV Packed ) format. @@ -213,10 +219,11 @@ pub fn yuv444_to_vyuy422_p16( packed_image: &mut YuvPackedImageMut, planar_image: &YuvPlanarImage, ) -> Result<(), YuvError> { - yuv_to_yuy2_impl::( - planar_image, - packed_image, - ) + yuv_to_yuy2_impl::< + u16, + { YuvChromaSubsampling::Yuv444 as u8 }, + { Yuy2Description::VYUY as usize }, + >(planar_image, packed_image) } /// Convert YUV 422 planar format to VYUY ( YUV Packed ) format. @@ -240,10 +247,11 @@ pub fn yuv422_to_vyuy422_p16( packed_image: &mut YuvPackedImageMut, planar_image: &YuvPlanarImage, ) -> Result<(), YuvError> { - yuv_to_yuy2_impl::( - planar_image, - packed_image, - ) + yuv_to_yuy2_impl::< + u16, + { YuvChromaSubsampling::Yuv422 as u8 }, + { Yuy2Description::VYUY as usize }, + >(planar_image, packed_image) } /// Convert YUV 420 planar format to VYUY ( YUV Packed ) format. @@ -267,10 +275,11 @@ pub fn yuv420_to_vyuy422_p16( packed_image: &mut YuvPackedImageMut, planar_image: &YuvPlanarImage, ) -> Result<(), YuvError> { - yuv_to_yuy2_impl::( - planar_image, - packed_image, - ) + yuv_to_yuy2_impl::< + u16, + { YuvChromaSubsampling::Yuv420 as u8 }, + { Yuy2Description::VYUY as usize }, + >(planar_image, packed_image) } /// Convert YUV 444 planar format to UYVY ( YUV Packed ) format. @@ -294,10 +303,11 @@ pub fn yuv444_to_uyvy422_p16( packed_image: &mut YuvPackedImageMut, planar_image: &YuvPlanarImage, ) -> Result<(), YuvError> { - yuv_to_yuy2_impl::( - planar_image, - packed_image, - ) + yuv_to_yuy2_impl::< + u16, + { YuvChromaSubsampling::Yuv444 as u8 }, + { Yuy2Description::UYVY as usize }, + >(planar_image, packed_image) } /// Convert YUV 422 planar format to UYVY ( YUV Packed ) format. @@ -321,10 +331,11 @@ pub fn yuv422_to_uyvy422_p16( packed_image: &mut YuvPackedImageMut, planar_image: &YuvPlanarImage, ) -> Result<(), YuvError> { - yuv_to_yuy2_impl::( - planar_image, - packed_image, - ) + yuv_to_yuy2_impl::< + u16, + { YuvChromaSubsampling::Yuv422 as u8 }, + { Yuy2Description::UYVY as usize }, + >(planar_image, packed_image) } /// Convert YUV 420 planar format to UYVY ( YUV Packed ) format. @@ -348,8 +359,9 @@ pub fn yuv420_to_uyvy422_p16( packed_image: &mut YuvPackedImageMut, planar_image: &YuvPlanarImage, ) -> Result<(), YuvError> { - yuv_to_yuy2_impl::( - planar_image, - packed_image, - ) + yuv_to_yuy2_impl::< + u16, + { YuvChromaSubsampling::Yuv420 as u8 }, + { Yuy2Description::UYVY as usize }, + >(planar_image, packed_image) }