Skip to content

Instantly share code, notes, and snippets.

@yohhoy
Last active June 11, 2024 03:44
Show Gist options
  • Save yohhoy/dafa5a47dade85d8b40625261af3776a to your computer and use it in GitHub Desktop.
Save yohhoy/dafa5a47dade85d8b40625261af3776a to your computer and use it in GitHub Desktop.
RGB <=> YCbCr(YPbPr) color space conversion
@Vanilagy
Copy link

Color spaces are the most niche, rabbit holey thing ever, I swear

@danigc98
Copy link

They really are. I feel I will never gain my time back from learning this stuff.

@zhanwang-sky
Copy link

e for BT.2020 should be 1.4746, it can be calculated by the following formula:
e = (1 - a) / 0.5,
d = (1 - c) / 0.5

@yohhoy
Copy link
Author

yohhoy commented Jun 8, 2023

e for BT.2020 should be 1.4746,

Fixed. thanks!

@molesmoke
Copy link

Looks like Cb/Cr should be centred around 0.5?

Y  = a * R + b * G + c * B
Cb = (B - Y) / d  + 0.5
Cr = (R - Y) / e + 0.5

@yohhoy
Copy link
Author

yohhoy commented Jan 17, 2024

Chrominance(Chroma) Cb/Cr are defined in the range [-0.5, 0.5].

@molesmoke
Copy link

Oh yup, my bad, I was thinking about it for use in a shader.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment