forked from katzen-cafe/iowo
svg-filters: more testssss
This commit is contained in:
parent
02c5e9e159
commit
ae86ae29ab
6 changed files with 124 additions and 53 deletions
|
@ -1,56 +1,17 @@
|
|||
mod color_matrix;
|
||||
|
||||
mod blend;
|
||||
mod color_matrix;
|
||||
mod complex;
|
||||
mod component_transfer;
|
||||
mod displacement_map;
|
||||
mod flood;
|
||||
mod gaussian_blur;
|
||||
mod offset;
|
||||
|
||||
mod component_transfer {
|
||||
use crate::{
|
||||
codegen::SvgDocument,
|
||||
types::nodes::primitives::{
|
||||
component_transfer::{ComponentTransfer, TransferFn},
|
||||
FePrimitive,
|
||||
},
|
||||
Node,
|
||||
};
|
||||
|
||||
#[test]
|
||||
fn test_comp_trans_simple() {
|
||||
let mut doc = SvgDocument::new();
|
||||
|
||||
let comptrans = doc.create_filter("comp_trans");
|
||||
|
||||
comptrans.add_node(Node::simple(FePrimitive::ComponentTransfer(
|
||||
ComponentTransfer {
|
||||
func_r: TransferFn::Table {
|
||||
table_values: vec![0., 0.1, 0.4, 0.9],
|
||||
},
|
||||
func_g: TransferFn::Discrete {
|
||||
table_values: vec![0.1, 0.3, 0.5, 0.7, 0.9],
|
||||
},
|
||||
func_b: TransferFn::Linear {
|
||||
slope: 1.0,
|
||||
intercept: 0.75,
|
||||
},
|
||||
func_a: TransferFn::Identity,
|
||||
},
|
||||
)));
|
||||
|
||||
assert_eq!(
|
||||
doc.generate_svg(),
|
||||
r#"<svg><filter id="comp_trans"><feComponentTransfer><feFuncR type="table" tableValues="0 0.1 0.4 0.9"/><feFuncG type="discrete" tableValues="0.1 0.3 0.5 0.7 0.9"/><feFuncB type="linear" slope="1" intercept="0.75"/><feFuncA type="identity"/></feComponentTransfer></filter></svg>"#
|
||||
);
|
||||
}
|
||||
}
|
||||
mod turbulence;
|
||||
mod composite {}
|
||||
mod convolve_matrix {}
|
||||
mod diffuse_lighting {}
|
||||
mod displacement_map {}
|
||||
mod flood {}
|
||||
mod image {}
|
||||
mod merge {}
|
||||
mod morphology {}
|
||||
mod specular_lighting {}
|
||||
mod tile {}
|
||||
mod turbulence {}
|
||||
|
|
36
crates/svg-filters/src/tests/component_transfer.rs
Normal file
36
crates/svg-filters/src/tests/component_transfer.rs
Normal file
|
@ -0,0 +1,36 @@
|
|||
use crate::{
|
||||
codegen::SvgDocument,
|
||||
types::nodes::primitives::{
|
||||
component_transfer::{ComponentTransfer, TransferFn},
|
||||
FePrimitive,
|
||||
},
|
||||
Node,
|
||||
};
|
||||
|
||||
#[test]
|
||||
fn test_comp_trans_simple() {
|
||||
let mut doc = SvgDocument::new();
|
||||
|
||||
let comptrans = doc.create_filter("comp_trans");
|
||||
|
||||
comptrans.add_node(Node::simple(FePrimitive::ComponentTransfer(
|
||||
ComponentTransfer {
|
||||
func_r: TransferFn::Table {
|
||||
table_values: vec![0., 0.1, 0.4, 0.9],
|
||||
},
|
||||
func_g: TransferFn::Discrete {
|
||||
table_values: vec![0.1, 0.3, 0.5, 0.7, 0.9],
|
||||
},
|
||||
func_b: TransferFn::Linear {
|
||||
slope: 1.0,
|
||||
intercept: 0.75,
|
||||
},
|
||||
func_a: TransferFn::Identity,
|
||||
},
|
||||
)));
|
||||
|
||||
assert_eq!(
|
||||
doc.generate_svg(),
|
||||
r#"<svg><filter id="comp_trans"><feComponentTransfer><feFuncR type="table" tableValues="0 0.1 0.4 0.9"/><feFuncG type="discrete" tableValues="0.1 0.3 0.5 0.7 0.9"/><feFuncB type="linear" slope="1" intercept="0.75"/><feFuncA type="identity"/></feComponentTransfer></filter></svg>"#
|
||||
);
|
||||
}
|
32
crates/svg-filters/src/tests/displacement_map.rs
Normal file
32
crates/svg-filters/src/tests/displacement_map.rs
Normal file
|
@ -0,0 +1,32 @@
|
|||
use crate::{
|
||||
codegen::SvgDocument,
|
||||
types::nodes::{
|
||||
primitives::{
|
||||
displacement_map::Channel,
|
||||
turbulence::{NoiseType, StitchTiles},
|
||||
},
|
||||
standard_input::StandardInput,
|
||||
},
|
||||
};
|
||||
|
||||
#[test]
|
||||
fn test_displacement_map_simple() {
|
||||
let mut doc = SvgDocument::new();
|
||||
|
||||
let displace = doc.create_filter("displace");
|
||||
|
||||
let simple_noise =
|
||||
displace.turbulence(0.01, 0.01, 1, 0, StitchTiles::Stitch, NoiseType::Turbulence);
|
||||
displace.displacement_map(
|
||||
StandardInput::SourceGraphic,
|
||||
simple_noise,
|
||||
128.,
|
||||
Channel::R,
|
||||
Channel::R,
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
doc.generate_svg(),
|
||||
r#"<svg><filter id="displace"><feTurbulence baseFrequency="0.01 0.01" stitchTiles="stitch" result="r6"/><feDisplacementMap scale="128" xChannelSelector="R" yChannelSelector="R" in="SourceGraphic" in2="r6"/></filter></svg>"#
|
||||
);
|
||||
}
|
17
crates/svg-filters/src/tests/flood.rs
Normal file
17
crates/svg-filters/src/tests/flood.rs
Normal file
|
@ -0,0 +1,17 @@
|
|||
use csscolorparser::Color;
|
||||
|
||||
use crate::codegen::SvgDocument;
|
||||
|
||||
#[test]
|
||||
fn test_flood_simple() {
|
||||
let mut doc = SvgDocument::new();
|
||||
|
||||
let turbdispl = doc.create_filter("noiseDisplace");
|
||||
|
||||
turbdispl.flood(Color::new(0.9, 0.7, 0.85, 1.), 1.);
|
||||
|
||||
assert_eq!(
|
||||
doc.generate_svg(),
|
||||
r##"<svg><filter id="noiseDisplace"><feFlood flood-color="#e6b3d9" flood-opacity="1"/></filter></svg>"##
|
||||
);
|
||||
}
|
25
crates/svg-filters/src/tests/turbulence.rs
Normal file
25
crates/svg-filters/src/tests/turbulence.rs
Normal file
|
@ -0,0 +1,25 @@
|
|||
use crate::{
|
||||
codegen::SvgDocument,
|
||||
types::nodes::primitives::turbulence::{NoiseType, StitchTiles},
|
||||
};
|
||||
|
||||
#[test]
|
||||
fn test_simple_turbulence() {
|
||||
let mut doc = SvgDocument::new();
|
||||
|
||||
let noise = doc.create_filter("noise");
|
||||
|
||||
noise.turbulence(
|
||||
0.01,
|
||||
0.01,
|
||||
1,
|
||||
0,
|
||||
StitchTiles::Stitch,
|
||||
NoiseType::FractalNoise,
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
doc.generate_svg(),
|
||||
r#"<svg><filter id="noise"><feTurbulence baseFrequency="0.01 0.01" stitchTiles="stitch" type="fractalNoise"/></filter></svg>"#
|
||||
);
|
||||
}
|
|
@ -88,13 +88,13 @@ impl WriteElement for FePrimitive {
|
|||
FePrimitive::GaussianBlur(el) => el.attrs(),
|
||||
FePrimitive::Offset(el) => el.attrs(),
|
||||
FePrimitive::Turbulence(el) => el.attrs(),
|
||||
FePrimitive::ConvolveMatrix(_) => todo!(),
|
||||
FePrimitive::DiffuseLighting(_) => todo!(),
|
||||
FePrimitive::DisplacementMap(el) => el.attrs(),
|
||||
FePrimitive::Flood(el) => el.attrs(),
|
||||
FePrimitive::Morphology(el) => el.attrs(),
|
||||
FePrimitive::ConvolveMatrix(_) => todo!(),
|
||||
FePrimitive::DiffuseLighting(_) => todo!(),
|
||||
FePrimitive::Image(_) => todo!(),
|
||||
FePrimitive::Merge(_) => todo!(),
|
||||
FePrimitive::Morphology(_) => todo!(),
|
||||
FePrimitive::SpecularLighting(_) => todo!(),
|
||||
FePrimitive::Tile(_) => todo!(),
|
||||
}
|
||||
|
@ -109,13 +109,13 @@ impl WriteElement for FePrimitive {
|
|||
FePrimitive::GaussianBlur(el) => el.tag_name(),
|
||||
FePrimitive::Offset(el) => el.tag_name(),
|
||||
FePrimitive::Turbulence(el) => el.tag_name(),
|
||||
FePrimitive::ConvolveMatrix(_) => todo!(),
|
||||
FePrimitive::DiffuseLighting(_) => todo!(),
|
||||
FePrimitive::DisplacementMap(el) => el.tag_name(),
|
||||
FePrimitive::Flood(el) => el.tag_name(),
|
||||
FePrimitive::Morphology(el) => el.tag_name(),
|
||||
FePrimitive::ConvolveMatrix(_) => todo!(),
|
||||
FePrimitive::DiffuseLighting(_) => todo!(),
|
||||
FePrimitive::Image(_) => todo!(),
|
||||
FePrimitive::Merge(_) => todo!(),
|
||||
FePrimitive::Morphology(_) => todo!(),
|
||||
FePrimitive::SpecularLighting(_) => todo!(),
|
||||
FePrimitive::Tile(_) => todo!(),
|
||||
}
|
||||
|
@ -136,13 +136,13 @@ impl WriteElement for FePrimitive {
|
|||
FePrimitive::Turbulence(el) => el.element_writer(writer, common, inputs, output),
|
||||
FePrimitive::GaussianBlur(el) => el.element_writer(writer, common, inputs, output),
|
||||
FePrimitive::Offset(el) => el.element_writer(writer, common, inputs, output),
|
||||
FePrimitive::ConvolveMatrix(_) => todo!(),
|
||||
FePrimitive::DiffuseLighting(_) => todo!(),
|
||||
FePrimitive::DisplacementMap(el) => el.element_writer(writer, common, inputs, output),
|
||||
FePrimitive::Flood(el) => el.element_writer(writer, common, inputs, output),
|
||||
FePrimitive::Morphology(el) => el.element_writer(writer, common, inputs, output),
|
||||
FePrimitive::ConvolveMatrix(_) => todo!(),
|
||||
FePrimitive::DiffuseLighting(_) => todo!(),
|
||||
FePrimitive::Image(_) => todo!(),
|
||||
FePrimitive::Merge(_) => todo!(),
|
||||
FePrimitive::Morphology(_) => todo!(),
|
||||
FePrimitive::SpecularLighting(_) => todo!(),
|
||||
FePrimitive::Tile(_) => todo!(),
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue