-
Notifications
You must be signed in to change notification settings - Fork 475
Parsing String Rule (EN)
All filters can be done by the filter effect rule string. Editor
Each step should start with '@',and followed by the function name. There can be any spaces between them.
For example: "@ method" and "@method" are both valid。There can be some characters after the 'method' separated by spaces.
The characters between the 'method' and the next '@' will be passed to the paired parser.
The rule string looks like this:
"@ method0
args_for_method0
@ method1args_for_method1
@ method2args_for_method2
..."
args_for_method*
represents for the additional arguments for the method*.
argN
has two kind:
① "RGB (x1, y1) (xn, yn)",
② "R (rx1, ry1) ... (rxn, ryn) G (gx1, gy1) ... (gxn, gyn) B (bx1, by1)...(bxn, byn)"
The range of the numbers should be [0, 255].
The R,G,B stands for the red, green and blue channel.
The RGB stands for all the three channels.
The points after the channel name are the control points of that channel.
There can be any spaces between each parameter.
The best way to generate the rule string of curve is using cge-tools.
Example:
① To apply a curve-filter with control point (0, 0) (100, 200) (255, 255),
The rule string is: "@curve RGB(0, 0) (100, 200) (255, 255)".
② To apply a curve-filter with control point of
R channel (0, 0) (100, 150) (255, 255),
RGB channel (0, 0) (200, 150) (255, 255),
The rule string is:
"@curve R(0, 0) (50, 25) (255, 255) G(0, 0) (100, 150) (255, 255) RGB(0, 0) (200, 150) (255, 255)".
PS: if you have more than one continuous curve filters, you can merge them into one curve function.
This will reduce the processing time.
For example, if you're doing both of the two curve function above(example ① and ②) continuously,
You can write your rule like this: "@curve RGB(0, 0) (100, 200) (255, 255) R(0, 0) (50, 25) (255, 255) G(0, 0) (100, 150) (255, 255) RGB(0, 0) (200, 150) (255, 255)"
This function will scale the blending image to fit the dst image.
Values for function
should be:
Tips: "AAA [BBB]" means BBB is short for AAA.
mix
dissolve [dsv]
darken [dk]
multiply [mp]
colorburn [cb]
linearburn [lb]
darkercolor [dc]
lighten [lt]
screen [sr]
colordodge [cd]
lineardodge [ld]
lightercolor [lc]
overlay [ol]
softlight [sl]
hardlight [hl]
vividlight [vvl]
linearlight [ll]
pinlight [pl]
hardmix [hm]
difference [dif]
exclude [ec]
subtract [sub]
divide [div]
hue
saturation [sat]
color [cl]
luminosity [lum]
/// The three blend mode can not be found in the wiki.
add // just add the src&dst
addrev //src.rgb * (1.0 - dst.a) + dst.rgb
//mix(src.rgb, vec3(dot(src.rgb, vec3(0.299, 0.587, 0.114))), dst.a)
//Note: dst.rgb is not used.
colorbw
The meaning of the blend modes can be found at blend mode wiki
texture
means the resource image name with postfix. e.g. "demo.png".
Note: Enhanced usage (add date 2016-1-5) The parameter can be directly used for texture id, width, height (enclosed in square brackets, separated by commas, without any spaces in the middle, for example: [10,1024,768]
denotes the use of texture ID 10, texture 10 is 1024 pixels wide and 768 pixels high.) Since square brackets cannot be used directly in a file name this method doesn't conflict with the normal processing.
Note: This usage is not suitable for editors, etc., it is for programmers to provide enhanced features!
Special Note: In enhanced usage, once the texture id is filled in incorrectly, conflicts with other texture ids can easily cause the entire app to function incorrectly! So use with care.
intensity
means blend intensity. Range: (0, 100]
.
Example:
To do a 80% overlay blending with the resource image "src.jpg":
"@blend ol src.jpg 80"
"@blend overlay src.jpg 80"
Both of the above strings are OK.
If you have set the image-loading callback,
the name string "src.jpg" will be passed to your callback.
If your callback returns the right image, you will get the right result.
Or the filter may be invalid.
Please see the demo for more details.
function
texture
intensity
are the same to normal blend
krblend will keep the resource image's aspect ratio while blending. (like AspectFill)
function
intensity
are the same to normal blend
color
includes four float numbers, standing for a color's four channels(r, g, b, a). Range: [0, 1]
or [0, 255]
Note: if the alpha of the provided color is bigger than 1.0, the four channels of the color will be divided by 255.0. So the color RGBA(255, 0, 0, 255) is the same to RGBA(1, 0, 0, 1).
Example:
To do a 90% overlay blending with the color RGBA(255, 0, 0, 255):
"@pixblend overlay 1 0 0 255 90"
"@pixblend overlay 255 0 0 255 90"
function
intensity
are the same to normal blend
"selfblend" will blend with the origin image.
low
range
centerX
centerY
[isLinear]"
function
color
intensity
is the same to pixblend
Values for [isLinear]: (Not necessary, default 0)
0: linear vignette without alpha blending.
1: linear vignette with alpha blending.
2: bilinear vignette without alpha blending.
3. bilinear vignette with alpha blending.
e.g.
"@vigblend ol 0 0 0 1 50 0.02 0.45 0.5 0.5 0"
"@vigblend mix 10 10 30 255 100 0 1.5 0.5 0.5 0",
"@vigblend mix 10 10 30 255 100 0 1.5 0.5 0.5 1",
"@vigblend mix 10 10 30 255 100 0 1.5 0.5 0.5 2",
"@vigblend mix 10 10 30 255 100 0 1.5 0.5 0.5 3",
The best way to know about this filter is using cge-tools.
Values for function
:
Tips: "AAA[BBB]" means BBB is short for AAA.
brightness:
Param num: 1 (intensity), range: [-1, 1].
e.g. "@adjust brightness 0.5"
contrast:
Param num: 1 (intensity), range: intensity > 0.
If 0 < intensity < 1, the result's contrast is lower than the origin.
If intensity = 1, the result is the same to the origin.
if intensity > 1, the result's contrast is higher than the origin.
e.g. "@adjust contrast 2"
saturation:
Param num: 1 (intensity), range: intensity >= 0.
If intensity = 0, the result is monochrome.
If 0 < intensity < 1, the result's saturation is lower than the origin.
If intensity = 1, the result is the same to the origin.
If intensity > 1, the result's saturation is higher than the origin.
e.g. "@adjust saturation 2"
monochrome:
Param num: 6 (red, green, blue, cyan, magenta, yellow), range (all): [-2, 3].
e.g. "@adjust monochrome 2 0.5 -0.1 3 -2 -0.5"
sharpen:
Param num: 1 (intensity), range: [0, 10].
If intensity = 0, the result is the same to the origin.
If intensity > 0, the result is more sharp than the origin.
e.g. "@adjust sharpen 4.33 2 "
blur:
Param num: 1 (intensity), range: [0, 10].
If intensity = 0, the result is the same to the origin.
If intensity > 0, the result is more blurred than the origin.
This function is not recommanded,
there are some other blur functions outof "adjust" module.
whitebalance:
Param num: 2 (temperature, tint).
Range of temperature: [-1, 1]. 0 for origin.
Range of tint: [0, 5]. 1 for origin.
e.g. "@adjust whitebalance -0.44 2.52 "
shadowhighlight[shl]:
Param num: 2 (shadow, highlight).
Range of shadow: [-200, 100]. 0 for origin.
Range of highlight: [-100, 200]. 0 for origin.
e.g. "@adjust shadowhighlight -99 200 "
hsv:
Param num: 6 (red, green, blue, magenta, yellow, cyan), range (all): [-1, 1].
e.g. "@adjust hsv -1 -0.5 0.2 0.5 1 0.1 "
hsl:
Param num: 3 (hue, saturation, luminance), range (all): [-1, 1].
e.g. "@adjust hsl -0.66 0.34 0.15 "
level:
Param num: 3 (dark, light, gamma), range (all): [0, 1], and dark < light
e.g. "@adjust level 0.23 0.56 1.96 "
exposure:
Param num 1 (intensity), range: [-2, 2].
e.g. @adjust exposure 0.62
colorbalance:
Param num 3 (redShift, greenShift, blueShift), range (all): [-1, 1].
e.g. "@adjust colorbalance 0.65 0.41 -0.49 "
lut: (tips: lookup table)
Param num 1 (lookup table resource name)
e.g. "@adjust lut lookup.png"
Note: lookup.png should be a 512x512 lookup table image file.
It's a usefull function, you can see it in the demo(both Andoird&iOS).
Note: centerX
centerY
is not necessary. (Default 0.5)
e.g. "@vignette 0.1 0.9" , "@vignette 0.1 0.9 0.5 0.5"
Values for function
① flt
e.g. "@colormul flt 1.5"
The all pixels of the origin image will be multiplied by 1.5.
dst.rgb = src.rgb * 1.5;
dst.a = src.a;
② vec
e.g. "@colormul vec 0.2 1.5 0.3"
The all pixels of the origin image will be multiplied by vec(0.2, 1.5, 0.3).
dst.rgb = src.rgb * vec(0.2, 1.5, 0.3);
dst.a = src.a;
With this function, you can handle the image's channel directly.
A simple pure red filter can be this: "@colormul vec 1 0 0".
And it's faster than "@curve G (0, 0), (255, 0) B (0, 0), (255, 0)".
③ mat
e.g. "@colormul mat 0.299 0.587 0.114 0.299 0.587 0.114 0.299 0.587 0.114 "
The all pixels of the origin image will be multiplied by the 3x3 mat.
dst.rgb = src.rgb * mat3(0.299, 0.587, 0.114,
0.299, 0.587, 0.114,
0.299, 0.587, 0.114);
The example shows a monochrome effect.
This is a useful function.
One more example:
“@colormul mat 0 1 0 1 0 0 0 0 1 ” (swap the red and the green channel)
It's just like the "selective color" function in Photoshop.
Values for colorN
:
red, green, blue, cyan, magenta, yellow, white, gray, black.
colorargsN
stands for the shifting of the specified color.
It contains four float values: (Range: [-1, 1]
)
cyan, megenta, yellow, black
e.g.
"@selcolor red(0, -74, 0, 0) green(0, 0, 18, 0) blue(0, 100, 0, 0) yellow(-100, 100, 100, -100) white(0, 0, 62, 0) "
Values for function