Trying to make my 1st "pipeline filter"

I wonder how’s thing holding up for you. Progress?

Hi,

Well it’s progressing slowly but it’s usable. I spend most of the time looking at the command reference pages and testing things.

2 Likes

Hello,

just posting the code for this so people can play with it. I’m curious what you can do with it.

I think it’s kinda slow and i’m trying to make it faster but i don’t have enough knowledge to do so… Anyway i also like the output for low resolutions (around 1000px or 1500px)

Also i don’t know how i can make broader lines for the sketch part, it’s too thin when using larger resolutions.

Here goes (sorry for bad code heh)

Code
#@gui WaterGmicB : watergmicB, watergmic_previewB(1)*
#@gui : note = note("<small>Author: <i><a href="http://prawnsushi.free.fr">Prawnsushi</i></a>.      Latest Update: <i>2023/14/03</i>.</small>")
#@gui : sep = separator()
#@gui : Write settings on picture = bool(0)
#@gui : note = note("<small>Use original input image resolution or choose processing resolution.\nHigher Res is slower and not always better. </small>")
#@gui : Original Resolution = bool(0)
#@gui : Processing Resolution = int(1000,500,5000)
#@gui : Garagecoder's DCCI2x rescale (Post) = int(0,0,5)
#@gui : sep = separator()
#@gui : Pre-Process = bool(1)
#@gui : - Sharpening = int(0,0,500)
#@gui : - Blur = float(0,0,10)
#@gui : - Local normalization = float(0.5,0.3,3)
#@gui : Sloppiness = bool(1)
#@gui : - Distort = float(3,0,20)
#@gui : - Blur = float(3,0,50)
#@gui : - Blend Mode = choice(13,"add","and","average","blue","burn","darken","difference","divide","dodge","exclusion","grainextract","grainmerge","green","hardlight","hardmix","hue","interpolation","lighten","lightness","linearburn","linearlight","luminance","multiply","negation","or","overlay","pinlight","red","reflect","saturation","screen","shapeaverage","softburn","softdodge","softlight","stamp","subtract","value","vividlight","xor")
#@gui : - Strength = float(0.5,0.0,1.0)
#@gui : sep = separator()
#@gui : Watering = bool(1)
#@gui : - Smoothing = int(12,0,40)
#@gui : - Iterations = int(1,0,10)
#@gui : Fuzzy Frame Size = int(30,0,350)
#@gui : - Frame Blur = int(20,0,150)
#@gui : - Frame Strentgh = float(0.5,0,5)
#@gui : Plasma Seed = int(-1,-1,9999999)
#@gui : - Plasma Saturation = int(-100,-100,100)
#@gui : - Blend Mode = choice(23,"add","and","average","blue","burn","darken","difference","divide","dodge","exclusion","grainextract","grainmerge","green","hardlight","hardmix","hue","interpolation","lighten","lightness","linearburn","linearlight","luminance","multiply","negation","or","overlay","pinlight","red","reflect","saturation",screen","shapeaverage","softburn","softdodge","softlight","stamp","subtract","value","vividlight","xor")
#@gui : - Plasma Strength = float(0.5,0,1)
#@gui : sep = separator()
#@gui : Cracks = bool(1)
#@gui : Sharpening = int(150,0,500)
#@gui : - Shock Filter = int(1,0,1)
#@gui : Light1(0 means all off) = float(0.15,0,1)
#@gui : - Light2 = float(0.02,0,1)
#@gui : - Light3 = float(0.02,0,1)
#@gui : sep = separator()
#@gui : Sketch = bool(1)
#@gui : - Likeness = int(25,0,30)
#@gui : - Threshold Min = int(0,0,255)
#@gui : - Threshold Max = int(20,0,255)
#@gui : - Sketch strength = float(1,0,1)
#@gui : --- Messy lines = float(0.9,0,1)
#@gui : - Blend Mode = choice(22,"add","and","average","blue","burn","darken","difference","divide","dodge","exclusion","grainextract","grainmerge","green","hardlight","hardmix","hue","interpolation","lighten","lightness","linearburn","linearlight","luminance","multiply","negation","or","overlay","pinlight","red","reflect","saturation",screen","shapeaverage","softburn","softdodge","softlight","stamp","subtract","value","vividlight","xor")
#@gui : note = note("<small>Setting Sktech Strength to 0 disables Messy lines too.\n Messy lines uses <Breaks> by David Tschumperlé.</small>")
#@gui : Noise = float(3,0,6)
#@gui : Canvas = float(0.3,0,1)
#@gui : sep = separator()
#@gui : Post-Process = bool(1)
#@gui : Mix Original Hue/Sat = float(0.5,0,1)
#@gui : Brightness = float(0,-100,100)
#@gui : Contrast = float(0,-100,100)
#@gui : Gamma = float(0,-100,100)
#@gui : Hue = float(0,-100,100)
#@gui : Saturation = float(0,-100,100)
#@gui : sep = separator()
#@gui : 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 :Preview Split=point(50,50,0,0,200,200,200,0,10)_0
#@gui : sep = separator()

watergmicB :

com,__origres,__procres,dccires,__bst,__bstsharp,_bstblur,__locnorm,__filt,__dist,__distblur,__distmerge,__diststr,__wc,__bilsize,__bilrep,__fuzz,__fuzzblur,__fuzstr,__plsmseed,__plsmsat,__plasmerge,__plastr,\
__cracks,__sckrad,__sck,__lgtone,__lgttwo,__lgthree,__sketch,__sklike,__cutmin,__cutmax,__linestr,__brkstr,__skmerge,__noistr,cnvs,__post,__huestr,__bri,__con,__gam,__hue,__sat=${1-45}


m "BlendMode : $""=__mode" BlendMode "add","and","average","blue","burn","darken","difference","divide","dodge","exclusion","grainextract","grainmerge","green","hardlight","hardmix","hue","interpolation","lighten","lightness","linearburn","linearlight","luminance","multiply","negation","or","overlay","pinlight","red","reflect","saturation","screen","shapeaverage","softburn","softdodge","softlight","stamp","subtract","value","vividlight","xor","error"

m "BlendModeP : $""=__modep" BlendModeP "add","and","average","blue","burn","darken","difference","divide","dodge","exclusion","grainextract","grainmerge","green","hardlight","hardmix","hue","interpolation","lighten","lightness","linearburn","linearlight","luminance","multiply","negation","or","overlay","pinlight","red","reflect","saturation","screen","shapeaverage","softburn","softdodge","softlight","stamp","subtract","value","vividlight","xor","error"


m "BlendModeL : $""=__model" BlendModeL "add","and","average","blue","burn","darken","difference","divide","dodge","exclusion","grainextract","grainmerge","green","hardlight","hardmix","hue","interpolation","lighten","lightness","linearburn","linearlight","luminance","multiply","negation","or","overlay","pinlight","red","reflect","saturation","screen","shapeaverage","softburn","softdodge","softlight","stamp","subtract","value","vividlight","xor","error"

#~ to_rgb
normalize 0,255
nm[0] ORIG
__ORIGW={0,w}
__ORIGH={0,h}

if !$__origres
	__res=$__procres,$__procres
	rr2d[ORIG] $__res,0,6
fi

if $__bst
blur $_bstblur sharpen $__bstsharp normalize_local $__locnorm,$__locnorm
fi

[ORIG] nm. REND

if $__filt
[ORIG] nm. FILT
	local[FILT]
		repeat 3
			apc "deform $__dist blur $__distblur"
		done
	done
blend[REND,FILT] ${__mode{$__distmerge+1}},$__diststr
normalize[REND] 0,255
fi

if $__wc
	if $__plastr>0
		[ORIG] nm. PLAS
			local[PLAS]
				if $__plsmseed>-1
					srand $__plsmseed
				fi
				#~ plasma 1,2,2
				plasma 1,2,5
				adjust_colors 0,0,0,0,$__plsmsat
			done
		blend[REND,PLAS] ${__modep{$__plasmerge+1}},$__plastr
	fi
fi

if $__wc
	if $__fuzz>0
	[ORIG] nm. FUZZ
		local[FUZZ]
			fill_color 0,0,0
			spread {$__fuzz/2},{$__fuzz/2},0
			negate
			frame_fuzzy $__fuzz
			blur $__fuzzblur,0
			deform $__fuzz
			spread {$__fuzz/2},{$__fuzz/2}
			spread 10
			split c rm. . negate.  append c
				if $__fuzstr!=1
					mul $__fuzstr
				fi
		done
	blend_median[REND,FUZZ]
	channels 0,2
	normalize[REND] 0,255
	fi
fi


local[REND]
	if $__cracks
		if $__sckrad>0
		repeat 3
			deform 1.5 sharpen $__sckrad,$__sck dilate_circ 1.5 sharpen $__sckrad,$__sck
		done
		fi

		if $__lgtone>0
		repeat 3
			fx_light_relief $__lgtone,$__lgttwo,$__lgthree,0,0.2,50,50,20,0.084,0,0 
			blur 2 erode_circ 3 sharpen $__sckrad
		done
		fi
	fi

	if $__wc
		repeat $__bilrep
			deform 0.3 sharpen 80,0,10,10 bilateral $__bilsize,$__bilsize,$__bilsize,$__bilsize
			#~ deform 0.3 sharpen 80,0,10,10 rolling_guidance $__bilsize,$__bilsize,0
		done
		sharpen 80,0,10,10 sharpen 50 normalize 0,255
	fi
done

if $__post
	if $__huestr>0
		[ORIG] nm. HUE
		[ORIG] nm. SAT
		move[ORIG] -1
		blend[HUE,REND] hue,$__huestr
		blend[SAT,REND] saturation,{$__huestr/3}
	fi
fi

if $__sketch
	if $__linestr>0
	[ORIG] nm. LINE
		local[LINE]
			lw={LINE,w}
			deform 1.5 rolling_guidance {31-$__sklike},10,0.5
			gradient_norm negate
				if $__brkstr>0
					+fx_breaks. 0,5,30,0,3
					blend[-1,-2,LINE] multiply,$__brkstr
				fi
			#~ equalize. 100,$__cutmin,$__cutmax d
			normalize. $__cutmin,$__cutmax
			sharpen. 100
			spread. 0.7
		done

	blend[LINE,REND] ${__model{$__skmerge+1}},$__linestr
	fi
fi

normalize[REND] 0,255
keep[REND]

if $__post
	adjust_colors[REND] $__bri,$__con,$__gam,$__hue,$__sat
fi

if $dccires>0
	repeat $dccires
		fx_scale_dcci2x[REND] 1.15,5,1
	done
fi

if $__sketch
	if $__noistr>0 fx_noise $__noistr,0,11,1,0,50,50 fi

	# canvas effect
	if $cnvs>0
		+fill_color 255,255,255
		noise. 1000,2 to_gray.
		. .
		parallel " repeat 20 blur_x. 10 sharpen. 5  spread. 0.7 deform. 0.5 done ","
		 repeat 20 blur_y.. 10 sharpen.. 5  spread.. 0.7 deform.. 0.5 done "
		*. .. 
		n 0,255 
		+gradient. xy,1 -a[-2,-1] c 
		*. {$cnvs/100}
		warp[REND] [-1],3,1,1,1
	fi
fi

keep[REND]

if $com
	RENDW={0,w}
	RENDH={0,h}
	expand_y 35,0
	shift 0,35
	text "${1-45}",10,30,12,1,255
	text ${__mode{$__distmerge+1}}" "${__modep{$__plasmerge+1}}" "${__model{$__skmerge+1}},10,50,20,1,255
fi

watergmic_previewB :
gui_split_preview "watergmicB $*",${-3--1}
2 Likes

I get an error about “undefined label LINE”, but that could be something I did wrong. Will have more time to investigate at the weekend…

I have been getting weird errors with 3.2.2 too. I think this works fine with 3.2.1. I’ll see to that later too.

mmm It should be created line 177: [ORIG] nm. LINE

Also, i forgot to remove lw={LINE,w} which is not used anymore.

My version is 3.2.0 on Manjaro

It might be rolling_guidance renaming the image. It was fixed a few days ago. Try running gmic -update?

That has fixed it indeed, thanks. The output is very “organic” looking, well done! My only (minor) complaint is processing time makes it tricky to tweak correctly, but this could just be a case of get-a-faster-computer.

Ah thanks, quite a nice word to hear! I guess that was the goal?

Yes, imagine poor me when I started this as a one liner on the command line, not knowing much about gmic functions and filters… Lots of painting in the dark.
Also, that’s the reason I added the " processing resolution" slider. I was tired of waiting. And then I added all those little bypass checkboxes, and most sliders are bypassed if you set them to zero. So if you want you can go step by step.

And now I’m searching how to make it faster, I tried “parallel” but it breaks with frame_fuzzy…

Also, how should I add presets (buttons?) and have the sliders reflect the settings? Like a few predefined params that look good and different enough. Or maybe stuff like “show only lineart” etc.?
Well, so many things to learn.

Thanks for testing, you may be the only one hahaha :wink:

Taken from the template filter file:

#   A G'MIC command can set new values for each filter parameter, through the status (see command 'status').
#   To do so, the returned status must follow the syntax :
#   '{params1}{params2}{..}{paramsN}' where N must be exactly equal to the number of parameters
#   for the current filter. Optionnally, you can append to each {param} its visibility state suffix ( e.g: {param}_1 ).

Which more or less means your command must end with the status command (shortcut u), with correct params. I personally find it a bit painstaking to do, mainly because the string/macro handling can be hard to grasp. My usual method is to look for an existing filter and see what it does.

I think there’s a significant number of “lurkers” who never post, don’t be so sure!

Hard to grasp indeed…
I could make presets work but couldn’t make the status command work (sliders don’t refresh) … At some point it sorta worked : i couldn’t use the checkmarks anymore, they would uncheck immediately hahaha.
I looked at other scripts (@Reptorian 's Attractor for example) that have working status refresh but couldn’t replicate it and have it work. I’ll try to create a dummy filter to test this, or just drop it.

EDIT : I got it working a few minutes later: i removed “gui_split_preview” and status update started working. Got 2 presets working but now i need to find out how to have a “no preset” dropdown entry (it doesn’t work for now). I probably have to make a preset with the default params i guess.

2 Likes

Hi,
I don’t know why but something weird is happening with the presets…
Example :
select filter → OK, shows default settings preview
preset 1 → OK, shows preview
preset 2 → shows preview but then switches to previous preset
preset 3 → shows preview but then switches to preset 1 ?
preset 4 → OK, shows preview

I only have a if $preset==1... elif 2... elif 3... elif 4 ... fi structure and this doesn’t happen if i remove the “u” command to update the GUI.
It happens wether i put the status command in the preview script or the main script.

Can someone help me figure out what’s happening? Thanks.

Here is the code:

Code
#@gui WaterGmicB : watergmicB, watergmic_previewB(0)
#@gui : note = note("<small>Author: <i><a href="http://prawnsushi.free.fr">Prawnsushi</i></a>.      Latest Update: <i>2023/14/03</i>.</small>")
#@gui : sep = separator()
#@gui : Write settings on picture = bool(0)
#@gui : note = note("<small>Use original input image resolution or choose processing resolution.\nHigher Res is slower and not always better. </small>")
#@gui : Original Resolution = bool(1)
#@gui : Processing Resolution = int(1000,500,5000)
#@gui : Garagecoder's DCCI2x rescale (Post) = int(0,0,5)
#@gui : sep = separator()
#@gui : note = note("<small>Will revert to None after application so settings can be modified. </small>")
#@gui : - Presets = choice(0,"None","1 - Soft","2 - Cracked","3 - Black","4 - Faded Black")
#@gui : sep = separator()
#@gui : Pre-Process = bool(1)
#@gui : - Sharpening = int(0,0,500)
#@gui : - Blur = float(0,0,10)
#@gui : - Local normalization = float(0.5,0.3,3)
#@gui : Sloppiness = bool(1)
#@gui : - Distort = float(3,0,20)
#@gui : - Blur = float(3,0,50)
#@gui : - Blend Mode = choice(13,"add","and","average","blue","burn","darken","difference","divide","dodge","exclusion","grainextract","grainmerge","green","hardlight","hardmix","hue","interpolation","lighten","lightness","linearburn","linearlight","luminance","multiply","negation","or","overlay","pinlight","red","reflect","saturation","screen","shapeaverage","softburn","softdodge","softlight","stamp","subtract","value","vividlight","xor")
#@gui : - Strength = float(0.5,0.0,1.0)
#@gui : sep = separator()
#@gui : Watering = bool(1)
#@gui : - Smoothing = int(12,0,40)
#@gui : - Iterations = int(1,0,10)
#@gui : Fuzzy Frame Size = int(30,0,350)
#@gui : - Frame Blur = int(20,0,150)
#@gui : - Frame Strentgh = float(0.5,0,5)
#@gui : Plasma Seed = int(-1,-1,9999999)
#@gui : - Plasma Saturation = int(-100,-100,100)
#@gui : - Blend Mode = choice(23,"add","and","average","blue","burn","darken","difference","divide","dodge","exclusion","grainextract","grainmerge","green","hardlight","hardmix","hue","interpolation","lighten","lightness","linearburn","linearlight","luminance","multiply","negation","or","overlay","pinlight","red","reflect","saturation",screen","shapeaverage","softburn","softdodge","softlight","stamp","subtract","value","vividlight","xor")
#@gui : - Plasma Strength = float(0.3,0,1)
#@gui : sep = separator()
#@gui : Cracks = bool(1)
#@gui : Sharpening = int(150,0,500)
#@gui : - Shock Filter = int(1,0,1)
#@gui : Light Relief (0 means all off) = float(0.15,0,1)
#@gui : - Light2 = float(0.02,0,1)
#@gui : - Light3 = float(0.02,0,1)
#@gui : sep = separator()
#@gui : Sketch = bool(1)
#@gui : - Likeness = int(25,0,30)
#@gui : - Threshold Min = int(0,0,255)
#@gui : - Threshold Max = int(20,0,255)
#@gui : - Sketch strength = float(1,0,1)
#@gui : --- Messy lines = float(0.9,0,1)
#@gui : - Blend Mode = choice(22,"add","and","average","blue","burn","darken","difference","divide","dodge","exclusion","grainextract","grainmerge","green","hardlight","hardmix","hue","interpolation","lighten","lightness","linearburn","linearlight","luminance","multiply","negation","or","overlay","pinlight","red","reflect","saturation",screen","shapeaverage","softburn","softdodge","softlight","stamp","subtract","value","vividlight","xor")
#@gui : note = note("<small>Setting Sktech Strength to 0 disables Messy lines too.\n Messy lines uses 'Breaks' by David Tschumperlé.</small>")
#@gui : Noise = float(3,0,6)
#@gui : Canvas = float(0.3,0,1)
#@gui : sep = separator()
#@gui : Post-Process = bool(1)
#@gui : Mix Original Hue/Sat = float(0.5,0,1)
#@gui : Brightness = float(0,-100,100)
#@gui : Contrast = float(0,-100,100)
#@gui : Gamma = float(0,-100,100)
#@gui : Hue = float(0,-100,100)
#@gui : Saturation = float(0,-100,100)
#@gui : sep = separator()

watergmicB :

com,__origres,__procres,dccires,preset,__bst,__bstsharp,__bstblur,__locnorm,__filt,__dist,__distblur,__distmerge,__diststr,__wc,__bilsize,__bilrep,__fuzz,__fuzzblur,__fuzstr,__plsmseed,__plsmsat,__plasmerge,__plastr,__cracks,__sckrad,__sck,__lgtone,__lgttwo,__lgthree,__sketch,__sklike,__cutmin,__cutmax,__linestr,__brkstr,__skmerge,__noistr,cnvs,__post,__huestr,__bri,__con,__gam,__hue,__sat=$*

if $preset==1
com,__origres,__procres,dccires,preset,__bst,__bstsharp,__bstblur,__locnorm,__filt,__dist,__distblur,__distmerge,__diststr,__wc,__bilsize,__bilrep,__fuzz,__fuzzblur,__fuzstr,__plsmseed,__plsmsat,__plasmerge,__plastr,__cracks,__sckrad,__sck,__lgtone,__lgttwo,__lgthree,__sketch,__sklike,__cutmin,__cutmax,__linestr,__brkstr,__skmerge,__noistr,cnvs,__post,__huestr,__bri,__con,__gam,__hue,__sat=\
0,1,1000,0,1,1,0,0,3,1,20,10,10,0.5,1,12,2,127,42,0.365,-1,2,11,0.282,1,1,1,0.01,0.02,0.02,1,29,0,70,0.455,1,20,4,0.2,1,1,0,0,9,0,-7.2
elif $preset==2	com,__origres,__procres,dccires,preset,__bst,__bstsharp,__bstblur,__locnorm,__filt,__dist,__distblur,__distmerge,__diststr,__wc,__bilsize,__bilrep,__fuzz,__fuzzblur,__fuzstr,__plsmseed,__plsmsat,__plasmerge,__plastr,__cracks,__sckrad,__sck,__lgtone,__lgttwo,__lgthree,__sketch,__sklike,__cutmin,__cutmax,__linestr,__brkstr,__skmerge,__noistr,cnvs,__post,__huestr,__bri,__con,__gam,__hue,__sat=\
0,1,1000,0,2,0,0,0,0.3,1,3,3,13,0.5,1,12,1,0,20,0.5,-1,-100,37,0.755,1,500,1,0.027,0.02,0.02,1,25,0,220,1,0.9,22,6,0.3,1,1,0,0,31,0,0
elif $preset==3	com,__origres,__procres,dccires,preset,__bst,__bstsharp,__bstblur,__locnorm,__filt,__dist,__distblur,__distmerge,__diststr,__wc,__bilsize,__bilrep,__fuzz,__fuzzblur,__fuzstr,__plsmseed,__plsmsat,__plasmerge,__plastr,__cracks,__sckrad,__sck,__lgtone,__lgttwo,__lgthree,__sketch,__sklike,__cutmin,__cutmax,__linestr,__brkstr,__skmerge,__noistr,cnvs,__post,__huestr,__bri,__con,__gam,__hue,__sat=\
0,1,1000,0,3,1,0,0,2.3736,1,3,3,13,0.5,1,23,2,30,20,0.5,-1,-100,23,0.5,1,0,1,0.01,0.02,0.02,1,28,0,20,1,0.9,22,6,0,1,0,0,0,0,0,-100
elif $preset==4
com,__origres,__procres,dccires,preset,__bst,__bstsharp,__bstblur,__locnorm,__filt,__dist,__distblur,__distmerge,__diststr,__wc,__bilsize,__bilrep,__fuzz,__fuzzblur,__fuzstr,__plsmseed,__plsmsat,__plasmerge,__plastr,__cracks,__sckrad,__sck,__lgtone,__lgttwo,__lgthree,__sketch,__sklike,__cutmin,__cutmax,__linestr,__brkstr,__skmerge,__noistr,cnvs,__post,__huestr,__bri,__con,__gam,__hue,__sat=\
0,1,1000,0,4,1,308,0,2.3736,1,3,3,0,0.5,1,23,2,350,1,0.5,-1,100,10,1,1,0,1,0.2,0.02,0.02,1,29,0,9,0.9,1,22,6,0.12,1,0,0,0,13.4,0,-100
fi



preset=0

m "BlendMode : $""=__mode" BlendMode "add","and","average","blue","burn","darken","difference","divide","dodge","exclusion","grainextract","grainmerge","green","hardlight","hardmix","hue","interpolation","lighten","lightness","linearburn","linearlight","luminance","multiply","negation","or","overlay","pinlight","red","reflect","saturation","screen","shapeaverage","softburn","softdodge","softlight","stamp","subtract","value","vividlight","xor","error"

m "BlendModeP : $""=__modep" BlendModeP "add","and","average","blue","burn","darken","difference","divide","dodge","exclusion","grainextract","grainmerge","green","hardlight","hardmix","hue","interpolation","lighten","lightness","linearburn","linearlight","luminance","multiply","negation","or","overlay","pinlight","red","reflect","saturation","screen","shapeaverage","softburn","softdodge","softlight","stamp","subtract","value","vividlight","xor","error"

m "BlendModeL : $""=__model" BlendModeL "add","and","average","blue","burn","darken","difference","divide","dodge","exclusion","grainextract","grainmerge","green","hardlight","hardmix","hue","interpolation","lighten","lightness","linearburn","linearlight","luminance","multiply","negation","or","overlay","pinlight","red","reflect","saturation","screen","shapeaverage","softburn","softdodge","softlight","stamp","subtract","value","vividlight","xor","error"



#~ to_rgb
normalize 0,255
nm[0] ORIG
__ORIGW={0,w}
__ORIGH={0,h}

if !$__origres
	__res=$__procres,$__procres
	rr2d[ORIG] $__res,0,6
fi


if $__bst
	blur $__bstblur sharpen $__bstsharp normalize_local $__locnorm,$__locnorm
fi

[ORIG] nm. REND



if $__filt
[ORIG] nm. FILT
	local[FILT]
			apc "deform $__dist blur $__distblur"
	done
blend[REND,FILT] ${__mode{$__distmerge+1}},$__diststr
n[REND] 0,255
fi

if $__wc
	if $__plastr>0
	[ORIG] nm. PLAS
		local[PLAS]
			if $__plsmseed>-1
				srand $__plsmseed
			fi
			plasma 1,2,5
			adjust_colors 0,0,0,0,$__plsmsat
		done
	blend[REND,PLAS] ${__modep{$__plasmerge+1}},$__plastr
	fi
fi

if $__wc
	if $__fuzz>0
	[ORIG] nm. FUZZ
		local[FUZZ]
			fill_color 0,0,0
			spread {$__fuzz/2},{$__fuzz/2},0
			negate
			frame_fuzzy $__fuzz
			blur $__fuzzblur,0
			deform $__fuzz
			spread {$__fuzz/2},{$__fuzz/2}
			spread 10
			split c rm. . negate.  append c
				if $__fuzstr!=1
					mul $__fuzstr
				fi
		done
	blend_median[REND,FUZZ]
	channels 0,2
	normalize[REND] 0,255
	fi
fi


local[REND]
	if $__cracks
		if $__sckrad>0
			deform 1.5 sharpen $__sckrad,$__sck dilate_circ 1.5 sharpen $__sckrad,$__sck
		fi

		if $__lgtone>0
			repeat 3
				fx_light_relief $__lgtone,$__lgttwo,$__lgthree,0,0.2,50,50,20,0.084,0,0 blur 2 erode_circ 3 sharpen $__sckrad
			done
		fi
	fi

	if $__wc
		repeat $__bilrep
			deform 0.3 sharpen 80,0,10,10 bilateral $__bilsize,$__bilsize,$__bilsize,$__bilsize
		done
		sharpen 80,0,10,10 sharpen 50 normalize 0,255
	fi
done

if $__post
	if $__huestr>0
		[ORIG] nm. HUE
		[ORIG] nm. SAT
		move[ORIG] -1
		blend[HUE,REND] hue,$__huestr
		blend[SAT,REND] saturation,{$__huestr/3}
	fi
fi

if $__sketch
	if $__linestr>0
	[ORIG] nm. LINE
		local[LINE]
			deform 1.5 rolling_guidance {31-$__sklike},10,0.5
			gradient_norm negate
				if $__brkstr>0
					+fx_breaks. 0,5,30,0,3
					blend[-1,-2,LINE] multiply,$__brkstr
				fi
			normalize. $__cutmin,$__cutmax
			sharpen. 100
			spread. 0.7
		done

	blend[LINE,REND] ${__model{$__skmerge+1}},$__linestr
	fi
fi

normalize[REND] 0,255
keep[REND]

if $__post
	adjust_colors[REND] $__bri,$__con,$__gam,$__hue,$__sat
fi

if $dccires>0
	repeat $dccires
		fx_scale_dcci2x[REND] 1.15,5,1
	done
fi

if $__sketch
	if $__noistr>0 fx_noise $__noistr,0,11,1,0,50,50 fi
	# canvas effect
	if $cnvs>0
		+fc 255,255,255
		noise. 1000,2 to_gray.
		. .
		parallel " repeat 20 blur_x. 10 sharpen. 5  spread. 0.7 deform. 0.5 done ","
		 repeat 20 blur_y.. 10 sharpen.. 5  spread.. 0.7 deform.. 0.5 done "
		*. ..
	        keep[0,-1]
		n. 0,255
		+gradient. xy,1 -a[-2,-1] c
		*. {$cnvs/100}
		warp[REND] [-1],3,1,1,1
	fi
fi

keep[REND]

if $com
	RENDW={0,w}
	RENDH={0,h}
	expand_y 35,0
	shift 0,35
	text "${1-45}",10,30,12,1,255
	text ${__mode{$__distmerge+1}}" "${__modep{$__plasmerge+1}}" "${__model{$__skmerge+1}},10,50,20,1,255
fi

u "{"$com"}""{"$__origres"}""{"$__procres"}{"$dccires"}""{"0"}""{"$__bst"}""{"$__bstsharp"}""{"$__bstblur"}""{"$__locnorm"}""{"$__filt"}""{"$__dist"}""{"$__distblur"}"\
"{"$__distmerge"}""{"$__diststr"}""{"$__wc"}""{"$__bilsize"}""{"$__bilrep"}""{"$__fuzz"}""{"$__fuzzblur"}""{"$__fuzstr"}""{"$__plsmseed"}""{"$__plsmsat"}""{"$__plasmerge"}"\
"{"$__plastr"}""{"$__cracks"}""{"$__sckrad"}""{"$__sck"}""{"$__lgtone"}""{"$__lgttwo"}""{"$__lgthree"}""{"$__sketch"}""{"$__sklike"}""{"$__cutmin"}""{"$__cutmax"}""{"$__linestr"}"\
"{"$__brkstr"}""{"$__skmerge"}""{"$__noistr"}""{"$cnvs"}""{"$__post"}""{"$__huestr"}""{"$__bri"}""{"$__con"}""{"$__gam"}""{"$__hue"}""{"$__sat"}"

watergmic_previewB :

gui_split_preview "watergmicB $*"

@prawnsushi

I made some changes to code. Please compare with your earlier code, so that you can learn from it.

1. Removal of global variables. I only kept variables as global where necessary.
2. Better parameters adjustments. Setting back to 0 is not needed, when you change setting after changing preset, it'll be replaced with 0 automatically.
3. More readable code structure without changing style
Code
#@gui WaterGmicB : watergmicB, watergmic_previewB(0)
#@gui : note = note("<small>Author: <i><a href="http://prawnsushi.free.fr">Prawnsushi</i></a>.      Latest Update: <i>2023/14/03</i>.</small>")
#@gui : sep = separator()
#@gui : Write settings on picture = bool(0)
#@gui : note = note("<small>Use original input image resolution or choose processing resolution.\nHigher Res is slower and not always better. </small>")
#@gui : Original Resolution = bool(1)
#@gui : Processing Resolution = int(1000,500,5000)
#@gui : Garagecoder's DCCI2x rescale (Post) = int(0,0,5)
#@gui : sep = separator()
#@gui : - Presets = choice(0,"None","1 - Soft","2 - Cracked","3 - Black","4 - Faded Black")
#@gui : sep = separator()
#@gui : Pre-Process = bool(1)
#@gui : - Sharpening = int(0,0,500)
#@gui : - Blur = float(0,0,10)
#@gui : - Local normalization = float(0.5,0.3,3)
#@gui : Sloppiness = bool(1)
#@gui : - Distort = float(3,0,20)
#@gui : - Blur = float(3,0,50)
#@gui : - Blend Mode = choice(13,"add","and","average","blue","burn","darken","difference","divide","dodge","exclusion","grainextract","grainmerge","green","hardlight","hardmix","hue","interpolation","lighten","lightness","linearburn","linearlight","luminance","multiply","negation","or","overlay","pinlight","red","reflect","saturation","screen","shapeaverage","softburn","softdodge","softlight","stamp","subtract","value","vividlight","xor")
#@gui : - Strength = float(0.5,0.0,1.0)
#@gui : sep = separator()
#@gui : Watering = bool(1)
#@gui : - Smoothing = int(12,0,40)
#@gui : - Iterations = int(1,0,10)
#@gui : Fuzzy Frame Size = int(30,0,350)
#@gui : - Frame Blur = int(20,0,150)
#@gui : - Frame Strentgh = float(0.5,0,5)
#@gui : Plasma Seed = int(-1,-1,9999999)
#@gui : - Plasma Saturation = int(-100,-100,100)
#@gui : - Blend Mode = choice(23,"add","and","average","blue","burn","darken","difference","divide","dodge","exclusion","grainextract","grainmerge","green","hardlight","hardmix","hue","interpolation","lighten","lightness","linearburn","linearlight","luminance","multiply","negation","or","overlay","pinlight","red","reflect","saturation",screen","shapeaverage","softburn","softdodge","softlight","stamp","subtract","value","vividlight","xor")
#@gui : - Plasma Strength = float(0.3,0,1)
#@gui : sep = separator()
#@gui : Cracks = bool(1)
#@gui : Sharpening = int(150,0,500)
#@gui : - Shock Filter = int(1,0,1)
#@gui : Light Relief (0 means all off) = float(0.15,0,1)
#@gui : - Light2 = float(0.02,0,1)
#@gui : - Light3 = float(0.02,0,1)
#@gui : sep = separator()
#@gui : Sketch = bool(1)
#@gui : - Likeness = int(25,0,30)
#@gui : - Threshold Min = int(0,0,255)
#@gui : - Threshold Max = int(20,0,255)
#@gui : - Sketch strength = float(1,0,1)
#@gui : --- Messy lines = float(0.9,0,1)
#@gui : - Blend Mode = choice(22,"add","and","average","blue","burn","darken","difference","divide","dodge","exclusion","grainextract","grainmerge","green","hardlight","hardmix","hue","interpolation","lighten","lightness","linearburn","linearlight","luminance","multiply","negation","or","overlay","pinlight","red","reflect","saturation",screen","shapeaverage","softburn","softdodge","softlight","stamp","subtract","value","vividlight","xor")
#@gui : note = note("<small>Setting Sktech Strength to 0 disables Messy lines too.\n Messy lines uses 'Breaks' by David Tschumperlé.</small>")
#@gui : Noise = float(3,0,6)
#@gui : Canvas = float(0.3,0,1)
#@gui : sep = separator()
#@gui : Post-Process = bool(1)
#@gui : Mix Original Hue/Sat = float(0.5,0,1)
#@gui : Brightness = float(0,-100,100)
#@gui : Contrast = float(0,-100,100)
#@gui : Gamma = float(0,-100,100)
#@gui : Hue = float(0,-100,100)
#@gui : Saturation = float(0,-100,100)
#@gui : sep = separator()
#@gui : - Old Presets = choice(0,"None","1 - Soft","2 - Cracked","3 - Black","4 - Faded Black")_0

watergmicB :

com,origres,procres,dccires,preset,bst,bstsharp,bstblur,locnorm,filt,dist,distblur,distmerge,diststr,wc,bilsize,bilrep,fuzz,fuzzblur,fuzstr,plsmseed,plsmsat,plasmerge,plastr,cracks,sckrad,sck,lgtone,lgttwo,lgthree,sketch,sklike,cutmin,cutmax,linestr,brkstr,skmerge,noistr,cnvs,post,huestr,bri,con,gam,hue,sat=${1-46}

m "BlendMode : $""=__mode" BlendMode "add","and","average","blue","burn","darken","difference","divide","dodge","exclusion","grainextract","grainmerge","green","hardlight","hardmix","hue","interpolation","lighten","lightness","linearburn","linearlight","luminance","multiply","negation","or","overlay","pinlight","red","reflect","saturation","screen","shapeaverage","softburn","softdodge","softlight","stamp","subtract","value","vividlight","xor","error"

m "BlendModeP : $""=__modep" BlendModeP "add","and","average","blue","burn","darken","difference","divide","dodge","exclusion","grainextract","grainmerge","green","hardlight","hardmix","hue","interpolation","lighten","lightness","linearburn","linearlight","luminance","multiply","negation","or","overlay","pinlight","red","reflect","saturation","screen","shapeaverage","softburn","softdodge","softlight","stamp","subtract","value","vividlight","xor","error"

m "BlendModeL : $""=__model" BlendModeL "add","and","average","blue","burn","darken","difference","divide","dodge","exclusion","grainextract","grainmerge","green","hardlight","hardmix","hue","interpolation","lighten","lightness","linearburn","linearlight","luminance","multiply","negation","or","overlay","pinlight","red","reflect","saturation","screen","shapeaverage","softburn","softdodge","softlight","stamp","subtract","value","vividlight","xor","error"

#~ to_rgb
normalize 0,255
nm[0] ORIG
ORIGW={0,w}
ORIGH={0,h}

if !$origres
	res=$procres,$procres
	rr2d[ORIG] $res,0,6
fi

if $bst
	blur $bstblur sharpen $bstsharp normalize_local $locnorm,$locnorm
fi

[ORIG] nm. REND

if $filt
    [ORIG] nm. FILT
    local[FILT]
	apc "deform "$dist" blur "$distblur""
    done
    blend[REND,FILT] ${__mode{$distmerge+1}},$diststr
    n[REND] 0,255
fi

if $wc
	if $plastr>0
        [ORIG] nm. PLAS
		local[PLAS]
			if $plsmseed>-1
				srand $plsmseed
			fi
			plasma 1,2,5
			adjust_colors 0,0,0,0,$plsmsat
		done
        blend[REND,PLAS] ${__modep{$plasmerge+1}},$plastr
	fi
fi

if $wc
	if $fuzz>0
		[ORIG] nm. FUZZ
		local[FUZZ]
			fill_color 0,0,0
			spread {$fuzz/2},{$fuzz/2},0
			negate
			frame_fuzzy $fuzz
			blur $fuzzblur,0
			deform $fuzz
			spread {$fuzz/2},{$fuzz/2}
			spread 10
			split c rm. . negate.  append c
			if $fuzstr!=1
				mul $fuzstr
			fi
		done
		blend_median[REND,FUZZ]
		channels 0,2
		normalize[REND] 0,255
	fi
fi

local[REND]
	if $cracks
		if $sckrad>0
			deform 1.5 sharpen $sckrad,$sck dilate_circ 1.5 sharpen $sckrad,$sck
		fi

		if $lgtone>0
			repeat 3
				fx_light_relief $lgtone,$lgttwo,$lgthree,0,0.2,50,50,20,0.084,0,0 blur 2 erode_circ 3 sharpen $sckrad
			done
		fi
	fi

	if $wc
		repeat $bilrep
			deform 0.3 sharpen 80,0,10,10 bilateral $bilsize,$bilsize,$bilsize,$bilsize
		done
		sharpen 80,0,10,10 sharpen 50 normalize 0,255
	fi
done

if $post
	if $huestr>0
		[ORIG] nm. HUE
		[ORIG] nm. SAT
		move[ORIG] -1
		blend[HUE,REND] hue,$huestr
		blend[SAT,REND] saturation,{$huestr/3}
	fi
fi

if $sketch
	if $linestr>0
		[ORIG] nm. LINE
		local[LINE]
			deform 1.5 rolling_guidance {31-$sklike},10,0.5
			gradient_norm negate
			if $brkstr>0
				+fx_breaks. 0,5,30,0,3
				blend[-1,-2,LINE] multiply,$brkstr
			fi
			normalize. $cutmin,$cutmax
			sharpen. 100
			spread. 0.7
		done
		blend[LINE,REND] ${__model{$skmerge+1}},$linestr
	fi
fi

normalize[REND] 0,255
keep[REND]

if $post
	adjust_colors[REND] $bri,$con,$gam,$hue,$sat
fi

if $dccires>0
	repeat $dccires
		fx_scale_dcci2x[REND] 1.15,5,1
	done
fi

if $sketch
	if $noistr>0 fx_noise $noistr,0,11,1,0,50,50 fi
	# canvas effect
	if $cnvs>0
		+fc 255,255,255
		noise. 1000,2 to_gray.
		. .
		parallel " repeat 20 blur_x. 10 sharpen. 5  spread. 0.7 deform. 0.5 done ","
		 repeat 20 blur_y.. 10 sharpen.. 5  spread.. 0.7 deform.. 0.5 done "
		*. ..
	        keep[0,-1]
		n. 0,255
		+gradient. xy,1 -a[-2,-1] c
		*. {$cnvs/100}
		warp[REND] [-1],3,1,1,1
	fi
fi

keep[REND]

if $com
	RENDW={0,w}
	RENDH={0,h}
	expand_y 35,0
	shift 0,35
	text "${1-45}",10,30,12,1,255
	text ${__mode{$distmerge+1}}" "${__modep{$plasmerge+1}}" "${__model{$skmerge+1}},10,50,20,1,255
fi

watergmic_previewB :

__output=${1-46}
preset,old_preset={[$5,$47]}

if $preset==1
    variables=0,1,1000,0,1,1,0,0,3,1,20,10,10,0.5,1,12,2,127,42,0.365,-1,2,11,0.282,1,1,1,0.01,0.02,0.02,1,29,0,70,0.455,1,20,4,0.2,1,1,0,0,9,0,-7.2
elif $preset==2	
    variables=0,1,1000,0,2,0,0,0,0.3,1,3,3,13,0.5,1,12,1,0,20,0.5,-1,-100,37,0.755,1,500,1,0.027,0.02,0.02,1,25,0,220,1,0.9,22,6,0.3,1,1,0,0,31,0,0
elif $preset==3	
    variables=0,1,1000,0,3,1,0,0,2.3736,1,3,3,13,0.5,1,23,2,30,20,0.5,-1,-100,23,0.5,1,0,1,0.01,0.02,0.02,1,28,0,20,1,0.9,22,6,0,1,0,0,0,0,0,-100
elif $preset==4
    variables=0,1,1000,0,4,1,308,0,2.3736,1,3,3,0,0.5,1,23,2,350,1,0.5,-1,100,10,1,1,0,1,0.2,0.02,0.02,1,29,0,9,0.9,1,22,6,0.12,1,0,0,0,13.4,0,-100
fi

if $preset
    if $preset==$old_preset
        if [$__output]!=[$variables]
            __output=${1-4},0,${6-46}
        fi
    else
        __output=$variables
    fi
fi

com,origres,procres,dccires,preset,bst,bstsharp,bstblur,locnorm,filt,dist,distblur,distmerge,diststr,wc,bilsize,bilrep,fuzz,fuzzblur,fuzstr,plsmseed,plsmsat,plasmerge,plastr,cracks,sckrad,sck,lgtone,lgttwo,lgthree,sketch,sklike,cutmin,cutmax,linestr,brkstr,skmerge,noistr,cnvs,post,huestr,bri,con,gam,hue,sat=$__output

gui_split_preview "watergmicB $__output"

u "{"$com"}""{"$origres"}""{"$procres"}""{"$dccires"}""{"$preset"}""{"$bst"}""{"$bstsharp"}""{"$bstblur"}""{"$locnorm"}""{"$filt"}""{"$dist"}""{"$distblur"}"\
"{"$distmerge"}""{"$diststr"}""{"$wc"}""{"$bilsize"}""{"$bilrep"}""{"$fuzz"}""{"$fuzzblur"}""{"$fuzstr"}""{"$plsmseed"}""{"$plsmsat"}""{"$plasmerge"}"\
"{"$plastr"}""{"$cracks"}""{"$sckrad"}""{"$sck"}""{"$lgtone"}""{"$lgttwo"}""{"$lgthree"}""{"$sketch"}""{"$sklike"}""{"$cutmin"}""{"$cutmax"}""{"$linestr"}"\
"{"$brkstr"}""{"$skmerge"}""{"$noistr"}""{"$cnvs"}""{"$post"}""{"$huestr"}""{"$bri"}""{"$con"}""{"$gam"}""{"$hue"}""{"$sat"}""{"$preset"}"

Thanks, it’s a lot cleaner that way indeed. Hope you didn’t laugh too much though.
Didn’t think of storing the presets as strings… that was some huge waste of time. And now it seems so damn obvious!

Well, since the filter is so slow, i intended to use parallel later though, so i knew i would need the globals.

Thanks, that’s another cool part! I hope i’ll remember all that (i have a very bad memory).

I have replicated your changes in my own .gmic file(didn’t just copy/paste) but I still have some problems though: When i switch from preset to preset (1 -2 -3…) they start to be applied twice in the preview. That’s strange. I must have missed something somewhere. Maybe because i kept the vars as globals?
Thanks for the help, and your time :wink:

1 Like

If you really want to find the bottleneck, I’d recommend to use text, and tic/toc command. You can retrieve time found with tic toc with ${}. There may be some faster way of doing things with convolve from the brief look.

1 Like

Once again, thanks for the tips!
I’ll try to see what i can do.

One last thing, you’re missing a "" somewhere here. So, just in case you’re missing this change.

Yeah i saw that, between procres and dccires. Which is strange anyway because i use search and replace to do this, same thing for globals ($ to $__).
And it should be dccirep, it’s either a typo or a failure due to the flu, or fatigue. Will change that.

I tried coy/pasting your code (the whole thing) and it also does the double application on presets 2 & 3. Don’t know why it’s happening but it doesn’t when i comment out the status command. But obviously the GUI doesn’t update anymore. Actually i think the status update should be automatic, without coding it, but maybe it would cause problems in some cases.

Btw, i wanted to ask: which text editor do you (or others) use? I’m trying to find a good color scheme for G’mic scripts, i use Geany or Mousepad on Linux, and setting filetype to “shell script”. Don’t know if someone made one.

Another dumb question : is it possible to align multiple buttons or checkboxes on the same line? Could save some space.

I do think double application is a bug, but at the same time, it can be used to find bugs too because of double application. C-koi should fix this while adding a checkmark for developers.

You’ll find that there is no agreed text editor.

Reptorian use KDE Kate and almost never, Notepad++.
David use Vim or Emacs. (Not sure which).
Garagecoder use Notepad++ or Geany.
Samj use Notepad++.

You should try all of them. I’d recommend testing neovim as well.

@garagecoder , @David_Tschumperle , @samj please confirm.

I wish… There are some cool ideas I have with this in mind.