1 module vips.operation; 2 3 import vips.bindings; 4 import vips.option; 5 import vips.conv : toGObject; 6 import gobject.Value; 7 import std..string : toStringz; 8 9 /** 10 * Wrapper around VipsOperation struct 11 */ 12 struct VOperation 13 { 14 private: 15 VipsOperation* operation; 16 public: 17 /** 18 * Construct new VipsOperation 19 * Given a name 20 */ 21 this(const(char)[] opName) 22 { 23 operation = vips_operation_new(opName.toStringz); 24 } 25 26 /** 27 * Construct a new VipsOperation 28 * Given an existing pointer 29 */ 30 this(VipsOperation* operation, bool ownedRef = false) 31 { 32 this.operation = operation; 33 if(!ownedRef){ 34 g_object_ref(operation); 35 } 36 } 37 38 ~this() 39 { 40 g_object_unref(operation); 41 } 42 43 /** 44 * Run an operation with a specific set of options 45 */ 46 void build(ref VOption options) 47 { 48 options.setInputs(this); 49 auto op = VOperation(vips_cache_operation_build(operation), true); 50 scope(exit) vips_object_unref_outputs(op.operation); 51 options.readOutputs(op); 52 } 53 54 void setProperty(string key, Value value) 55 { 56 import vips.bindings : g_object_set_property; 57 g_object_set_property( 58 operation.toGObject, 59 key.toStringz, 60 value.getValueStruct(), 61 ); 62 } 63 64 void getProperty(string key, Value value) 65 { 66 import vips.bindings : g_object_get_property; 67 g_object_get_property( 68 operation.toGObject, 69 key.toStringz, 70 value.getValueStruct(), 71 ); 72 } 73 }