Skip to content

Commit

Permalink
Merge pull request #62 from awxkee/dev
Browse files Browse the repository at this point in the history
YCgCo improvements
  • Loading branch information
awxkee authored Feb 5, 2025
2 parents 825f5b2 + 2bc20c1 commit 4c07fce
Show file tree
Hide file tree
Showing 13 changed files with 1,337 additions and 321 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.

7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ workspace = { members = ["app", "fuzz"] }

[package]
name = "yuvutils-rs"
version = "0.7.0"
version = "0.8.0"
edition = "2021"
description = "High performance utilities for YUV format handling and conversion."
readme = "README.md"
Expand All @@ -19,7 +19,7 @@ rust-version = "1.82.0"
[dependencies]
num-traits = "0.2.19"
rayon = { version = "1.10.0", optional = true }
fast_transpose = "0.2.3"
fast_transpose = { version = "0.2.3", optional = true }

[dev-dependencies]
rand = "0.9.0"
Expand Down Expand Up @@ -48,10 +48,11 @@ nightly_i8mm = []
fast_mode = []
# Enables `professional_mode` support on available paths
professional_mode = []
# Enables `rayon` support, use with care, in common, YUV encoding/decoding is more usually used in single thread mode
# Enables `rayon` support, use with care, in common, YUV encoding/decoding is more usually expected to be used in single thread mode
rayon = ["dep:rayon"]
# Support for Big-Endian YUV
big_endian = []
geometry = ["dep:fast_transpose"]
rdp = []

[profile.dev.package]
Expand Down
28 changes: 28 additions & 0 deletions app/benches/yuv8/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -749,6 +749,34 @@ pub fn criterion_benchmark(c: &mut Criterion) {
})
});

c.bench_function("yuvutils YCgCo 4:2:2 Full -> RGBA", |b| {
let mut rgb_bytes = vec![0u8; dimensions.0 as usize * 4 * dimensions.1 as usize];
b.iter(|| {
yuv422_to_rgba(
&fixed_planar422,
&mut rgb_bytes,
dimensions.0 * 4u32,
YuvRange::Full,
YuvStandardMatrix::Bt601,
)
.unwrap();
})
});

c.bench_function("yuvutils YCgCo 4:2:2 Limited -> RGBA", |b| {
let mut rgb_bytes = vec![0u8; dimensions.0 as usize * 4 * dimensions.1 as usize];
b.iter(|| {
yuv422_to_rgba(
&fixed_planar422,
&mut rgb_bytes,
dimensions.0 * 4u32,
YuvRange::Limited,
YuvStandardMatrix::Bt601,
)
.unwrap();
})
});

c.bench_function("libyuv YUV 4:2:2 -> RGBA", |b| {
let mut rgb_bytes = vec![0u8; dimensions.0 as usize * 4 * dimensions.1 as usize];
b.iter(|| unsafe {
Expand Down
30 changes: 26 additions & 4 deletions app/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,17 @@ use image::{ColorType, DynamicImage, EncodableLayout, GenericImageView, ImageRea
use std::fs::File;
use std::io::Read;
use std::time::Instant;
use yuvutils_rs::{rdp_rgba_to_yuv444, rdp_yuv444_to_rgba, YuvBiPlanarImageMut, YuvChromaSubsampling, YuvPlanarImageMut};
use yuvutils_rs::{
ar30_to_rgb8, i010_to_rgb10, i010_to_rgb_f16, i012_to_rgb12, i014_to_rgb14, i016_to_rgb16,
i210_to_rgb10, i210_to_rgb_f16, i210_to_rgba_f16, i214_to_rgb14, i214_to_rgb_f16,
i214_to_rgba14, i216_to_rgb16, i410_to_rgb10, i410_to_rgb_f16, i410_to_rgba10, i414_to_rgb14,
i414_to_rgb_f16, i416_to_rgb16, p210_to_ar30, p212_to_ar30, rgb10_to_i010, rgb10_to_i210,
rgb10_to_i410, rgb10_to_p210, rgb12_to_i012, rgb12_to_p212, rgb14_to_i014, rgb14_to_i214,
rgb14_to_i414, rgb16_to_i016, rgb16_to_i216, rgb16_to_i416, rgb_to_ycgco420, rgb_to_ycgco422,
rgb_to_ycgco444, rgba14_to_i214, rgba_to_ycgco420, ycgco420_to_rgb, ycgco420_to_rgba,
ycgco422_to_rgb, ycgco444_to_rgb, ycgco444_to_rgba, Rgb30ByteOrder, YuvBiPlanarImageMut,
YuvChromaSubsampling, YuvPlanarImageMut, YuvRange, YuvStandardMatrix,
};

fn read_file_bytes(file_path: &str) -> Result<Vec<u8>, String> {
// Open the file
Expand Down Expand Up @@ -93,27 +103,39 @@ fn main() {
);

let mut planar_image =
YuvPlanarImageMut::<i16>::alloc(width as u32, height as u32, YuvChromaSubsampling::Yuv444);
YuvPlanarImageMut::<u8>::alloc(width as u32, height as u32, YuvChromaSubsampling::Yuv420);
//
let mut bytes_16: Vec<u16> = src_bytes
.iter()
.map(|&x| ((x as u16) << 4) | ((x as u16) >> 4))
.collect();

let start_time = Instant::now();
rdp_rgba_to_yuv444(&mut planar_image, src_bytes, rgba_stride as u32).unwrap();
rgba_to_ycgco420(
&mut planar_image,
&src_bytes,
rgba_stride as u32,
YuvRange::Full,
)
.unwrap();

println!("Forward time: {:?}", start_time.elapsed());
let fixed = planar_image.to_fixed();
rgba.fill(0);
rdp_yuv444_to_rgba(&fixed, &mut rgba, rgba_stride as u32).unwrap();

let fixed_biplanar = bi_planar_image.to_fixed();
let fixed_planar = planar_image.to_fixed();
// bytes_16.fill(0);

let mut j_rgba = vec![0u8; dimensions.0 as usize * dimensions.1 as usize * 4];

ycgco420_to_rgba(
&fixed_planar,
&mut rgba,
dimensions.0 as u32 * 4,
YuvRange::Full,
)
.unwrap();
// let mut rgba_f16: Vec<f16> = vec![0.; rgba.len()];
// //
// i210_to_rgb_f16(
Expand Down
39 changes: 36 additions & 3 deletions fuzz/yuv_to_rgb/yuv_to_rgb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@

use libfuzzer_sys::fuzz_target;
use yuvutils_rs::{
yuv420_alpha_to_rgba, yuv420_to_rgb, yuv420_to_rgba, yuv422_alpha_to_rgba, yuv422_to_rgb,
yuv422_to_rgba, yuv444_alpha_to_rgba, yuv444_to_rgb, yuv444_to_rgba, YuvPlanarImage,
YuvPlanarImageWithAlpha, YuvRange, YuvStandardMatrix,
ycgco420_to_rgb, ycgco420_to_rgba, ycgco422_to_rgb, ycgco422_to_rgba, yuv420_alpha_to_rgba,
yuv420_to_rgb, yuv420_to_rgba, yuv422_alpha_to_rgba, yuv422_to_rgb, yuv422_to_rgba,
yuv444_alpha_to_rgba, yuv444_to_rgb, yuv444_to_rgba, YuvPlanarImage, YuvPlanarImageWithAlpha,
YuvRange, YuvStandardMatrix,
};

fuzz_target!(|data: (u8, u8, u8, u8, u8, u8)| {
Expand Down Expand Up @@ -73,6 +74,14 @@ fn fuzz_yuv_420(i_width: u8, i_height: u8, y_value: u8, u_value: u8, v_value: u8
)
.unwrap();

ycgco420_to_rgb(
&planar_image,
&mut target_rgb,
i_width as u32 * 3,
YuvRange::Full,
)
.unwrap();

let mut target_rgba = vec![0u8; i_width as usize * i_height as usize * 4];

yuv420_to_rgba(
Expand All @@ -84,6 +93,14 @@ fn fuzz_yuv_420(i_width: u8, i_height: u8, y_value: u8, u_value: u8, v_value: u8
)
.unwrap();

ycgco420_to_rgba(
&planar_image,
&mut target_rgba,
i_width as u32 * 4,
YuvRange::Full,
)
.unwrap();

let planar_image_with_alpha = YuvPlanarImageWithAlpha {
y_plane: &y_plane,
y_stride: i_width as u32,
Expand Down Expand Up @@ -139,6 +156,14 @@ fn fuzz_yuv_422(i_width: u8, i_height: u8, y_value: u8, u_value: u8, v_value: u8
)
.unwrap();

ycgco422_to_rgb(
&planar_image,
&mut target_rgb,
i_width as u32 * 3,
YuvRange::Full,
)
.unwrap();

let mut target_rgba = vec![0u8; i_width as usize * i_height as usize * 4];

yuv422_to_rgba(
Expand All @@ -150,6 +175,14 @@ fn fuzz_yuv_422(i_width: u8, i_height: u8, y_value: u8, u_value: u8, v_value: u8
)
.unwrap();

ycgco422_to_rgba(
&planar_image,
&mut target_rgba,
i_width as u32 * 4,
YuvRange::Full,
)
.unwrap();

let planar_image_with_alpha = YuvPlanarImageWithAlpha {
y_plane: &y_plane,
y_stride: i_width as u32,
Expand Down
15 changes: 9 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,11 @@ mod built_coefficients;
mod f16_converter;
mod from_identity;
mod from_identity_alpha;
#[cfg(feature = "geometry")]
mod geometry;
mod images;
mod internals;
#[cfg(feature = "geometry")]
mod mirroring;
#[cfg(all(target_arch = "aarch64", target_feature = "neon"))]
mod neon;
Expand Down Expand Up @@ -272,9 +274,9 @@ pub use ycgco_to_rgb::{
};

pub use ycgco_to_rgb::{
icgc010_to_rgb, icgc010_to_rgba, icgc012_to_rgb, icgc012_to_rgba, icgc210_to_rgb,
icgc210_to_rgba, icgc212_to_rgb, icgc212_to_rgba, icgc410_to_rgb, icgc410_to_rgba,
icgc412_to_rgb, icgc412_to_rgba,
icgc010_to_rgb10, icgc010_to_rgba10, icgc012_to_rgb12, icgc012_to_rgba12, icgc210_to_rgb10,
icgc210_to_rgba10, icgc212_to_rgb12, icgc212_to_rgba12, icgc410_to_rgb10, icgc410_to_rgba10,
icgc412_to_rgb12, icgc412_to_rgba12,
};

pub use yuv_nv_to_rgba::yuv_nv16_to_bgr;
Expand All @@ -292,8 +294,8 @@ pub use ycgco_to_rgb_alpha::{
};

pub use ycgco_to_rgb_alpha::{
icgc010_alpha_to_rgba, icgc012_alpha_to_rgba, icgc210_alpha_to_rgba, icgc212_alpha_to_rgba,
icgc410_alpha_to_rgba, icgc412_alpha_to_rgba,
icgc010_alpha_to_rgba10, icgc012_alpha_to_rgba12, icgc210_alpha_to_rgba10,
icgc212_alpha_to_rgba12, icgc410_alpha_to_rgba10, icgc412_alpha_to_rgba12,
};

pub use yuv_to_yuy2::yuv420_to_uyvy422;
Expand Down Expand Up @@ -475,11 +477,12 @@ pub use f16_converter::{
convert_rgba_f16_to_rgba16, convert_rgba_to_f16,
};

#[cfg(feature = "geometry")]
pub use geometry::{
rotate_cbcr, rotate_cbcr16, rotate_plane, rotate_plane16, rotate_rgb, rotate_rgb16,
rotate_rgba, rotate_rgba16, RotationMode,
};

#[cfg(feature = "geometry")]
pub use mirroring::{
mirror_cbcr, mirror_cbcr16, mirror_plane, mirror_plane16, mirror_rgb, mirror_rgb16,
mirror_rgba, mirror_rgba16, MirrorMode,
Expand Down
2 changes: 2 additions & 0 deletions src/neon/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ mod utils;
mod y_p16_to_rgba16;
mod y_to_rgb;
mod y_to_rgb_alpha;
mod ycgco_to_rgb;
mod yuv_nv_p10_to_ar30;
mod yuv_nv_p10_to_rgba;
#[cfg(feature = "professional_mode")]
Expand Down Expand Up @@ -161,6 +162,7 @@ pub(crate) use y_to_rgb::neon_y_to_rgb_row_rdm;
pub(crate) use y_to_rgb_alpha::neon_y_to_rgb_alpha_row;
#[cfg(feature = "rdm")]
pub(crate) use y_to_rgb_alpha::neon_y_to_rgb_row_alpha_rdm;
pub(crate) use ycgco_to_rgb::{neon_ycgco420_to_rgba_row, neon_ycgco_full_range_to_rgb};
pub(crate) use yuv_nv_p10_to_ar30::neon_yuv_nv12_p10_to_ar30_row;
pub(crate) use yuv_nv_p10_to_rgba::neon_yuv_nv12_p10_to_rgba_row;
#[cfg(feature = "professional_mode")]
Expand Down
Loading

0 comments on commit 4c07fce

Please sign in to comment.