mirror of
https://forge.katzen.cafe/katzen-cafe/iowo.git
synced 2024-12-22 10:05:52 +01:00
svg-filters: blend node
This commit is contained in:
parent
f59062cf88
commit
e17fffb66b
6 changed files with 46 additions and 11 deletions
|
@ -1,10 +1,10 @@
|
|||
mod color_matrix;
|
||||
|
||||
mod blend;
|
||||
mod complex;
|
||||
mod gaussian_blur;
|
||||
mod offset;
|
||||
|
||||
mod blend {}
|
||||
mod component_transfer {}
|
||||
mod composite {}
|
||||
mod convolve_matrix {}
|
||||
|
|
20
crates/svg-filters/src/tests/blend.rs
Normal file
20
crates/svg-filters/src/tests/blend.rs
Normal file
|
@ -0,0 +1,20 @@
|
|||
use crate::{
|
||||
codegen::SvgDocument,
|
||||
types::nodes::{primitives::blend::BlendMode, standard_input::StandardInput},
|
||||
};
|
||||
|
||||
#[test]
|
||||
fn test_offset_blend() {
|
||||
let mut doc = SvgDocument::new();
|
||||
|
||||
let blend = doc.create_filter("blend");
|
||||
|
||||
let offset0 = blend.offset(StandardInput::SourceGraphic, 100., 0.);
|
||||
let offset1 = blend.offset(StandardInput::SourceGraphic, -100., 0.);
|
||||
blend.blend(offset0, offset1, BlendMode::Multiply);
|
||||
|
||||
assert_eq!(
|
||||
doc.generate_svg(),
|
||||
r#"<svg><filter id="blend"><feOffset dx="-100" dy="0" in="SourceGraphic" result="r7"/><feOffset dx="100" dy="0" in="SourceGraphic" result="r6"/><feBlend mode="multiply" in="r6" in2="r7"/></filter></svg>"#
|
||||
);
|
||||
}
|
|
@ -9,5 +9,5 @@ fn test_simple_blur() {
|
|||
assert_eq!(
|
||||
doc.generate_svg(),
|
||||
r#"<svg><filter id="blur"><feGaussianBlur stdDeviation="30 30" in="SourceGraphic"/></filter></svg>"#
|
||||
)
|
||||
);
|
||||
}
|
||||
|
|
|
@ -3,12 +3,12 @@ use crate::{codegen::SvgDocument, types::nodes::standard_input::StandardInput};
|
|||
#[test]
|
||||
fn test_offset_simple() {
|
||||
let mut doc = SvgDocument::new();
|
||||
let mut offset = doc.create_filter("offset");
|
||||
let offset = doc.create_filter("offset");
|
||||
|
||||
offset.offset(StandardInput::SourceGraphic, 25., -25.);
|
||||
|
||||
assert_eq!(
|
||||
doc.generate_svg(),
|
||||
r#"<svg><filter id="offset"><feOffset dx="25" dy="-25" in="SourceGraphic"/></filter></svg>"#
|
||||
)
|
||||
);
|
||||
}
|
||||
|
|
|
@ -1,11 +1,9 @@
|
|||
use std::fmt::{Debug, Display};
|
||||
|
||||
use petgraph::{data::Build, prelude::NodeIndex, prelude::*, visit::IntoNeighborsDirected};
|
||||
use petgraph::{prelude::NodeIndex, prelude::*};
|
||||
|
||||
use crate::Node;
|
||||
|
||||
use self::edge::Edge;
|
||||
|
||||
use super::nodes::standard_input::StandardInput;
|
||||
|
||||
#[derive(Debug)]
|
||||
|
@ -141,9 +139,12 @@ impl FilterGraph {
|
|||
}
|
||||
|
||||
pub mod abstracted_inputs {
|
||||
use petgraph::{data::Build, prelude::NodeIndex};
|
||||
use petgraph::prelude::NodeIndex;
|
||||
|
||||
use crate::{types::nodes::primitives::color_matrix::ColorMatrixType, Node};
|
||||
use crate::{
|
||||
types::nodes::primitives::{blend::BlendMode, color_matrix::ColorMatrixType},
|
||||
Node,
|
||||
};
|
||||
|
||||
use super::{FilterGraph, NodeInput};
|
||||
|
||||
|
@ -178,6 +179,20 @@ pub mod abstracted_inputs {
|
|||
node_idx
|
||||
}
|
||||
|
||||
pub fn blend(
|
||||
&mut self,
|
||||
r#in: impl Into<NodeInput>,
|
||||
in2: impl Into<NodeInput>,
|
||||
mode: BlendMode,
|
||||
) -> NodeIndex {
|
||||
let node_idx = self.dag.add_node(Node::blend(mode));
|
||||
self.dag
|
||||
.add_edge(self.resolve_input(r#in.into()), node_idx, ());
|
||||
self.dag
|
||||
.add_edge(self.resolve_input(in2.into()), node_idx, ());
|
||||
node_idx
|
||||
}
|
||||
|
||||
pub fn composite_arithmetic(
|
||||
&mut self,
|
||||
r#in: impl Into<NodeInput>,
|
||||
|
|
|
@ -82,7 +82,7 @@ pub enum FePrimitive {
|
|||
impl WriteElement for FePrimitive {
|
||||
fn attrs(&self) -> std::vec::Vec<quick_xml::events::attributes::Attribute<'_>> {
|
||||
match self {
|
||||
FePrimitive::Blend(_) => todo!(),
|
||||
FePrimitive::Blend(el) => el.attrs(),
|
||||
FePrimitive::ColorMatrix(el) => el.attrs(),
|
||||
FePrimitive::ComponentTransfer(_) => todo!(),
|
||||
FePrimitive::Composite(el) => el.attrs(),
|
||||
|
@ -103,7 +103,7 @@ impl WriteElement for FePrimitive {
|
|||
|
||||
fn tag_name(&self) -> &'static str {
|
||||
match self {
|
||||
FePrimitive::Blend(_) => todo!(),
|
||||
FePrimitive::Blend(el) => el.tag_name(),
|
||||
FePrimitive::ColorMatrix(el) => el.tag_name(),
|
||||
FePrimitive::ComponentTransfer(_) => todo!(),
|
||||
FePrimitive::Composite(el) => el.tag_name(),
|
||||
|
|
Loading…
Reference in a new issue