/
ColorMatrix.avsi
20 lines (17 loc) · 979 Bytes
/
ColorMatrix.avsi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# Performs color matrix conversion with 16 bit depth to avoid banding
function ColorMatrixShader(clip input, string "MatrixIn", string "MatrixOut", string "FormatOut") {
MatrixIn = default(MatrixIn, "709")
MatrixOut = default(MatrixOut, "709")
FormatOut = default(FormatOut, "")
Assert(MatrixIn == "601" || MatrixIn == "709", "MatrixIn must be 601 or 709")
Assert(MatrixOut == "601" || MatrixOut == "709", "MatrixOut must be 601 or 709")
Assert(MatrixIn != MatrixOut, "MatrixIn and MatrixOut must be different")
input
sourceFormat = FormatOut != "" ? FormatOut : IsYV12 ? "YV12" : IsYV24 ? "YV24" : ""
Assert(sourceFormat != "", chr(10) + "Source must be YV12 or YV24" + chr(10))
input = ConvertToShader(1)
Shader(MatrixIn == "601" ? "Yuv601ToGamma.cso" : "YuvToGamma.cso")
Shader(MatrixOut == "601" ? "GammaToYuv601.cso" : "GammaToYuv.cso")
ExecuteShader(last, input, Precision=2, Clip1Precision=1, OutputPrecision=1)
ConvertFromShader(1, format=sourceFormat)
}