Custom G'MIC script not working

Hi again, I’m busy trying to build a custom G’MIC command from a script I used with the custom command box:

# plasma rendering and pixelisation followed by random warp with gamma and hue randomisation and final HSV scaling

-fx_plasma 0.5,0,8,1,0,128,128,128

pixel_x={round(u*7.498+3.501)}
pixel_y={round(u*7.498+3.501)}

-samj_Contours_Gros_Pixels 0.5,10,2,{$pixel_x},{$pixel_y},100,1.25,0,0,15,0,0,22,1

f=5 # iterations
i=1 # warp intensity
m=5 # offset magnitude
s=0.25 # gamma
v=1 # hue

hue_min=0
hue_max=5
sat_min=0.5
sat_max=5
val_min=0
val_max=5

-repeat {$f*sign($f)}

a=(u-0.5)*$i
b=(u-0.5)*$i
c=(u-0.5)*$m*sign($m)
d=(u-0.5)*$m*sign($m)
e={round(u)}
f={round((u*2.98)+0.51)}
g={round((u*33.98)-0.49)}
h=(u-0.5)*$s*200
i=(u-0.5)*$v*200

-fx_warp_by_intensity {$a},{$b},{$c},{$d},{$e},0,{$f},{$g},0
-fx_adjust_colors 0,0,{$h},{$i},0,0

-done

j={$hue_min+(u*($hue_max-$hue_min))}
k={$sat_min+(u*($sat_max-$sat_min))}
l={$val_min+(u*($val_max-$val_min))}

-fx_mix_hsv {$j},0,0,{$k},0,0,{$l},0,0,0,2,0
-fx_warp_by_intensity {$a},{$b},{$c},{$d},{$e},0,{$f},{$g},0

Here is my attempt to turn it into a GUI script; my problem is that it’s not showing up in the commands when I place the file in ~/.config/gmic. How can I make it work?

Place that code in a file called .gmic - mind the dot - and store that in /home.
If you still have problems, have a look over here, it shows step by step how to create/replicate gmic filters for use in the g’mic gimp plugin:

1 Like

That works, although I would’ve liked to create a custom G’MIC file with a custom filename. Now I keep getting syntax errors on anything that isn’t a comment and the error prevents me from running every single other filter. This is a bug with the interpreter.

Would you mind sharing your .gmic file, so we can check what is going on ?
What kind of errors do you get ?
I honestly doubt there is a problem with the interpreter at this point, because this has been working for years with maaaaany other filters.

First, the error:


Secondly, the file’s already here.

Several errors in your file:

  • You forgot to define the start of the command hyperwarpplus, I added it l.30.
  • Your command hyperwarpplus_preview is useless: it is not referenced anywhere, and as you haven’t the preview splitting options in your argument list, there are no ways it can work. I’ve removed it.
  • Your variables $h and $i were not correctly defined (missing braces). Correct syntax should be probably:
h={(u-0.5)*$s*200}
i={(u-0.5)*$v*200}
  • Putting variables between braces is also useless, so things like {$a},{$b} can be replaced by $a,$b.
  • With default parameters, your variable $f is set to 0, which means that the -repeat {$f*sign($f)} loop doesn’t execute a single iteration, which means that variables $g and $h are not assigned to any values, leading to missing parameters in l.149: -fx_warp_by_intensity {$a},{$b},{$c},{$d},{$e},0,{$f},{$g},0. I’ve then replaced the repeat command by this : -repeat {max(1,$f*sign($f))} to ensure at least one iteration of this loop is done. I don’t know if that is something you expect or not, but in any case, defining non-local variables to a loop only inside a loop is probably not recommended at all.

With all these changes, I get a working filter (that looks a bit strange, but I don’t know what it is supposed to do).
Here is the modified file: #@gmic## File : seriously.gmic# ( G'MIC commands fi - Pastebin.com

and a screenshot of the filter running in the plug-in:

Yeah, I realised that {!$x} means a boolean NOT and the loop broke. Here’s the filter working as it should (with a new name), though I reckon I could add some salt-and-pepper noise to make it even more erratic:

I’ll also add a channel-locking feature in future though I eventually wish to include it as a community filter by making a pull request. That means I’ll need to save it as a named .gmic file, which didn’t work last time.

@Joan_Rake1 Looks interesting. What did you have in mind for this filter? Where are you using it?

It’s for general use, though I use it to generate extremely-distorted and ‘raw’ textures in a matter of seconds:



Those three are on the default settings (with the exception of the plasma texture rendering been turned on). When applied on other images the results are even messier:

I’m not done yet; I’d like to include blurring in addition to channel-locking.

Just save the content of your .gmic file as a new file your_name.gmic and I’ll add it to the gmic-community repository, and register it as a new external filter source. So it will appear for everyone after a filter update.

Will do; I’ve added the blurring and moved to using quadtree-based ‘pixelisation’. All I need now is to figure out how to lock channels. Can I use channel names instead of numbers when passing it to the warp command?

What does channel-locking means precisely ? You want to apply the filter only on some channels ?
If so, I’d suggest you add a parameter Channel(s) in your parameter list and use command -apply_channels (shortcut -ac), as it is already done for other filters.
Should be as simple as adding:

#@gui : sep = separator(), Channel(s) = choice("All","RGBA [all]","RGB [all]","RGB [red]","RGB [green]","RGB [blue]","RGBA [alpha]","Linear RGB [all]","Linear RGB [red]","Linear RGB [green]","Linear RGB [blue]","YCbCr [luminance]","YCbCr [blue-red chrominances]","YCbCr [blue chrominance]","YCbCr [red chrominance]","YCbCr [green chrominance]","Lab [lightness]","Lab [ab-chrominances]","Lab [a-chrominance]","Lab [b-chrominance]","Lch [ch-chrominances]","Lch [c-chrominance]","Lch [h-chrominance]","HSV [hue]","HSV [saturation]","HSV [value]","HSI [intensity]","HSL [lightness]","CMYK [cyan]","CMYK [magenta]","CMYK [yellow]","CMYK [key]","YIQ [luma]","YIQ [chromas]")
#@gui : Value action = choice("None","Cut","Normalize")

and add a new command like that:


fx_hyperwarpplus :
  -ac "-hyperwarpplus $*",$-2,$-1

(and put this new command as the command to execute for the filter).

That’s at the end of the filter; what I want is something that sets the channel option right at the -fx_warp_by_intensity command.

Here’s the command as it stands now.

All that from the almost default settings: that is pretty cool. The 3rd image is like a Chinese painting of misty mountains and the river that meanders between them.

Yeah, it’s pretty good for extreme abstraction; the blurring produces interesting artistic forms. It’s especially good with creating layer masks:

The blue/black boxed artifacts look like a tiling issue in algorithm…

That’s the work of a layer mask.

I had an error but I figured out that it was due to local variables not being transferred. I have no idea why I was talking about a pull request but here’s the script if you wish to add it.

Added in Degradations/

Thanks, I might add some more filters soon. I’ll PM you if I do. For now I’ve tried to fix and update UltraWarp++ but the filter broke again without me editing it: