Re: [Gimp-developer] Plugin that can open a drawable on screen. What am I doing wrong?

2009-12-27 Thread Sven Neumann
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


___
Gimp-developer mailing list
Gimp-developer@lists.XCF.Berkeley.EDU
https://lists.XCF.Berkeley.EDU/mailman/listinfo/gimp-developer


Re: [Gimp-developer] Plugin that can open a drawable on screen. What am I doing wrong?

2009-12-27 Thread Louise Hoffman
 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?
___
Gimp-developer mailing list
Gimp-developer@lists.XCF.Berkeley.EDU
https://lists.XCF.Berkeley.EDU/mailman/listinfo/gimp-developer


Re: [Gimp-developer] Plugin that can open a drawable on screen. What am I doing wrong?

2009-12-27 Thread Louise Hoffman
 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?
___
Gimp-developer mailing list
Gimp-developer@lists.XCF.Berkeley.EDU
https://lists.XCF.Berkeley.EDU/mailman/listinfo/gimp-developer


Re: [Gimp-developer] Plugin that can open a drawable on screen. What am I doing wrong?

2009-12-27 Thread Sven Neumann
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


___
Gimp-developer mailing list
Gimp-developer@lists.XCF.Berkeley.EDU
https://lists.XCF.Berkeley.EDU/mailman/listinfo/gimp-developer


Re: [Gimp-developer] Plugin that can open a drawable on screen. What am I doing wrong?

2009-12-27 Thread Martin Nordholts
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

   gint32drawable_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

-- 

My GIMP Blog:
http://www.chromecode.com/
Best way to keep up with GIMP from git
___
Gimp-developer mailing list
Gimp-developer@lists.XCF.Berkeley.EDU
https://lists.XCF.Berkeley.EDU/mailman/listinfo/gimp-developer


Re: [Gimp-developer] Plugin that can open a drawable on screen. What am I doing wrong?

2009-12-26 Thread Martin Nordholts

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


--

My GIMP Blog:
http://www.chromecode.com/
Reducing UI clutter, docking bars removed
#include libgimp/gimp.h

static void
query (void)
{
  static GimpParamDef args[] =
  {
{
  GIMP_PDB_INT32,
  run-mode,
  Run mode
},
  };

  gimp_install_procedure (
plug-in-hello,
Hello, world!,
Displays \Hello, world!\ in a dialog,
David Neary,
Copyright David Neary,
2004,
_Hello world...,
NULL,
GIMP_PLUGIN,
G_N_ELEMENTS (args), 0,
args, NULL);

  gimp_plugin_menu_register (plug-in-hello,
 Image/Filters/Misc);
}

static void
run (const gchar  *name,
 gint  nparams,
 const GimpParam  *param,
 gint *nreturn_vals,
 GimpParam   **return_vals)
{
  static GimpParam  values[1];
  GimpPDBStatusType status = GIMP_PDB_SUCCESS;
  GimpRunMode   run_mode;
  gint32image;
  gint32layer;
  gint32display;

  /* Setting mandatory output values */
  *nreturn_vals = 1;
  *return_vals  = values;

  values[0].type = GIMP_PDB_STATUS;
  values[0].data.d_status = status;

  /* Getting run_mode - we won't display a dialog if 
   * we are in NONINTERACTIVE mode */
  run_mode = param[0].data.d_int32;

  image = gimp_image_new (800, 600, GIMP_RGB);
  layer = gimp_layer_new (image,
  foo,
  800, 600,
  GIMP_RGBA_IMAGE,
  100.0,
  GIMP_NORMAL_MODE);
  gimp_image_add_layer (image, layer, 0);
  display = gimp_display_new (image);

  if (run_mode != GIMP_RUN_NONINTERACTIVE)
g_message(Hello, world!\n);
}

GimpPlugInInfo PLUG_IN_INFO =
{
  NULL,
  NULL,
  query,
  run
};

MAIN()
___
Gimp-developer mailing list
Gimp-developer@lists.XCF.Berkeley.EDU
https://lists.XCF.Berkeley.EDU/mailman/listinfo/gimp-developer


Re: [Gimp-developer] Plugin that can open a drawable on screen. What am I doing wrong?

2009-12-26 Thread saulgoode
Quoting Louise Hoffman louise.hoff...@gmail.com:

 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.



___
Gimp-developer mailing list
Gimp-developer@lists.XCF.Berkeley.EDU
https://lists.XCF.Berkeley.EDU/mailman/listinfo/gimp-developer


Re: [Gimp-developer] Plugin that can open a drawable on screen. What am I doing wrong?

2009-12-26 Thread Louise Hoffman
 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 =)
___
Gimp-developer mailing list
Gimp-developer@lists.XCF.Berkeley.EDU
https://lists.XCF.Berkeley.EDU/mailman/listinfo/gimp-developer


Re: [Gimp-developer] Plugin that can open a drawable on screen. What am I doing wrong?

2009-12-26 Thread Louise Hoffman
 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 =)
#include libgimp/gimp.h

static void
query (void)
{
  static GimpParamDef args[] =
  {
{
  GIMP_PDB_INT32,
  run-mode,
  Run mode
},
  };

  gimp_install_procedure (
plug-in-hello,
Hello, world!,
Displays \Hello, world!\ in a dialog,
David Neary,
Copyright David Neary,
2004,
_Hello world...,
NULL,
GIMP_PLUGIN,
G_N_ELEMENTS (args), 0,
args, NULL);

  gimp_plugin_menu_register (plug-in-hello,
 Image/Filters/Misc);
}

static void
run (const gchar  *name,
 gint  nparams,
 const GimpParam  *param,
 gint *nreturn_vals,
 GimpParam   **return_vals)
{
  static GimpParam  values[1];
  GimpPDBStatusType status = GIMP_PDB_SUCCESS;
  GimpRunMode   run_mode;
  gint32image;
  gint32layer;
  gint32display;

  /* Setting mandatory output values */
  *nreturn_vals = 1;
  *return_vals  = values;

  values[0].type = GIMP_PDB_STATUS;
  values[0].data.d_status = status;

  /* Getting run_mode - we won't display a dialog if 
   * we are in NONINTERACTIVE mode */
  run_mode = param[0].data.d_int32;

  image = gimp_image_new (800, 600, GIMP_RGB);
  layer = gimp_layer_new (image,
  foo,
  800, 600,
  GIMP_RGBA_IMAGE,
  100.0,
  GIMP_NORMAL_MODE);
  gimp_image_add_layer (image, layer, 0);


  /* 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);


  display = gimp_display_new (image);

  if (run_mode != GIMP_RUN_NONINTERACTIVE)
g_message(Hello, world!\n);
}

GimpPlugInInfo PLUG_IN_INFO =
{
  NULL,
  NULL,
  query,
  run
};

MAIN()
___
Gimp-developer mailing list
Gimp-developer@lists.XCF.Berkeley.EDU
https://lists.XCF.Berkeley.EDU/mailman/listinfo/gimp-developer


Re: [Gimp-developer] Plugin that can open a drawable on screen. What am I doing wrong?

2009-12-26 Thread Louise Hoffman
 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 =)
___
Gimp-developer mailing list
Gimp-developer@lists.XCF.Berkeley.EDU
https://lists.XCF.Berkeley.EDU/mailman/listinfo/gimp-developer


Re: [Gimp-developer] Plugin that can open a drawable on screen. What am I doing wrong?

2009-12-26 Thread Martin Nordholts
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


-- 

My GIMP Blog:
http://www.chromecode.com/
Best way to keep up with GIMP from git

___
Gimp-developer mailing list
Gimp-developer@lists.XCF.Berkeley.EDU
https://lists.XCF.Berkeley.EDU/mailman/listinfo/gimp-developer


Re: [Gimp-developer] Plugin that can open a drawable on screen. What am I doing wrong?

2009-12-26 Thread Louise Hoffman
 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
___
Gimp-developer mailing list
Gimp-developer@lists.XCF.Berkeley.EDU
https://lists.XCF.Berkeley.EDU/mailman/listinfo/gimp-developer


Re: [Gimp-developer] Plugin that can open a drawable on screen. What am I doing wrong?

2009-12-26 Thread Martin Nordholts
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

-- 

My GIMP Blog:
http://www.chromecode.com/
Reducing UI clutter, docking bars removed
___
Gimp-developer mailing list
Gimp-developer@lists.XCF.Berkeley.EDU
https://lists.XCF.Berkeley.EDU/mailman/listinfo/gimp-developer