[Gimp-developer] Python plugin registration: choosing between a closed set of strings
I'd like the user to select a variant of a plugin (among 3 to 5 ones). I would normally do so with a R/O drop-down box displaying the names. Is there a way to do so using the right type of parameter type in the registration (couldn't find it)? Otherwise what would be the recommended way to do it? Define separate plugins for each variant? Btw, can I define several plugins (ie, register() calls) in one single Python file? Or what is the best way (ie, easier to install for the end-user) to share code between Python plugins? -- Ofnuts ___ Gimp-developer mailing list Gimp-developer@lists.XCF.Berkeley.EDU https://lists.XCF.Berkeley.EDU/mailman/listinfo/gimp-developer
Re: [Gimp-developer] Python plugin registration: choosing between a closed set of strings
If your 'variants' are similar you could just use PF_OPTION and change your variables/options with an if/else... Or you can define different functions and register them separately in the same file. The 'palette-to-gradient.py' file in the source does this... http://git.gnome.org/browse/gimp/tree/plug-ins/pygimp/plug-ins/palette-to-gradient.py On 09/07/2010 10:53 AM, Ofnuts wrote: I'd like the user to select a variant of a plugin (among 3 to 5 ones). I would normally do so with a R/O drop-down box displaying the names. Is there a way to do so using the right type of parameter type in the registration (couldn't find it)? Otherwise what would be the recommended way to do it? Define separate plugins for each variant? Btw, can I define several plugins (ie, register() calls) in one single Python file? Or what is the best way (ie, easier to install for the end-user) to share code between Python plugins? -- Ofnuts ___ 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] Python plugin registration: choosing between a closed set of strings
On Tue, 2010-09-07 at 16:53 +0200, Ofnuts wrote: I'd like the user to select a variant of a plugin (among 3 to 5 ones). I would normally do so with a R/O drop-down box displaying the names. Is there a way to do so using the right type of parameter type in the registration (couldn't find it)? You should consider to avoid gimpfu for this and write a real GIMP plug-in in Python using a user interface built in PyGTK. The auto-generated UI of gimpfu is really just suited for very simple scripts. And there is a lot of awkwardness in gimpfu. It tries to make things easy for you, but then it gets into your way and you end up spending time to find workarounds for that. Sven ___ Gimp-developer mailing list Gimp-developer@lists.XCF.Berkeley.EDU https://lists.XCF.Berkeley.EDU/mailman/listinfo/gimp-developer
Re: [Gimp-developer] Python plugin registration: choosing between a closed set of strings
On 07/09/2010 20:52, Sven Neumann wrote: On Tue, 2010-09-07 at 16:53 +0200, Ofnuts wrote: I'd like the user to select a variant of a plugin (among 3 to 5 ones). I would normally do so with a R/O drop-down box displaying the names. Is there a way to do so using the right type of parameter type in the registration (couldn't find it)? You should consider to avoid gimpfu for this and write a real GIMP plug-in in Python using a user interface built in PyGTK. The auto-generated UI of gimpfu is really just suited for very simple scripts. And there is a lot of awkwardness in gimpfu. It tries to make things easy for you, but then it gets into your way and you end up spending time to find workarounds for that. Still a rather simple script so far, parameter-wise, so python-fu is sufficient, especially given Jerry's answers... but I'll keep your suggestion in mind for when I get more proficient with all this. ___ Gimp-developer mailing list Gimp-developer@lists.XCF.Berkeley.EDU https://lists.XCF.Berkeley.EDU/mailman/listinfo/gimp-developer
Re: [Gimp-developer] Python plugin registration: choosing between a closed set of strings
On 07/09/2010 20:55, Jerry Baker wrote: PF_OPTION is what I had in mind, without finding it described. I googled it after you netioned itn and found a nice python-fu sample with all parameters types... I wish I had found it earlier... Thanks for confirming my guess that multiple registration could work. It is therefore a serious option, especially since some variants require less parameters. If your 'variants' are similar you could just use PF_OPTION and change your variables/options with an if/else... Or you can define different functions and register them separately in the same file. The 'palette-to-gradient.py' file in the source does this... http://git.gnome.org/browse/gimp/tree/plug-ins/pygimp/plug-ins/palette-to-gradient.py On 09/07/2010 10:53 AM, Ofnuts wrote: I'd like the user to select a variant of a plugin (among 3 to 5 ones). I would normally do so with a R/O drop-down box displaying the names. Is there a way to do so using the right type of parameter type in the registration (couldn't find it)? Otherwise what would be the recommended way to do it? Define separate plugins for each variant? Btw, can I define several plugins (ie, register() calls) in one single Python file? Or what is the best way (ie, easier to install for the end-user) to share code between Python plugins? -- Ofnuts ___ 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
[Gimp-developer] python plugin dos not receives changes to FLOATARRAY parameters done by libgimp functions.
hi! i wrote a c gimp plugin which is called from an python gimp plugin. the c plugin receives a FLOATARRAY parameter which it modifies. the c plugin sees the values the python plugin has put into the FLOATARRAY, but if it modifies these, this changes are not send back to the python plugin. how to made it work? do i have to change my python or my c plugin? do i have to modify gimps python-plugin-interface? i guess some special converter has to be written to automaticaly construct a python array from FLOATARRAYS. an equivalent question: how to use gimp_path_get_points from a python plugin? here some samplecode: def somefunc(image): floatarray = [] for i in range(100): floatarray.append(0.0) closed = 0 count = 0 gimp.pdb.gimp_path_get_points(image, path1, 1, closed, count, floatarray) return floatarray floatarray should be modified by 'gimp_path_get_points' but it's not. how to get this values transfered to the python plugin? regards kl ___ Gimp-developer mailing list Gimp-developer@lists.XCF.Berkeley.EDU https://lists.XCF.Berkeley.EDU/mailman/listinfo/gimp-developer
Re: [Gimp-developer] python plugin dos not receives changes to FLOATARRAY parameters done by libgimp functions.
On Wed, Mar 15, 2006 at 01:43:12AM +0100, Kleistereimer wrote: how to use gimp_path_get_points from a python plugin? here some samplecode: def somefunc(image): floatarray = [] for i in range(100): floatarray.append(0.0) closed = 0 count = 0 gimp.pdb.gimp_path_get_points(image, path1, 1, closed, count, floatarray) return floatarray floatarray should be modified by 'gimp_path_get_points' but it's not. how to get this values transfered to the python plugin? No, that's now how things work. This is how you do it: def somefunc(image): path_type, path_closed, num_path_point_details, points_pairs = \ pdb.gimp_path_get_points(image, path1) return points_pairs Return values are returned as return values, which is the python way to do things. It's not like the C API. If you browse the PDB within the python console, when you select a procedure at hit Apply, it will paste a sample of how to call it in to the console entry box. -Yosh ___ Gimp-developer mailing list Gimp-developer@lists.XCF.Berkeley.EDU https://lists.XCF.Berkeley.EDU/mailman/listinfo/gimp-developer
Re: [Gimp-developer] python plugin
Hi emanuele, Sorry I cant help you but I am interested in your surname. I too have the same surname and was of the belief that my son and I were the only two left in the world with this family name, obviously not. If you are interested in replying please do so. For your interest I live in Australia Thanx David View this message in context: Re: python plugin Sent from the Gimp Developer forum at Nabble.com. ___ Gimp-developer mailing list Gimp-developer@lists.XCF.Berkeley.EDU https://lists.XCF.Berkeley.EDU/mailman/listinfo/gimp-developer
Re: [Gimp-developer] python plugin
Hi, Emanuele Zattin [EMAIL PROTECTED] writes: my name is Emanuele Zattin and i'm developing a plug-in implementing a texture synthesis algorithm described in a paper (Texture Synthesis by Non-parametric sampling by Efros and Leung). Here attached you can see my actual implementation which works on grayscale images. It is anyway VERY slow, which was anyway predictable judging from the complexity of the algorithm. I was wondering if translating it to C would make it much faster or if there are some more speedup techniques i'm just missing. You could try to speed it up by optimizing your pixel accessors. Perhaps use a RowIterator as is done in the colorxhtml plug-in? Sven ___ Gimp-developer mailing list Gimp-developer@lists.XCF.Berkeley.EDU https://lists.XCF.Berkeley.EDU/mailman/listinfo/gimp-developer
[Gimp-developer] python plugin
Hello everybody, my name is Emanuele Zattin and i'm developing a plug-in implementing a texture synthesis algorithm described in a paper (Texture Synthesis by Non-parametric sampling by Efros and Leung). Here attached you can see my actual implementation which works on grayscale images. It is anyway VERY slow, which was anyway predictable judging from the complexity of the algorithm. I was wondering if translating it to C would make it much faster or if there are some more speedup techniques i'm just missing. Thank you very much!! Emanuele Zattin #!/usr/bin/python import math from gimpfu import * from Numeric import * def getpixel(drawable, x, y): tile = drawable.get_tile2(FALSE, x, y) x_offset = x % 64 y_offset = y % 64 pixel = tile[x_offset, y_offset] values = [] for i in range(len(pixel)): values.append(ord(pixel[i])) if len(values) == 1: values.append(255) return values def putpixel(drawable, x, y, value): tile = drawable.get_tile2(FALSE, x, y) x_offset = x % 64 y_offset = y % 64 tile[x_offset, y_offset] = chr(value) + chr(255) return def texture_synthesis(image, drawable, w): # first let's retrieve some useful stats about the current layer layer = image.active_layer height = layer.height width = layer.width gimp.tile_cache_ntiles(2 * (width + 63) / 64) # where are the transparent pixels? gimp.progress_init(Gathering stats...) transparent = [] for i in range(width): for j in range(height): pixel = getpixel(layer, i, j) if pixel[1] 255: transparent.append([i, j]) gimp.progress_update(float(i-w)/(width-1-2*w)) if len(transparent) == 0: return while len(transparent) 0: # which is the next pixel to synthetize? neighbours = [] for index in range(len(transparent)): count = 0 pixel_pos = transparent[index] for x in range(max(0, pixel_pos[0]-w), min(width, pixel_pos[0]+w)): for y in range(max(0, pixel_pos[1]-w), min(height, pixel_pos[1]+w)): pixel = getpixel(layer, x, y) if pixel[1] == 255: count = count + 1 neighbours.append(count) trans_index = neighbours.index(max(neighbours)) next_pixel_pos = transparent[trans_index] # create the pattern around that pixel pattern = arrayrange((4*w*w+4*w+1)) pattern.shape = (2*w+1, 2*w+1) for i in range(2*w+1): for j in range(2*w+1): # where's the pixel we're gonna check? px = next_pixel_pos[0]+i-w py = next_pixel_pos[1]+j-w # is it in the image? if px0 or px=width or py0 or py=height: pixel = [-1, 0] else: pixel = getpixel(layer, px, py) if pixel[1] == 255: pattern[i,j] = pixel[0] else: if pixel[0] == -1: pattern[i,j] = -1 else: pattern[i,j] = 0 # let's find the closest matches max_result = 0 values = [] positions = [] gimp.progress_init(Computing pixel: + str(len(transparent)) + more to go) for i in range(width): for j in range(height): result = 0 dist = pow((next_pixel_pos[0]-i),2) + pow((next_pixel_pos[1]-j),2) if dist 0: for x in range(2*w+1): for y in range(2*w+1): px = i+x-w py = j+y-w if px=0 and pxwidth and py=0 and pyheight: pixel = getpixel(layer, px, py) if pixel[1] == 255 and pattern[x,y] =0: result = result + 255-abs(pixel[0]-pattern[x, y]) if result max_result: print Matching: + str(float(result)/(255*((2*w+1)*(2*w+1 + (+ str(i) +,+ str(j) + ) max_result = result pixel = getpixel(layer, i, j) values = [] values.append(pixel[0]) positions = [] positions.append([i, j]) elif result == max_result: pixel = getpixel(layer, i, j) values.append(pixel[0]) positions.append([i, j]) gimp.progress_update(float(i)/(width-1)) distances = [] for i in positions: distances.append(pow((next_pixel_pos[0]-i[0]),2) + pow((next_pixel_pos[1]-i[1]),2)) min_distance_index = distances.index(min(distances)) min_distance_value = values[min_distance_index] putpixel(layer, next_pixel_pos[0], next_pixel_pos[1], min_distance_value) layer.update(next_pixel_pos[0], next_pixel_pos[1], 1, 1) transparent[trans_index:trans_index+1] = [] register( TextureSynthesis, Synthetize transparent pixels of the current layer, Synthetize transparent pixels of the current layer, Ling Xu, Emanuele Zattin, Ling Xu, Emanuele Zattin, 2006, Image/Python-Fu/Texture/Synthesis, GRAY*, [ (PF_INT, w, Window Size, 9) ], [], texture_synthesis) main() ___ Gimp-developer mailing list Gimp-developer@lists.XCF.Berkeley.EDU https://lists.XCF.Berkeley.EDU/mailman/listinfo/gimp-developer
Re: [Gimp-developer] python plugin
On Monday 16 January 2006 12:10 pm, Emanuele Zattin wrote: Hello everybody, my name is Emanuele Zattin and i'm developing a plug-in implementing a texture synthesis algorithm described in a paper (Texture Synthesis by Non-parametric sampling by Efros and Leung). Here attached you can see my actual implementation which works on grayscale images. It is anyway VERY slow, which was anyway predictable judging from the complexity of the algorithm. I was wondering if translating it to C would make it much faster or if there are some more speedup techniques i'm just missing. Thank you very much!! Emanuele Zattin Hi Emanuele, The default way for accessing pixels from python plug-ins is slow. I started researching a faster way a while back, but halted. i think it is important. I don't have teh time now to check if this is the problem in your cscrpit, but from my previous experience, it is rather likely. I will take a look at it later, and suggest another way to manipulate the pixels if possible (or if not possible, seeing what can be done on the gimp-python bindings themselves). Either way, since you already use Numeric, going to C won't be necessary (unless I fail to do all of the above). Regards, JS -- ___ Gimp-developer mailing list Gimp-developer@lists.XCF.Berkeley.EDU https://lists.XCF.Berkeley.EDU/mailman/listinfo/gimp-developer