[librsvg: 1/14] Replace two variants in FilterError with a single



commit 648a0d8cc42bc2e854c2b4350bd853529ae447e9
Author: Ivan Molodetskikh <yalterz gmail com>
Date:   Sat Jul 14 09:13:14 2018 +0300

    Replace two variants in FilterError with a single

 rsvg_internals/src/filters/blend.rs                |  8 +--
 rsvg_internals/src/filters/color_matrix.rs         |  5 +-
 rsvg_internals/src/filters/component_transfer.rs   |  5 +-
 rsvg_internals/src/filters/composite.rs            | 10 +--
 rsvg_internals/src/filters/context.rs              | 40 +++++------
 rsvg_internals/src/filters/convolve_matrix.rs      | 38 ++++------
 rsvg_internals/src/filters/displacement_map.rs     | 13 ++--
 rsvg_internals/src/filters/error.rs                | 26 +++----
 rsvg_internals/src/filters/flood.rs                |  5 +-
 rsvg_internals/src/filters/gaussian_blur.rs        | 82 ++++++++--------------
 rsvg_internals/src/filters/image.rs                |  9 ++-
 .../src/filters/light/diffuse_lighting.rs          | 30 +++-----
 .../src/filters/light/specular_lighting.rs         | 30 +++-----
 rsvg_internals/src/filters/merge.rs                | 10 +--
 rsvg_internals/src/filters/morphology.rs           |  5 +-
 rsvg_internals/src/filters/offset.rs               |  5 +-
 rsvg_internals/src/filters/tile.rs                 |  7 +-
 rsvg_internals/src/filters/turbulence.rs           |  5 +-
 18 files changed, 127 insertions(+), 206 deletions(-)
---
diff --git a/rsvg_internals/src/filters/blend.rs b/rsvg_internals/src/filters/blend.rs
index 272eb8d3..98910f15 100644
--- a/rsvg_internals/src/filters/blend.rs
+++ b/rsvg_internals/src/filters/blend.rs
@@ -83,10 +83,7 @@ impl Filter for Blend {
             .add_input(&input_2)
             .into_irect(draw_ctx);
 
-        let output_surface = input_2
-            .surface()
-            .copy_surface(bounds)
-            .map_err(FilterError::IntermediateSurfaceCreation)?;
+        let output_surface = input_2.surface().copy_surface(bounds)?;
         {
             let cr = cairo::Context::new(&output_surface);
             cr.rectangle(
@@ -105,8 +102,7 @@ impl Filter for Blend {
         Ok(FilterResult {
             name: self.base.result.borrow().clone(),
             output: FilterOutput {
-                surface: SharedImageSurface::new(output_surface)
-                    .map_err(FilterError::BadIntermediateSurfaceStatus)?,
+                surface: SharedImageSurface::new(output_surface)?,
                 bounds,
             },
         })
diff --git a/rsvg_internals/src/filters/color_matrix.rs b/rsvg_internals/src/filters/color_matrix.rs
index a8aec2fa..d437b5ee 100644
--- a/rsvg_internals/src/filters/color_matrix.rs
+++ b/rsvg_internals/src/filters/color_matrix.rs
@@ -193,7 +193,7 @@ impl Filter for ColorMatrix {
             cairo::Format::ARgb32,
             ctx.source_graphic().width(),
             ctx.source_graphic().height(),
-        ).map_err(FilterError::IntermediateSurfaceCreation)?;
+        )?;
 
         let output_stride = output_surface.get_stride() as usize;
         {
@@ -234,8 +234,7 @@ impl Filter for ColorMatrix {
         Ok(FilterResult {
             name: self.base.result.borrow().clone(),
             output: FilterOutput {
-                surface: SharedImageSurface::new(output_surface)
-                    .map_err(FilterError::BadIntermediateSurfaceStatus)?,
+                surface: SharedImageSurface::new(output_surface)?,
                 bounds,
             },
         })
diff --git a/rsvg_internals/src/filters/component_transfer.rs 
b/rsvg_internals/src/filters/component_transfer.rs
index f6c3c628..e15b7c3d 100644
--- a/rsvg_internals/src/filters/component_transfer.rs
+++ b/rsvg_internals/src/filters/component_transfer.rs
@@ -290,7 +290,7 @@ impl Filter for ComponentTransfer {
             cairo::Format::ARgb32,
             ctx.source_graphic().width(),
             ctx.source_graphic().height(),
-        ).map_err(FilterError::IntermediateSurfaceCreation)?;
+        )?;
 
         // Enumerate all child <feFuncX> nodes.
         let functions = node
@@ -372,8 +372,7 @@ impl Filter for ComponentTransfer {
         Ok(FilterResult {
             name: self.base.result.borrow().clone(),
             output: FilterOutput {
-                surface: SharedImageSurface::new(output_surface)
-                    .map_err(FilterError::BadIntermediateSurfaceStatus)?,
+                surface: SharedImageSurface::new(output_surface)?,
                 bounds,
             },
         })
diff --git a/rsvg_internals/src/filters/composite.rs b/rsvg_internals/src/filters/composite.rs
index 6e66e963..4146ac92 100644
--- a/rsvg_internals/src/filters/composite.rs
+++ b/rsvg_internals/src/filters/composite.rs
@@ -116,7 +116,7 @@ impl Filter for Composite {
                 cairo::Format::ARgb32,
                 input.surface().width(),
                 input.surface().height(),
-            ).map_err(FilterError::IntermediateSurfaceCreation)?;
+            )?;
 
             let output_stride = output_surface.get_stride() as usize;
             {
@@ -162,10 +162,7 @@ impl Filter for Composite {
 
             output_surface
         } else {
-            let output_surface = input_2
-                .surface()
-                .copy_surface(bounds)
-                .map_err(FilterError::IntermediateSurfaceCreation)?;
+            let output_surface = input_2.surface().copy_surface(bounds)?;
 
             let cr = cairo::Context::new(&output_surface);
             cr.rectangle(
@@ -186,8 +183,7 @@ impl Filter for Composite {
         Ok(FilterResult {
             name: self.base.result.borrow().clone(),
             output: FilterOutput {
-                surface: SharedImageSurface::new(output_surface)
-                    .map_err(FilterError::BadIntermediateSurfaceStatus)?,
+                surface: SharedImageSurface::new(output_surface)?,
                 bounds,
             },
         })
diff --git a/rsvg_internals/src/filters/context.rs b/rsvg_internals/src/filters/context.rs
index 05b72efb..13e605c7 100644
--- a/rsvg_internals/src/filters/context.rs
+++ b/rsvg_internals/src/filters/context.rs
@@ -297,7 +297,7 @@ impl FilterContext {
     pub fn source_alpha(&self, bounds: IRect) -> Result<cairo::ImageSurface, FilterError> {
         self.source_surface
             .extract_alpha(bounds)
-            .map_err(FilterError::IntermediateSurfaceCreation)
+            .map_err(FilterError::CairoError)
     }
 
     /// Computes and returns the background image snapshot.
@@ -354,10 +354,9 @@ impl FilterContext {
 
         *bg = Some(
             self.compute_background_image(draw_ctx)
-                .map_err(FilterError::IntermediateSurfaceCreation)
+                .map_err(FilterError::CairoError)
                 .and_then(|surface| {
-                    SharedImageSurface::new(surface)
-                        .map_err(FilterError::BadIntermediateSurfaceStatus)
+                    SharedImageSurface::new(surface).map_err(FilterError::CairoError)
                 }),
         );
 
@@ -374,7 +373,7 @@ impl FilterContext {
     ) -> Result<cairo::ImageSurface, FilterError> {
         self.background_image(draw_ctx)?
             .extract_alpha(bounds)
-            .map_err(FilterError::IntermediateSurfaceCreation)
+            .map_err(FilterError::CairoError)
     }
 
     /// Returns the output of the filter primitive by its result name.
@@ -394,10 +393,9 @@ impl FilterContext {
                     cairo::Format::ARgb32,
                     self.source_surface.width(),
                     self.source_surface.height(),
-                ).map_err(FilterError::IntermediateSurfaceCreation)?;
+                ).map_err(FilterError::CairoError)?;
 
-                SharedImageSurface::new(empty_surface)
-                    .map_err(FilterError::BadIntermediateSurfaceStatus)
+                SharedImageSurface::new(empty_surface).map_err(FilterError::CairoError)
             }
         }
     }
@@ -409,10 +407,9 @@ impl FilterContext {
         if self.processing_linear_rgb {
             result.output.surface =
                 unlinearize_surface(&result.output.surface, result.output.bounds)
-                    .map_err(FilterError::IntermediateSurfaceCreation)
+                    .map_err(FilterError::CairoError)
                     .and_then(|surface| {
-                        SharedImageSurface::new(surface)
-                            .map_err(FilterError::BadIntermediateSurfaceStatus)
+                        SharedImageSurface::new(surface).map_err(FilterError::CairoError)
                     })?;
         }
 
@@ -525,8 +522,7 @@ impl FilterContext {
             Input::SourceAlpha => self
                 .source_alpha(self.effects_region().rect.unwrap().into())
                 .and_then(|surface| {
-                    SharedImageSurface::new(surface)
-                        .map_err(FilterError::BadIntermediateSurfaceStatus)
+                    SharedImageSurface::new(surface).map_err(FilterError::CairoError)
                 })
                 .map(FilterInput::StandardInput),
             Input::BackgroundImage => self
@@ -536,25 +532,22 @@ impl FilterContext {
             Input::BackgroundAlpha => self
                 .background_alpha(draw_ctx, self.effects_region().rect.unwrap().into())
                 .and_then(|surface| {
-                    SharedImageSurface::new(surface)
-                        .map_err(FilterError::BadIntermediateSurfaceStatus)
+                    SharedImageSurface::new(surface).map_err(FilterError::CairoError)
                 })
                 .map(FilterInput::StandardInput),
 
             Input::FillPaint => self
                 .get_paint_server_surface(draw_ctx, &values.fill.0, values.fill_opacity.0)
-                .map_err(FilterError::IntermediateSurfaceCreation)
+                .map_err(FilterError::CairoError)
                 .and_then(|surface| {
-                    SharedImageSurface::new(surface)
-                        .map_err(FilterError::BadIntermediateSurfaceStatus)
+                    SharedImageSurface::new(surface).map_err(FilterError::CairoError)
                 })
                 .map(FilterInput::StandardInput),
             Input::StrokePaint => self
                 .get_paint_server_surface(draw_ctx, &values.stroke.0, values.stroke_opacity.0)
-                .map_err(FilterError::IntermediateSurfaceCreation)
+                .map_err(FilterError::CairoError)
                 .and_then(|surface| {
-                    SharedImageSurface::new(surface)
-                        .map_err(FilterError::BadIntermediateSurfaceStatus)
+                    SharedImageSurface::new(surface).map_err(FilterError::CairoError)
                 })
                 .map(FilterInput::StandardInput),
 
@@ -587,10 +580,9 @@ impl FilterContext {
             };
 
             linearize_surface(surface, bounds)
-                .map_err(FilterError::IntermediateSurfaceCreation)
+                .map_err(FilterError::CairoError)
                 .and_then(|surface| {
-                    SharedImageSurface::new(surface)
-                        .map_err(FilterError::BadIntermediateSurfaceStatus)
+                    SharedImageSurface::new(surface).map_err(FilterError::CairoError)
                 })
                 .map(|surface| match raw {
                     FilterInput::StandardInput(_) => FilterInput::StandardInput(surface),
diff --git a/rsvg_internals/src/filters/convolve_matrix.rs b/rsvg_internals/src/filters/convolve_matrix.rs
index 4414cec7..37c85010 100644
--- a/rsvg_internals/src/filters/convolve_matrix.rs
+++ b/rsvg_internals/src/filters/convolve_matrix.rs
@@ -227,12 +227,8 @@ impl Filter for ConvolveMatrix {
 
         let mut input_surface = if self.preserve_alpha.get() {
             // preserve_alpha means we need to premultiply and unpremultiply the values.
-            let unpremultiplied_surface = input
-                .surface()
-                .unpremultiply(bounds)
-                .map_err(FilterError::IntermediateSurfaceCreation)?;
-            SharedImageSurface::new(unpremultiplied_surface)
-                .map_err(FilterError::BadIntermediateSurfaceStatus)?
+            let unpremultiplied_surface = input.surface().unpremultiply(bounds)?;
+            SharedImageSurface::new(unpremultiplied_surface)?
         } else {
             input.surface().clone()
         };
@@ -244,12 +240,9 @@ impl Filter for ConvolveMatrix {
 
         if let Some((ox, oy)) = scale {
             // Scale the input surface to match kernel_unit_length.
-            let (new_surface, new_bounds) = input_surface
-                .scale(bounds, 1.0 / ox, 1.0 / oy)
-                .map_err(FilterError::IntermediateSurfaceCreation)?;
+            let (new_surface, new_bounds) = input_surface.scale(bounds, 1.0 / ox, 1.0 / oy)?;
 
-            let new_surface = SharedImageSurface::new(new_surface)
-                .map_err(FilterError::BadIntermediateSurfaceStatus)?;
+            let new_surface = SharedImageSurface::new(new_surface)?;
 
             input_surface = new_surface;
             bounds = new_bounds;
@@ -262,7 +255,7 @@ impl Filter for ConvolveMatrix {
             cairo::Format::ARgb32,
             input_surface.width(),
             input_surface.height(),
-        ).map_err(FilterError::IntermediateSurfaceCreation)?;
+        )?;
 
         let output_stride = output_surface.get_stride() as usize;
         {
@@ -331,22 +324,17 @@ impl Filter for ConvolveMatrix {
             }
         }
 
-        let mut output_surface = SharedImageSurface::new(output_surface)
-            .map_err(FilterError::BadIntermediateSurfaceStatus)?;
+        let mut output_surface = SharedImageSurface::new(output_surface)?;
 
         if let Some((ox, oy)) = scale {
             // Scale the output surface back.
-            output_surface = SharedImageSurface::new(
-                output_surface
-                    .scale_to(
-                        ctx.source_graphic().width(),
-                        ctx.source_graphic().height(),
-                        original_bounds,
-                        ox,
-                        oy,
-                    )
-                    .map_err(FilterError::IntermediateSurfaceCreation)?,
-            ).map_err(FilterError::BadIntermediateSurfaceStatus)?;
+            output_surface = SharedImageSurface::new(output_surface.scale_to(
+                ctx.source_graphic().width(),
+                ctx.source_graphic().height(),
+                original_bounds,
+                ox,
+                oy,
+            )?)?;
 
             bounds = original_bounds;
         }
diff --git a/rsvg_internals/src/filters/displacement_map.rs b/rsvg_internals/src/filters/displacement_map.rs
index 8c21dfaf..4830cdea 100644
--- a/rsvg_internals/src/filters/displacement_map.rs
+++ b/rsvg_internals/src/filters/displacement_map.rs
@@ -94,12 +94,8 @@ impl Filter for DisplacementMap {
             .into_irect(draw_ctx);
 
         // Displacement map's values need to be non-premultiplied.
-        let displacement_surface = displacement_input
-            .surface()
-            .unpremultiply(bounds)
-            .map_err(FilterError::IntermediateSurfaceCreation)?;
-        let displacement_surface = SharedImageSurface::new(displacement_surface)
-            .map_err(FilterError::BadIntermediateSurfaceStatus)?;
+        let displacement_surface = displacement_input.surface().unpremultiply(bounds)?;
+        let displacement_surface = SharedImageSurface::new(displacement_surface)?;
 
         let scale = self.scale.get();
         let (sx, sy) = ctx.paffine().transform_distance(scale, scale);
@@ -111,7 +107,7 @@ impl Filter for DisplacementMap {
             cairo::Format::ARgb32,
             ctx.source_graphic().width(),
             ctx.source_graphic().height(),
-        ).map_err(FilterError::IntermediateSurfaceCreation)?;
+        )?;
 
         {
             let cr = cairo::Context::new(&output_surface);
@@ -148,8 +144,7 @@ impl Filter for DisplacementMap {
         Ok(FilterResult {
             name: self.base.result.borrow().clone(),
             output: FilterOutput {
-                surface: SharedImageSurface::new(output_surface)
-                    .map_err(FilterError::BadIntermediateSurfaceStatus)?,
+                surface: SharedImageSurface::new(output_surface)?,
                 bounds,
             },
         })
diff --git a/rsvg_internals/src/filters/error.rs b/rsvg_internals/src/filters/error.rs
index d1cd83a3..f25547a6 100644
--- a/rsvg_internals/src/filters/error.rs
+++ b/rsvg_internals/src/filters/error.rs
@@ -10,10 +10,11 @@ pub enum FilterError {
     InvalidInput,
     /// The filter input surface has an unsuccessful status.
     BadInputSurfaceStatus(cairo::Status),
-    /// Couldn't create an intermediate surface.
-    IntermediateSurfaceCreation(cairo::Status),
-    /// An intermediate surface has an unsuccessful status.
-    BadIntermediateSurfaceStatus(cairo::Status),
+    /// A Cairo error.
+    ///
+    /// This means that either a failed intermediate surface creation or bad intermediate surface
+    /// status.
+    CairoError(cairo::Status),
     /// A lighting filter has none or multiple light sources.
     InvalidLightSourceCount,
 }
@@ -24,12 +25,7 @@ impl Error for FilterError {
         match *self {
             FilterError::InvalidInput => "invalid value of the `in` attribute",
             FilterError::BadInputSurfaceStatus(_) => "invalid status of the input surface",
-            FilterError::IntermediateSurfaceCreation(_) => {
-                "couldn't create an intermediate surface"
-            }
-            FilterError::BadIntermediateSurfaceStatus(_) => {
-                "invalid status of an intermediate surface"
-            }
+            FilterError::CairoError(_) => "Cairo error",
             FilterError::InvalidLightSourceCount => "invalid light source count",
         }
     }
@@ -44,11 +40,17 @@ impl fmt::Display for FilterError {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
         match *self {
             FilterError::BadInputSurfaceStatus(ref status)
-            | FilterError::IntermediateSurfaceCreation(ref status)
-            | FilterError::BadIntermediateSurfaceStatus(ref status) => {
+            | FilterError::CairoError(ref status) => {
                 write!(f, "{}: {:?}", self.description(), status)
             }
             _ => write!(f, "{}", self.description()),
         }
     }
 }
+
+impl From<cairo::Status> for FilterError {
+    #[inline]
+    fn from(x: cairo::Status) -> Self {
+        FilterError::CairoError(x)
+    }
+}
diff --git a/rsvg_internals/src/filters/flood.rs b/rsvg_internals/src/filters/flood.rs
index eddfcbb7..db6c6cc7 100644
--- a/rsvg_internals/src/filters/flood.rs
+++ b/rsvg_internals/src/filters/flood.rs
@@ -50,7 +50,7 @@ impl Filter for Flood {
             cairo::Format::ARgb32,
             ctx.source_graphic().width(),
             ctx.source_graphic().height(),
-        ).map_err(FilterError::IntermediateSurfaceCreation)?;
+        )?;
 
         let cascaded = node.get_cascaded_values();
         let values = cascaded.get();
@@ -83,8 +83,7 @@ impl Filter for Flood {
         Ok(FilterResult {
             name: self.base.result.borrow().clone(),
             output: FilterOutput {
-                surface: SharedImageSurface::new(output_surface)
-                    .map_err(FilterError::BadIntermediateSurfaceStatus)?,
+                surface: SharedImageSurface::new(output_surface)?,
                 bounds,
             },
         })
diff --git a/rsvg_internals/src/filters/gaussian_blur.rs b/rsvg_internals/src/filters/gaussian_blur.rs
index 938aef5f..be3b825a 100644
--- a/rsvg_internals/src/filters/gaussian_blur.rs
+++ b/rsvg_internals/src/filters/gaussian_blur.rs
@@ -158,56 +158,40 @@ fn three_box_blurs(
         let mut surface = input_surface.clone();
 
         for _ in 0..3 {
-            surface = SharedImageSurface::new(
-                surface
-                    .convolve(
-                        bounds,
-                        ((cols / 2) as i32, (rows / 2) as i32),
-                        &kernel,
-                        EdgeMode::None,
-                    )
-                    .map_err(FilterError::IntermediateSurfaceCreation)?,
-            ).map_err(FilterError::BadInputSurfaceStatus)?;
+            surface = SharedImageSurface::new(surface.convolve(
+                bounds,
+                ((cols / 2) as i32, (rows / 2) as i32),
+                &kernel,
+                EdgeMode::None,
+            )?)?;
         }
 
         surface
     } else {
         // Even kernel sizes have a more interesting scheme.
-        let surface = SharedImageSurface::new(
-            input_surface
-                .convolve(
-                    bounds,
-                    ((cols / 2) as i32, (rows / 2) as i32),
-                    &kernel,
-                    EdgeMode::None,
-                )
-                .map_err(FilterError::IntermediateSurfaceCreation)?,
-        ).map_err(FilterError::BadInputSurfaceStatus)?;
-
-        let surface = SharedImageSurface::new(
-            surface
-                .convolve(
-                    bounds,
-                    (max((cols / 2) as i32 - 1, 0), max((rows / 2) as i32 - 1, 0)),
-                    &kernel,
-                    EdgeMode::None,
-                )
-                .map_err(FilterError::IntermediateSurfaceCreation)?,
-        ).map_err(FilterError::BadInputSurfaceStatus)?;
+        let surface = SharedImageSurface::new(input_surface.convolve(
+            bounds,
+            ((cols / 2) as i32, (rows / 2) as i32),
+            &kernel,
+            EdgeMode::None,
+        )?)?;
+
+        let surface = SharedImageSurface::new(surface.convolve(
+            bounds,
+            (max((cols / 2) as i32 - 1, 0), max((rows / 2) as i32 - 1, 0)),
+            &kernel,
+            EdgeMode::None,
+        )?)?;
 
         let d = d + 1;
         let (rows, cols) = if vertical { (d, 1) } else { (1, d) };
         let kernel = Matrix::new(rows, cols, box_blur_kernel(d));
-        SharedImageSurface::new(
-            surface
-                .convolve(
-                    bounds,
-                    ((cols / 2) as i32, (rows / 2) as i32),
-                    &kernel,
-                    EdgeMode::None,
-                )
-                .map_err(FilterError::IntermediateSurfaceCreation)?,
-        ).map_err(FilterError::BadInputSurfaceStatus)?
+        SharedImageSurface::new(surface.convolve(
+            bounds,
+            ((cols / 2) as i32, (rows / 2) as i32),
+            &kernel,
+            EdgeMode::None,
+        )?)?
     };
 
     Ok(surface)
@@ -230,16 +214,12 @@ fn gaussian_blur(
     };
     let kernel = Matrix::new(rows, cols, kernel);
 
-    SharedImageSurface::new(
-        input_surface
-            .convolve(
-                bounds,
-                ((cols / 2) as i32, (rows / 2) as i32),
-                &kernel,
-                EdgeMode::None,
-            )
-            .map_err(FilterError::IntermediateSurfaceCreation)?,
-    ).map_err(FilterError::BadIntermediateSurfaceStatus)
+    Ok(SharedImageSurface::new(input_surface.convolve(
+        bounds,
+        ((cols / 2) as i32, (rows / 2) as i32),
+        &kernel,
+        EdgeMode::None,
+    )?)?)
 }
 
 impl Filter for GaussianBlur {
diff --git a/rsvg_internals/src/filters/image.rs b/rsvg_internals/src/filters/image.rs
index 5a0f0939..e24d5361 100644
--- a/rsvg_internals/src/filters/image.rs
+++ b/rsvg_internals/src/filters/image.rs
@@ -64,7 +64,7 @@ impl Image {
             cairo::Format::ARgb32,
             ctx.source_graphic().width(),
             ctx.source_graphic().height(),
-        ).map_err(FilterError::IntermediateSurfaceCreation)?;
+        )?;
 
         draw_ctx.get_cairo_context().set_matrix(ctx.paffine());
 
@@ -87,7 +87,7 @@ impl Image {
             cairo::Format::ARgb32,
             ctx.source_graphic().width(),
             ctx.source_graphic().height(),
-        ).map_err(FilterError::IntermediateSurfaceCreation)?;
+        )?;
 
         let cr = cairo::Context::new(&output_surface);
         cr.rectangle(
@@ -142,7 +142,7 @@ impl Image {
             cairo::Format::ARgb32,
             ctx.source_graphic().width(),
             ctx.source_graphic().height(),
-        ).map_err(FilterError::IntermediateSurfaceCreation)?;
+        )?;
 
         // TODO: this goes through a f64->i32->f64 conversion.
         let render_bounds = bounds_builder.into_irect_without_clipping(draw_ctx);
@@ -239,8 +239,7 @@ impl Filter for Image {
         Ok(FilterResult {
             name: self.base.result.borrow().clone(),
             output: FilterOutput {
-                surface: SharedImageSurface::new(output_surface)
-                    .map_err(FilterError::BadIntermediateSurfaceStatus)?,
+                surface: SharedImageSurface::new(output_surface)?,
                 bounds,
             },
         })
diff --git a/rsvg_internals/src/filters/light/diffuse_lighting.rs 
b/rsvg_internals/src/filters/light/diffuse_lighting.rs
index d4631cd3..d6275f73 100644
--- a/rsvg_internals/src/filters/light/diffuse_lighting.rs
+++ b/rsvg_internals/src/filters/light/diffuse_lighting.rs
@@ -142,12 +142,9 @@ impl Filter for DiffuseLighting {
 
         if let Some((ox, oy)) = scale {
             // Scale the input surface to match kernel_unit_length.
-            let (new_surface, new_bounds) = input_surface
-                .scale(bounds, 1.0 / ox, 1.0 / oy)
-                .map_err(FilterError::IntermediateSurfaceCreation)?;
+            let (new_surface, new_bounds) = input_surface.scale(bounds, 1.0 / ox, 1.0 / oy)?;
 
-            let new_surface = SharedImageSurface::new(new_surface)
-                .map_err(FilterError::BadIntermediateSurfaceStatus)?;
+            let new_surface = SharedImageSurface::new(new_surface)?;
 
             input_surface = new_surface;
             bounds = new_bounds;
@@ -159,7 +156,7 @@ impl Filter for DiffuseLighting {
             cairo::Format::ARgb32,
             input_surface.width(),
             input_surface.height(),
-        ).map_err(FilterError::IntermediateSurfaceCreation)?;
+        )?;
 
         let output_stride = output_surface.get_stride() as usize;
         {
@@ -189,22 +186,17 @@ impl Filter for DiffuseLighting {
             }
         }
 
-        let mut output_surface = SharedImageSurface::new(output_surface)
-            .map_err(FilterError::BadIntermediateSurfaceStatus)?;
+        let mut output_surface = SharedImageSurface::new(output_surface)?;
 
         if let Some((ox, oy)) = scale {
             // Scale the output surface back.
-            output_surface = SharedImageSurface::new(
-                output_surface
-                    .scale_to(
-                        ctx.source_graphic().width(),
-                        ctx.source_graphic().height(),
-                        original_bounds,
-                        ox,
-                        oy,
-                    )
-                    .map_err(FilterError::IntermediateSurfaceCreation)?,
-            ).map_err(FilterError::BadIntermediateSurfaceStatus)?;
+            output_surface = SharedImageSurface::new(output_surface.scale_to(
+                ctx.source_graphic().width(),
+                ctx.source_graphic().height(),
+                original_bounds,
+                ox,
+                oy,
+            )?)?;
 
             bounds = original_bounds;
         }
diff --git a/rsvg_internals/src/filters/light/specular_lighting.rs 
b/rsvg_internals/src/filters/light/specular_lighting.rs
index 319c201d..f77396cf 100644
--- a/rsvg_internals/src/filters/light/specular_lighting.rs
+++ b/rsvg_internals/src/filters/light/specular_lighting.rs
@@ -160,12 +160,9 @@ impl Filter for SpecularLighting {
 
         if let Some((ox, oy)) = scale {
             // Scale the input surface to match kernel_unit_length.
-            let (new_surface, new_bounds) = input_surface
-                .scale(bounds, 1.0 / ox, 1.0 / oy)
-                .map_err(FilterError::IntermediateSurfaceCreation)?;
+            let (new_surface, new_bounds) = input_surface.scale(bounds, 1.0 / ox, 1.0 / oy)?;
 
-            let new_surface = SharedImageSurface::new(new_surface)
-                .map_err(FilterError::BadIntermediateSurfaceStatus)?;
+            let new_surface = SharedImageSurface::new(new_surface)?;
 
             input_surface = new_surface;
             bounds = new_bounds;
@@ -177,7 +174,7 @@ impl Filter for SpecularLighting {
             cairo::Format::ARgb32,
             input_surface.width(),
             input_surface.height(),
-        ).map_err(FilterError::IntermediateSurfaceCreation)?;
+        )?;
 
         let output_stride = output_surface.get_stride() as usize;
         {
@@ -211,22 +208,17 @@ impl Filter for SpecularLighting {
             }
         }
 
-        let mut output_surface = SharedImageSurface::new(output_surface)
-            .map_err(FilterError::BadIntermediateSurfaceStatus)?;
+        let mut output_surface = SharedImageSurface::new(output_surface)?;
 
         if let Some((ox, oy)) = scale {
             // Scale the output surface back.
-            output_surface = SharedImageSurface::new(
-                output_surface
-                    .scale_to(
-                        ctx.source_graphic().width(),
-                        ctx.source_graphic().height(),
-                        original_bounds,
-                        ox,
-                        oy,
-                    )
-                    .map_err(FilterError::IntermediateSurfaceCreation)?,
-            ).map_err(FilterError::BadIntermediateSurfaceStatus)?;
+            output_surface = SharedImageSurface::new(output_surface.scale_to(
+                ctx.source_graphic().width(),
+                ctx.source_graphic().height(),
+                original_bounds,
+                ox,
+                oy,
+            )?)?;
 
             bounds = original_bounds;
         }
diff --git a/rsvg_internals/src/filters/merge.rs b/rsvg_internals/src/filters/merge.rs
index bb3970fe..4e611ddd 100644
--- a/rsvg_internals/src/filters/merge.rs
+++ b/rsvg_internals/src/filters/merge.rs
@@ -87,10 +87,7 @@ impl MergeNode {
         let input = ctx.get_input(draw_ctx, self.in_.borrow().as_ref())?;
 
         if output_surface.is_none() {
-            return input
-                .surface()
-                .copy_surface(bounds)
-                .map_err(FilterError::IntermediateSurfaceCreation);
+            return Ok(input.surface().copy_surface(bounds)?);
         }
         let output_surface = output_surface.unwrap();
 
@@ -147,14 +144,13 @@ impl Filter for Merge {
                 cairo::Format::ARgb32,
                 ctx.source_graphic().width(),
                 ctx.source_graphic().height(),
-            ).map_err(FilterError::IntermediateSurfaceCreation)?,
+            )?,
         };
 
         Ok(FilterResult {
             name: self.base.result.borrow().clone(),
             output: FilterOutput {
-                surface: SharedImageSurface::new(output_surface)
-                    .map_err(FilterError::BadIntermediateSurfaceStatus)?,
+                surface: SharedImageSurface::new(output_surface)?,
                 bounds,
             },
         })
diff --git a/rsvg_internals/src/filters/morphology.rs b/rsvg_internals/src/filters/morphology.rs
index 2b7f6786..9435387b 100644
--- a/rsvg_internals/src/filters/morphology.rs
+++ b/rsvg_internals/src/filters/morphology.rs
@@ -101,7 +101,7 @@ impl Filter for Morphology {
             cairo::Format::ARgb32,
             ctx.source_graphic().width(),
             ctx.source_graphic().height(),
-        ).map_err(FilterError::IntermediateSurfaceCreation)?;
+        )?;
 
         let output_stride = output_surface.get_stride() as usize;
         {
@@ -150,8 +150,7 @@ impl Filter for Morphology {
         Ok(FilterResult {
             name: self.base.result.borrow().clone(),
             output: FilterOutput {
-                surface: SharedImageSurface::new(output_surface)
-                    .map_err(FilterError::BadIntermediateSurfaceStatus)?,
+                surface: SharedImageSurface::new(output_surface)?,
                 bounds,
             },
         })
diff --git a/rsvg_internals/src/filters/offset.rs b/rsvg_internals/src/filters/offset.rs
index cb7a7618..bde1905e 100644
--- a/rsvg_internals/src/filters/offset.rs
+++ b/rsvg_internals/src/filters/offset.rs
@@ -90,7 +90,7 @@ impl Filter for Offset {
             cairo::Format::ARgb32,
             ctx.source_graphic().width(),
             ctx.source_graphic().height(),
-        ).map_err(FilterError::IntermediateSurfaceCreation)?;
+        )?;
 
         {
             let cr = cairo::Context::new(&output_surface);
@@ -109,8 +109,7 @@ impl Filter for Offset {
         Ok(FilterResult {
             name: self.base.result.borrow().clone(),
             output: FilterOutput {
-                surface: SharedImageSurface::new(output_surface)
-                    .map_err(FilterError::BadIntermediateSurfaceStatus)?,
+                surface: SharedImageSurface::new(output_surface)?,
                 bounds,
             },
         })
diff --git a/rsvg_internals/src/filters/tile.rs b/rsvg_internals/src/filters/tile.rs
index 69008394..15508f4c 100644
--- a/rsvg_internals/src/filters/tile.rs
+++ b/rsvg_internals/src/filters/tile.rs
@@ -58,7 +58,7 @@ impl Filter for Tile {
                     cairo::Format::ARgb32,
                     input_bounds.x1 - input_bounds.x0,
                     input_bounds.y1 - input_bounds.y0,
-                ).map_err(FilterError::IntermediateSurfaceCreation)?;
+                )?;
 
                 {
                     let cr = cairo::Context::new(&bounded_input_surface);
@@ -81,7 +81,7 @@ impl Filter for Tile {
                     cairo::Format::ARgb32,
                     ctx.source_graphic().width(),
                     ctx.source_graphic().height(),
-                ).map_err(FilterError::IntermediateSurfaceCreation)?;
+                )?;
 
                 {
                     let cr = cairo::Context::new(&output_surface);
@@ -97,8 +97,7 @@ impl Filter for Tile {
                     cr.paint();
                 }
 
-                SharedImageSurface::new(output_surface)
-                    .map_err(FilterError::BadIntermediateSurfaceStatus)?
+                SharedImageSurface::new(output_surface)?
             }
         };
 
diff --git a/rsvg_internals/src/filters/turbulence.rs b/rsvg_internals/src/filters/turbulence.rs
index 2598249a..b13e20ae 100644
--- a/rsvg_internals/src/filters/turbulence.rs
+++ b/rsvg_internals/src/filters/turbulence.rs
@@ -362,7 +362,7 @@ impl Filter for Turbulence {
             cairo::Format::ARgb32,
             ctx.source_graphic().width(),
             ctx.source_graphic().height(),
-        ).map_err(FilterError::IntermediateSurfaceCreation)?;
+        )?;
 
         let output_stride = output_surface.get_stride() as usize;
         {
@@ -404,8 +404,7 @@ impl Filter for Turbulence {
         Ok(FilterResult {
             name: self.base.result.borrow().clone(),
             output: FilterOutput {
-                surface: SharedImageSurface::new(output_surface)
-                    .map_err(FilterError::BadIntermediateSurfaceStatus)?,
+                surface: SharedImageSurface::new(output_surface)?,
                 bounds,
             },
         })


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