diff --git a/README.md b/README.md index d7f8683..9729f43 100644 --- a/README.md +++ b/README.md @@ -320,11 +320,25 @@ This creates a new metadata item of the specified type, name and value. This changes the value of an existing field, but will not change its type. +You can't use `set()` to change core fields such as like `width` or +`interpretation`. Use `copy()` instead.` + +Image references will be shared by the operation cache, so modifying an image +can chage an image somewhere else in your program. Before changing an image, +you must make sure you own a private copy of an image with `copy`. + +```lua +local new_image = image:copy()` +new_image:set("orientation", 7) +``` + ### `boolean = vips.Image.remove(image, field_name)` This will remove a piece of metadata. It returns `true` if an item was successfully removed, `false` otherwise. +As with `set`, you must use copy before removing a metadata item. + ## Call any libvips operation You can call any libvips operation as a member function, for example diff --git a/src/vips.lua b/src/vips.lua index 77f5d7b..802df96 100644 --- a/src/vips.lua +++ b/src/vips.lua @@ -22,6 +22,7 @@ local vips = { vobject = require "vips.vobject", voperation = require "vips.voperation", Image = require "vips.Image_methods", + Image = require "vips.Interpolate", } function vips.leak_set(leak) diff --git a/src/vips/Interpolate.lua b/src/vips/Interpolate.lua new file mode 100644 index 0000000..359ee22 --- /dev/null +++ b/src/vips/Interpolate.lua @@ -0,0 +1,34 @@ +-- make image interpolators, see affine + +local ffi = require "ffi" + +local verror = require "vips.verror" +local vobject = require "vips.vobject" + +local vips_lib = ffi.load(ffi.os == "Windows" and "libvips-42.dll" or "vips") + +local Interpolate = {} + +Interpolate.vobject = function(self) + return ffi.cast(vobject.typeof, self) +end + +Interpolate.new = function(self) + return vobject.new(self) +end + +Interpolate.new_from_name = function(name) + -- there could potentially be other params here, but ignore that for now + local interpolate = vips_lib.vips_interpolate_new(name) + if interpolate == nil then + error("no such interpolator\n" .. verror.get()) + end + + return Interpolate.new(interpolate) +end + +return ffi.metatype("Interpolate", { + __index = Interpolate +}) + + diff --git a/src/vips/cdefs.lua b/src/vips/cdefs.lua index 81e427e..3ba723a 100644 --- a/src/vips/cdefs.lua +++ b/src/vips/cdefs.lua @@ -186,6 +186,8 @@ ffi.cdef [[ // opaque } VipsOperation; + VipsInterpolate *vips_interpolate_new (const char *name); + VipsOperation *vips_operation_new (const char *name); typedef void * (*VipsArgumentMapFn) (VipsOperation *object,