GIMP Chat
http://gimpchat.com/

How to make plugin run faster
http://gimpchat.com/viewtopic.php?f=9&t=18473
Page 1 of 1

Author:  Pocholo [ Thu Jun 18, 2020 8:43 pm ]
Post subject:  How to make plugin run faster

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!

Author:  MareroQ [ Fri Jun 19, 2020 12:06 am ]
Post subject:  Re: How to make plugin run faster

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.

Author:  paynekj [ Fri Jun 19, 2020 1:54 am ]
Post subject:  Re: How to make plugin run faster

If you tell us what you are trying to achieve, we may be able to suggest a quicker way of doing it.

Kevin

Author:  ofnuts [ Fri Jun 19, 2020 2:51 am ]
Post subject:  Re: How to make plugin run faster

Post the bloody code already. :)

Author:  dinasset [ Fri Jun 19, 2020 4:05 am ]
Post subject:  Re: How to make plugin run faster

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.

Author:  ofnuts [ Fri Jun 19, 2020 4:22 am ]
Post subject:  Re: How to make plugin run faster

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 :)

Author:  rich2005 [ Fri Jun 19, 2020 5:32 am ]
Post subject:  Re: How to make plugin run faster

Now why would anyone think that ;)

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

Author:  mahvin [ Fri Jun 19, 2020 7:02 am ]
Post subject:  Re: How to make plugin run faster

Rich, you forgot (requires at least two paths for it to run and you know where they go, figure it out).

Author:  ofnuts [ Fri Jun 19, 2020 7:05 am ]
Post subject:  Re: How to make plugin run faster

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.

Author:  mahvin [ Fri Jun 19, 2020 7:09 am ]
Post subject:  Re: How to make plugin run faster

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.

Author:  Pocholo [ Fri Jun 19, 2020 7:50 am ]
Post subject:  Re: How to make plugin run faster

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()

Author:  ofnuts [ Fri Jun 19, 2020 8:50 am ]
Post subject:  Re: How to make plugin run faster

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.

Author:  MareroQ [ Wed Aug 12, 2020 7:23 am ]
Post subject:  Re: How to make plugin run faster

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 5147 times ]
Hulk Alpha to Logo.png
Hulk Alpha to Logo.png [ 227.99 KiB | Viewed 5147 times ]
pm_hulk.zip [2.94 KiB]
Downloaded 82 times

Author:  Pocholo [ Wed Aug 12, 2020 8:00 am ]
Post subject:  Re: How to make plugin run faster

No a problem my friend. I'm rather flatter by using my script to improve it. Thanks :) :hi5

Page 1 of 1 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/