Gimp <-> prolog interface
This discussion is connected to the gimp-developer-list.gnome.org mailing list which is provided by the GIMP developers and not related to gimpusers.com.
This is a read-only list on gimpusers.com so this discussion thread is read-only, too.
Gimp <-> prolog interface | Ryan Eisele | 03 Dec 04:17 |
200912031353.16672.tneuer@i... | Torsten Neuer | 03 Dec 13:53 |
Gimp <-> prolog interface | Joao S. O. Bueno | 03 Dec 19:15 |
Gimp <-> prolog interface | Ryan Eisele | 08 Dec 08:51 |
Gimp <-> prolog interface | Tor Lillqvist | 08 Dec 10:05 |
Gimp <-> prolog interface
I want to write some plug-ins in Prolog. I don't want to deal with any C pointers, while-loops or if-thens. Although the code below doesn't make use of it, I want to make use of Prolog backtracking in order to find a correct solution through trial-and-error, such as filling a region with a texture that melds into all edges with no abrupt color differences. I want to be able to write code such as this, in Prolog, for the blur function for example
blur(In, Out) :- blur(In, Out, In). %the function needs to access input pixels more than %once (not just when they are at the head of the input list), so pass on another copy of the %input as the 3rd argument
blur([], [], _). %when there is no more input, there is no more output, so stop
blur( [X-Y-A-R-G-B | Input_Tail], [OX-OY-OA-OR-OG-OB | Output_Tail], Input) :-
%find all the neighbors of current pixel, average them, and unify result with head of
%the output list
findall( X2-Y2-A2-R2-G2-B2, (
neighbor(X-Y, X2-Y2),
member(X2-Y2-A2-R2-G2-B2, Input),
Neighbors),
average_pixels(Neighbors, OX-OY-OA-OR-OG-OB),
blur(Input_Tail, Output_Tail, Input). %recursion
I want to be able to deal with the input and output in the form of a Prolog list, one list for each layer. And for multiple layers, a list of lists. The code above is written for one layer.
Each pixel could come in the form of X-Y-A-R-G-B (integers separated by hyphens) where X and Y are the location coordinates, A is the alpha channel, and R-G-B are their respective RGB values.
I understand that processing the data in Prolog would come with performance drawbacks, but I want to make use of backtracking, and I don't want to be dealing with for-loops and array pointers when I'm defining the output. If it needs to be optimized somebody could rewrite it into C.
Is there anyone who has written plug-ins before in the C language that would be able to help me make a Gimp Prolog interface so that Prolog programs can be run from a Gimp plug-in. I want to have a new plug-in under Filters->Prolog that will open up a list of *.pl files in the plug-ins directory (*.pl meaning Prolog file extension). I can then choose a *.pl file and the plug-in will then communicate with Prolog. So in other words, instead of compiling a plug-in for Gimp every time, this single plug-in will be able to run all Prolog programs in their *.pl form as soon as they are written.
Preferring to work in Prolog I need some help from a C programmer to write this plug-in. I'd appreciate any help from someone who has written a plug-in before.
Ryan
Gimp <-> prolog interface
Hi Ryan -
I strongly suggest you learn python instead, and us it for your scripts, instead.
It attends eveeryone of yoru requisites: - no dealing with pointers or memory allocation/deallocation - gimp data structures are provided as high level objects - the language syntax even allows for a funciotnal-like programing if you prefer that.
(for example to interact through layers, you just do:
image = gimp.list_images()[0]
for layer in image.layers:
#your code dealing with the "layer" object
When you get to the pixels you have then as a byte sequence, you then convert to a bytearray (python 2.6) - to get all the green bytes for the pixels from such an array on a separate array, I could do:
green =[1::4]
Follow the tutorial in www.python.org docs, you could get proficient in the language in less than 1 hour - then check the pythons cripts that come with gimp for examples of the API use and pixel access.
js ->
Gimp <-> prolog interface
js,
Thanks, I believe Python is the solution I was looking for.
- Ryan
--- On Thu, 12/3/09, Joao S. O. Bueno wrote:
From: Joao S. O. Bueno
Subject: Re: [Gimp-developer] Gimp prolog interface
To: "Ryan Eisele"
Cc: gimp-developer@lists.xcf.berkeley.edu
Date: Thursday, December 3, 2009, 1:15 PM
Hi Ryan -
I strongly suggest you learn python instead, and us it for your scripts, instead.
It attends eveeryone of yoru requisites: - no dealing with pointers or memory allocation/deallocation - gimp data structures are provided as high level objects - the language syntax even allows for a funciotnal-like programing if you prefer that.
(for example to interact through layers, you just do:
image = gimp.list_images()[0]
for layer in image.layers:
#your code dealing with the "layer" object
When you get to the pixels you have then as a byte sequence, you then convert to a bytearray (python 2.6) - to get all the green bytes for the pixels from such an array on a separate array, I could do:
green =[1::4]
Follow the tutorial in www.python.org docs, you could get proficient in the language in less than 1 hour - then check the pythons cripts that come with gimp for examples of the API use and pixel access.
js ->
Gimp <-> prolog interface
Thanks, I believe Python is the solution I was looking for.
But if you really wanted to use Prolog, surely Python is quite far from that? Or is there some extension or whatever to Python that allows one to write Prolog-like clauses, a Python-hosted Prolog in a way?
(Apparently, yes, there are several, see for instance http://code.activestate.com/recipes/303057/ , http://christophe.delord.free.fr/pylog/index.html and and http://codespeak.net/pypy/extradoc/paper/prolog-in-python.pdf )
--tml