diff options
author | Federico Mena Quintero <federico@gnome.org> | 2023-02-23 16:42:11 -0600 |
---|---|---|
committer | Federico Mena Quintero <federico@gnome.org> | 2023-02-23 16:42:11 -0600 |
commit | 288119774d2a0a50c444fea8909c1661017ae703 (patch) | |
tree | 49a1887051a74f48b10db8809ee62eb2be8c163e | |
parent | 01fdf2d593d1baa71a7e3591334d35fe521a8fc5 (diff) | |
download | librsvg-288119774d2a0a50c444fea8909c1661017ae703.tar.gz |
filters/component_transfer.rs: Remove the channel field in FeFunc*
This is a vestige of the C code. All the feFuncX elements were
represented with a single struct that had a "channel" field, to
identify which is which.
<feComponentTransfer ...>
<feFuncR .../>
<feFuncG .../>
</feComponentTransfer>
When scanning the children of feComponentTransfer, the individual
func->channel were tested to see which of the children is the Red
function, which the Green function, etc.
But now we identify the individual functions by their element type, so
we can just do `matches!(element, Element::FeFuncR)` or similar.
Part-of: <https://gitlab.gnome.org/GNOME/librsvg/-/merge_requests/801>
-rw-r--r-- | src/filters/component_transfer.rs | 44 |
1 files changed, 11 insertions, 33 deletions
diff --git a/src/filters/component_transfer.rs b/src/filters/component_transfer.rs index ae358d72..e233980d 100644 --- a/src/filters/component_transfer.rs +++ b/src/filters/component_transfer.rs @@ -46,15 +46,6 @@ impl SetAttributes for FeComponentTransfer { } } -/// Pixel components that can be influenced by `feComponentTransfer`. -#[derive(Debug, Clone, Copy, PartialEq, Eq)] -pub enum Channel { - R, - G, - B, - A, -} - /// Component transfer function types. #[derive(Clone, Debug, PartialEq)] pub enum FunctionType { @@ -147,16 +138,12 @@ trait FeComponentTransferFunc { /// Returns the component transfer function parameters. fn function_parameters(&self) -> FunctionParameters; - - /// Returns the channel. - fn channel(&self) -> Channel; } macro_rules! func_x { - ($func_name:ident, $channel:expr) => { + ($func_name:ident) => { #[derive(Clone, Debug, PartialEq)] pub struct $func_name { - pub channel: Channel, pub function_type: FunctionType, pub table_values: Vec<f64>, pub slope: f64, @@ -170,7 +157,6 @@ macro_rules! func_x { #[inline] fn default() -> Self { Self { - channel: $channel, function_type: FunctionType::Identity, table_values: Vec::new(), slope: 1.0, @@ -205,11 +191,6 @@ macro_rules! func_x { FunctionType::Gamma => gamma, } } - - #[inline] - fn channel(&self) -> Channel { - self.channel - } } impl SetAttributes for $func_name { @@ -264,16 +245,16 @@ macro_rules! func_x { } // The `<feFuncR>` element -func_x!(FeFuncR, Channel::R); +func_x!(FeFuncR); // The `<feFuncG>` element -func_x!(FeFuncG, Channel::G); +func_x!(FeFuncG); // The `<feFuncB>` element -func_x!(FeFuncB, Channel::B); +func_x!(FeFuncB); // The `<feFuncA>` element -func_x!(FeFuncA, Channel::A); +func_x!(FeFuncA); macro_rules! func_or_default { ($func_node:ident, $func_type:ident) => { @@ -288,15 +269,12 @@ macro_rules! func_or_default { } macro_rules! get_func_x_node { - ($func_node:ident, $func_type:ident, $channel:expr) => { + ($func_node:ident, $func_type:ident) => { $func_node .children() .rev() .filter(|c| c.is_element()) - .find(|c| match *c.borrow_element() { - Element::$func_type(ref f) => f.channel() == $channel, - _ => false, - }) + .find(|c| matches!(*c.borrow_element(), Element::$func_type(_))) }; } @@ -402,10 +380,10 @@ impl FilterEffect for FeComponentTransfer { /// Takes a feComponentTransfer and walks its children to produce the feFuncX arguments. fn get_functions(node: &Node) -> Result<Functions, FilterResolveError> { - let func_r_node = get_func_x_node!(node, FeFuncR, Channel::R); - let func_g_node = get_func_x_node!(node, FeFuncG, Channel::G); - let func_b_node = get_func_x_node!(node, FeFuncB, Channel::B); - let func_a_node = get_func_x_node!(node, FeFuncA, Channel::A); + let func_r_node = get_func_x_node!(node, FeFuncR); + let func_g_node = get_func_x_node!(node, FeFuncG); + let func_b_node = get_func_x_node!(node, FeFuncB); + let func_a_node = get_func_x_node!(node, FeFuncA); let r = func_or_default!(func_r_node, FeFuncR); let g = func_or_default!(func_g_node, FeFuncG); |