summaryrefslogtreecommitdiff
path: root/src/gegl.rs
diff options
context:
space:
mode:
authorKjetil Orbekk <kjetil.orbekk@gmail.com>2016-08-08 23:13:46 -0400
committerKjetil Orbekk <kjetil.orbekk@gmail.com>2016-08-08 23:13:46 -0400
commit996e089f75690045ac1e9de78e8f6f91ba25cf45 (patch)
treef66545aa4b74cb9b441601ae8d4554285da632b1 /src/gegl.rs
parentbbd2af6b67a846252b5cb07e7d46d78ce6231b6a (diff)
Move GEGL things to its own library.
Diffstat (limited to 'src/gegl.rs')
-rw-r--r--src/gegl.rs60
1 files changed, 60 insertions, 0 deletions
diff --git a/src/gegl.rs b/src/gegl.rs
new file mode 100644
index 0000000..b03fca1
--- /dev/null
+++ b/src/gegl.rs
@@ -0,0 +1,60 @@
+extern crate libc;
+
+use gegl_ffi as ffi;
+use std::ptr;
+use std::ffi::CString;
+
+pub struct GeglContext {
+ _private: ()
+}
+
+unsafe fn unref<T>(object: *mut T) {
+ ffi::g_object_unref(object as *mut libc::c_void);
+}
+
+impl GeglContext {
+ pub fn new() -> GeglContext {
+ unsafe { ffi::gegl_init(&mut 0, ptr::null_mut()) }
+ GeglContext { _private: () }
+ }
+
+ pub fn new_node(&self) -> GeglNode {
+ GeglNode(unsafe { ffi::gegl_node_new() })
+ }
+}
+
+impl Drop for GeglContext {
+ fn drop(&mut self) {
+ unsafe { ffi::gegl_exit(); }
+ }
+}
+
+pub struct GeglNode(*mut ffi::CGeglNode);
+
+impl 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())
+ })
+ }
+}
+
+impl Drop for GeglNode {
+ fn drop(&mut self) {
+ unsafe { unref(self.0); }
+ }
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+ use gegl_ffi as ffi;
+
+ #[test]
+ fn can_create_nodes() {
+ let context = GeglContext::new();
+ let node = context.new_node();
+ let node2 = context.new_node();
+ }
+}