diff options
| author | Ivan Molodetskikh <yalterz@gmail.com> | 2024-07-16 10:22:03 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-07-16 07:22:03 +0000 |
| commit | 3ace97660fde7fe1f0cc07a3925d1114af9a9c2f (patch) | |
| tree | 9d736a1d403875737566ad8817bb347a9e8056fe /niri-visual-tests/src/cases/gradient_oklch_increasing.rs | |
| parent | 0824737757d10cbeb844871c3f67756ca969cf7c (diff) | |
| download | niri-3ace97660fde7fe1f0cc07a3925d1114af9a9c2f.tar.gz niri-3ace97660fde7fe1f0cc07a3925d1114af9a9c2f.tar.bz2 niri-3ace97660fde7fe1f0cc07a3925d1114af9a9c2f.zip | |
Implement gradient color interpolation option (#548)
* Added the better color averaging code (tested & functional)
* rustfmt
* Make Color f32 0..1, clarify premul/unpremul
* Fix imports and test name
* Premultiply gradient colors matching CSS
* Fix indentation
* fixup
* Add gradient image
---------
Co-authored-by: K's Thinkpad <K.T.Kraft@protonmail.com>
Diffstat (limited to 'niri-visual-tests/src/cases/gradient_oklch_increasing.rs')
| -rw-r--r-- | niri-visual-tests/src/cases/gradient_oklch_increasing.rs | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/niri-visual-tests/src/cases/gradient_oklch_increasing.rs b/niri-visual-tests/src/cases/gradient_oklch_increasing.rs new file mode 100644 index 00000000..2a020923 --- /dev/null +++ b/niri-visual-tests/src/cases/gradient_oklch_increasing.rs @@ -0,0 +1,53 @@ +use niri::render_helpers::border::BorderRenderElement; +use niri_config::{ + Color, CornerRadius, GradientColorSpace, GradientInterpolation, HueInterpolation, +}; +use smithay::backend::renderer::element::RenderElement; +use smithay::backend::renderer::gles::GlesRenderer; +use smithay::utils::{Logical, Physical, Rectangle, Size}; + +use super::TestCase; + +pub struct GradientOklchIncreasing { + gradient_format: GradientInterpolation, +} + +impl GradientOklchIncreasing { + pub fn new(_size: Size<i32, Logical>) -> Self { + Self { + gradient_format: GradientInterpolation { + color_space: GradientColorSpace::Oklch, + hue_interpolation: HueInterpolation::Increasing, + }, + } + } +} + +impl TestCase for GradientOklchIncreasing { + fn render( + &mut self, + _renderer: &mut GlesRenderer, + size: Size<i32, Physical>, + ) -> Vec<Box<dyn RenderElement<GlesRenderer>>> { + let (a, b) = (size.w / 6, size.h / 3); + let size = (size.w - a * 2, size.h - b * 2); + let area = Rectangle::from_loc_and_size((a, b), size).to_f64(); + + [BorderRenderElement::new( + area.size, + Rectangle::from_loc_and_size((0., 0.), area.size), + self.gradient_format, + Color::new_unpremul(1., 0., 0., 1.), + Color::new_unpremul(0., 1., 0., 1.), + 0., + Rectangle::from_loc_and_size((0., 0.), area.size), + 0., + CornerRadius::default(), + 1., + ) + .with_location(area.loc)] + .into_iter() + .map(|elem| Box::new(elem) as _) + .collect() + } +} |
