Skip to content

Commit

Permalink
Merge pull request #22 from awxkee/dev
Browse files Browse the repository at this point in the history
YUY2 bugfixes
  • Loading branch information
awxkee authored Dec 10, 2024
2 parents 480c89a + ffd400f commit 160bd37
Show file tree
Hide file tree
Showing 31 changed files with 843 additions and 342 deletions.
19 changes: 17 additions & 2 deletions .github/workflows/build_push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,20 @@ jobs:
- run: RUSTFLAGS="-C target-feature=+avx2" cargo build --target i686-unknown-linux-gnu
- run: cargo build --target powerpc-unknown-linux-gnu
- run: RUSTFLAGS="-C target-feature=+avx2" cargo build --features "nightly_avx512" --target x86_64-unknown-linux-gnu
- name: Test release pipeline
run: cargo publish --dry-run

fuzz_decoding:
name: Fuzzing decoders
strategy:
matrix:
os: [ ubuntu-latest, macos-latest ]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@nightly
- run: cargo install cargo-fuzz
- run: cargo fuzz run yuv_to_rgb -- -max_total_time=15
- run: cargo fuzz run yuv_nv_to_rgb -- -max_total_time=15
- run: cargo fuzz run y_to_rgb -- -max_total_time=15
- run: cargo fuzz run yuv16_to_rgb16 -- -max_total_time=15
- run: cargo fuzz run y16_to_rgb16 -- -max_total_time=15
- run: cargo fuzz run yuv_to_yuyu2 -- -max_total_time=15
43 changes: 1 addition & 42 deletions Cargo.lock

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

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

[package]
name = "yuvutils-rs"
version = "0.5.10"
version = "0.5.11"
edition = "2021"
description = "High performance utilities for YUV format handling and conversion."
readme = "README.md"
Expand Down
147 changes: 83 additions & 64 deletions app/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ use image::{ColorType, DynamicImage, EncodableLayout, GenericImageView, ImageRea
use std::fs::File;
use std::io::Read;
use std::time::Instant;
use yuv_sys::{rs_I420ToRGB24, rs_NV12ToRGB24, rs_NV21ToABGR, rs_NV21ToRGB24};
use yuv_sys::{rs_I420ToRGB24, rs_NV12ToRGB24, rs_NV21ToABGR, rs_NV21ToRGB24, rs_RGB24ToI420};
use yuvutils_rs::{
gbr_to_rgb, rgb_to_gbr, rgb_to_sharp_yuv420, rgb_to_yuv420, rgb_to_yuv420_p16, rgb_to_yuv422,
rgb_to_yuv422_p16, rgb_to_yuv444, rgb_to_yuv_nv12, yuv420_p16_to_rgb16, yuv420_to_rgb,
yuv420_to_yuyv422, yuv422_p16_to_rgb16, yuv422_to_rgb, yuv444_to_rgb, yuv_nv12_to_rgb,
yuv_nv12_to_rgba, yuyv422_to_yuv420, BufferStoreMut, SharpYuvGammaTransfer,
yuv_nv12_to_rgba, yuyv422_to_rgb, yuyv422_to_yuv420, BufferStoreMut, SharpYuvGammaTransfer,
YuvBiPlanarImageMut, YuvBytesPacking, YuvChromaSubsampling, YuvEndianness, YuvPackedImage,
YuvPackedImageMut, YuvPlanarImageMut, YuvRange, YuvStandardMatrix,
};
Expand Down Expand Up @@ -113,7 +113,7 @@ fn main() {
// println!("rgb_to_yuv_nv12 time: {:?}", start_time.elapsed());
//
println!("Forward time: {:?}", start_time.elapsed());
// // //
// // // //
let full_size = if width % 2 == 0 {
2 * width as usize * height as usize
} else {
Expand All @@ -128,53 +128,47 @@ fn main() {
2 * (width as usize + 1)
};

// let mut yuy2_plane = vec![0u8; full_size];
let mut yuy2_plane = vec![0u8; full_size];
// // // //
// let start_time = Instant::now();
// // // //
// let plane = planar_image.to_fixed();
// //
// let mut packed_image_mut = YuvPackedImageMut {
// yuy: BufferStoreMut::Owned(yuy2_plane),
// yuy_stride: yuy2_stride as u32,
// width,
// height,
// };
let plane = planar_image.to_fixed();
// //
// yuv420_to_yuyv422(&mut packed_image_mut, &plane).unwrap();
let mut packed_image_mut = YuvPackedImageMut {
yuy: BufferStoreMut::Owned(yuy2_plane),
yuy_stride: yuy2_stride as u32,
width,
height,
};
//
yuv420_to_yuyv422(&mut packed_image_mut, &plane).unwrap();
// let end_time = Instant::now().sub(start_time);
// println!("yuv420_to_yuyv422 time: {:?}", end_time);
// // rgba.fill(0);
// // let start_time = Instant::now();
// yuyv422_to_rgb(
// &yuy2_plane,
// yuy2_stride as u32,
// &mut rgba,
// rgba_stride as u32,
// width,
// height,
// YuvRange::Limited,
// YuvStandardMatrix::Bt709,
// );
let yuy2_img = packed_image_mut.to_fixed();
yuyv422_to_rgb(
&yuy2_img,
&mut rgba,
rgba_stride as u32,
YuvRange::Limited,
YuvStandardMatrix::Bt601,
)
.unwrap();
//
// let end_time = Instant::now().sub(start_time);
// println!("yuyv422_to_rgb time: {:?}", end_time);

// let start_time = Instant::now();
// //
//
// let packed_image = YuvPackedImage {
// yuy: packed_image_mut.yuy.borrow(),
// yuy_stride: yuy2_stride as u32,
// width,
// height,
// };
// //
// yuyv422_to_yuv420(&mut planar_image, &packed_image).unwrap();
let packed_image = packed_image_mut.to_fixed();
//
yuyv422_to_yuv420(&mut planar_image, &packed_image).unwrap();
// // //
// let end_time = Instant::now().sub(start_time);
// println!("yuyv422_to_yuv444 time: {:?}", end_time);
rgba.fill(0);
// rgba.fill(0);
// let mut bgra = vec![0u8; width as usize * height as usize * 4];
// let start_time = Instant::now();
// yuv420_to_rgb(
Expand Down Expand Up @@ -241,7 +235,7 @@ fn main() {
// YuvBytesPacking::LeastSignificantBytes,
// )
// .unwrap();
rgba.fill(0);
// rgba.fill(0);
// ra30_to_rgb8(
// &ar30,
// width,
Expand All @@ -258,52 +252,77 @@ fn main() {
// let rgba_stride = width as usize * 4;
// let mut rgba = vec![0u8; height as usize * rgba_stride];

yuv420_to_rgb(
&fixed_planar,
&mut rgba,
rgba_stride as u32,
YuvRange::Limited,
YuvStandardMatrix::Bt601,
)
.unwrap();
// yuv420_to_rgb(
// &fixed_planar,
// &mut rgba,
// rgba_stride as u32,
// YuvRange::Limited,
// YuvStandardMatrix::Bt601,
// )
// .unwrap();

println!("Backward time: {:?}", start_time.elapsed());

let start_time = Instant::now();

// unsafe {
// // rs_I420ToRGB24(
// // fixed_planar.y_plane.as_ptr(),
// // fixed_planar.y_stride as i32,
// // fixed_planar.u_plane.as_ptr(),
// // fixed_planar.u_stride as i32,
// // fixed_planar.v_plane.as_ptr(),
// // fixed_planar.v_stride as i32,
// // rgba.as_mut_ptr(),
// // rgba_stride as i32,
// // fixed_planar.width as i32,
// // fixed_planar.height as i32,
// // );
// rs_NV12ToRGB24(
// fixed_biplanar.y_plane.as_ptr(),
// fixed_biplanar.y_stride as i32,
// fixed_biplanar.uv_plane.as_ptr(),
// fixed_biplanar.uv_stride as i32,
// let mut planar_image =
// YuvPlanarImageMut::<u8>::alloc(width as u32, height as u32, YuvChromaSubsampling::Yuv420);
//
// let mut source_bgr = vec![0u8; src_bytes.len()];
//
// rgba.chunks_exact(3).zip(source_bgr.chunks_exact_mut(3)).for_each(|(src, dst)| {
// let b = src[0];
// dst[0] = src[2];
// dst[1] = src[1];
// dst[2] = b;
// });
//
// rs_RGB24ToI420(
// src_bytes.as_ptr(),
// rgba_stride as i32,
// planar_image.y_plane.borrow_mut().as_mut_ptr(),
// planar_image.y_stride as i32,
// planar_image.u_plane.borrow_mut().as_mut_ptr(),
// planar_image.u_stride as i32,
// planar_image.v_plane.borrow_mut().as_mut_ptr(),
// planar_image.v_stride as i32,
// dimensions.0 as i32,
// dimensions.1 as i32,
// );
// let fixed_planar = planar_image.to_fixed();
// rs_I420ToRGB24(
// fixed_planar.y_plane.as_ptr(),
// fixed_planar.y_stride as i32,
// fixed_planar.u_plane.as_ptr(),
// fixed_planar.u_stride as i32,
// fixed_planar.v_plane.as_ptr(),
// fixed_planar.v_stride as i32,
// rgba.as_mut_ptr(),
// rgba_stride as i32,
// fixed_planar.width as i32,
// fixed_planar.height as i32,
// );
//
// // rgba.chunks_exact_mut(3).for_each(|chunk| {
// // let b = chunk[0];
// // chunk[0] = chunk[2];
// // chunk[2] = b;
// // });
// // rs_NV12ToRGB24(
// // fixed_biplanar.y_plane.as_ptr(),
// // fixed_biplanar.y_stride as i32,
// // fixed_biplanar.uv_plane.as_ptr(),
// // fixed_biplanar.uv_stride as i32,
// // rgba.as_mut_ptr(),
// // rgba_stride as i32,
// // fixed_planar.width as i32,
// // fixed_planar.height as i32,
// // );
// }

// / println!("Backward LIBYUV time: {:?}", start_time.elapsed());

// rgba.chunks_exact_mut(3).for_each(|chunk| {
// let b = chunk[0];
// chunk[0] = chunk[2];
// chunk[2] = b;
// });

// rgba = bytes_16.iter().map(|&x| (x >> 4) as u8).collect();

image::save_buffer(
Expand Down
21 changes: 21 additions & 0 deletions fuzz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,24 @@ path = "y_to_rgb/y_to_rgb.rs"
test = false
doc = false
bench = false

[[bin]]
name = "yuv16_to_rgb16"
path = "yuv16_to_rgb16/yuv16_to_rgb16.rs"
test = false
doc = false
bench = false

[[bin]]
name = "y16_to_rgb16"
path = "y16_to_rgb16/y16_to_rgb16.rs"
test = false
doc = false
bench = false

[[bin]]
name = "yuv_to_yuyu2"
path = "yuv_to_yuyu2/yuv_to_yuyu2.rs"
test = false
doc = false
bench = false
Loading

0 comments on commit 160bd37

Please sign in to comment.