Skip to content

Commit

Permalink
Added FAST conversion to HSV, HSL and BACK for NEON
Browse files Browse the repository at this point in the history
  • Loading branch information
awxkee committed Jun 8, 2024
1 parent 61077c6 commit 47590d9
Show file tree
Hide file tree
Showing 49 changed files with 3,049 additions and 203 deletions.
187 changes: 187 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ exclude = ["*.jpg"]

[dependencies]
half = "2.4.1"
clap = { version = "4.5.6", features = ["derive"] }

[features]
default = []
53 changes: 39 additions & 14 deletions src/app/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::arch::aarch64::{vdupq_n_f32, vdupq_n_u32, vgetq_lane_f32, vgetq_lane_u32};
use colorutils_rs::*;
use image::io::Reader as ImageReader;
use image::{EncodableLayout, GenericImageView};
Expand Down Expand Up @@ -27,13 +28,37 @@ fn main() {
// _mm_storeu_ps(dst.as_mut_ptr() as *mut f32, ln);
// println!("{:?}", dst);
// }
#[cfg(target_arch = "aarch64")]
unsafe {
let m = vdupq_n_f32(27f32);
let cbrt = vcbrtq_f32_ulp2(m);
let l = vgetq_lane_f32::<0>(cbrt);
println!("Cbrt {}", l);
}
// #[cfg(target_arch = "aarch64")]
// unsafe {
// let m = vdupq_n_f32(27f32);
// let cbrt = vcbrtq_f32_ulp2(m);
// let l = vgetq_lane_f32::<0>(cbrt);
// println!("Cbrt {}", l);
// }

let rgb = Rgb::<u8>::new(140, 164, 177);
let hsl = rgb.to_hsl();
println!("RGB {:?}", rgb);
println!("HSL {:?}", hsl);
println!("Back RGB {:?}", hsl.to_rgb8());

// unsafe {
// let (h, s, l) = neon_rgb_to_hsl(vdupq_n_u32(255), vdupq_n_u32(156), vdupq_n_u32(255), vdupq_n_f32(1f32));
// println!("NEON HSL {}, {}, {}", vgetq_lane_f32::<0>(h), vgetq_lane_f32::<0>(s), vgetq_lane_f32::<0>(l));
// let (r1, g1, b1) = neon_hsl_to_rgb(h, s, l, vdupq_n_f32(1f32));
//
// println!("NEON HSL -> RHB {}, {}, {}", vgetq_lane_u32::<0>(r1), vgetq_lane_u32::<0>(g1), vgetq_lane_u32::<0>(b1));
// }
//
// unsafe {
// let (h, s, v) = neon_rgb_to_hsv(vdupq_n_u32(255), vdupq_n_u32(156), vdupq_n_u32(255), vdupq_n_f32(1f32));
// let hsv = rgb.to_hsv();
// println!("HSV {:?}", hsv);
// println!("NEON HSV {}, {}, {}", vgetq_lane_f32::<0>(h), vgetq_lane_f32::<0>(s), vgetq_lane_f32::<0>(v));
// let (r1, g1, b1) = neon_hsv_to_rgb(h, s,v, vdupq_n_f32(1f32));
// println!("NEON RGB {}, {}, {}", vgetq_lane_u32::<0>(r1), vgetq_lane_u32::<0>(g1), vgetq_lane_u32::<0>(b1));

// }

let img = ImageReader::open("./assets/asset_middle.jpg")
.unwrap()
Expand Down Expand Up @@ -65,17 +90,17 @@ fn main() {
dst_slice.resize(width as usize * 4 * height as usize, 0u8);

{
let mut lab_store: Vec<f32> = vec![];
let store_stride = width as usize * 4usize * std::mem::size_of::<f32>();
lab_store.resize(width as usize * 4usize * height as usize, 0f32);
let mut lab_store: Vec<u16> = vec![];
let store_stride = width as usize * 4usize * std::mem::size_of::<u16>();
lab_store.resize(width as usize * 4usize * height as usize, 0u16);
let start_time = Instant::now();
rgba_to_lab_with_alpha(
rgba_to_hsl(
src_bytes,
4u32 * width,
&mut lab_store,
store_stride as u32,
width,
height,
height,100f32
);
// let mut destination: Vec<f32> = vec![];
// destination.resize(width as usize * height as usize * 4, 0f32);
Expand All @@ -99,13 +124,13 @@ fn main() {
// src_shift += src_stride as usize;
// }

lab_with_alpha_to_rgba(
hsl_to_rgba(
&lab_store,
store_stride as u32,
&mut dst_slice,
4u32 * width,
width,
height,
height,100f32,
);

let elapsed_time = start_time.elapsed();
Expand Down
Loading

0 comments on commit 47590d9

Please sign in to comment.