Reptorian G'MIC Filters

Hope your surgery went well.

I am still not sure what you are asking. I would do this. (Guess it doesn’t answer your question since I am using n).

r={[im,iM]} (-1,-1,-1;1,1,1) +convolve[0] [1],1,1 +convolve[0] [1] n $r

convolve[0] [1],1,1

convolve[0] [1]

It did went well. Recovered fully, and need rest.

#csmode=0=RGB8#
#csmode=1=RYB8#
#csmode=2=CMY8#
#csmode=3=CMYK8#
#csmode=4=HSI8#
#csmode=5=HSV8#
#csmode=6=LAB8#
#csmode=7=LCH8#
#csmode=8=LAB8#
#csmode=9=LCH8#
#csmode=10=YIQ8#
#csmode=11=YUV8#
#csmode=12=XYZ8#
lcmod_1=1
lcmod_2=2
lcmod_3=3
lcmod_4=4
cs=2
alp=0
diag=1
interpolation=1
subpixel=0
tc={$cs!=3?3+$alp:4}
iw={w}
ih={h}
f 0 r {($subpixel+1)*100}%,{($subpixel+1)*100}%,100%,$tc
1,1,1,$tc
l. repeat $tc sh[0] $> done ti=$! 
f[1] $lcmod_1
f[2] $lcmod_2
f[3] $lcmod_3
if $tc==4 f[4] $lcmod_4 fi 
remove_duplicates[^0]
if $!!=$ti v + error "Duplicate channel numbers detected" v - fi
k[0]
endl

I’m trying to use [1] image channel value as identifier for shared channels on [0]. Is that possible?

My attempt is this:

repeat $tc sh[1] $> sh[0] {ia#-2} rm.. done
f[4] x

Another attempt - This one works

repeat $tc sh[1] $> done
repeat $tc sh[0] {ia#($>+2)-1} done
rm[1-{1+$tc}]

Okay, I got something. I’m not sure if I’m doing this right since I am recovering from all that has happened. Let me know if I’m doing this right since I’m still slower than I used to be.

#@cli rep_colmt: (eq. to rep_color_modulo_texture)
rep_colmt: rep_color_modulo_texture $*
#@cli rep_color_modulo_texture: 0<=_modulo_method<=5,_maxmod>0,_endmodvalue>0,_negate_mod = { 0=normal | 1 = inverted },\
0<=_modulo_method<=5,_maxmod>0,_endmodvalue>0,_negate_mod= { 0=normal | 1=inverted },\
0<=_modulo_method<=5,_maxmod>0,_endmodvalue>0,_negate_mod= { 0=normal | 1=inverted },\
0<=_modulo_method<=5,_maxmod>0,_endmodvalue>0,_negate_mod= { 0=normal | 1=inverted },\
_diagonal_flip= { 0=not flipped | 1 = flipped },_subpixel_processing_level>0,0<=_interpolation<=5,0<=_colorspacemode<=12,_contain_alpha= { 0=no_alpha | 1=alpha },\
0<=_channel_num<=4,0<=_channel_num<=4,0<=_channel_num<=4,0<=_channel_num<=
#@cli: Inspired by MadJik's Color Modulo Texture for Paint.NET, this is a extension of that filter converted into G'MIC form. New features is being able to change color space, allow alpha, anti-aliasing...
rep_color_modulo_texture:
repeat $! l[$>]
lcmod_1=$22
lcmod_2=$23
lcmod_3=$24
lcmod_4=$25
cs=$20
alp=$21
diag=$17
interpolation=$19
subpixel=$18
subpixel+=1
tc={$cs!=3?3+$alp:4}
iw={w}
ih={h}
f 0 r {$interpolation?$subpixel*100:100}%,{$interpolation?$subpixel*100:100}%,100%,$tc
($lcmod_1,$lcmod_2,$lcmod_3,$lcmod_4)
l. s x ti=$! remove_duplicates if $!!=$ti v + error "Invalid channel inputs!" v - fi a x endl
repeat $tc sh[0] {i(#1,$>,0)} done rm[1]
f[1] x/$subpixel modf[1] $1,$2,{$3/$2} if $4 negate[1] fi
f[2] y/$subpixel modf[2] $5,$6,{$7/$6} if $8 negate[2] fi
f[3] (!$diag?x+y:abs(x-y))/$subpixel modf[3] $9,$10,{$11/$10} if $12 negate[3] fi
if $tc==4 f[4] (!$diag?abs(x-y):x+y)/$subpixel modf[4] $13,$14,{$15/$14} if $16 negate[4] fi fi
k[0]
if $interpolation&&($subpixel>=2) r $iw,$ih,100%,100%,$interpolation fi
if $cs!=3
sh 0,2
if $cs==1 ryb2rgb.
elif $cs==2 cmy2rgb.
elif $cs==4 hsi82rgb.
elif $cs==5 hsl82rgb.
elif $cs==6 hsv82rgb.
elif $cs==7 lab82rgb.
elif $cs==8 lch82rgb.
elif $cs==9 yiq8rgb.
elif $cs==10 yuv82rgb.
elif $cs==11 yuv82rgb.
elif $cs==12 xyz82rgb.
fi
rm.
else
cmyk2rgb
fi
endl done

This is basically the color modulo texture converted into cli form, and uses shared. So, it’s much more efficient than the current implementation. I will be adding skip soon anyway, but it looks good, right?

After dealing with my own code, I don’t think I have energy to spare to review your work. It does look cleaner than before, at least you have that.

Oh, a value got cut off.

1 Like

@Joan_Rake1, @David_Tschumperle

I would like to update my g’mic fork, but can’t seem to figure out how to do that. It been a while, how do I do that?

I see this - This branch is 1 commit ahead, 9 commits behind dtschump:master. And when I do it, I seem to get a pull request into @David_Tschumperle page, and ended up closing it.

I have been reading up on that. In the GUI, it is as simple as reversing the pull request. I mean choosing the opposite for the left and right drop down menus. Not as clean as git though since it will be logged as a commit.

And exactly how do I do that? I know I have did that before, but it seem rather confusing as I always end up on @David_Tschumperle page.


EDIT: I just did it, but I don’t like to go through loops.

Ok, now I’m close to done with just one issue.

@cli rep_colmt: (eq. to rep_color_modulo_texture)
rep_colmt: rep_color_modulo_texture $*
#@cli rep_color_modulo_texture: 0<=_modulo_method<=5,_maxmod>0,_endmodvalue>0,0<=_angle<=360,_value_shift>0,_centered= { 0=Not centered | 1=Centered },_negate_mod= { 0=normal | 1=inverted },_normalize_bool= { 0=Do not Normalize | 1=Normalize },\
0<=_modulo_method<=5,_maxmod>0,_endmodvalue>0,0<=_angle<=360,_value_shift>0,_centered= { 0=Not centered | 1=Centered },_negate_mod= { 0=normal | 1=inverted },_normalize_bool= { 0=Do not Normalize | 1=Normalize },\
0<=_modulo_method<=5,_maxmod>0,_endmodvalue>0,0<=_angle<=360,_value_shift>0,_centered= { 0=Not centered | 1=Centered },_negate_mod= { 0=normal | 1=inverted },_normalize_bool= { 0=Do not Normalize | 1=Normalize },\
0<=_modulo_method<=5,_maxmod>0,_endmodvalue>0,0<=_angle<=360,_value_shift>0,_centered= { 0=Not centered | 1=Centered },_negate_mod= { 0=normal | 1=inverted },_normalize_bool= { 0=Do not Normalize | 1=Normalize },\
_diagonal_flip= { 0=not flipped | 1 = flipped },_subpixel_processing_level>0,0<=_interpolation<=5,0<=_colorspacemode<=12,_contain_alpha= { 0=no_alpha | 1=alpha },\
0<=_channel_num<=4,0<=_channel_num<=4,0<=_channel_num<=4,0<=_channel_num<=4
#@cli: Inspired by MadJik's Color Modulo Texture for Paint.NET, this is a extension of that filter converted into G'MIC form. New features is being able to change color space, allow alpha, anti-aliasing...
rep_color_modulo_texture:
repeat $! l[$>]
lcmod_1=$38
lcmod_2=$39
lcmod_3=$40
lcmod_4=$41
cs=$36
alp=$37
diag=$33
interpolation=$35
subpixel=$34
subpixel+=1
tc={$cs!=3?3+$alp:4}
iw={w}
ih={h}
maxv={max(w,h)}
sd={min(w,h)/max(w,h)}
sx={w<h?$sd:1}
sy={h<w?$sd:1}
msx={.5*$sx}
msy={.5*$sy}
center=1
f 0 r {$interpolation?$subpixel*100:100}%,{$interpolation?$subpixel*100:100}%,100%,$tc
($lcmod_1,$lcmod_2,$lcmod_3,$lcmod_4)
l. 
    s x ti=$! remove_duplicates 
    if $!!=$ti v + error "Invalid channel inputs!" v - fi a x 
endl
repeat $tc sh[0] {i(#1,$>,0)} done rm[1]
f[1] ang=pi*($4/180);ix=(x/w)-.5;iy=(y/h)-.5;ix*=$sx;iy*=$sy;IX=ix*cos(ang)-iy*sin(ang);IX+=!$6?$msx;IX*=$maxv;ix=IX;ix/$subpixel abs[1] modf[1] $1,$2,{$3/$2} 
    if {$8&&($1<2)} +[1] {$3<$2?$3} fi 
    if $7 negate[1] fi 
    temp={im#1} -[1] $temp modf[1] 4,{iM#1},$5 +[1] $temp
f[2] ang=pi*($12/180);ix=(x/w)-.5;iy=(y/h)-.5;ix*=$sx;iy*=$sy;IY=ix*sin(ang)+iy*cos(ang);IY+=!$14?$msx;IY*=$maxv;iy=IY;iy/$subpixel abs[2] modf[2] $9,$10,{$11/$10} 
    if {$16&&($9<2)} +[2] {$11<$10?$11} fi 
    if $15 negate[2] fi 
    temp={im#2} -[2] $temp modf[2] 4,{iM#2},$13 +[2] $temp 
f[3] ang=pi*($20/180);ix=(x/w)-.5;iy=(y/h)-.5;ix*=$sx;iy*=$sy;IX=ix*cos(ang)-iy*sin(ang);IY=ix*sin(ang)+iy*cos(ang);IX+=!$22?$msx;IX*=$maxv;IY+=!$22?$msx;IY*=$maxv;ix=IX;iy=IY;($diag?(abs(ix)+abs(iy)):abs(abs(ix)-abs(iy)))/$subpixel modf[3] $17,$18,{$19/$18} 
    if {$24&&($17<2)} +[3] {$19<$18?$19} fi 
    if $23 negate[3] fi 
    temp={im#3} -[3] $temp modf[3] 4,{iM#3},$21 +[3] $temp 
if $tc==4 
    f[4] ang=pi*($28/180);ix=(x/w)-.5;iy=(y/h)-.5;ix*=$sx;iy*=$sy;IX=ix*cos(ang)-iy*sin(ang);IY=ix*sin(ang)+iy*cos(ang);IX+=!$30?$msx;IX*=$maxv;IY+=!$30?$msx;IY*=$maxv;ix=IX;iy=IY;(!$diag?(abs(ix)+abs(iy)):abs(abs(ix)-abs(iy)))/$subpixel modf[4] $25,$26,{$27/$26} 
    if {$32&&($25<2)} +[4] {$27<$26?$27} fi  
    if $31 negate[4] fi 
    temp={im#4} -[4] $temp modf[4] 4,{iM#4},$29 +[4] 
fi
k[0]
if $interpolation&&($subpixel>=2) r $iw,$ih,100%,100%,$interpolation fi
if $cs!=3
    if $cs!=0 sh 0,2 fi
    if $cs==1 ryb2rgb.
    elif $cs==2 cmy2rgb.
    elif $cs==4 hsi82rgb.
    elif $cs==5 hsl82rgb.
    elif $cs==6 hsv82rgb.
    elif $cs==7 lab82rgb.
    elif $cs==8 lch82rgb.
    elif $cs==9 yiq8rgb.
    elif $cs==10 yuv82rgb.
    elif $cs==11 yuv82rgb.
    elif $cs==12 xyz82rgb.
    fi
    if $cs!=0 rm. fi
else
    cmyk2rgb
fi
endl done

The following works

 rep_color_modulo_texture 3,255,64,0,0,1,0,0,3,255,64,0,0,1,0,0,3,255,64,0,0,1,0,0,3,255,64,0,0,1,0,0,1,1,3,3,1,0,1,2,3

But, rep_colmt gets me a funny message about cli, and I don’t know how to fix that.

image

Also, subpixel doesn’t play like how I wanted the result to. So…

EDIT: Never mind about subpixel. Removing it on f[x] series solved it.

Ok, some progress on Color Modulo Here (There are some bugs which I haven’t figured out):

#@cli rep_colmt: (eq. to rep_color_modulo_texture)
rep_colmt: rep_color_modulo_texture $*
#@cli rep_color_modulo_texture: 0<=_modulo_method<=5,_maxmod>0,_endmodvalue>0,0<=_angle<=360,_value_shift>0,_centered= { 0=Not centered | 1=Centered },_negate_mod= { 0=normal | 1=inverted },_normalize_bool= { 0=Do not Normalize | 1=Normalize }, \
# 0<=_modulo_method<=5,_maxmod>0,_endmodvalue>0,0<=_angle<=360,_value_shift>0,_centered= { 0=Not centered | 1=Centered },_negate_mod= { 0=normal | 1=inverted },_normalize_bool= { 0=Do not Normalize | 1=Normalize }, \
# 0<=_modulo_method<=5,_maxmod>0,_endmodvalue>0,0<=_angle<=360,_value_shift>0,_centered= { 0=Not centered | 1=Centered },_negate_mod= { 0=normal | 1=inverted },_normalize_bool= { 0=Do not Normalize | 1=Normalize }, \
# 0<=_modulo_method<=5,_maxmod>0,_endmodvalue>0,0<=_angle<=360,_value_shift>0,_centered= { 0=Not centered | 1=Centered },_negate_mod= { 0=normal | 1=inverted },_normalize_bool= { 0=Do not Normalize | 1=Normalize }, \
# _diagonal_flip= { 0=not flipped | 1 = flipped },_subpixel_processing_level>0,0<=_interpolation<=5,0<=_colorspacemode<=11,_contain_alpha= { 0=no_alpha | 1=alpha }, \
# 0<=_channel_num<=4,0<=_channel_num<=4,0<=_channel_num<=4,0<=_channel_num<=4
#@cli: Inspired by MadJik's Color Modulo Texture for Paint.NET, this is a extension of that filter converted into G'MIC form. New features is being able to change color space, allow alpha, anti-aliasing...
rep_color_modulo_texture:
repeat $! l[$>]
lcmod_1=$38
lcmod_2=$39
lcmod_3=$40
lcmod_4=$41
cs=$36
alp=$37
diag=$33
interpolation=$35
subpixel=$34
subpixel+=1
tc={$cs!=3?3+$alp:4}
iw={w}
ih={h}
maxv={max(w,h)}
sd={min(w,h)/max(w,h)}
sx={w<h?$sd:1}
sy={h<w?$sd:1}
msx={.5*$sx}
msy={.5*$sy}
center=1
f 0 r {$interpolation?$subpixel*100:100}%,{$interpolation?$subpixel*100:100}%,100%,$tc
($lcmod_1,$lcmod_2,$lcmod_3,$lcmod_4)
l. 
    s x ti=$! remove_duplicates 
    if $!!=$ti v + error "Invalid channel inputs!" v - fi a x 
endl
repeat $tc sh[0] {i(#1,$>,0)} done rm[1]
f[1] ang=pi*($4/180);ix=(x/w)-.5;iy=(y/h)-.5;ix*=$sx;iy*=$sy;IX=ix*cos(ang)-iy*sin(ang);IX+=!$6?$msx;IX*=$maxv;ix=IX;ix abs[1] modf[1] $1,$2,{$3/$2} 
    if {$8&&($1<2)} +[1] {$3<$2?$3} fi 
    if $7 negate[1] fi 
    temp={im#1} -[1] $temp modf[1] 4,{iM#1},$5 +[1] $temp
f[2] ang=pi*($12/180);ix=(x/w)-.5;iy=(y/h)-.5;ix*=$sx;iy*=$sy;IY=ix*sin(ang)+iy*cos(ang);IY+=!$14?$msx;IY*=$maxv;iy=IY;iy abs[2] modf[2] $9,$10,{$11/$10} 
    if {$16&&($9<2)} +[2] {$11<$10?$11} fi 
    if $15 negate[2] fi 
    temp={im#2} -[2] $temp modf[2] 4,{iM#2},$13 +[2] $temp 
f[3] ang=pi*($20/180);ix=(x/w)-.5;iy=(y/h)-.5;ix*=$sx;iy*=$sy;IX=ix*cos(ang)-iy*sin(ang);IY=ix*sin(ang)+iy*cos(ang);IX+=!$22?$msx;IX*=$maxv;IY+=!$22?$msx;IY*=$maxv;ix=IX;iy=IY;($diag?(abs(ix)+abs(iy)):abs(abs(ix)-abs(iy))) modf[3] $17,$18,{$19/$18} 
    if {$24&&($17<2)} +[3] {$19<$18?$19} fi 
    if $23 negate[3] fi 
    temp={im#3} -[3] $temp modf[3] 4,{iM#3},$21 +[3] $temp 
if $tc==4 
    f[4] ang=pi*($28/180);ix=(x/w)-.5;iy=(y/h)-.5;ix*=$sx;iy*=$sy;IX=ix*cos(ang)-iy*sin(ang);IY=ix*sin(ang)+iy*cos(ang);IX+=!$30?$msx;IX*=$maxv;IY+=!$30?$msx;IY*=$maxv;ix=IX;iy=IY;(!$diag?(abs(ix)+abs(iy)):abs(abs(ix)-abs(iy))) modf[4] $25,$26,{$27/$26} 
    if {$32&&($25<2)} +[4] {$27<$26?$27} fi  
    if $31 negate[4] fi 
    temp={im#4} -[4] $temp modf[4] 4,{iM#4},$29 +[4] 
fi
k[0]
if $interpolation&&($subpixel>=2) r $iw,$ih,100%,100%,$interpolation fi
if $cs!=3
    if $cs!=0 sh 0,2 fi
    if $cs==1 ryb2rgb.
    elif $cs==2 cmy2rgb.
    elif $cs==4 hsi82rgb.
    elif $cs==5 hsl82rgb.
    elif $cs==6 hsv82rgb.
    elif $cs==7 lab82rgb.
    elif $cs==8 lch82rgb.
    elif $cs==9 yiq82rgb.
    elif $cs==10 yuv82rgb.
    elif $cs==11 xyz82rgb.
    fi
    if $cs!=0 rm. fi
else
    cmyk2rgb
fi
endl done
#@gui Color Modulo Texture : rep_colmt_gui,rep_colmt_gui_preview(0)
#@gui : note = note("This filter is inspired by <i><a href="https://forums.getpaint.net/topic/7186-madjik-all-plugins-last-updated-2018-04-07/">MadJik's<small><small>.</small></small></a></i> PDN plugin named <i>Color Modulo</i>. G'MIC version exclusive features : Modulo Method, Angle, Value Shift, Negate."), sep = separator()
#@gui : note = note("<b>Color Setting</b>")
#@gui : 1.Color Space=choice(3,"RGB-8","RYB-8","CMY-8","CMYK-8","HSI-8","HSL-8","HSV-8","LAB-8","LCH-8","YIQ-8","YUV-8","XYZ-8")
#@gui : 2.Alpha (Inapplicable to CMYK) = bool(0)
#@gui : sep = separator()
#@gui : note = note("<b>Main Texture Generation</b>")
#@gui : note = note("Channel #1")
#@gui : 3.Modulo Method = choice(3,"Modulo","Modulo-Continuous","Divisive Modulo","Divisive Modulo-Continuous")
#@gui : 4.Max Number = float(255,.1,255)
#@gui : 5.Modulo Result Number = float(128,.1,255)
#@gui : 6.Angle = float(0,-180,180)
#@gui : 7.Value Shift = float(0,0,255)
#@gui : 8.Centered? = bool(0)
#@gui : 9.Negate Value? = bool(0)
#@gui : 10.Normalize based on min? = bool(0)
#@gui : note = note("Channel #2")
#@gui : 11.Modulo Method = choice(3,"Modulo","Modulo-Continuous","Divisive Modulo","Divisive Modulo-Continuous")
#@gui : 12.Max Number = float(255,.1,255)
#@gui : 13.Modulo Result Number = float(128,.1,255)
#@gui : 14.Angle = float(0,-180,180)
#@gui : 15.Value Shift = float(0,0,255)
#@gui : 16.Centered? = bool(0)
#@gui : 17.Negate Value? = bool(0)
#@gui : 18.Normalize based on min? = bool(0)
#@gui : note = note("Channel #3")
#@gui : 19.Modulo Method = choice(3,"Modulo","Modulo-Continuous","Divisive Modulo","Divisive Modulo-Continuous")
#@gui : 20.Max Number = float(255,.1,255)
#@gui : 21.Modulo Result Number = float(128,.1,255)
#@gui : 22.Angle = float(0,-180,180)
#@gui : 23.Value Shift = float(0,0,255)
#@gui : 24.Centered? = bool(0)
#@gui : 25.Negate Value? = bool(0)
#@gui : 26.Normalize based on min? = bool(0)
#@gui : note = note("Channel #4")
#@gui : 27.Modulo Method = choice(3,"Modulo","Modulo-Continuous","Divisive Modulo","Divisive Modulo-Continuous")
#@gui : 28.Max Number = float(255,.1,255)
#@gui : 29.Modulo Result Number = float(128,.1,255)
#@gui : 30.Angle = float(0,-180,180)
#@gui : 31.Value Shift = float(0,0,255)
#@gui : 32.Centered? = bool(0)
#@gui : 33.Negate Value? = bool(0)
#@gui : 34.Normalize based on min? = bool(0)
#@gui : sep = separator(), note = note("<b>Additional Texture Generation Option</b>")
#@gui : 35. Diagonal Flip? = bool(0)
#@gui : sep = separator(), note = note("<b>Channel Order</b>\n\nPick numbers to order the channels")
#@gui : 36.First Channel  = choice(0,"Channel 1","Channel 2","Channel 3","Channel 4")
#@gui : 37.Second Channel  = choice(1,"Channel 1","Channel 2","Channel 3","Channel 4")
#@gui : 38.Third Channel  = choice(2,"Channel 1","Channel 2","Channel 3","Channel 4")
#@gui : 39.Fourth Channel  = choice(3,"Channel 1","Channel 2","Channel 3","Channel 4")
#@gui : sep = separator(), note = note("<b>Processing Value</b>")
#@gui : 40.Subpixel Level = int(0,0,3)
#@gui : 41.Interpolation  = choice(2,"None","Nearest","Average","Linear","Grid","Bicubic","Lanczos")
#@gui :  sep  = separator(), note = note("<small>Author : <i>Reptorian</i>      Latest update: <i>2019/07/18</i>.</small>")
rep_colmt_gui: rep_colmt ${3-34},$35,${40-41},${1-2},${36-39}
rep_colmt_gui_preview: rep_colmt_gui $*

Nice! Your filter writing is much cleaner now. Congrats on your progress. What seems to be the problem currently?

Well, I just found out that my modf function does not seem to do what I’d like. modf 4,255,.5 will reveal a break in gradient even if they are continuous. To explain further, I would like to be able to loop value after shifting. That’s my final issue to solve now.

modf 5,255,.5 n min,max would probably solve the issue. I’ll have to see to that.

Added 50+ palettes. By the way, I would like to export those palettes via gui method. I tried output. whereintheworldsandiego,.gpl, but I can’t find it in my computer. Can G’MIC even export in .gpl?

It’s not a “native” format - there’s a scripted command input_gpl to read them but I don’t see one for output. If you know the structure of a .gpl file, you could write your own in raw mode I expect (perhaps look at the code of input_gpl).

Deleted earlier irrelevant post.

Successfully made multiangle stitching

Finally, I finished tiled pixel commands as I found a workaround using i code for custom shapes support. Also more commentary below this code -

#@cli shape: 0<=_shape
#@cli : Create shape. Variable are defined by the shape chosen.
shape:
v - _gmic_s="$?" v +
_$0 $"*"
_shape:
v - form="$1"
if {isnum("$1")} if {isint("$1")} form=${arg\ 1+$1,australia,barbedwire,circle,crosshair,cupid,diamond,dragonfly,fern,flip,gear,gumleaf,heart,information,kookaburra,mail,mapleleaf,paint_splat,paw,phone,polygon,rooster,shopping_cart,snowflake,star} fi fi
v + e[^-1] "Create shape '"$form"' for shape-based effect."$_gmic_s"." v -
shape_$form ${2--1}
rep_tiles_shape:
apply_parallel "_rep_tiles_shape $*"
_rep_tiles_shape:
repeat $! l[$>]
ww={w}
hh={h}
min_w={$-2}
min_h={$-1}
new_w={ceil(w/$min_w)*$min_w}
new_h={ceil(h/$min_h)*$min_h}
use_shape={isnum("$1")&&isint("$1")?$1+1:1}
if $use_shape at "rep_shape_blend_average ${1--3}",${-2--1}
else at "rep_shape_blend_average_input_file ${2--3}",${-2--1} fi
r $ww,$hh,100%,100%,0,0,.5,.5
endl done
rep_shape_blend_average_input_file:
skip ${2=1}
i "${1}" rep_shape_blend_average -1,${2--1}
rep_shape_blend_average:
#local filter#
if $!>2 v + "Cannot use more than two 2 layer at once!" v - fi
skip ${2=1},${3=.5},${4=4},${5=0},${6=0}
shape=$1
fill_ratio=$2
sub={$3+1}
interpolation={$4+1}
flip_shape=$5
rotate_shape=$6
shape_size={max(w,h)*$sub}
skip ${7=$shape_size}
use_shape={isnum("$1")&&isint("$1")?$1+1:1}
if $use_shape<0&&$!>2 v + error "Cannot use 2 or more layer at once with shape option!" v - fi
if $sub<1 v + error "Invalid subpixel level!" v - fi
if $interpolation<1 v + error "Invalid interpolation level!" v - fi
if $use_shape shape $shape,${7--1}
else to_graya. n. 0,1 compose_channels. * fi
if $5!=0 
if $5==1 mirror. x
elif $5==2 mirror. y
fi fi
if $6!=0 rotate. $6,1 fi
autocrop.
shape_image_ratio={w#1/h#1}
target_image_ratio={w#0/h#0}
resize_width={$target_image_ratio>$shape_image_ratio?w#1*(h#0/h#1):w#0}
resize_height={$target_image_ratio>$shape_image_ratio?h#0:h#1*(w#0/w#1)}
r. {$resize_width*$fill_ratio},{$resize_height*$fill_ratio},1,1,$interpolation,0,.5,.5
r. {w#0},{h#0},1,1,0,0,.5,.5
cut. 0,1
avg={ia#1}
..
f. i*i0#1 f... i*(1-i0#1)
repeat {s#0}
sh... $>
sh.. $>
f. is/($avg*w*h)*($>=={s#0-1}?i0#1:1)
f.. is/((1-$avg)*w*h)
rm[^0-2]
done
rm..
sh[0,1] 0,{s#0-2}
sh[0,1] {s#0-1}
malp={max(iM#4,iM#5)}
/[4,5] $malp
f[2] i#3*i0#4*i0#5+i#3*(1-i0#4)+i*(1-i0#5)
f[4] i*i#5+i#5*(1-i)+i*(1-i#5)
*[4,5] $malp
k[0]

Now, I’m stuck with describing the cli. How would I go formatting the cli description code for rep_tiles_shape? Note that rep_tiles_shape has completely dynamic variables. This is needed to enable dynamic shape modification, and to allow to use file instead.

If $1=-1 on rep_tiles_shape, then $2 becomes file location and the rest is followed by fill_ratio,subpixel_level,interpolation,flip_shape,rotate_angle,shape_size (had to use skip as I don’t know how to skip over $7 for variables used by shape_fern),custom shape_variable after size

if $1=shape, then $2 becomes fill_ratio, and if $8 and later is defined, then they’re used for dynamic shape support. So, if $2 is fern, all custom variables after $8 are defined by shape_fern.

The last two variables on rep_tiles_shape are obviously used for tile size.

Tip = Please put $7 as empty variable when using rep_tiles_shape.

All of this is needed to make the gui filter easy to make, and to enable the most features possible. I could do layer-based filter, but problem is that I don’t know how to send layer inside apply_tiles, and I don’t want to write workarounds, so this is what one is going to get.

Any thoughts?


EDIT: @afre Since you are the only one that’s I know of that use cli here. I’d like to know if you understand this.

#@cli rep_tiles_shape : _negative_number,_file_location,fill_ratio,_subpixel_level,_interpolation,_flip_orientation,_rotation,_shape_size,_tile_width,_tile_height : \
# 0<=_shape_id<=24,0<fill_ratio<=1,0<=_subpixel_level<=1,_interpolation,_flip_orientation,_rotation,_shape_size,...,_tile_width,_tile_height : (+)
#@cli : When $1 is either a name of a shape or a integer number that is between 0 and 24 inclusive, then the formatting of the command becomes the second one.
#@cli : After $2, the last 2 variables are always tile_height, and tile_width! Removing variables between fill_ratio, and shape_size will be omitted, and internally, the command will use respective values found in other commands used by rep_tiles_shape. That means, those variables are used, but not specified by the users, and as mentioned, the last 2 variables are generally _tile_width, and _tile_height.
#@cli : Note - It is advisible to omit $7. If there are 9 variables, then $8 becomes one variable used by a shape id which enables dynamic shape editing.

I know this sound confusing, but it’s the best I can describe the dynamic command.

1 Like

It has been a long day. What I would say is

1 Do it the old way. Write the core filter and have variant or more sophisticated filters refer to it. That is the approach that stdlib (David) takes.

2 Recently, I wrote a filter with two variants. The main filter refers to sub-filters using conditionals. That is a clearer way to have one filter that can accept a variable number of arguments. It also has 1.

It’s a little late to do it the old way, but I believe I can add variants which refers to the rep_tile_shapes filter if it too complicated to use the base command. Like say, I could do rep_tiles_shape_fern,rep_tiles_shape_polygon, and so on. That’ll take a while nonetheless.

It is a blessing once you get used to tackling commands in smaller pieces since you could change one sub, core or main command and BOOM everything else benefits. I haven’t gotten into macros yet. That perhaps would be the next logical step.

1 Like

I really should be using n+1 as I dislike adding numbers just to fit a variable. Maybe I should be using that for future filters similar to Color Modulo Texture or Binary Quaddro Texture. Maybe I should specify number of variables per channel, and then use ${2+$variable_count} as that would be more convenient. Something I’ll try is repeat loop {2+(>*variable_count)} to make it easier.

PS to my previous post. I was saying it in a general way. There are other benefits and possible combinations.