[librsvg: 20/23] feTurbulence - resolve and render separately
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 20/23] feTurbulence - resolve and render separately
- Date: Thu, 11 Mar 2021 23:12:24 +0000 (UTC)
commit cdea662f149ee7c874eb2aee394c6745327e5122
Author: Federico Mena Quintero <federico gnome org>
Date: Thu Mar 11 16:43:30 2021 -0600
feTurbulence - resolve and render separately
src/filters/mod.rs | 6 ++----
src/filters/turbulence.rs | 32 ++++++++++++++++++++++++++------
2 files changed, 28 insertions(+), 10 deletions(-)
---
diff --git a/src/filters/mod.rs b/src/filters/mod.rs
index bb524861..893bbae1 100644
--- a/src/filters/mod.rs
+++ b/src/filters/mod.rs
@@ -52,8 +52,6 @@ pub mod offset;
pub mod tile;
pub mod turbulence;
-use turbulence::FeTurbulence;
-
/// Resolved parameters for each filter primitive.
///
/// These gather all the data that a primitive may need during rendering:
@@ -76,7 +74,7 @@ pub enum PrimitiveParams {
Offset(offset::Offset),
SpecularLighting(lighting::SpecularLighting),
Tile(tile::Tile),
- Turbulence(Node),
+ Turbulence(turbulence::Turbulence),
}
/// The base filter primitive node containing common properties.
@@ -327,7 +325,7 @@ fn render_primitive(
(Element::FeOffset(_), Offset(p)) => p.render(ctx, acquired_nodes, draw_ctx),
(Element::FeSpecularLighting(_), SpecularLighting(p)) => p.render(ctx, acquired_nodes, draw_ctx),
(Element::FeTile(_), Tile(p)) => p.render(ctx, acquired_nodes, draw_ctx),
- (Element::FeTurbulence(ref inner), Turbulence(node)) =>
FeTurbulence::render(&inner.element_impl, &node, ctx, acquired_nodes, draw_ctx),
+ (Element::FeTurbulence(_), Turbulence(p)) => p.render(ctx, acquired_nodes, draw_ctx),
(_, _) => unreachable!(),
}
}
diff --git a/src/filters/turbulence.rs b/src/filters/turbulence.rs
index be0c71b5..44f37de4 100644
--- a/src/filters/turbulence.rs
+++ b/src/filters/turbulence.rs
@@ -7,6 +7,7 @@ use crate::element::{ElementResult, SetAttributes};
use crate::error::*;
use crate::node::{CascadedValues, Node};
use crate::parsers::{NonNegative, NumberOptionalNumber, Parse, ParseValue};
+use crate::property_defs::ColorInterpolationFilters;
use crate::surface_utils::{
shared_surface::{ExclusiveImageSurface, SurfaceType},
ImageSurfaceDataExt, Pixel, PixelOps,
@@ -41,6 +42,17 @@ pub struct FeTurbulence {
type_: NoiseType,
}
+/// Resolved `feTurbulence` primitive for rendering.
+pub struct Turbulence {
+ base: Primitive,
+ base_frequency: (f64, f64),
+ num_octaves: i32,
+ seed: i32,
+ stitch_tiles: StitchTiles,
+ type_: NoiseType,
+ color_interpolation_filters: ColorInterpolationFilters,
+}
+
impl Default for FeTurbulence {
/// Constructs a new `Turbulence` with empty properties.
#[inline]
@@ -323,10 +335,9 @@ impl NoiseGenerator {
}
}
-impl FeTurbulence {
+impl Turbulence {
pub fn render(
&self,
- node: &Node,
ctx: &FilterContext,
_acquired_nodes: &mut AcquiredNodes<'_>,
draw_ctx: &mut DrawingCtx,
@@ -345,11 +356,9 @@ impl FeTurbulence {
f64::from(bounds.height()),
);
- let cascaded = CascadedValues::new_from_node(node);
- let values = cascaded.get();
// The generated color values are in the color space determined by
// color-interpolation-filters.
- let surface_type = SurfaceType::from(values.color_interpolation_filters());
+ let surface_type = SurfaceType::from(self.color_interpolation_filters);
let mut surface = ExclusiveImageSurface::new(
ctx.source_graphic().width(),
@@ -404,7 +413,18 @@ impl FeTurbulence {
impl FilterEffect for FeTurbulence {
fn resolve(&self, node: &Node) -> Result<PrimitiveParams, FilterError> {
- Ok(PrimitiveParams::Turbulence(node.clone()))
+ let cascaded = CascadedValues::new_from_node(node);
+ let values = cascaded.get();
+
+ Ok(PrimitiveParams::Turbulence(Turbulence {
+ base: self.base.clone(),
+ base_frequency: self.base_frequency.clone(),
+ num_octaves: self.num_octaves.clone(),
+ seed: self.seed.clone(),
+ stitch_tiles: self.stitch_tiles.clone(),
+ type_: self.type_.clone(),
+ color_interpolation_filters: values.color_interpolation_filters(),
+ }))
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]