[librsvg: 6/14] filters: port morphology to ExclusiveImageSurface
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 6/14] filters: port morphology to ExclusiveImageSurface
- Date: Wed, 15 Jan 2020 00:32:39 +0000 (UTC)
commit 4b24ba536bbb40d71eca89252877fbc537a6484a
Author: Paolo Borelli <pborelli gnome org>
Date: Tue Jan 14 01:29:25 2020 +0100
filters: port morphology to ExclusiveImageSurface
rsvg_internals/src/filters/morphology.rs | 83 +++++++++++++++-----------------
1 file changed, 39 insertions(+), 44 deletions(-)
---
diff --git a/rsvg_internals/src/filters/morphology.rs b/rsvg_internals/src/filters/morphology.rs
index 83302fb2..a2ab7fa2 100644
--- a/rsvg_internals/src/filters/morphology.rs
+++ b/rsvg_internals/src/filters/morphology.rs
@@ -11,8 +11,8 @@ use crate::property_bag::PropertyBag;
use crate::rect::IRect;
use crate::surface_utils::{
iterators::{PixelRectangle, Pixels},
- shared_surface::SharedImageSurface,
- EdgeMode, ImageSurfaceDataExt, Pixel,
+ shared_surface::ExclusiveImageSurface,
+ EdgeMode, Pixel,
};
use super::context::{FilterContext, FilterOutput, FilterResult};
@@ -92,60 +92,55 @@ impl FilterEffect for FeMorphology {
// The radii can become negative here due to the transform.
let (rx, ry) = (rx.abs(), ry.abs());
- 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) {
- // Compute the kernel rectangle bounds.
- let kernel_bounds = IRect::new(
- (f64::from(x) - rx).floor() as i32,
- (f64::from(y) - ry).floor() as i32,
- (f64::from(x) + rx).ceil() as i32 + 1,
- (f64::from(y) + ry).ceil() as i32 + 1,
- );
-
- // Compute the new pixel values.
- let initial = match self.operator {
- Operator::Erode => u8::max_value(),
- Operator::Dilate => u8::min_value(),
+ for (x, y, _pixel) in Pixels::within(input.surface(), bounds) {
+ // Compute the kernel rectangle bounds.
+ let kernel_bounds = IRect::new(
+ (f64::from(x) - rx).floor() as i32,
+ (f64::from(y) - ry).floor() as i32,
+ (f64::from(x) + rx).ceil() as i32 + 1,
+ (f64::from(y) + ry).ceil() as i32 + 1,
+ );
+
+ // Compute the new pixel values.
+ let initial = match self.operator {
+ Operator::Erode => u8::max_value(),
+ Operator::Dilate => u8::min_value(),
+ };
+
+ let mut output_pixel = Pixel {
+ r: initial,
+ g: initial,
+ b: initial,
+ a: initial,
+ };
+
+ for (_x, _y, pixel) in
+ PixelRectangle::within(&input.surface(), bounds, kernel_bounds, EdgeMode::None)
+ {
+ let op = match self.operator {
+ Operator::Erode => min,
+ Operator::Dilate => max,
};
- let mut output_pixel = Pixel {
- r: initial,
- g: initial,
- b: initial,
- a: initial,
- };
-
- for (_x, _y, pixel) in
- PixelRectangle::within(&input.surface(), bounds, kernel_bounds, EdgeMode::None)
- {
- let op = match self.operator {
- Operator::Erode => min,
- Operator::Dilate => max,
- };
-
- output_pixel.r = op(output_pixel.r, pixel.r);
- output_pixel.g = op(output_pixel.g, pixel.g);
- output_pixel.b = op(output_pixel.b, pixel.b);
- output_pixel.a = op(output_pixel.a, pixel.a);
- }
-
- output_data.set_pixel(output_stride, output_pixel, x, y);
+ output_pixel.r = op(output_pixel.r, pixel.r);
+ output_pixel.g = op(output_pixel.g, pixel.g);
+ output_pixel.b = op(output_pixel.b, pixel.b);
+ output_pixel.a = op(output_pixel.a, pixel.a);
}
+
+ 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]