Skip to content

Commit

Permalink
Linearize bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
awxkee committed May 28, 2024
1 parent 5ae972e commit 997efed
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 28 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.2"
version = "0.2.3"
edition = "2021"
description = "Hig performance utilities for color format handling and conversion."
readme = "README.md"
Expand Down
50 changes: 26 additions & 24 deletions src/app/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,26 +46,26 @@ fn main() {
println!("dimensions {:?}", img.dimensions());

println!("{:?}", img.color());
let src_bytes = img.as_bytes();
let mut src_bytes = img.as_bytes();
let width = dimensions.0;
let height = dimensions.1;
let components = 3;
let components = 4;

let mut dst_rgba = vec![];
dst_rgba.resize(4usize * width as usize * height as usize, 0u8);
// let rgba = &rgb_to_rgba(
// &src_bytes,
// 3u32 * width,
// &mut dst_rgba,
// 4u32 * width,
// width,
// height,
// 255,
// );
// src_bytes = rgba;
rgb_to_rgba(
&src_bytes,
3u32 * width,
&mut dst_rgba,
4u32 * width,
width,
height,
255,
);
src_bytes = &dst_rgba;

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

let mut a_plane: Vec<f32> = vec![];
a_plane.resize(width as usize * height as usize, 0f32);
Expand All @@ -82,15 +82,7 @@ fn main() {
// width,
// height,
// );
rgb_to_lab(
src_bytes,
width * components,
&mut xyz,
width * 3 * std::mem::size_of::<f32>() as u32,
width,
height,
);
// rgb_to_linear(
// rgba_to_linear(
// src_bytes,
// width * components,
// &mut xyz,
Expand All @@ -99,6 +91,15 @@ fn main() {
// height,
// TransferFunction::Srgb,
// );
rgba_to_linear(
src_bytes,
width * components,
&mut xyz,
width * 4 * std::mem::size_of::<f32>() as u32,
width,
height,
TransferFunction::Srgb,
);
let elapsed_time = start_time.elapsed();
// Print the elapsed time in milliseconds
println!("sRGB to XYZ: {:.2?}", elapsed_time);
Expand All @@ -117,13 +118,14 @@ fn main() {
// height,
// );

lab_to_srgb(
linear_to_rgba(
&xyz,
width * 3 * std::mem::size_of::<f32>() as u32,
width * 4 * std::mem::size_of::<f32>() as u32,
&mut dst_bytes,
width * components,
width,
height,
TransferFunction::Srgb,
);

// linear_to_rgb(
Expand Down
2 changes: 1 addition & 1 deletion src/image_to_linear.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ pub fn rgba_to_linear(
height: u32,
transfer_function: TransferFunction,
) {
channels_to_linear::<{ ImageConfiguration::Rgba as u8 }, false>(
channels_to_linear::<{ ImageConfiguration::Rgba as u8 }, true>(
src,
src_stride,
dst,
Expand Down
2 changes: 1 addition & 1 deletion src/linear_to_image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ pub fn linear_to_rgba(
height: u32,
transfer_function: TransferFunction,
) {
linear_to_gamma_channels::<{ ImageConfiguration::Rgba as u8 }, false>(
linear_to_gamma_channels::<{ ImageConfiguration::Rgba as u8 }, true>(
src,
src_stride,
dst,
Expand Down

0 comments on commit 997efed

Please sign in to comment.