[librsvg] filters: factor out shared conversion code



commit 8ce7041367a132fc90b12898690c45476c327913
Author: Paolo Borelli <pborelli gnome org>
Date:   Wed Dec 11 20:52:27 2019 +0100

    filters: factor out shared conversion code

 rsvg_internals/src/filters/light/lighting.rs | 8 +-------
 rsvg_internals/src/filters/mod.rs            | 9 +++++++++
 rsvg_internals/src/filters/turbulence.rs     | 8 +-------
 3 files changed, 11 insertions(+), 14 deletions(-)
---
diff --git a/rsvg_internals/src/filters/light/lighting.rs b/rsvg_internals/src/filters/light/lighting.rs
index 20a6dbae..e432fb1c 100644
--- a/rsvg_internals/src/filters/light/lighting.rs
+++ b/rsvg_internals/src/filters/light/lighting.rs
@@ -34,7 +34,6 @@ use crate::filters::{
 use crate::node::{CascadedValues, NodeResult, NodeTrait, NodeType, RsvgNode};
 use crate::parsers;
 use crate::property_bag::PropertyBag;
-use crate::property_defs::ColorInterpolationFilters;
 use crate::surface_utils::{
     shared_surface::{SharedImageSurface, SurfaceType},
     ImageSurfaceDataExt,
@@ -468,12 +467,7 @@ macro_rules! impl_lighting_filter {
                 let values = cascaded.get();
                 // The generated color values are in the color space determined by
                 // color-interpolation-filters.
-                let surface_type =
-                    if values.color_interpolation_filters == ColorInterpolationFilters::LinearRgb {
-                        SurfaceType::LinearRgb
-                    } else {
-                        SurfaceType::SRgb
-                    };
+                let surface_type = SurfaceType::from(values.color_interpolation_filters);
                 let mut output_surface = SharedImageSurface::new(output_surface, surface_type)?;
 
                 if let Some((ox, oy)) = scale {
diff --git a/rsvg_internals/src/filters/mod.rs b/rsvg_internals/src/filters/mod.rs
index a117bb3f..b4ae8736 100644
--- a/rsvg_internals/src/filters/mod.rs
+++ b/rsvg_internals/src/filters/mod.rs
@@ -346,3 +346,12 @@ pub fn render(
 
     Ok(filter_ctx.into_output()?.into_image_surface()?)
 }
+
+impl From<ColorInterpolationFilters> for SurfaceType {
+   fn from(c: ColorInterpolationFilters) -> Self {
+        match c {
+            ColorInterpolationFilters::LinearRgb => SurfaceType::LinearRgb,
+            _ => SurfaceType::SRgb,
+        }
+    }
+}
diff --git a/rsvg_internals/src/filters/turbulence.rs b/rsvg_internals/src/filters/turbulence.rs
index 84720045..1320ac47 100644
--- a/rsvg_internals/src/filters/turbulence.rs
+++ b/rsvg_internals/src/filters/turbulence.rs
@@ -6,7 +6,6 @@ use crate::error::{AttributeResultExt, NodeError};
 use crate::node::{CascadedValues, NodeResult, NodeTrait, RsvgNode};
 use crate::parsers;
 use crate::property_bag::PropertyBag;
-use crate::property_defs::ColorInterpolationFilters;
 use crate::surface_utils::{
     shared_surface::{SharedImageSurface, SurfaceType},
     ImageSurfaceDataExt,
@@ -404,12 +403,7 @@ impl FilterEffect for FeTurbulence {
         let values = cascaded.get();
         // The generated color values are in the color space determined by
         // color-interpolation-filters.
-        let surface_type =
-            if values.color_interpolation_filters == ColorInterpolationFilters::LinearRgb {
-                SurfaceType::LinearRgb
-            } else {
-                SurfaceType::SRgb
-            };
+        let surface_type = SurfaceType::from(values.color_interpolation_filters);
 
         Ok(FilterResult {
             name: self.base.result.clone(),


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]