Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add get and set image profile to image magick #52

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 37 additions & 1 deletion magick/wand/data.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
13 changes: 11 additions & 2 deletions magick/wand/image.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down
45 changes: 9 additions & 36 deletions magick/wand/lib.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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()
Expand All @@ -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)
Expand All @@ -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
Expand Down