Today I learned (G'MIC)

Here’s a thread that’s the opposite of G’MIC exercise. For developers to share what they have learned in G’MIC.

In G’MIC, you can actually create something similar to Python dictionaries in Python.

rep_test_2:
a1,b1,c1,d1,e1,f1,g1,h1,i1,j1,k1,l1,m1,n1,o1,p1,q1,r1,s1,t1,u1,v1,w1,x1,y1,z1,a2,b2,c2,d2,e2,f2,g2,h2,i2,j2,k2,l2,m2,n2,o2,p2,q2,r2,s2,t2,u2,v2,w2,x2,y2,z2,a3,b3,c3,d3,e3,f3,g3,h3,i3,j3,k3,l3,m3,n3,o3,p3,q3,r3,s3,t3,u3,v3,w3,x3,y3,z3,a4,b4,c4,d4,e4,f4,g4,h4,i4,j4,k4,l4,m4,n4,o4,p4,q4,r4,s4,t4,u4,v4,w4,x4,y4,z4,a5,b5,c5,d5,e5,f5,g5,h5,i5,j5,k5,l5,m5,n5,o5,p5,q5,r5,s5,t5,u5,v5,w5,x5,y5,z5,a6,b6,c6,d6,e6,f6,g6,h6,i6,j6,k6,l6,m6,n6,o6,p6,q6,r6,s6,t6,u6,v6,w6,x6,y6,z6,a7,b7,c7,d7,e7,f7,g7,h7,i7,j7,k7,l7,m7,n7,o7,p7,q7,r7,s7,t7,u7,v7,w7,x7,y7,z7,a8,b8,c8,d8,e8,f8,g8,h8,i8,j8,k8,l8,m8,n8,o8,p8,q8,r8,s8,t8,u8,v8,w8,x8,y8,z8,a9,b9,c9,d9,e9,f9,g9,h9,i9,j9,k9,l9,m9,n9,o9,p9,q9,r9,s9,t9,u9,v9,w9,x9,y9,z9,a10,b10,c10,d10,e10,f10,g10,h10,i10,j10,k10,l10,m10,n10,o10,p10,q10,r10,s10,t10,u10,v10,w10,x10,y10,z10,a11,b11,c11,d11,e11,f11,g11,h11,i11,j11,k11,l11,m11,n11,o11,p11,q11,r11,s11,t11,u11,v11,w11,x11,y11,z11,a12,b12,c12,d12,e12,f12,g12,h12,i12,j12,k12,l12,m12,n12,o12,p12,q12,r12,s12,t12,u12,v12,w12,x12,y12,z12,a13,b13,c13,d13,e13,f13,g13,h13,i13,j13,k13,l13,m13,n13,o13,p13,q13,r13,s13,t13,u13,v13,w13,x13,y13,z13,a14,b14,c14,d14,e14,f14,g14,h14,i14,j14,k14,l14,m14,n14,o14,p14,q14,r14,s14,t14,u14,v14,w14,x14,y14,z14={expr('x',364)}
echo $$1

There are 364 variables. When you do rep_test_2 k14, it will print out 348. This is very similar to Python dictionary. $$1 evaluates $1 first and convert it as string, then evaluate as if it was a string you put it into the code. Basically this acts as a key.

Also, this is just perfect for my quest to remove subcommands for pal command.

1 Like

I learned matchpatch can do rudimentary self similar upscaling:

gcd_upscale_self :
  foreach {
    +r2dx. 50%,2 +matchpatch[0] .,3,3,1,10,15,-2
    r. 200%,200%,100%,100%,1 *. 2 f. "I+[x%2,y%2]"
    warp[0] .,0 k[0]
  }
3 Likes

This looks like JPEG upscaling. I can see JPEG-like artifacts upon zooming.

Yes, nothing magical; it’s only block matching. Best to start from something which isn’t a .jpg (e.g. it works okish with most of the sample images). It does have some interesting properties, such as sharp edges.

Musing: foreach is pretty cool because I can generate copies of images via +foreach. Previously, I caught myself typing +repeat $! local by mistake.

1 Like

This is more of a Today I learned material - Today I learned (G'MIC) - #4 by garagecoder .

Moving it there. I did not catch that thread because of busyness.

This is something I learned a bit ago, but tangent to first post.

custom,use_custom_arg=-1,0
list_of_args=red,green,blue,cat
num_of_args_in_list_of_args={narg($list_of_args)}

if isnum($1)
 arg_choice={$1>=0?int($1)%$num_of_args_in_list_of_args:-1}
else
 $list_of_args={expr('x',narg($list_of_args))}
 arg_choice=$$1
 if !narg($arg_choice) error inv_inp_\$1 fi
fi

if $arg_choice==-1
 use_custom_arg=1
else
 $list_of_args={v=vector$num_of_args_in_list_of_args(0);v[$arg_choice]=1;v;}
fi

if $use_custom_arg
 #commands here
else
 if $red # commands here
 elif $green # commands here
 elif $blue # commands here
 elif $cat # commands here
 else error arg_id_no_info
 fi
fi

With this set up, if I wanted to add the option to allow user to use foo as valid variable, I simple add foo into list_of_args, then I add elif $foo and set up what I need there. No need to muck with ==0,==1… That’s done in the background. I can see this being too complex to set up, but it’s maintainable once you do so. Plus, the error is there for easier debugging. If you hit that, then you’re missing one of the elif condition.