Skip to content

Commit a6b9350

Browse files
committed
add inline rules to Color funcs
1 parent 45ef4c1 commit a6b9350

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/color/model.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ impl Color {
5353
pub const BLUE: Self = Self::new(0, 0, 255, 255);
5454
pub const WHITE: Self = Self::new(255, 255, 255, 255);
5555

56+
#[must_use]
5657
#[inline]
5758
pub const fn new(r: u8, g: u8, b: u8, a: u8) -> Self {
5859
Self { r, g, b, a }
@@ -94,6 +95,8 @@ impl Color {
9495
])
9596
}
9697

98+
#[must_use]
99+
#[inline]
97100
pub fn lerp_oklch(self, other: Color, t: ColorFloat) -> Color {
98101
let t = t.clamp(0.0, 1.0);
99102
let [l1, c1, h1] = self.into_oklch();
@@ -163,6 +166,7 @@ impl Color {
163166
// Blend this color over a bg using the given blend mode
164167
// Math done in linear space, output encoded back to sRGB with straight alpha
165168
#[must_use]
169+
#[inline]
166170
pub fn blend_over(self, bg: Color, mode: BlendMode) -> Color {
167171
use BlendMode::*;
168172

@@ -296,6 +300,7 @@ impl Color {
296300
}
297301
}
298302

303+
#[must_use]
299304
#[inline]
300305
pub const fn from_rgb(rgb: [u8; 3]) -> Self {
301306
Self {
@@ -312,6 +317,7 @@ impl Color {
312317
[self.r, self.g, self.b]
313318
}
314319

320+
#[must_use]
315321
#[inline]
316322
pub const fn from_rgba(rgba: [u8; 4]) -> Self {
317323
Self {
@@ -647,11 +653,13 @@ impl Color {
647653
}
648654

649655
// helpers for non-separable blend modes
656+
#[inline]
650657
fn lum(c: [ColorFloat; 3]) -> ColorFloat {
651658
let [r, g, b] = c;
652659
0.3 * r + 0.59 * g + 0.11 * b
653660
}
654661

662+
#[inline]
655663
fn clip_color(c: [ColorFloat; 3]) -> [ColorFloat; 3] {
656664
let [r, g, b] = c;
657665
let l = Self::lum(c);
@@ -674,17 +682,20 @@ impl Color {
674682
}
675683
}
676684

685+
#[inline]
677686
fn set_lum(c: [ColorFloat; 3], l: ColorFloat) -> [ColorFloat; 3] {
678687
let [r, g, b] = c;
679688
let d = l - Self::lum(c);
680689
Self::clip_color([r + d, g + d, b + d])
681690
}
682691

692+
#[inline]
683693
fn sat(c: [ColorFloat; 3]) -> ColorFloat {
684694
let [r, g, b] = c;
685695
r.max(g).max(b) - r.min(g).min(b)
686696
}
687697

698+
#[inline]
688699
fn set_sat(c: [ColorFloat; 3], s: ColorFloat) -> [ColorFloat; 3] {
689700
let [r, g, b] = c;
690701
let max: ColorFloat;

0 commit comments

Comments
 (0)