RSS/Atom feed Twitter
Site is read-only, email is disabled

Plugin that can open a drawable on screen. What am I doing wrong?

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.

15 of 15 messages available
Toggle history

Please log in to manage your subscriptions.

Plugin that can open a drawable on screen. What am I doing wrong? Louise Hoffman 26 Dec 13:51
  Plugin that can open a drawable on screen. What am I doing wrong? Sven Neumann 26 Dec 15:00
   Plugin that can open a drawable on screen. What am I doing wrong? Louise Hoffman 26 Dec 18:54
  Plugin that can open a drawable on screen. What am I doing wrong? Martin Nordholts 26 Dec 15:01
   Plugin that can open a drawable on screen. What am I doing wrong? Louise Hoffman 26 Dec 19:03
    Plugin that can open a drawable on screen. What am I doing wrong? Martin Nordholts 26 Dec 19:08
     Plugin that can open a drawable on screen. What am I doing wrong? Louise Hoffman 26 Dec 19:41
      Plugin that can open a drawable on screen. What am I doing wrong? Martin Nordholts 26 Dec 21:58
       Plugin that can open a drawable on screen. What am I doing wrong? Louise Hoffman 27 Dec 11:11
    Plugin that can open a drawable on screen. What am I doing wrong? Sven Neumann 27 Dec 09:42
     Plugin that can open a drawable on screen. What am I doing wrong? Louise Hoffman 27 Dec 11:18
      Plugin that can open a drawable on screen. What am I doing wrong? Sven Neumann 27 Dec 13:51
       Plugin that can open a drawable on screen. What am I doing wrong? Martin Nordholts 27 Dec 14:14
  Plugin that can open a drawable on screen. What am I doing wrong? saulgoode@flashingtwelve.brickfilms.com 26 Dec 15:07
   Plugin that can open a drawable on screen. What am I doing wrong? Louise Hoffman 26 Dec 19:05
Louise Hoffman
2009-12-26 13:51:41 UTC (almost 15 years ago)

Plugin that can open a drawable on screen. What am I doing wrong?

Dear developers,

I am trying to make a GIMP plugin that can open a new drawable on the screen. Just like when you make one from File->New.

It should be 800x600 24bit greyscale.

The code I have written is attached with Makefile.

When I select the plugin in GIMP I get these errors:

Calling error for procedure 'gimp-drawable-width': Procedure 'gimp-drawable-width' has been called with an invalid ID for argument 'drawable'. Most likely a plug-in is trying to work on a layer that doesn't exist any longer.

Calling error for procedure 'gimp-drawable-height': Procedure 'gimp-drawable-height' has been called with an invalid ID for argument 'drawable'. Most likely a plug-in is trying to work on a layer that doesn't exist any longer.

Calling error for procedure 'gimp-drawable-bpp': Procedure 'gimp-drawable-bpp' has been called with an invalid ID for argument 'drawable'. Most likely a plug-in is trying to work on a layer that doesn't exist any longer.

Can someone see what's wrong?

Lots of love, Louise

Sven Neumann
2009-12-26 15:00:13 UTC (almost 15 years ago)

Plugin that can open a drawable on screen. What am I doing wrong?

On Sat, 2009-12-26 at 13:51 +0100, Louise Hoffman wrote:

Dear developers,

I am trying to make a GIMP plugin that can open a new drawable on the screen. Just like when you make one from File->New.

It should be 800x600 24bit greyscale.

File->New creates a new image, not a new drawable.

Your code writes to the GimpDrawable struct, but this struct is read-only and must not be written to by the plug-in. I suggest that you take a look at other plug-ins that create new images.

Sven

Martin Nordholts
2009-12-26 15:01:25 UTC (almost 15 years ago)

Plugin that can open a drawable on screen. What am I doing wrong?

Louise Hoffman wrote:

Dear developers,

I am trying to make a GIMP plugin that can open a new drawable on the screen. Just like when you make one from File->New.

Hi!

You can't show a drawable by itself, it needs to be in an image. Also, an image can't show itself, you must create a display for that. You are also using the API in weird ways, for example, objects such as layers and images are represented by integers in the plug-in context.

You are also saying that the plug-in takes the active image and drawable as parameter, but since you are creating a new image, you are not interested in those values (I assume) so there is no point in specifying these as arguments to the hello-world procedure.

I have attached a rewritten version of main.c (called hello-world.c since that is a name that doesn't conflict as much) that should do what you want. You might also want to consider using a scripting language like Scheme or Python for this.

/ Martin

saulgoode@flashingtwelve.brickfilms.com
2009-12-26 15:07:06 UTC (almost 15 years ago)

Plugin that can open a drawable on screen. What am I doing wrong?

Quoting Louise Hoffman :

When I select the plugin in GIMP I get these errors:

Calling error for procedure 'gimp-drawable-width': Procedure 'gimp-drawable-width' has been called with an invalid ID for argument 'drawable'. Most likely a plug-in is trying to work on a layer that doesn't exist any longer.
...

Your invocation of 'gimp_install_procedure' specifies NULL for the image_type. This is probably what you want -- you don't need an image opened in order to create a new image -- but this means that you shouldn't be using GIMP_PDB_IMAGE and GIMP_PDB_DRAWABLE in your GimpParamDef (if there is no image open when you execute the plug-in, those parameters can't be provided).

As a side note, I don't understand why you define your own 'MyDrawable' struct when it is identical to the GimpDrawable struct already available.

Louise Hoffman
2009-12-26 18:54:35 UTC (almost 15 years ago)

Plugin that can open a drawable on screen. What am I doing wrong?

File->New creates a new image, not a new drawable.

Okay, I had that mixed up. A new image is really what I wanted then =)

Louise Hoffman
2009-12-26 19:03:50 UTC (almost 15 years ago)

Plugin that can open a drawable on screen. What am I doing wrong?

You can't show a drawable by itself, it needs to be in an image. Also, an image can't show itself, you must create a display for that. You are also using the API in weird ways, for example, objects such as layers and images are represented by integers in the plug-in context.

You are also saying that the plug-in takes the active image and drawable as parameter, but since you are creating a new image, you are not interested in those values (I assume) so there is no point in specifying these as arguments to the hello-world procedure.

This is my first attempt to write a GIMP plugin, as you probably have guessed by now =)

I have attached a rewritten version of main.c (called hello-world.c since that is a name that doesn't conflict as much) that should do what you want. You might also want to consider using a scripting language like Scheme or Python for this.

Wow. That's amazing. Thank you very much =)

What I ultimately would like to end up with is being able to set pixels, the user makes changes to the image, and I read the pixels one by one again.

So now I have tried to set a pixel like so

/* Trying to set a pixel at x=5,y=5 with value 150 */ GimpDrawable* drawable;
drawable = gimp_drawable_get (layer);

/* Trying to set a pixel at x=5,y=5 with value 150 in 24 bit color */ gboolean s;
s = gimp_drawable_set_pixel (drawable, 5, 5, 24, 150);

But when I compile I get:

hello-world.c:73: warning: passing argument 1 of ‘gimp_drawable_set_pixel’ makes integer from pointer without a cast /usr/include/gimp-2.0/libgimp/gimpdrawable_pdb.h:89: note: expected ‘gint32’ but argument is of type ‘struct GimpDrawable *’

The code is attached. I am bit lost how to solve this.

Any help will be very appreciated =)

Louise Hoffman
2009-12-26 19:05:15 UTC (almost 15 years ago)

Plugin that can open a drawable on screen. What am I doing wrong?

Your invocation of 'gimp_install_procedure' specifies NULL for the image_type. This is probably what you want -- you don't need an image opened in order to create a new image -- but this means that you shouldn't be using GIMP_PDB_IMAGE and GIMP_PDB_DRAWABLE in your GimpParamDef (if there is no image open when you execute the plug-in, those parameters can't be provided).

As a side note, I don't understand why you define your own 'MyDrawable' struct when it is identical to the GimpDrawable struct already available.

I thought that was how a new image was created =)

Martin Nordholts
2009-12-26 19:08:15 UTC (almost 15 years ago)

Plugin that can open a drawable on screen. What am I doing wrong?

Louise Hoffman wrote:

hello-world.c:73: warning: passing argument 1 of ‘gimp_drawable_set_pixel’ makes integer from pointer without a cast /usr/include/gimp-2.0/libgimp/gimpdrawable_pdb.h:89: note: expected ‘gint32’ but argument is of type ‘struct GimpDrawable *’

As I said, in the plug-in context layers (and drawables) are identified by integers, not pointers. Looks like you try to use a struct pointer again.

Plug-ins run in their own process and thus pointer-passing doesn't work.

/ Martin

Louise Hoffman
2009-12-26 19:41:18 UTC (almost 15 years ago)

Plugin that can open a drawable on screen. What am I doing wrong?

As I said, in the plug-in context layers (and drawables) are identified by integers, not pointers. Looks like you try to use a struct pointer again.

Plug-ins run in their own process and thus pointer-passing doesn't work.

Sorry about that.

Now I don't get any errors, but I don't see the pixel either...

/* Trying to set a pixel at x=5,y=5 with value 150 in 24 bit color */ const guint8 *pixel;
pixel = (guint8 *) "150";
gboolean s;
s = gimp_drawable_set_pixel (layer, 5, 5, 24, pixel); printf ("Was the pixel set?: %i", s);

and s returns 0.

Is it how I define the pixel value that is the problem?

The hello-world.c is here with my change http://pastebin.com/m39f62a20

Martin Nordholts
2009-12-26 21:58:47 UTC (almost 15 years ago)

Plugin that can open a drawable on screen. What am I doing wrong?

Louise Hoffman wrote:

Now I don't get any errors, but I don't see the pixel either...

/* Trying to set a pixel at x=5,y=5 with value 150 in 24 bit color */ const guint8 *pixel;
pixel = (guint8 *) "150";
gboolean s;
s = gimp_drawable_set_pixel (layer, 5, 5, 24, pixel); printf ("Was the pixel set?: %i", s);

Hi again!

No you got an error. 0, or FALSE, means "error" which you can read in the documentation for the function:

http://developer.gimp.org/api/2.0/libgimp/libgimp-gimpdrawable.html#gimp-drawable-set-pixel

There you can also read that the num_channels parameter shall be the "The number of channels for the pixel.". You try to pass the number of bits, 24. Even that is wrong since you create the layer with an alpha channel, so the correct wrong thing to pass would be 32.

/ Martin

Sven Neumann
2009-12-27 09:42:56 UTC (almost 15 years ago)

Plugin that can open a drawable on screen. What am I doing wrong?

On Sat, 2009-12-26 at 19:03 +0100, Louise Hoffman wrote:

You can't show a drawable by itself, it needs to be in an image. Also, an image can't show itself, you must create a display for that. You are also using the API in weird ways, for example, objects such as layers and images are represented by integers in the plug-in context.

You are also saying that the plug-in takes the active image and drawable as parameter, but since you are creating a new image, you are not interested in those values (I assume) so there is no point in specifying these as arguments to the hello-world procedure.

This is my first attempt to write a GIMP plugin, as you probably have guessed by now =)

I strongly suggest that you read the tutorial on developer.gimp.org then:

http://developer.gimp.org/writing-a-plug-in/1/index.html

and perhaps study the code of a plug-in that does something similar to what you want to achieve. Writing a plug-in without any idea of how the GIMP API works is not going to be a fun experience.

Sven

Louise Hoffman
2009-12-27 11:11:31 UTC (almost 15 years ago)

Plugin that can open a drawable on screen. What am I doing wrong?

No you got an error. 0, or FALSE, means "error" which you can read in the documentation for the function:

http://developer.gimp.org/api/2.0/libgimp/libgimp-gimpdrawable.html#gimp-drawable-set-pixel

Now I see =) And now I get my red pixel as I wanted =)

gboolean s; guint8 pixel[] = { 0xff, 0, 0, 0xff }; s = gimp_drawable_set_pixel (layer, 5, 5, 4, (guint8 *)pixel ); printf ("Was the pixel set?: %i", s);

Full source at http://pastebin.com/m35f95e3e

There you can also read that the num_channels parameter shall be the "The number of channels for the pixel.". You try to pass the number of bits, 24. Even that is wrong since you create the layer with an alpha channel, so the correct wrong thing to pass would be 32.

The thing is, what I would really like is to be able to plot 16bit (doubles), but I can't figure out, how to put that in, when in my case, pixel[], is guint8.

So if I set bpp to 32, and I have a 16bit value. How should I put that in?

Louise Hoffman
2009-12-27 11:18:38 UTC (almost 15 years ago)

Plugin that can open a drawable on screen. What am I doing wrong?

I strongly suggest that you read the tutorial on developer.gimp.org then:

 http://developer.gimp.org/writing-a-plug-in/1/index.html

I read that one, and it was from that, I copied a lot of the code. I was why I had all this pointer and structs at first =)

and perhaps study the code of a plug-in that does something similar to what you want to achieve. Writing a plug-in without any idea of how the GIMP API works is not going to be a fun experience.

hehe =) Yes, it is pretty tough, but you guys have helped me out a lot, so now I am very close to my goal =)

I guess the biggest problem right now is, how I plot a 16bit value.

Searching I find some that say GEGL will first be usable in GIMP 2.10.

Have you had any experience with plotting 16 bit (doubles)? Can it be done?

Sven Neumann
2009-12-27 13:51:02 UTC (almost 15 years ago)

Plugin that can open a drawable on screen. What am I doing wrong?

On Sun, 2009-12-27 at 11:18 +0100, Louise Hoffman wrote:

I strongly suggest that you read the tutorial on developer.gimp.org then:

http://developer.gimp.org/writing-a-plug-in/1/index.html

I read that one, and it was from that, I copied a lot of the code. I was why I had all this pointer and structs at first =)

The code you showed us was definitely not copied from there. And it is correct to use the GimpDrawable struct from plug-ins. Martins advice that plug-ins would only refer to drawables by their integer ID is incorrect.

Sven

Martin Nordholts
2009-12-27 14:14:53 UTC (almost 15 years ago)

Plugin that can open a drawable on screen. What am I doing wrong?

Sven Neumann wrote:

On Sun, 2009-12-27 at 11:18 +0100, Louise Hoffman wrote:

I strongly suggest that you read the tutorial on developer.gimp.org then:

http://developer.gimp.org/writing-a-plug-in/1/index.html

I read that one, and it was from that, I copied a lot of the code. I was why I had all this pointer and structs at first =)

The code you showed us was definitely not copied from there. And it is correct to use the GimpDrawable struct from plug-ins. Martins advice that plug-ins would only refer to drawables by their integer ID is incorrect.

I would like to point out that the GimpDrawable struct in libgimp has a member

gint32 drawable_id; /* drawable ID */

so plug-ins still refers to drawables in the core through an ID, even though it might be indirectly through a pointer to the libgimp GimpDrawable structure.

I agree however that my advice was misleading and stand corrected.

/ Martin