From cc81524cecc2be3d326ed2a8d85c4e1c1966dd46 Mon Sep 17 00:00:00 2001 From: Kjetil Orbekk Date: Wed, 10 Aug 2016 23:43:01 -0400 Subject: Add load() operation. --- src/gegl.rs | 41 ++++++++++++++++++++++++++++++----------- src/lib.rs | 3 +++ 2 files changed, 33 insertions(+), 11 deletions(-) diff --git a/src/gegl.rs b/src/gegl.rs index 0ffdf9c..d5655d2 100644 --- a/src/gegl.rs +++ b/src/gegl.rs @@ -1,9 +1,10 @@ -extern crate libc; - +use glib::Value; +use glib::translate::*; use gegl_ffi as ffi; use std::ptr; use std::ffi::CString; use std::ffi::CStr; +use libc; pub struct GeglContext { _private: () @@ -26,14 +27,14 @@ impl GeglContext { impl Drop for GeglContext { fn drop(&mut self) { - unsafe { ffi::gegl_exit(); } + // unsafe { ffi::gegl_exit(); } } } pub struct GeglNode(*mut ffi::CGeglNode); impl GeglNode { - pub fn create_child(self, operation: &str) -> GeglNode { + pub fn create_child(&self, operation: &str) -> GeglNode { GeglNode(unsafe { let operation0 = CString::new(operation).unwrap(); ffi::gegl_node_create_child(self.0, operation0.as_ptr()) @@ -47,6 +48,24 @@ impl Drop for GeglNode { } } +pub trait GeglOperations { + fn load(&self, path: &str) -> GeglNode; +} + +impl GeglOperations for GeglNode { + fn load(&self, path: &str) -> GeglNode { + let result = self.create_child("gegl:load"); + unsafe { + ffi::gegl_node_set_property( + result.0, + CString::new("path").unwrap().as_ptr(), + Value::from(path).to_glib_none().0 + as *const libc::c_void); + } + result + } +} + pub fn list_operations() -> Vec { let mut num_operations: usize = 0; let mut result = vec!(); @@ -70,13 +89,13 @@ mod tests { #[test] fn implements_all_operations() { let context = GeglContext::new(); - assert_eq!(Vec::::new(), list_operations()); + // assert_eq!(Vec::::new(), list_operations()); } - // #[test] - // fn can_create_nodes() { - // let context = GeglContext::new(); - // context.new_node(); - // context.new_node(); - // } + #[test] + fn can_create_nodes() { + let context = GeglContext::new(); + context.new_node(); + context.new_node(); + } } diff --git a/src/lib.rs b/src/lib.rs index 0acd7f0..4a016c8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,2 +1,5 @@ +extern crate libc; +extern crate glib; + pub mod gegl_ffi; pub mod gegl; -- cgit v1.2.3