New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix parameters for ImageSurface::create_from_png and write_to_png #123

Merged
merged 1 commit into from Apr 23, 2017

Conversation

Projects
None yet
2 participants
@EPashkin
Member

EPashkin commented Apr 23, 2017

Fix errors found in #121

@EPashkin

This comment has been minimized.

Show comment
Hide comment
@EPashkin

EPashkin Apr 23, 2017

Member

@GuillaumeGomez I tested it with cairo_threads: first part writes, after switching part it read

diff --git a/src/bin/cairo_threads.rs b/src/bin/cairo_threads.rs
index 2d66a72..6800ba0 100644
--- a/src/bin/cairo_threads.rs
+++ b/src/bin/cairo_threads.rs
@@ -117,6 +117,13 @@ fn main() {
                 // draw an arc with a weirdly calculated radius
                 draw_slow(&cr, delay, x, y, 1.2_f64.powi(((n as i32) << thread_num) % 32));
                 image.flush();
+
+if thread_num == 0 && n == 20 {
+println!("writing");
+let mut file = std::fs::File::create("test.png").unwrap();
+image.write_to_png(&mut file);
+}
+
             }
         }));
     }
@@ -141,8 +148,14 @@ fn main() {
         while let Ok((thread_num, buf)) = ready_rx.try_recv() {
             let &mut (ref mut images, ref origins, ref workers) = &mut *cell.borrow_mut();
             let tx = workers[thread_num].clone();
-            let mut image = ImageSurface::create_for_data(buf, move |b| { let _ = tx.send(b); },
+let mut image: ImageSurface;
+/*if thread_num == 0 {
+let mut file = std::fs::File::open("test.png").unwrap();
+image = ImageSurface::create_from_png(&mut file).unwrap();
+} else*/ {
+            image = ImageSurface::create_for_data(buf, move |b| { let _ = tx.send(b); },
                 format, width, height, stride);
+}
             mem::swap(&mut images[thread_num], &mut image);
             area.queue_draw_area(origins[thread_num].0, origins[thread_num].1, width, height);
         }
Member

EPashkin commented Apr 23, 2017

@GuillaumeGomez I tested it with cairo_threads: first part writes, after switching part it read

diff --git a/src/bin/cairo_threads.rs b/src/bin/cairo_threads.rs
index 2d66a72..6800ba0 100644
--- a/src/bin/cairo_threads.rs
+++ b/src/bin/cairo_threads.rs
@@ -117,6 +117,13 @@ fn main() {
                 // draw an arc with a weirdly calculated radius
                 draw_slow(&cr, delay, x, y, 1.2_f64.powi(((n as i32) << thread_num) % 32));
                 image.flush();
+
+if thread_num == 0 && n == 20 {
+println!("writing");
+let mut file = std::fs::File::create("test.png").unwrap();
+image.write_to_png(&mut file);
+}
+
             }
         }));
     }
@@ -141,8 +148,14 @@ fn main() {
         while let Ok((thread_num, buf)) = ready_rx.try_recv() {
             let &mut (ref mut images, ref origins, ref workers) = &mut *cell.borrow_mut();
             let tx = workers[thread_num].clone();
-            let mut image = ImageSurface::create_for_data(buf, move |b| { let _ = tx.send(b); },
+let mut image: ImageSurface;
+/*if thread_num == 0 {
+let mut file = std::fs::File::open("test.png").unwrap();
+image = ImageSurface::create_from_png(&mut file).unwrap();
+} else*/ {
+            image = ImageSurface::create_for_data(buf, move |b| { let _ = tx.send(b); },
                 format, width, height, stride);
+}
             mem::swap(&mut images[thread_num], &mut image);
             area.queue_draw_area(origins[thread_num].0, origins[thread_num].1, width, height);
         }
@GuillaumeGomez

This comment has been minimized.

Show comment
Hide comment
@GuillaumeGomez

GuillaumeGomez Apr 23, 2017

Member

Thanks!

Member

GuillaumeGomez commented Apr 23, 2017

Thanks!

@GuillaumeGomez GuillaumeGomez merged commit 7e23bcd into gtk-rs:master Apr 23, 2017

2 checks passed

continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details

@EPashkin EPashkin deleted the EPashkin:write_to_png branch Apr 23, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment