Trying to make my 1st "pipeline filter"

@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.

The term may be misleading. It’s not like the filter is applied twice, but like the 2nd application replaces the 1st. I use random deformations so it’s noticeable.

I know Kate but there will be so many dependencies for my Ubuntu arm xfce VM. My MacBook will fill up. Also I don’t know if there is a notepad++ for Linux. Used it around 15-20 years ago on windows though, if I’m not mistaken.
Geany is cool though, but I need better syntax highlighting. Gotta test them all now haha.

And this makes me think one could use an INT slider for presets too, if one doesn’t care about description (1,2,3,4…). Less clutter too. I also wish the separators could be clickable to fold/unflod the params in between them by default. A bit like code folding in Geany.

Thanks, found out fx_breaks and rolling_guidance ( for Sketch ) were taking a lot of time.
tests on a 3100x4400px png :
Changed fx_breaks. 0,5,30,0,3 (9s) to fx_breaks. 1,5,30,0,3 (0.5s!!!).
Changed rolling_guidance (25),10,0.5 (4,3s) to rolling_guidance (25),20,0 (2,8s)

Maybe i’ll use something else instead of rolling_guidance.

1 Like

Correct, mostly Geany. Depending on the size of the gmic file I set “document type” (for highlighting) to shell, makefile, or even “R”.

Here is an update for this. The preview is a bit faster now. You can see the processing time with the checkmark. The filter takes approx 40 seconds on a 5800 x 3500px picture:


Added a few things here and there…
I still have the “double application” bug in the preview (only with presets), it’s only really annoying with the “Roll the DIce!” preset, which randomizes a lot of things, and is quite slow. Didn’t have the time to look into it, I guess i’m saving it for last! :sweat_smile:
BTW, i had to remove almost all of the floor(u(min-max)) to convert floats to integers because it was so damn slow (Now these sliders don’t update with status, but that’s ok for now)… Is there any way to get random integers faster, using “u”?

Code 25/04/23

#@gui Uglify : uglify, uglify_preview(0)
#@gui : note = note("<small>Author: <i><a href="http://prawnsushi.free.fr">Prawnsushi</i></a>.      Latest Update: <i>2023/25/04</i>.</small>")
#@gui : sep = separator()
#@gui : Write settings on picture = int(0,0,1)
#@gui : note = note{"<small>Use original input image resolution or choose processing resolution (i.e. Half res + Upscale 2x). Beware: Preview lies.</small>"}
#@gui : Original Resolution = int(1,0,1)
#@gui : Processing Resolution = int(1000,500,5000)
#@gui : Upscale 2x (Iterations) = _int(0,0,5)
#@gui : sep = separator()
#@gui : - Presets = choice(0,"Default","1 - From Scratch","2 - Soft","3- Cracked","4 - Black","5 - Faded Black")
#@gui : sep = separator()
#@gui : Pre-Process = int(1,0,1)
#@gui : - Sharpening = int(0,0,500)
#@gui : - Blur = float(0,0,10)
#@gui : - Local normalization = float(0,0,3)
#@gui : sep = separator()
#@gui : Sloppiness = int(1,0,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 = int(1,0,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 ( -1 : Random ) = int{-1,-1,999999}
#@gui : - Plasma Saturation = int(-100,-100,100)
#@gui : - Plasma Blur = float(0,0,50)
#@gui : - Blend Mode = choice(7,"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.6,0,1)
#@gui : sep = separator()
#@gui : Cracks = int(1,0,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 = int(1,0,1)
#@gui : - Likeness = int(25,0,30)
#@gui : - Threshold Min = int(0,0,255)
#@gui : - Threshold Max = int(255,0,255)
#@gui : - Thickness = int(2,0,40)
#@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 : sep = separator()
#@gui : Noise = float(3,0,6)
#@gui : Canvas = float(0.3,0,1)
#@gui : Canvas style = int(0,0,100)
#@gui : Color = color(255,255,255,0)
#@gui : sep = separator()
#@gui : Post-Process = int(1,0,1)
#@gui : Emboss = float(1.5,0,5)
#@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,"Default","1 - From Scratch","2 -Soft","3 - Cracked","4 - Black","5 - Faded Black")_0

uglify :

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

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_rgba

nm[0] ORIG
ORIGW={0,w}
ORIGH={0,h}

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

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

[ORIG] nm. REND

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

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

#~ if $wc
  if $fuzz
    [ORIG] nm. FUZZ
    local[FUZZ]
      fc 0,0,0
      negate
      frame_fuzzy $fuzz
      if $fuzzblur blur $fuzzblur,0 fi
        deform $fuzz
        spread {$fuzz/2},{$fuzz/2}
        split c rm. . negate.  a c
      if $fuzstr!=1
        mul $fuzstr
      fi
    done
    blend_median[REND,FUZZ]
  fi
fi

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

    if $lgtone
      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
    if $bilrep>0
      repeat $bilrep
        deform {0,w/1000}
        bilateral $bilsize,$bilsize,$bilsize,$bilsize
      done
    fi
  fi
done

if $post
  if $huestr
    [ORIG] nm. HUE
    [ORIG] nm. SAT
    b[HUE,SAT] 5
    blend[HUE,REND] hue,$huestr
    blend[SAT,REND] saturation,{$huestr}
  fi
fi

if $sketch
  if $linestr>0
    [ORIG] nm. LINE

    local[LINE]

      r 50%,50%,1,6
      deform {0,w/2000}
      rolling_guidance {31-$sklike},20,0
      r 200%,200%,1,6
      gradient_norm negate

      if $brkstr>0
        +fx_breaks. 1,5,20,0,3
        blend[-1,-2,LINE] multiply,$brkstr
      fi
      if $linthick erode_circ. $linthick spread {$linthick/10} dilate_circ. 3 fi
      n. $cutmin,$cutmax
      sharpen. 100
      spread. 1.7
    done
    split[REND] c
    a[1,2,3] c
    blend[LINE,REND] ${__model{$skmerge+1}},$linestr
    a[REND] [-1],c
  fi
fi

normalize[REND] 0,255
keep[REND]

if $post
  usrmod=$bri,$con,$gam,$hue,$sat
  if [$usrmod]!=[0,0,0,0,0]
  adjust_colors[REND] $bri,$con,$gam,$hue,$sat
  fi
fi

if $dccires
  repeat $dccires
    r 200%,200%
  done
fi

  if $noistr
  fx_noise $noistr,0,11,1,0,50,50
  fi
  if $cnvs
    +fc 255,255,255
    noise. 50,2
    to_gray.
    . .
    if $cvmod
      __wat=$cvmod,1,45
    else
      __wat=0,0,0
    fi
    parallel " blur_x. 30 water. $__wat  sharpen. 50  spread. 1.7 "," blur_y.. 30  water.. $__wat sharpen.. 50 spread.. 1.7  "
    *. ..
    keep[0,-1] n. 0,255
    +gradient. xy,1 -a[-2,-1] c
    *. {$cnvs/100}
    warp[REND] .,3,1,1,1
  fi

+fc[REND] $cvr,$cvg,$cvb,$cva
move[-1] 0
blend[0,REND] alpha
nm[0] REND
keep[REND]

if $post
  if $emboss
  fx_emboss_relief 5,0,0.5,$emboss,1,0,1
  fi
fi

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



uglify_preview :

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

if $preset==1
  variables=0,1,1000,0,1,0,0,0,0,0,0,0,13,0,0,0,0,0,0,0,-1,-100,0,23,0,0,0,0,0,0,0,0,0,0,255,2,0,0,22,0,0,0,255,255,255,255,0,0,0,0,0,0,0,0
elif $preset==2
  variables=0,1,1000,0,2,1,0,2,0,1,20,10,7,0.4,1,12,2,127,42,0.365,-1,0,0,11,0.5,1,1,0,0.01,0.02,0.02,1,30,0,255,5,1,0,22,6,0,0,255,255,255,255,1,0,0.8,0,0,9,0,0
elif $preset==3
  variables=0,1,1000,0,3,0,0,0,0.3,1,3,3,13,0.5,1,12,1,0,20,0.5,-1,-100,0,37,0.755,1,500,1,0.027,0.02,0.02,1,25,0,255,2,1,0.9,22,6,0.3,0,255,255,255,255,1,1.5,1,0,0,31,0,0
elif $preset==4
  variables=0,1,1000,0,0,1,0,0,2.3736,1,3,3,13,0.5,1,23,2,30,20,0.5,-1,80,0,7,0.2,1,0,1,0.01,0.02,0.02,1,28,0,255,2,1,0.9,22,6,1,11,255,255,255,255,1,1.1,0,0,0,-30,0,-100
elif $preset==5
  variables=0,1,1000,0,0,1,308,0,2.3736,1,3,3,0,0.5,1,23,2,350,1,0.5,-1,100,0,10,1,1,0,1,0.2,0.02,0.02,1,29,0,255,2,0.9,1,22,6,1,19,134,110,71,255,1,1,0,0,0,13.4,0,-100
fi

if $preset
  if $preset==$old_preset
    if [$__output]!=[$variables]
      __output=${1-4},0,${6--2}
    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,plsmblur,plasmerge,plastr,cracks,sckrad,sck,lgtone,\
lgttwo,lgthree,sketch,sklike,cutmin,cutmax,linthick,linestr,brkstr,skmerge,\
noistr,cnvs,cvmod,cvr,cvg,cvb,cva,post,emboss,huestr,\
bri,con,gam,hue,sat=$__output

uglify $__output

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


2 Likes

That is quite surprising.
This shouldn’t take a lot of time.

For me (ubuntu), I have for instance:

foo :
  sp lena,1024
  tic
  +f ">floor(i/10)"
  toc
  rm.
  tic
  +f ">round(i/10)"
  toc
  rm.

$ gmic foo
[gmic]-0./ Start G'MIC interpreter.
[gmic]-2./foo/ Elapsed time: 0.083 s.
[gmic]-2./foo/ Elapsed time: 0.09 s.

So computing the floor value for 1024x1024=1048576 values takes 83 ms.

Well, i have around 40-45 random values (u). Don’t know if that counts?
Probably half are integers so i have to use floor. But then this preset was very slow to render. I’m not sure what causes this so i removed the floor command and it seems a bit faster. And this double application drives me crazy, sometimes :crazy_face:.

Here are my results:

$ gmic sp lena,1024 tic +f ">floor(i/10)" toc rm. tic +f ">round(i/10)" toc rm.
[gmic]-0./ Start G'MIC interpreter.
[gmic]-1./ Input sample image 'lena' (1 image 1024x1024x1x3).
[gmic]-1./ Initialize timer.
[gmic]-1./ Fill image [0] with expression '>floor(i/10)'.
[gmic]-2./ Elapsed time: 0.041 s.
[gmic]-2./ Remove image [1] (1 image left).
[gmic]-1./ Initialize timer.
[gmic]-1./ Fill image [0] with expression '>round(i/10)'.
[gmic]-2./ Elapsed time: 0.051 s.
[gmic]-2./ Remove image [1] (1 image left).
[gmic]-1./ Display image [0] = 'lena'.

Maybe it’s not what causes the slowdown then.
I guess my script doesn’t like random floats like " 0.138653263528759" ?
Runs to https://gmic.eu/reference/mathematical_expressions.html

Updated script here : Trying to make my 1st "pipeline filter" - #32 by prawnsushi

Here are a few possibilities for this Frankenscript :man_zombie:
Original picture from Unsplash : Adnan Mistry





2 Likes

I like Black & White :

Originals from Unsplash :

Patrick Baum

Icons8 Team

From nothing to… noodling :

With Alpha channel :

1 Like