Skip to content

Commit

Permalink
Added color blending
Browse files Browse the repository at this point in the history
  • Loading branch information
awxkee committed Jul 25, 2024
1 parent 028787b commit 9d5820f
Show file tree
Hide file tree
Showing 10 changed files with 1,347 additions and 34 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.5.4"
version = "0.5.5"
edition = "2021"
description = "High performance utilities for color format handling and conversion."
readme = "README.md"
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ pub mod planar_to_linear;
mod rgb;
mod rgb_expand;
mod rgba;
mod routines;
mod sigmoidal;
mod sigmoidal_to_image;
#[cfg(all(
Expand Down
17 changes: 9 additions & 8 deletions src/neon/image_to_oklab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
* // license that can be found in the LICENSE file.
*/
use crate::image::ImageConfiguration;
use crate::image_to_oklab::OklabTarget;
use crate::neon::get_neon_linear_transfer;
use crate::neon::math::vcolorq_matrix_f32;
use crate::{load_u8_and_deinterleave, TransferFunction, SRGB_TO_XYZ_D65};
use erydanos::{vatan2q_f32, vcbrtq_fast_f32, vhypotq_fast_f32};
use std::arch::aarch64::*;
use crate::image_to_oklab::OklabTarget;

macro_rules! triple_to_oklab {
($r: expr, $g: expr, $b: expr, $transfer: expr, $target: expr,
Expand All @@ -36,7 +36,8 @@ macro_rules! triple_to_oklab {
let m_ = vcbrtq_fast_f32(l_m);
let s_ = vcbrtq_fast_f32(l_s);

let (l, mut a, mut b) = vcolorq_matrix_f32(l_, m_, s_, $m0, $m1, $m2, $m3, $m4, $m5, $m6, $m7, $m8);
let (l, mut a, mut b) =
vcolorq_matrix_f32(l_, m_, s_, $m0, $m1, $m2, $m3, $m4, $m5, $m6, $m7, $m8);

if $target == OklabTarget::OKLCH {
let c = vhypotq_fast_f32(a, b);
Expand Down Expand Up @@ -119,8 +120,8 @@ pub unsafe fn neon_image_to_oklab<const CHANNELS_CONFIGURATION: u8, const TARGET
let b_low_low = vmovl_u16(vget_low_u16(b_low));

let (x_low_low, y_low_low, z_low_low) = triple_to_oklab!(
r_low_low, g_low_low, b_low_low, &transfer, target, x0, x1, x2, x3, x4, x5, x6, x7, x8, c0, c1,
c2, c3, c4, c5, c6, c7, c8, m0, m1, m2, m3, m4, m5, m6, m7, m8
r_low_low, g_low_low, b_low_low, &transfer, target, x0, x1, x2, x3, x4, x5, x6, x7, x8,
c0, c1, c2, c3, c4, c5, c6, c7, c8, m0, m1, m2, m3, m4, m5, m6, m7, m8
);

let a_low = vmovl_u8(vget_low_u8(a_chan));
Expand All @@ -140,8 +141,8 @@ pub unsafe fn neon_image_to_oklab<const CHANNELS_CONFIGURATION: u8, const TARGET
let b_low_high = vmovl_high_u16(b_low);

let (x_low_high, y_low_high, z_low_high) = triple_to_oklab!(
r_low_high, g_low_high, b_low_high, &transfer, target, x0, x1, x2, x3, x4, x5, x6, x7, x8, c0,
c1, c2, c3, c4, c5, c6, c7, c8, m0, m1, m2, m3, m4, m5, m6, m7, m8
r_low_high, g_low_high, b_low_high, &transfer, target, x0, x1, x2, x3, x4, x5, x6, x7,
x8, c0, c1, c2, c3, c4, c5, c6, c7, c8, m0, m1, m2, m3, m4, m5, m6, m7, m8
);

if image_configuration.has_alpha() {
Expand All @@ -162,8 +163,8 @@ pub unsafe fn neon_image_to_oklab<const CHANNELS_CONFIGURATION: u8, const TARGET
let b_high_low = vmovl_u16(vget_low_u16(b_high));

let (x_high_low, y_high_low, z_high_low) = triple_to_oklab!(
r_high_low, g_high_low, b_high_low, &transfer, target, x0, x1, x2, x3, x4, x5, x6, x7, x8, c0,
c1, c2, c3, c4, c5, c6, c7, c8, m0, m1, m2, m3, m4, m5, m6, m7, m8
r_high_low, g_high_low, b_high_low, &transfer, target, x0, x1, x2, x3, x4, x5, x6, x7,
x8, c0, c1, c2, c3, c4, c5, c6, c7, c8, m0, m1, m2, m3, m4, m5, m6, m7, m8
);

let a_high = vmovl_high_u8(a_chan);
Expand Down
4 changes: 2 additions & 2 deletions src/neon/oklab_to_image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
* // license that can be found in the LICENSE file.
*/
use crate::image::ImageConfiguration;
use crate::image_to_oklab::OklabTarget;
use crate::neon::get_neon_gamma_transfer;
use crate::neon::math::vcolorq_matrix_f32;
use crate::{load_f32_and_deinterleave, TransferFunction, XYZ_TO_SRGB_D65};
use std::arch::aarch64::*;
use erydanos::{vcosq_f32, vsinq_f32};
use crate::image_to_oklab::OklabTarget;
use std::arch::aarch64::*;

#[inline(always)]
unsafe fn neon_oklab_gamma_vld<const CHANNELS_CONFIGURATION: u8, const TARGET: u8>(
Expand Down
1 change: 0 additions & 1 deletion src/neon/planar_to_linear.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ unsafe fn process_pixels(
let r_high_high = vmovl_high_u16(r_high);

let x_high_high = neon_to_linear(r_high_high, &transfer);

let storing_row = float32x4x4_t(x_low_low, x_low_high, x_high_low, x_high_high);
storing_row
}
Expand Down
20 changes: 10 additions & 10 deletions src/oklab_to_image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@
* // license that can be found in the LICENSE file.
*/
use crate::image::ImageConfiguration;
use crate::image_to_oklab::OklabTarget;
#[cfg(all(
any(target_arch = "aarch64", target_arch = "arm"),
target_feature = "neon"
))]
use crate::neon::neon_oklab_to_image;
use crate::oklch::Oklch;
#[cfg(all(
any(target_arch = "x86_64", target_arch = "x86"),
target_feature = "sse4.1"
))]
use crate::sse::sse_oklab_to_image;
use crate::{Oklab, TransferFunction};
use crate::image_to_oklab::OklabTarget;
use crate::oklch::Oklch;

fn oklab_to_image<const CHANNELS_CONFIGURATION: u8, const TARGET: u8>(
src: &[f32],
Expand Down Expand Up @@ -134,7 +134,7 @@ pub fn oklab_to_rgba(
height: u32,
transfer_function: TransferFunction,
) {
oklab_to_image::<{ ImageConfiguration::Rgba as u8 }, {OklabTarget::OKLAB as u8}>(
oklab_to_image::<{ ImageConfiguration::Rgba as u8 }, { OklabTarget::OKLAB as u8 }>(
src,
src_stride,
dst,
Expand Down Expand Up @@ -164,7 +164,7 @@ pub fn oklab_to_rgb(
height: u32,
transfer_function: TransferFunction,
) {
oklab_to_image::<{ ImageConfiguration::Rgb as u8 }, {OklabTarget::OKLAB as u8}>(
oklab_to_image::<{ ImageConfiguration::Rgb as u8 }, { OklabTarget::OKLAB as u8 }>(
src,
src_stride,
dst,
Expand Down Expand Up @@ -194,7 +194,7 @@ pub fn oklab_to_bgr(
height: u32,
transfer_function: TransferFunction,
) {
oklab_to_image::<{ ImageConfiguration::Bgr as u8 }, {OklabTarget::OKLAB as u8}>(
oklab_to_image::<{ ImageConfiguration::Bgr as u8 }, { OklabTarget::OKLAB as u8 }>(
src,
src_stride,
dst,
Expand Down Expand Up @@ -224,7 +224,7 @@ pub fn oklab_to_bgra(
height: u32,
transfer_function: TransferFunction,
) {
oklab_to_image::<{ ImageConfiguration::Bgra as u8 }, {OklabTarget::OKLAB as u8}>(
oklab_to_image::<{ ImageConfiguration::Bgra as u8 }, { OklabTarget::OKLAB as u8 }>(
src,
src_stride,
dst,
Expand Down Expand Up @@ -254,7 +254,7 @@ pub fn oklch_to_rgba(
height: u32,
transfer_function: TransferFunction,
) {
oklab_to_image::<{ ImageConfiguration::Rgba as u8 }, {OklabTarget::OKLCH as u8}>(
oklab_to_image::<{ ImageConfiguration::Rgba as u8 }, { OklabTarget::OKLCH as u8 }>(
src,
src_stride,
dst,
Expand Down Expand Up @@ -284,7 +284,7 @@ pub fn oklch_to_rgb(
height: u32,
transfer_function: TransferFunction,
) {
oklab_to_image::<{ ImageConfiguration::Rgb as u8 }, {OklabTarget::OKLCH as u8}>(
oklab_to_image::<{ ImageConfiguration::Rgb as u8 }, { OklabTarget::OKLCH as u8 }>(
src,
src_stride,
dst,
Expand Down Expand Up @@ -314,7 +314,7 @@ pub fn oklch_to_bgr(
height: u32,
transfer_function: TransferFunction,
) {
oklab_to_image::<{ ImageConfiguration::Bgr as u8 }, {OklabTarget::OKLCH as u8}>(
oklab_to_image::<{ ImageConfiguration::Bgr as u8 }, { OklabTarget::OKLCH as u8 }>(
src,
src_stride,
dst,
Expand Down Expand Up @@ -344,7 +344,7 @@ pub fn oklch_to_bgra(
height: u32,
transfer_function: TransferFunction,
) {
oklab_to_image::<{ ImageConfiguration::Bgra as u8 }, {OklabTarget::OKLCH as u8}>(
oklab_to_image::<{ ImageConfiguration::Bgra as u8 }, { OklabTarget::OKLCH as u8 }>(
src,
src_stride,
dst,
Expand Down
Loading

0 comments on commit 9d5820f

Please sign in to comment.