Skip to content

Commit c93b2c7

Browse files
committed
Added Jzazbz and Jzczhz
1 parent 103c4ea commit c93b2c7

File tree

13 files changed

+61
-25
lines changed

13 files changed

+61
-25
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ workspace = { members = ["src/app"] }
22

33
[package]
44
name = "colorutils-rs"
5-
version = "0.4.17"
5+
version = "0.5.0"
66
edition = "2021"
77
description = "High performance utilities for color format handling and conversion."
88
readme = "README.md"

src/hsl.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ pub struct Hsl {
1818
}
1919

2020
impl Hsl {
21+
#[inline]
2122
pub fn new(h: u16, s: u16, l: u16) -> Hsl {
2223
Hsl {
2324
h: h as f32,
@@ -26,14 +27,17 @@ impl Hsl {
2627
}
2728
}
2829

30+
#[inline]
2931
pub fn from_components(h: f32, s: f32, l: f32) -> Hsl {
3032
Hsl { h, s, l }
3133
}
3234

33-
pub fn from_rgb(rgb: &Rgb<u8>) -> Hsl {
35+
#[inline]
36+
pub fn from_rgb(rgb: Rgb<u8>) -> Hsl {
3437
rgb2hsl(rgb.r, rgb.g, rgb.b)
3538
}
3639

40+
#[inline]
3741
pub fn to_rgb8(&self) -> Rgb<u8> {
3842
let c = (1f32 - (2f32 * self.l - 1f32).abs()) * self.s;
3943
let x = c * (1f32 - ((self.h / 60f32) % 2f32 - 1f32).abs());
@@ -60,23 +64,28 @@ impl Hsl {
6064
}
6165
}
6266

67+
#[inline]
6368
pub fn to_rgb(&self) -> Rgb<u8> {
6469
self.to_rgb8()
6570
}
6671

72+
#[inline]
6773
pub fn get_saturation(&self) -> u16 {
6874
((self.s * 100f32) as u16).min(100u16)
6975
}
7076

77+
#[inline]
7178
pub fn get_lightness(&self) -> u16 {
7279
((self.l * 100f32) as u16).min(100u16)
7380
}
7481

82+
#[inline]
7583
pub fn get_hue(&self) -> u16 {
7684
(self.h as u16).min(360)
7785
}
7886
}
7987

88+
#[inline]
8089
fn rgb2hsl(o_r: u8, o_g: u8, o_b: u8) -> Hsl {
8190
let r = o_r as f32 / 255f32;
8291
let g = o_g as f32 / 255f32;

src/hsv.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ static HSV_U8_SCALE: f32 = 1f32 / 255f32;
2121
static HSV_PERCENTAGE_SCALE: f32 = 1f32 / 100f32;
2222

2323
impl Hsv {
24+
#[inline]
2425
pub fn new(h: u16, s: u16, l: u16) -> Hsv {
2526
Hsv {
2627
h: h as f32,
@@ -33,7 +34,7 @@ impl Hsv {
3334
Hsv { h, s, v }
3435
}
3536
#[inline]
36-
pub fn from(rgb: &Rgb<u8>) -> Hsv {
37+
pub fn from(rgb: Rgb<u8>) -> Hsv {
3738
let (h, s, v) = rgb_to_hsv(
3839
rgb.r as f32 * HSV_U8_SCALE,
3940
rgb.g as f32 * HSV_U8_SCALE,

src/image_to_xyz_lab.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ fn channels_to_xyz<const CHANNELS_CONFIGURATION: u8, const USE_ALPHA: bool, cons
220220
}
221221
}
222222
XyzTarget::XYZ => {
223-
let xyz = Xyz::from_rgb(&rgb, &matrix, transfer_function);
223+
let xyz = Xyz::from_rgb(rgb, &matrix, transfer_function);
224224
unsafe {
225225
ptr.write_unaligned(xyz.x);
226226
ptr.add(1).write_unaligned(xyz.y);

src/image_xyza_laba.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ fn channels_to_xyz_with_alpha<const CHANNELS_CONFIGURATION: u8, const TARGET: u8
129129
}
130130
}
131131
XyzTarget::XYZ => {
132-
let xyz = Xyz::from_rgb(&rgb, &matrix, transfer_function);
132+
let xyz = Xyz::from_rgb(rgb, &matrix, transfer_function);
133133
unsafe {
134134
dst_store.write_unaligned(xyz.x);
135135
dst_store.add(1).write_unaligned(xyz.y);

src/lab.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ impl Lab {
3737
}
3838

3939
impl Lab {
40-
pub fn from_rgb(rgb: &Rgb<u8>) -> Self {
40+
/// Converts to CIE Lab from Rgb
41+
#[inline]
42+
pub fn from_rgb(rgb: Rgb<u8>) -> Self {
4143
let xyz = Xyz::from_srgb(rgb);
4244
let x = xyz.x * 100f32 / 95.047f32;
4345
let y = xyz.y * 100f32 / 100f32;
@@ -62,6 +64,8 @@ impl Lab {
6264
}
6365

6466
impl Lab {
67+
/// Converts CIE Lab into Rgb
68+
#[inline]
6569
pub fn to_rgb8(&self) -> Rgb<u8> {
6670
let y = (self.l + 16.0) / 116.0;
6771
let x = self.a * (1f32 / 500f32) + y;
@@ -93,18 +97,22 @@ impl Lab {
9397
Xyz::new(x / 100f32, y / 100f32, z / 100f32).to_srgb()
9498
}
9599

100+
/// Converts CIE Lab into Rgb
101+
#[inline]
96102
pub fn to_rgb(&self) -> Rgb<u8> {
97103
self.to_rgb8()
98104
}
99105
}
100106

101107
impl EuclideanDistance for Lab {
108+
#[inline]
102109
fn euclidean_distance(&self, other: Lab) -> f32 {
103110
(self.l - other.l).hypot3(self.a - other.a, self.b - other.b)
104111
}
105112
}
106113

107114
impl TaxicabDistance for Lab {
115+
#[inline]
108116
fn taxicab_distance(&self, other: Self) -> f32 {
109117
(self.a - other.a).hypot(self.b - other.b) + (self.l - other.l).abs()
110118
}

src/luv.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ pub(crate) const LUV_CUTOFF_FORWARD_Y: f32 = (6f32 / 29f32) * (6f32 / 29f32) * (
6868
pub(crate) const LUV_MULTIPLIER_FORWARD_Y: f32 = (29f32 / 3f32) * (29f32 / 3f32) * (29f32 / 3f32);
6969
pub(crate) const LUV_MULTIPLIER_INVERSE_Y: f32 = (3f32 / 29f32) * (3f32 / 29f32) * (3f32 / 29f32);
7070
impl Luv {
71-
pub fn from_rgb(rgb: &Rgb<u8>) -> Self {
71+
/// Converts RGB to CIE Luv
72+
#[inline]
73+
pub fn from_rgb(rgb: Rgb<u8>) -> Self {
7274
let xyz = Xyz::from_srgb(rgb);
7375
let [x, y, z] = [xyz.x, xyz.y, xyz.z];
7476
let den = x + 15.0 * y + 3.0 * z;
@@ -94,8 +96,10 @@ impl Luv {
9496
Luv { l, u, v }
9597
}
9698

97-
pub fn from_rgba(rgba: &Rgba<u8>) -> Self {
98-
Luv::from_rgb(&rgba.to_rgb())
99+
//
100+
#[inline]
101+
pub fn from_rgba(rgba: Rgba<u8>) -> Self {
102+
Luv::from_rgb(rgba.to_rgb())
99103
}
100104

101105
pub fn to_rgb(&self) -> Rgb<u8> {
@@ -129,11 +133,11 @@ impl Luv {
129133
}
130134

131135
impl LCh {
132-
pub fn from_rgb(rgb: &Rgb<u8>) -> Self {
136+
pub fn from_rgb(rgb: Rgb<u8>) -> Self {
133137
LCh::from_luv(Luv::from_rgb(rgb))
134138
}
135139

136-
pub fn from_rgba(rgba: &Rgba<u8>) -> Self {
140+
pub fn from_rgba(rgba: Rgba<u8>) -> Self {
137141
LCh::from_luv(Luv::from_rgba(rgba))
138142
}
139143

src/neon/hsv_to_image.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,14 @@ pub unsafe fn neon_hsv_u16_to_image<
218218
let pixel_set = uint8x8x3_t(r_chan, g_chan, b_chan);
219219
vst3_u8(dst_ptr.add(cx * channels), pixel_set);
220220
}
221-
ImageConfiguration::Rgba => {}
222-
ImageConfiguration::Bgra => {}
221+
ImageConfiguration::Rgba => {
222+
let pixel_set = uint8x8x4_t(r_chan, g_chan, b_chan, vdup_n_u8(0));
223+
vst4_u8(dst_ptr.add(cx * channels), pixel_set);
224+
}
225+
ImageConfiguration::Bgra => {
226+
let pixel_set = uint8x8x4_t(b_chan, g_chan, r_chan, vdup_n_u8(0));
227+
vst4_u8(dst_ptr.add(cx * channels), pixel_set);
228+
}
223229
ImageConfiguration::Bgr => {
224230
let pixel_set = uint8x8x3_t(b_chan, g_chan, r_chan);
225231
vst3_u8(dst_ptr.add(cx * channels), pixel_set);

src/rgb.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,37 +32,37 @@ impl Rgb<u8> {
3232
/// Converts rgb to XYZ
3333
#[inline]
3434
pub fn to_xyz(&self, matrix: &[[f32; 3]; 3], transfer_function: TransferFunction) -> Xyz {
35-
Xyz::from_rgb(self, matrix, transfer_function)
35+
Xyz::from_rgb(*self, matrix, transfer_function)
3636
}
3737

3838
/// Converts rgb to HSL
3939
#[inline]
4040
pub fn to_hsl(&self) -> Hsl {
41-
Hsl::from_rgb(self)
41+
Hsl::from_rgb(*self)
4242
}
4343

4444
/// Converts rgb to HSV
4545
#[inline]
4646
pub fn to_hsv(&self) -> Hsv {
47-
Hsv::from(self)
47+
Hsv::from(*self)
4848
}
4949

5050
/// Converts rgb to CIELAB
5151
#[inline]
5252
pub fn to_lab(&self) -> Lab {
53-
Lab::from_rgb(self)
53+
Lab::from_rgb(*self)
5454
}
5555

5656
/// Converts rgb to CIELUV
5757
#[inline]
5858
pub fn to_luv(&self) -> Luv {
59-
Luv::from_rgb(self)
59+
Luv::from_rgb(*self)
6060
}
6161

6262
/// Converts rgb to CIELCH
6363
#[inline]
6464
pub fn to_lch(&self) -> LCh {
65-
LCh::from_rgb(self)
65+
LCh::from_rgb(*self)
6666
}
6767

6868
/// Converts rgb to RGB f32
@@ -79,7 +79,7 @@ impl Rgb<u8> {
7979
/// Converts rgb to S-shaped sigmoidized components
8080
#[inline]
8181
pub fn to_sigmoidal(&self) -> Sigmoidal {
82-
Sigmoidal::from_rgb(self)
82+
Sigmoidal::from_rgb(*self)
8383
}
8484
}
8585

src/rgba.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,24 @@ impl Rgba<f16> {
3737
}
3838

3939
impl Rgba<f32> {
40+
#[inline]
4041
pub fn new(r: f32, g: f32, b: f32, a: f32) -> Rgba<f32> {
4142
return Rgba { r, g, b, a };
4243
}
4344

45+
#[inline]
4446
pub fn from_rgb(r: f32, g: f32, b: f32) -> Rgba<f32> {
4547
return Rgba { r, g, b, a: 1f32 };
4648
}
4749
}
4850

4951
impl Rgba<u8> {
52+
#[inline]
5053
pub fn new(r: u8, g: u8, b: u8, a: u8) -> Rgba<u8> {
5154
return Rgba { r, g, b, a };
5255
}
5356

57+
#[inline]
5458
pub fn from_rgb(r: u8, g: u8, b: u8) -> Rgba<u8> {
5559
return Rgba {
5660
r,
@@ -60,6 +64,7 @@ impl Rgba<u8> {
6064
};
6165
}
6266

67+
#[inline]
6368
pub fn to_rgb(&self) -> Rgb<u8> {
6469
Rgb {
6570
r: self.r,
@@ -161,6 +166,7 @@ impl Rgb565 {
161166
}
162167

163168
impl ToRgba8 for Rgb565 {
169+
#[inline]
164170
fn to_rgba8(&self) -> Rgba<u8> {
165171
let red8 = ((self.rgb565 & 0b1111100000000000) >> 8) as u8;
166172
let green8 = ((self.rgb565 & 0b11111100000) >> 3) as u8;
@@ -173,6 +179,7 @@ static SCALE_RGB565_5BIT: f32 = 1f32 / 31f32;
173179
static SCALE_RGB565_6BIT: f32 = 1f32 / 63f32;
174180

175181
impl ToRgbaF16 for Rgb565 {
182+
#[inline]
176183
fn to_rgba_f16(&self) -> Rgba<f16> {
177184
let red5 = (self.rgb565 & 0b1111100000000000) as f32 * SCALE_RGB565_5BIT;
178185
let green6 = (self.rgb565 & 0b11111100000) as f32 * SCALE_RGB565_6BIT;

src/sigmoidal.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,13 @@ fn inverse_sigmoidal(x: f32) -> f32 {
4040
}
4141

4242
impl Sigmoidal {
43+
#[inline]
4344
pub fn new(sr: f32, sg: f32, sb: f32) -> Self {
4445
Sigmoidal { sr, sg, sb }
4546
}
4647

4748
#[inline]
48-
pub fn from_rgb(rgb: &Rgb<u8>) -> Self {
49+
pub fn from_rgb(rgb: Rgb<u8>) -> Self {
4950
let normalized = rgb.to_rgb_f32();
5051
Sigmoidal::new(
5152
to_sigmoidal(normalized.r),
@@ -68,7 +69,7 @@ impl Sigmoidal {
6869
impl From<Rgb<u8>> for Sigmoidal {
6970
#[inline]
7071
fn from(value: Rgb<u8>) -> Self {
71-
Sigmoidal::from_rgb(&value)
72+
Sigmoidal::from_rgb(value)
7273
}
7374
}
7475

src/xyz.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ impl Xyz {
5353

5454
/// This functions always use sRGB transfer function and Rec.601 primaries with D65 White point
5555
#[inline]
56-
pub fn from_srgb(rgb: &Rgb<u8>) -> Self {
56+
pub fn from_srgb(rgb: Rgb<u8>) -> Self {
5757
Xyz::from_rgb(rgb, &SRGB_TO_XYZ_D65, TransferFunction::Srgb)
5858
}
5959

@@ -63,7 +63,7 @@ impl Xyz {
6363
/// * `transfer_function` - Transfer functions for current colorspace
6464
#[inline]
6565
pub fn from_rgb(
66-
rgb: &Rgb<u8>,
66+
rgb: Rgb<u8>,
6767
matrix: &[[f32; 3]; 3],
6868
transfer_function: TransferFunction,
6969
) -> Self {

0 commit comments

Comments
 (0)