forked from katzen-cafe/iowo
svg-filters: add turbulence and displacement map
This commit is contained in:
parent
919a3bb377
commit
0197df5ee2
5 changed files with 98 additions and 9 deletions
|
@ -90,7 +90,7 @@ impl WriteElement for FePrimitive {
|
|||
FePrimitive::Turbulence(el) => el.attrs(),
|
||||
FePrimitive::ConvolveMatrix(_) => todo!(),
|
||||
FePrimitive::DiffuseLighting(_) => todo!(),
|
||||
FePrimitive::DisplacementMap(_) => todo!(),
|
||||
FePrimitive::DisplacementMap(el) => el.attrs(),
|
||||
FePrimitive::Flood(el) => el.attrs(),
|
||||
FePrimitive::Image(_) => todo!(),
|
||||
FePrimitive::Merge(_) => todo!(),
|
||||
|
@ -111,7 +111,7 @@ impl WriteElement for FePrimitive {
|
|||
FePrimitive::Turbulence(el) => el.tag_name(),
|
||||
FePrimitive::ConvolveMatrix(_) => todo!(),
|
||||
FePrimitive::DiffuseLighting(_) => todo!(),
|
||||
FePrimitive::DisplacementMap(_) => todo!(),
|
||||
FePrimitive::DisplacementMap(el) => el.tag_name(),
|
||||
FePrimitive::Flood(el) => el.tag_name(),
|
||||
FePrimitive::Image(_) => todo!(),
|
||||
FePrimitive::Merge(_) => todo!(),
|
||||
|
@ -138,7 +138,7 @@ impl WriteElement for FePrimitive {
|
|||
FePrimitive::Offset(el) => el.element_writer(writer, common, inputs, output),
|
||||
FePrimitive::ConvolveMatrix(_) => todo!(),
|
||||
FePrimitive::DiffuseLighting(_) => todo!(),
|
||||
FePrimitive::DisplacementMap(_) => todo!(),
|
||||
FePrimitive::DisplacementMap(el) => el.element_writer(writer, common, inputs, output),
|
||||
FePrimitive::Flood(el) => el.element_writer(writer, common, inputs, output),
|
||||
FePrimitive::Image(_) => todo!(),
|
||||
FePrimitive::Merge(_) => todo!(),
|
||||
|
|
|
@ -1,13 +1,32 @@
|
|||
use super::WriteElement;
|
||||
|
||||
/// [feDisplacementMap](https://www.w3.org/TR/SVG11/filters.html#feDisplacementMapElement)
|
||||
#[derive(Debug)]
|
||||
pub struct DisplacementMap {
|
||||
scale: f32,
|
||||
x_channel_selector: Channel,
|
||||
y_channel_selector: Channel,
|
||||
pub scale: f32,
|
||||
pub x_channel_selector: Channel,
|
||||
pub y_channel_selector: Channel,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
enum Channel {
|
||||
impl WriteElement for DisplacementMap {
|
||||
fn attrs(&self) -> Vec<quick_xml::events::attributes::Attribute> {
|
||||
let mut r = Vec::new();
|
||||
gen_attrs![
|
||||
r;
|
||||
self.scale != 0. => b"scale": self.scale,
|
||||
self.x_channel_selector != Channel::A => b"xChannelSelector": format!("{:?}", self.x_channel_selector),
|
||||
self.y_channel_selector != Channel::A => b"yChannelSelector": format!("{:?}", self.y_channel_selector)
|
||||
];
|
||||
r
|
||||
}
|
||||
|
||||
fn tag_name(&self) -> &'static str {
|
||||
"feDisplacementMap"
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
pub enum Channel {
|
||||
A,
|
||||
R,
|
||||
G,
|
||||
|
|
|
@ -3,6 +3,8 @@ use csscolorparser::Color;
|
|||
use super::WriteElement;
|
||||
|
||||
/// [feFlood](https://www.w3.org/TR/SVG11/filters.html#feFloodElement)
|
||||
// NOTE: this doesn't work for some reason, but the examples from mdn don't either.
|
||||
// might be a browser bug, def worth investigating
|
||||
#[derive(Debug)]
|
||||
pub struct Flood {
|
||||
pub flood_color: Color,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue