Beware, that’s a quite “technical” post about G’MIC syntax!
I’d want to describe some advances I’ve made on the math evaluator of G’MIC, for next version 2.9.3.
Tonight, I’ve basically added two new (hopefully useful) functions:
expr('expression',_w,_h,_d,_s)returns a vector of size
w*h*d*swhose values are computed just as if one were filling an image of size
(w,h,d,s)with the specified
expression(e.g. with command
fill). That’s useful, if you want to initialize vectors with expressions, e.g you can write:
foo_293 : eval " V = expr('x + y',3,3); print(V); "
in remplacement of
foo_292 : eval " V = vector9(); ind = 0; for (y = 0, y<3, ++y, for (x = 0, x<3, ++x, V[ind++] = x + y; ) ) print(V); "
This leads to
$ gmic foo_293 [gmic]-0./ Start G'MIC interpreter. [gmic_math_parser] V = [ 0,1,2,1,2,3,2,3,4 ] (size: 9) [gmic]-0./ End G'MIC interpreter.
So, a quite useful function to initialize of fill vectors without having to write explicit loops for doing it.
get('varname',_size)returns a vector of size
sizewhose values come from the content of the G’MIC named variable
size==0(default), then a scalar is returned.
foo : var1=1976 var2=10,20,30,40 sp lena,512 store. var3 eval " v1 = get('var1'); print(v1); v2 = get('var2',4); print(v2); v3 = get('var3',512*512*3); print(v3); "
$ ./gmic foo [gmic]-0./ Start G'MIC interpreter. [gmic_math_parser] v1 = 1976 [gmic_math_parser] v2 = [ 10,20,30,40 ] (size: 4) [gmic_math_parser] v3 = [ 225,225,223,223,225,225,225,223,225,223,223,223,223,225,223,223,223,223,225,223,223,224,224,223,223,223,223,224,223,223,223,223,224,223,224,223,223,225,228,234,234,235,234,234,234,236,237,234,237,237,234,236,234,234,231,231,228,223,223,212,204,206,185,173,...,78,89,78,77,79,93,89,104,89,89,89,89,77,93,79,77,79,89,91,80,88,96,108,108,110,108,119,119,119,118,108,118,107,91,104,77,70,65,69,69,70,64,61,61,56,56,56,55,55,61,63,63,78,78,78,77,91,80,79,89,77,79,79,82 ] (size: 786432) [gmic]-0./ End G'MIC interpreter.
As you see, even image-encoded variables (with command or function
store) are managed correctly. This way, it’s now possible to pass a vector-valued variable encoding an image, into a G’MIC pipeline, modify it within the pipeline, and get it back in the math evaluator, like this:
foo : sp portrait1,512 eval " V = crop(200,200,128,128); # Get a 128x128 color patch store(V,'V',128,128,1,3); # Store it as an image-encoded variable 'V' run('$V rotate. 90 b. 3 store. V'); # Modify it in a G'MIC pipeline W = get('V',size(V)); # Get the modified patch as a new vector 'W' draw(W,200,200,0,0,128,128,1,3); # Draw 'W' back on the image. "
which leads to the following result:
Here again, this opens new possibilities to pass data from/to a
Well that’s all for now, 11:24pm, time to go to bed