-
-
Save dnjulek/58a252948adbe63fd4929fd9ce151eca to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from math import log | |
import vapoursynth as vs | |
core = vs.core | |
a = (pow(2.0, 18.0) - 16.0) / 117.45 | |
b = (1023.0 - 95.0) / 1023.0 | |
c = 95.0 / 1023.0 | |
s = (7 * log(2) * pow(2.0, 7 - 14 * c / b)) / (a * b) | |
t = (pow(2.0, 14.0 * (-c / b) + 6.0) - 64.0) / a | |
# LogC4 Curve Encoding Function | |
def ex_relativeSceneLinearToNormalizedLogC4(src: vs.VideoNode) -> vs.VideoNode: | |
return src.std.Expr(f'x {t} < x {t} - {s} / {a} x * 64 + log 2 log / 6 - 14 / {b} * {c} + ?') | |
# LogC4 Curve Decoding Function | |
def ex_normalizedLogC4ToRelativeSceneLinear(src: vs.VideoNode) -> vs.VideoNode: | |
return src.std.Expr(f'x 0 < x {s} * {t} + 2 x {c} - 14 * {b} / 6 + pow 64 - {a} / ?') | |
def logC4ToACES(src: vs.VideoNode) -> vs.VideoNode: | |
src_lin = ex_normalizedLogC4ToRelativeSceneLinear(src) | |
r_lin, g_lin, b_lin = src_lin.std.SplitPlanes() | |
# Matrix AWG4 + D65 --CAT02--> ACES AP0 + ACES RGB White Point | |
rOut = core.std.Expr([r_lin, g_lin, b_lin], 'x 0.750957362824734131 * y 0.144422786709757084 * z 0.104619850465508965 * + +') | |
gOut = core.std.Expr([r_lin, g_lin, b_lin], 'x 0.000821837079380207 * y 1.007397584885003194 * z -0.008219421964383583 * + +') | |
bOut = core.std.Expr([r_lin, g_lin, b_lin], 'x -0.000499952143533471 * y -0.000854177231436971 * z 1.001354129374970370 * + +') | |
return core.std.ShufflePlanes([rOut, gOut, bOut], [0, 0, 0], vs.RGB) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment