Palash Sharma
Palash Sharma

Reputation: 1

How can I call cool image library functions by using prolog?

I am looking to build a system in which I am able to call Cool Image library functions (It's a C Language library for image processing tasks) by using Prolog.

There are functions in CoolImage Library such resizing an image, creating a mask etc. So I don't want to make any changes to those functions, it's just that by using Prolog I can call them and further use it for building a WIN32 API.

I would be thankful if someone can guide me regarding this i.e. any reference which I should refer or any way of implementation.

Upvotes: 0

Views: 141

Answers (1)

CapelliC
CapelliC

Reputation: 60034

I've uploaded to github an example of a simple minded interface, running the first example found in CImg documentation (see example.pl) when passed as argument to the program.

It shows how to create objects and define methods that act on such objects. Take a look at what the code does, and feel free to ask for problems.

edit:

Updated the git repo introducing modules for the interface predicates. Now exposed members of CImg,CImgDisplay classes must be prefixed respectively by cImg,cImgDisplay, and constructors/destructors are named new, delete.

The file example.pl has been moved to examples/getting_started.pl, and it's shown how to fetch images located relative to the source:


    ...
    module_property(getting_started,file(ModuleFile)),
    file_directory_name(ModuleFile,ModuleDir),
    directory_file_path(ModuleDir,'img/milla.bmp',Milla),

    cImg:new(Milla,Image),
    cImg:blur(Image,2.5),

edit: When you find you need to call a member not yet implemented, you should add it in your swipl_cimg.cpp, in the appropriate section (I mean, where you see the #define PROLOG_MODULE className... corresponding to the object you need), dereference the object(s) using the cast functions and call the c++ method. It's a lengthy, boring way, sorry but I don't know nothing better... To cover the full CImg library, a lot of work is required. So, attempt to implement - and carefully test - only what is needed...

It's useful to follow some convention: input parameters first, output last.

Upvotes: 1

Related Questions