leafo / magick

Lua bindings to ImageMagick for LuaJIT using FFI
407 stars 80 forks source link

Trying to implement MagickGetImageHistogram. #44

Closed rahulpatel033 closed 7 years ago

rahulpatel033 commented 7 years ago

I have been trying to implement MagickGetImageHistogram, so I have changed two files. below is my change. image.lua

local len = ffi.new("size_t[?]", 5)
local t = handle_result(self, lib.MagickGetImageHistogram(self.wand, len))

lib.lua

ffi.cdef([[  typedef void MagickWand;
typedef void PixelWand;

typedef int MagickBooleanType;
typedef int ExceptionType;
typedef int ssize_t;
typedef int CompositeOperator;
typedef int GravityType;
typedef int OrientationType;
typedef int InterlaceType;
typedef char DistortMethod[];

void MagickWandGenesis();
MagickWand* NewMagickWand();

PixelWand **MagickGetImageHistogram(MagickWand *wand, size_t *number_colors);
]])

But when I called MagickGetImageHistogram function from image.lua, it always return bool true. I don't understand what I missed. In documentation it says

MagickGetImageHistogram() returns the image histogram as an array of PixelWand wands.

So how do I convert it to lua table?

leafo commented 7 years ago

you should be able to use the ffi library to extract the information you need: http://luajit.org/ext_ffi.html

rahulpatel033 commented 7 years ago

Honestly, I'm new to lua. I started to learn few weeks ago. I checked ffi library and passed the second argument like local len = ffi.new("size_t[?]", 5) , but I don't understand why it returns boolean true. It should be an array of PixelWand wands. I don't know what I missed.