calling a procedure in a plugin
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.
calling a procedure in a plugin | Giuseppe Pasquino | 16 Oct 13:04 |
calling a procedure in a plugin | Aurimas Juška | 16 Oct 16:02 |
calling a procedure in a plugin | Giuseppe Pasquino | 16 Oct 16:39 |
calling a procedure in a plugin | Sven Neumann | 17 Oct 20:34 |
calling a procedure in a plugin | Sven Neumann | 17 Oct 20:32 |
calling a procedure in a plugin | Giuseppe Pasquino | 18 Oct 11:59 |
calling a procedure in a plugin | Aurimas Juška | 18 Oct 12:06 |
calling a procedure in a plugin | Giuseppe Pasquino | 18 Oct 14:14 |
calling a procedure in a plugin | Sven Neumann | 18 Oct 14:32 |
calling a procedure in a plugin | Giuseppe Pasquino | 18 Oct 15:05 |
calling a procedure in a plugin | Sven Neumann | 18 Oct 15:13 |
calling a procedure in a plugin | Giuseppe Pasquino | 19 Oct 11:00 |
calling a procedure in a plugin | David Gowers | 19 Oct 11:27 |
calling a procedure in a plugin | Giuseppe Pasquino | 19 Oct 11:37 |
calling a procedure in a plugin | Giuseppe Pasquino | 16 Oct 14:22 |
calling a procedure in a plugin
Hello, I'm working on this plugin: after few operations, it picks a color from the image (with che function gimp_pixel_rgn_get_pixel) to get the guchar value of the components of the related color. At this point, I need to call the "gimp_by_color_select" procedure but I'm not sure to follow the right way... Anyone can help me? How do I manage the guchar values to convert in GimpRGB?
Thanks a lot to all and sorry for my bad English (I'm italian)...
Giuseppe.
__________________
calling a procedure in a plugin
Hello, I'm working on this plugin:after few operations, it picks a color from the image (with che function gimp_pixel_rgn_get_pixel) to get the guchar value of the components of the related color.At this point, I need to call the "gimp_by_color_select" procedure but I'm not sure to follow the right way... Anyone can help me? How do I manage the guchar values to convert in GimpRGB?Thanks a lot to all and sorry for my bad English (I'm italian)...Giuseppe. __________________
calling a procedure in a plugin
http://developer.gimp.org/api/2.0/libgimp/libgimp-gimp.html#gimp-run-procedure
Procedure parameters: http://www.goof.com/pcg/marc/pdb/gimp_by_color_select.html
But it is generally easier to lookup params in procedure browser.
On 10/16/07, Giuseppe Pasquino wrote:
Hello, I'm working on this plugin: after few operations, it picks a color from the image (with che function gimp_pixel_rgn_get_pixel) to get the guchar value of the components of the related color.
At this point, I need to call the "gimp_by_color_select" procedure but I'm not sure to follow the right way... Anyone can help me? How do I manage the guchar values to convert in GimpRGB?Thanks a lot to all and sorry for my bad English (I'm italian)...
Giuseppe.
________________________________ Con Windows Live Messenger condividi file senza limiti di peso! Windows Live Messenger
calling a procedure in a plugin
Thanks for your help... I have another question: how can I convert a guchar value taken by "gimp_pixel_rgn_get_pixel" to COLOR?
Date: Tue, 16 Oct 2007 17:02:15 +0300> From: aurimas.juska@gmail.com> To: giuseppepasquino@hotmail.com> Subject: Re: [Gimp-developer] calling a procedure in a plugin> CC: gimp-developer@lists.xcf.berkeley.edu> > http://developer.gimp.org/api/2.0/libgimp/libgimp-gimp.html#gimp-run-procedure> > Procedure parameters:> http://www.goof.com/pcg/marc/pdb/gimp_by_color_select.html> > But it is generally easier to lookup params in procedure browser.
__________________
calling a procedure in a plugin
Hi,
On Tue, 2007-10-16 at 13:04 +0200, Giuseppe Pasquino wrote:
after few operations, it picks a color from the image (with che function gimp_pixel_rgn_get_pixel) to get the guchar value of the components of the related color.
At this point, I need to call the "gimp_by_color_select" procedure
Just use the C wrapper. Have a look at the API reference manual, it's
all nicely documented:
http://developer.gimp.org/api/2.0/libgimp/libgimp-gimptools.html#id2678685
How do I manage the guchar values to convert in GimpRGB?
http://developer.gimp.org/api/2.0/libgimpcolor/libgimpcolor-GimpRGB.html#gimp-rgb-set-uchar
Sven
calling a procedure in a plugin
Hi,
On Tue, 2007-10-16 at 17:02 +0300, Aurimas Juška wrote:
http://developer.gimp.org/api/2.0/libgimp/libgimp-gimp.html#gimp-run-procedure
Procedure parameters: http://www.goof.com/pcg/marc/pdb/gimp_by_color_select.html
Thanks for your attempt to help. But please don't point people to the outdated PDB documentation at Marc's website. It hasn't been updated for ages and we have a nice API reference manual online at http://developer.gimp.org/.
Sven
calling a procedure in a plugin
Thanks to all for the useful help... I'll write this function but it return a fatal error (SEGMENTATION FAULT) and it don't make the selection...
Here is the code:
static void evidenzia (GimpDrawable *drawable, GimpPreview *preview){ gint width, height; //dell'immagine su cui va applicato il plugin gint altezza, larghezza; //numero di pixel formanti la palette gint x1, x2, y1, y2; GimpPixelRgn rgn_in, rgn_out; guchar pixel[4]; guchar colore[3]; gint i, channels; gint distanza; GimpParam *return_vals; gint nreturn_vals; if (preview) return; else gimp_progress_init ("Evidenzia Temperatura...");
//Recupero del drawable gimp_drawable_mask_bounds (drawable->drawable_id, &x1, &y1, &x2, &y2); width = x2 - x1; height = y2 - y1;
/* Inizializza due PixelRgns, uno per leggere i dati originali, * e l'altro per scrivere i dati modificati. Il secondo sarà * poi applicato all'immaginne alla fine attraverso la chiamata * gimp_drawable_merge_shadow() */ gimp_pixel_rgn_init (&rgn_in, drawable, x1, y1, width, height, FALSE, FALSE); gimp_pixel_rgn_init (&rgn_out, drawable, x1, y1, width, height, preview == NULL, TRUE);
//Recupero del numero di canali channels = gimp_drawable_bpp (drawable->drawable_id); //Calcolo delle dimensioni della palette altezza = termogramma.palettey2 - termogramma.palettey1; larghezza = termogramma.palettex2 - termogramma.palettex1;
/* * Se l'altezza è più grande della larghezza allora vuol dire che la palette è disposta in verticale. * Se succede il contrario allora la palette è disposta in orizzontale */ if(altezza > larghezza) { //g_print("1\n"); altezza //g_print("2\n"); debug distanza = (termogramma.tempselezionata - termogramma.tempmin) * larghezza / (termogramma.tempmax - termogramma.tempmin); //Ottengo il pixel corrispondete (coordinate (x1 + distanza), y1 + (y2 - y1)/2) gimp_pixel_rgn_get_pixel(&rgn_in, pixel, termogramma.palettex1 + distanza, termogramma.palettey1 + (termogramma.palettey2 - termogramma.palettey1)/2); //g_print("%i, %i", termogramma.palettex1 + distanza, termogramma.palettey1 + (termogramma.palettey2 - termogramma.palettey1)/2); debug } for(i = 0; i < 3; i++) colore[i] = pixel[i]; return_vals = gimp_run_procedure("gimp_by_color_select", &nreturn_vals, GIMP_PDB_DRAWABLE, drawable, //drawable GIMP_PDB_COLOR, colore, //color GIMP_PDB_INT32, termogramma.scarto, //threshold GIMP_PDB_INT32, 2, //operation GIMP_PDB_INT32, 0, //antialiasing GIMP_PDB_INT32, 0, GIMP_PDB_INT32, 0, GIMP_PDB_FLOAT, 0.0, GIMP_PDB_INT32, 0);
}
What's wrong with this code?
__________________
calling a procedure in a plugin
gimp_run_procedure() is not properly terminated with GIMP_PDB_END (see documentation). Again, as Sven said, use c wrappers if they are available for procedure that you need.
On 10/18/07, Giuseppe Pasquino wrote:
Thanks to all for the useful help... I'll write this function but it return a fatal error (SEGMENTATION FAULT) and it don't make the selection... Here is the code:
static void evidenzia (GimpDrawable *drawable, GimpPreview *preview) {
gint width, height; //dell'immagine su cui va applicato il plugin gint altezza, larghezza; //numero di pixel formanti la palette gint x1, x2, y1, y2;
GimpPixelRgn rgn_in, rgn_out; guchar pixel[4];
guchar colore[3];
gint i, channels;
gint distanza;
GimpParam *return_vals;
gint nreturn_vals;if (preview) return; else gimp_progress_init ("Evidenzia Temperatura..."); //Recupero del drawable
gimp_drawable_mask_bounds (drawable->drawable_id, &x1, &y1, &x2, &y2); width = x2 - x1;
height = y2 - y1;
/* Inizializza due PixelRgns, uno per leggere i dati originali, * e l'altro per scrivere i dati modificati. Il secondo sarà * poi applicato all'immaginne alla fine attraverso la chiamata * gimp_drawable_merge_shadow() */ gimp_pixel_rgn_init (&rgn_in, drawable, x1, y1, width, height, FALSE, FALSE); gimp_pixel_rgn_init (&rgn_out, drawable, x1, y1, width, height, preview == NULL, TRUE); //Recupero del numero di canali channels = gimp_drawable_bpp (drawable->drawable_id);//Calcolo delle dimensioni della palette altezza = termogramma.palettey2 - termogramma.palettey1; larghezza = termogramma.palettex2 - termogramma.palettex1; /*
* Se l'altezza è più grande della larghezza allora vuol dire che la palette è disposta in verticale.
* Se succede il contrario allora la palette è disposta in orizzontale
*/
if(altezza > larghezza) {
//g_print("1\n"); altezza //g_print("2\n"); debug distanza = (termogramma.tempselezionata - termogramma.tempmin) * larghezza / (termogramma.tempmax - termogramma.tempmin);
//Ottengo il pixel corrispondete (coordinate (x1 + distanza), y1 + (y2 - y1)/2)
gimp_pixel_rgn_get_pixel(&rgn_in, pixel, termogramma.palettex1 + distanza, termogramma.palettey1 + (termogramma.palettey2 - termogramma.palettey1)/2); //g_print("%i, %i", termogramma.palettex1 + distanza, termogramma.palettey1 + (termogramma.palettey2 - termogramma.palettey1)/2); debug
}
for(i = 0; i < 3; i++) colore[i] = pixel[i]; return_vals =
gimp_run_procedure("gimp_by_color_select", &nreturn_vals, GIMP_PDB_DRAWABLE, drawable, //drawable
GIMP_PDB_COLOR, colore, //color
GIMP_PDB_INT32, termogramma.scarto, //threshold
GIMP_PDB_INT32, 2, //operation
GIMP_PDB_INT32, 0, //antialiasing
GIMP_PDB_INT32, 0, GIMP_PDB_INT32, 0, GIMP_PDB_FLOAT, 0.0,
GIMP_PDB_INT32, 0);}
What's wrong with this code?
________________________________ Sfida i tuoi amici in entusiasmanti sfide con i giochi di Messenger! Messenger Giochi
calling a procedure in a plugin
Ok, I'll modify the plugin in this way:
static void evidenzia (GimpDrawable *drawable,
GimpPreview *preview)
{
gint width, height; //dell'immagine su cui va applicato il plugin
gint altezza, larghezza; //numero di pixel formanti la palette
gint x1, x2, y1, y2;
GimpPixelRgn rgn_in, rgn_out;
guchar pixel[4];
guchar colore[3];
gint i, channels;
gint distanza;
GimpParam *return_vals;
gint nreturn_vals;
gboolean success;
if (preview) return;
else gimp_progress_init ("Evidenzia Temperatura...");
//Recupero del drawable
gimp_drawable_mask_bounds (drawable->drawable_id,
&x1, &y1,
&x2, &y2);
width = x2 - x1;
height = y2 - y1;
/* Inizializza due PixelRgns, uno per leggere i dati originali, * e l'altro per scrivere i dati modificati. Il secondo sarà * poi applicato all'immaginne alla fine attraverso la chiamata * gimp_drawable_merge_shadow() */ gimp_pixel_rgn_init (&rgn_in, drawable, x1, y1, width, height, FALSE, FALSE); gimp_pixel_rgn_init (&rgn_out, drawable, x1, y1, width, height, preview == NULL, TRUE);
//Recupero del numero di canali
channels = gimp_drawable_bpp (drawable->drawable_id);
//Calcolo delle dimensioni della palette
altezza = termogramma.palettey2 - termogramma.palettey1;
larghezza = termogramma.palettex2 - termogramma.palettex1;
/*
* Se l'altezza è più grande della larghezza allora vuol dire che la palette è disposta in verticale.
* Se succede il contrario allora la palette è disposta in orizzontale
*/
if(altezza> larghezza) {
g_print("1\n");
//Ottengo il colore alla temperatura specificata. Lo faccio facendo una media tra tutti i colori che si trovano sulla stessa riga
distanza = (termogramma.tempselezionata - termogramma.tempmin) * altezza / (termogramma.tempmax - termogramma.tempmin);
//Ottengo il pixel corrispondente (coordinate x1 + (x2 - x1)/2, (y2 - distanza))
gimp_pixel_rgn_get_pixel(&rgn_in, pixel, termogramma.palettex1 + (termogramma.palettex2 - termogramma.palettex1)/2, termogramma.palettey2 - distanza);
g_print("%i, %i\n", termogramma.palettex1 + (termogramma.palettex2 - termogramma.palettex1)/2, termogramma.palettey2 - distanza);
}
else {//larghezza> altezza
g_print("2\n");
distanza = (termogramma.tempselezionata - termogramma.tempmin) * larghezza / (termogramma.tempmax - termogramma.tempmin);
//Ottengo il pixel corrispondete (coordinate (x1 + distanza), y1 + (y2 - y1)/2)
gimp_pixel_rgn_get_pixel(&rgn_in, pixel, termogramma.palettex1 + distanza, termogramma.palettey1 + (termogramma.palettey2 - termogramma.palettey1)/2);
g_print("%i, %i\n", termogramma.palettex1 + distanza, termogramma.palettey1 + (termogramma.palettey2 - termogramma.palettey1)/2);
}
for(i = 0; i < 3; i++) {
colore[i] = pixel[i];
g_print("%i ",colore[i]);
}
return_vals = gimp_run_procedure ("gimp-by-color-select",
&nreturn_vals,
GIMP_PDB_DRAWABLE, drawable->drawable_id,
GIMP_PDB_COLOR, pixel,
GIMP_PDB_INT32, termogramma.scarto,
GIMP_PDB_INT32, 2,
GIMP_PDB_INT32, FALSE,
GIMP_PDB_INT32, FALSE,
GIMP_PDB_FLOAT, 0.0,
GIMP_PDB_INT32, FALSE,
GIMP_PDB_END);
success = return_vals[0].data.d_status == GIMP_PDB_SUCCESS; //si distruggono i parametri per liberare la memoria gimp_destroy_params (return_vals, nreturn_vals); if(success) g_print("Fatto\n");
}
the variable success is TRUE after calling the procedure but it select every black pixel instead the values contained in the "colori" vector. It' is a bug or I'm make some mistakes?
__________________
calling a procedure in a plugin
Hi,
why don't you just do what we suggested? If you would use gimp_by_color_select() instead of gimp_run_procedure(), the compiler would be able to tell you that your code is buggy.
Sven
calling a procedure in a plugin
Because I have problem converting the guchar vector for the color in "GimpRGB" and I don't know how manage with GimpChannelOps...
Can you write me down an example?
----------------------------------------> Subject: RE: RE: [Gimp-developer] calling a procedure in a plugin> From: sven@gimp.org> To: giuseppepasquino@hotmail.com> CC: gimp-developer@lists.xcf.berkeley.edu> Date: Thu, 18 Oct 2007 14:32:05 +0200>> Hi,>> why don't you just do what we suggested? If you would use> gimp_by_color_select() instead of gimp_run_procedure(), the compiler> would be able to tell you that your code is buggy.>>> Sven>>
__________________
calling a procedure in a plugin
Hi,
On Thu, 2007-10-18 at 15:05 +0200, Giuseppe Pasquino wrote:
Because I have problem converting the guchar vector for the color in "GimpRGB" and I don't know how manage with GimpChannelOps...
I think I already pointed you to the API reference for GimpRGB and gimp_rgb_set_uchar() in particular. GimpChannelOps is an enum and the possible values are listed in the API reference. Just follow the link.
You can also save yourself the hassle of working with pixel regions if all you want to do is to get the color of a single pixel. There's gimp_drawable_get_pixel() for that purpose.
Sven
calling a procedure in a plugin
I have modified the code as you suggested:
GimpRGB *colore;
GimpChannelOps parametri;
gboolean success;
gimp_rgb_set_uchar(colore, pixel[0], pixel[1], pixel[2]);
parametri = GIMP_CHANNEL_OP_REPLACE;
success = gimp_by_color_select(drawable->drawable_id,
colore,
termogramma.scarto,
parametri,
FALSE,
FALSE,
0.0,
FALSE);
The compiler returns me no error but when I execute the gimp return a fatal error: "segmentation fault". I think the problem is in one of this line but, with my few experience, I can't find it...
Hi,
I think I already pointed you to the API reference for GimpRGB andgimp_rgb_set_uchar() in particular. GimpChannelOps is an enum and the possible values are listed in the API reference. Just follow the link.
You can also save yourself the hassle of working with pixel regions if
all you want to do is to get the color of a single pixel. There's gimp_drawable_get_pixel() for that purpose.
Sven>>
__________________
calling a procedure in a plugin
On 10/19/07, Giuseppe Pasquino wrote:
I have modified the code as you suggested:
GimpRGB *colore; GimpChannelOps parametri;
gboolean success;
gimp_rgb_set_uchar(colore, pixel[0], pixel[1], pixel[2]); parametri = GIMP_CHANNEL_OP_REPLACE; success = gimp_by_color_select(drawable->drawable_id, colore, termogramma.scarto, parametri, FALSE, FALSE, 0.0, FALSE);The compiler returns me no error but when I execute the gimp return a fatal error: "segmentation fault". I think the problem is in one of this line but, with my few experience, I can't find it...
You are attempting to modify a color at some random memory location, that's never been allocated (you didn't initialize colore) -- and then you passed this dodgy pointer to gimp_by_color_select.
In most parts of the GIMP, GimpRGB are statically allocated, and you see that they are used more like this:
GimpRGB colore;
GimpChannelOps parametri;
gboolean success;
gimp_rgb_set_uchar(&colore, pixel[0], pixel[1], pixel[2]);
parametri = GIMP_CHANNEL_OP_REPLACE;
success = gimp_by_color_select(drawable->drawable_id,
&colore,
termogramma.scarto,
parametri,
FALSE,
FALSE,
0.0,
FALSE);
calling a procedure in a plugin
Thanks to all... Now it's work...
You are attempting to modify a color at some random memory location, that's never been allocated (you didn't initialize colore) and then you passed this dodgy pointer to gimp_by_color_select. In most parts of the GIMP, GimpRGB are statically allocated, and you see that they are used more like this:
GimpRGB colore;
GimpChannelOps parametri;
gboolean success;
gimp_rgb_set_uchar(&colore, pixel[0], pixel[1], pixel[2]);
parametri = GIMP_CHANNEL_OP_REPLACE;
success = gimp_by_color_select(drawable->drawable_id,
&colore,
termogramma.scarto,
parametri,
FALSE,
FALSE,
0.0,
FALSE);
__________________