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.