Sign in to follow this  
Reptillian

[Tutorial] Transforming a basic PDN effect into a G'MIC Plugin - Overblur used as example

Recommended Posts

Introduction

 

As G'MIC is now available for PDN, there is now easily accessible alternative to C# for developing filters.

 

What exactly would be the benefit of turning a PDN filter to a G'MIC filter? Well, here's some few benefits to some users of PDN and especially for those that use multiple applications that use G'MIC.

 

  • G'MIC are accessible to the following program - Paint.NET, Krita, GIMP, Natron, Blender . This would mean that you could continue your project elsewhere while still having access to G'MIC filters.
  • Better filter preservation. To explain this in a easier way, G'MIC by itself is likely going to be accessible for a long time to go, and many filters can also be preserved. Individual filters tend to have a big issue of being lost permanently requiring users to remake filters again or to restore it from a backup. Just look at the dead links due to the forum upgrade in some threads at plugins section of this forum to see what I mean. And if G'MIC sources disappear on the main website, there's likely going to be a person who do have the source code for it and instructions to compile G'MIC for respective softwares, and precompiled versions would also exist elsewhere.
  • It's an alternative to C# with many syntaxs and option. You would have to read the 400 page documentation for example of G'MIC scripting, and look at G'MIC reference. It even support for loop. For some, this can be beneficial as it can be easier to learn for some users, and G'MIC has a big advantages of being able to make the GUI alongside with $x where x is the variable number being directly connected to the GUI.

 

The downside is that for those who do not want people to have source code to their filter or want to allow others to modify their filter will have to use the standard #C instead and not even bother with this tutorial at all. You have to share your code to the world if you want your G'MIC filter to be accessible to others, no if and no but here unless maybe you're a developer of proprietary programs (I think the license changed to allow proprietary programs to do so, but I'm not sure, hence maybe.).

 

That being said, those are the few reasons why you would want to turn a PDN filter to a G'MIC filter.

 

Resources

https://gmic.eu/reference.shtml - This link refers to everything or almost everything about G'MIC scripting with examples

https://gmic.eu/gmic_reference.pdf - 458 pages of examples and some clarifications of scripting

 

Tutorial

This tutorial is going to be about transforming basic filter to a G'MIC filter. More advanced ones are possible, but that would require some good amount of understanding of G'MIC scripting, and its syntax. Spaces are critical here.

 

For basic filter and possibly advanced ones (I'm not sure the extent this can be used with code[local], you can use code[local] filter to test your script first.

 

This tutorial uses Code[Local] first.

 

Note 1 - [x] are G'MIC layers

Note 2 - $x are G'MIC variables connected

 

- Part 1 : Preparation

1. Open Paint.NET/Krita/GIMP with G'MIC installed. Krita and GIMP supports multiple layer output, so you can see how your code works by clicking applies. The [0] is the currently selected, and [n] or [-1] are basically anything below the [0] layer.  See debug info is crucial to diagnosing how your code will work within code[local]

2. Copy and Paste a image to be used for testing

3. Open G'MIC. G'MIC can be located by Effect > Advanced > G'MIC-QT

4. Go to Custom Code[Local] filter

5. Go to Part 2

 

- Part 2 : Making the over-blur script and testing it

1. Read about the PDN effect you are going to replicate [Yes, so you can make a theory on how to replicate the G'MIC filter in theory

2. For overblur, it seems that it uses a blur filter first, and generate the difference between the blur image and the original image. Overblur add the sum of the difference with the blur result multiplied by a variable and the original. Overblur (final_image) = Original + (Blur_Variable - Original) * V1 . That means your filter would need at least 2 tabs on its GUI. More on that later.

3. To create a layer within G'MIC with filter applied within code[local] -> Type in +{Effect}[layer_number] x...z where x...z are all numbers of variables you are going to use. See update24xx.gmic on the appdata folder to see effect. $1.....$inf are placement of each variables that are connected the GUI of the filter they're respective to most of the time.

4. Finally, type in blend[0,1] add to see the overblur effect within the preview. Debug info is crucial for PDN as you cannot output multiple layers in there.

 

- Part 3 : Making the G'MIC code

 

Note: The code needs more work, but this is more of a starter code. Completing it and describing it will just more efforts than I want to do.

 

If you look at update24xx.gmic within Kate text editor, you'd note how the GUI works just by looking at the code of the filter and comparing it with the GUI windows.

All notes, and separators are ignored. $x correspond with adjustable number variables.

 

Everything must start with #@gui. All the other are just GUI development.

Okay, now to make the filter for real.

 

1. Open Kate text editor (I'm not too sure on Notepad++ when copy and paste into .gmic found at appdata, haven't tried it.)

2. Copy and paste the code[local] code within Kate.

3. Convert number to variables. The first variable should be $1, and the second variable should $2.

 

So, it should look like this in Kate text editor. You will copy and paste the final code that to updatexxx.gmic later on, but not now.


+blur[0] $1

+blend[0,1] difference

mul[2] $2

remove[1]

-blend[0,1] add

There, that means you should have at least 2 sliding tabs on the GUI.

 

4. Type in $@gui _

This should go into top of the code.

 

5. Now, type in #@gui {FilterName}: {Effect_Command_Name}, {Effect_Command_Name}_preview(0)

where {Effect_Command_Name} is your chosen name for this effect. To clarify, here's a example of what I mean.

#@gui Overblur: overblur, _overblur_preview(0)

 

That should go on second half top of the code. Every other GUI part of the code here are below this.

 

6. You can add texts to it by typing #@gui : note = note ("") ; where anything between "" is your text that you want to leave info for users of your filter about.

7. You can add separator by adding #@gui : sep = separator()

8. We are going to use 2 float variable. So this means you should add 2 copies of #@gui : {Name of Variable} = float (default, min, max) below the above line referenced in this tutorial.

9. You can add preview by copy and pasting one of the preview type code. That should go into the second bottom line of the gui section.

10. If you want to credit yourself, copy and paste one the existing credit note and replace it with the correct name and date.

11. After you made your GUI. You can continue on the bottom portion of the code. The code so far should look like this.

 


#@gui _
#@gui Overblur: overblur, _overblur_preview(0)
#@gui : note = note("Overblur the image")
#@gui : sep = separator()
#@gui : Blur Factor = float(1,.1,10)
#@gui : Multiply Factor = float (1,.1,10)
#@gui : sep = separator(), Preview type = choice("Full","Forward horizontal","Forward vertical","Backward horizontal","Backward vertical","Duplicate top","Duplicate left","Duplicate bottom","Duplicate right","Duplicate horizontal","Duplicate vertical","Checkered","Checkered inverse")
#@gui : sep = separator(), note = note("<small>Author : <i>Reptorian</i>      Created by: <i>2018/12/21</i>.</small>")

 

+blur[0] $1
+blend[0,1] difference
mul[2] $2
remove[1]
-blend[0,1] add

 

12. Add overblur: above the +blur[0]$1

13. Add _overblur_preview: below -blend[0,1] add

It should look like this on the bottom portion of the code:


overblur:

+blur[0] $1
+blend[0,1] difference
mul[2] $2
remove[1]
-blend[0,1] add

_overblur_preview:

14. For ease, I'd just copy and paste this below preview:

gui_split_preview "overblur ${1--2}", $-1

 

By this point, you are done with the code. It should look like this.


#@gui _
#@gui Overblur: overblur, _overblur_preview(0)
#@gui : note = note("Overblur the image")
#@gui : sep = separator()
#@gui : Blur Factor = float(1,.1,10)
#@gui : Multiply Factor = float (1,.1,10)
#@gui : sep = separator(), Preview type = choice("Full","Forward horizontal","Forward vertical","Backward horizontal","Backward vertical","Duplicate top","Duplicate left","Duplicate bottom","Duplicate right","Duplicate horizontal","Duplicate vertical","Checkered","Checkered inverse")
#@gui : sep = separator(), note = note("<small>Author : <i>Reptorian</i>      Created by: <i>2018/12/21</i>.</small>")

overblur:
+blur[0] $1
+blend[0,1] difference
mul[2] $2
remove[1]
-blend[0,1] add

_overblur_preview:
gui_split_preview "overblur ${1--2}", $-1

 

Copy and paste anywhere below Testing within updatexxxx.gmic

 

- Part 4 : See your work

 

1. Open Paint.NET

2. Load G'MIC-QT

3. Search Overblur

4. Click it.

 

If all goes well, it seem that it should work.

 

Now the basics should be learned.

Edited by Reptillian
  • Like 1
  • Upvote 3

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this