Skip to content

Commit

Permalink
YCgCo refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
awxkee committed Feb 3, 2025
1 parent b796596 commit 7ee727c
Show file tree
Hide file tree
Showing 21 changed files with 323 additions and 2,263 deletions.
32 changes: 18 additions & 14 deletions app/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,16 @@ use image::{ColorType, DynamicImage, EncodableLayout, GenericImageView, ImageRea
use std::fs::File;
use std::io::Read;
use std::time::Instant;
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, rgba14_to_i214, Rgb30ByteOrder, YuvBiPlanarImageMut, YuvChromaSubsampling, YuvPlanarImageMut, YuvRange, YuvStandardMatrix};
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_ycgco444, rgba14_to_i214,
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 @@ -94,20 +103,19 @@ fn main() {
);

let mut planar_image =
YuvPlanarImageMut::<u16>::alloc(width as u32, height as u32, YuvChromaSubsampling::Yuv444);
YuvPlanarImageMut::<u8>::alloc(width as u32, height as u32, YuvChromaSubsampling::Yuv444);
//
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();
rgb12_to_p212(
&mut bi_planar_image,
&bytes_16,
rgb_to_ycgco444(
&mut planar_image,
&src_bytes,
rgba_stride as u32,
YuvRange::Limited,
YuvStandardMatrix::Bt709,
)
.unwrap();

Expand Down Expand Up @@ -200,18 +208,14 @@ fn main() {

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

p212_to_ar30(
&fixed_biplanar,
&mut j_rgba,
dimensions.0 as u32 * 4,
Rgb30ByteOrder::Host,
ycgco444_to_rgb(
&fixed_planar,
&mut rgba,
dimensions.0 as u32 * 3,
YuvRange::Limited,
YuvStandardMatrix::Bt709,
)
.unwrap();

ar30_to_rgb8(&j_rgba,dimensions.0 as u32 * 4, Rgb30ByteOrder::Host, &mut rgba, dimensions.0 as u32 * 3, dimensions.0, dimensions.1 ).unwrap();

// let a_plane = vec![1023u16; width as usize * height as usize];
// let planar_with_alpha = YuvPlanarImageWithAlpha {
// y_plane: planar_image.y_plane.borrow(),
Expand Down
9 changes: 0 additions & 9 deletions src/avx2/avx2_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,15 +336,6 @@ pub(crate) unsafe fn avx2_deinterleave_rgb(
// _mm256_permute4x64_epi64::<MASK>(v)
// }

#[inline(always)]
pub(crate) unsafe fn avx2_pairwise_widen_avg(v: __m256i) -> __m256i {
let sums = _mm256_maddubs_epi16(v, _mm256_set1_epi8(1));
let shifted = _mm256_srli_epi16::<1>(_mm256_add_epi16(sums, _mm256_set1_epi16(1)));
let packed_lo = _mm256_packus_epi16(shifted, shifted);
const MASK: i32 = shuffle(3, 1, 2, 0);
_mm256_permute4x64_epi64::<MASK>(packed_lo)
}

#[inline(always)]
pub(crate) unsafe fn avx_pairwise_avg_epi16(a: __m256i, b: __m256i) -> __m256i {
let sums = _mm256_hadd_epi16(a, b);
Expand Down
120 changes: 0 additions & 120 deletions src/avx2/avx2_ycgco.rs

This file was deleted.

5 changes: 0 additions & 5 deletions src/avx2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
*/
#![deny(unreachable_code, unreachable_pub)]
mod avx2_utils;
mod avx2_ycgco;
#[cfg(feature = "nightly_f16")]
mod f16_converter;
mod gbr_to_rgb;
Expand All @@ -39,7 +38,6 @@ mod rgb_to_nv420_prof;
#[cfg(feature = "professional_mode")]
mod rgb_to_nv_prof;
mod rgb_to_y;
mod rgb_to_ycgco;
#[cfg(feature = "professional_mode")]
mod rgb_to_yuv420_prof;
mod rgb_to_yuv_p16;
Expand All @@ -61,7 +59,6 @@ mod rgba_to_yuv_fast420;
mod shuffle;
mod y_to_rgba;
mod y_to_rgba_alpha;
mod ycgco_to_rgb;
mod ycgco_to_rgba_alpha;
mod yuv_nv_to_rgba;
mod yuv_nv_to_rgba420;
Expand Down Expand Up @@ -101,7 +98,6 @@ pub(crate) use rgb_to_nv420_prof::avx2_rgba_to_nv420_prof;
#[cfg(feature = "professional_mode")]
pub(crate) use rgb_to_nv_prof::avx2_rgba_to_nv_prof;
pub(crate) use rgb_to_y::avx2_rgb_to_y_row;
pub(crate) use rgb_to_ycgco::avx2_rgb_to_ycgco_row;
#[cfg(feature = "professional_mode")]
pub(crate) use rgb_to_yuv420_prof::avx2_rgba_to_yuv420_prof;
pub(crate) use rgb_to_yuv_p16::avx_rgba_to_yuv_p16;
Expand All @@ -123,7 +119,6 @@ pub(crate) use rgba_to_yuv_fast420::avx2_rgba_to_yuv_dot_rgba420;
pub(crate) use shuffle::{ShuffleConverterAvx2, ShuffleQTableConverterAvx2};
pub(crate) use y_to_rgba::avx2_y_to_rgba_row;
pub(crate) use y_to_rgba_alpha::avx2_y_to_rgba_alpha_row;
pub(crate) use ycgco_to_rgb::avx2_ycgco_to_rgb_row;
pub(crate) use ycgco_to_rgba_alpha::avx2_ycgco_to_rgba_alpha;
pub(crate) use yuv_nv_to_rgba::avx2_yuv_nv_to_rgba_row;
pub(crate) use yuv_nv_to_rgba420::avx2_yuv_nv_to_rgba_row420;
Expand Down
Loading

0 comments on commit 7ee727c

Please sign in to comment.