[Gimp-developer] Fwd: Drawing per Script
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? What does prevent you from using the calls for gimp_vectors_bezier_stroke_new_moveto and gimp_vectors_bezier_stroke_lineto to draw lines? (Don't forget to alias then in your code to shorter names, last you have really undereadable stuff) Still, creating a vectors object from stroking is one way of painting with scripts in GIMP (the recomended one to draw curves and circles, though) - for stragiht lines you can use pdb.gimp_paintbrush instead. 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) - 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) When using the circle drawing with vectors I would expect that this technique can do it's work fast. But it's very slow (using a loop to set paths in those vectors). (In OpenGL for example there are Vertex Arrays that can be used to speed up drawing. Something like that in GIMP, and available for scripting would be nice.) Sorry to tell you that - tehre is some slowdown in using the PDB, but this is more or less as fast as it gets using GIMP to draw yiu stroken circles. You probably coukd get some speed-u dealing straight with the image data if you don't need the stroking engines from GIMP - i.e. - no need to use different brushes, gradients, dynamics and so on) If so you can get some significant speed-up using C, or maybe even python if you get an efficient way to draw your circles using pixel data. (A suggestion would be to cache different pixel data for the circles with the radii you want, as gimp-buffers, and paste then on the desred places on teh image - that shoul be much faster than creating/stroking paths) (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 :-) How can I speed up my drawings without switching to C? With my Python script I need about 3 or 4 seconds just for drawing 2072 circles. 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 This can give you a 3x to 4x times improvement when you have many small operations going on (like drawing thousands of circles) . Unfortunatelly this spoins the undo system for you rimage -even after a call to undo_enable. If you are editing the image interactvely I suggest you make your script to: - copy the drawable you are interested to a new image - disable the undo system on the new image - perform your painting operations - copy the drawable back to the original image (and destroy the newly created image, of course) This seems very slow to me. If I also would need to write pixels of a line pixel-wise, If you weant 1 pixel thick straight lines, use the pencil tool and the pixel brush. I would also await to have very slow scripts. Special functions for drawing lines from within Python-plugins, that use C-speed would be fine. Regards, js -- Gruß, Oliver ___ Gimp-developer mailing list Gimp-developer@lists.XCF.Berkeley.EDU https://lists.XCF.Berkeley.EDU/mailman/listinfo/gimp-developer ___ 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
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
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
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