StainlessS
17th October 2021, 16:39
Hi guys,
can you math geniuses out there try this thingy out and point out any screwups I've made [if any].
A daft script I've spent a couple of days on,
a bit experimental and will tend to crash due to stack exhaustion when over doing it plotting points on graph.
Anyways, here tis.
/*
Silly folly.
GrafCanvas(), Make a single frame graph clip.
GrafFunc(), Plot an avisynth function, via Eval.
GrafFunc_mt_Lut() Plot mt_lut expression.
GrafCanvas, create single frame graph clip. [Prone to crash due to stack exhaustion if too many pixels plotted]
xmax, ymax; specify maximum physical pixel coords, range of graf 0->xmax, 0->ymax.
Logical coords are used only by GrafFunc() function, eg GrafFunc("sin(x-PI)",color=$FF0000).
Logical coords specified by startx/y and rangex/y.
If start and range not specified, then logical and physical coords are the same, 0->xmax, 0->ymax.
Examples:
Plot sin() in red, 2 cycles centered both x and y, with origin axis shown at 0,0.
GrafCanvas(511,255,startx=-2*PI, rangex=4*PI, starty=-1.0, rangey=2.0).GrafFunc("sin(x)",$FF0000)
About the same but with origin axis shifted off center.
GrafCanvas(511,255,startx =-PI, rangex=4*PI, starty=-1.0, rangey=2.0).GrafFunc("sin(x)",$FF0000)
3 Phase [Crash on my machine if 511,255, too many points plotted, stack overflow or something]
GrafCanvas(255,255,startx=-2*PI,rangex=4*PI,starty=-1.0,rangey=2.0).GrafFunc("sin(x)",$FF0000).GrafFunc("sin(x-2*PI/3)",$00FF00).GrafFunc("sin(x-4*PI/3)",$0000FF)
4 Phase [AXIS OFF else Crash]
GrafCanvas(255,255,startx=-2*PI,rangex=4*PI,starty=-1.0,rangey=2.0,AXIS=FALSE).GrafFunc("sin(x)",$FF0000).GrafFunc("sin(x-1*PI/2)",$00FF00).GrafFunc("sin(x-2*PI/2)",$0000FF).GrafFunc("sin(x-3*PI/2)",$FF00FF)
Suggest load into Vdub2, right click and tick "Free Adjust", then double click the graphic.
*/
# Examples
GrafCanvas(511,255,startx=-2*PI, rangex=4*PI, starty=-1.0, rangey=2.0).GrafFunc("sin(x)",$FF0000)
#GrafCanvas(511,255,startx =-PI, rangex=4*PI, starty=-1.0, rangey=2.0).GrafFunc("sin(x)",$FF00FF)
#GrafCanvas(255,255,startx=-2*PI,rangex=4*PI,starty=-1.0,rangey=2.0).GrafFunc("sin(x)",$FF0000).GrafFunc("sin(x-2*PI/3)",$00FF00).GrafFunc("sin(x-4*PI/3)",$0000FF)
#GrafCanvas(255,255,startx=-2*PI,rangex=4*PI,starty=-1.0,rangey=2.0,AXIS=FALSE).GrafFunc("sin(x)",$FF0000).GrafFunc("sin(x-1*PI/2)",$00FF00).GrafFunc("sin(x-2*PI/2)",$0000FF).GrafFunc("sin(x-3*PI/2)",$FF00FF)
#GrafFunc_mt_Lut("x") # Infix "x"
#GrafFunc_mt_Lut("255 x -") # Infix "255 - x"
#GrafFunc_mt_Lut("x 16 < x 235 > | 0 255 ?") # Infix "(x < 16 | x > 235) ? 0 : 255"
#GrafFunc_mt_Lutxy() # Infix = "x" (default)
#GrafFunc_mt_Lutxy("x y +",128) # Infix = "x + y"
#GrafFunc_mt_Lutxy("x y -",128) # Infix = "x - y"
#GrafFunc_mt_Lutxy("255 x y - abs 16 * -", y_Y = 0) # Infix = "255-(abs(x-y)*16)"
#GrafFunc_mt_Lutxy("255 x y - abs 16 * -", y_Y=128) # Infix = "255-(abs(x-y)*16)"
#GrafFunc_mt_Lutxy("255 x y - abs 16 * -", y_Y=255) # Infix = "255-(abs(x-y)*16)"
#GrafFunc_mt_Lutxy("x y - abs 128 / 1 4.0 x y - abs 64 / - / ^ 255 *", y_Y = 0) # Infix="( (abs(x-y)/128) ^ (1/ (4.0-(abs(x-y)/64)) ) )*255"
#GrafFunc_mt_Lutxy("x y - abs 128 / 1 4.0 x y - abs 64 / - / ^ 255 *", y_Y=128) # Infix="( (abs(x-y)/128) ^ (1/ (4.0-(abs(x-y)/64)) ) )*255"
#GrafFunc_mt_Lutxy("x y - abs 128 / 1 4.0 x y - abs 64 / - / ^ 255 *", y_Y=255) # Infix="( (abs(x-y)/128) ^ (1/ (4.0-(abs(x-y)/64)) ) )*255"
#GrafFunc_mt_Lutxyz("x y - abs 128 / 1 4.0 x y - abs 64 / - / ^ 255 *", y_Y=128, z_Y= 128) # Infix="( (abs(x-y)/128) ^ (1/ (4.0-(abs(x-y)/64)) ) )*255" [z NOT used, same as above GrafFunc_mt_Lutxy]
#GrafFunc_mt_Lutxyz("y x - 2.0 ^ z x - 2.0 ^ + 0.5 ^", y_Y=128, z_Y= 128) # Infix="(((y-x)^2.0)+((z-x)^2.0))^0.5"
#GrafFunc_mt_Lutxyz("y x - 2.0 ^ z x - 2.0 ^ + 0.5 ^", y_Y=64, z_Y= 64) # Infix="(((y-x)^2.0)+((z-x)^2.0))^0.5"
#GrafFunc_mt_Lutxyz("y x - 2.0 ^ z x - 2.0 ^ + 0.5 ^", y_Y=192, z_Y= 192) # Infix="(((y-x)^2.0)+((z-x)^2.0))^0.5"
#GrafFunc_mt_Lutxyz("y x - 2.0 ^ z x - 2.0 ^ + 0.5 ^", y_Y=64, z_Y= 192) # Infix="(((y-x)^2.0)+((z-x)^2.0))^0.5"
#GrafFunc_mt_Lutxyz("255 y x - 2.0 ^ z x - 2.0 ^ + 0.5 ^ -", y_Y=64, z_Y= 192) # Infix="255-((((y-x)^2.0)+((z-x)^2.0))^0.5)"
#GrafFunc_mt_Lutxyz("y x - 2.0 ^ z x - 2.0 ^ + 0.5 ^", y_Y=32, z_Y= 224) # Infix="(((y-x)^2.0)+((z-x)^2.0))^0.5"
#GrafFunc_mt_Lutxyz("255 y x - 2.0 ^ z x - 2.0 ^ + 0.5 ^ -", y_Y=32, z_Y= 224) # Infix="255-((((y-x)^2.0)+((z-x)^2.0))^0.5)"
return last
Function GrafCanvas(int "xmax",int "ymax", [* Physical pixel max coords (suggest 255) *]
\ float "startx",float "rangex",float "starty",float "rangey", [* Logical coords bottom left, and ranges, eg startx=-PI, rangex=2*PI, starty=-1.0, Rangey=2.0 *]
\ int "bkColor",int "iColor",int "oColor",int "aColor",int "pColor",
\ bool "Axis" [* May need to switch off Axis if crash *]
\ ) {
xmax = Default(xmax,255) ymax = Default(ymax,255) # Max Physical X and Y pixel coords of drawing area. [physical xmin,ymin are always 0]
startx = Default(startx,0) rangex = Default(rangex,xmax) # Leftmost logical x coord and range to logical RHS pixel.
starty = Default(starty,0) rangey = Default(rangey,ymax) # Bottommost logical y coord and range to logical Topmost pixel.
bkColor= default(bkColor,$000000).BitAnd($FFFFFF) # Background color of drawing area.
iColor = default(iColor, $4060A0).BitAnd($FFFFFF) # Inner perimeter color outside of drawing area.
oColor = default(oColor ,$102060).BitAnd($FFFFFF) # Outer perimeter color, outside of Inner perimeter.
aColor = default(aColor ,$808080).BitAnd($FFFFFF) # Axis color.
pColor = default(pColor ,$FFFFFF).BitAnd($FFFFFF) # Plotted pixel color.
axis = Default(axis,true) # Draw Axis.
Global G_xmax = xmax Global G_ymax = ymax # *** GLOBALS ***
Global G_startx = startx Global G_rangex = rangex
Global G_starty = starty Global G_rangey = rangey
Global G_pColor = pColor
physicalx = (startx==0 && rangex==xmax)
physicaly = (starty==0 && rangey==ymax)
BlankClip(Pixel_type="RGB32",Length=1,Width=xmax+1,Height=ymax+1,Color=bkColor)
Addborders(1,1,1,1,iColor)
Addborders(1,1,1,1,oColor)
if(axis) {
if(physicalx) { axis_x=(xmax/2.0).Round }
else {
if(startx <= 0 <= (startx + rangex)) { axis_x = (xmax * (0.0 - startx) / rangex).Round }
else { axis_x = - 1 }
}
if(0 <= axis_x <= xmax) { for(y=0,ymax) { GrafPoint(axis_x,y,color=aColor) } }
if(physicaly) { axis_y=(ymax/2.0).Round }
else {
if(starty <= 0 <= (starty + rangey)) { axis_y = (ymax * (0.0 - starty) / rangey).Round }
else { axis_y = - 1 }
}
if(0 <= axis_y <= ymax) { for(x=0,xmax) { GrafPoint(x,axis_y,color=aColor) } }
}
Return Last
}
Function GrafPoint(clip c,int x,int y,int "Color") { # Physical coords plotter.
c W = Width H=Height
Color = default(Color,G_pColor)
xmax = W-5 ymax = H-5
if(!(0 <= x <= xmax && 0 <= y <= ymax)) {
RT_DebugF("Coord out of Bounds, x=%d y=%d",x,y,name="GrafPoint: ")
x=x.min(xmax).max(0)
y=y.min(ymax).max(0)
}
pix = Last.BlankClip(Pixel_Type="RGB32",Length=1,width=1,height=1,color=Color)
xo = 2 xr = xo + x
yo = H-3 yr = yo - y
Overlay(pix,x=xr,y=yr,opacity=1.0)
Return Last
}
Function GrafFunc(clip c,String func,int "Color") { # eg GrafFunc(grafclip,"sin(x-PI/4)",color=$FFFFFF) ie sine function delayed by 45 degrees (PI/4 radians).
c
xstepf = G_rangex/G_xmax ystepf = G_rangey/G_ymax
startx = G_startx starty = G_starty
for(xi=0, G_xmax) {
x = xi * xstepf + startx
y = Eval(func)
yi = (((y - starty) / ystepf)).Round
GrafPoint(xi,yi,Color)
}
}
Function GrafFunc_mt_Lut(String "yexpr",int "Color") {
RT_DebugF("DBGVIEWCLEAR",name="CLEAR DEBUGVIEW: ")
yexpr = Default(yexpr,"x")
Color = Default(Color,$FF00FF)
GrafCanvas(255,255)
x_C = BlankClip(width=256,height=1,length=1,Pixel_type="Y8").mt_lutspa(mode = "absolute", expr = "x")
R_C = X_C.Mt_lut(yexpr=yexpr)
RT_DebugF("YEXPR='%s' :: INFIX='%s'",yexpr,mt_Infix(yexpr),name="GrafFunc_mt_Lut: ")
for(x=0,255) {
Y=R_C.RT_AverageLuma(n=0,x=x,y=0,w=1,h=1).Round
GrafPoint(x,y,color=Color)
}
Return Last
}
Function GrafFunc_mt_Lutxy(String "yexpr",Int "y_Y",int "Color") { # y_Y 0->255
RT_DebugF("DBGVIEWCLEAR",name="CLEAR DEBUGVIEW: ")
yexpr = Default(yexpr,"x")
y_Y = Default(y_Y, 128)
Color = Default(Color,$FF00FF)
GrafCanvas(255,255)
Y_C = BlankClip(Pixel_type="Y8",Length=1,Width=4,Height=4,Color_YUV=(y_Y *256+128)*256+128)
X_C = BlankClip(width=256,height=1,length=1,Pixel_type="Y8").mt_lutspa(mode = "absolute", expr = "x")
R_C=Mt_lutxy(X_C,Y_C,yexpr=yexpr)
RT_DebugF("YEXPR='%s' :: INFIX='%s'",yexpr,mt_Infix(yexpr),name="GrafFunc_mt_Lutxy: ")
for(x=0,255) {
Y=R_C.RT_AverageLuma(n=0,x=x,y=0,w=1,h=1).Round
GrafPoint(x,y,color=Color)
}
Return Last
}
Function GrafFunc_mt_Lutxyz(String "yexpr",Int "y_Y",Int "z_Y",int "Color") { # y_Y and z_Y, 0->255
RT_DebugF("DBGVIEWCLEAR",name="CLEAR DEBUGVIEW: ")
yexpr = Default(yexpr,"x")
y_Y = Default(y_Y,128)
z_Y = Default(z_Y,128)
Color = Default(Color,$FF00FF)
GrafCanvas(255,255)
Y_C = BlankClip(Pixel_type="Y8",Length=1,Width=4,Height=4, Color_YUV=(y_Y *256+128)*256+128)
Z_C = BlankClip(Pixel_type="Y8",Length=1,Width=4,Height=4,Color_YUV=(z_Y *256+128)*256+128)
X_C = BlankClip(width=256,height=1,length=1,Pixel_type="Y8").mt_lutspa(mode = "absolute", expr = "x")
R_C = Mt_lutxyz(X_C,Y_C,Z_C,yexpr=yexpr)
RT_DebugF("YEXPR='%s' :: INFIX='%s'",yexpr,mt_Infix(yexpr),name="GrafFunc_mt_Lutxyz: ")
for(x=0,255) {
Y=R_C.RT_AverageLuma(n=0,x=x,y=0,w=1,h=1).Round
GrafPoint(x,y,color=Color)
}
Return Last
}
Try out the examples. [uncomment]
Here, masktools lut tutorial by tp7:- https://tp7.github.io/articles/masktools/
You can try out some of the examples there.
can you math geniuses out there try this thingy out and point out any screwups I've made [if any].
A daft script I've spent a couple of days on,
a bit experimental and will tend to crash due to stack exhaustion when over doing it plotting points on graph.
Anyways, here tis.
/*
Silly folly.
GrafCanvas(), Make a single frame graph clip.
GrafFunc(), Plot an avisynth function, via Eval.
GrafFunc_mt_Lut() Plot mt_lut expression.
GrafCanvas, create single frame graph clip. [Prone to crash due to stack exhaustion if too many pixels plotted]
xmax, ymax; specify maximum physical pixel coords, range of graf 0->xmax, 0->ymax.
Logical coords are used only by GrafFunc() function, eg GrafFunc("sin(x-PI)",color=$FF0000).
Logical coords specified by startx/y and rangex/y.
If start and range not specified, then logical and physical coords are the same, 0->xmax, 0->ymax.
Examples:
Plot sin() in red, 2 cycles centered both x and y, with origin axis shown at 0,0.
GrafCanvas(511,255,startx=-2*PI, rangex=4*PI, starty=-1.0, rangey=2.0).GrafFunc("sin(x)",$FF0000)
About the same but with origin axis shifted off center.
GrafCanvas(511,255,startx =-PI, rangex=4*PI, starty=-1.0, rangey=2.0).GrafFunc("sin(x)",$FF0000)
3 Phase [Crash on my machine if 511,255, too many points plotted, stack overflow or something]
GrafCanvas(255,255,startx=-2*PI,rangex=4*PI,starty=-1.0,rangey=2.0).GrafFunc("sin(x)",$FF0000).GrafFunc("sin(x-2*PI/3)",$00FF00).GrafFunc("sin(x-4*PI/3)",$0000FF)
4 Phase [AXIS OFF else Crash]
GrafCanvas(255,255,startx=-2*PI,rangex=4*PI,starty=-1.0,rangey=2.0,AXIS=FALSE).GrafFunc("sin(x)",$FF0000).GrafFunc("sin(x-1*PI/2)",$00FF00).GrafFunc("sin(x-2*PI/2)",$0000FF).GrafFunc("sin(x-3*PI/2)",$FF00FF)
Suggest load into Vdub2, right click and tick "Free Adjust", then double click the graphic.
*/
# Examples
GrafCanvas(511,255,startx=-2*PI, rangex=4*PI, starty=-1.0, rangey=2.0).GrafFunc("sin(x)",$FF0000)
#GrafCanvas(511,255,startx =-PI, rangex=4*PI, starty=-1.0, rangey=2.0).GrafFunc("sin(x)",$FF00FF)
#GrafCanvas(255,255,startx=-2*PI,rangex=4*PI,starty=-1.0,rangey=2.0).GrafFunc("sin(x)",$FF0000).GrafFunc("sin(x-2*PI/3)",$00FF00).GrafFunc("sin(x-4*PI/3)",$0000FF)
#GrafCanvas(255,255,startx=-2*PI,rangex=4*PI,starty=-1.0,rangey=2.0,AXIS=FALSE).GrafFunc("sin(x)",$FF0000).GrafFunc("sin(x-1*PI/2)",$00FF00).GrafFunc("sin(x-2*PI/2)",$0000FF).GrafFunc("sin(x-3*PI/2)",$FF00FF)
#GrafFunc_mt_Lut("x") # Infix "x"
#GrafFunc_mt_Lut("255 x -") # Infix "255 - x"
#GrafFunc_mt_Lut("x 16 < x 235 > | 0 255 ?") # Infix "(x < 16 | x > 235) ? 0 : 255"
#GrafFunc_mt_Lutxy() # Infix = "x" (default)
#GrafFunc_mt_Lutxy("x y +",128) # Infix = "x + y"
#GrafFunc_mt_Lutxy("x y -",128) # Infix = "x - y"
#GrafFunc_mt_Lutxy("255 x y - abs 16 * -", y_Y = 0) # Infix = "255-(abs(x-y)*16)"
#GrafFunc_mt_Lutxy("255 x y - abs 16 * -", y_Y=128) # Infix = "255-(abs(x-y)*16)"
#GrafFunc_mt_Lutxy("255 x y - abs 16 * -", y_Y=255) # Infix = "255-(abs(x-y)*16)"
#GrafFunc_mt_Lutxy("x y - abs 128 / 1 4.0 x y - abs 64 / - / ^ 255 *", y_Y = 0) # Infix="( (abs(x-y)/128) ^ (1/ (4.0-(abs(x-y)/64)) ) )*255"
#GrafFunc_mt_Lutxy("x y - abs 128 / 1 4.0 x y - abs 64 / - / ^ 255 *", y_Y=128) # Infix="( (abs(x-y)/128) ^ (1/ (4.0-(abs(x-y)/64)) ) )*255"
#GrafFunc_mt_Lutxy("x y - abs 128 / 1 4.0 x y - abs 64 / - / ^ 255 *", y_Y=255) # Infix="( (abs(x-y)/128) ^ (1/ (4.0-(abs(x-y)/64)) ) )*255"
#GrafFunc_mt_Lutxyz("x y - abs 128 / 1 4.0 x y - abs 64 / - / ^ 255 *", y_Y=128, z_Y= 128) # Infix="( (abs(x-y)/128) ^ (1/ (4.0-(abs(x-y)/64)) ) )*255" [z NOT used, same as above GrafFunc_mt_Lutxy]
#GrafFunc_mt_Lutxyz("y x - 2.0 ^ z x - 2.0 ^ + 0.5 ^", y_Y=128, z_Y= 128) # Infix="(((y-x)^2.0)+((z-x)^2.0))^0.5"
#GrafFunc_mt_Lutxyz("y x - 2.0 ^ z x - 2.0 ^ + 0.5 ^", y_Y=64, z_Y= 64) # Infix="(((y-x)^2.0)+((z-x)^2.0))^0.5"
#GrafFunc_mt_Lutxyz("y x - 2.0 ^ z x - 2.0 ^ + 0.5 ^", y_Y=192, z_Y= 192) # Infix="(((y-x)^2.0)+((z-x)^2.0))^0.5"
#GrafFunc_mt_Lutxyz("y x - 2.0 ^ z x - 2.0 ^ + 0.5 ^", y_Y=64, z_Y= 192) # Infix="(((y-x)^2.0)+((z-x)^2.0))^0.5"
#GrafFunc_mt_Lutxyz("255 y x - 2.0 ^ z x - 2.0 ^ + 0.5 ^ -", y_Y=64, z_Y= 192) # Infix="255-((((y-x)^2.0)+((z-x)^2.0))^0.5)"
#GrafFunc_mt_Lutxyz("y x - 2.0 ^ z x - 2.0 ^ + 0.5 ^", y_Y=32, z_Y= 224) # Infix="(((y-x)^2.0)+((z-x)^2.0))^0.5"
#GrafFunc_mt_Lutxyz("255 y x - 2.0 ^ z x - 2.0 ^ + 0.5 ^ -", y_Y=32, z_Y= 224) # Infix="255-((((y-x)^2.0)+((z-x)^2.0))^0.5)"
return last
Function GrafCanvas(int "xmax",int "ymax", [* Physical pixel max coords (suggest 255) *]
\ float "startx",float "rangex",float "starty",float "rangey", [* Logical coords bottom left, and ranges, eg startx=-PI, rangex=2*PI, starty=-1.0, Rangey=2.0 *]
\ int "bkColor",int "iColor",int "oColor",int "aColor",int "pColor",
\ bool "Axis" [* May need to switch off Axis if crash *]
\ ) {
xmax = Default(xmax,255) ymax = Default(ymax,255) # Max Physical X and Y pixel coords of drawing area. [physical xmin,ymin are always 0]
startx = Default(startx,0) rangex = Default(rangex,xmax) # Leftmost logical x coord and range to logical RHS pixel.
starty = Default(starty,0) rangey = Default(rangey,ymax) # Bottommost logical y coord and range to logical Topmost pixel.
bkColor= default(bkColor,$000000).BitAnd($FFFFFF) # Background color of drawing area.
iColor = default(iColor, $4060A0).BitAnd($FFFFFF) # Inner perimeter color outside of drawing area.
oColor = default(oColor ,$102060).BitAnd($FFFFFF) # Outer perimeter color, outside of Inner perimeter.
aColor = default(aColor ,$808080).BitAnd($FFFFFF) # Axis color.
pColor = default(pColor ,$FFFFFF).BitAnd($FFFFFF) # Plotted pixel color.
axis = Default(axis,true) # Draw Axis.
Global G_xmax = xmax Global G_ymax = ymax # *** GLOBALS ***
Global G_startx = startx Global G_rangex = rangex
Global G_starty = starty Global G_rangey = rangey
Global G_pColor = pColor
physicalx = (startx==0 && rangex==xmax)
physicaly = (starty==0 && rangey==ymax)
BlankClip(Pixel_type="RGB32",Length=1,Width=xmax+1,Height=ymax+1,Color=bkColor)
Addborders(1,1,1,1,iColor)
Addborders(1,1,1,1,oColor)
if(axis) {
if(physicalx) { axis_x=(xmax/2.0).Round }
else {
if(startx <= 0 <= (startx + rangex)) { axis_x = (xmax * (0.0 - startx) / rangex).Round }
else { axis_x = - 1 }
}
if(0 <= axis_x <= xmax) { for(y=0,ymax) { GrafPoint(axis_x,y,color=aColor) } }
if(physicaly) { axis_y=(ymax/2.0).Round }
else {
if(starty <= 0 <= (starty + rangey)) { axis_y = (ymax * (0.0 - starty) / rangey).Round }
else { axis_y = - 1 }
}
if(0 <= axis_y <= ymax) { for(x=0,xmax) { GrafPoint(x,axis_y,color=aColor) } }
}
Return Last
}
Function GrafPoint(clip c,int x,int y,int "Color") { # Physical coords plotter.
c W = Width H=Height
Color = default(Color,G_pColor)
xmax = W-5 ymax = H-5
if(!(0 <= x <= xmax && 0 <= y <= ymax)) {
RT_DebugF("Coord out of Bounds, x=%d y=%d",x,y,name="GrafPoint: ")
x=x.min(xmax).max(0)
y=y.min(ymax).max(0)
}
pix = Last.BlankClip(Pixel_Type="RGB32",Length=1,width=1,height=1,color=Color)
xo = 2 xr = xo + x
yo = H-3 yr = yo - y
Overlay(pix,x=xr,y=yr,opacity=1.0)
Return Last
}
Function GrafFunc(clip c,String func,int "Color") { # eg GrafFunc(grafclip,"sin(x-PI/4)",color=$FFFFFF) ie sine function delayed by 45 degrees (PI/4 radians).
c
xstepf = G_rangex/G_xmax ystepf = G_rangey/G_ymax
startx = G_startx starty = G_starty
for(xi=0, G_xmax) {
x = xi * xstepf + startx
y = Eval(func)
yi = (((y - starty) / ystepf)).Round
GrafPoint(xi,yi,Color)
}
}
Function GrafFunc_mt_Lut(String "yexpr",int "Color") {
RT_DebugF("DBGVIEWCLEAR",name="CLEAR DEBUGVIEW: ")
yexpr = Default(yexpr,"x")
Color = Default(Color,$FF00FF)
GrafCanvas(255,255)
x_C = BlankClip(width=256,height=1,length=1,Pixel_type="Y8").mt_lutspa(mode = "absolute", expr = "x")
R_C = X_C.Mt_lut(yexpr=yexpr)
RT_DebugF("YEXPR='%s' :: INFIX='%s'",yexpr,mt_Infix(yexpr),name="GrafFunc_mt_Lut: ")
for(x=0,255) {
Y=R_C.RT_AverageLuma(n=0,x=x,y=0,w=1,h=1).Round
GrafPoint(x,y,color=Color)
}
Return Last
}
Function GrafFunc_mt_Lutxy(String "yexpr",Int "y_Y",int "Color") { # y_Y 0->255
RT_DebugF("DBGVIEWCLEAR",name="CLEAR DEBUGVIEW: ")
yexpr = Default(yexpr,"x")
y_Y = Default(y_Y, 128)
Color = Default(Color,$FF00FF)
GrafCanvas(255,255)
Y_C = BlankClip(Pixel_type="Y8",Length=1,Width=4,Height=4,Color_YUV=(y_Y *256+128)*256+128)
X_C = BlankClip(width=256,height=1,length=1,Pixel_type="Y8").mt_lutspa(mode = "absolute", expr = "x")
R_C=Mt_lutxy(X_C,Y_C,yexpr=yexpr)
RT_DebugF("YEXPR='%s' :: INFIX='%s'",yexpr,mt_Infix(yexpr),name="GrafFunc_mt_Lutxy: ")
for(x=0,255) {
Y=R_C.RT_AverageLuma(n=0,x=x,y=0,w=1,h=1).Round
GrafPoint(x,y,color=Color)
}
Return Last
}
Function GrafFunc_mt_Lutxyz(String "yexpr",Int "y_Y",Int "z_Y",int "Color") { # y_Y and z_Y, 0->255
RT_DebugF("DBGVIEWCLEAR",name="CLEAR DEBUGVIEW: ")
yexpr = Default(yexpr,"x")
y_Y = Default(y_Y,128)
z_Y = Default(z_Y,128)
Color = Default(Color,$FF00FF)
GrafCanvas(255,255)
Y_C = BlankClip(Pixel_type="Y8",Length=1,Width=4,Height=4, Color_YUV=(y_Y *256+128)*256+128)
Z_C = BlankClip(Pixel_type="Y8",Length=1,Width=4,Height=4,Color_YUV=(z_Y *256+128)*256+128)
X_C = BlankClip(width=256,height=1,length=1,Pixel_type="Y8").mt_lutspa(mode = "absolute", expr = "x")
R_C = Mt_lutxyz(X_C,Y_C,Z_C,yexpr=yexpr)
RT_DebugF("YEXPR='%s' :: INFIX='%s'",yexpr,mt_Infix(yexpr),name="GrafFunc_mt_Lutxyz: ")
for(x=0,255) {
Y=R_C.RT_AverageLuma(n=0,x=x,y=0,w=1,h=1).Round
GrafPoint(x,y,color=Color)
}
Return Last
}
Try out the examples. [uncomment]
Here, masktools lut tutorial by tp7:- https://tp7.github.io/articles/masktools/
You can try out some of the examples there.