G’mic : Making better custom filters
0-Introduction
Here, it is supposed that you read the previous article on the subject and are ready for more. The official goal is give tricks to make slicker and more reliable filters.
1-Better preview
1.1-Default zoom
You can specify what should be the default zoom for your preview by pasting a float number between parenthesis to the preview command at the first line end of your custom filter. Ex:
#@gimp Better Filter : better_filter, better_filter_preview(0)
(0) means 1:1 preview, (1) means previewing the whole image, (2) means 1/2 image and so on…
1.2-Split preview
You must have seen that some filters propose a split preview, so you can accurately compare the existing image with the future filtered one. You can add this functionality to your filter if you:
- add a new choice option dedicated to the preview type and
- embed your filter command inside the
-gimp_split_preview
command.
The filter from the previous article would become:
#@gimp Better Filter : better_filter, better_filter_preview(0) #@gimp : Size = float(0.3,0,5) #@gimp : Amplitude for B&W pencil= float(60,0,200) #@gimp : Amplitude for Soft glow = float(1,0,20) #@gimp : sep = separator() #@gimp : Preview type = choice("Full","Forward horizontal","Forward vertical","Backward horizontal","Backward vertical") better_filter : --gimp_pencilbw $1,$2,0,0,0 -gimp_glow[1] $3,0,0 -compose_multiply better_filter_preview : -gimp_split_preview "-better_filter ${1--2}",$-1
2-Multiple input management
2.1-A possible issue
As a user, if you have several layers and want to apply the filter above on each of them, you might feel natural to just set the Input layer
option to All
and proceed. But with the filter as it is right now, you won’t get the expected result.
This is because the -gimp_pencilbw
and the -compose_multiply
commands are applied on every layers without discernment. To address this issue, one solution is to create a loop inside which, each layer is considered one by one.
2.2-The saving loop
For that, you create a “-repeat ... -done
” loop that runs as many times as you have layers. Then, inside that loop, you isolate the layer that has to be processed this time with a “-local ... -endlocal
” block. The filter then becomes:
#@gimp Better Filter : better_filter, better_filter_preview(0) #@gimp : Size = float(0.3,0,5) #@gimp : Amplitude for B&W pencil= float(60,0,200) #@gimp : Amplitude for Soft glow = float(1,0,20) #@gimp : sep = separator(), Preview type = choice("Full","Forward horizontal","Forward vertical","Backward horizontal","Backward vertical") better_filter : -repeat @# -local[@{>,-1}] Â --gimp_pencilbw $1,$2,0,0,0 -gimp_glow[1] $3,0,0 -compose_multiply -endlocal -done better_filter_preview : -gimp_split_preview "-better_filter ${1--2}",$-1
The variable @#
returns the number of layers. If you have 3 layers the code inside the loop will be run 3 times.
The variable ~>
is the counter telling you how many times the loop has been run so far. So, for 3 layers, it takes successively the values 0,1,2.
Only one layer enter the “-local[~>] ... -endlocal
” block, and inside that block, it is considered as being number [0].
3-Sort out your filters
Having many custom filters in your .gmic file can create a mess in your plug-in window. To sort out that, you can create directories! The next line means : “everything that follows will be placed in the directory called: My Directory”
#@gimp My Directory
Whereas that one means : “everything that follows will be in the parent directory”
#@gimp _
So put the first one at the top of your .gmic file and the second one at the bottom and things are sorted out.
Hy Zonderr
thank for this new tut
About the spit preview i will like to understand the function of ${1–2} and of $-1
Hi PhotoComix,
Variables are like images, you can count them starting from the end with negative values and you can call a set of them too
So:
$-1 means the last variable.
$-2 means the second last one.
${1-3} means from the first to the third one.
${1–2} (with 2 minus signs) means from the first to the second last one (=all but the last one).
When you add a split preview, the last variable is the Preview type and you need it for the -gimp_split_preview function, but at the opposite, for your -better_filter, you need all the variables but the last one.
I have some problem on point 2,2 with the -local & -endlocal command
The problem is for escape
for escape i mean options after certain steps to skip all what may follow (the main use is to have a visual control on that step…may even be used to save also that output )
well basically before i was using .return to escape now i get a error if i try about missing .endlocal, but try to add endlocal there only give me other errors
I imagine that if you end your local loop while you are in a if or for loop, you get errors. But I can’t be sure this is your problem, it might be better to develop this in the flickr forum.
Doing now
Thanks for finally talking about >G’mic : Making better custom filters | G’mic tutorials <Liked it!