Skip to content

Commit

Permalink
Some linearizing fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
awxkee committed Oct 18, 2024
1 parent c789fa4 commit ad63ce3
Show file tree
Hide file tree
Showing 12 changed files with 18 additions and 35 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.7.1"
version = "0.7.2"
edition = "2021"
description = "High performance utilities for color format handling and conversion."
readme = "README.md"
Expand Down
12 changes: 6 additions & 6 deletions src/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,23 @@ 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,
}
}

#[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,
}
}

#[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,
Expand All @@ -40,23 +40,23 @@ 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,
}
}

#[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,
ImageConfiguration::Bgra | ImageConfiguration::Bgr => 0,
}
}
#[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,
Expand Down
5 changes: 2 additions & 3 deletions src/image_to_linear_u8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,8 @@ fn channels_to_linear<const CHANNELS_CONFIGURATION: u8, const USE_ALPHA: bool>(

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;
Expand Down
4 changes: 1 addition & 3 deletions src/jzazbz_to_image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ fn jzazbz_to_image<const CHANNELS_CONFIGURATION: u8, const TARGET: u8>(

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 {
Expand Down
4 changes: 1 addition & 3 deletions src/lalphabeta_to_image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ fn lalphabeta_to_image<const CHANNELS_CONFIGURATION: u8>(

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 {
Expand Down
4 changes: 1 addition & 3 deletions src/linear_to_image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ fn linear_to_gamma_channels<const CHANNELS_CONFIGURATION: u8, const USE_ALPHA: b

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 {
Expand Down
4 changes: 1 addition & 3 deletions src/linear_to_image_u8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ fn linear_to_gamma_channels<const CHANNELS_CONFIGURATION: u8, const USE_ALPHA: b

let mut lut_table = vec![0u8; 256];
for i in 0..256 {
lut_table[i] = (transfer_function.gamma(i as f32 * (1. / 255.0)) * 255.)
.ceil()
.min(255.) as u8;
lut_table[i] = (transfer_function.gamma(i as f32 * (1. / 255.0)) * 255.).min(255.) as u8;
}

#[cfg(feature = "rayon")]
Expand Down
4 changes: 1 addition & 3 deletions src/linear_to_planar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,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 src_slice_safe_align = unsafe {
Expand Down
4 changes: 1 addition & 3 deletions src/oklab_to_image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,7 @@ fn oklab_to_image<const CHANNELS_CONFIGURATION: u8, const TARGET: u8>(

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();
Expand Down
4 changes: 1 addition & 3 deletions src/xyz_lab_to_image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,7 @@ fn xyz_to_channels<const CHANNELS_CONFIGURATION: u8, const USE_ALPHA: bool, cons

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;
}

#[cfg(feature = "rayon")]
Expand Down
4 changes: 1 addition & 3 deletions src/xyza_laba_to_image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,7 @@ fn xyz_with_alpha_to_channels<const CHANNELS_CONFIGURATION: u8, const TARGET: u8

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 {
Expand Down

0 comments on commit ad63ce3

Please sign in to comment.