From 381147a250d401c96c2bbc9571ebcd4f034a53fe Mon Sep 17 00:00:00 2001 From: awxkee Date: Wed, 29 May 2024 08:58:08 +0100 Subject: [PATCH] Some bugfixes --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/app/src/main.rs | 2 -- src/concat_alpha.rs | 12 +++---- src/lib.rs | 2 ++ src/xyz_lab_to_image.rs | 77 +++++++++++++++++++++++++++++++++++++++-- 6 files changed, 85 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index df124fc..d77723a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -163,7 +163,7 @@ checksum = "3d7b894f5411737b7867f4827955924d7c254fc9f4d91a6aad6b097804b1018b" [[package]] name = "colorutils-rs" -version = "0.2.4" +version = "0.2.5" dependencies = [ "half", ] diff --git a/Cargo.toml b/Cargo.toml index ec7c0ae..9b547a2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ workspace = { members = ["src/app"] } [package] name = "colorutils-rs" -version = "0.2.4" +version = "0.2.5" edition = "2021" description = "Hig performance utilities for color format handling and conversion." readme = "README.md" diff --git a/src/app/src/main.rs b/src/app/src/main.rs index 3089598..7690e51 100644 --- a/src/app/src/main.rs +++ b/src/app/src/main.rs @@ -1,8 +1,6 @@ use colorutils_rs::*; use image::io::Reader as ImageReader; use image::{EncodableLayout, GenericImageView}; -#[cfg(target_arch = "aarch64")] -use std::arch::aarch64::*; #[cfg(target_arch = "x86_64")] use std::arch::x86_64::*; use std::mem::transmute; diff --git a/src/concat_alpha.rs b/src/concat_alpha.rs index ab30eee..628c079 100644 --- a/src/concat_alpha.rs +++ b/src/concat_alpha.rs @@ -30,18 +30,18 @@ pub fn append_alpha( let mut a_offset = 0usize; #[cfg(any(target_arch = "x86_64", target_arch = "x86"))] - let mut use_sse = false; + let mut _use_sse = false; #[cfg(any(target_arch = "x86_64", target_arch = "x86"))] - let mut use_avx = false; + let mut _use_avx = false; #[cfg(any(target_arch = "x86_64", target_arch = "x86"))] { if is_x86_feature_detected!("sse4.1") { - use_sse = true; + _use_sse = true; } if is_x86_feature_detected!("avx2") { - use_avx = true; + _use_avx = true; } } @@ -57,7 +57,7 @@ pub fn append_alpha( #[cfg(any(target_arch = "x86_64", target_arch = "x86"))] unsafe { - if use_avx { + if _use_avx { while cx + 8 < width as usize { let xyz_chan_ptr = src_ptr.add(cx * 3usize); let a_chan_ptr = a_ptr.add(cx); @@ -77,7 +77,7 @@ pub fn append_alpha( cx += 8; } } - if use_sse { + if _use_sse { while cx + 4 < width as usize { let xyz_chan_ptr = src_ptr.add(cx * 3usize); let a_chan_ptr = a_ptr.add(cx); diff --git a/src/lib.rs b/src/lib.rs index 315c268..54f8d50 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -62,6 +62,8 @@ 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; +pub use xyz_lab_to_image::laba_to_srgb; +pub use xyz_lab_to_image::xyza_to_rgba; pub use image_to_linear::*; pub use linear_to_image::*; pub use concat_alpha::append_alpha; diff --git a/src/xyz_lab_to_image.rs b/src/xyz_lab_to_image.rs index 93fdc55..13c8cb0 100644 --- a/src/xyz_lab_to_image.rs +++ b/src/xyz_lab_to_image.rs @@ -1,6 +1,5 @@ use std::slice; -use crate::{Lab, Xyz, XYZ_TO_SRGB_D65}; use crate::gamma_curves::TransferFunction; use crate::image::ImageConfiguration; use crate::image_to_xyz_lab::XyzTarget; @@ -10,6 +9,7 @@ use crate::image_to_xyz_lab::XyzTarget::{LAB, XYZ}; target_feature = "neon" ))] use crate::neon_xyz_lab_to_image::neon_xyz_to_channels; +use crate::{Lab, Xyz, XYZ_TO_SRGB_D65}; fn xyz_to_channels( src: &[f32], @@ -105,7 +105,8 @@ fn xyz_to_channels( + src, + src_stride, + &a_plane, + a_stride, + dst, + dst_stride, + width, + height, + &XYZ_TO_SRGB_D65, + TransferFunction::Srgb, + ); +} + +/// This function converts XYZ with separate alpha channel to RGBA. This is much more effective than naive direct transformation +/// +/// # Arguments +/// * `src` - A slice contains LAB data +/// * `src_stride` - Bytes per row for src data. +/// * `a_plane` - A slice contains Alpha data +/// * `a_stride` - Bytes per row for alpha plane data +/// * `dst` - A mutable slice to receive RGB data +/// * `dst_stride` - Bytes per row for dst data +/// * `width` - Image width +/// * `height` - Image height +pub fn xyza_to_rgba( + src: &[f32], + src_stride: u32, + a_plane: &[f32], + a_stride: u32, + dst: &mut [u8], + dst_stride: u32, + width: u32, + height: u32, + matrix: &[[f32; 3]; 3], + transfer_function: TransferFunction, +) { + xyz_to_channels::<{ ImageConfiguration::Rgba as u8 }, true, { XYZ as u8 }>( + src, + src_stride, + &a_plane, + a_stride, + dst, + dst_stride, + width, + height, + matrix, + transfer_function, + ); +}