Color parameter in G'MIC scripts - 3 or 4 values?


(Tobias Fleischer) #1

Hi guys,
maybe a simple thing, but I haven’t found a conclusive answer yet.
For G’MIC commands/scripts that have a color parameter, some seem to take them in RGB format, others in RGBA. Example: fx_reflect has RGBA, while fx_chromatic_aberrations only wants RGB format. Since this seems to be directly tied to the parameter indexing, you need to know the correct number of channels before, right? How is this determined? Do I have to look at how many parameters the default value for the color parameter has for a specific command?
Please enlighten me, as this is currently causing some bugs with my OpenFX integration of G’MIC.

Cheers,
Toby


#2

As you say, it depends on the command or filter. Spectrum is what you are looking for to see how many channels an input image has.

gmic sample tiger echo {s} quit

[gmic]-0./ Start G'MIC interpreter.
[gmic]-1./ Input sample image 'tiger' (1 image 750x500x1x3).
[gmic]-1./ 3
[gmic]-1./ Quit G'MIC interpreter.

From the docs (https://gmic.eu/reference.shtml):

image


(Tobias Fleischer) #3

Yes, but what about the same input image?
If I call the two commands mentioned above, for one I have to specify RGB, for the other RGBA:
gmic -input t.jpg -fx_chromatic_aberrations R,G,B,2,2,R,G,B,0,0,0,50,50 -output o.jpg
gmic -input t.jpg -fx_reflect 50,1,R,G,B,A,0,1.5,0,0,7,1.5 -output o.jpg
I need to keep to the exact parameter order/indexing, so I need to know if a color is to be given as RGB or RGBA. The only way I found to determine this is to look at the default value of the color parameter in that command, if it has 3 channels, I also need to give 3 channels on the commands line, if it has 4, then I need to put in 4.

#@gui Reflection : fx_reflect, fx_reflect(1)
#@gui : Height = float(50,0,100)
#@gui : Attenuation = float(1,0.1,4)
#@gui : Color = color(110,160,190,64)
#@gui : Waves Amplitude = float(0,0,100)
#@gui : Waves Smoothness = float(1.5,0,4)
#@gui : X-Angle = float(0,-10,10)
#@gui : Y-Angle = float(-3.30,-10,10)
#@gui : Focale = float(7,0,10)
#@gui : Zoom = float(1.5,1,5)

#@gui Chromatic Aberrations : fx_chromatic_aberrations, fx_chromatic_aberrations_preview(0)
#@gui : Primary Color = color(255,0,0)
#@gui : X-Shift = float(2,-16,16)
#@gui : Y-Shift = float(2,-16,16)
#@gui : sep = separator()
#@gui : Secondary Color = color(0,255,0)
#@gui : X-Shift (px) = float(0,-16,16)
#@gui : Y-Shift (px) = float(0,-16,16)


#4

Oh, I get it. I normally use CLI, so I haven’t thought of the problem. I guess you could determine the total no of parameters. E.g., Reflection has 9 GUI items but only 1 of them is a colour parameter, which has 3-4 sub-parameters. So, if the max value of parameters is 12, then you would know that it is RGBA.


(Tobias Fleischer) #5

I just looked into the sources for gmic-qt, and indeed, that is how it is done - simply counting the amount of elements for the default color value to determine if it is with or without an alpha channel :slight_smile: