Skip to content

Commit

Permalink
LICENSE header, a lot of fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
awxkee committed Jul 17, 2024
1 parent d37a630 commit bf785a9
Show file tree
Hide file tree
Showing 89 changed files with 788 additions and 412 deletions.
6 changes: 3 additions & 3 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions 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.13"
version = "0.4.14"
edition = "2021"
description = "High performance utilities for color format handling and conversion."
readme = "README.md"
Expand All @@ -16,7 +16,7 @@ repository = "https://github.com/awxkee/colorutils-rs"
exclude = ["*.jpg"]

[dependencies]
erydanos = "0.2.3"
erydanos = "0.2.6"
half = "2.4.1"

[features]
Expand Down
29 changes: 22 additions & 7 deletions src/app/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
/*
* // Copyright 2024 (c) the Radzivon Bartoshyk. All rights reserved.
* //
* // Use of this source code is governed by a BSD-style
* // license that can be found in the LICENSE file.
*/

use std::time::Instant;

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

fn main() {
let r = 140;
let g = 164;
let b = 177;
let r = 126;
let g = 126;
let b = 126;
let rgb = Rgb::<u8>::new(r, g, b);
let hsl = rgb.to_hsl();
let hsl = rgb.to_lab();
println!("RGB {:?}", rgb);
println!("HSL {:?}", hsl);
println!("RGB 0,0,0 {:?}", hsl);
println!(
"RGB 127,127,127 {:?}",
Rgb::<u8>::new(127, 127, 127).to_lab()
);
println!(
"RGB 255,255,255 {:?}",
Rgb::<u8>::new(255, 255, 255).to_lab()
);
println!("Back RGB {:?}", hsl.to_rgb8());

let img = ImageReader::open("./assets/beach_horizon.jpg")
Expand Down Expand Up @@ -58,7 +73,7 @@ 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();
rgb_to_lch(
rgb_to_lab(
src_bytes,
src_stride,
&mut lab_store,
Expand Down Expand Up @@ -92,7 +107,7 @@ fn main() {
// }

let start_time = Instant::now();
lch_to_rgb(
lab_to_srgb(
&lab_store,
store_stride as u32,
&mut dst_slice,
Expand Down
7 changes: 7 additions & 0 deletions src/avx/cie.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
/*
* // Copyright 2024 (c) the Radzivon Bartoshyk. All rights reserved.
* //
* // Use of this source code is governed by a BSD-style
* // license that can be found in the LICENSE file.
*/

use crate::avx::math::*;
use crate::avx::{_mm256_cube_ps, _mm256_prefer_fma_ps, _mm256_select_ps};
use crate::luv::{
Expand Down
7 changes: 7 additions & 0 deletions src/avx/from_sigmoidal.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
/*
* // Copyright 2024 (c) the Radzivon Bartoshyk. All rights reserved.
* //
* // Use of this source code is governed by a BSD-style
* // license that can be found in the LICENSE file.
*/

use crate::avx::sigmoidal::avx_sigmoidal_to_rgb;
use crate::avx::{
avx2_deinterleave_rgb_ps, avx2_deinterleave_rgba_ps, avx2_interleave_rgb,
Expand Down
7 changes: 7 additions & 0 deletions src/avx/gamma_curves.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
/*
* // Copyright 2024 (c) the Radzivon Bartoshyk. All rights reserved.
* //
* // Use of this source code is governed by a BSD-style
* // license that can be found in the LICENSE file.
*/

use crate::avx::math::*;
#[allow(unused_imports)]
use crate::gamma_curves::TransferFunction;
Expand Down
7 changes: 7 additions & 0 deletions src/avx/linear_to_image.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
/*
* // Copyright 2024 (c) the Radzivon Bartoshyk. All rights reserved.
* //
* // Use of this source code is governed by a BSD-style
* // license that can be found in the LICENSE file.
*/

use crate::avx::gamma_curves::get_avx_gamma_transfer;
use crate::avx::{
avx2_deinterleave_rgb_ps, avx2_deinterleave_rgba_ps, avx2_interleave_rgb,
Expand Down
7 changes: 7 additions & 0 deletions src/avx/math.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
/*
* // Copyright 2024 (c) the Radzivon Bartoshyk. All rights reserved.
* //
* // Use of this source code is governed by a BSD-style
* // license that can be found in the LICENSE file.
*/

#[cfg(target_arch = "x86")]
use std::arch::x86::*;
#[cfg(target_arch = "x86_64")]
Expand Down
2 changes: 1 addition & 1 deletion src/avx/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* // Copyright (c) the Radzivon Bartoshyk. All rights reserved.
* // Copyright 2024 (c) the Radzivon Bartoshyk. All rights reserved.
* //
* // Use of this source code is governed by a BSD-style
* // license that can be found in the LICENSE file.
Expand Down
7 changes: 7 additions & 0 deletions src/avx/sigmoidal.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
/*
* // Copyright 2024 (c) the Radzivon Bartoshyk. All rights reserved.
* //
* // Use of this source code is governed by a BSD-style
* // license that can be found in the LICENSE file.
*/

use crate::avx::{_mm256_exp_ps, _mm256_log_ps, _mm256_neg_ps, _mm256_select_ps};
#[cfg(target_arch = "x86")]
use std::arch::x86::*;
Expand Down
2 changes: 1 addition & 1 deletion src/avx/support.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* // Copyright (c) the Radzivon Bartoshyk. All rights reserved.
* // Copyright 2024 (c) the Radzivon Bartoshyk. All rights reserved.
* //
* // Use of this source code is governed by a BSD-style
* // license that can be found in the LICENSE file.
Expand Down
7 changes: 7 additions & 0 deletions src/avx/to_linear.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
/*
* // Copyright 2024 (c) the Radzivon Bartoshyk. All rights reserved.
* //
* // Use of this source code is governed by a BSD-style
* // license that can be found in the LICENSE file.
*/

use crate::avx::gamma_curves::get_avx2_linear_transfer;
use crate::avx::{
avx2_deinterleave_rgb_epi8, avx2_deinterleave_rgba_epi8, avx2_interleave_rgb_ps,
Expand Down
7 changes: 7 additions & 0 deletions src/avx/to_sigmoidal.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
/*
* // Copyright 2024 (c) the Radzivon Bartoshyk. All rights reserved.
* //
* // Use of this source code is governed by a BSD-style
* // license that can be found in the LICENSE file.
*/

use crate::avx::sigmoidal::avx_rgb_to_sigmoidal;
use crate::avx::{
avx2_deinterleave_rgb_epi8, avx2_deinterleave_rgba_epi8, avx2_interleave_rgb_ps,
Expand Down
7 changes: 7 additions & 0 deletions src/avx/to_xyz_lab.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
/*
* // Copyright 2024 (c) the Radzivon Bartoshyk. All rights reserved.
* //
* // Use of this source code is governed by a BSD-style
* // license that can be found in the LICENSE file.
*/

#[cfg(target_arch = "x86")]
use std::arch::x86::*;
#[cfg(target_arch = "x86_64")]
Expand Down
7 changes: 7 additions & 0 deletions src/avx/utils.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
/*
* // Copyright 2024 (c) the Radzivon Bartoshyk. All rights reserved.
* //
* // Use of this source code is governed by a BSD-style
* // license that can be found in the LICENSE file.
*/

#[cfg(target_arch = "x86")]
use std::arch::x86::*;
#[cfg(target_arch = "x86_64")]
Expand Down
7 changes: 7 additions & 0 deletions src/avx/xyz_lab_to_image.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
/*
* // Copyright 2024 (c) the Radzivon Bartoshyk. All rights reserved.
* //
* // Use of this source code is governed by a BSD-style
* // license that can be found in the LICENSE file.
*/

use crate::avx::cie::{avx_lab_to_xyz, avx_lch_to_xyz, avx_luv_to_xyz};
use crate::avx::gamma_curves::get_avx_gamma_transfer;
use crate::avx::{
Expand Down
7 changes: 7 additions & 0 deletions src/avx/xyza_laba_to_image.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
/*
* // Copyright 2024 (c) the Radzivon Bartoshyk. All rights reserved.
* //
* // Use of this source code is governed by a BSD-style
* // license that can be found in the LICENSE file.
*/

#[cfg(target_arch = "x86")]
use std::arch::x86::*;
#[cfg(target_arch = "x86_64")]
Expand Down
7 changes: 7 additions & 0 deletions src/concat_alpha.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
/*
* // Copyright 2024 (c) the Radzivon Bartoshyk. All rights reserved.
* //
* // Use of this source code is governed by a BSD-style
* // license that can be found in the LICENSE file.
*/

#[cfg(all(
any(target_arch = "x86_64", target_arch = "x86"),
target_feature = "avx2"
Expand Down
11 changes: 11 additions & 0 deletions src/euclidean.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* // Copyright 2024 (c) the Radzivon Bartoshyk. All rights reserved.
* //
* // Use of this source code is governed by a BSD-style
* // license that can be found in the LICENSE file.
*/

/// Trait that implements Euclidean distance for color
pub trait EuclideanDistance {
fn euclidean_distance(&self, other: Self) -> f32;
}
27 changes: 17 additions & 10 deletions src/gamma_curves.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
#[inline(always)]
/*
* // Copyright 2024 (c) the Radzivon Bartoshyk. All rights reserved.
* //
* // Use of this source code is governed by a BSD-style
* // license that can be found in the LICENSE file.
*/

#[inline]
/// Linear transfer function for sRGB
pub fn srgb_to_linear(gamma: f32) -> f32 {
return if gamma < 0f32 {
Expand All @@ -12,7 +19,7 @@ pub fn srgb_to_linear(gamma: f32) -> f32 {
};
}

#[inline(always)]
#[inline]
/// Gamma transfer function for sRGB
pub fn srgb_from_linear(linear: f32) -> f32 {
return if linear < 0.0f32 {
Expand All @@ -26,7 +33,7 @@ pub fn srgb_from_linear(linear: f32) -> f32 {
};
}

#[inline(always)]
#[inline]
/// Linear transfer function for Rec.709
pub fn rec709_to_linear(gamma: f32) -> f32 {
return if gamma < 0.0f32 {
Expand All @@ -40,7 +47,7 @@ pub fn rec709_to_linear(gamma: f32) -> f32 {
};
}

#[inline(always)]
#[inline]
/// Gamma transfer function for Rec.709
pub fn rec709_from_linear(linear: f32) -> f32 {
return if linear < 0.0f32 {
Expand All @@ -66,25 +73,25 @@ pub fn pure_gamma_function(x: f32, gamma: f32) -> f32 {
}
}

#[inline(always)]
#[inline]
/// Pure gamma transfer function for gamma 2.2
pub fn gamma2p2_from_linear(linear: f32) -> f32 {
pure_gamma_function(linear, 1f32 / 2.2f32)
}

#[inline(always)]
#[inline]
/// Linear transfer function for gamma 2.2
pub fn gamma2p2_to_linear(gamma: f32) -> f32 {
pure_gamma_function(gamma, 2.2f32)
}

#[inline(always)]
#[inline]
/// Pure gamma transfer function for gamma 2.8
pub fn gamma2p8_from_linear(linear: f32) -> f32 {
pure_gamma_function(linear, 1f32 / 2.8f32)
}

#[inline(always)]
#[inline]
/// Linear transfer function for gamma 2.8
pub fn gamma2p8_to_linear(gamma: f32) -> f32 {
pure_gamma_function(gamma, 2.8f32)
Expand All @@ -104,7 +111,7 @@ pub enum TransferFunction {
}

impl TransferFunction {
#[inline(always)]
#[inline]
pub fn get_linearize_function(&self) -> fn(f32) -> f32 {
match self {
TransferFunction::Srgb => srgb_to_linear,
Expand All @@ -114,7 +121,7 @@ impl TransferFunction {
}
}

#[inline(always)]
#[inline]
pub fn get_gamma_function(&self) -> fn(f32) -> f32 {
match self {
TransferFunction::Srgb => srgb_from_linear,
Expand Down
6 changes: 6 additions & 0 deletions src/hsl.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/*
* // Copyright 2024 (c) the Radzivon Bartoshyk. All rights reserved.
* //
* // Use of this source code is governed by a BSD-style
* // license that can be found in the LICENSE file.
*/
use crate::rgb::Rgb;

#[derive(Debug, Copy, Clone, PartialOrd, PartialEq)]
Expand Down
Loading

0 comments on commit bf785a9

Please sign in to comment.