It is currently Mon Jul 01, 2024 10:43 pm


All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 14 posts ] 
Author Message
 Post subject: How to make plugin run faster
PostPosted: Thu Jun 18, 2020 8:43 pm  (#1) 
Offline
GimpChat Member

Joined: Jul 28, 2018
Posts: 1196
Hi guys, I hope everything is fine with all. I made a text effect python script using LayerFx.py filters but the script runs on about 30 seconds on a 100 px size text. Is there any way to make this script faster? Thanks in advanced and be safe!

_________________
https://www.deviantart.com/pocholo17
Image


Share on Facebook Share on Twitter Share on Orkut Share on Digg Share on MySpace Share on Delicious Share on Technorati
Top
 Post subject: Re: How to make plugin run faster
PostPosted: Fri Jun 19, 2020 12:06 am  (#2) 
Offline
GimpChat Member
User avatar

Joined: Jan 13, 2011
Posts: 2260
Location: Poland
Hi Pocholo.

Only small suggestions.
It may not be the easiest solution, but try to find the right piece of code in the layerfx.py file, analyze it and use (paste) in the new code. Layerfx.py contains about 6570 lines of code, but a significant part is related only to the preview function (using gtk, which slows down the execution). It is possible that it will be easier to parse the layerfx.scm code (this is only about 1485 lines of code). The adaptation will also have the advantage that it will work for users who do not have the layerfx.py file installed.

_________________
Image

Slava
Ukraini!


Top
 Post subject: Re: How to make plugin run faster
PostPosted: Fri Jun 19, 2020 1:54 am  (#3) 
Offline
Script Coder
User avatar

Joined: Jun 22, 2010
Posts: 1171
Location: Here and there
If you tell us what you are trying to achieve, we may be able to suggest a quicker way of doing it.

Kevin


Top
 Post subject: Re: How to make plugin run faster
PostPosted: Fri Jun 19, 2020 2:51 am  (#4) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4752
Post the bloody code already. :)

_________________
Image


Top
 Post subject: Re: How to make plugin run faster
PostPosted: Fri Jun 19, 2020 4:05 am  (#5) 
Offline
GimpChat Member
User avatar

Joined: Jan 20, 2013
Posts: 14816
Location: roma, italy
MareroQ wrote:
Hi Pocholo.

... Layerfx.py contains about 6570 lines of code, but a significant part is related only to the preview function (using gtk, which slows down the execution). It is possible that it will be easier to parse the layerfx.scm code (this is only about 1485 lines of code)....


...I'm sure that -if Ofnuts will spend a bit of his summer vacation on this subject- his python version of layerfx would be less of 1000 lines of code.

_________________
"Where am I ?"


Top
 Post subject: Re: How to make plugin run faster
PostPosted: Fri Jun 19, 2020 4:22 am  (#6) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4752
dinasset wrote:
MareroQ wrote:
Hi Pocholo.

... Layerfx.py contains about 6570 lines of code, but a significant part is related only to the preview function (using gtk, which slows down the execution). It is possible that it will be easier to parse the layerfx.scm code (this is only about 1485 lines of code)....


...I'm sure that -if Ofnuts will spend a bit of his summer vacation on this subject- his python version of layerfx would be less of 1000 lines of code.


Yes, but nobody would understand how to use it :)

_________________
Image


Top
 Post subject: Re: How to make plugin run faster
PostPosted: Fri Jun 19, 2020 5:32 am  (#7) 
Offline
GimpChat Member

Joined: Mar 04, 2011
Posts: 2436
Now why would anyone think that ;)

Attachment:
fx.jpg
fx.jpg [ 170.84 KiB | Viewed 7385 times ]

_________________
Image


Top
 Post subject: Re: How to make plugin run faster
PostPosted: Fri Jun 19, 2020 7:02 am  (#8) 
Offline
Global Moderator
User avatar

Joined: Oct 06, 2010
Posts: 4050
Rich, you forgot (requires at least two paths for it to run and you know where they go, figure it out).

_________________
"In order to attain the impossible, one must attempt the absurd."
~ Miguel de Cervantes


Top
 Post subject: Re: How to make plugin run faster
PostPosted: Fri Jun 19, 2020 7:05 am  (#9) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4752
rich2005 wrote:
Now why would anyone think that ;)

Attachment:
fx.jpg


Node-based editing at its finest :) And if you draw a chicken you get your text as rolling 3D credits, Star-wars style.

_________________
Image


Top
 Post subject: Re: How to make plugin run faster
PostPosted: Fri Jun 19, 2020 7:09 am  (#10) 
Offline
Global Moderator
User avatar

Joined: Oct 06, 2010
Posts: 4050
ofnuts wrote:
rich2005 wrote:
Now why would anyone think that ;)

Attachment:
fx.jpg


Node-based editing at its finest :) And if you draw a chicken you get your text as rolling 3D credits, Star-wars style.


Now I'm going to open all of your files and check for Easter eggs.

_________________
"In order to attain the impossible, one must attempt the absurd."
~ Miguel de Cervantes


Top
 Post subject: Re: How to make plugin run faster
PostPosted: Fri Jun 19, 2020 7:50 am  (#11) 
Offline
GimpChat Member

Joined: Jul 28, 2018
Posts: 1196
Thank you for your quick responds, here is the code:

#!/usr/bin/env python

# author: Pocholo
# date: 6/6/20

# Comments directed to http://gimpchat.com

# Installation:
# This script should be placed in the user plugin folder

# Copyright (C)

#   This program is free software: you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by   
#   the Free Software Foundation, either version 3 of the License, or
#   (at your option) any later version.

#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this program.  If not, see <https://www.gnu.org/licenses/>.


from gimpfu import *

def pm_incredible_hulk_text(customtext, font, fontsize, textcolor):

   
   #Create image
   img = pdb.gimp_image_new(1, 1, RGB_IMAGE)
   
   pdb.gimp_context_push()
   
   #Create the text
   pdb.gimp_context_set_foreground(textcolor)
   layer = pdb.gimp_text_fontname(img, None, 0, 0, customtext, 65,
                              TRUE, fontsize, PIXELS, font)
   pdb.gimp_text_layer_set_letter_spacing(layer, 30)
   pdb.gimp_text_layer_set_justification(layer, 2)
         
   #Resize image
   img.resize(layer.width, layer.height, 0, 0)
   
   #Create background
   backlayer = pdb.gimp_layer_new(img, layer.width, layer.height, RGB_IMAGE, "Background", 100, LAYER_MODE_NORMAL)
   pdb.gimp_image_add_layer(img, backlayer, 1)
   pdb.gimp_context_set_gradient("Greens")
   pdb.gimp_drawable_edit_gradient_fill(backlayer, 0, 0, TRUE, 3, 0.20, TRUE, 800, 0, 800, 900)
   
   
   #Text drop shadow
   pdb.python_layerfx_drop_shadow(img, layer,
                           (0, 0, 0),   #color
                                0.75,   #opacity
                                  1,   #contou
                                  0,   #noise
                                  3,   #mode for multiply
                                 15,   #spread
                                 20,   #size
                                 120,   #offset_angle
                                 20,   #offset_distance
                                TRUE,   #knockout
                               FALSE)   #merge
   
      
   #Text inner shadow
   pdb.python_layerfx_inner_shadow(img, layer,
                            (0, 0, 0),   #color
                                   75,   #opacity
                                   1,   #contou
                                   0,   #noise
                                   3,   #mode for multiply
                                   1,   #source
                                   0,   #choke
                                   45,   #size
                                 120,   #offset_angle
                                   5,   #offset_distance
                                 FALSE)  #merge
   
      
   #Text outer glow
   pdb.python_layerfx_outer_glow(img, layer,
                           (14, 34, 0),   #color
                                 100,   #opacity
                                   0,   #contou
                                   0,   #noise
                                   4,   #mode
                                    8,   #spread
                                  14,   #size
                                 TRUE,   #knockout
                                FALSE)   #merge   
   
   
   pdb.python_layerfx_bevel_emboss(img, layer,
                                    1,   #style inner bevel
                                    65,   #depth
                                     0,   #direction
                                    48,   #size
                                    4,   #soften
                                   120,   #angle
                                    65,   #altitude
                                    5,   #gloss_contour
                                "White",   #highlight_color
                                    10,   #highlight_mode lighten only
                                    40,   #highlight_opacity
                                "Black",   #shadow_color
                                    17,   #shadow_mode burn
                                    55,   #shadow_opacity
                                     6,   #surface_contour
                                  TRUE,   #use_texture
                            "Dried mud",   #pattern
                                   150,   #scale
                                   -30,   #tex_depth
                                  TRUE,   #invert
                                 FALSE)   #merge   
   
      
   pdb.python_layerfx_satin(img, layer,
                      (27, 92, 26),   #color
                               90,   #opacity
                               3,   #mode MULTIPLY
                              19,   #offset_angle
                              14,   #offset_distance
                               60,   #size
                                3,   #contou
                             TRUE,   #invert
                            FALSE)   #merge   
   
   
   pdb.python_layerfx_color_overlay(img, layer,
                              (44, 63, 2),   #color
                                    100,   #opacity
                                     18,   #mode hard light   
                                   FALSE)   #merge
   
   
   pdb.gimp_context_set_foreground((0, 255, 0))
   pdb.gimp_context_set_background((255, 255, 255))
   pdb.python_layerfx_gradient_overlay(img, layer,
                            "FG to BG (RGB)",   #gradient
                                        0,   #gradient_type linear
                                        0,   #repeat none
                                     FALSE,   #reverse
                                       85,   #opacity
                                       21,   #mode grain merge
                                        0,   #center_x
                                        0,   #center_y
                                       90,   #angle
                                       200,   #width
                                     FALSE)   #merge
   
         
   pdb.python_layerfx_pattern_overlay(img, layer,
                                "Dried mud",   #pattern
                                      100,   #opacity
                                        21,   #mode grain merge
                                      150,   #scale
                                       0,   #interpolation
                                    FALSE)   #merge
   
      
   gimp.Display(img)
   pdb.gimp_context_pop()
   
      
   
register(
   "pm_incredible_hulk_text",
   "Creates a muscles text",
   "Creates a Hulk text",
   "Pocholo",
   "Pocholo",
   "2020",
   "The incredible Hulk text",
   "",
[
   (PF_STRING, "customtext", "Text string", 'HULK'),
    (PF_FONT, "font", "Font face", "Berlin Sans FB Bold"),
   (PF_SPINNER, "fontsize", "Font size", 300, (100, 500, 1)),
   (PF_COLOR, "textcolor", "Text color", (1, 48, 1)),
],
[],
pm_incredible_hulk_text, menu="<Image>/Python-Fu/The incredible Hulk text")
main()

_________________
https://www.deviantart.com/pocholo17
Image


Last edited by Pocholo on Tue Feb 01, 2022 11:53 am, edited 1 time in total.

Top
 Post subject: Re: How to make plugin run faster
PostPosted: Fri Jun 19, 2020 8:50 am  (#12) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4752
Since you are working on a new image, you can disable undo: pdb.gimp_image_undo_disable(image)/pdb.gimp_image_undo_enable(image).

Otherwise since you are mostly calling LayerFX functions, either you find a way to obtain the same results without piling up effects, or you look at the LayerFx code and steal the relevant bits.

_________________
Image


Top
 Post subject: Re: How to make plugin run faster
PostPosted: Wed Aug 12, 2020 7:23 am  (#13) 
Offline
GimpChat Member
User avatar

Joined: Jan 13, 2011
Posts: 2260
Location: Poland
Hi Pocholo.

I quickly needed such an effect so I added the Filters / Alpha to Logo / Hulk efect by Pocholo option ...
You didn't add a download package - so I add.
I hope you won't be offended by the attention: maybe you will add this option to your other plugins?

The speed of execution is acceptable - I know much slower ones.


Attachments:
Hulk Text.png
Hulk Text.png [ 238.33 KiB | Viewed 5134 times ]
Hulk Alpha to Logo.png
Hulk Alpha to Logo.png [ 227.99 KiB | Viewed 5134 times ]
pm_hulk.zip [2.94 KiB]
Downloaded 82 times

_________________
Image

Slava
Ukraini!
Top
 Post subject: Re: How to make plugin run faster
PostPosted: Wed Aug 12, 2020 8:00 am  (#14) 
Offline
GimpChat Member

Joined: Jul 28, 2018
Posts: 1196
No a problem my friend. I'm rather flatter by using my script to improve it. Thanks :) :hi5

_________________
https://www.deviantart.com/pocholo17
Image


Top
Post new topic Reply to topic  [ 14 posts ] 

All times are UTC - 5 hours [ DST ]


   Similar Topics   Replies 
No new posts How to make G'MIC runs faster?

6

No new posts Make a key binding to access third party GEGL Operations faster

1

No new posts Attachment(s) Create a starfield plugin (Faster than "starry sky.scm")

9

No new posts Attachment(s) Baby's first GEGL plugin - a very basic GEGL plugin anyone can make.

9

No new posts Is it possible to make a plugin that runs bash scripts on a clipboard

1



* Login  



Powered by phpBB3 © phpBB Group