Skip to content

Commit

Permalink
Linearize bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
awxkee committed May 29, 2024
1 parent 997efed commit e164777
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 3 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.2.3"
version = "0.2.4"
edition = "2021"
description = "Hig performance utilities for color format handling and conversion."
readme = "README.md"
Expand Down
14 changes: 14 additions & 0 deletions src/app/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,20 @@ fn main() {
);
src_bytes = &dst_rgba;

// {
// let mut store: Vec<f32> = vec![];
// let store_stride = width as usize * 3usize * std::mem::size_of::<f32>();
// store.resize(width as usize * 3usize * height as usize, 0f32);
// let mut alpha_store: Vec<f32> = vec![];
// let alpha_stride = width as usize * std::mem::size_of::<f32>();
// alpha_store.resize(width as usize * height as usize, 0f32);
// rgba_to_laba(src_bytes, 4u32 * width, &mut store, store_stride as u32, &mut alpha_store, alpha_stride as u32, width, height);
// let mut destination: Vec<f32> = vec![];
// destination.resize(width as usize * height as usize * 4, 0f32);
// let dst_stride = width * 4 * std::mem::size_of::<f32>() as u32;
// append_alpha(&mut destination, dst_stride, &store, store_stride as u32, &alpha_store, alpha_stride as u32, width, height);
// }

let mut xyz: Vec<f32> = vec![];
xyz.resize(4 * width as usize * height as usize, 0f32);

Expand Down
2 changes: 1 addition & 1 deletion src/concat_alpha.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub fn append_alpha(
let a_ptr = unsafe { (a_plane.as_ptr() as *const u8).add(a_offset) as *const f32 };
let a_slice = unsafe { slice::from_raw_parts(a_ptr, width as usize) };
let dst_ptr = unsafe { (dst.as_mut_ptr() as *mut u8).add(dst_offset) as *mut f32 };
let dst_slice = unsafe { slice::from_raw_parts_mut(dst_ptr, width as usize) };
let dst_slice = unsafe { slice::from_raw_parts_mut(dst_ptr, width as usize * 4) };

#[cfg(any(target_arch = "x86_64", target_arch = "x86"))]
unsafe {
Expand Down
35 changes: 35 additions & 0 deletions src/image_to_xyz_lab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,41 @@ pub fn srgba_to_xyza(
);
}

/// This function converts RGBA to CIE L*ab against D65 white point without alpha. This is much more effective than naive direct transformation
///
/// # Arguments
/// * `src` - A slice contains RGBA data
/// * `src_stride` - Bytes per row for src data.
/// * `width` - Image width
/// * `height` - Image height
/// * `dst` - A mutable slice to receive LAB data
/// * `dst_stride` - Bytes per row for dst data
/// * `a_plane` - A mutable slice to receive XYZ data
/// * `a_stride` - Bytes per row for dst data
pub fn rgba_to_lab(
src: &[u8],
src_stride: u32,
dst: &mut [f32],
dst_stride: u32,
a_plane: &mut [f32],
a_stride: u32,
width: u32,
height: u32,
) {
channels_to_xyz::<{ ImageConfiguration::Rgba as u8 }, false, { LAB as u8 }>(
src,
src_stride,
dst,
dst_stride,
a_plane,
a_stride,
width,
height,
&SRGB_TO_XYZ_D65,
TransferFunction::Srgb,
);
}

/// This function converts RGBA to CIE L*ab against D65 white point and preserving and normalizing alpha channels. This is much more effective than naive direct transformation
///
/// # Arguments
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ pub use image_to_xyz_lab::rgba_to_laba;
pub use image_to_xyz_lab::bgra_to_laba;
pub use image_to_xyz_lab::bgr_to_lab;
pub use image_to_xyz_lab::srgb_to_xyz;
pub use image_to_xyz_lab::rgba_to_lab;
pub use xyz_lab_to_image::xyz_to_rgb;
pub use xyz_lab_to_image::lab_to_srgb;
pub use xyz_lab_to_image::xyz_to_srgb;
Expand Down

0 comments on commit e164777

Please sign in to comment.