[librsvg: 4/9] Use the rows iterator in pixbuf_from_surface to iterate the SharedImageSurface



commit 2dded1936bc3d8d5b0962ad269860452c436bbaf
Author: Federico Mena Quintero <federico gnome org>
Date:   Thu May 28 18:13:37 2020 -0500

    Use the rows iterator in pixbuf_from_surface to iterate the SharedImageSurface
    
    The next step is to iterate quickly on the pixbuf.

 librsvg/pixbuf_utils.rs   | 35 +++++++++++++++++++++--------------
 rsvg_internals/src/lib.rs |  1 +
 2 files changed, 22 insertions(+), 14 deletions(-)
---
diff --git a/librsvg/pixbuf_utils.rs b/librsvg/pixbuf_utils.rs
index b2f4fcaa..e6dcef7c 100644
--- a/librsvg/pixbuf_utils.rs
+++ b/librsvg/pixbuf_utils.rs
@@ -9,7 +9,7 @@ use url::Url;
 use crate::c_api::checked_i32;
 
 use rsvg_internals::{
-    Dpi, Handle, IRect, LoadOptions, LoadingError, Pixels, RenderingError, SharedImageSurface,
+    Dpi, Handle, LoadOptions, LoadingError, Pixel, RenderingError, SharedImageSurface,
     SurfaceType,
 };
 
@@ -36,20 +36,27 @@ pub fn pixbuf_from_surface(surface: &SharedImageSurface) -> Result<Pixbuf, Rende
     let height = surface.height();
 
     let pixbuf = pixbuf_new(width, height)?;
-    let bounds = IRect::from_size(width, height);
-
-    for (x, y, pixel) in Pixels::within(&surface, bounds) {
-        let (r, g, b, a) = if pixel.a == 0 {
-            (0, 0, 0, 0)
-        } else {
-            let pixel = pixel.unpremultiply();
-            (pixel.r, pixel.g, pixel.b, pixel.a)
-        };
 
-        // FIXME: Use pixbuf.put_pixel when
-        // https://github.com/gtk-rs/gdk-pixbuf/issues/147
-        // is integrated
-        my_put_pixel(&pixbuf, x as i32, y as i32, r, g, b, a);
+    for (y, row) in surface.rows().enumerate() {
+        for (x, pixel) in row.iter().enumerate() {
+            let (r, g, b, a) = if pixel.a == 0 {
+                (0, 0, 0, 0)
+            } else {
+                let pixel = Pixel {
+                    r: pixel.r,
+                    g: pixel.g,
+                    b: pixel.b,
+                    a: pixel.a,
+                }.unpremultiply();
+
+                (pixel.r, pixel.g, pixel.b, pixel.a)
+            };
+
+            // FIXME: Use pixbuf.put_pixel when
+            // https://github.com/gtk-rs/gdk-pixbuf/issues/147
+            // is integrated
+            my_put_pixel(&pixbuf, x as i32, y as i32, r, g, b, a);
+        }
     }
 
     Ok(pixbuf)
diff --git a/rsvg_internals/src/lib.rs b/rsvg_internals/src/lib.rs
index fe86e648..0c5f2784 100644
--- a/rsvg_internals/src/lib.rs
+++ b/rsvg_internals/src/lib.rs
@@ -66,6 +66,7 @@ pub use crate::structure::IntrinsicDimensions;
 pub use crate::surface_utils::{
     iterators::Pixels,
     shared_surface::{SharedImageSurface, SurfaceType},
+    Pixel,
 };
 
 pub use crate::viewbox::ViewBox;


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