From ad63ce36c2bf4a1ef625726a00bf22a570c895f2 Mon Sep 17 00:00:00 2001 From: awxkee Date: Fri, 18 Oct 2024 11:35:34 +0100 Subject: [PATCH] Some linearizing fixes --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/image.rs | 12 ++++++------ src/image_to_linear_u8.rs | 5 ++--- src/jzazbz_to_image.rs | 4 +--- src/lalphabeta_to_image.rs | 4 +--- src/linear_to_image.rs | 4 +--- src/linear_to_image_u8.rs | 4 +--- src/linear_to_planar.rs | 4 +--- src/oklab_to_image.rs | 4 +--- src/xyz_lab_to_image.rs | 4 +--- src/xyza_laba_to_image.rs | 4 +--- 12 files changed, 18 insertions(+), 35 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 064569e..87c73c5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -169,7 +169,7 @@ checksum = "3d7b894f5411737b7867f4827955924d7c254fc9f4d91a6aad6b097804b1018b" [[package]] name = "colorutils-rs" -version = "0.7.1" +version = "0.7.2" dependencies = [ "erydanos", "half", diff --git a/Cargo.toml b/Cargo.toml index a7960db..965ba0b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ workspace = { members = ["src/app"] } [package] name = "colorutils-rs" -version = "0.7.1" +version = "0.7.2" edition = "2021" description = "High performance utilities for color format handling and conversion." readme = "README.md" diff --git a/src/image.rs b/src/image.rs index d8e29cc..277ebf6 100644 --- a/src/image.rs +++ b/src/image.rs @@ -15,7 +15,7 @@ pub enum ImageConfiguration { impl ImageConfiguration { #[inline(always)] - pub fn get_channels_count(&self) -> usize { + pub const fn get_channels_count(&self) -> usize { match self { ImageConfiguration::Rgb | ImageConfiguration::Bgr => 3, ImageConfiguration::Rgba | ImageConfiguration::Bgra => 4, @@ -23,7 +23,7 @@ impl ImageConfiguration { } #[inline(always)] - pub fn has_alpha(&self) -> bool { + pub const fn has_alpha(&self) -> bool { match self { ImageConfiguration::Rgb | ImageConfiguration::Bgr => false, ImageConfiguration::Rgba | ImageConfiguration::Bgra => true, @@ -31,7 +31,7 @@ impl ImageConfiguration { } #[inline(always)] - pub fn get_r_channel_offset(&self) -> usize { + pub const fn get_r_channel_offset(&self) -> usize { match self { ImageConfiguration::Rgb => 0, ImageConfiguration::Rgba => 0, @@ -40,7 +40,7 @@ impl ImageConfiguration { } #[inline(always)] - pub fn get_g_channel_offset(&self) -> usize { + pub const fn get_g_channel_offset(&self) -> usize { match self { ImageConfiguration::Rgb | ImageConfiguration::Bgr => 1, ImageConfiguration::Rgba | ImageConfiguration::Bgra => 1, @@ -48,7 +48,7 @@ impl ImageConfiguration { } #[inline(always)] - pub fn get_b_channel_offset(&self) -> usize { + pub const fn get_b_channel_offset(&self) -> usize { match self { ImageConfiguration::Rgb => 2, ImageConfiguration::Rgba => 2, @@ -56,7 +56,7 @@ impl ImageConfiguration { } } #[inline(always)] - pub fn get_a_channel_offset(&self) -> usize { + pub const fn get_a_channel_offset(&self) -> usize { match self { ImageConfiguration::Rgb | ImageConfiguration::Bgr => 0, ImageConfiguration::Rgba | ImageConfiguration::Bgra => 3, diff --git a/src/image_to_linear_u8.rs b/src/image_to_linear_u8.rs index 581b426..c05674c 100644 --- a/src/image_to_linear_u8.rs +++ b/src/image_to_linear_u8.rs @@ -31,9 +31,8 @@ fn channels_to_linear( let mut lut_table = vec![0u8; 256]; for i in 0..256 { - lut_table[i] = (transfer_function.linearize(i as f32 * (1. / 255.0)) * 255.) - .ceil() - .min(255.) as u8; + lut_table[i] = + (transfer_function.linearize(i as f32 * (1. / 255.0)) * 255.).min(255.) as u8; } let iter; diff --git a/src/jzazbz_to_image.rs b/src/jzazbz_to_image.rs index 2839dda..3fb5df6 100644 --- a/src/jzazbz_to_image.rs +++ b/src/jzazbz_to_image.rs @@ -47,9 +47,7 @@ fn jzazbz_to_image( let mut lut_table = vec![0u8; 2049]; for i in 0..2049 { - lut_table[i] = (transfer_function.gamma(i as f32 * (1. / 2048.0)) * 255.) - .ceil() - .min(255.) as u8; + lut_table[i] = (transfer_function.gamma(i as f32 * (1. / 2048.0)) * 255.).min(255.) as u8; } let src_slice_safe_align = unsafe { diff --git a/src/lalphabeta_to_image.rs b/src/lalphabeta_to_image.rs index 85372d4..1fe7a10 100644 --- a/src/lalphabeta_to_image.rs +++ b/src/lalphabeta_to_image.rs @@ -27,9 +27,7 @@ fn lalphabeta_to_image( let mut lut_table = vec![0u8; 2049]; for i in 0..2049 { - lut_table[i] = (transfer_function.gamma(i as f32 * (1. / 2048.0)) * 255.) - .round() - .min(255.) as u8; + lut_table[i] = (transfer_function.gamma(i as f32 * (1. / 2048.0)) * 255.).min(255.) as u8; } let src_slice_safe_align = unsafe { diff --git a/src/linear_to_image.rs b/src/linear_to_image.rs index 13486ce..630729a 100644 --- a/src/linear_to_image.rs +++ b/src/linear_to_image.rs @@ -32,9 +32,7 @@ fn linear_to_gamma_channels( let mut lut_table = vec![0u8; 2049]; for i in 0..2049 { - lut_table[i] = (transfer_function.gamma(i as f32 * (1. / 2048.0)) * 255.) - .ceil() - .min(255.) as u8; + lut_table[i] = (transfer_function.gamma(i as f32 * (1. / 2048.0)) * 255.).min(255.) as u8; } let channels = image_configuration.get_channels_count(); diff --git a/src/xyz_lab_to_image.rs b/src/xyz_lab_to_image.rs index 16ce680..557630d 100644 --- a/src/xyz_lab_to_image.rs +++ b/src/xyz_lab_to_image.rs @@ -80,9 +80,7 @@ fn xyz_to_channels