Skip to content

Commit

Permalink
Merge pull request #5 from awxkee/dev
Browse files Browse the repository at this point in the history
Small fixes
  • Loading branch information
awxkee authored Nov 10, 2024
2 parents bbc1b4f + 8402a08 commit c052ef0
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 67 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
13 changes: 10 additions & 3 deletions app/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Vec<u8>, String> {
// Open the file
Expand Down Expand Up @@ -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::<u16>::alloc(width as u32, height as u32, YuvChromaSubsampling::Yuv420);
let mut bi_planar_image = YuvBiPlanarImageMut::<u16>::alloc(
width as u32,
height as u32,
YuvChromaSubsampling::Yuv420,
);

let mut planar_image =
YuvPlanarImageMut::<u8>::alloc(width as u32, height as u32, YuvChromaSubsampling::Yuv422);
Expand Down
3 changes: 2 additions & 1 deletion src/rgb_to_yuv_p16.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
14 changes: 7 additions & 7 deletions src/ycgco_to_rgb_alpha.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ use crate::yuv_support::*;
use crate::{YuvError, YuvPlanarImageWithAlpha, YuvRange};

fn ycgco_ro_rgbx<const DESTINATION_CHANNELS: u8, const SAMPLING: u8>(
planar_image_with_alpha: YuvPlanarImageWithAlpha<u8>,
planar_image_with_alpha: &YuvPlanarImageWithAlpha<u8>,
rgba: &mut [u8],
rgba_stride: u32,
range: YuvRange,
Expand Down Expand Up @@ -357,7 +357,7 @@ fn ycgco_ro_rgbx<const DESTINATION_CHANNELS: u8, const SAMPLING: u8>(
/// 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<u8>,
planar_image_with_alpha: &YuvPlanarImageWithAlpha<u8>,
rgba: &mut [u8],
rgba_stride: u32,
range: YuvRange,
Expand Down Expand Up @@ -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<u8>,
planar_image_with_alpha: &YuvPlanarImageWithAlpha<u8>,
bgra: &mut [u8],
bgra_stride: u32,
range: YuvRange,
Expand Down Expand Up @@ -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<u8>,
planar_image_with_alpha: &YuvPlanarImageWithAlpha<u8>,
rgba: &mut [u8],
rgba_stride: u32,
range: YuvRange,
Expand Down Expand Up @@ -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<u8>,
planar_image_with_alpha: &YuvPlanarImageWithAlpha<u8>,
bgra: &mut [u8],
bgra_stride: u32,
range: YuvRange,
Expand Down Expand Up @@ -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<u8>,
planar_image_with_alpha: &YuvPlanarImageWithAlpha<u8>,
rgba: &mut [u8],
rgba_stride: u32,
range: YuvRange,
Expand Down Expand Up @@ -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<u8>,
planar_image_with_alpha: &YuvPlanarImageWithAlpha<u8>,
bgra: &mut [u8],
bgra_stride: u32,
range: YuvRange,
Expand Down
30 changes: 24 additions & 6 deletions src/yuv_to_rgba_alpha.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
108 changes: 60 additions & 48 deletions src/yuv_to_yuy2_p16.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,11 @@ pub fn yuv444_to_yuyv422_p16(
packed_image: &mut YuvPackedImageMut<u16>,
planar_image: &YuvPlanarImage<u16>,
) -> Result<(), YuvError> {
yuv_to_yuy2_impl::<u16, { YuvChromaSubsampling::Yuv444 as u8 }, { Yuy2Description::YUYV as usize }>(
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.
Expand All @@ -78,10 +79,11 @@ pub fn yuv422_to_yuyv422_p16(
packed_image: &mut YuvPackedImageMut<u16>,
planar_image: &YuvPlanarImage<u16>,
) -> Result<(), YuvError> {
yuv_to_yuy2_impl::<u16, { YuvChromaSubsampling::Yuv422 as u8 }, { Yuy2Description::YUYV as usize }>(
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.
Expand All @@ -105,10 +107,11 @@ pub fn yuv420_to_yuyv422_p16(
packed_image: &mut YuvPackedImageMut<u16>,
planar_image: &YuvPlanarImage<u16>,
) -> Result<(), YuvError> {
yuv_to_yuy2_impl::<u16, { YuvChromaSubsampling::Yuv420 as u8 }, { Yuy2Description::YUYV as usize }>(
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.
Expand All @@ -132,10 +135,11 @@ pub fn yuv444_to_yvyu422_p16(
packed_image: &mut YuvPackedImageMut<u16>,
planar_image: &YuvPlanarImage<u16>,
) -> Result<(), YuvError> {
yuv_to_yuy2_impl::<u16, { YuvChromaSubsampling::Yuv444 as u8 }, { Yuy2Description::YVYU as usize }>(
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.
Expand All @@ -159,10 +163,11 @@ pub fn yuv422_to_yvyu422_p16(
packed_image: &mut YuvPackedImageMut<u16>,
planar_image: &YuvPlanarImage<u16>,
) -> Result<(), YuvError> {
yuv_to_yuy2_impl::<u16, { YuvChromaSubsampling::Yuv422 as u8 }, { Yuy2Description::YVYU as usize }>(
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.
Expand All @@ -186,10 +191,11 @@ pub fn yuv420_to_yvyu422_p16(
packed_image: &mut YuvPackedImageMut<u16>,
planar_image: &YuvPlanarImage<u16>,
) -> Result<(), YuvError> {
yuv_to_yuy2_impl::<u16, { YuvChromaSubsampling::Yuv420 as u8 }, { Yuy2Description::YVYU as usize }>(
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.
Expand All @@ -213,10 +219,11 @@ pub fn yuv444_to_vyuy422_p16(
packed_image: &mut YuvPackedImageMut<u16>,
planar_image: &YuvPlanarImage<u16>,
) -> Result<(), YuvError> {
yuv_to_yuy2_impl::<u16, { YuvChromaSubsampling::Yuv444 as u8 }, { Yuy2Description::VYUY as usize }>(
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.
Expand All @@ -240,10 +247,11 @@ pub fn yuv422_to_vyuy422_p16(
packed_image: &mut YuvPackedImageMut<u16>,
planar_image: &YuvPlanarImage<u16>,
) -> Result<(), YuvError> {
yuv_to_yuy2_impl::<u16, { YuvChromaSubsampling::Yuv422 as u8 }, { Yuy2Description::VYUY as usize }>(
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.
Expand All @@ -267,10 +275,11 @@ pub fn yuv420_to_vyuy422_p16(
packed_image: &mut YuvPackedImageMut<u16>,
planar_image: &YuvPlanarImage<u16>,
) -> Result<(), YuvError> {
yuv_to_yuy2_impl::<u16, { YuvChromaSubsampling::Yuv420 as u8 }, { Yuy2Description::VYUY as usize }>(
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.
Expand All @@ -294,10 +303,11 @@ pub fn yuv444_to_uyvy422_p16(
packed_image: &mut YuvPackedImageMut<u16>,
planar_image: &YuvPlanarImage<u16>,
) -> Result<(), YuvError> {
yuv_to_yuy2_impl::<u16, { YuvChromaSubsampling::Yuv444 as u8 }, { Yuy2Description::UYVY as usize }>(
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.
Expand All @@ -321,10 +331,11 @@ pub fn yuv422_to_uyvy422_p16(
packed_image: &mut YuvPackedImageMut<u16>,
planar_image: &YuvPlanarImage<u16>,
) -> Result<(), YuvError> {
yuv_to_yuy2_impl::<u16, { YuvChromaSubsampling::Yuv422 as u8 }, { Yuy2Description::UYVY as usize }>(
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.
Expand All @@ -348,8 +359,9 @@ pub fn yuv420_to_uyvy422_p16(
packed_image: &mut YuvPackedImageMut<u16>,
planar_image: &YuvPlanarImage<u16>,
) -> Result<(), YuvError> {
yuv_to_yuy2_impl::<u16, { YuvChromaSubsampling::Yuv420 as u8 }, { Yuy2Description::UYVY as usize }>(
planar_image,
packed_image,
)
yuv_to_yuy2_impl::<
u16,
{ YuvChromaSubsampling::Yuv420 as u8 },
{ Yuy2Description::UYVY as usize },
>(planar_image, packed_image)
}

0 comments on commit c052ef0

Please sign in to comment.