diff --git a/magick/wand/data.lua b/magick/wand/data.lua index dec9a4c..fc2a0fc 100644 --- a/magick/wand/data.lua +++ b/magick/wand/data.lua @@ -105,9 +105,45 @@ local interlace = enum({ "JPEGInterlace", "PNGInterlace" }) +local filtertype = enum({ + [0] = "UndefinedFilter", + "PointFilter", + "BoxFilter", + "TriangleFilter", + "HermiteFilter", + "HannFilter", + "HammingFilter", + "BlackmanFilter", + "GaussianFilter", + "QuadraticFilter", + "CubicFilter", + "CatromFilter", + "MitchellFilter", + "JincFilter", + "SincFilter", + "SincFastFilter", + "KaiserFilter", + "WelchFilter", + "ParzenFilter", + "BohmanFilter", + "BartlettFilter", + "LagrangeFilter", + "LanczosFilter", + "LanczosSharpFilter", + "Lanczos2Filter", + "Lanczos2SharpFilter", + "RobidouxFilter", + "RobidouxSharpFilter", + "CosineFilter", + "SplineFilter", + "LanczosRadiusFilter", + "CubicSplineFilter", + "SentinelFilter" +}) return { composite_operators = composite_operators, gravity = gravity, orientation = orientation, - interlace = interlace + interlace = interlace, + filtertype = filtertype } diff --git a/magick/wand/image.lua b/magick/wand/image.lua index 21a1d19..35d3257 100644 --- a/magick/wand/image.lua +++ b/magick/wand/image.lua @@ -4,10 +4,11 @@ do local _obj_0 = require("magick.wand.lib") lib, can_resize, get_filter = _obj_0.lib, _obj_0.can_resize, _obj_0.get_filter end -local composite_operators, gravity, orientation, interlace +local composite_operators, gravity, orientation, interlace, filtertype do local _obj_0 = require("magick.wand.data") composite_operators, gravity, orientation, interlace = _obj_0.composite_operators, _obj_0.gravity, _obj_0.orientation, _obj_0.interlace + filtertype = _obj_0.filtertype end local get_exception get_exception = function(wand) @@ -101,7 +102,7 @@ do error("Failed to load filter list, can't resize") end w, h = self:_keep_aspect(w, h) - return handle_result(self, lib.MagickResizeImage(self.wand, w, h, get_filter(f), blur)) + return handle_result(self, lib.MagickResizeImage(self.wand, w, h, filtertype:to_int(f .. 'Filter'), blur)) end, adaptive_resize = function(self, w, h) w, h = self:_keep_aspect(w, h) @@ -238,6 +239,14 @@ do itype = assert(interlace:to_int(itype), "invalid interlace type") return lib.MagickSetImageInterlaceScheme(self.wand, itype) end, + get_profile = function(self, profile) + local len = ffi.new("size_t[1]", 0) + local blob = ffi.gc(lib.MagickGetImageProfile(self.wand, profile, len), lib.MagickRelinquishMemory) + return ffi.string(blob, len[0]) + end, + set_profile = function(self, profile, value) + return handle_result(self, lib.MagickSetImageProfile(self.wand, profile, value, #value)) + end, auto_orient = function(self) return handle_result(self, lib.MagickAutoOrientImage(self.wand)) end, diff --git a/magick/wand/lib.lua b/magick/wand/lib.lua index d5ab763..015af8f 100644 --- a/magick/wand/lib.lua +++ b/magick/wand/lib.lua @@ -10,6 +10,7 @@ ffi.cdef([[ typedef void MagickWand; typedef int GravityType; typedef int OrientationType; typedef int InterlaceType; + typedef int FilterType; void MagickWandGenesis(); MagickWand* NewMagickWand(); @@ -114,6 +115,12 @@ ffi.cdef([[ typedef void MagickWand; MagickBooleanType MagickSetImageDepth(MagickWand *,const unsigned long); unsigned long MagickGetImageDepth(MagickWand *); + unsigned char *MagickGetImageProfile(MagickWand *wand,const char *name, + size_t *length); + + MagickBooleanType MagickSetImageProfile(MagickWand *wand,const char *name, + const void *profile,const size_t length); + ]]) local get_flags get_flags = function() @@ -127,41 +134,7 @@ get_flags = function() end local get_filters get_filters = function() - local fname = "magick/resample.h" - local prefixes = { - "/usr/include/ImageMagick", - "/usr/local/include/ImageMagick", - unpack((function() - local _accum_0 = { } - local _len_0 = 1 - for p in get_flags():gmatch("-I([^%s]+)") do - _accum_0[_len_0] = p - _len_0 = _len_0 + 1 - end - return _accum_0 - end)()) - } - for _index_0 = 1, #prefixes do - local p = prefixes[_index_0] - local full = tostring(p) .. "/" .. tostring(fname) - do - local f = io.open(full) - if f then - local content - do - local _with_0 = f:read("*a") - f:close() - content = _with_0 - end - local filter_types = content:match("(typedef enum.-FilterTypes;)") - if filter_types then - ffi.cdef(filter_types) - return true - end - end - end - end - return false + return true end local get_filter get_filter = function(name) @@ -171,7 +144,7 @@ local can_resize if get_filters() then ffi.cdef([[ MagickBooleanType MagickResizeImage(MagickWand*, const size_t, const size_t, - const FilterTypes, const double); + const FilterType, const double); ]]) can_resize = true end