1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-30 13:20:05 -04:00

Improve the look of thin lines, making them look weaker (#2437)

* Revert "fix all clippy lints and remove them from allow list in cranky (#2419)"

This reverts commit 930ef2db38.

* Explain the cranky lints better

* Add Color32::gamma_multiply

* Remove unused pub use

* Remove non-existing crate category

* Improve color test with more lines

* Improve the look of thin lines, making them look weaker

Before they looked were too strong for the thickness.

* Use asserts for shader compilations

* Update changelogs
This commit is contained in:
Emil Ernerfeldt
2022-12-12 16:18:05 +01:00
committed by GitHub
parent 6c4fc50fdf
commit e0b5bb17e5
13 changed files with 55 additions and 25 deletions

View File

@@ -171,9 +171,29 @@ impl Color32 {
Rgba::from(*self).to_srgba_unmultiplied()
}
/// Multiply with 0.5 to make color half as opaque.
/// Multiply with 0.5 to make color half as opaque, perceptually.
///
/// Fast multiplication in gamma-space.
///
/// This is perceptually even, and faster that [`Self::linear_multiply`].
#[inline]
pub fn gamma_multiply(self, factor: f32) -> Color32 {
crate::ecolor_assert!(0.0 <= factor && factor <= 1.0);
let Self([r, g, b, a]) = self;
Self([
(r as f32 * factor + 0.5) as u8,
(g as f32 * factor + 0.5) as u8,
(b as f32 * factor + 0.5) as u8,
(a as f32 * factor + 0.5) as u8,
])
}
/// Multiply with 0.5 to make color half as opaque in linear space.
///
/// This is using linear space, which is not perceptually even.
/// You may want to use [`Self::gamma_multiply`] instead.
pub fn linear_multiply(self, factor: f32) -> Color32 {
crate::ecolor_assert!((0.0..=1.0).contains(&factor));
crate::ecolor_assert!(0.0 <= factor && factor <= 1.0);
// As an unfortunate side-effect of using premultiplied alpha
// we need a somewhat expensive conversion to linear space and back.
Rgba::from(self).multiply(factor).into()

View File

@@ -100,7 +100,7 @@ fn fast_round(r: f32) -> u8 {
pub fn test_srgba_conversion() {
for b in 0..=255 {
let l = linear_f32_from_gamma_u8(b);
assert!((0.0..=1.0).contains(&l));
assert!(0.0 <= l && l <= 1.0);
assert_eq!(gamma_u8_from_linear_f32(l), b);
}
}

View File

@@ -96,22 +96,22 @@ impl Rgba {
}
pub fn from_luminance_alpha(l: f32, a: f32) -> Self {
crate::ecolor_assert!((0.0..=1.0).contains(&l));
crate::ecolor_assert!((0.0..=1.0).contains(&a));
crate::ecolor_assert!(0.0 <= l && l <= 1.0);
crate::ecolor_assert!(0.0 <= a && a <= 1.0);
Self([l * a, l * a, l * a, a])
}
/// Transparent black
#[inline(always)]
pub fn from_black_alpha(a: f32) -> Self {
crate::ecolor_assert!((0.0..=1.0).contains(&a));
crate::ecolor_assert!(0.0 <= a && a <= 1.0);
Self([0.0, 0.0, 0.0, a])
}
/// Transparent white
#[inline(always)]
pub fn from_white_alpha(a: f32) -> Self {
crate::ecolor_assert!((0.0..=1.0).contains(&a), "a: {}", a);
crate::ecolor_assert!(0.0 <= a && a <= 1.0, "a: {}", a);
Self([a, a, a, a])
}