GithubHelp home page GithubHelp logo

Comments (6)

ChthonVII avatar ChthonVII commented on April 28, 2024 1

I put in a PR. Unfortunately, I don't have a suitable Windows build environment readily available, so it's totally untested.

I noticed some other colorimetry issues along the way. I'll try to write them up.

from ffnx.

ChthonVII avatar ChthonVII commented on April 28, 2024

Assuming I understand the math correctly, it appears that using a decoding gamma of ~2.2 instead of the bt601/709 transfer curve gives wrong results that are very close to the observed wrong results. So my current working hypothesis is that something in the pipeline is ignoring the "transfer" metadata set by x264 and using something near 2.2 instead.

from ffnx.

ChthonVII avatar ChthonVII commented on April 28, 2024

Yep, it looks like that's it exactly. In /src/video/movies.cpp, ffmpeg is never asked to fetch the transfer metadata. And then, in misc/FFNx.common.sh, the srgb transfer curve is used to decode gamma. Which is wrong because the gamma encoding was almost certainly done with the SMPTE170M transfer curve (shared by rec601 and rec709) in the first instance.

So the fix is:

Add this function to misc/FFNx.common.sh:

vec3 toLinearSMPTE170M(vec3 _rgb)
{
	bvec3 cutoff = lessThan(_rgb.rgb, vec3_splat(0.081));
	vec3 higher = pow((_rgb.rgb + vec3_splat(0.099)) / vec3_splat(1.099), (vec3_splat(1.0) / vec3_splat(0.45)));
	vec3 lower = _rgb.rgb / vec3_splat(4.5);

	return mix(higher, lower, cutoff);
}

Then on line 96 of /misc/FFNx.frag, replace
color.rgb = toLinear(color.rgb);
with

if (isMovie){
	color.rgb = toLinearSMPTE170M(color.rgb);
}
else {
	color.rgb = toLinear(color.rgb);
}

And then make the same change on line 116 of misc/FFNx.lighting.frag.

from ffnx.

julianxhokaxhiu avatar julianxhokaxhiu commented on April 28, 2024

Thanks for the research and knowledge share. Care to make a PR? :) I'll be happy to review, thank you!

from ffnx.

julianxhokaxhiu avatar julianxhokaxhiu commented on April 28, 2024

Thanks a lot

from ffnx.

julianxhokaxhiu avatar julianxhokaxhiu commented on April 28, 2024

Closing in favor of #536

from ffnx.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.