Skip to content

Commit

Permalink
NEON, bi-planar to RGB16
Browse files Browse the repository at this point in the history
  • Loading branch information
awxkee committed Sep 1, 2024
1 parent f37de07 commit f377653
Show file tree
Hide file tree
Showing 16 changed files with 951 additions and 623 deletions.
6 changes: 3 additions & 3 deletions app/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::io::Read;
use std::ops::Sub;
use std::time::Instant;

use yuvutils_rs::{rgb_to_yuv_nv12_p16, yuv_nv12_p10_to_rgb, yuv_nv12_to_rgb_p16, YuvBytesPacking, YuvEndiannes, YuvRange, YuvStandardMatrix};
use yuvutils_rs::{rgb_to_yuv_nv12_p16, yuv_nv12_p10_to_rgb, yuv_nv12_to_rgb_p16, YuvBytesPacking, YuvEndianness, YuvRange, YuvStandardMatrix};

fn read_file_bytes(file_path: &str) -> Result<Vec<u8>, String> {
// Open the file
Expand Down Expand Up @@ -68,7 +68,7 @@ fn main() {
height,
YuvRange::Full,
YuvStandardMatrix::Bt709,
YuvEndiannes::BigEndian,
YuvEndianness::BigEndian,
YuvBytesPacking::LeastSignificantBytes,
);
bytes_16.fill(0);
Expand All @@ -90,7 +90,7 @@ fn main() {
height,
YuvRange::Full,
YuvStandardMatrix::Bt709,
YuvEndiannes::BigEndian,
YuvEndianness::BigEndian,
YuvBytesPacking::LeastSignificantBytes,
);
// yuv_nv12_p10_to_rgb(
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ mod yuv_to_yuy2;
mod yuy2_to_yuv;

pub use yuv_support::YuvBytesPacking;
pub use yuv_support::YuvEndiannes;
pub use yuv_support::YuvEndianness;
pub use yuv_support::YuvRange;
pub use yuv_support::YuvStandardMatrix;

Expand Down
10 changes: 5 additions & 5 deletions src/neon/rgb_to_yuv_p10.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::internals::ProcessedOffset;
use crate::yuv_support::{
CbCrForwardTransform, YuvChromaRange, YuvChromaSample, YuvSourceChannels,
};
use crate::{YuvBytesPacking, YuvEndiannes};
use crate::{YuvBytesPacking, YuvEndianness};
use std::arch::aarch64::*;

pub unsafe fn neon_rgba_to_yuv_p10<
Expand All @@ -30,7 +30,7 @@ pub unsafe fn neon_rgba_to_yuv_p10<
) -> ProcessedOffset {
let chroma_subsampling: YuvChromaSample = SAMPLING.into();
let source_channels: YuvSourceChannels = ORIGIN_CHANNELS.into();
let endianness: YuvEndiannes = ENDIANNESS.into();
let endianness: YuvEndianness = ENDIANNESS.into();
let bytes_position: YuvBytesPacking = BYTES_POSITION.into();
let channels = source_channels.get_channels_count();

Expand Down Expand Up @@ -162,7 +162,7 @@ pub unsafe fn neon_rgba_to_yuv_p10<
y_vl = vshlq_u16(y_vl, v_shift_count);
}

if endianness == YuvEndiannes::BigEndian {
if endianness == YuvEndianness::BigEndian {
y_vl = vreinterpretq_u16_u8(vrev16q_u8(vreinterpretq_u8_u16(y_vl)));
}

Expand All @@ -178,7 +178,7 @@ pub unsafe fn neon_rgba_to_yuv_p10<
cr_s = vshl_u16(cr_s, vget_low_s16(v_shift_count));
}

if endianness == YuvEndiannes::BigEndian {
if endianness == YuvEndianness::BigEndian {
cb_s = vreinterpret_u16_u8(vrev16_u8(vreinterpret_u8_u16(cb_s)));
cr_s = vreinterpret_u16_u8(vrev16_u8(vreinterpret_u8_u16(cr_s)));
}
Expand All @@ -194,7 +194,7 @@ pub unsafe fn neon_rgba_to_yuv_p10<
cr_vl = vshlq_u16(cr_vl, v_shift_count);
}

if endianness == YuvEndiannes::BigEndian {
if endianness == YuvEndianness::BigEndian {
cb_vl = vreinterpretq_u16_u8(vrev16q_u8(vreinterpretq_u8_u16(cb_vl)));
cr_vl = vreinterpretq_u16_u8(vrev16q_u8(vreinterpretq_u8_u16(cr_vl)));
}
Expand Down
14 changes: 7 additions & 7 deletions src/neon/yuv_nv_p10_to_rgba.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::arch::aarch64::*;

use crate::internals::ProcessedOffset;
use crate::yuv_support::{
CbCrInverseTransform, YuvBytesPacking, YuvChromaRange, YuvChromaSample, YuvEndiannes, YuvNVOrder,
CbCrInverseTransform, YuvBytesPacking, YuvChromaRange, YuvChromaSample, YuvEndianness, YuvNVOrder,
YuvSourceChannels,
};

Expand All @@ -35,7 +35,7 @@ pub unsafe fn neon_yuv_nv12_p10_to_rgba_row<
let channels = destination_channels.get_channels_count();
let uv_order: YuvNVOrder = NV_ORDER.into();
let chroma_subsampling: YuvChromaSample = SAMPLING.into();
let endianness: YuvEndiannes = ENDIANNESS.into();
let endianness: YuvEndianness = ENDIANNESS.into();
let bytes_position: YuvBytesPacking = BYTES_POSITION.into();
let dst_ptr = bgra.as_mut_ptr();
let cr_coef = transform.cr_coef;
Expand Down Expand Up @@ -70,7 +70,7 @@ pub unsafe fn neon_yuv_nv12_p10_to_rgba_row<
let v_low: int16x4_t;

let mut y_vl = vld1q_u16(y_ld_ptr.add(cx));
if endianness == YuvEndiannes::BigEndian {
if endianness == YuvEndianness::BigEndian {
y_vl = vreinterpretq_u16_u8(vrev16q_u8(vreinterpretq_u8_u16(y_vl)));
}
if bytes_position == YuvBytesPacking::MostSignificantBytes {
Expand All @@ -87,11 +87,11 @@ pub unsafe fn neon_yuv_nv12_p10_to_rgba_row<
}

let mut u_vl = uv_values_u.0;
if endianness == YuvEndiannes::BigEndian {
if endianness == YuvEndianness::BigEndian {
u_vl = vreinterpret_u16_u8(vrev16_u8(vreinterpret_u8_u16(u_vl)));
}
let mut v_vl = uv_values_u.1;
if endianness == YuvEndiannes::BigEndian {
if endianness == YuvEndianness::BigEndian {
v_vl = vreinterpret_u16_u8(vrev16_u8(vreinterpret_u8_u16(v_vl)));
}
if bytes_position == YuvBytesPacking::MostSignificantBytes {
Expand All @@ -113,11 +113,11 @@ pub unsafe fn neon_yuv_nv12_p10_to_rgba_row<
uv_values_u = uint16x8x2_t(uv_values_u.1, uv_values_u.0);
}
let mut u_vl = uv_values_u.0;
if endianness == YuvEndiannes::BigEndian {
if endianness == YuvEndianness::BigEndian {
u_vl = vreinterpretq_u16_u8(vrev16q_u8(vreinterpretq_u8_u16(u_vl)));
}
let mut v_vl = uv_values_u.1;
if endianness == YuvEndiannes::BigEndian {
if endianness == YuvEndianness::BigEndian {
v_vl = vreinterpretq_u16_u8(vrev16q_u8(vreinterpretq_u8_u16(v_vl)));
}
if bytes_position == YuvBytesPacking::MostSignificantBytes {
Expand Down
16 changes: 8 additions & 8 deletions src/neon/yuv_nv_p16_to_rgb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::arch::aarch64::*;

use crate::internals::ProcessedOffset;
use crate::yuv_support::{
CbCrInverseTransform, YuvBytesPacking, YuvChromaRange, YuvChromaSample, YuvEndiannes,
CbCrInverseTransform, YuvBytesPacking, YuvChromaRange, YuvChromaSample, YuvEndianness,
YuvNVOrder, YuvSourceChannels,
};

Expand All @@ -34,7 +34,7 @@ pub unsafe fn neon_yuv_nv_p16_to_rgba_row<
let channels = destination_channels.get_channels_count();
let uv_order: YuvNVOrder = NV_ORDER.into();
let chroma_subsampling: YuvChromaSample = SAMPLING.into();
let endianness: YuvEndiannes = ENDIANNESS.into();
let endianness: YuvEndianness = ENDIANNESS.into();
let bytes_position: YuvBytesPacking = BYTES_POSITION.into();
let cr_coef = transform.cr_coef;
let cb_coef = transform.cb_coef;
Expand All @@ -47,7 +47,7 @@ pub unsafe fn neon_yuv_nv_p16_to_rgba_row<

let mut dst_ptr = bgra;

let v_max_colors = vdupq_n_u16(1u16 << BIT_DEPTH as u16);
let v_max_colors = vdupq_n_u16((1u16 << BIT_DEPTH as u16) - 1);

let y_corr = vdupq_n_s16(bias_y as i16);
let uv_corr = vdup_n_s16(bias_uv as i16);
Expand All @@ -73,7 +73,7 @@ pub unsafe fn neon_yuv_nv_p16_to_rgba_row<
let v_low: int16x4_t;

let mut y_vl = vld1q_u16(y_ld_ptr.add(cx));
if endianness == YuvEndiannes::BigEndian {
if endianness == YuvEndianness::BigEndian {
y_vl = vreinterpretq_u16_u8(vrev16q_u8(vreinterpretq_u8_u16(y_vl)));
}
if bytes_position == YuvBytesPacking::MostSignificantBytes {
Expand All @@ -90,11 +90,11 @@ pub unsafe fn neon_yuv_nv_p16_to_rgba_row<
}

let mut u_vl = uv_values_u.0;
if endianness == YuvEndiannes::BigEndian {
if endianness == YuvEndianness::BigEndian {
u_vl = vreinterpret_u16_u8(vrev16_u8(vreinterpret_u8_u16(u_vl)));
}
let mut v_vl = uv_values_u.1;
if endianness == YuvEndiannes::BigEndian {
if endianness == YuvEndianness::BigEndian {
v_vl = vreinterpret_u16_u8(vrev16_u8(vreinterpret_u8_u16(v_vl)));
}
if bytes_position == YuvBytesPacking::MostSignificantBytes {
Expand All @@ -116,11 +116,11 @@ pub unsafe fn neon_yuv_nv_p16_to_rgba_row<
uv_values_u = uint16x8x2_t(uv_values_u.1, uv_values_u.0);
}
let mut u_vl = uv_values_u.0;
if endianness == YuvEndiannes::BigEndian {
if endianness == YuvEndianness::BigEndian {
u_vl = vreinterpretq_u16_u8(vrev16q_u8(vreinterpretq_u8_u16(u_vl)));
}
let mut v_vl = uv_values_u.1;
if endianness == YuvEndiannes::BigEndian {
if endianness == YuvEndianness::BigEndian {
v_vl = vreinterpretq_u16_u8(vrev16q_u8(vreinterpretq_u8_u16(v_vl)));
}
if bytes_position == YuvBytesPacking::MostSignificantBytes {
Expand Down
8 changes: 4 additions & 4 deletions src/neon/yuv_p10_to_rgba.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::arch::aarch64::*;

use crate::internals::ProcessedOffset;
use crate::yuv_support::{
CbCrInverseTransform, YuvBytesPacking, YuvChromaRange, YuvChromaSample, YuvEndiannes,
CbCrInverseTransform, YuvBytesPacking, YuvChromaRange, YuvChromaSample, YuvEndianness,
YuvSourceChannels,
};

Expand All @@ -34,7 +34,7 @@ pub unsafe fn neon_yuv_p10_to_rgba_row<
let destination_channels: YuvSourceChannels = DESTINATION_CHANNELS.into();
let channels = destination_channels.get_channels_count();
let chroma_subsampling: YuvChromaSample = SAMPLING.into();
let endianness: YuvEndiannes = ENDIANNESS.into();
let endianness: YuvEndianness = ENDIANNESS.into();
let bytes_position: YuvBytesPacking = BYTES_POSITION.into();
let dst_ptr = rgba.as_mut_ptr();

Expand All @@ -61,7 +61,7 @@ pub unsafe fn neon_yuv_p10_to_rgba_row<
let v_values_l = vld1_u16(v_ld_ptr.add(ux));

match endianness {
YuvEndiannes::BigEndian => {
YuvEndianness::BigEndian => {
let mut y_u_values = vreinterpretq_u16_u8(vrev16q_u8(vreinterpretq_u8_u16(
vld1q_u16(y_ld_ptr.add(cx)),
)));
Expand All @@ -79,7 +79,7 @@ pub unsafe fn neon_yuv_p10_to_rgba_row<
u_values_c = vsub_s16(vreinterpret_s16_u16(u_v), uv_corr);
v_values_c = vsub_s16(vreinterpret_s16_u16(v_v), uv_corr);
}
YuvEndiannes::LittleEndian => {
YuvEndianness::LittleEndian => {
let mut y_vl = vld1q_u16(y_ld_ptr.add(cx));
if bytes_position == YuvBytesPacking::MostSignificantBytes {
y_vl = vshrq_n_u16::<6>(y_vl);
Expand Down
Loading

0 comments on commit f377653

Please sign in to comment.