The Big Bad G'MIC Thread of Silly Questions

From gmic h um:


    Set argument to '*' for discarding all existing custom commands.
    (equivalent to shortcut command 'um').

Not sure if just um would do the job, that last sentence seem to imply this.

I tested this:

$ m foo:5 um * sample cat rep_fragment_blur 5

And it caused a error. I think it has application for GUI filters and interactive filters, but for most CLI filters, that can trigger a error.

Workaround is to collect all of your potential internal commands and append that next to um. Use $0_circpat instead.

If you put in $ debug um *, you get this:

<gmic>./ Item[2]: 'debug', selection [].
<gmic>./ Item[3]: 'um', selection [].
<gmic>./ Command 'um': arguments = '*'.
[gmic]./ Discard definitions of all custom commands (4818 commands).
<gmic>./ Exit scope './'.

But um seem to work here:

gmic run 'm foo:5 e um *  sample cat ${-foo}'
[gmic]./ Start G'MIC interpreter (v.3.3.4).
[gmic]./run/__run/ Import custom commands from expression 'foo:5' (1 new, total: 4733).
um
[gmic]./run/__run/ Multiply image [].
[gmic]./run/__run/ Input sample image 'cat' (1 image 600x550x1x3).
[gmic]./run/__run/*substitute/ *** Error *** Item substitution '${"-foo"}': Expression incorrectly changes the number of images (from 1 to 2).

What does $0_circpat mean?

um * seem to remove all commands then?

Hmm, it appears under run, it multiplies rather than removing all commands.

$0 means the name of your command.

foo: echo $0 would print out foo. If you do m $0_circpat inside foo, the name of the custom internal command is equal to foo_circpat. This helps avoid potential conflicts with existing command or even future commands.

1 Like

Thanks for the tip!

It seems i keep running into problems today.

Some circles don’t “connect”:

Looks like this is the effect of resize when the circle radius is w/$r where $r is an odd number. Should i start checking about even/odd numbers and always make it “even”?

You can make a odd number even by doing this. var=$var+($var&1) assuming $var is a integer. That’s one way of going by it. That can be simplified to var+=$var&1.

Let’s say var=5:
5 is 0b101, and 0b101&1 is 1, so therefore 0b101+(0b101&1) is 0b110 or 6.

1 Like

Brings me to this : W,H,r:=w,h,$_Size+($_Size&1)+1

m "$0_circpat : W,H,r:=w,h,$_Size+($_Size&1)+1 R:=w/$r X,Y:=-$R expand_xy. 1 repeat {(h/$R)+2} { repeat {(w/$R)+2} { circle $X,$Y,$R,1,$7,0,0,0,255 X+=$R } X=-$R Y+=$R } r. $W,$H,100%,100%,1"

Thanks, looks like it works :

But for some reason i feel like i’m doing it wrong again, with all this cheatin’ n’ fixin’. The +1 and expand 1 is a little cheat to prevent the last pixel to be shaved on the image’s edge. (Or so i think lol.).

1 Like

@prawnsushi Here’s my take:

$ 1520,550 rep_circpat 256

#@cli rep_circpat: radius
#@cli : Create Circular patterns onto images.
rep_circpat:
check "isint($1)&&($1>3)"

diameter:=$1+($1&1)

foreach {
  ow,oh,tw,th,nw,nh={od=[w,h];td=ceil(od/$diameter);[od,td,td*$diameter]} rm
  $nw,$nh,1,1,1
  {[$tw,$th]+1},1,1,>"begin(
      const diameter=$diameter;
      const radius=diameter>>1;
    );
    ellipse(#-1,x*diameter+radius,y*diameter+radius,-radius,-radius,0,1,0xffffffff,0);
    ellipse(#-1,x*diameter,y*diameter,-radius,-radius,0,1,0xffffffff,0);
    ellipse(#-1,x*diameter+radius,y*diameter,-radius,-radius,0,1,0xffffffff,0);
    ellipse(#-1,x*diameter,y*diameter+radius,-radius,-radius,0,1,0xffffffff,0);" 
  rm.
}

Nice!
Is this the full image?
If it is, you have the save problem as me: the circles go out of the image by 1 pixel at the bottom, and on the right.

It does remove all definitions of custom commands indeed.

$ gmic um \* sample colorful
[gmic]./ Start G'MIC interpreter (v.3.3.5).
[gmic]./ Discard definitions of all custom commands (4878 commands).
[gmic]./ Input file 'sample' at position 0
[gmic]./ *** Error *** Unknown command or filename 'sample'; did you mean 'name'?

It does not remove the definitions of the native commands, as those are hard-coded in the G’MIC interpreter.

Better not play too much with it then.

Just made this little lazy trick:

#Usual gui stuff
#@gui : Design  = choice(0,"Circles","Triangles","Bananas")

Design=$1

m "$0_pat_0 : [Circles code stuff]"
m "$0_pat_1 : [Triangles code stuff]"
m "$0_pat_2 : [Bananas stuffed in my code]"

${-$0_pat_$Design.}

Is this viable? It actually works fine.

Have fun with Uncommand!

Yes, it can be done like that if you don’t want to use:

if $Design==0
  # Circles code stuffs
elif $Design==1
  # Triangles code stuffs
elif $Design==2
  # Banana stuffed in my code
fi

Personnaly, I prefer the latter because if the stuff you insert is quite long, it’s more a pain to write as a newly created command with command command (where, e.g. things like " must be escaped, and so on).

Thanks, I’ll see what i’ll use in the end.
The thing is, i want to make a lot of different patterns in a dropdown menu. Using ${-$0_pat_$Design.} would save me from a lot of if...elif... and also indentation, unless i keep everything in between on a single line. 5 or 6 would be ok, but what if i end up with 30? Well, might want to split it into 2 or 3 different filters at that point if the conditions below can’t happen.
I’ll surely need your help in the near future (@grosgood and @Reptorian) because i think i’m rushing into GUI nightmare:

  • how to show/hide or modify elements when i select Circles or Bananas (i’ll probably find out in the stdlib) so i can show different options
  • what about the args of the hidden elements? Are they still passed to the command or just ignored?
    ETc,etc.

Just a bunch of stuff going on in my head every now and then.
But for now i have a bunch of patterns to do lol.

You have used u with a structure that defines dynamic gui states on the end. You’d note that {gui_element(s)}_$var… structure. $var can be 0-2, and 0 means hidden, 1 means grayed-out, and 2 means visible.

They’re passed on. And you can even adjust them meanwhile the user can’t tell what’s going on unless the user knows how to read G’MIC code. That means you can store information within GUI for another run of G’MIC filter, and another way to do that is use _persistent variable, and you can use both at the same time.

It’s a pretty advanced subject. I’d probably think it’s behind 3D related things, and but slightly harder than AI related thing. I have only done 3D for a bit, and just to make meshes, but not rendering, and never delved into AI.

Here’s the full image:

I agree that there seems to be a issue. Here’s the one with the fixed code:

#@cli rep_circpat: radius
#@cli : Create Circular patterns onto images.
rep_circpat:
check "isint($1)&&($1>3)"

diameter:=$1+($1&1)

foreach {
  ow,oh,tw,th,nw,nh={od=[w,h];td=ceil(od/$diameter);[od,td+1,td*$diameter+1]} rm
  $nw,$nh,1,1,1
  {[$tw,$th]},1,1,>"begin(
      const diameter=$diameter;
      const radius=diameter>>1;
    );
    ellipse(#-1,x*diameter+radius,y*diameter+radius,-radius,-radius,0,1,0xffffffff,0);
    ellipse(#-1,x*diameter,y*diameter,-radius,-radius,0,1,0xffffffff,0);
    ellipse(#-1,x*diameter+radius,y*diameter,-radius,-radius,0,1,0xffffffff,0);
    ellipse(#-1,x*diameter,y*diameter+radius,-radius,-radius,0,1,0xffffffff,0);" 
  rm.
}

By the way, there’s this:

Thanks for the detailed reply, i’ll try to figure things out.
For now i’m trying to figure out how to create a 1x8 image from the 8 colors selected in the GUI. Well, i haven’t figured it out yet - i get either a grayscale ramp, or colors that are not those i selected… strange. Then if i use map, i end up with an image with 12 channels, and apparently the GUI doesn’t like that. :man_shrugging:

As for the patterns, thanks for the link but i don’t plan on doing only circles. Hell, i don’t even check pattern formulas or algorithm lol. I just look at images and see if i can find out how i can do it.

Here’s what i got so far:


I might replace my code with yours or adapt mine, since yours seem to fill portrait or landscape images as well. Mine only fills square images (yes, didn’t really plan ahead for this, as usual).
But as of now, your version gives me a fully black image.

# I replaced some vars to fit my settings
if bleh... # yes, i went back to if...elif structure. m command forces me to either use $1,$2 etc or $_name1,$_name2, etc. 
  *blablacode for pictures above*
elif $Design==2
  # By Reptorian
  check "isint($Size)&&($Size>3)"
  diameter:=$Size+($Size&1)
  # foreach {
    ow,oh,tw,th,nw,nh={od=[w,h];td=ceil(od/$diameter);[od,td+1,td*$diameter+1]} #rm
    $nw,$nh,1,1,1
    {[$tw,$th]},1,1,>"begin(
        const diameter=$diameter;
        const radius=diameter>>1;
      );
      ellipse(#-1,x*diameter+radius,y*diameter+radius,-radius,-radius,0,1,$Outl,0);
      ellipse(#-1,x*diameter,y*diameter,-radius,-radius,0,1,$Outl,0);
      ellipse(#-1,x*diameter+radius,y*diameter,-radius,-radius,0,1,$Outl,0);
      ellipse(#-1,x*diameter,y*diameter+radius,-radius,-radius,0,1,$Outl,0);"
    rm.
  # }

fi

I also get a black image if i put your unaltered code in the custom filter in gmic-qt. So, i don’t know…

Could you share your full code, and the relevant line? This is easy to do.

It’s not normalized. So, the image is 0,1 value only. I normalized my example image to demonstrate the output. White (255 in provided image) is 1 and Black is 0.

I’m sure of it. But i’ve re-read the tutorial and i still don’t know if i should use brackets or accolades or quotes or…

This is the closest to something that i want:

1,8,1,3,'$C1R,$C1G,$C1B,$C2R,$C2G,$C2B,$C3R,$C3G,$C3B,$C4R,$C4G,$C4B,$C5R,$C5G,$C5B,$C6R,$C6G,$C6B,$C7R,$C7G,$C7B,$C8R,$C8G,$C8B' d
map.. 3,0 d

But:

Here are the default values:

#@gui : Color 1 = color(255,0,0)
#@gui : Color 2 = color(255,113,57)
#@gui : Color 3 = color(255,255,0)
#@gui : Color 4 = color(85,0,255)
#@gui : Color 5 = color(0,0,255)
#@gui : Color 6 = color(0,113,165)
#@gui : Color 7 = color(85,170,0)
#@gui : Color 8 = color(255,255,255)

They are mixed up in the palette. 1st color became 255,0,113, etc.

Try this toy GUI filter:

#@gui 7 Color Palette Example:fx_7_color_example
#@gui:Color 0=color(44,73,88)
#@gui:Color 1=color(139,151,156)
#@gui:Color 2=color(196,196,196)
#@gui:Color 3=color(75,79,77)
#@gui:Color 4=color(34,39,37)
#@gui:Color 5=color(18,17,19)
#@gui:Color 6=color(42,19,30)
fx_7_color_example:
rm
(${1-3};${4-6};${7-9};${10-12};${13-15};${16-18};${19-21}) permute. cyzx
1 Like

Ok so i did write it with the parenthesis and “;” before, but i was missing the permute command…
Now the colors are right in my script, but the map command still outputs a 12 channel image, fully red. Note than the circles are rendered on their own with an alpha channel.

Doing an alpha blending with the background before mapping works but then i have a 9 channel image…

This also gives me a 12 channel image :
gmic run 'sp tiger s. c . a c map cool'
SHould i use compose_channels or something?