[librsvg: 2/14] filters: port color matrix to ExclusiveImageSurface



commit ff31ea09dbc254f5264c984d4723b64cb7e76944
Author: Paolo Borelli <pborelli gnome org>
Date:   Tue Jan 14 01:07:03 2020 +0100

    filters: port color matrix to ExclusiveImageSurface

 rsvg_internals/src/filters/color_matrix.rs | 65 +++++++++++++-----------------
 1 file changed, 29 insertions(+), 36 deletions(-)
---
diff --git a/rsvg_internals/src/filters/color_matrix.rs b/rsvg_internals/src/filters/color_matrix.rs
index 5882e93a..230f200b 100644
--- a/rsvg_internals/src/filters/color_matrix.rs
+++ b/rsvg_internals/src/filters/color_matrix.rs
@@ -8,9 +8,7 @@ use crate::node::{NodeResult, NodeTrait, RsvgNode};
 use crate::number_list::{NumberList, NumberListLength};
 use crate::parsers::{Parse, ParseValue};
 use crate::property_bag::PropertyBag;
-use crate::surface_utils::{
-    iterators::Pixels, shared_surface::SharedImageSurface, ImageSurfaceDataExt, Pixel,
-};
+use crate::surface_utils::{iterators::Pixels, shared_surface::ExclusiveImageSurface, Pixel};
 use crate::util::clamp;
 
 use super::context::{FilterContext, FilterOutput, FilterResult};
@@ -166,52 +164,47 @@ impl FilterEffect for FeColorMatrix {
             .add_input(&input)
             .into_irect(draw_ctx);
 
-        let mut output_surface = cairo::ImageSurface::create(
-            cairo::Format::ARgb32,
+        let mut surface = ExclusiveImageSurface::new(
             ctx.source_graphic().width(),
             ctx.source_graphic().height(),
+            input.surface().surface_type(),
         )?;
 
-        let output_stride = output_surface.get_stride() as usize;
-        {
-            let mut output_data = output_surface.get_data().unwrap();
-
-            for (x, y, pixel) in Pixels::within(input.surface(), bounds) {
-                let alpha = f64::from(pixel.a) / 255f64;
-
-                let pixel_vec = if alpha == 0.0 {
-                    Vector5::new(0.0, 0.0, 0.0, 0.0, 1.0)
-                } else {
-                    Vector5::new(
-                        f64::from(pixel.r) / 255f64 / alpha,
-                        f64::from(pixel.g) / 255f64 / alpha,
-                        f64::from(pixel.b) / 255f64 / alpha,
-                        alpha,
-                        1.0,
-                    )
-                };
-                let mut new_pixel_vec = Vector5::zeros();
-                self.matrix.mul_to(&pixel_vec, &mut new_pixel_vec);
+        for (x, y, pixel) in Pixels::within(input.surface(), bounds) {
+            let alpha = f64::from(pixel.a) / 255f64;
+
+            let pixel_vec = if alpha == 0.0 {
+                Vector5::new(0.0, 0.0, 0.0, 0.0, 1.0)
+            } else {
+                Vector5::new(
+                    f64::from(pixel.r) / 255f64 / alpha,
+                    f64::from(pixel.g) / 255f64 / alpha,
+                    f64::from(pixel.b) / 255f64 / alpha,
+                    alpha,
+                    1.0,
+                )
+            };
+            let mut new_pixel_vec = Vector5::zeros();
+            self.matrix.mul_to(&pixel_vec, &mut new_pixel_vec);
 
-                let new_alpha = clamp(new_pixel_vec[3], 0.0, 1.0);
+            let new_alpha = clamp(new_pixel_vec[3], 0.0, 1.0);
 
-                let premultiply = |x: f64| ((clamp(x, 0.0, 1.0) * new_alpha * 255f64) + 0.5) as u8;
+            let premultiply = |x: f64| ((clamp(x, 0.0, 1.0) * new_alpha * 255f64) + 0.5) as u8;
 
-                let output_pixel = Pixel {
-                    r: premultiply(new_pixel_vec[0]),
-                    g: premultiply(new_pixel_vec[1]),
-                    b: premultiply(new_pixel_vec[2]),
-                    a: ((new_alpha * 255f64) + 0.5) as u8,
-                };
+            let output_pixel = Pixel {
+                r: premultiply(new_pixel_vec[0]),
+                g: premultiply(new_pixel_vec[1]),
+                b: premultiply(new_pixel_vec[2]),
+                a: ((new_alpha * 255f64) + 0.5) as u8,
+            };
 
-                output_data.set_pixel(output_stride, output_pixel, x, y);
-            }
+            surface.set_pixel(output_pixel, x, y);
         }
 
         Ok(FilterResult {
             name: self.base.result.clone(),
             output: FilterOutput {
-                surface: SharedImageSurface::wrap(output_surface, input.surface().surface_type())?,
+                surface: surface.share()?,
                 bounds,
             },
         })


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