1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-29 04:40:03 -04:00

Improve text redering and do all color operation in gamma space (#2071)

This commit is contained in:
Emil Ernerfeldt
2022-09-24 17:53:11 +02:00
committed by GitHub
parent 29fa63317e
commit 4ac1e28eae
36 changed files with 468 additions and 733 deletions

View File

@@ -4,6 +4,7 @@ All notable changes to the epaint crate will be documented in this file.
## Unreleased
* ⚠️ BREAKING: Fix text being too small ([#2069](https://github.com/emilk/egui/pull/2069)).
* ⚠️ BREAKING: epaint now expects integrations to do all color blending in gamma space ([#2071](https://github.com/emilk/egui/pull/2071)).
## 0.19.0 - 2022-08-20

View File

@@ -326,7 +326,7 @@ impl Rgba {
/// Transparent white
#[inline(always)]
pub fn from_white_alpha(a: f32) -> Self {
crate::epaint_assert!(0.0 <= a && a <= 1.0);
crate::epaint_assert!(0.0 <= a && a <= 1.0, "a: {}", a);
Self([a, a, a, a])
}

View File

@@ -195,17 +195,19 @@ impl FontImage {
/// Returns the textures as `sRGBA` premultiplied pixels, row by row, top to bottom.
///
/// `gamma` should normally be set to 1.0.
/// If you are having problems with text looking skinny and pixelated, try
/// setting a lower gamma, e.g. `0.5`.
pub fn srgba_pixels(&'_ self, gamma: f32) -> impl ExactSizeIterator<Item = Color32> + '_ {
/// `gamma` should normally be set to `None`.
///
/// If you are having problems with text looking skinny and pixelated, try using a low gamma, e.g. `0.4`.
pub fn srgba_pixels(
&'_ self,
gamma: Option<f32>,
) -> impl ExactSizeIterator<Item = Color32> + '_ {
let gamma = gamma.unwrap_or(0.55); // TODO(emilk): this default coverage gamma is a magic constant, chosen by eye. I don't even know why we need it.
self.pixels.iter().map(move |coverage| {
// This is arbitrarily chosen to make text look as good as possible.
// In particular, it looks good with gamma=1 and the default eframe backend,
// which uses linear blending.
// See https://github.com/emilk/egui/issues/1410
let a = fast_round(coverage.powf(gamma / 2.2) * 255.0);
Color32::from_rgba_premultiplied(a, a, a, a) // this makes no sense, but works
let alpha = coverage.powf(gamma);
// We want to multiply with `vec4(alpha)` in the fragment shader:
let a = fast_round(alpha * 255.0);
Color32::from_rgba_premultiplied(a, a, a, a)
})
}

View File

@@ -14,7 +14,7 @@ pub struct Shadow {
}
impl Shadow {
/// Tooltips, menus, …
/// Tooltips, menus, …, for dark mode.
pub fn small_dark() -> Self {
Self {
extrusion: 16.0,
@@ -22,15 +22,15 @@ impl Shadow {
}
}
/// Tooltips, menus, …
/// Tooltips, menus, …, for light mode.
pub fn small_light() -> Self {
Self {
extrusion: 16.0,
color: Color32::from_black_alpha(32),
color: Color32::from_black_alpha(20),
}
}
/// Subtle and nice on dark backgrounds
/// Used for widnows in dark mode.
pub fn big_dark() -> Self {
Self {
extrusion: 32.0,
@@ -38,11 +38,11 @@ impl Shadow {
}
}
/// Subtle and nice on white backgrounds
/// Used for widnows in light mode.
pub fn big_light() -> Self {
Self {
extrusion: 32.0,
color: Color32::from_black_alpha(40),
color: Color32::from_black_alpha(16),
}
}