[librsvg: 11/23] feDisplacementMap - resolve and render separately
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 11/23] feDisplacementMap - resolve and render separately
- Date: Thu, 11 Mar 2021 23:12:24 +0000 (UTC)
commit 67063f040df6ceb3e513cd84f09667dc1c000114
Author: Federico Mena Quintero <federico gnome org>
Date: Thu Mar 11 14:19:33 2021 -0600
feDisplacementMap - resolve and render separately
src/filters/displacement_map.rs | 38 ++++++++++++++++++++++++++++++--------
src/filters/mod.rs | 5 ++---
2 files changed, 32 insertions(+), 11 deletions(-)
---
diff --git a/src/filters/displacement_map.rs b/src/filters/displacement_map.rs
index f2aee635..0cd16e8b 100644
--- a/src/filters/displacement_map.rs
+++ b/src/filters/displacement_map.rs
@@ -33,6 +33,17 @@ pub struct FeDisplacementMap {
y_channel_selector: ColorChannel,
}
+/// Resolved `feDisplacementMap` primitive for rendering.
+pub struct DisplacementMap {
+ base: Primitive,
+ in1: Input,
+ in2: Input,
+ scale: f64,
+ x_channel_selector: ColorChannel,
+ y_channel_selector: ColorChannel,
+ color_interpolation_filters: ColorInterpolationFilters,
+}
+
impl Default for FeDisplacementMap {
/// Constructs a new `DisplacementMap` with empty properties.
#[inline]
@@ -71,18 +82,13 @@ impl SetAttributes for FeDisplacementMap {
}
}
-impl FeDisplacementMap {
+impl DisplacementMap {
pub fn render(
&self,
- node: &Node,
ctx: &FilterContext,
acquired_nodes: &mut AcquiredNodes<'_>,
draw_ctx: &mut DrawingCtx,
) -> Result<FilterResult, FilterError> {
- let cascaded = CascadedValues::new_from_node(node);
- let values = cascaded.get();
- let cif = values.color_interpolation_filters();
-
// https://www.w3.org/TR/filter-effects/#feDisplacementMapElement
// "The color-interpolation-filters property only applies to
// the in2 source image and does not apply to the in source
@@ -95,7 +101,12 @@ impl FeDisplacementMap {
&self.in1,
ColorInterpolationFilters::Auto,
)?;
- let displacement_input = ctx.get_input(acquired_nodes, draw_ctx, &self.in2, cif)?;
+ let displacement_input = ctx.get_input(
+ acquired_nodes,
+ draw_ctx,
+ &self.in2,
+ self.color_interpolation_filters,
+ )?;
let bounds = self
.base
.get_bounds(ctx)?
@@ -158,7 +169,18 @@ impl FeDisplacementMap {
impl FilterEffect for FeDisplacementMap {
fn resolve(&self, node: &Node) -> Result<PrimitiveParams, FilterError> {
- Ok(PrimitiveParams::DisplacementMap(node.clone()))
+ let cascaded = CascadedValues::new_from_node(node);
+ let values = cascaded.get();
+
+ Ok(PrimitiveParams::DisplacementMap(DisplacementMap {
+ base: self.base.clone(),
+ in1: self.in1.clone(),
+ in2: self.in2.clone(),
+ scale: self.scale.clone(),
+ x_channel_selector: self.x_channel_selector.clone(),
+ y_channel_selector: self.y_channel_selector.clone(),
+ color_interpolation_filters: values.color_interpolation_filters(),
+ }))
}
}
diff --git a/src/filters/mod.rs b/src/filters/mod.rs
index 013a0f8f..1607119f 100644
--- a/src/filters/mod.rs
+++ b/src/filters/mod.rs
@@ -52,7 +52,6 @@ pub mod offset;
pub mod tile;
pub mod turbulence;
-use displacement_map::FeDisplacementMap;
use flood::FeFlood;
use gaussian_blur::FeGaussianBlur;
use image::FeImage;
@@ -76,7 +75,7 @@ pub enum PrimitiveParams {
Composite(composite::Composite),
ConvolveMatrix(convolve_matrix::ConvolveMatrix),
DiffuseLighting(Node),
- DisplacementMap(Node),
+ DisplacementMap(displacement_map::DisplacementMap),
Flood(Node),
GaussianBlur(Node),
Image(Node),
@@ -327,7 +326,7 @@ fn render_primitive(
(Element::FeComposite(_), Composite(p)) => p.render(ctx, acquired_nodes, draw_ctx),
(Element::FeConvolveMatrix(_), ConvolveMatrix(p)) => p.render(ctx, acquired_nodes, draw_ctx),
(Element::FeDiffuseLighting(ref inner), DiffuseLighting(node)) =>
FeDiffuseLighting::render(&inner.element_impl, &node, ctx, acquired_nodes, draw_ctx),
- (Element::FeDisplacementMap(ref inner), DisplacementMap(node)) =>
FeDisplacementMap::render(&inner.element_impl, &node, ctx, acquired_nodes, draw_ctx),
+ (Element::FeDisplacementMap(_), DisplacementMap(p)) => p.render(ctx, acquired_nodes, draw_ctx),
(Element::FeFlood(ref inner), Flood(node)) =>
FeFlood::render(&inner.element_impl, &node, ctx, acquired_nodes, draw_ctx),
(Element::FeGaussianBlur(ref inner), GaussianBlur(node)) =>
FeGaussianBlur::render(&inner.element_impl, &node, ctx, acquired_nodes, draw_ctx),
(Element::FeImage(ref inner), Image(node)) =>
FeImage::render(&inner.element_impl, &node, ctx, acquired_nodes, draw_ctx),
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]