PDA

View Full Version : script translation


kolak
28th February 2015, 17:22
Could anyone try to translate this (if possible) to vs:

Dither_lut8(expr="x 128 - 3 / 128 + 256 *",yexpr="x 125.5 - 3 / 125.5 + 256 *",u=3,v=3)
# replace 128 and 125.5 with 127.5 if working with a full-range source
Dither_convert_yuv_to_rgb(matrix="709",lsb_in=true,output="rgb48y")
r = SelectEvery(3,0)
g = SelectEvery(3,1)
b = SelectEvery(3,2)
undershoot = cl_exprxyz(r,g,b,"21760 x y z min min -",lsb=true).SelectEvery(1,0,0,0)
overshoot = cl_exprxyz(r,g,b,"x y z max max 43520 -",lsb=true).SelectEvery(1,0,0,0)
rgb_fixed = cl_exprxyz(last,undershoot,overshoot,"x 21760 y - - 21760 y z + + / 65280 *",lsb=true)
# the above is not exactly "fancy" soft limiting, but derp.
rgb_fixed.DitherPost(mode=6)
MergeRGB(SelectEvery(3,0),SelectEvery(3,1),SelectEvery(3,2))

jackoneill
28th February 2015, 18:03
What does it do?

Reel.Deel
28th February 2015, 18:18
Out of gamut fix: http://forum.doom9.org/showthread.php?t=171846

jackoneill
28th February 2015, 19:20
Dither_lut8(expr="x 128 - 3 / 128 + 256 *",yexpr="x 125.5 - 3 / 125.5 + 256 *",u=3,v=3)
# replace 128 and 125.5 with 127.5 if working with a full-range source
Dither_convert_yuv_to_rgb(matrix="709",lsb_in=true,output="rgb48y")
r = SelectEvery(3,0)
g = SelectEvery(3,1)
b = SelectEvery(3,2)
undershoot = cl_exprxyz(r,g,b,"21760 x y z min min -",lsb=true).SelectEvery(1,0,0,0)
overshoot = cl_exprxyz(r,g,b,"x y z max max 43520 -",lsb=true).SelectEvery(1,0,0,0)
rgb_fixed = cl_exprxyz(last,undershoot,overshoot,"x 21760 y - - 21760 y z + + / 65280 *",lsb=true)
# the above is not exactly "fancy" soft limiting, but derp.
rgb_fixed.DitherPost(mode=6)
MergeRGB(SelectEvery(3,0),SelectEvery(3,1),SelectEvery(3,2))


Untested translation:


# src = asdf.mov

src = c.fmtc.bitdepth(src, bits=16)

lut_y = []
lut_uv = []

middle_y = 125.5 * 256
middle_uv = 128 * 256

for x in range(256 * 256):
lut_y.append(int((x - middle_y) / 3 + middle_y + 0.5))
lut_uv.append(int((x - middle_uv) / 3 + middle_uv + 0.5))

src = c.std.Lut(src, planes=0, lut=lut_y)
src = c.std.Lut(src, planes=[1,2], lut=lut_uv)

rgb = src
rgb = c.fmtc.resample(rgb, css="444", kernel="bicubic")
rgb = c.fmtc.matrix(rgb, mat="709", col_fam=vs.RGB)

r = c.std.ShufflePlanes(clips=rgb, planes=0, colorfamily=vs.GRAY)
g = c.std.ShufflePlanes(clips=rgb, planes=1, colorfamily=vs.GRAY)
b = c.std.ShufflePlanes(clips=rgb, planes=2, colorfamily=vs.GRAY)

undershoot = c.std.Expr([r,g,b], expr="21760 x y z min min -")
overshoot = c.std.Expr([r,g,b], expr="x y z max max 43520 -")

asdf = "x 21760 y - - 21760 y z + + / 65280 *"
r = c.std.Expr([r, undershoot, overshoot], expr=asdf)
g = c.std.Expr([g, undershoot, overshoot], expr=asdf)
b = c.std.Expr([b, undershoot, overshoot], expr=asdf)

rgb_fixed = c.std.ShufflePlanes(clips=[r,g,b], planes=[0,0,0], colorfamily=vs.RGB)

rgb_fixed = c.fmtc.bitdepth(rgb_fixed, bits=8, dmode=6)

kolak
28th February 2015, 20:46
Looks wrong, not like a reference avs output.
It does something, but instead of "adjusting" colors is adds banding in out of gamut areas.

I have added:


ret= c.fmtc.matrix(rgb_fixed,matd="709", col_fam=vs.YUV, bits=16)
ret= c.fmtc.resample(ret, css="422")
ret= c.fmtc.bitdepth(ret, bits=10, dmode=6, ampo=0, ampn=0)
ret.set_output()
enable_v210=True

but I assume this is not breaking it.
I'm using vs version 24, which has some bugs in expr, so this may be the reason.

Ref:

http://diff.pics/tOuEecjmoLCs