Skip to content

Commit

Permalink
Fixes ln, atan2
Browse files Browse the repository at this point in the history
  • Loading branch information
awxkee committed Jun 21, 2024
1 parent acdf13d commit 630298f
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 23 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.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ workspace = { members = ["src/app"] }

[package]
name = "colorutils-rs"
version = "0.4.8"
version = "0.4.9"
edition = "2021"
description = "High performance utilities for color format handling and conversion."
readme = "README.md"
Expand Down
18 changes: 6 additions & 12 deletions src/app/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use std::arch::aarch64::{vdupq_n_f32, vgetq_lane_f32};
use std::time::Instant;

use image::io::Reader as ImageReader;
Expand All @@ -15,13 +14,6 @@ pub const fn shuffle(z: u32, y: u32, x: u32, w: u32) -> i32 {
}

fn main() {
unsafe {
let y = vdupq_n_f32(0f32);
let x = vdupq_n_f32(0f32);
let v = vatan2q_f32(y, x);
let val = vgetq_lane_f32::<0>(v);
print!("{}", val);
}
let r = 140;
let g = 164;
let b = 177;
Expand All @@ -31,7 +23,7 @@ fn main() {
println!("HSL {:?}", hsl);
println!("Back RGB {:?}", hsl.to_rgb8());

let img = ImageReader::open("./assets/horse.png")
let img = ImageReader::open("./assets/asset_2.jpg")
.unwrap()
.decode()
.unwrap();
Expand All @@ -42,7 +34,7 @@ fn main() {
let mut src_bytes = img.as_bytes();
let width = dimensions.0;
let height = dimensions.1;
let components = 4;
let components = 3;
//
// let mut dst_rgba = vec![];
// dst_rgba.resize(4usize * width as usize * height as usize, 0u8);
Expand All @@ -66,13 +58,14 @@ fn main() {
lab_store.resize(width as usize * components * height as usize, 0f32);
let src_stride = width * components as u32;
let start_time = Instant::now();
rgba_to_lch_with_alpha(
rgb_to_linear(
src_bytes,
src_stride,
&mut lab_store,
store_stride as u32,
width,
height,
TransferFunction::Gamma2p2,
);
let elapsed_time = start_time.elapsed();
// Print the elapsed time in milliseconds
Expand Down Expand Up @@ -100,13 +93,14 @@ fn main() {
// }

let start_time = Instant::now();
lch_with_alpha_to_rgba(
linear_to_rgb(
&lab_store,
store_stride as u32,
&mut dst_slice,
src_stride,
width,
height,
TransferFunction::Gamma2p2,
);

let elapsed_time = start_time.elapsed();
Expand Down
5 changes: 2 additions & 3 deletions src/avx/math.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use crate::sse::{_mm_mulsign_ps, _mm_select_ps};
#[cfg(target_arch = "x86")]
use std::arch::x86::*;
#[cfg(target_arch = "x86_64")]
Expand Down Expand Up @@ -210,13 +209,13 @@ unsafe fn _mm256_exp_ps_impl<const PROCESS_NAN: bool>(x: __m256) -> __m256 {
#[inline(always)]
#[allow(dead_code)]
pub unsafe fn _mm256_pow_ps(x: __m256, n: __m256) -> __m256 {
_mm256_exp_ps(_mm256_mul_ps(n, _mm256_log_ps(x)))
_mm256_exp_ps(_mm256_mul_ps(n, _mm256_log_ps::<false>(x)))
}

#[inline(always)]
#[allow(dead_code)]
pub unsafe fn _mm256_pow_n_ps(x: __m256, n: f32) -> __m256 {
_mm256_exp_ps(_mm256_mul_ps(_mm256_set1_ps(n), _mm256_log_ps(x)))
_mm256_exp_ps(_mm256_mul_ps(_mm256_set1_ps(n), _mm256_log_ps::<false>(x)))
}

#[inline(always)]
Expand Down
2 changes: 1 addition & 1 deletion src/avx/sigmoidal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub(crate) unsafe fn avx_sigmoidal_to_color(x: __m256) -> __m256 {
let k = _mm256_mul_ps(x, _mm256_rcp_ps(den));
let zeros = _mm256_setzero_ps();
let zero_mask_2 = _mm256_cmp_ps::<_CMP_LT_OS>(k, zeros);
let ln = _mm256_log_ps(k);
let ln = _mm256_log_ps::<false>(k);
let rs = _mm256_select_ps(_mm256_and_ps(zero_mask_1, zero_mask_2), zeros, ln);
return rs;
}
Expand Down
1 change: 0 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ pub use xyza_laba_to_image::xyz_with_alpha_to_rgba;
pub use image_to_sigmoidal::bgra_to_sigmoidal;
pub use image_to_sigmoidal::rgb_to_sigmoidal;
pub use image_to_sigmoidal::rgba_to_sigmoidal;
pub use neon::*;
pub use rgb_expand::*;
pub use sigmoidal::Sigmoidal;
pub use sigmoidal_to_image::sigmoidal_to_bgra;
Expand Down
1 change: 0 additions & 1 deletion src/neon/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ pub use gamma_curves::*;
pub use hsv_to_image::*;
pub use image_to_hsv::*;
pub use linear_to_image::*;
pub use math::vatan2q_f32;
pub use to_linear::*;
pub use to_linear_u8::*;
pub use to_sigmoidal::neon_image_to_sigmoidal;
Expand Down
4 changes: 2 additions & 2 deletions src/sse/math.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,12 +193,12 @@ unsafe fn _mm_exp_ps_ulp_5_impl<const PROCESS_NAN: bool>(x: __m128) -> __m128 {

#[inline(always)]
pub unsafe fn _mm_pow_ps(x: __m128, n: __m128) -> __m128 {
_mm_exp_ps(_mm_mul_ps(n, _mm_log_ps(x)))
_mm_exp_ps(_mm_mul_ps(n, _mm_log_ps::<false>(x)))
}

#[inline(always)]
pub unsafe fn _mm_pow_n_ps(x: __m128, n: f32) -> __m128 {
_mm_exp_ps(_mm_mul_ps(_mm_set1_ps(n), _mm_log_ps(x)))
_mm_exp_ps(_mm_mul_ps(_mm_set1_ps(n), _mm_log_ps::<false>(x)))
}

#[inline(always)]
Expand Down
2 changes: 1 addition & 1 deletion src/sse/sigmoidal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub(crate) unsafe fn sse_sigmoidal_to_color(x: __m128) -> __m128 {
let k = _mm_mul_ps(x, _mm_rcp_ps(den));
let zeros = _mm_setzero_ps();
let zero_mask_2 = _mm_cmple_ps(k, zeros);
let ln = _mm_log_ps(k);
let ln = _mm_log_ps::<false>(k);
let rs = _mm_select_ps(_mm_and_ps(zero_mask_1, zero_mask_2), zeros, ln);
return rs;
}
Expand Down

0 comments on commit 630298f

Please sign in to comment.