Skip to content

Commit

Permalink
Big reworking with speed increasing
Browse files Browse the repository at this point in the history
  • Loading branch information
awxkee committed Oct 10, 2024
1 parent d7057ed commit f3ee410
Show file tree
Hide file tree
Showing 51 changed files with 1,311 additions and 7,793 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.6.1"
version = "0.7.0"
edition = "2021"
description = "High performance utilities for color format handling and conversion."
readme = "README.md"
Expand Down
10 changes: 6 additions & 4 deletions src/app/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ fn main() {
// let restored = lalphabeta.to_rgb(TransferFunction::Srgb);
// println!("Restored RGB {:?}", restored);

let img = ImageReader::open("./assets/asset.jpg")
let img = ImageReader::open("./assets/op_fhd.jpg")
.unwrap()
.decode()
.unwrap();
let dimensions = img.dimensions();
println!("dimensions {:?}", img.dimensions());

println!("{:?}", img.color());
// let img = img.to_rgba8();
let img = img.to_rgb8();
let mut src_bytes = img.as_bytes();
let width = dimensions.0;
let height = dimensions.1;
Expand All @@ -68,13 +68,14 @@ fn main() {
lab_store.resize(width as usize * components * height as usize, 0.);
let src_stride = width * components as u32;
let start_time = Instant::now();
rgb_to_oklch(
rgb_to_jzazbz(
src_bytes,
src_stride,
&mut lab_store,
store_stride as u32,
width,
height,
200.,
TransferFunction::Srgb,
);
let elapsed_time = start_time.elapsed();
Expand Down Expand Up @@ -103,13 +104,14 @@ fn main() {
// }

let start_time = Instant::now();
oklch_to_rgb(
jzazbz_to_rgb(
&lab_store,
store_stride as u32,
&mut dst_slice,
src_stride,
width,
height,
200.,
TransferFunction::Srgb,
);

Expand Down
21 changes: 4 additions & 17 deletions src/avx/cie.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@
*/

use crate::avx::_mm256_cube_ps;
use crate::avx::gamma_curves::perform_avx2_linear_transfer;
use crate::avx::math::*;
use crate::luv::{
LUV_CUTOFF_FORWARD_Y, LUV_MULTIPLIER_FORWARD_Y, LUV_MULTIPLIER_INVERSE_Y, LUV_WHITE_U_PRIME,
LUV_WHITE_V_PRIME,
};
use crate::TransferFunction;
use erydanos::{
_mm256_atan2_ps, _mm256_cbrt_ps, _mm256_cos_ps, _mm256_hypot_ps, _mm256_prefer_fma_ps,
_mm256_select_ps, _mm256_sin_ps,
Expand Down Expand Up @@ -103,9 +101,9 @@ pub(crate) unsafe fn avx_lch_to_xyz(l: __m256, c: __m256, h: __m256) -> (__m256,

#[inline(always)]
pub(crate) unsafe fn avx2_triple_to_xyz(
r: __m256i,
g: __m256i,
b: __m256i,
r: __m256,
g: __m256,
b: __m256,
c1: __m256,
c2: __m256,
c3: __m256,
Expand All @@ -115,19 +113,8 @@ pub(crate) unsafe fn avx2_triple_to_xyz(
c7: __m256,
c8: __m256,
c9: __m256,
transfer_function: TransferFunction,
) -> (__m256, __m256, __m256) {
let u8_scale = _mm256_set1_ps(1f32 / 255f32);
let r_f = _mm256_mul_ps(_mm256_cvtepi32_ps(r), u8_scale);
let g_f = _mm256_mul_ps(_mm256_cvtepi32_ps(g), u8_scale);
let b_f = _mm256_mul_ps(_mm256_cvtepi32_ps(b), u8_scale);
let r_linear = perform_avx2_linear_transfer(transfer_function, r_f);
let g_linear = perform_avx2_linear_transfer(transfer_function, g_f);
let b_linear = perform_avx2_linear_transfer(transfer_function, b_f);

let (x, y, z) = _mm256_color_matrix_ps(
r_linear, g_linear, b_linear, c1, c2, c3, c4, c5, c6, c7, c8, c9,
);
let (x, y, z) = _mm256_color_matrix_ps(r, g, b, c1, c2, c3, c4, c5, c6, c7, c8, c9);
(x, y, z)
}

Expand Down
Loading

0 comments on commit f3ee410

Please sign in to comment.