summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKjetil Orbekk <kjetil.orbekk@gmail.com>2016-08-10 23:43:01 -0400
committerKjetil Orbekk <kjetil.orbekk@gmail.com>2016-08-10 23:43:01 -0400
commitcc81524cecc2be3d326ed2a8d85c4e1c1966dd46 (patch)
treedb9248e02f69f9c680913ff64adf52e52fc5a6d2
parente8ed9ace0b7e2aed2bd0c6b99a6787da411ad9cb (diff)
Add load() operation.
-rw-r--r--src/gegl.rs41
-rw-r--r--src/lib.rs3
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<String> {
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::<String>::new(), list_operations());
+ // assert_eq!(Vec::<String>::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;