Re: [Gimp-developer] Fwd: Drawing per Script

2010-09-13 Thread Simon Budig
Joao S. O. Bueno (gwid...@mpc.com.br) wrote:
 On Sun, Sep 12, 2010 at 8:58 AM,  oli...@first.in-berlin.de wrote:
  (I also saw, that what on the GUI are Paths internally are called
  vectors. To make things better undesrstandable, it would make sense
  to give things the same name... but maybe there is more to vectors
  and I don't see it so far. Why are there different names?)
 
  will leave that up to Simon :-)

There already is an internal API that uses the gimp-path-prefix and I
wanted to avoid confusion. The new shiny vectors API should have its
own namespace, to clearly separate it from the old pesky
gimp-path-*-API  :-)

Also, the vectors infrastructure was designed to allow future extensions
that go beyond simple paths. The goal was to have a vectors object as
a container for strokes (i.e. connected bezier segments) or
circles/ellipses or contrast-following-segments. So it theoretically could
contain other stuff as well, going beyond plain paths.

That aspect has never been fleshed out, mostly due to
UI-confusion-considerations.

Bye,
Simon
-- 
  si...@budig.de  http://simon.budig.de/
___
Gimp-developer mailing list
Gimp-developer@lists.XCF.Berkeley.EDU
https://lists.XCF.Berkeley.EDU/mailman/listinfo/gimp-developer


Re: [Gimp-developer] Fwd: Drawing per Script

2010-09-13 Thread oliver
Hi,

On Mon, Sep 13, 2010 at 05:21:09PM -0300, Joao S. O. Bueno wrote:
 On Sun, Sep 12, 2010 at 8:58 AM,  oli...@first.in-berlin.de wrote:
  Hello,
 
 
 Hi
 
 
  I tried drawing per Script.
  I'm using Python.
 
  I can already use vectors for drawing circles,
  and set single points.
 
  I did not found a way to create rectangles,
  or lines.
 
 
 You are probablu using pdb_gimp_vectors_bezier_stroke_new_ellipse
 to draw circles, right?

I use:
  pdb.gimp_vectors_bezier_stroke_new_ellipse


So I think it's what you are talking about, just
the absolute name is different.



 What does prevent you from using the calls for
 gimp_vectors_bezier_stroke_new_moveto and
 gimp_vectors_bezier_stroke_lineto to draw lines?

I looked for draw and did not find functions that do it.
So, in short words: I did not found thos functions.


 (Don't  forget to alias then in your code to shorter names, last you
 have really undereadable stuff)

If it does not eat up too much ressources in Python...

...you mean using def for creating a function that just calls the other one?
or are aliases what Python offers as a separate feature?



[...]
  Aren't there pdb-functions that draw a line?
 
  Do I have to create it pixelwise?
  In a loop?
 
 
 As I stated above, there are calls to draw lines.
 Are you even using the procedure browser? (Help menu -  Procedure browser) -

I use the procedure browser.
But it does not help me, if I look for names that aren't there
...if I look for draw I got nothing.
The circle-drawing function via bezier I found by accident/chance.


 
 In Python you can access the image data directly, using calls to get
 the pixel regions if you want to as well (that is about 100x  faster
 than gimp_drawable_set_pixel  due to the function calls involved for
 each pixel change)

How can I access the pixel data directly?

That would be very interesting to me, especially for some other scripts,
where I think about even more intensive work.


[...]
 So, besides my hints above: when I need speed on a PDB using script
 (which includes python scripts),
 I found out that GIMP's undo system is the cause for a significant slow down.
 Creating an Undo group does not help - you have to disbale the undo with
 pdb.gimp_image_undo_disable

OK, I will try that.


Thanks for all that hints. :)

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


Re: [Gimp-developer] Fwd: Drawing per Script

2010-09-13 Thread Joao S. O. Bueno
On Mon, Sep 13, 2010 at 8:56 PM,  oli...@first.in-berlin.de wrote:
 Hi,

 On Mon, Sep 13, 2010 at 05:21:09PM -0300, Joao S. O. Bueno wrote:
 On Sun, Sep 12, 2010 at 8:58 AM,  oli...@first.in-berlin.de wrote:
  Hello,


 Hi

 
  I tried drawing per Script.
  I'm using Python.
 
  I can already use vectors for drawing circles,
  and set single points.
 
  I did not found a way to create rectangles,
  or lines.


 You are probablu using pdb_gimp_vectors_bezier_stroke_new_ellipse
 to draw circles, right?

 I use:
  pdb.gimp_vectors_bezier_stroke_new_ellipse


Your way is the correct - mine was just a typo - a thing I excel in.

 So I think it's what you are talking about, just
 the absolute name is different.



 What does prevent you from using the calls for
 gimp_vectors_bezier_stroke_new_moveto and
 gimp_vectors_bezier_stroke_lineto to draw lines?

 I looked for draw and did not find functions that do it.
 So, in short words: I did not found thos functions.

yes-- the procedure broswer has this downside --
you have to keep looking with related words if you don't find
something at first.

 (Don't  forget to alias then in your code to shorter names, last you
 have really undereadable stuff)

 If it does not eat up too much ressources in Python...

It does not.
What is delaying the execution is much more the nature of the PDB and
the Undo system than python.

With aliasing I mea just attributing the pdb functions to a local
variable - with lines like these at the start of your function (or
even at the start of your module):

lineto = pdb.gimp_vectors_bezier_stroke_new_lineto
ellipse = pdb.gimp_vectors_bezier_stroke_new_ellipse

From then on you can jsut type ellipse( ...)  instead of the long
name designed to avoid namespace clash.
This does not create new functions - you call the very same function,
 just using another name.

 ...you mean using def for creating a function that just calls the other one?
 or are aliases what Python offers as a separate feature?



 [...]
  Aren't there pdb-functions that draw a line?
 
  Do I have to create it pixelwise?
  In a loop?
 

 As I stated above, there are calls to draw lines.
 Are you even using the procedure browser? (Help menu -  Procedure browser) -

 I use the procedure browser.
 But it does not help me, if I look for names that aren't there
 ...if I look for draw I got nothing.
 The circle-drawing function via bezier I found by accident/chance.

If you type vectors you will see all teh vector related functions.
Howeer to paint straight without using a path, you have to look for
the tool name:
pencil, paintbrush, etc...


 In Python you can access the image data directly, using calls to get
 the pixel regions if you want to as well (that is about 100x  faster
 than gimp_drawable_set_pixel  due to the function calls involved for
 each pixel change)

 How can I access the pixel data directly?

 That would be very interesting to me, especially for some other scripts,
 where I think about even more intensive work.

px = drawable.get_pixel_rgn(top, left, width, height)
px [:, :]  = \xff\x00\x00 * drawable.width * drawable.height()
drawable.update(top, left, width, height)

The get_pixel_region and update are methods of GIMP drawable objects.

The item assignment to set/reset pixels is a bit aukward - the example above
paints the whole drawable in red (if it is  a 3BPP RGB channel, else
you willget an
error telling the setting string is of the wrong size)

For serious work with pixel regions you might prefer to copy the pixel
data to a Numpy array - ther eyou can work with numbers from 0 to 2545
instead of having to convert all data to string prior to setting the
pixels.


 [...]
 So, besides my hints above: when I need speed on a PDB using script
 (which includes python scripts),
 I found out that GIMP's undo system is the cause for a significant slow down.
 Creating an Undo group does not help - you have to disbale the undo with
 pdb.gimp_image_undo_disable

 OK, I will try that.


 Thanks for all that hints. :)

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


regards,

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