forked from katzen-cafe/iowo
svg-filters: add basic graph and stuffs
This commit is contained in:
parent
69f0baf425
commit
56848a1b05
25 changed files with 340 additions and 69 deletions
|
@ -1,36 +1,29 @@
|
|||
use crate::types::length::{Coordinate, Length};
|
||||
|
||||
mod blend;
|
||||
mod color_matrix;
|
||||
mod component_transfer;
|
||||
mod composite;
|
||||
mod convolve_matrix;
|
||||
mod diffuse_lighting;
|
||||
mod displacement_map;
|
||||
mod flood;
|
||||
mod gaussian_blur;
|
||||
mod image;
|
||||
mod merge;
|
||||
mod morphology;
|
||||
mod offset;
|
||||
mod specular_lighting;
|
||||
mod tile;
|
||||
mod turbulence;
|
||||
use self::blend::BlendMode;
|
||||
|
||||
pub struct Primitive {
|
||||
primitive: FePrimitive,
|
||||
common_attrs: CommonAttrs,
|
||||
}
|
||||
use super::Node;
|
||||
|
||||
struct CommonAttrs {
|
||||
x: Coordinate,
|
||||
y: Coordinate,
|
||||
width: Length,
|
||||
height: Length,
|
||||
}
|
||||
pub mod blend;
|
||||
pub mod color_matrix;
|
||||
pub mod component_transfer;
|
||||
pub mod composite;
|
||||
pub mod convolve_matrix;
|
||||
pub mod diffuse_lighting;
|
||||
pub mod displacement_map;
|
||||
pub mod flood;
|
||||
pub mod gaussian_blur;
|
||||
pub mod image;
|
||||
pub mod merge;
|
||||
pub mod morphology;
|
||||
pub mod offset;
|
||||
pub mod specular_lighting;
|
||||
pub mod tile;
|
||||
pub mod turbulence;
|
||||
|
||||
/// svg filter effects primitives
|
||||
enum FePrimitive {
|
||||
#[derive(Debug)]
|
||||
pub enum FePrimitive {
|
||||
// 2 inputs
|
||||
Blend(blend::Blend),
|
||||
ColorMatrix(color_matrix::ColorMatrix),
|
||||
|
|
|
@ -1,10 +1,26 @@
|
|||
/// [feBlend](https://www.w3.org/TR/SVG11/filters.html#feBlendElement)
|
||||
pub struct Blend {
|
||||
#[derive(Debug)]
|
||||
pub(in crate::types::nodes) struct Blend {
|
||||
mode: BlendMode,
|
||||
}
|
||||
|
||||
impl Blend {
|
||||
pub fn new(mode: BlendMode) -> Self {
|
||||
Self { mode }
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Blend {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
mode: BlendMode::Normal,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// as according to https://drafts.fxtf.org/compositing-1/#blending
|
||||
enum BlendMode {
|
||||
#[derive(Debug)]
|
||||
pub enum BlendMode {
|
||||
Normal,
|
||||
Multiply,
|
||||
Screen,
|
||||
|
|
|
@ -1,19 +1,19 @@
|
|||
/// [feColorMatrix](https://www.w3.org/TR/SVG11/filters.html#feColorMatrixElement)
|
||||
#[derive(Debug)]
|
||||
pub struct ColorMatrix {
|
||||
cm_type: ColorMatrixType,
|
||||
}
|
||||
|
||||
enum ColorMatrixType {
|
||||
Matrix {
|
||||
values: [f32; 20],
|
||||
},
|
||||
Saturate {
|
||||
// is the values attribute anyway tho
|
||||
value: f32,
|
||||
},
|
||||
HueRotate {
|
||||
// also the values attribute
|
||||
degrees: f32,
|
||||
},
|
||||
impl ColorMatrix {
|
||||
pub fn new(cm_type: ColorMatrixType) -> Self {
|
||||
Self { cm_type }
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum ColorMatrixType {
|
||||
Matrix(Box<[f32; 20]>),
|
||||
Saturate(f32),
|
||||
HueRotate(f32),
|
||||
LuminanceToAlpha,
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
/// [feComponentTransfer](https://www.w3.org/TR/SVG11/filters.html#feComponentTransferElement)
|
||||
#[derive(Debug)]
|
||||
pub struct ComponentTransfer {
|
||||
func_r: TransferFunction,
|
||||
func_g: TransferFunction,
|
||||
|
@ -7,6 +8,7 @@ pub struct ComponentTransfer {
|
|||
}
|
||||
|
||||
/// [transfer functions](https://www.w3.org/TR/SVG11/filters.html#transferFuncElements)
|
||||
#[derive(Debug)]
|
||||
enum TransferFunction {
|
||||
Identity,
|
||||
Table {
|
||||
|
|
|
@ -1,9 +1,23 @@
|
|||
/// [feComposite](https://www.w3.org/TR/SVG11/filters.html#feCompositeElement)
|
||||
#[derive(Debug)]
|
||||
pub struct Composite {
|
||||
operator: CompositeOperator,
|
||||
}
|
||||
|
||||
enum CompositeOperator {
|
||||
impl Composite {
|
||||
pub fn new(op: CompositeOperator) -> Self {
|
||||
Self { operator: op }
|
||||
}
|
||||
|
||||
pub fn arithmetic(k1: f32, k2: f32, k3: f32, k4: f32) -> Self {
|
||||
Self {
|
||||
operator: CompositeOperator::Arithmetic { k1, k2, k3, k4 },
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum CompositeOperator {
|
||||
Over,
|
||||
In,
|
||||
Out,
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
#[derive(Debug)]
|
||||
pub struct ConvolveMatrix {
|
||||
order: (u16, u16),
|
||||
// must be checked to be `order.0 * order.1`
|
||||
|
@ -11,6 +12,7 @@ pub struct ConvolveMatrix {
|
|||
preserve_alpha: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
enum EdgeMode {
|
||||
None,
|
||||
Duplicate,
|
||||
|
|
|
@ -1,2 +1,3 @@
|
|||
// TODO
|
||||
#[derive(Debug)]
|
||||
pub struct DiffuseLighting;
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
/// [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,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
enum Channel {
|
||||
A,
|
||||
R,
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
use csscolorparser::Color;
|
||||
|
||||
/// [feFlood](https://www.w3.org/TR/SVG11/filters.html#feFloodElement)
|
||||
#[derive(Debug)]
|
||||
pub struct Flood {
|
||||
flood_color: Color,
|
||||
flood_opacity: f32,
|
||||
|
|
|
@ -1,4 +1,19 @@
|
|||
/// [feGaussianBlur](https://www.w3.org/TR/SVG11/filters.html#feGaussianBlurElement)
|
||||
#[derive(Debug)]
|
||||
pub struct GaussianBlur {
|
||||
std_deviation: (f32, f32),
|
||||
std_deviation: (u16, u16),
|
||||
}
|
||||
|
||||
impl GaussianBlur {
|
||||
pub fn single(v: u16) -> Self {
|
||||
Self {
|
||||
std_deviation: (v, v),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn with_xy(x: u16, y: u16) -> Self {
|
||||
Self {
|
||||
std_deviation: (x, y),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,2 +1,3 @@
|
|||
// TODO
|
||||
#[derive(Debug)]
|
||||
pub struct Image;
|
||||
|
|
|
@ -1,2 +1,3 @@
|
|||
// TODO
|
||||
#[derive(Debug)]
|
||||
pub struct Merge;
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
/// [feMorphology](https://www.w3.org/TR/SVG11/filters.html#feMorphologyElement)
|
||||
#[derive(Debug)]
|
||||
pub struct Morphology {
|
||||
operator: Operator,
|
||||
radius: (f32, f32),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
enum Operator {
|
||||
Erode,
|
||||
Dilate,
|
||||
|
|
|
@ -1,5 +1,12 @@
|
|||
/// [feOffset](https://www.w3.org/TR/SVG11/filters.html#feOffsetElement)
|
||||
#[derive(Debug)]
|
||||
pub struct Offset {
|
||||
dx: f32,
|
||||
dy: f32,
|
||||
}
|
||||
|
||||
impl Offset {
|
||||
pub fn new(dx: f32, dy: f32) -> Self {
|
||||
Self { dx, dy }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,2 +1,3 @@
|
|||
// TODO
|
||||
#[derive(Debug)]
|
||||
pub struct SpecularLighting;
|
||||
|
|
|
@ -1,2 +1,3 @@
|
|||
/// [feTile](https://www.w3.org/TR/SVG11/filters.html#feTileElement)
|
||||
#[derive(Debug)]
|
||||
pub struct Tile;
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
/// [feTurbulence](https://www.w3.org/TR/SVG11/filters.html#feTurbulenceElement)
|
||||
#[derive(Debug)]
|
||||
pub struct Turbulence {
|
||||
base_frequency: (f32, f32),
|
||||
num_octaves: (u16),
|
||||
|
@ -8,10 +9,12 @@ pub struct Turbulence {
|
|||
noise_type: NoiseType,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
enum StitchTiles {
|
||||
Stitch,
|
||||
NoStitch,
|
||||
}
|
||||
#[derive(Debug)]
|
||||
enum NoiseType {
|
||||
Turbulence,
|
||||
FractalNoise,
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
/// [svg filter effect standard input](https://www.w3.org/TR/SVG11/filters.html#FilterPrimitiveInAttribute)
|
||||
/// technically not a node, but for implementation simplicity... yeah
|
||||
#[derive(Debug)]
|
||||
pub enum StandardInput {
|
||||
SourceGraphic,
|
||||
SourceAlpha,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue