This is an automated email from the git hooks/post-receive script. Git pushed a commit to branch master in repository ffmpeg.
commit c206b1fdd7ca0186fd3cbe19de36dab618824395 Author: Kacper Michajłow <[email protected]> AuthorDate: Sat Oct 24 04:06:39 2026 +0200 Commit: Kacper Michajłow <[email protected]> CommitDate: Wed Oct 28 19:22:28 2026 +0000 swscale/csputils: derive the RGB to XYZ matrix without dividing by y ff_sws_rgb2xyz built its columns from X/Y and Z/Y of each primary and then solved for the scale that fits the white point, so the division by y cancels out, while av_div_q by y = 0 turned the matrix into infinities and NaNs. Use the xyz chromaticity vectors directly, which gives the same matrix and also works for a primary with y = 0, such as the Z axis of the CIE 1931 XYZ. Signed-off-by: Kacper Michajłow <[email protected]> --- libswscale/csputils.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/libswscale/csputils.c b/libswscale/csputils.c index 6ab6ac3f7a..1c2c96da27 100644 --- a/libswscale/csputils.c +++ b/libswscale/csputils.c @@ -92,23 +92,26 @@ static inline AVRational cie_Z(AVCIExy xy) SwsMatrix3x3 ff_sws_rgb2xyz(const AVColorPrimariesDesc *desc) { SwsMatrix3x3 out = {{{0}}}; - float S[3], X[3], Z[3], Xw, Zw; + float S[3], X[3], Y[3], Z[3], Xw, Zw; - X[0] = av_q2d(cie_X(desc->prim.r)); - X[1] = av_q2d(cie_X(desc->prim.g)); - X[2] = av_q2d(cie_X(desc->prim.b)); + X[0] = av_q2d(desc->prim.r.x); + X[1] = av_q2d(desc->prim.g.x); + X[2] = av_q2d(desc->prim.b.x); - Z[0] = av_q2d(cie_Z(desc->prim.r)); - Z[1] = av_q2d(cie_Z(desc->prim.g)); - Z[2] = av_q2d(cie_Z(desc->prim.b)); + Y[0] = av_q2d(desc->prim.r.y); + Y[1] = av_q2d(desc->prim.g.y); + Y[2] = av_q2d(desc->prim.b.y); + + for (int i = 0; i < 3; i++) + Z[i] = 1.0f - X[i] - Y[i]; Xw = av_q2d(cie_X(desc->wp)); Zw = av_q2d(cie_Z(desc->wp)); - /* S = XYZ^-1 * W */ + /* S = xyz^-1 * W */ for (int i = 0; i < 3; i++) { out.m[0][i] = X[i]; - out.m[1][i] = 1.0f; + out.m[1][i] = Y[i]; out.m[2][i] = Z[i]; } @@ -117,10 +120,10 @@ SwsMatrix3x3 ff_sws_rgb2xyz(const AVColorPrimariesDesc *desc) for (int i = 0; i < 3; i++) S[i] = out.m[i][0] * Xw + out.m[i][1] + out.m[i][2] * Zw; - /* M = [Sc * XYZc] */ + /* M = [Sc * xyzc] */ for (int i = 0; i < 3; i++) { out.m[0][i] = S[i] * X[i]; - out.m[1][i] = S[i]; + out.m[1][i] = S[i] * Y[i]; out.m[2][i] = S[i] * Z[i]; } -- To stop receiving notification emails like this one, please contact [email protected]. _______________________________________________ ffmpeg-cvslog mailing list -- [email protected] To unsubscribe send an email to [email protected]
