-
Notifications
You must be signed in to change notification settings - Fork 377
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
update yuvRgbConvCoeffs slightly #584
base: develop
Are you sure you want to change the base?
Conversation
Could you share which formula and rounding you used for this? Has been a while since I calculated these. |
Also do not forget that AviSynth/AviSynthPlus#259
|
Hi @ValeZAA Would you explain the link you attached more clearly? What it is that I missed in the conversion formula? |
Yes, you are right. Cb = Clip1_C ( Round( ( ( 1 << BitDepth_C ) − 1 ) * E′_PB ) + ( 1 << ( BitDepth_C − 1 ) ) ) Chroma in Cb, Cr in float and goes from -0.5 and +0.5 and those map to 0.5 and 255.5 before rounding and clipping.
I mean... It is just float value, still digital float. Analog YIQ and YUV are very different matrices. |
Well, the "analog value" I used is for electrical level values in range [0,1] and those in [-0.5,0.5], biased relative values. Could you please explain more clearly, where is it that 255.5 or 127.5 coming from? |
So I also took a look and I think the whole conversion here is not really correct. I looked at the standard (https://www.itu.int/rec/R-REC-BT.2020/en) and inverted the formulas in there (10 bit YUV limited range to RGB 8 bit full range) and got quite different values:
I think I never calculated these values myself but inherited them from previous code. Maybe this code needs a good rework overall. Ultimately I was planning on implementing an external library for the conversions aniways. I was thinking about zImg because that can do all color conversions as well as dithering. It also has some assembly optimizations ... The calculation you presented above is not really derived from the BT.2020 standard, is it? |
Generally, this conversion could be divided into 2 parts:
The first part is where conversion coefficients are needed for sure, the latter one can be done with just right-shift or dithering. With precondition as above, 16bit decimal precision coefficient for 10bit limited YUV to 10bit full RGB through BT.2020 is:
The key coefficient I presented as above ( |
The calculation in the original code is OK. |
ITU-T Series H Supplement 15 (01/2017) says (https://www.itu.int/itu-t/recommendations/rec.aspx?rec=13243) what the inverted matrix should be. Remember, the main matrix is the matrix from R'G'B' to Y'Cb'Cr'. That matrix has 4 digits and is not allowed to be higher presicion. It is the Y'Cb'Cr to R'G'B' that is inverted, and depends on bitness. 16 bits may need more digits in the matrix. |
Hi @ValeZAA This ITU-T H.Sup15 document you mentioned is about "Conversion and coding practices for HDR/WCG Y'CbCr 4:2:0 video with PQ transfer characteristics". This PR is about BT.601/BT.709/BT.2020 conversion, and more precisely, is about linear matrix conversion, with no consideration about gamma/EOTF/OETF. |
And that is what that document is about too. I quoted from it, see screenshot. But, k_R, k_G, k_B = 0.2627, 0.6780, 0.0593 are derived from BT.2020 primaries and white point. |
Sorry, I am confused. What is wrong with "k_R, k_G, k_B = 0.2627, 0.6780, 0.0593 are derived from BT.2020 primaries and white point"? Could you explain it? |
Nothing is wrong. I am saying that WCG is implicitly used in matrix. Indeed, D65 is xy 0.3127 0.3290 Red: 0.708 0.292 Green 0.170 0.797 Blue 0.131 0.046 Then use H.273 document eq 39— 44 https://www.itu.int/rec/T-REC-H.273-202309-T/en Kr and Kb are calculated using those 8 numbers above. |
When talking about BT.601/BT.709/BT.2020, shouldn't we just refer to BT.601/BT.709/BT.2020? Do you mean that HDR and WCG options need taking into account? |
Where is your math provided in those docs? No, we need to read all related to series H docs. Again, supplement 15 talks about matrix and chroma siting and upscaling from 420 to 444 algorithm, its FIR filter for topleft or left chroma siting, it is implememted in YUView.
Yes, R'G'B'. |
Have you reviewed the modifications in this PR? They are about BT.601/BT.709/BT.2020 only.
No, series BT docs is enough, because only BT.601/BT.709/BT.2020 coefficients are modified for now, they are prefixed with "BT", NOT "H". And they have nothing to do with dithering or gamma or chroma-downsample or HDR or WCG you mentioned above. If you care about those things that could be added into this project, you can open new issues or PR. |
612357f
to
219a1a7
Compare
Minor modifications here can bring the conversion result closer to the theoretical value.