Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log2Lin's lin2log math might be incorrect #76

Closed
markreidvfx opened this issue Sep 5, 2020 · 9 comments
Closed

Log2Lin's lin2log math might be incorrect #76

markreidvfx opened this issue Sep 5, 2020 · 9 comments
Assignees

Comments

@markreidvfx
Copy link

Hi,

I was looking at the implementation of log2lin for reference and I think the lin2log math might be incorrect.

https://github.com/NatronGitHub/openfx-misc/blob/master/Log2Lin/Log2Lin.cpp#L146

the comment there says

offset = pow(10,(blackpoint - whitepoint) * 0.002 / gamma)
gain = 1/(1-offset)
linear = gain * (pow(10,(1023*v - whitepoint)*0.002/gamma) - offset)
cineon = (log10((v + offset) /gain)/ (0.002 / gamma) + whitepoint)/1023

To me, the should cineon lin2log expression be

cineon = (log10(v/gain + offset )/ (0.002 / gamma) + whitepoint)/1023

v/gain + offset instead of (v + offset)/gain

Also the comment shows up twice in the file and the first one is different

@devernay
Copy link
Member

devernay commented Sep 8, 2020

There is definitely an inconsistency between the two formulas.
Note that TuttleOFX has the same issue:

I can't find where I got these formulas from. Do you have a reference? Maybe the log2lin formula is wrong, and not the lin2log?

@devernay
Copy link
Member

devernay commented Sep 8, 2020

This doc, which is to be the foundation to Cineon, seems to imply that log2lin is wrong, rather than lin2log:
http://www.dotcsw.com/doc/cineon1.pdf
image
image
image

@devernay
Copy link
Member

devernay commented Sep 8, 2020

Does this look good to you? c89ac63

@markreidvfx
Copy link
Author

The inverse math and the spec make sense to me!

I thought the lin2log was wrong because the log2lin matches nuke.

But the spec implies nuke's math is wrong

(pow(10,(1023*x-685)/300)-.0108)/(1-.0108)

they shuffled a couple things around, divides instead of multiplies

1 /0.002 / 0.6 == 300
offset == 0.0108

The minus offset is happening before the gain.

am I crazy?

@devernay
Copy link
Member

devernay commented Sep 9, 2020

@markreidvfx I see that python colour' version refers to This formula in Sony's code which implies that lin2log is wrong, as you initially said. Do we agree on this? (sorry, I need you as a reviewer)

Edit: There's also this code in ACES

@markreidvfx
Copy link
Author

Yes I agree, I think it might be best fix the lin2log like I initially suggested. python colour's lin2log version seems to also match the one I formulated by inverting the log2lin.

I still find it a bit un-nerving that the spec says otherwise, but I guess it is better to be compatible other implementations.

@devernay
Copy link
Member

Does #79 look right?

devernay added a commit that referenced this issue Feb 13, 2021
* Lin2Log: fix inconsistency between log2lin and lin2log

See #76
@devernay
Copy link
Member

closed by #79

@markreidvfx
Copy link
Author

sorry, I missed this, looks good to me!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants